PagarmeTransferResponseData.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Data\Pagarme\Response;
  3. final readonly class PagarmeTransferResponseData extends PagarmeResponseData
  4. {
  5. public function __construct(
  6. public ?string $id,
  7. public ?int $amount,
  8. public ?string $type,
  9. public ?string $status,
  10. public ?int $fee,
  11. public ?string $fundingDate,
  12. public ?string $fundingEstimatedDate,
  13. public ?array $bankAccount,
  14. public ?string $bankResponse,
  15. public ?string $createdAt,
  16. public ?array $metadata,
  17. ) {}
  18. //
  19. public static function fromArray(array $payload): static
  20. {
  21. return new self(
  22. id: static::arrString($payload, 'id'),
  23. amount: static::arrInt($payload, 'amount'),
  24. type: static::arrString($payload, 'type'),
  25. status: static::arrString($payload, 'status'),
  26. fee: static::arrInt($payload, 'fee'),
  27. fundingDate: static::arrString($payload, 'funding_date'),
  28. fundingEstimatedDate: static::arrString($payload, 'funding_estimated_date'),
  29. bankAccount: static::arrGet($payload, 'bank_account'),
  30. bankResponse: static::arrString($payload, 'bank_response'),
  31. createdAt: static::arrString($payload, 'created_at') ?? static::arrString($payload, 'date_created'),
  32. metadata: static::arrGet($payload, 'metadata'),
  33. );
  34. }
  35. public function toArray(): array
  36. {
  37. return [
  38. 'id' => $this->id,
  39. 'amount' => $this->amount,
  40. 'type' => $this->type,
  41. 'status' => $this->status,
  42. 'fee' => $this->fee,
  43. 'funding_date' => $this->fundingDate,
  44. 'funding_estimated_date' => $this->fundingEstimatedDate,
  45. 'bank_account' => $this->bankAccount,
  46. 'bank_response' => $this->bankResponse,
  47. 'created_at' => $this->createdAt,
  48. 'metadata' => $this->metadata,
  49. ];
  50. }
  51. }