PagarmeCardResponseData.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Data\Pagarme\Response;
  3. final 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 function brand(): ?string
  19. {
  20. return $this->brand;
  21. }
  22. public function id(): ?string
  23. {
  24. return $this->id;
  25. }
  26. public function lastFourDigits(): ?string
  27. {
  28. return $this->lastFourDigits;
  29. }
  30. public function requireId(): string
  31. {
  32. if (! $this->id) {
  33. throw new \RuntimeException('Pagar.me card creation returned an empty id.');
  34. }
  35. return $this->id;
  36. }
  37. //
  38. public function toArray(): array
  39. {
  40. return [
  41. 'id' => $this->id,
  42. 'first_six_digits' => $this->firstSixDigits,
  43. 'last_four_digits' => $this->lastFourDigits,
  44. 'brand' => $this->brand,
  45. 'holder_name' => $this->holderName,
  46. 'exp_month' => $this->expMonth,
  47. 'exp_year' => $this->expYear,
  48. 'status' => $this->status,
  49. 'type' => $this->type,
  50. 'created_at' => $this->createdAt,
  51. 'updated_at' => $this->updatedAt,
  52. ];
  53. }
  54. }