PagarmeTransferResponseData.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Data\Pagarme\Response;
  3. readonly class PagarmeTransferResponseData
  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. public static function fromArray(array $payload): self
  19. {
  20. return new self(
  21. id: $payload['id'] ?? null,
  22. amount: $payload['amount'] ?? null,
  23. type: $payload['type'] ?? null,
  24. status: $payload['status'] ?? null,
  25. fee: $payload['fee'] ?? null,
  26. fundingDate: $payload['funding_date'] ?? null,
  27. fundingEstimatedDate: $payload['funding_estimated_date'] ?? null,
  28. bankAccount: $payload['bank_account'] ?? null,
  29. bankResponse: $payload['bank_response'] ?? null,
  30. createdAt: $payload['created_at'] ?? $payload['date_created'] ?? null,
  31. metadata: $payload['metadata'] ?? null,
  32. );
  33. }
  34. public function id(): ?string
  35. {
  36. return $this->id;
  37. }
  38. public function status(): ?string
  39. {
  40. return $this->status;
  41. }
  42. public function toArray(): array
  43. {
  44. return [
  45. 'id' => $this->id,
  46. 'amount' => $this->amount,
  47. 'type' => $this->type,
  48. 'status' => $this->status,
  49. 'fee' => $this->fee,
  50. 'funding_date' => $this->fundingDate,
  51. 'funding_estimated_date' => $this->fundingEstimatedDate,
  52. 'bank_account' => $this->bankAccount,
  53. 'bank_response' => $this->bankResponse,
  54. 'created_at' => $this->createdAt,
  55. 'metadata' => $this->metadata,
  56. ];
  57. }
  58. }