TransferResponseData.php 2.2 KB

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