1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 21:52:35 +01:00
invoiceninja/app/Http/Requests/Payment/RefundPaymentRequest.php

91 lines
2.4 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Requests\Payment;
use App\Http\Requests\Request;
use App\Http\ValidationRules\Payment\ValidRefundableRequest;
use App\Http\ValidationRules\ValidRefundableInvoices;
use App\Models\Payment;
use App\Utils\Traits\MakesHash;
class RefundPaymentRequest extends Request
{
use MakesHash;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
2024-01-14 05:05:00 +01:00
public function authorize(): bool
{
2023-08-01 14:36:04 +02:00
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->isAdmin();
}
2022-06-24 03:55:41 +02:00
public function prepareForValidation()
{
$input = $this->all();
if (! isset($input['gateway_refund'])) {
$input['gateway_refund'] = false;
}
if (! isset($input['send_email'])) {
$input['send_email'] = false;
}
if (isset($input['id'])) {
$input['id'] = $this->decodePrimaryKey($input['id']);
}
if (isset($input['invoices'])) {
foreach ($input['invoices'] as $key => $invoice) {
$input['invoices'][$key]['invoice_id'] = $this->decodePrimaryKey($invoice['invoice_id']);
}
}
if (isset($input['credits'])) {
unset($input['credits']);
// foreach($input['credits'] as $key => $credit)
2023-10-26 04:57:44 +02:00
// $input['credits'][$key]['credit_id'] = $this->decodePrimaryKey($credit['credit_id']);
}
$this->replace($input);
}
2023-08-01 15:28:30 +02:00
public function rules(): array
{
$input = $this->all();
$rules = [
2023-08-01 15:28:30 +02:00
'id' => 'bail|required', //@phpstan-ignore-line
'id' => new ValidRefundableRequest($input),
'amount' => 'numeric',
'date' => 'required',
'invoices.*.invoice_id' => 'required',
'invoices.*.amount' => 'required',
'invoices' => new ValidRefundableInvoices($input),
];
return $rules;
}
2023-08-01 15:01:48 +02:00
public function payment(): ?\App\Models\Payment
{
$input = $this->all();
return Payment::whereId($input['id'])->first();
}
}