| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace App\Data\Pagarme\Response\PagarmeCustomerResponseData;
- use App\Data\Pagarme\Response\PagarmeCustomerResponseData\PagarmeCustomerPhonesResponseData\PagarmeCustomerPhonesResponseData;
- final readonly class PagarmeCustomerResponseData
- {
- public function __construct(
- public ?string $id,
- public ?string $name,
- public ?string $email,
- public ?string $code,
- public ?string $document,
- public ?string $documentType,
- public ?string $type,
- public ?bool $delinquent,
- public ?PagarmeCustomerAddressResponseData $address,
- public PagarmeCustomerPhonesResponseData $phones,
- public ?string $createdAt = null,
- public ?string $updatedAt = null,
- ) {}
- public function id(): ?string
- {
- return $this->id;
- }
- public function requireId(): string
- {
- if (! $this->id) {
- throw new \RuntimeException('Customer creation returned an empty id.');
- }
- return $this->id;
- }
- public static function fromArray(array $payload): self
- {
- return new self(
- id: $payload['id'] ?? null,
- name: $payload['name'] ?? null,
- email: $payload['email'] ?? null,
- code: $payload['code'] ?? null,
- document: $payload['document'] ?? null,
- documentType: $payload['document_type'] ?? null,
- type: $payload['type'] ?? null,
- delinquent: $payload['delinquent'] ?? null,
- address: PagarmeCustomerAddressResponseData::fromArray($payload['address'] ?? null),
- phones: PagarmeCustomerPhonesResponseData::fromArray($payload['phones'] ?? null),
- createdAt: $payload['created_at'] ?? null,
- updatedAt: $payload['updated_at'] ?? null,
- );
- }
- public function toArray(): array
- {
- return [
- 'id' => $this->id,
- 'name' => $this->name,
- 'email' => $this->email,
- 'code' => $this->code,
- 'document' => $this->document,
- 'document_type' => $this->documentType,
- 'type' => $this->type,
- 'delinquent' => $this->delinquent,
- 'address' => $this->address?->toArray(),
- 'phones' => $this->phones->toArray(),
- 'created_at' => $this->createdAt,
- 'updated_at' => $this->updatedAt,
- ];
- }
- }
|