PagarmeTransferResponseData.php 2.3 KB

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