|
@@ -0,0 +1,73 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace App\Http\Requests;
|
|
|
|
|
+
|
|
|
|
|
+use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
+
|
|
|
|
|
+class ClientPaymentMethodRequest extends FormRequest
|
|
|
|
|
+{
|
|
|
|
|
+ public function authorize(): bool
|
|
|
|
|
+ {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function rules(): array
|
|
|
|
|
+ {
|
|
|
|
|
+ $rules = [
|
|
|
|
|
+ 'client_id' => ['sometimes', 'integer', 'exists:clients,id'],
|
|
|
|
|
+ 'card_number' => ['sometimes', 'string', 'min:13', 'max:19'],
|
|
|
|
|
+ 'holder_name' => ['sometimes', 'string', 'max:255'],
|
|
|
|
|
+ 'expiration' => ['sometimes', 'string', 'regex:/^(0[1-9]|1[0-2])\/\d{4}$/'],
|
|
|
|
|
+ 'cvv' => ['sometimes', 'string', 'min:3', 'max:4'],
|
|
|
|
|
+ 'card_name' => ['nullable', 'string', 'max:255'],
|
|
|
|
|
+ 'brand' => ['nullable', 'string', 'max:50'],
|
|
|
|
|
+ 'last_four_digits' => ['sometimes', 'string', 'size:4'],
|
|
|
|
|
+ 'is_active' => ['nullable', 'boolean'],
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ if ($this->isMethod('POST')) {
|
|
|
|
|
+ $rules['client_id'] = ['required', 'integer', 'exists:clients,id'];
|
|
|
|
|
+ $rules['card_number'] = ['required', 'string', 'min:13', 'max:19'];
|
|
|
|
|
+ $rules['holder_name'] = ['required', 'string', 'max:255'];
|
|
|
|
|
+ $rules['expiration'] = ['required', 'string', 'regex:/^(0[1-9]|1[0-2])\/\d{4}$/'];
|
|
|
|
|
+ $rules['cvv'] = ['required', 'string', 'min:3', 'max:4'];
|
|
|
|
|
+ $rules['last_four_digits'] = ['required', 'string', 'size:4'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $rules;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function messages(): array
|
|
|
|
|
+ {
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'client_id.required' => 'O cliente é obrigatório.',
|
|
|
|
|
+ 'client_id.exists' => 'Cliente não encontrado.',
|
|
|
|
|
+ 'card_number.required' => 'O número do cartão é obrigatório.',
|
|
|
|
|
+ 'card_number.min' => 'O número do cartão deve ter no mínimo 13 dígitos.',
|
|
|
|
|
+ 'card_number.max' => 'O número do cartão deve ter no máximo 19 dígitos.',
|
|
|
|
|
+ 'holder_name.required' => 'O nome do titular é obrigatório.',
|
|
|
|
|
+ 'expiration.required' => 'A data de validade é obrigatória.',
|
|
|
|
|
+ 'expiration.regex' => 'A data de validade deve estar no formato MM/YYYY.',
|
|
|
|
|
+ 'cvv.required' => 'O CVV é obrigatório.',
|
|
|
|
|
+ 'cvv.min' => 'O CVV deve ter no mínimo 3 dígitos.',
|
|
|
|
|
+ 'cvv.max' => 'O CVV deve ter no máximo 4 dígitos.',
|
|
|
|
|
+ 'last_four_digits.required' => 'Os últimos 4 dígitos são obrigatórios.',
|
|
|
|
|
+ 'last_four_digits.size' => 'Devem ser exatamente 4 dígitos.',
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ protected function prepareForValidation(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($this->has('card_number')) {
|
|
|
|
|
+ $this->merge([
|
|
|
|
|
+ 'card_number' => str_replace(' ', '', $this->card_number),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($this->has('cvv')) {
|
|
|
|
|
+ $this->merge([
|
|
|
|
|
+ 'cvv' => str_replace(' ', '', $this->cvv),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|