PagarmeCustomerResponseData.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Data\Pagarme\Response\PagarmeCustomerResponseData;
  3. use App\Data\Pagarme\Response\PagarmeCustomerResponseData\PagarmeCustomerPhonesResponseData\PagarmeCustomerPhonesResponseData;
  4. final readonly class PagarmeCustomerResponseData
  5. {
  6. public function __construct(
  7. public ?string $id,
  8. public ?string $name,
  9. public ?string $email,
  10. public ?string $code,
  11. public ?string $document,
  12. public ?string $documentType,
  13. public ?string $type,
  14. public ?bool $delinquent,
  15. public ?PagarmeCustomerAddressResponseData $address,
  16. public PagarmeCustomerPhonesResponseData $phones,
  17. public ?string $createdAt = null,
  18. public ?string $updatedAt = null,
  19. ) {}
  20. public function id(): ?string
  21. {
  22. return $this->id;
  23. }
  24. public function requireId(): string
  25. {
  26. if (! $this->id) {
  27. throw new \RuntimeException('Customer creation returned an empty id.');
  28. }
  29. return $this->id;
  30. }
  31. public function toArray(): array
  32. {
  33. return [
  34. 'id' => $this->id,
  35. 'name' => $this->name,
  36. 'email' => $this->email,
  37. 'code' => $this->code,
  38. 'document' => $this->document,
  39. 'document_type' => $this->documentType,
  40. 'type' => $this->type,
  41. 'delinquent' => $this->delinquent,
  42. 'address' => $this->address?->toArray(),
  43. 'phones' => $this->phones->toArray(),
  44. 'created_at' => $this->createdAt,
  45. 'updated_at' => $this->updatedAt,
  46. ];
  47. }
  48. }