PagarmeRecipientResponseData.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Data\Pagarme\Response\PagarmeRecipientResponseData;
  3. final readonly class PagarmeRecipientResponseData
  4. {
  5. public function __construct(
  6. public ?string $id,
  7. public ?string $name,
  8. public ?string $email,
  9. public ?string $document,
  10. public ?string $type,
  11. public ?string $status,
  12. public ?PagarmeRecipientBankAccountResponseData $defaultBankAccount = null,
  13. public ?string $createdAt = null,
  14. public ?string $updatedAt = null,
  15. ) {}
  16. public function defaultBankAccount(): ?PagarmeRecipientBankAccountResponseData
  17. {
  18. return $this->defaultBankAccount;
  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('Pagar.me recipient creation returned an empty id.');
  28. }
  29. return $this->id;
  30. }
  31. //
  32. public function toArray(): array
  33. {
  34. return [
  35. 'id' => $this->id,
  36. 'name' => $this->name,
  37. 'email' => $this->email,
  38. 'document' => $this->document,
  39. 'type' => $this->type,
  40. 'status' => $this->status,
  41. 'default_bank_account' => $this->defaultBankAccount?->toArray(),
  42. 'created_at' => $this->createdAt,
  43. 'updated_at' => $this->updatedAt,
  44. ];
  45. }
  46. }