2017-01-30 21:40:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
2016-05-02 11:38:01 +03:00
|
|
|
|
|
|
|
|
use App\Models\Invoice;
|
2016-12-13 17:52:09 +11:00
|
|
|
|
2016-05-02 11:38:01 +03:00
|
|
|
class CreatePaymentAPIRequest extends PaymentRequest
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function authorize()
|
|
|
|
|
{
|
|
|
|
|
return $this->user()->can('create', ENTITY_PAYMENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function rules()
|
|
|
|
|
{
|
2017-01-30 18:05:31 +02:00
|
|
|
if (! $this->invoice_id || ! $this->amount) {
|
2016-05-02 11:38:01 +03:00
|
|
|
return [
|
2016-09-27 17:13:42 +03:00
|
|
|
'invoice_id' => 'required|numeric|min:1',
|
2017-03-26 21:31:13 +03:00
|
|
|
'amount' => 'required|numeric|not_in:0',
|
2016-05-02 11:38:01 +03:00
|
|
|
];
|
|
|
|
|
}
|
2016-07-18 21:12:18 +03:00
|
|
|
|
2017-01-13 09:02:22 +02:00
|
|
|
$this->invoice = $invoice = Invoice::scope($this->invoice_id)
|
2016-07-18 21:12:18 +03:00
|
|
|
->invoices()
|
|
|
|
|
->firstOrFail();
|
2016-05-02 11:38:01 +03:00
|
|
|
|
|
|
|
|
$this->merge([
|
2016-07-18 21:12:18 +03:00
|
|
|
'invoice_id' => $invoice->id,
|
2016-05-02 11:38:01 +03:00
|
|
|
'client_id' => $invoice->client->id,
|
|
|
|
|
]);
|
2016-07-18 21:12:18 +03:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
$rules = [
|
2017-06-13 22:35:09 +03:00
|
|
|
'amount' => 'required|numeric|not_in:0',
|
2016-07-03 18:11:58 +02:00
|
|
|
];
|
2016-05-02 11:38:01 +03:00
|
|
|
|
|
|
|
|
if ($this->payment_type_id == PAYMENT_TYPE_CREDIT) {
|
|
|
|
|
$rules['payment_type_id'] = 'has_credit:' . $invoice->client->public_id . ',' . $this->amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $rules;
|
|
|
|
|
}
|
|
|
|
|
}
|