Quellcode durchsuchen

refactor: remove fromArray

Gustavo Mantovani vor 1 Woche
Ursprung
Commit
9789918417
26 geänderte Dateien mit 554 neuen und 620 gelöschten Zeilen
  1. 0 53
      app/Data/Pagarme/Request/PagarmeBankAccountUpdateRequestData.php
  2. 0 18
      app/Data/Pagarme/Request/PagarmeCustomerRequestData/PagarmeCustomerAddressRequestData.php
  3. 0 25
      app/Data/Pagarme/Request/PagarmeCustomerRequestData/PagarmeCustomerPhonesRequestData/PagarmeCustomerPhonesRequestData.php
  4. 0 22
      app/Data/Pagarme/Request/PagarmeCustomerRequestData/PagarmeCustomerRequestData.php
  5. 0 10
      app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderItemData.php
  6. 0 49
      app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderRequestData.php
  7. 0 53
      app/Data/Pagarme/Request/PagarmeRecipientRequestData/PagarmeRecipientBankAccountData.php
  8. 0 119
      app/Data/Pagarme/Request/PagarmeRecipientRequestData/PagarmeRecipientRequestData.php
  9. 0 19
      app/Data/Pagarme/Response/PagarmeCardResponseData.php
  10. 0 20
      app/Data/Pagarme/Response/PagarmeCustomerResponseData/PagarmeCustomerAddressResponseData.php
  11. 0 8
      app/Data/Pagarme/Response/PagarmeCustomerResponseData/PagarmeCustomerPhonesResponseData/PagarmeCustomerPhonesResponseData.php
  12. 0 13
      app/Data/Pagarme/Response/PagarmeCustomerResponseData/PagarmeCustomerPhonesResponseData/PagarmePhoneResponseData.php
  13. 0 20
      app/Data/Pagarme/Response/PagarmeCustomerResponseData/PagarmeCustomerResponseData.php
  14. 6 24
      app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderChargeResponseData/PagarmeOrderChargeResponseData.php
  15. 0 14
      app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderChargeResponseData/PagarmeOrderTransactionResponseData.php
  16. 0 9
      app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderCheckoutResponseData.php
  17. 0 14
      app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderItemResponseData.php
  18. 0 38
      app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderResponseData.php
  19. 0 15
      app/Data/Pagarme/Response/PagarmeRecipientResponseData/PagarmeRecipientBankAccountResponseData.php
  20. 0 19
      app/Data/Pagarme/Response/PagarmeRecipientResponseData/PagarmeRecipientResponseData.php
  21. 0 17
      app/Data/Pagarme/Response/PagarmeTransferResponseData.php
  22. 23 2
      app/Services/Pagarme/PagarmeCardService.php
  23. 130 14
      app/Services/Pagarme/PagarmeCustomerService.php
  24. 148 16
      app/Services/Pagarme/PagarmePaymentService.php
  25. 229 8
      app/Services/Pagarme/PagarmeRecipientService.php
  26. 18 1
      app/Services/ProviderWithdrawalService.php

+ 0 - 53
app/Data/Pagarme/Request/PagarmeBankAccountUpdateRequestData.php

@@ -3,7 +3,6 @@
 namespace App\Data\Pagarme\Request;
 
 use App\Data\Pagarme\PagarmeData;
-use Illuminate\Support\Str;
 
 final readonly class PagarmeBankAccountUpdateRequestData extends PagarmeData
 {
@@ -28,21 +27,6 @@ final readonly class PagarmeBankAccountUpdateRequestData extends PagarmeData
         self::requireFilled($this->type, 'bank_account.type');
     }
 
-    public static function fromArray(array $payload): self
-    {
-        return new self(
-            holderName:        self::normalizeHolderName($payload['holder_name']),
-            holderType:        $payload['holder_type'],
-            holderDocument:    self::digits($payload['holder_document']),
-            bank:              $payload['bank'],
-            branchNumber:      $payload['branch_number'],
-            branchCheckDigit:  $payload['branch_check_digit'] ?? null,
-            accountNumber:     $payload['account_number'],
-            accountCheckDigit: $payload['account_check_digit'],
-            type:              $payload['type'],
-        );
-    }
-
     public function toArray(): array
     {
         return $this->filterFilledRecursive([
@@ -59,41 +43,4 @@ final readonly class PagarmeBankAccountUpdateRequestData extends PagarmeData
             ],
         ]);
     }
-
-    //
-
-    private static function normalizeHolderName(string $holderName): string
-    {
-        $holderName = trim(preg_replace('/\s+/', ' ', $holderName) ?? '');
-
-        if (Str::length($holderName) < 30) {
-            return $holderName;
-        }
-
-        $parts = explode(' ', $holderName);
-
-        if (count($parts) >= 3) {
-            $firstName = array_shift($parts);
-            $lastName  = array_pop($parts);
-
-            $initials = array_map(
-                static fn (string $part): string => Str::upper(Str::substr($part, 0, 1)),
-                $parts
-            );
-
-            $abbreviated = trim($firstName.' '.implode(' ', $initials).' '.$lastName);
-
-            if (Str::length($abbreviated) < 30) {
-                return $abbreviated;
-            }
-
-            $firstAndLast = trim($firstName.' '.$lastName);
-
-            if (Str::length($firstAndLast) < 30) {
-                return $firstAndLast;
-            }
-        }
-
-        return Str::limit($holderName, 29, '');
-    }
 }

+ 0 - 18
app/Data/Pagarme/Request/PagarmeCustomerRequestData/PagarmeCustomerAddressRequestData.php

@@ -15,24 +15,6 @@ final readonly class PagarmeCustomerAddressRequestData extends PagarmeData
         public ?string $country,
     ) {}
 
-    public static function fromPayload(array $data): self
-    {
-        $line1Parts = array_filter([
-            (string) ($data['number'] ?? '0'),
-            (string) ($data['address'] ?? ''),
-            (string) ($data['district'] ?? ''),
-        ], static fn ($value) => $value !== '');
-
-        return new self(
-            line1:   implode(', ', $line1Parts),
-            line2:   (string) ($data['complement'] ?? $data['instructions'] ?? ''),
-            zipCode: self::digits($data['zip_code'] ?? null),
-            city:    (string) ($data['city'] ?? ''),
-            state:   (string) ($data['state'] ?? ''),
-            country: (string) ($data['country'] ?? 'BR'),
-        );
-    }
-
     public function toArray(): array
     {
         return $this->filterFilledRecursive([

+ 0 - 25
app/Data/Pagarme/Request/PagarmeCustomerRequestData/PagarmeCustomerPhonesRequestData/PagarmeCustomerPhonesRequestData.php

@@ -10,31 +10,6 @@ final readonly class PagarmeCustomerPhonesRequestData extends PagarmeData
         public ?PagarmeCustomerPhoneData $mobilePhone = null,
     ) {}
 
-    public static function fromPhone(?string $phone): self
-    {
-        $digits = self::digits($phone);
-
-        if ($digits === '') {
-            return new self;
-        }
-
-        $areaCode = substr($digits, 0, 2);
-        $number   = substr($digits, 2);
-
-        if (strlen($digits) <= 2) {
-            $areaCode = '';
-            $number   = $digits;
-        }
-
-        return new self(
-            mobilePhone: new PagarmeCustomerPhoneData(
-                countryCode: '55',
-                areaCode:    $areaCode,
-                number:      $number,
-            ),
-        );
-    }
-
     public function toArray(): array
     {
         return $this->filterFilledRecursive([

+ 0 - 22
app/Data/Pagarme/Request/PagarmeCustomerRequestData/PagarmeCustomerRequestData.php

@@ -25,28 +25,6 @@ final readonly class PagarmeCustomerRequestData extends PagarmeData
         self::requireFilled($this->code, 'code');
     }
 
-    public static function fromPayload(
-        ?string $name,
-        ?string $email,
-        ?string $document,
-        string  $code,
-        array   $addressData = [],
-        ?string $phone       = null,
-    ): self {
-        $document = self::digits($document);
-
-        return new self(
-            name:         $name ?: 'Cliente',
-            email:        (string) $email,
-            document:     $document,
-            type:         strlen($document) === 14 ? 'company' : 'individual',
-            documentType: strlen($document) === 14 ? 'CNPJ' : 'CPF',
-            code:         $code,
-            address:      PagarmeCustomerAddressRequestData::fromPayload($addressData),
-            phones:       PagarmeCustomerPhonesRequestData::fromPhone($phone),
-        );
-    }
-
     public function toArray(): array
     {
         return $this->filterFilledRecursive([

+ 0 - 10
app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderItemData.php

@@ -17,16 +17,6 @@ final readonly class PagarmeOrderItemData extends PagarmeData
         self::requirePositiveInt($this->quantity, 'items.quantity');
     }
 
-    public static function fromArray(array $item): self
-    {
-        return new self(
-            code:        (string) $item['code'],
-            amount:      (int) $item['amount'],
-            quantity:    (int) $item['quantity'],
-            description: $item['description'] ?? null,
-        );
-    }
-
     public function toArray(): array
     {
         return $this->filterFilledRecursive([

+ 0 - 49
app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderRequestData.php

@@ -44,38 +44,6 @@ final readonly class PagarmeOrderRequestData extends PagarmeData
         }
     }
 
-    public static function fromOrderPayload(
-        string                  $code,
-        array                   $items,
-        PagarmeOrderPaymentData $paymentMethod,
-        array                   $metadata,
-        mixed                   $customerId = null,
-        bool                    $closed     = true,
-        ?string                 $channel    = null,
-        CustomerData            $customer,
-    ): self {
-        if (empty($items)) {
-            throw new \InvalidArgumentException('items nao pode estar vazio.');
-        }
-
-        $customerIdPayload = self::filled($customerId) ? (string) $customerId : null;
-
-        if (! $customerIdPayload && ! $customer) {
-            throw new \InvalidArgumentException('customer ou customer_id e obrigatorio.');
-        }
-
-        return new self(
-            code:       $code,
-            items:      self::validateItems($items),
-            payments:   [$paymentMethod],
-            metadata:   $metadata,
-            customerId: $customerIdPayload,
-            closed:     $closed,
-            channel:    $channel,
-            customer:   $customer,
-        );
-    }
-
     //
 
     public static function amountInCents(float $amount): int
@@ -139,21 +107,4 @@ final readonly class PagarmeOrderRequestData extends PagarmeData
             'customer'    => $this->customer,
         ]);
     }
-
-    //
-
-    private static function filled(mixed $value): bool
-    {
-        return $value !== null && $value !== '' && $value !== [];
-    }
-
-    private static function validateItems(array $items): array
-    {
-        return collect($items)
-            ->map(function (PagarmeOrderItemData $item) {
-                return $item;
-            })
-            ->values()
-            ->all();
-    }
 }

+ 0 - 53
app/Data/Pagarme/Request/PagarmeRecipientRequestData/PagarmeRecipientBankAccountData.php

@@ -3,7 +3,6 @@
 namespace App\Data\Pagarme\Request\PagarmeRecipientRequestData;
 
 use App\Data\Pagarme\PagarmeData;
-use Illuminate\Support\Str;
 
 final readonly class PagarmeRecipientBankAccountData extends PagarmeData
 {
@@ -28,21 +27,6 @@ final readonly class PagarmeRecipientBankAccountData extends PagarmeData
         self::requireFilled($this->type, 'type');
     }
 
-    public static function fromArray(array $payload): self
-    {
-        return new self(
-            holderName:        self::normalizeHolderName($payload['holder_name']),
-            holderType:        $payload['holder_type'],
-            holderDocument:    self::digits($payload['holder_document']),
-            bank:              $payload['bank'],
-            branchNumber:      $payload['branch_number'],
-            branchCheckDigit:  $payload['branch_check_digit'] ?? null,
-            accountNumber:     $payload['account_number'],
-            accountCheckDigit: $payload['account_check_digit'],
-            type:              $payload['type'],
-        );
-    }
-
     public function toArray(): array
     {
         return $this->filterFilledRecursive([
@@ -57,41 +41,4 @@ final readonly class PagarmeRecipientBankAccountData extends PagarmeData
             'type'                => $this->type,
         ]);
     }
-
-    //
-
-    private static function normalizeHolderName(string $holderName): string
-    {
-        $holderName = trim(preg_replace('/\s+/', ' ', $holderName) ?? '');
-
-        if (Str::length($holderName) < 30) {
-            return $holderName;
-        }
-
-        $parts = explode(' ', $holderName);
-
-        if (count($parts) >= 3) {
-            $firstName = array_shift($parts);
-            $lastName  = array_pop($parts);
-
-            $initials = array_map(
-                static fn (string $part): string => Str::upper(Str::substr($part, 0, 1)),
-                $parts
-            );
-
-            $abbreviated = trim($firstName.' '.implode(' ', $initials).' '.$lastName);
-
-            if (Str::length($abbreviated) < 30) {
-                return $abbreviated;
-            }
-
-            $firstAndLast = trim($firstName.' '.$lastName);
-
-            if (Str::length($firstAndLast) < 30) {
-                return $firstAndLast;
-            }
-        }
-
-        return Str::limit($holderName, 29, '');
-    }
 }

+ 0 - 119
app/Data/Pagarme/Request/PagarmeRecipientRequestData/PagarmeRecipientRequestData.php

@@ -3,11 +3,6 @@
 namespace App\Data\Pagarme\Request\PagarmeRecipientRequestData;
 
 use App\Data\Pagarme\PagarmeData;
-use App\Data\Pagarme\Request\PagarmeRecipientRequestData\PagarmeRecipientRegisterInformationData\PagarmeRecipientAddressData;
-use App\Data\Pagarme\Request\PagarmeRecipientRequestData\PagarmeRecipientRegisterInformationData\PagarmeRecipientPhoneNumbersData\PagarmeRecipientPhoneData;
-use App\Data\Pagarme\Request\PagarmeRecipientRequestData\PagarmeRecipientRegisterInformationData\PagarmeRecipientPhoneNumbersData\PagarmeRecipientPhoneNumbersData;
-use App\Data\Pagarme\Request\PagarmeRecipientRequestData\PagarmeRecipientRegisterInformationData\PagarmeRecipientRegisterInformationData;
-use Carbon\Carbon;
 
 final readonly class PagarmeRecipientRequestData extends PagarmeData
 {
@@ -21,54 +16,6 @@ final readonly class PagarmeRecipientRequestData extends PagarmeData
         self::requireFilled($this->code, 'code');
     }
 
-    public static function fromPayload(string $code, array $data): self
-    {
-        $addressParts = self::extractAddressParts($data);
-
-        return new self(
-            code: $code,
-
-            registerInformation: new PagarmeRecipientRegisterInformationData(
-                name:                   $data['recipient_name'],
-                email:                  $data['recipient_email'],
-                document:               self::digits($data['recipient_document'] ?? null),
-                type:                   $data['recipient_type'] ?? 'individual',
-                birthdate:              self::formatBirthdate($data['birth_date'] ?? null),
-                monthlyIncome:          isset($data['monthly_income']) ? (int) $data['monthly_income'] : 1000,
-                professionalOccupation: $data['professional_occupation'] ?? 'autonomo',
-
-                phoneNumbers: new PagarmeRecipientPhoneNumbersData(
-                    self::phoneFromPayload($data['phone'] ?? null),
-                ),
-
-                address: new PagarmeRecipientAddressData(
-                    street:         $data['address'],
-                    complementary:  $addressParts['complementary'],
-                    streetNumber:   $addressParts['street_number'],
-                    neighborhood:   $addressParts['neighborhood'],
-                    city:           $data['city'] ?? null,
-                    state:          $data['state'] ?? null,
-                    zipCode:        self::digits($data['zip_code'] ?? null),
-                    referencePoint: $addressParts['reference_point'],
-                ),
-            ),
-
-            defaultBankAccount: PagarmeRecipientBankAccountData::fromArray(
-                $data['recipient_default_bank_account'],
-            ),
-
-            transferSettings: new PagarmeRecipientTransferSettingsData(
-                transferEnabled:  false,
-                transferInterval: 'Daily',
-                transferDay:      0,
-            ),
-
-            automaticAnticipationSettings: new PagarmeRecipientAutomaticAnticipationSettingsData(
-                enabled: false,
-            ),
-        );
-    }
-
     public function toArray(): array
     {
         return $this->filterFilledRecursive([
@@ -79,70 +26,4 @@ final readonly class PagarmeRecipientRequestData extends PagarmeData
             'automatic_anticipation_settings' => $this->automaticAnticipationSettings,
         ]);
     }
-
-    //
-
-    private static function extractAddressParts(array $data): array
-    {
-        $addressLine   = trim((string) ($data['address'] ?? ''));
-        $segments      = array_map('trim', explode(',', $addressLine));
-        $streetSegment = $segments[0] ?? '';
-
-        if (($data['number'] ?? null) === null) {
-            preg_match('/^(\d+)/', $streetSegment, $matches);
-        }
-
-        return [
-            'street_number'   => (string) ($data['number'] ?? $matches[1] ?? 'S/N'),
-            'neighborhood'    => (string) ($data['district'] ?? $segments[1] ?? 'N/A'),
-            'reference_point' => (string) ($data['reference_point'] ?? 'N/A'),
-            'complementary'   => (string) ($data['complement'] ?? 'N/A'),
-        ];
-    }
-
-    private static function formatBirthdate(mixed $birthdate): ?string
-    {
-        if ($birthdate === null || $birthdate === '') {
-            return null;
-        }
-
-        if ($birthdate instanceof \DateTimeInterface) {
-            return Carbon::instance($birthdate)->format('d/m/Y');
-        }
-
-        $birthdate = trim((string) $birthdate);
-
-        if (preg_match('/^\d{2}\/\d{2}\/\d{4}$/', $birthdate) === 1) {
-            return $birthdate;
-        }
-
-        if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $birthdate) === 1) {
-            return Carbon::createFromFormat('Y-m-d', $birthdate)->format('d/m/Y');
-        }
-
-        return Carbon::parse($birthdate)->format('d/m/Y');
-    }
-
-    private static function phoneFromPayload(?string $phone): PagarmeRecipientPhoneData
-    {
-        $digits = self::digits($phone);
-
-        if (strlen($digits) < 10) {
-            return new PagarmeRecipientPhoneData(
-                ddd:    '11',
-                number: '999999999',
-                type:   'mobile',
-            );
-        }
-
-        if (str_starts_with($digits, '55')) {
-            $digits = substr($digits, 2);
-        }
-
-        return new PagarmeRecipientPhoneData(
-            ddd:    substr($digits, 0, 2),
-            number: substr($digits, 2),
-            type:   'mobile',
-        );
-    }
 }

+ 0 - 19
app/Data/Pagarme/Response/PagarmeCardResponseData.php

@@ -44,25 +44,6 @@ final readonly class PagarmeCardResponseData
 
     //
 
-    public static function fromArray(array $payload): self
-    {
-        return new self(
-            id:             $payload['id']               ?? null,
-            firstSixDigits: $payload['first_six_digits'] ?? null,
-            lastFourDigits: $payload['last_four_digits'] ?? null,
-            brand:          $payload['brand']            ?? null,
-            holderName:     $payload['holder_name']      ?? null,
-
-            expMonth:       isset($payload['exp_month']) ? (int) $payload['exp_month'] : null,
-            expYear:        isset($payload['exp_year'])  ? (int) $payload['exp_year']  : null,
-
-            status:         $payload['status']     ?? null,
-            type:           $payload['type']       ?? null,
-            createdAt:      $payload['created_at'] ?? null,
-            updatedAt:      $payload['updated_at'] ?? null,
-        );
-    }
-
     public function toArray(): array
     {
         return [

+ 0 - 20
app/Data/Pagarme/Response/PagarmeCustomerResponseData/PagarmeCustomerAddressResponseData.php

@@ -17,26 +17,6 @@ final readonly class PagarmeCustomerAddressResponseData
         public ?string $updatedAt = null,
     ) {}
 
-    public static function fromArray(?array $payload): ?self
-    {
-        if (empty($payload)) {
-            return null;
-        }
-
-        return new self(
-            id:        $payload['id']         ?? null,
-            line1:     $payload['line_1']     ?? null,
-            line2:     $payload['line_2']     ?? null,
-            zipCode:   $payload['zip_code']   ?? null,
-            city:      $payload['city']       ?? null,
-            state:     $payload['state']      ?? null,
-            country:   $payload['country']    ?? null,
-            status:    $payload['status']     ?? null,
-            createdAt: $payload['created_at'] ?? null,
-            updatedAt: $payload['updated_at'] ?? null,
-        );
-    }
-
     public function toArray(): array
     {
         return [

+ 0 - 8
app/Data/Pagarme/Response/PagarmeCustomerResponseData/PagarmeCustomerPhonesResponseData/PagarmeCustomerPhonesResponseData.php

@@ -9,14 +9,6 @@ final readonly class PagarmeCustomerPhonesResponseData
         public ?PagarmePhoneResponseData $mobilePhone,
     ) {}
 
-    public static function fromArray(?array $payload): self
-    {
-        return new self(
-            homePhone:   PagarmePhoneResponseData::fromArray($payload['home_phone'] ?? null),
-            mobilePhone: PagarmePhoneResponseData::fromArray($payload['mobile_phone'] ?? null),
-        );
-    }
-
     public function toArray(): array
     {
         return array_filter([

+ 0 - 13
app/Data/Pagarme/Response/PagarmeCustomerResponseData/PagarmeCustomerPhonesResponseData/PagarmePhoneResponseData.php

@@ -10,19 +10,6 @@ final readonly class PagarmePhoneResponseData
         public ?string $number,
     ) {}
 
-    public static function fromArray(?array $payload): ?self
-    {
-        if (empty($payload)) {
-            return null;
-        }
-
-        return new self(
-            countryCode: $payload['country_code'] ?? null,
-            areaCode:    $payload['area_code']    ?? null,
-            number:      $payload['number']       ?? null,
-        );
-    }
-
     public function toArray(): array
     {
         return [

+ 0 - 20
app/Data/Pagarme/Response/PagarmeCustomerResponseData/PagarmeCustomerResponseData.php

@@ -35,26 +35,6 @@ final readonly class PagarmeCustomerResponseData
         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 [

+ 6 - 24
app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderChargeResponseData/PagarmeOrderChargeResponseData.php

@@ -5,12 +5,12 @@ namespace App\Data\Pagarme\Response\PagarmeOrderResponseData\PagarmeOrderChargeR
 final readonly class PagarmeOrderChargeResponseData
 {
     public function __construct(
-        public ?string                              $id,
-        public ?string                              $status,
-        public ?int                                 $amount,
-        public ?string                              $currency,
-        public ?string                              $paidAt,
-        public ?string                              $createdAt,
+        public ?string                            $id,
+        public ?string                            $status,
+        public ?int                               $amount,
+        public ?string                            $currency,
+        public ?string                            $paidAt,
+        public ?string                            $createdAt,
         public ?PagarmeOrderTransactionResponseData $lastTransaction,
     ) {}
 
@@ -19,24 +19,6 @@ final readonly class PagarmeOrderChargeResponseData
         return $this->lastTransaction;
     }
 
-    public static function fromArray(array $payload): self
-    {
-        return new self(
-            id:     $payload['id']     ?? null,
-            status: $payload['status'] ?? null,
-
-            amount: isset($payload['amount']) ? (int) $payload['amount'] : null,
-
-            currency:  $payload['currency']   ?? null,
-            paidAt:    $payload['paid_at']    ?? null,
-            createdAt: $payload['created_at'] ?? null,
-
-            lastTransaction: ! empty($payload['last_transaction'])
-                ? PagarmeOrderTransactionResponseData::fromArray($payload['last_transaction'])
-                : null,
-        );
-    }
-
     public function toArray(): array
     {
         return array_filter([

+ 0 - 14
app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderChargeResponseData/PagarmeOrderTransactionResponseData.php

@@ -13,20 +13,6 @@ final readonly class PagarmeOrderTransactionResponseData
         public array   $gatewayResponse,
     ) {}
 
-    public static function fromArray(array $payload): self
-    {
-        return new self(
-            id:     $payload['id']     ?? null,
-            status: $payload['status'] ?? null,
-
-            amount: isset($payload['amount']) ? (int) $payload['amount'] : null,
-
-            createdAt:       $payload['created_at']       ?? null,
-            acquirerMessage: $payload['acquirer_message'] ?? null,
-            gatewayResponse: $payload['gateway_response'] ?? [],
-        );
-    }
-
     public function toArray(): array
     {
         return [

+ 0 - 9
app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderCheckoutResponseData.php

@@ -10,15 +10,6 @@ final readonly class PagarmeOrderCheckoutResponseData
         public ?string $url,
     ) {}
 
-    public static function fromArray(array $payload): self
-    {
-        return new self(
-            id:     $payload['id']     ?? null,
-            status: $payload['status'] ?? null,
-            url:    $payload['url']    ?? null,
-        );
-    }
-
     public function toArray(): array
     {
         return [

+ 0 - 14
app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderItemResponseData.php

@@ -13,20 +13,6 @@ final readonly class PagarmeOrderItemResponseData
         public ?string $status,
     ) {}
 
-    public static function fromArray(array $payload): self
-    {
-        return new self(
-            id:   $payload['id']   ?? null,
-            code: $payload['code'] ?? null,
-
-            amount:   isset($payload['amount'])   ? (int) $payload['amount']   : null,
-            quantity: isset($payload['quantity']) ? (int) $payload['quantity'] : null,
-
-            description: $payload['description'] ?? null,
-            status:      $payload['status']      ?? null,
-        );
-    }
-
     public function toArray(): array
     {
         return [

+ 0 - 38
app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderResponseData.php

@@ -172,44 +172,6 @@ final readonly class PagarmeOrderResponseData
 
     //
 
-    public static function fromArray(array $payload): self
-    {
-        return new self(
-            id:   $payload['id']   ?? null,
-            code: $payload['code'] ?? null,
-
-            amount: isset($payload['amount']) ? (int) $payload['amount'] : null,
-
-            currency: $payload['currency'] ?? null,
-            closed:   $payload['closed']   ?? null,
-            status:   $payload['status']   ?? null,
-
-            items: array_map(
-                static fn (array $item) => PagarmeOrderItemResponseData::fromArray($item),
-                $payload['items'] ?? [],
-            ),
-
-            customer: ! empty($payload['customer'])
-                ? PagarmeCustomerResponseData::fromArray($payload['customer'])
-                : null,
-
-            charges: array_map(
-                static fn (array $charge) => PagarmeOrderChargeResponseData::fromArray($charge),
-                $payload['charges'] ?? [],
-            ),
-
-            checkouts: array_map(
-                static fn (array $checkout) => PagarmeOrderCheckoutResponseData::fromArray($checkout),
-                $payload['checkouts'] ?? [],
-            ),
-
-            metadata:  $payload['metadata']   ?? [],
-            createdAt: $payload['created_at'] ?? null,
-            updatedAt: $payload['updated_at'] ?? null,
-            closedAt:  $payload['closed_at']  ?? null,
-        );
-    }
-
     public function toArray(): array
     {
         return [

+ 0 - 15
app/Data/Pagarme/Response/PagarmeRecipientResponseData/PagarmeRecipientBankAccountResponseData.php

@@ -16,21 +16,6 @@ final readonly class PagarmeRecipientBankAccountResponseData
         public ?string $type,
     ) {}
 
-    public static function fromArray(array $payload): self
-    {
-        return new self(
-            holderName:        $payload['holder_name']         ?? null,
-            holderType:        $payload['holder_type']         ?? null,
-            holderDocument:    $payload['holder_document']     ?? null,
-            bank:              $payload['bank']                ?? null,
-            branchNumber:      $payload['branch_number']       ?? null,
-            branchCheckDigit:  $payload['branch_check_digit']  ?? null,
-            accountNumber:     $payload['account_number']      ?? null,
-            accountCheckDigit: $payload['account_check_digit'] ?? null,
-            type:              $payload['type']                ?? null,
-        );
-    }
-
     public function toArray(): array
     {
         return [

+ 0 - 19
app/Data/Pagarme/Response/PagarmeRecipientResponseData/PagarmeRecipientResponseData.php

@@ -37,25 +37,6 @@ final readonly class PagarmeRecipientResponseData
 
     //
 
-    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 [

+ 0 - 17
app/Data/Pagarme/Response/PagarmeTransferResponseData.php

@@ -30,23 +30,6 @@ final readonly class PagarmeTransferResponseData
 
     //
 
-    public static function fromArray(array $payload): self
-    {
-        return new self(
-            id:                   $payload['id']                     ?? null,
-            amount:               $payload['amount']                 ?? null,
-            type:                 $payload['type']                   ?? null,
-            status:               $payload['status']                 ?? null,
-            fee:                  $payload['fee']                    ?? null,
-            fundingDate:          $payload['funding_date']           ?? null,
-            fundingEstimatedDate: $payload['funding_estimated_date'] ?? null,
-            bankAccount:          $payload['bank_account']           ?? null,
-            bankResponse:         $payload['bank_response']          ?? null,
-            createdAt:            $payload['created_at']             ?? $payload['date_created'] ?? null,
-            metadata:             $payload['metadata']               ?? null,
-        );
-    }
-
     public function toArray(): array
     {
         return [

+ 23 - 2
app/Services/Pagarme/PagarmeCardService.php

@@ -30,7 +30,7 @@ class PagarmeCardService
             []
         );
 
-        $cardData = PagarmeCardResponseData::fromArray($this->pagarmeRequest(
+        $raw = $this->pagarmeRequest(
             method: 'POST',
             path: "/customers/{$customerId}/cards",
 
@@ -50,7 +50,9 @@ class PagarmeCardService
 
             idempotencyKey: $this->idempotencyKey($paymentMethod),
             errorMessage: 'Erro ao salvar cartao no Pagar.me.',
-        ));
+        );
+
+        $cardData = $this->buildCardResponse($raw);
 
         $cardId = $cardData->requireId();
 
@@ -63,6 +65,25 @@ class PagarmeCardService
         return $cardId;
     }
 
+    //
+
+    private function buildCardResponse(array $raw): PagarmeCardResponseData
+    {
+        return new PagarmeCardResponseData(
+            id:             $raw['id']               ?? null,
+            firstSixDigits: $raw['first_six_digits'] ?? null,
+            lastFourDigits: $raw['last_four_digits'] ?? null,
+            brand:          $raw['brand']            ?? null,
+            holderName:     $raw['holder_name']      ?? null,
+            expMonth:       isset($raw['exp_month']) ? (int) $raw['exp_month'] : null,
+            expYear:        isset($raw['exp_year'])  ? (int) $raw['exp_year']  : null,
+            status:         $raw['status']     ?? null,
+            type:           $raw['type']       ?? null,
+            createdAt:      $raw['created_at'] ?? null,
+            updatedAt:      $raw['updated_at'] ?? null,
+        );
+    }
+
     // evita criacao duplicada de cartao
 
     private function idempotencyKey(ClientPaymentMethod $paymentMethod): string

+ 130 - 14
app/Services/Pagarme/PagarmeCustomerService.php

@@ -2,7 +2,13 @@
 
 namespace App\Services\Pagarme;
 
+use App\Data\Pagarme\Request\PagarmeCustomerRequestData\PagarmeCustomerAddressRequestData;
+use App\Data\Pagarme\Request\PagarmeCustomerRequestData\PagarmeCustomerPhonesRequestData\PagarmeCustomerPhoneData;
+use App\Data\Pagarme\Request\PagarmeCustomerRequestData\PagarmeCustomerPhonesRequestData\PagarmeCustomerPhonesRequestData;
 use App\Data\Pagarme\Request\PagarmeCustomerRequestData\PagarmeCustomerRequestData;
+use App\Data\Pagarme\Response\PagarmeCustomerResponseData\PagarmeCustomerAddressResponseData;
+use App\Data\Pagarme\Response\PagarmeCustomerResponseData\PagarmeCustomerPhonesResponseData\PagarmeCustomerPhonesResponseData;
+use App\Data\Pagarme\Response\PagarmeCustomerResponseData\PagarmeCustomerPhonesResponseData\PagarmePhoneResponseData;
 use App\Data\Pagarme\Response\PagarmeCustomerResponseData\PagarmeCustomerResponseData;
 use App\Models\Client;
 use App\Services\Pagarme\Concerns\SendsPagarmeRequests;
@@ -20,25 +26,36 @@ class PagarmeCustomerService
 
         $client->loadMissing('user');
 
-        $name = $client->user?->name ?? $data['name'] ?? 'Cliente';
+        $name  = $client->user?->name ?? $data['name'] ?? 'Cliente';
         $email = $client->user?->email ?? $data['email'] ?? null;
-
-        $code = $this->ensureCustomerCode($client);
-
-        $customerData = PagarmeCustomerResponseData::fromArray($this->pagarmeRequest(
+        $code  = $this->ensureCustomerCode($client);
+
+        $document    = $this->onlyDigits($client->document ?? $data['document'] ?? null);
+        $documentLen = strlen($document);
+
+        $address = $this->buildAddressData($data);
+        $phones  = $this->buildPhones($client->user?->phone ?? $data['phone'] ?? null);
+
+        $customerRequest = new PagarmeCustomerRequestData(
+            name:         $name,
+            email:        (string) $email,
+            document:     $document,
+            type:         $documentLen === 14 ? 'company' : 'individual',
+            documentType: $documentLen === 14 ? 'CNPJ' : 'CPF',
+            code:         $code,
+            address:      $address,
+            phones:       $phones,
+        );
+
+        $raw = $this->pagarmeRequest(
             method: 'POST',
             path: '/customers',
-            payload: PagarmeCustomerRequestData::fromPayload(
-                name: $name,
-                email: $email,
-                document: $client->document ?? $data['document'] ?? null,
-                code: $code,
-                addressData: $data,
-                phone: $client->user?->phone ?? $data['phone'] ?? null,
-            ),
+            payload: $customerRequest,
             idempotencyKey: $this->idempotencyKey($client->id),
             errorMessage: 'Erro ao criar cliente no Pagar.me.',
-        ));
+        );
+
+        $customerData = $this->buildCustomerResponse($raw);
 
         $customerId = $customerData->requireId();
 
@@ -50,6 +67,105 @@ class PagarmeCustomerService
         return $customerId;
     }
 
+    //
+
+    private function buildAddressData(array $data): PagarmeCustomerAddressRequestData
+    {
+        $line1Parts = array_filter([
+            (string) ($data['number'] ?? '0'),
+            (string) ($data['address'] ?? ''),
+            (string) ($data['district'] ?? ''),
+        ], static fn ($value) => $value !== '');
+
+        return new PagarmeCustomerAddressRequestData(
+            line1:   implode(', ', $line1Parts),
+            line2:   (string) ($data['complement'] ?? $data['instructions'] ?? ''),
+            zipCode: $this->onlyDigits($data['zip_code'] ?? null),
+            city:    (string) ($data['city'] ?? ''),
+            state:   (string) ($data['state'] ?? ''),
+            country: (string) ($data['country'] ?? 'BR'),
+        );
+    }
+
+    private function buildPhones(?string $phone): PagarmeCustomerPhonesRequestData
+    {
+        $digits = $this->onlyDigits($phone);
+
+        if ($digits === '') {
+            return new PagarmeCustomerPhonesRequestData;
+        }
+
+        $areaCode = substr($digits, 0, 2);
+        $number   = substr($digits, 2);
+
+        if (strlen($digits) <= 2) {
+            $areaCode = '';
+            $number   = $digits;
+        }
+
+        return new PagarmeCustomerPhonesRequestData(
+            mobilePhone: new PagarmeCustomerPhoneData(
+                countryCode: '55',
+                areaCode:    $areaCode,
+                number:      $number,
+            ),
+        );
+    }
+
+    private function buildCustomerResponse(array $raw): PagarmeCustomerResponseData
+    {
+        return new PagarmeCustomerResponseData(
+            id:           $raw['id']            ?? null,
+            name:         $raw['name']          ?? null,
+            email:        $raw['email']         ?? null,
+            code:         $raw['code']          ?? null,
+            document:     $raw['document']      ?? null,
+            documentType: $raw['document_type'] ?? null,
+            type:         $raw['type']          ?? null,
+            delinquent:   $raw['delinquent']    ?? null,
+
+            address: ! empty($raw['address'])
+                ? new PagarmeCustomerAddressResponseData(
+                    id:        $raw['address']['id']         ?? null,
+                    line1:     $raw['address']['line_1']     ?? null,
+                    line2:     $raw['address']['line_2']     ?? null,
+                    zipCode:   $raw['address']['zip_code']   ?? null,
+                    city:      $raw['address']['city']       ?? null,
+                    state:     $raw['address']['state']      ?? null,
+                    country:   $raw['address']['country']    ?? null,
+                    status:    $raw['address']['status']     ?? null,
+                    createdAt: $raw['address']['created_at'] ?? null,
+                    updatedAt: $raw['address']['updated_at'] ?? null,
+                )
+                : null,
+
+            phones: new PagarmeCustomerPhonesResponseData(
+                homePhone:   ! empty($raw['phones']['home_phone'])
+                    ? new PagarmePhoneResponseData(
+                        countryCode: $raw['phones']['home_phone']['country_code'] ?? null,
+                        areaCode:    $raw['phones']['home_phone']['area_code'] ?? null,
+                        number:      $raw['phones']['home_phone']['number'] ?? null,
+                    )
+                    : null,
+                mobilePhone: ! empty($raw['phones']['mobile_phone'])
+                    ? new PagarmePhoneResponseData(
+                        countryCode: $raw['phones']['mobile_phone']['country_code'] ?? null,
+                        areaCode:    $raw['phones']['mobile_phone']['area_code'] ?? null,
+                        number:      $raw['phones']['mobile_phone']['number'] ?? null,
+                    )
+                    : null,
+            ),
+
+            createdAt: $raw['created_at'] ?? null,
+            updatedAt: $raw['updated_at'] ?? null,
+        );
+    }
+
+    private function onlyDigits(?string $value): string
+    {
+        return preg_replace('/\D+/', '', (string) $value) ?? '';
+    }
+
     // evita criacao duplicada de customer
 
     private function idempotencyKey(int $clientId, string $suffix = 'customer'): string

+ 148 - 16
app/Services/Pagarme/PagarmePaymentService.php

@@ -8,6 +8,14 @@ use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData\Pag
 use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData\PagarmeOrderPaymentData;
 use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData\PagarmeOrderPixData;
 use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderRequestData;
+use App\Data\Pagarme\Response\PagarmeCustomerResponseData\PagarmeCustomerAddressResponseData;
+use App\Data\Pagarme\Response\PagarmeCustomerResponseData\PagarmeCustomerPhonesResponseData\PagarmeCustomerPhonesResponseData;
+use App\Data\Pagarme\Response\PagarmeCustomerResponseData\PagarmeCustomerPhonesResponseData\PagarmePhoneResponseData;
+use App\Data\Pagarme\Response\PagarmeCustomerResponseData\PagarmeCustomerResponseData;
+use App\Data\Pagarme\Response\PagarmeOrderResponseData\PagarmeOrderChargeResponseData\PagarmeOrderChargeResponseData;
+use App\Data\Pagarme\Response\PagarmeOrderResponseData\PagarmeOrderChargeResponseData\PagarmeOrderTransactionResponseData;
+use App\Data\Pagarme\Response\PagarmeOrderResponseData\PagarmeOrderCheckoutResponseData;
+use App\Data\Pagarme\Response\PagarmeOrderResponseData\PagarmeOrderItemResponseData;
 use App\Data\Pagarme\Response\PagarmeOrderResponseData\PagarmeOrderResponseData;
 use App\Enums\PaymentSplitStatusEnum;
 use App\Enums\PaymentStatusEnum;
@@ -67,29 +75,33 @@ class PagarmePaymentService
         PagarmeOrderPaymentData $paymentMethod,
         array $options = []
     ): array {
-        $requestData = PagarmeOrderRequestData::fromOrderPayload(
-            code: $this->ensurePaymentCode($payment),
-            items: $items,
-            customer: $customer,
-            paymentMethod: $paymentMethod,
-            metadata: array_merge([
-                'payment_id'  => (string) $payment->id,
-                'schedule_id' => (string) $payment->schedule_id,
-                'client_id'   => (string) $payment->client_id,
-                'provider_id' => (string) $payment->provider_id,
-            ], $options['metadata'] ?? []),
+        $metadata = array_merge([
+            'payment_id'  => (string) $payment->id,
+            'schedule_id' => (string) $payment->schedule_id,
+            'client_id'   => (string) $payment->client_id,
+            'provider_id' => (string) $payment->provider_id,
+        ], $options['metadata'] ?? []);
+
+        $requestData = new PagarmeOrderRequestData(
+            code:       $this->ensurePaymentCode($payment),
+            items:      $items,
+            payments:   [$paymentMethod],
+            metadata:   $metadata,
+            customer:   $customer,
             customerId: $options['customer_id'] ?? null,
-            closed: $options['closed'] ?? true,
-            channel: $options['channel'] ?? null,
+            closed:     $options['closed'] ?? true,
+            channel:    $options['channel'] ?? null,
         );
 
-        $order = PagarmeOrderResponseData::fromArray($this->pagarmeRequest(
+        $raw = $this->pagarmeRequest(
             method: 'POST',
             path: '/orders',
             payload: $requestData,
             idempotencyKey: $this->idempotencyKey($payment),
             errorMessage: 'Erro ao criar pedido de pagamento no Pagar.me.',
-        ));
+        );
+
+        $order = $this->buildOrderResponse($raw);
 
         $order->requireId();
 
@@ -120,7 +132,7 @@ class PagarmePaymentService
 
     public function applyGatewayResponseToPayment(Payment $payment, array $orderResponse): Payment
     {
-        $order = PagarmeOrderResponseData::fromArray($orderResponse);
+        $order = $this->buildOrderResponse($orderResponse);
         $newStatus = $order->paymentStatus();
         $failureCode = null;
         $failureMessage = null;
@@ -158,4 +170,124 @@ class PagarmePaymentService
 
         return $payment->fresh();
     }
+
+    //
+
+    private function buildOrderResponse(array $raw): PagarmeOrderResponseData
+    {
+        return new PagarmeOrderResponseData(
+            id:       $raw['id']   ?? null,
+            code:     $raw['code'] ?? null,
+            amount:   isset($raw['amount']) ? (int) $raw['amount'] : null,
+            currency: $raw['currency'] ?? null,
+            closed:   $raw['closed']   ?? null,
+            status:   $raw['status']   ?? null,
+
+            items: array_map(
+                fn (array $item) => new PagarmeOrderItemResponseData(
+                    id:          $item['id'] ?? null,
+                    code:        $item['code'] ?? null,
+                    amount:      isset($item['amount']) ? (int) $item['amount'] : null,
+                    quantity:    isset($item['quantity']) ? (int) $item['quantity'] : null,
+                    description: $item['description'] ?? null,
+                    status:      $item['status'] ?? null,
+                ),
+                $raw['items'] ?? [],
+            ),
+
+            customer: ! empty($raw['customer'])
+                ? $this->buildCustomerResponse($raw['customer'])
+                : null,
+
+            charges: array_map(
+                fn (array $charge) => $this->buildChargeResponse($charge),
+                $raw['charges'] ?? [],
+            ),
+
+            checkouts: array_map(
+                fn (array $checkout) => new PagarmeOrderCheckoutResponseData(
+                    id:     $checkout['id'] ?? null,
+                    status: $checkout['status'] ?? null,
+                    url:    $checkout['url'] ?? null,
+                ),
+                $raw['checkouts'] ?? [],
+            ),
+
+            metadata:  $raw['metadata']   ?? [],
+            createdAt: $raw['created_at'] ?? null,
+            updatedAt: $raw['updated_at'] ?? null,
+            closedAt:  $raw['closed_at']  ?? null,
+        );
+    }
+
+    private function buildChargeResponse(array $raw): PagarmeOrderChargeResponseData
+    {
+        return new PagarmeOrderChargeResponseData(
+            id:              $raw['id'] ?? null,
+            status:          $raw['status'] ?? null,
+            amount:          isset($raw['amount']) ? (int) $raw['amount'] : null,
+            currency:        $raw['currency'] ?? null,
+            paidAt:          $raw['paid_at'] ?? null,
+            createdAt:       $raw['created_at'] ?? null,
+            lastTransaction: ! empty($raw['last_transaction'])
+                ? new PagarmeOrderTransactionResponseData(
+                    id:              $raw['last_transaction']['id'] ?? null,
+                    status:          $raw['last_transaction']['status'] ?? null,
+                    amount:          isset($raw['last_transaction']['amount']) ? (int) $raw['last_transaction']['amount'] : null,
+                    createdAt:       $raw['last_transaction']['created_at'] ?? null,
+                    acquirerMessage: $raw['last_transaction']['acquirer_message'] ?? null,
+                    gatewayResponse: $raw['last_transaction']['gateway_response'] ?? [],
+                )
+                : null,
+        );
+    }
+
+    private function buildCustomerResponse(array $raw): PagarmeCustomerResponseData
+    {
+        return new PagarmeCustomerResponseData(
+            id:           $raw['id']            ?? null,
+            name:         $raw['name']          ?? null,
+            email:        $raw['email']         ?? null,
+            code:         $raw['code']          ?? null,
+            document:     $raw['document']      ?? null,
+            documentType: $raw['document_type'] ?? null,
+            type:         $raw['type']          ?? null,
+            delinquent:   $raw['delinquent']    ?? null,
+
+            address: ! empty($raw['address'])
+                ? new PagarmeCustomerAddressResponseData(
+                    id:        $raw['address']['id']         ?? null,
+                    line1:     $raw['address']['line_1']     ?? null,
+                    line2:     $raw['address']['line_2']     ?? null,
+                    zipCode:   $raw['address']['zip_code']   ?? null,
+                    city:      $raw['address']['city']       ?? null,
+                    state:     $raw['address']['state']      ?? null,
+                    country:   $raw['address']['country']    ?? null,
+                    status:    $raw['address']['status']     ?? null,
+                    createdAt: $raw['address']['created_at'] ?? null,
+                    updatedAt: $raw['address']['updated_at'] ?? null,
+                )
+                : null,
+
+            phones: new PagarmeCustomerPhonesResponseData(
+                homePhone:   ! empty($raw['phones']['home_phone'])
+                    ? new PagarmePhoneResponseData(
+                        countryCode: $raw['phones']['home_phone']['country_code'] ?? null,
+                        areaCode:    $raw['phones']['home_phone']['area_code'] ?? null,
+                        number:      $raw['phones']['home_phone']['number'] ?? null,
+                    )
+                    : null,
+                mobilePhone: ! empty($raw['phones']['mobile_phone'])
+                    ? new PagarmePhoneResponseData(
+                        countryCode: $raw['phones']['mobile_phone']['country_code'] ?? null,
+                        areaCode:    $raw['phones']['mobile_phone']['area_code'] ?? null,
+                        number:      $raw['phones']['mobile_phone']['number'] ?? null,
+                    )
+                    : null,
+            ),
+
+            createdAt: $raw['created_at'] ?? null,
+            updatedAt: $raw['updated_at'] ?? null,
+        );
+    }
 }

+ 229 - 8
app/Services/Pagarme/PagarmeRecipientService.php

@@ -3,10 +3,19 @@
 namespace App\Services\Pagarme;
 
 use App\Data\Pagarme\Request\PagarmeBankAccountUpdateRequestData;
+use App\Data\Pagarme\Request\PagarmeRecipientRequestData\PagarmeRecipientAddressData;
+use App\Data\Pagarme\Request\PagarmeRecipientRequestData\PagarmeRecipientAutomaticAnticipationSettingsData;
+use App\Data\Pagarme\Request\PagarmeRecipientRequestData\PagarmeRecipientBankAccountData;
+use App\Data\Pagarme\Request\PagarmeRecipientRequestData\PagarmeRecipientPhoneData;
+use App\Data\Pagarme\Request\PagarmeRecipientRequestData\PagarmeRecipientPhoneNumbersData;
+use App\Data\Pagarme\Request\PagarmeRecipientRequestData\PagarmeRecipientRegisterInformationData;
 use App\Data\Pagarme\Request\PagarmeRecipientRequestData\PagarmeRecipientRequestData;
+use App\Data\Pagarme\Request\PagarmeRecipientRequestData\PagarmeRecipientTransferSettingsData;
+use App\Data\Pagarme\Response\PagarmeRecipientResponseData\PagarmeRecipientBankAccountResponseData;
 use App\Data\Pagarme\Response\PagarmeRecipientResponseData\PagarmeRecipientResponseData;
 use App\Models\Provider;
 use App\Services\Pagarme\Concerns\SendsPagarmeRequests;
+use Carbon\Carbon;
 use Illuminate\Support\Str;
 
 class PagarmeRecipientService
@@ -19,19 +28,69 @@ class PagarmeRecipientService
             return $provider->recipient_id;
         }
 
-        $metadata = $data['recipient_metadata'] ?? [];
-        $paymentMode = $data['recipient_payment_mode'];
+        $metadata      = $data['recipient_metadata'] ?? [];
+        $paymentMode   = $data['recipient_payment_mode'];
         $recipientCode = $this->ensureRecipientCode($provider);
-        $payload = PagarmeRecipientRequestData::fromPayload($recipientCode, $data);
+
+        $addressParts = $this->extractAddressParts($data);
+
+        $registerInformation = new PagarmeRecipientRegisterInformationData(
+            name:                   $data['recipient_name'],
+            email:                  $data['recipient_email'],
+            document:               $this->onlyDigits($data['recipient_document'] ?? null),
+            type:                   $data['recipient_type'] ?? 'individual',
+            birthdate:              $this->formatBirthdate($data['birth_date'] ?? null),
+            monthlyIncome:          isset($data['monthly_income']) ? (int) $data['monthly_income'] : 1000,
+            professionalOccupation: $data['professional_occupation'] ?? 'autonomo',
+
+            phoneNumbers: new PagarmeRecipientPhoneNumbersData(
+                $this->buildRecipientPhone($data['phone'] ?? null),
+            ),
+
+            address: new PagarmeRecipientAddressData(
+                street:         $data['address'],
+                complementary:  $addressParts['complementary'],
+                streetNumber:   $addressParts['street_number'],
+                neighborhood:   $addressParts['neighborhood'],
+                city:           $data['city'] ?? null,
+                state:          $data['state'] ?? null,
+                zipCode:        $this->onlyDigits($data['zip_code'] ?? null),
+                referencePoint: $addressParts['reference_point'],
+            ),
+        );
+
+        $defaultBankAccount = $this->buildRecipientBankAccount(
+            $data['recipient_default_bank_account'],
+        );
+
+        $payload = new PagarmeRecipientRequestData(
+            code: $recipientCode,
+
+            registerInformation: $registerInformation,
+            defaultBankAccount:  $defaultBankAccount,
+
+            transferSettings: new PagarmeRecipientTransferSettingsData(
+                transferEnabled:  false,
+                transferInterval: 'Daily',
+                transferDay:      0,
+            ),
+
+            automaticAnticipationSettings: new PagarmeRecipientAutomaticAnticipationSettingsData(
+                enabled: false,
+            ),
+        );
+
         $bankAccountData = $payload->defaultBankAccount->toArray();
 
-        $recipientData = PagarmeRecipientResponseData::fromArray($this->pagarmeRequest(
+        $raw = $this->pagarmeRequest(
             method: 'POST',
             path: '/recipients',
             payload: $payload,
             idempotencyKey: $this->idempotencyKey($provider->id),
             errorMessage: 'Erro ao criar recebedor no Pagar.me.',
-        ));
+        );
+
+        $recipientData = $this->buildRecipientResponse($raw);
 
         $recipientId = $recipientData->requireId();
 
@@ -64,15 +123,27 @@ class PagarmeRecipientService
 
     public function updateDefaultBankAccount(Provider $provider, array $bankAccountData): Provider
     {
-        $payload = PagarmeBankAccountUpdateRequestData::fromArray($bankAccountData);
+        $payload = new PagarmeBankAccountUpdateRequestData(
+            holderName:        $this->normalizeHolderName($bankAccountData['holder_name']),
+            holderType:        $bankAccountData['holder_type'],
+            holderDocument:    $this->onlyDigits($bankAccountData['holder_document']),
+            bank:              $bankAccountData['bank'],
+            branchNumber:      $bankAccountData['branch_number'],
+            branchCheckDigit:  $bankAccountData['branch_check_digit'] ?? null,
+            accountNumber:     $bankAccountData['account_number'],
+            accountCheckDigit: $bankAccountData['account_check_digit'],
+            type:              $bankAccountData['type'],
+        );
 
-        $recipientData = PagarmeRecipientResponseData::fromArray($this->pagarmeRequest(
+        $raw = $this->pagarmeRequest(
             method: 'PATCH',
             path: "/recipients/{$provider->recipient_id}/default-bank-account",
             payload: $payload,
             idempotencyKey: $this->idempotencyKey($provider->id, 'default-bank-account-'.sha1(json_encode($payload->toArray()))),
             errorMessage: 'Erro ao atualizar conta bancaria do recebedor no Pagar.me.',
-        ));
+        );
+
+        $recipientData = $this->buildRecipientResponse($raw);
 
         $provider->forceFill([
             'recipient_default_bank_account' => $recipientData->defaultBankAccount()?->toArray() ?: $payload->toArray()['bank_account'],
@@ -81,6 +152,156 @@ class PagarmeRecipientService
         return $provider->fresh();
     }
 
+    //
+
+    private function buildRecipientBankAccount(array $data): PagarmeRecipientBankAccountData
+    {
+        return new PagarmeRecipientBankAccountData(
+            holderName:        $this->normalizeHolderName($data['holder_name']),
+            holderType:        $data['holder_type'],
+            holderDocument:    $this->onlyDigits($data['holder_document']),
+            bank:              $data['bank'],
+            branchNumber:      $data['branch_number'],
+            branchCheckDigit:  $data['branch_check_digit'] ?? null,
+            accountNumber:     $data['account_number'],
+            accountCheckDigit: $data['account_check_digit'],
+            type:              $data['type'],
+        );
+    }
+
+    private function buildRecipientPhone(?string $phone): PagarmeRecipientPhoneData
+    {
+        $digits = $this->onlyDigits($phone);
+
+        if (strlen($digits) < 10) {
+            return new PagarmeRecipientPhoneData(
+                ddd:    '11',
+                number: '999999999',
+                type:   'mobile',
+            );
+        }
+
+        if (str_starts_with($digits, '55')) {
+            $digits = substr($digits, 2);
+        }
+
+        return new PagarmeRecipientPhoneData(
+            ddd:    substr($digits, 0, 2),
+            number: substr($digits, 2),
+            type:   'mobile',
+        );
+    }
+
+    private function extractAddressParts(array $data): array
+    {
+        $addressLine   = trim((string) ($data['address'] ?? ''));
+        $segments      = array_map('trim', explode(',', $addressLine));
+        $streetSegment = $segments[0] ?? '';
+
+        if (($data['number'] ?? null) === null) {
+            preg_match('/^(\d+)/', $streetSegment, $matches);
+        }
+
+        return [
+            'street_number'   => (string) ($data['number'] ?? $matches[1] ?? 'S/N'),
+            'neighborhood'    => (string) ($data['district'] ?? $segments[1] ?? 'N/A'),
+            'reference_point' => (string) ($data['reference_point'] ?? 'N/A'),
+            'complementary'   => (string) ($data['complement'] ?? 'N/A'),
+        ];
+    }
+
+    private function formatBirthdate(mixed $birthdate): ?string
+    {
+        if ($birthdate === null || $birthdate === '') {
+            return null;
+        }
+
+        if ($birthdate instanceof \DateTimeInterface) {
+            return Carbon::instance($birthdate)->format('d/m/Y');
+        }
+
+        $birthdate = trim((string) $birthdate);
+
+        if (preg_match('/^\d{2}\/\d{2}\/\d{4}$/', $birthdate) === 1) {
+            return $birthdate;
+        }
+
+        if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $birthdate) === 1) {
+            return Carbon::createFromFormat('Y-m-d', $birthdate)->format('d/m/Y');
+        }
+
+        return Carbon::parse($birthdate)->format('d/m/Y');
+    }
+
+    private function normalizeHolderName(string $holderName): string
+    {
+        $holderName = trim(preg_replace('/\s+/', ' ', $holderName) ?? '');
+
+        if (Str::length($holderName) < 30) {
+            return $holderName;
+        }
+
+        $parts = explode(' ', $holderName);
+
+        if (count($parts) >= 3) {
+            $firstName = array_shift($parts);
+            $lastName  = array_pop($parts);
+
+            $initials = array_map(
+                static fn (string $part): string => Str::upper(Str::substr($part, 0, 1)),
+                $parts
+            );
+
+            $abbreviated = trim($firstName.' '.implode(' ', $initials).' '.$lastName);
+
+            if (Str::length($abbreviated) < 30) {
+                return $abbreviated;
+            }
+
+            $firstAndLast = trim($firstName.' '.$lastName);
+
+            if (Str::length($firstAndLast) < 30) {
+                return $firstAndLast;
+            }
+        }
+
+        return Str::limit($holderName, 29, '');
+    }
+
+    private function buildRecipientResponse(array $raw): PagarmeRecipientResponseData
+    {
+        return new PagarmeRecipientResponseData(
+            id:       $raw['id']       ?? null,
+            name:     $raw['name']     ?? null,
+            email:    $raw['email']    ?? null,
+            document: $raw['document'] ?? null,
+            type:     $raw['type']     ?? null,
+            status:   $raw['status']   ?? null,
+
+            defaultBankAccount: ! empty($raw['default_bank_account'])
+                ? new PagarmeRecipientBankAccountResponseData(
+                    holderName:        $raw['default_bank_account']['holder_name']         ?? null,
+                    holderType:        $raw['default_bank_account']['holder_type']         ?? null,
+                    holderDocument:    $raw['default_bank_account']['holder_document']     ?? null,
+                    bank:              $raw['default_bank_account']['bank']                ?? null,
+                    branchNumber:      $raw['default_bank_account']['branch_number']       ?? null,
+                    branchCheckDigit:  $raw['default_bank_account']['branch_check_digit']  ?? null,
+                    accountNumber:     $raw['default_bank_account']['account_number']      ?? null,
+                    accountCheckDigit: $raw['default_bank_account']['account_check_digit'] ?? null,
+                    type:              $raw['default_bank_account']['type']                ?? null,
+                )
+                : null,
+
+            createdAt: $raw['created_at'] ?? null,
+            updatedAt: $raw['updated_at'] ?? null,
+        );
+    }
+
+    private function onlyDigits(?string $value): string
+    {
+        return preg_replace('/\D+/', '', (string) $value) ?? '';
+    }
+
     // evita criacao duplica de recipient
 
     private function idempotencyKey(int $providerId, string $suffix = 'recipient'): string

+ 18 - 1
app/Services/ProviderWithdrawalService.php

@@ -115,7 +115,7 @@ class ProviderWithdrawalService
                     $idempotencyKey,
                 );
 
-                $transfer = PagarmeTransferResponseData::fromArray($response);
+                $transfer = $this->buildTransferResponse($response);
 
                 $withdrawal->forceFill([
                     'transfer_id'        => $transfer->id(),
@@ -239,6 +239,23 @@ class ProviderWithdrawalService
             });
     }
 
+    private function buildTransferResponse(array $raw): PagarmeTransferResponseData
+    {
+        return new PagarmeTransferResponseData(
+            id:                   $raw['id']                     ?? null,
+            amount:               $raw['amount']                 ?? null,
+            type:                 $raw['type']                   ?? null,
+            status:               $raw['status']                 ?? null,
+            fee:                  $raw['fee']                    ?? null,
+            fundingDate:          $raw['funding_date']           ?? null,
+            fundingEstimatedDate: $raw['funding_estimated_date'] ?? null,
+            bankAccount:          $raw['bank_account']           ?? null,
+            bankResponse:         $raw['bank_response']          ?? null,
+            createdAt:            $raw['created_at']             ?? $raw['date_created'] ?? null,
+            metadata:             $raw['metadata']               ?? null,
+        );
+    }
+
     private function scheduleEndedAtExpression(): string
     {
         return match (DB::connection()->getDriverName()) {