PaymentSplitResource.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. class PaymentSplitResource extends JsonResource
  7. {
  8. public function toArray(Request $request): array
  9. {
  10. return [
  11. 'id' => $this->id,
  12. 'payment_id' => $this->payment_id,
  13. 'provider_id' => $this->provider_id,
  14. 'provider_name' => $this->provider?->user?->name,
  15. 'provider_withdrawal_id' => $this->provider_withdrawal_id,
  16. 'gateway_provider' => $this->gateway_provider,
  17. 'gateway_transfer_target_reference' => $this->gateway_transfer_target_reference,
  18. 'gateway_transfer_target_label' => $this->gateway_transfer_target_label,
  19. 'status' => $this->status,
  20. 'gross_amount' => $this->gross_amount,
  21. 'gateway_fee_amount' => $this->gateway_fee_amount,
  22. 'net_amount' => $this->net_amount,
  23. 'transferred_at' => $this->transferred_at?->toISOString(),
  24. 'metadata' => $this->metadata,
  25. 'payment_status' => $this->payment?->status?->value,
  26. 'payment_paid_at' => $this->payment?->paid_at?->toISOString(),
  27. 'cart_id' => $this->payment?->cart_id,
  28. 'schedule_ids' => $this->payment?->cart?->items?->pluck('schedule_id')->values(),
  29. 'schedule_date' => $this->payment?->schedule?->date,
  30. 'schedule_status' => $this->payment?->schedule?->status,
  31. 'schedule_period_type' => $this->payment?->schedule?->period_type,
  32. 'client_name' => $this->payment?->schedule?->client?->user?->name,
  33. 'created_at' => $this->created_at?->toISOString(),
  34. 'updated_at' => $this->updated_at?->toISOString(),
  35. ];
  36. }
  37. public static function collection($resource): AnonymousResourceCollection
  38. {
  39. return parent::collection($resource);
  40. }
  41. }