PagarmeCustomerResponseData.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Data\Pagarme\Response\PagarmeCustomerResponseData;
  3. use App\Data\Pagarme\Response\PagarmeCustomerResponseData\PagarmeCustomerPhonesResponseData\PagarmeCustomerPhonesResponseData;
  4. 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 static function fromArray(array $payload): self
  21. {
  22. return new self(
  23. id: $payload['id'] ?? null,
  24. name: $payload['name'] ?? null,
  25. email: $payload['email'] ?? null,
  26. code: $payload['code'] ?? null,
  27. document: $payload['document'] ?? null,
  28. documentType: $payload['document_type'] ?? null,
  29. type: $payload['type'] ?? null,
  30. delinquent: $payload['delinquent'] ?? null,
  31. address: PagarmeCustomerAddressResponseData::fromArray($payload['address'] ?? null),
  32. phones: PagarmeCustomerPhonesResponseData::fromArray($payload['phones'] ?? null),
  33. createdAt: $payload['created_at'] ?? null,
  34. updatedAt: $payload['updated_at'] ?? null,
  35. );
  36. }
  37. public function id(): ?string
  38. {
  39. return $this->id;
  40. }
  41. public function toArray(): array
  42. {
  43. return [
  44. 'id' => $this->id,
  45. 'name' => $this->name,
  46. 'email' => $this->email,
  47. 'code' => $this->code,
  48. 'document' => $this->document,
  49. 'document_type' => $this->documentType,
  50. 'type' => $this->type,
  51. 'delinquent' => $this->delinquent,
  52. 'address' => $this->address?->toArray(),
  53. 'phones' => $this->phones->toArray(),
  54. 'created_at' => $this->createdAt,
  55. 'updated_at' => $this->updatedAt,
  56. ];
  57. }
  58. }