PagarmeCustomerResponseData.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Data\Pagarme\Response;
  3. use App\Data\Pagarme\Response\Objects\PagarmeCustomerAddressResponseData;
  4. use App\Data\Pagarme\Response\Objects\PagarmeCustomerPhonesResponseData;
  5. readonly class PagarmeCustomerResponseData
  6. {
  7. public function __construct(
  8. public ?string $id,
  9. public ?string $name,
  10. public ?string $email,
  11. public ?string $code,
  12. public ?string $document,
  13. public ?string $documentType,
  14. public ?string $type,
  15. public ?bool $delinquent,
  16. public ?PagarmeCustomerAddressResponseData $address,
  17. public PagarmeCustomerPhonesResponseData $phones,
  18. public ?string $createdAt = null,
  19. public ?string $updatedAt = null,
  20. ) {}
  21. public static function fromArray(array $payload): self
  22. {
  23. return new self(
  24. id: $payload['id'] ?? null,
  25. name: $payload['name'] ?? null,
  26. email: $payload['email'] ?? null,
  27. code: $payload['code'] ?? null,
  28. document: $payload['document'] ?? null,
  29. documentType: $payload['document_type'] ?? null,
  30. type: $payload['type'] ?? null,
  31. delinquent: $payload['delinquent'] ?? null,
  32. address: PagarmeCustomerAddressResponseData::fromArray($payload['address'] ?? null),
  33. phones: PagarmeCustomerPhonesResponseData::fromArray($payload['phones'] ?? null),
  34. createdAt: $payload['created_at'] ?? null,
  35. updatedAt: $payload['updated_at'] ?? null,
  36. );
  37. }
  38. public function id(): ?string
  39. {
  40. return $this->id;
  41. }
  42. public function toArray(): array
  43. {
  44. return [
  45. 'id' => $this->id,
  46. 'name' => $this->name,
  47. 'email' => $this->email,
  48. 'code' => $this->code,
  49. 'document' => $this->document,
  50. 'document_type' => $this->documentType,
  51. 'type' => $this->type,
  52. 'delinquent' => $this->delinquent,
  53. 'address' => $this->address?->toArray(),
  54. 'phones' => $this->phones->toArray(),
  55. 'created_at' => $this->createdAt,
  56. 'updated_at' => $this->updatedAt,
  57. ];
  58. }
  59. }