|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Coyote\Http\Requests\Job; |
|
4
|
|
|
|
|
5
|
|
|
use Coyote\Repositories\Contracts\CountryRepositoryInterface as CountryRepository; |
|
6
|
|
|
use Illuminate\Foundation\Http\FormRequest; |
|
7
|
|
|
use Illuminate\Validation\Rule; |
|
8
|
|
|
|
|
9
|
|
|
class PaymentRequest extends FormRequest |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Determine if the user is authorized to make this request. |
|
13
|
|
|
* |
|
14
|
|
|
* @return bool |
|
15
|
|
|
*/ |
|
16
|
|
|
public function authorize() |
|
17
|
|
|
{ |
|
18
|
|
|
return true; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param CountryRepository $country |
|
23
|
|
|
* @return array |
|
24
|
|
|
*/ |
|
25
|
|
|
public function rules(CountryRepository $country) |
|
26
|
|
|
{ |
|
27
|
|
|
$codes = $country->pluck('code', 'id'); |
|
28
|
|
|
|
|
29
|
|
|
$price = $this->input('price'); |
|
30
|
|
|
$priceRule = Rule::requiredIf(fn () => $price > 0); |
|
31
|
|
|
|
|
32
|
|
|
return [ |
|
33
|
|
|
'payment_method' => 'required|in:card,p24', |
|
34
|
|
|
'price' => 'required|numeric', |
|
35
|
|
|
'coupon' => [ |
|
36
|
|
|
'nullable', |
|
37
|
|
|
Rule::exists('coupons', 'code')->whereNull('deleted_at') |
|
38
|
|
|
], |
|
39
|
|
|
|
|
40
|
|
|
'invoice.name' => ['bail', $priceRule, 'nullable', 'string', 'max:200'], |
|
41
|
|
|
'invoice.vat_id' => 'nullable|string|max:20', |
|
42
|
|
|
'invoice.address' => ['bail', $priceRule, 'nullable', 'string', 'max:200'], |
|
43
|
|
|
'invoice.city' => ['bail', $priceRule, 'nullable', 'string', 'max:200'], |
|
44
|
|
|
'invoice.postal_code' => ['bail', $priceRule, 'nullable', 'string', 'max:30'], |
|
45
|
|
|
'invoice.country_id' => [ |
|
46
|
|
|
'nullable', |
|
47
|
|
|
Rule::requiredIf($this->input('invoice.vat_id') !== null), |
|
48
|
|
|
Rule::in(array_flip($codes)) |
|
49
|
|
|
] |
|
50
|
|
|
]; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|