PaymentSplitResource.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. $schedule = $this->payment?->schedule ?? $this->payment?->servicePackage?->items?->first()?->schedule;
  11. return [
  12. 'id' => $this->id,
  13. 'payment_id' => $this->payment_id,
  14. 'provider_id' => $this->provider_id,
  15. 'provider_name' => $this->provider?->user?->name,
  16. 'provider_withdrawal_id' => $this->provider_withdrawal_id,
  17. 'gateway_provider' => $this->gateway_provider,
  18. 'gateway_transfer_target_reference' => $this->gateway_transfer_target_reference,
  19. 'gateway_transfer_target_label' => $this->gateway_transfer_target_label,
  20. 'status' => $this->status,
  21. 'gross_amount' => $this->gross_amount,
  22. 'gateway_fee_amount' => $this->gateway_fee_amount,
  23. 'net_amount' => $this->net_amount,
  24. 'transferred_at' => $this->transferred_at?->toISOString(),
  25. 'metadata' => $this->metadata,
  26. 'payment_status' => $this->payment?->status?->value,
  27. 'payment_paid_at' => $this->payment?->paid_at?->toISOString(),
  28. 'service_package_id' => $this->payment?->service_package_id,
  29. 'schedule_ids' => $this->payment?->servicePackage?->items
  30. ?->pluck('schedule_id')
  31. ->values(),
  32. 'schedule_date' => $schedule?->date?->format('d/m/Y'),
  33. 'schedule_status' => $schedule?->status,
  34. 'schedule_period_type' => $schedule?->period_type,
  35. 'client_name' => $schedule?->client?->user?->name,
  36. 'created_at' => $this->created_at?->toISOString(),
  37. 'updated_at' => $this->updated_at?->toISOString(),
  38. ];
  39. }
  40. public static function collection($resource): AnonymousResourceCollection
  41. {
  42. return parent::collection($resource);
  43. }
  44. }