| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace App\Data\Pagarme\Customer;
- use App\Data\Pagarme\PagarmeData;
- use App\Data\Pagarme\Customer\Parts\Request\AddressData;
- use App\Data\Pagarme\Customer\Parts\Request\PhonesData;
- final readonly class CustomerRequestData extends PagarmeData
- {
- public function __construct(
- public string $name,
- public string $email,
- public string $document,
- public string $type,
- public string $documentType,
- public string $code,
- public ?AddressData $address = null,
- public ?PhonesData $phones = null,
- ) {
- self::requireFilled($this->name, 'name');
- self::requireFilled($this->email, 'email');
- self::requireFilled($this->document, 'document');
- self::requireIn($this->type, ['individual', 'company'], 'type');
- self::requireIn($this->documentType, ['CPF', 'CNPJ', 'PASSPORT'], 'document_type');
- self::requireFilled($this->code, 'code');
- }
- public function toArray(): array
- {
- return $this->filterFilledRecursive([
- 'name' => $this->name,
- 'email' => $this->email,
- 'document' => $this->document,
- 'type' => $this->type,
- 'document_type' => $this->documentType,
- 'documents' => [
- [
- 'type' => $this->documentType,
- 'number' => $this->documentType === 'PASSPORT'
- ? $this->document
- : self::digits($this->document),
- ],
- ],
- 'code' => $this->code,
- 'address' => $this->address,
- 'phones' => $this->phones,
- ]);
- }
- }
|