PaymentResource.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Models\Payment;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
  6. use Illuminate\Http\Resources\Json\JsonResource;
  7. class PaymentResource extends JsonResource
  8. {
  9. /**
  10. * Transform the resource into an array.
  11. *
  12. * @return array<string, mixed>
  13. */
  14. public function toArray(Request $request): array
  15. {
  16. return [
  17. 'id' => $this->id,
  18. 'schedule_id' => $this->schedule_id,
  19. 'client_id' => $this->client_id,
  20. 'provider_id' => $this->provider_id,
  21. 'client_payment_method_id' => $this->client_payment_method_id,
  22. 'gateway_provider' => $this->gateway_provider,
  23. 'gateway_entity_reference' => $this->gateway_entity_reference,
  24. 'gateway_entity_label' => $this->gateway_entity_label,
  25. 'gateway_operation_reference' => $this->gateway_operation_reference,
  26. 'gateway_operation_label' => $this->gateway_operation_label,
  27. 'payment_method' => $this->payment_method,
  28. 'status' => $this->status,
  29. 'gross_amount' => $this->gross_amount,
  30. 'gateway_fee_amount' => $this->gateway_fee_amount,
  31. 'platform_fee_amount' => $this->platform_fee_amount,
  32. 'net_amount' => $this->net_amount,
  33. 'currency' => $this->currency,
  34. 'installments' => $this->installments,
  35. 'authorized_at' => $this->authorized_at?->toISOString(),
  36. 'paid_at' => $this->paid_at?->toISOString(),
  37. 'failed_at' => $this->failed_at?->toISOString(),
  38. 'cancelled_at' => $this->cancelled_at?->toISOString(),
  39. 'expires_at' => $this->expires_at?->toISOString(),
  40. 'failure_code' => $this->failure_code,
  41. 'failure_message' => $this->failure_message,
  42. 'gateway_payload' => $this->gateway_payload,
  43. 'metadata' => $this->metadata,
  44. 'created_at' => $this->created_at?->toISOString(),
  45. 'updated_at' => $this->updated_at?->toISOString(),
  46. ];
  47. }
  48. /**
  49. * @param \Illuminate\Database\Eloquent\Collection<Payment> $resource
  50. * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<PaymentResource>
  51. */
  52. public static function collection($resource): AnonymousResourceCollection
  53. {
  54. return parent::collection($resource);
  55. }
  56. }