PagarmeRecipientResponseData.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Data\Pagarme\Response\PagarmeRecipientResponseData;
  3. 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 static function fromArray(array $payload): self
  17. {
  18. return new self(
  19. id: $payload['id'] ?? null,
  20. name: $payload['name'] ?? null,
  21. email: $payload['email'] ?? null,
  22. document: $payload['document'] ?? null,
  23. type: $payload['type'] ?? null,
  24. status: $payload['status'] ?? null,
  25. defaultBankAccount: ! empty($payload['default_bank_account'])
  26. ? PagarmeRecipientBankAccountResponseData::fromArray($payload['default_bank_account'])
  27. : null,
  28. createdAt: $payload['created_at'] ?? null,
  29. updatedAt: $payload['updated_at'] ?? null,
  30. );
  31. }
  32. public function id(): ?string
  33. {
  34. return $this->id;
  35. }
  36. public function defaultBankAccount(): ?PagarmeRecipientBankAccountResponseData
  37. {
  38. return $this->defaultBankAccount;
  39. }
  40. public function toArray(): array
  41. {
  42. return [
  43. 'id' => $this->id,
  44. 'name' => $this->name,
  45. 'email' => $this->email,
  46. 'document' => $this->document,
  47. 'type' => $this->type,
  48. 'status' => $this->status,
  49. 'default_bank_account' => $this->defaultBankAccount?->toArray(),
  50. 'created_at' => $this->createdAt,
  51. 'updated_at' => $this->updatedAt,
  52. ];
  53. }
  54. }