PagarmeCardResponseData.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Data\Pagarme\Response;
  3. readonly class PagarmeCardResponseData
  4. {
  5. public function __construct(
  6. public ?string $id,
  7. public ?string $firstSixDigits,
  8. public ?string $lastFourDigits,
  9. public ?string $brand,
  10. public ?string $holderName,
  11. public ?int $expMonth,
  12. public ?int $expYear,
  13. public ?string $status,
  14. public ?string $type,
  15. public ?string $createdAt = null,
  16. public ?string $updatedAt = null,
  17. ) {}
  18. public static function fromArray(array $payload): self
  19. {
  20. return new self(
  21. id: $payload['id'] ?? null,
  22. firstSixDigits: $payload['first_six_digits'] ?? null,
  23. lastFourDigits: $payload['last_four_digits'] ?? null,
  24. brand: $payload['brand'] ?? null,
  25. holderName: $payload['holder_name'] ?? null,
  26. expMonth: isset($payload['exp_month']) ? (int) $payload['exp_month'] : null,
  27. expYear: isset($payload['exp_year']) ? (int) $payload['exp_year'] : null,
  28. status: $payload['status'] ?? null,
  29. type: $payload['type'] ?? null,
  30. createdAt: $payload['created_at'] ?? null,
  31. updatedAt: $payload['updated_at'] ?? null,
  32. );
  33. }
  34. public function id(): ?string
  35. {
  36. return $this->id;
  37. }
  38. public function brand(): ?string
  39. {
  40. return $this->brand;
  41. }
  42. public function lastFourDigits(): ?string
  43. {
  44. return $this->lastFourDigits;
  45. }
  46. public function toArray(): array
  47. {
  48. return [
  49. 'id' => $this->id,
  50. 'first_six_digits' => $this->firstSixDigits,
  51. 'last_four_digits' => $this->lastFourDigits,
  52. 'brand' => $this->brand,
  53. 'holder_name' => $this->holderName,
  54. 'exp_month' => $this->expMonth,
  55. 'exp_year' => $this->expYear,
  56. 'status' => $this->status,
  57. 'type' => $this->type,
  58. 'created_at' => $this->createdAt,
  59. 'updated_at' => $this->updatedAt,
  60. ];
  61. }
  62. }