| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace App\Data\Pagarme\Response\PagarmeRecipientResponseData;
- final readonly class PagarmeRecipientResponseData
- {
- public function __construct(
- public ?string $id,
- public ?string $name,
- public ?string $email,
- public ?string $document,
- public ?string $type,
- public ?string $status,
- public ?PagarmeRecipientBankAccountResponseData $defaultBankAccount = null,
- public ?string $createdAt = null,
- public ?string $updatedAt = null,
- ) {}
- public function defaultBankAccount(): ?PagarmeRecipientBankAccountResponseData
- {
- return $this->defaultBankAccount;
- }
- public function id(): ?string
- {
- return $this->id;
- }
- public function requireId(): string
- {
- if (! $this->id) {
- throw new \RuntimeException('Pagar.me recipient 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,
- document: $payload['document'] ?? null,
- type: $payload['type'] ?? null,
- status: $payload['status'] ?? null,
- defaultBankAccount: ! empty($payload['default_bank_account'])
- ? PagarmeRecipientBankAccountResponseData::fromArray($payload['default_bank_account'])
- : 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,
- 'document' => $this->document,
- 'type' => $this->type,
- 'status' => $this->status,
- 'default_bank_account' => $this->defaultBankAccount?->toArray(),
- 'created_at' => $this->createdAt,
- 'updated_at' => $this->updatedAt,
- ];
- }
- }
|