PaymentSplitResource.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. use Illuminate\Support\Facades\Storage;
  7. class PaymentSplitResource extends JsonResource
  8. {
  9. public function toArray(Request $request): array
  10. {
  11. $schedule = $this->payment?->schedule ?? $this->payment?->servicePackage?->items?->first()?->schedule;
  12. return [
  13. 'id' => $this->id,
  14. 'payment_id' => $this->payment_id,
  15. 'provider_id' => $this->provider_id,
  16. 'provider_name' => $this->provider?->user?->name,
  17. 'provider_withdrawal_id' => $this->provider_withdrawal_id,
  18. 'gateway_provider' => $this->gateway_provider,
  19. 'gateway_transfer_target_reference' => $this->gateway_transfer_target_reference,
  20. 'gateway_transfer_target_label' => $this->gateway_transfer_target_label,
  21. 'status' => $this->status,
  22. 'gross_amount' => $this->gross_amount,
  23. 'gateway_fee_amount' => $this->gateway_fee_amount,
  24. 'net_amount' => $this->net_amount,
  25. 'transferred_at' => $this->transferred_at?->toISOString(),
  26. 'metadata' => $this->metadata,
  27. 'payment_status' => $this->payment?->status?->value,
  28. 'payment_paid_at' => $this->payment?->paid_at?->toISOString(),
  29. 'service_package_id' => $this->payment?->service_package_id,
  30. 'schedule_ids' => $this->payment?->servicePackage?->items
  31. ?->pluck('schedule_id')
  32. ->values(),
  33. 'schedule_date' => $schedule?->date?->format('d/m/Y'),
  34. 'schedule_status' => $schedule?->status,
  35. 'schedule_period_type' => $schedule?->period_type,
  36. 'client_name' => $schedule?->client?->user?->name,
  37. 'client_photo' => $schedule?->client?->profileMedia?->path
  38. ? Storage::temporaryUrl($schedule->client->profileMedia->path, now()->addMinutes(60))
  39. : null,
  40. 'created_at' => $this->created_at?->toISOString(),
  41. 'updated_at' => $this->updated_at?->toISOString(),
  42. ];
  43. }
  44. public static function collection($resource): AnonymousResourceCollection
  45. {
  46. return parent::collection($resource);
  47. }
  48. }