CustomerAddressResponseData.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Data\Pagarme\Response\CustomerResponseData;
  3. use App\Data\Pagarme\PagarmeResponseData;
  4. final readonly class CustomerAddressResponseData extends PagarmeResponseData
  5. {
  6. public function __construct(
  7. public ?string $id,
  8. public ?string $line1,
  9. public ?string $line2,
  10. public ?string $zipCode,
  11. public ?string $city,
  12. public ?string $state,
  13. public ?string $country,
  14. public ?string $status,
  15. public ?string $createdAt = null,
  16. public ?string $updatedAt = null,
  17. ) {}
  18. public static function fromArray(array $payload): static
  19. {
  20. return new self(
  21. id: static::arrString($payload, 'id'),
  22. line1: static::arrString($payload, 'line_1'),
  23. line2: static::arrString($payload, 'line_2'),
  24. zipCode: static::arrString($payload, 'zip_code'),
  25. city: static::arrString($payload, 'city'),
  26. state: static::arrString($payload, 'state'),
  27. country: static::arrString($payload, 'country'),
  28. status: static::arrString($payload, 'status'),
  29. createdAt: static::arrString($payload, 'created_at'),
  30. updatedAt: static::arrString($payload, 'updated_at'),
  31. );
  32. }
  33. public function toArray(): array
  34. {
  35. return [
  36. 'id' => $this->id,
  37. 'line_1' => $this->line1,
  38. 'line_2' => $this->line2,
  39. 'zip_code' => $this->zipCode,
  40. 'city' => $this->city,
  41. 'state' => $this->state,
  42. 'country' => $this->country,
  43. 'status' => $this->status,
  44. 'created_at' => $this->createdAt,
  45. 'updated_at' => $this->updatedAt,
  46. ];
  47. }
  48. }