|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Coyote\Http\Forms\Job; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
use Coyote\Services\FormBuilder\Form; |
|
7
|
|
|
use Illuminate\Support\Fluent; |
|
8
|
|
|
use Illuminate\Validation\Rule; |
|
9
|
|
|
|
|
10
|
|
|
class PaymentForm extends Form |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $theme = self::THEME_INLINE; |
|
16
|
|
|
|
|
17
|
|
|
public function buildForm() |
|
18
|
|
|
{ |
|
19
|
|
|
$this |
|
20
|
|
|
->setAttr([ |
|
21
|
|
|
'class' => 'submit-form', |
|
22
|
|
|
'id' => 'payment-form', |
|
23
|
|
|
'@submit.prevent' => 'submit' |
|
24
|
|
|
]) |
|
25
|
|
|
->add('price', 'hidden', [ |
|
26
|
|
|
'attr' => [ |
|
27
|
|
|
'v-model' => 'grossPrice' |
|
28
|
|
|
] |
|
29
|
|
|
]) |
|
30
|
|
|
->add('name', 'text', [ |
|
31
|
|
|
// 'required' => true, |
|
|
|
|
|
|
32
|
|
|
'label' => 'Nazwa (jaka widnieje na karcie kredytowej)', |
|
33
|
|
|
'help' => 'Np. imię i nazwisko. Maksymalnie 32 znaki.', |
|
34
|
|
|
'rules' => 'string|max:32', |
|
35
|
|
|
'attr' => [ |
|
36
|
|
|
'v-model' => 'form.name' |
|
37
|
|
|
] |
|
38
|
|
|
]) |
|
39
|
|
|
->add('number', 'text', [ |
|
40
|
|
|
// 'required' => true, |
|
|
|
|
|
|
41
|
|
|
'label' => 'Numer karty kredytowej lub debetowej', |
|
42
|
|
|
'help' => 'Nie martw się. Numer karty nie będzie przechowywany na naszym serwerze.', |
|
43
|
|
|
'rules' => 'string|cc_number', |
|
44
|
|
|
'attr' => [ |
|
45
|
|
|
'id' => 'credit-card', |
|
46
|
|
|
'v-model' => 'form.number' |
|
47
|
|
|
] |
|
48
|
|
|
]) |
|
49
|
|
|
->add('exp_year', 'select', [ |
|
50
|
|
|
'choices' => $this->getYearList(), |
|
51
|
|
|
'rules' => 'int', |
|
52
|
|
|
'value' => date('Y'), |
|
53
|
|
|
'attr' => [ |
|
54
|
|
|
'class' => 'input-inline', |
|
55
|
|
|
'v-model' => 'form.expiration_year' |
|
56
|
|
|
] |
|
57
|
|
|
]) |
|
58
|
|
|
->add('exp_month', 'select', [ |
|
59
|
|
|
'choices' => $this->getMonthList(), |
|
60
|
|
|
'rules' => 'int|cc_date:exp_month,exp_year', |
|
61
|
|
|
'value' => date('n'), |
|
62
|
|
|
'attr' => [ |
|
63
|
|
|
'class' => 'input-inline', |
|
64
|
|
|
'v-model' => 'form.expiration_month' |
|
65
|
|
|
] |
|
66
|
|
|
]) |
|
67
|
|
|
->add('cvc', 'text', [ |
|
68
|
|
|
'label' => 'Kod zabezpieczeń (CVC)', |
|
69
|
|
|
'help' => '3 ostatnie cyfry na odwrocie karty.', |
|
70
|
|
|
'rules' => 'cc_cvc:number', |
|
71
|
|
|
'attr' => [ |
|
72
|
|
|
'id' => 'cvc', |
|
73
|
|
|
'v-model' => 'form.cvc' |
|
74
|
|
|
] |
|
75
|
|
|
]) |
|
76
|
|
|
->add('enable_invoice', 'checkbox', [ |
|
77
|
|
|
'label' => 'Tak, chcę otrzymać fakturę', |
|
78
|
|
|
'value' => true, |
|
79
|
|
|
'attr' => [ |
|
80
|
|
|
'id' => 'enable-invoice' |
|
81
|
|
|
] |
|
82
|
|
|
]) |
|
83
|
|
|
->add('coupon', 'text', [ |
|
84
|
|
|
'rules' => Rule::exists('coupons', 'code')->whereNull('deleted_at'), |
|
85
|
|
|
'label' => 'Masz kod promocyjny?', |
|
86
|
|
|
'attr' => [ |
|
87
|
|
|
'class' => 'input-sm', |
|
88
|
|
|
'@keyup' => 'validateCoupon', |
|
89
|
|
|
'autocomplete' => 'off' |
|
90
|
|
|
], |
|
91
|
|
|
'row_attr' => [ |
|
92
|
|
|
'v-show' => 'coupon.code || show_coupon === true' |
|
93
|
|
|
] |
|
94
|
|
|
]) |
|
95
|
|
|
->add('invoice', 'child_form', [ |
|
96
|
|
|
'class' => InvoiceForm::class, |
|
97
|
|
|
'value' => $this->data->job->firm |
|
98
|
|
|
]); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return array |
|
103
|
|
|
*/ |
|
104
|
|
|
public function attributes() |
|
105
|
|
|
{ |
|
106
|
|
|
return [ |
|
107
|
|
|
'name' => 'nazwa', |
|
108
|
|
|
'number' => 'numer karty kredytowej', |
|
109
|
|
|
'cvc' => 'CVC' |
|
110
|
|
|
]; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return \Illuminate\Contracts\Validation\Validator |
|
115
|
|
|
*/ |
|
116
|
|
|
protected function getValidatorInstance() |
|
117
|
|
|
{ |
|
118
|
|
|
$validator = parent::getValidatorInstance(); |
|
119
|
|
|
|
|
120
|
|
|
$validator->sometimes(['name', 'number', 'cvc'], 'required', function (Fluent $input) { |
|
|
|
|
|
|
121
|
|
|
return $input->price > 0; |
|
122
|
|
|
}); |
|
123
|
|
|
|
|
124
|
|
|
return $validator; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return array |
|
129
|
|
|
*/ |
|
130
|
|
|
private function getYearList() |
|
131
|
|
|
{ |
|
132
|
|
|
$yearList = []; |
|
133
|
|
|
$currYear = date('Y'); |
|
134
|
|
|
|
|
135
|
|
|
for ($i = $currYear; $i <= $currYear + 10; $i++) { |
|
136
|
|
|
$yearList[$i] = $i; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
return $yearList; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return array |
|
144
|
|
|
*/ |
|
145
|
|
|
private function getMonthList() |
|
146
|
|
|
{ |
|
147
|
|
|
$monthList = []; |
|
148
|
|
|
$currYear = date('Y'); |
|
149
|
|
|
|
|
150
|
|
|
for ($i = 1; $i <= 12; $i++) { |
|
151
|
|
|
$monthList[$i] = sprintf('%2d - %s', $i, Carbon::createFromDate($currYear, $i, 1)->formatLocalized('%B')); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
return $monthList; |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.