PaymentRequest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Http\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. class PaymentRequest extends FormRequest
  5. {
  6. public function authorize(): bool
  7. {
  8. return true;
  9. }
  10. public function rules(): array
  11. {
  12. $rules = [
  13. 'schedule_id' => ['sometimes', 'integer', 'exists:schedules,id'],
  14. 'client_id' => ['sometimes', 'integer', 'exists:clients,id'],
  15. 'provider_id' => ['nullable', 'integer', 'exists:providers,id'],
  16. 'client_payment_method_id' => ['nullable', 'integer', 'exists:client_payment_methods,id'],
  17. 'gateway_provider' => ['sometimes', 'string', 'max:255'],
  18. 'gateway_entity_reference' => ['nullable', 'string', 'max:255'],
  19. 'gateway_entity_label' => ['nullable', 'string', 'max:255'],
  20. 'gateway_operation_reference' => ['nullable', 'string', 'max:255'],
  21. 'gateway_operation_label' => ['nullable', 'string', 'max:255'],
  22. 'payment_method' => ['sometimes', 'in:credit_card,pix'],
  23. 'status' => ['sometimes', 'in:pending,processing,authorized,paid,failed,cancelled'],
  24. 'gross_amount' => ['sometimes', 'numeric', 'min:0'],
  25. 'gateway_fee_amount' => ['sometimes', 'numeric', 'min:0'],
  26. 'platform_fee_amount' => ['sometimes', 'numeric', 'min:0'],
  27. 'net_amount' => ['sometimes', 'numeric', 'min:0'],
  28. 'currency' => ['sometimes', 'string', 'size:3'],
  29. 'installments' => ['sometimes', 'integer', 'min:1', 'max:24'],
  30. 'authorized_at' => ['nullable', 'date'],
  31. 'paid_at' => ['nullable', 'date'],
  32. 'failed_at' => ['nullable', 'date'],
  33. 'cancelled_at' => ['nullable', 'date'],
  34. 'expires_at' => ['nullable', 'date'],
  35. 'failure_code' => ['nullable', 'string', 'max:255'],
  36. 'failure_message' => ['nullable', 'string'],
  37. 'gateway_payload' => ['nullable', 'array'],
  38. 'metadata' => ['nullable', 'array'],
  39. ];
  40. if ($this->isMethod('POST')) {
  41. $rules['schedule_id'] = ['required', 'integer', 'exists:schedules,id'];
  42. $rules['client_id'] = ['required', 'integer', 'exists:clients,id'];
  43. $rules['payment_method'] = ['required', 'in:credit_card,pix'];
  44. $rules['gross_amount'] = ['required', 'numeric', 'min:0'];
  45. $rules['net_amount'] = ['required', 'numeric', 'min:0'];
  46. }
  47. return $rules;
  48. }
  49. }