|
|
@@ -16,14 +16,33 @@ class ProviderPaymentMethodRequest extends FormRequest
|
|
|
|
|
|
public function rules(): array
|
|
|
{
|
|
|
- return [
|
|
|
- 'provider_id' => ['required', 'exists:providers,id'],
|
|
|
- 'account_type' => ['required', Rule::in([AccountTypeEnum::PIX->value, AccountTypeEnum::BANK_ACCOUNT->value])],
|
|
|
- 'pix_key' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::PIX->value)],
|
|
|
- 'bank_account_type' => ['nullable', Rule::in([BankAccountTypeEnum::CHECKING->value, BankAccountTypeEnum::SAVINGS->value]), Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
|
|
|
- 'agency' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
|
|
|
- 'account' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
|
|
|
- 'digit' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
|
|
|
- ];
|
|
|
+
|
|
|
+ if ($this->account_type == AccountTypeEnum::PIX->value) {
|
|
|
+
|
|
|
+ $rules = [
|
|
|
+ 'account_type' => ['sometimes', Rule::in([AccountTypeEnum::PIX->value, AccountTypeEnum::BANK_ACCOUNT->value])],
|
|
|
+ 'pix_key' => ['required', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::PIX->value)],
|
|
|
+ 'bank_account_type' => ['nullable', Rule::in([BankAccountTypeEnum::CHECKING->value, BankAccountTypeEnum::SAVINGS->value]), Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
|
|
|
+ 'agency' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
|
|
|
+ 'account' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
|
|
|
+ 'digit' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $rules = [
|
|
|
+ 'account_type' => ['sometimes', Rule::in([AccountTypeEnum::PIX->value, AccountTypeEnum::BANK_ACCOUNT->value])],
|
|
|
+ 'pix_key' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::PIX->value)],
|
|
|
+ 'bank_account_type' => ['sometimes', Rule::in([BankAccountTypeEnum::CHECKING->value, BankAccountTypeEnum::SAVINGS->value]), Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
|
|
|
+ 'agency' => ['sometimes', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
|
|
|
+ 'account' => ['sometimes', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
|
|
|
+ 'digit' => ['sometimes', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->isMethod('post')) {
|
|
|
+ $rules['provider_id'] = ['required', 'exists:providers,id'];
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ return $rules;
|
|
|
}
|
|
|
}
|