PagarmeCustomerAddressResponseData.php 1.7 KB

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