Bladeren bron

refactor: alterando classes do pagarme

Gustavo Mantovani 1 week geleden
bovenliggende
commit
fc48e5f35c
37 gewijzigde bestanden met toevoegingen van 866 en 545 verwijderingen
  1. 17 18
      app/Data/Pagarme/Request/PagarmeBankAccountUpdateRequestData.php
  2. 10 11
      app/Data/Pagarme/Request/PagarmeCardRequestData/PagarmeCardBillingAddressData.php
  3. 2 2
      app/Data/Pagarme/Request/PagarmeCardRequestData/PagarmeCardRequestData.php
  4. 4 4
      app/Data/Pagarme/Request/PagarmeCustomerRequestData/PagarmeCustomerAddressRequestData.php
  5. 4 7
      app/Data/Pagarme/Request/PagarmeCustomerRequestData/PagarmeCustomerPhonesRequestData/PagarmeCustomerPhonesRequestData.php
  6. 17 17
      app/Data/Pagarme/Request/PagarmeCustomerRequestData/PagarmeCustomerRequestData.php
  7. 0 41
      app/Data/Pagarme/Request/PagarmeCustomerRequestData/PagarmeCustomerUpdateRequestData.php
  8. 39 0
      app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderItemData.php
  9. 27 0
      app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderPaymentData/PagarmeOrderCreditCardData.php
  10. 70 0
      app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderPaymentData/PagarmeOrderPaymentData.php
  11. 24 0
      app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderPaymentData/PagarmeOrderPixAdditionalInformationData.php
  12. 30 0
      app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderPaymentData/PagarmeOrderPixData.php
  13. 29 0
      app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderPaymentData/PagarmeOrderSplitData.php
  14. 23 0
      app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderPaymentData/PagarmeOrderSplitOptionsData.php
  15. 62 173
      app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderRequestData.php
  16. 17 18
      app/Data/Pagarme/Request/PagarmeRecipientRequestData/PagarmeRecipientBankAccountData.php
  17. 6 6
      app/Data/Pagarme/Request/PagarmeRecipientRequestData/PagarmeRecipientRegisterInformationData/PagarmeRecipientAddressData.php
  18. 8 8
      app/Data/Pagarme/Request/PagarmeRecipientRequestData/PagarmeRecipientRegisterInformationData/PagarmeRecipientRegisterInformationData.php
  19. 37 29
      app/Data/Pagarme/Request/PagarmeRecipientRequestData/PagarmeRecipientRequestData.php
  20. 2 2
      app/Data/Pagarme/Request/PagarmeRecipientRequestData/PagarmeRecipientTransferSettingsData.php
  21. 1 3
      app/Data/Pagarme/Request/PagarmeTransferRequestData.php
  22. 11 11
      app/Data/Pagarme/Response/PagarmeCardResponseData.php
  23. 8 8
      app/Data/Pagarme/Response/PagarmeCustomerResponseData/PagarmeCustomerAddressResponseData.php
  24. 1 1
      app/Data/Pagarme/Response/PagarmeCustomerResponseData/PagarmeCustomerPhonesResponseData/PagarmeCustomerPhonesResponseData.php
  25. 2 2
      app/Data/Pagarme/Response/PagarmeCustomerResponseData/PagarmeCustomerPhonesResponseData/PagarmePhoneResponseData.php
  26. 22 22
      app/Data/Pagarme/Response/PagarmeCustomerResponseData/PagarmeCustomerResponseData.php
  27. 50 0
      app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderChargeResponseData/PagarmeOrderChargeResponseData.php
  28. 39 0
      app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderChargeResponseData/PagarmeOrderTransactionResponseData.php
  29. 30 0
      app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderCheckoutResponseData.php
  30. 39 0
      app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderItemResponseData.php
  31. 112 69
      app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderResponseData.php
  32. 8 8
      app/Data/Pagarme/Response/PagarmeRecipientResponseData/PagarmeRecipientBankAccountResponseData.php
  33. 16 14
      app/Data/Pagarme/Response/PagarmeRecipientResponseData/PagarmeRecipientResponseData.php
  34. 15 15
      app/Data/Pagarme/Response/PagarmeTransferResponseData.php
  35. 11 6
      app/Services/Pagarme/PagarmePaymentService.php
  36. 71 49
      app/Services/PaymentService.php
  37. 2 1
      pint.json

+ 17 - 18
app/Data/Pagarme/Request/PagarmeBankAccountUpdateRequestData.php

@@ -8,15 +8,15 @@ use Illuminate\Support\Str;
 final readonly class PagarmeBankAccountUpdateRequestData extends PagarmeData
 {
     public function __construct(
-        public string $holderName,
-        public string $holderType,
-        public string $holderDocument,
-        public string $bank,
-        public string $branchNumber,
+        public string  $holderName,
+        public string  $holderType,
+        public string  $holderDocument,
+        public string  $bank,
+        public string  $branchNumber,
         public ?string $branchCheckDigit,
-        public string $accountNumber,
-        public string $accountCheckDigit,
-        public string $type,
+        public string  $accountNumber,
+        public string  $accountCheckDigit,
+        public string  $type,
     ) {
         self::requireFilled($this->holderName, 'bank_account.holder_name');
         self::requireIn($this->holderType, ['individual', 'company'], 'bank_account.holder_type');
@@ -31,15 +31,15 @@ final readonly class PagarmeBankAccountUpdateRequestData extends PagarmeData
     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'],
+            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'],
+            type:              $payload['type'],
         );
     }
 
@@ -74,8 +74,7 @@ final readonly class PagarmeBankAccountUpdateRequestData extends PagarmeData
 
         if (count($parts) >= 3) {
             $firstName = array_shift($parts);
-
-            $lastName = array_pop($parts);
+            $lastName  = array_pop($parts);
 
             $initials = array_map(
                 static fn (string $part): string => Str::upper(Str::substr($part, 0, 1)),

+ 10 - 11
app/Data/Pagarme/Request/PagarmeCardRequestData/PagarmeCardBillingAddressData.php

@@ -8,12 +8,12 @@ use App\Models\Address;
 final readonly class PagarmeCardBillingAddressData extends PagarmeData
 {
     public function __construct(
-        public string $line1,
+        public string  $line1,
         public ?string $line2,
-        public string $zipCode,
-        public string $city,
-        public string $state,
-        public string $country,
+        public string  $zipCode,
+        public string  $city,
+        public string  $state,
+        public string  $country,
     ) {
         self::requireFilled($this->line1, 'billing_address.line_1');
         self::requireFilled($this->zipCode, 'billing_address.zip_code');
@@ -25,8 +25,7 @@ final readonly class PagarmeCardBillingAddressData extends PagarmeData
     public static function fromAddress(?Address $address): self
     {
         $state = $address?->state?->code ?? $address?->city?->state?->code;
-
-        $city = $address?->city?->name;
+        $city  = $address?->city?->name;
 
         $line1 = implode(', ', array_filter([
             $address?->number ?: 'S/N',
@@ -35,11 +34,11 @@ final readonly class PagarmeCardBillingAddressData extends PagarmeData
         ]));
 
         return new self(
-            line1: $line1,
-            line2: $address?->complement ?: $address?->instructions,
+            line1:   $line1,
+            line2:   $address?->complement ?: $address?->instructions,
             zipCode: self::digits($address?->zip_code),
-            city: (string) $city,
-            state: (string) $state,
+            city:    (string) $city,
+            state:   (string) $state,
             country: 'BR',
         );
     }

+ 2 - 2
app/Data/Pagarme/Request/PagarmeCardRequestData/PagarmeCardRequestData.php

@@ -7,8 +7,8 @@ use App\Data\Pagarme\PagarmeData;
 final readonly class PagarmeCardRequestData extends PagarmeData
 {
     public function __construct(
-        public string $token,
-        public ?string $label = null,
+        public string                         $token,
+        public ?string                        $label          = null,
         public ?PagarmeCardBillingAddressData $billingAddress = null,
     ) {
         self::requireFilled($this->token, 'token');

+ 4 - 4
app/Data/Pagarme/Request/PagarmeCustomerRequestData/PagarmeCustomerAddressRequestData.php

@@ -24,11 +24,11 @@ final readonly class PagarmeCustomerAddressRequestData extends PagarmeData
         ], static fn ($value) => $value !== '');
 
         return new self(
-            line1: implode(', ', $line1Parts),
-            line2: (string) ($data['complement'] ?? $data['instructions'] ?? ''),
+            line1:   implode(', ', $line1Parts),
+            line2:   (string) ($data['complement'] ?? $data['instructions'] ?? ''),
             zipCode: self::digits($data['zip_code'] ?? null),
-            city: (string) ($data['city'] ?? ''),
-            state: (string) ($data['state'] ?? ''),
+            city:    (string) ($data['city'] ?? ''),
+            state:   (string) ($data['state'] ?? ''),
             country: (string) ($data['country'] ?? 'BR'),
         );
     }

+ 4 - 7
app/Data/Pagarme/Request/PagarmeCustomerRequestData/PagarmeCustomerPhonesRequestData/PagarmeCustomerPhonesRequestData.php

@@ -7,7 +7,6 @@ use App\Data\Pagarme\PagarmeData;
 final readonly class PagarmeCustomerPhonesRequestData extends PagarmeData
 {
     public function __construct(
-        public ?PagarmeCustomerPhoneData $homePhone = null,
         public ?PagarmeCustomerPhoneData $mobilePhone = null,
     ) {}
 
@@ -20,19 +19,18 @@ final readonly class PagarmeCustomerPhonesRequestData extends PagarmeData
         }
 
         $areaCode = substr($digits, 0, 2);
-
-        $number = substr($digits, 2);
+        $number   = substr($digits, 2);
 
         if (strlen($digits) <= 2) {
             $areaCode = '';
-            $number = $digits;
+            $number   = $digits;
         }
 
         return new self(
             mobilePhone: new PagarmeCustomerPhoneData(
                 countryCode: '55',
-                areaCode: $areaCode,
-                number: $number,
+                areaCode:    $areaCode,
+                number:      $number,
             ),
         );
     }
@@ -40,7 +38,6 @@ final readonly class PagarmeCustomerPhonesRequestData extends PagarmeData
     public function toArray(): array
     {
         return $this->filterFilledRecursive([
-            'home_phone'   => $this->homePhone,
             'mobile_phone' => $this->mobilePhone,
         ]);
     }

+ 17 - 17
app/Data/Pagarme/Request/PagarmeCustomerRequestData/PagarmeCustomerRequestData.php

@@ -8,14 +8,14 @@ use App\Data\Pagarme\Request\PagarmeCustomerRequestData\PagarmeCustomerPhonesReq
 final readonly class PagarmeCustomerRequestData extends PagarmeData
 {
     public function __construct(
-        public string $name,
-        public string $email,
-        public string $document,
-        public string $type,
-        public string $documentType,
-        public string $code,
+        public string                             $name,
+        public string                             $email,
+        public string                             $document,
+        public string                             $type,
+        public string                             $documentType,
+        public string                             $code,
         public ?PagarmeCustomerAddressRequestData $address = null,
-        public ?PagarmeCustomerPhonesRequestData $phones = null,
+        public ?PagarmeCustomerPhonesRequestData  $phones  = null,
     ) {
         self::requireFilled($this->name, 'name');
         self::requireFilled($this->email, 'email');
@@ -29,21 +29,21 @@ final readonly class PagarmeCustomerRequestData extends PagarmeData
         ?string $name,
         ?string $email,
         ?string $document,
-        string $code,
-        array $addressData = [],
-        ?string $phone = null,
+        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',
+            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),
+            code:         $code,
+            address:      PagarmeCustomerAddressRequestData::fromPayload($addressData),
+            phones:       PagarmeCustomerPhonesRequestData::fromPhone($phone),
         );
     }
 

+ 0 - 41
app/Data/Pagarme/Request/PagarmeCustomerRequestData/PagarmeCustomerUpdateRequestData.php

@@ -1,41 +0,0 @@
-<?php
-
-namespace App\Data\Pagarme\Request\PagarmeCustomerRequestData;
-
-use App\Data\Pagarme\PagarmeData;
-
-final readonly class PagarmeCustomerUpdateRequestData extends PagarmeData
-{
-    public function __construct(
-        public ?string $name = null,
-        public ?string $email = null,
-        public ?string $document = null,
-        public ?string $type = null,
-        public ?string $documentType = null,
-        public ?string $code = null,
-        public ?PagarmeCustomerAddressRequestData $address = null,
-        public ?PagarmeCustomerPhonesRequestData $phones = null,
-    ) {
-        if ($this->type !== null) {
-            self::requireIn($this->type, ['individual', 'company'], 'type');
-        }
-
-        if ($this->documentType !== null) {
-            self::requireIn($this->documentType, ['CPF', 'CNPJ'], 'document_type');
-        }
-    }
-
-    public function toArray(): array
-    {
-        return $this->filterFilledRecursive([
-            'name'          => $this->name,
-            'email'         => $this->email,
-            'document'      => $this->document,
-            'type'          => $this->type,
-            'document_type' => $this->documentType,
-            'code'          => $this->code,
-            'address'       => $this->address,
-            'phones'        => $this->phones,
-        ]);
-    }
-}

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

@@ -0,0 +1,39 @@
+<?php
+
+namespace App\Data\Pagarme\Request\PagarmeOrderRequestData;
+
+use App\Data\Pagarme\PagarmeData;
+
+final readonly class PagarmeOrderItemData extends PagarmeData
+{
+    public function __construct(
+        public string  $code,
+        public int     $amount,
+        public int     $quantity,
+        public ?string $description = null,
+    ) {
+        self::requireFilled($this->code, 'items.code');
+        self::requirePositiveInt($this->amount, 'items.amount');
+        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([
+            'code'        => $this->code,
+            'amount'      => $this->amount,
+            'quantity'    => $this->quantity,
+            'description' => $this->description,
+        ]);
+    }
+}

+ 27 - 0
app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderPaymentData/PagarmeOrderCreditCardData.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData;
+
+use App\Data\Pagarme\PagarmeData;
+
+final readonly class PagarmeOrderCreditCardData extends PagarmeData
+{
+    public function __construct(
+        public string  $cardId,
+        public ?int    $installments        = null,
+        public ?string $statementDescriptor = null,
+        public ?string $operationType       = null,
+    ) {
+        self::requireFilled($this->cardId, 'credit_card.card_id');
+    }
+
+    public function toArray(): array
+    {
+        return $this->filterFilledRecursive([
+            'card_id'              => $this->cardId,
+            'installments'         => $this->installments,
+            'statement_descriptor' => $this->statementDescriptor,
+            'operation_type'       => $this->operationType,
+        ]);
+    }
+}

+ 70 - 0
app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderPaymentData/PagarmeOrderPaymentData.php

@@ -0,0 +1,70 @@
+<?php
+
+namespace App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData;
+
+use App\Data\Pagarme\PagarmeData;
+
+final readonly class PagarmeOrderPaymentData extends PagarmeData
+{
+    /**
+     * @param  PagarmeOrderSplitData[]|null  $split
+     */
+    public function __construct(
+        public string                      $paymentMethod,
+        public ?PagarmeOrderCreditCardData $creditCard = null,
+        public ?PagarmeOrderPixData        $pix        = null,
+        public ?array                      $split      = null,
+    ) {
+        self::requireIn($this->paymentMethod, ['credit_card', 'pix'], 'payments.payment_method');
+
+        if ($this->paymentMethod === 'credit_card' && ! $this->creditCard) {
+            throw new \InvalidArgumentException('payments.credit_card e obrigatorio para credit_card.');
+        }
+
+        if ($this->paymentMethod === 'pix' && ! $this->pix) {
+            throw new \InvalidArgumentException('payments.pix e obrigatorio para pix.');
+        }
+    }
+
+    /**
+     * @param  PagarmeOrderSplitData[]|null  $split
+     */
+    public static function creditCard(PagarmeOrderCreditCardData $creditCard, ?array $split = null): self
+    {
+        return new self(
+            paymentMethod: 'credit_card',
+            creditCard:    $creditCard,
+            split:         $split,
+        );
+    }
+
+    /**
+     * @param  PagarmeOrderSplitData[]|null  $split
+     */
+    public static function pix(PagarmeOrderPixData $pix, ?array $split = null): self
+    {
+        return new self(
+            paymentMethod: 'pix',
+            pix:           $pix,
+            split:         $split,
+        );
+    }
+
+    public function toArray(): array
+    {
+        $payload = $this->filterFilledRecursive([
+            'payment_method' => $this->paymentMethod,
+            'split'          => $this->split,
+        ]);
+
+        if ($this->creditCard) {
+            $payload['credit_card'] = $this->creditCard->toArray();
+        }
+
+        if ($this->pix) {
+            $payload['pix'] = $this->pix->toArray();
+        }
+
+        return $payload;
+    }
+}

+ 24 - 0
app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderPaymentData/PagarmeOrderPixAdditionalInformationData.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData;
+
+use App\Data\Pagarme\PagarmeData;
+
+final readonly class PagarmeOrderPixAdditionalInformationData extends PagarmeData
+{
+    public function __construct(
+        public string $name,
+        public string $value,
+    ) {
+        self::requireFilled($this->name, 'additional_information.name');
+        self::requireFilled($this->value, 'additional_information.value');
+    }
+
+    public function toArray(): array
+    {
+        return $this->filterFilledRecursive([
+            'name'  => $this->name,
+            'value' => $this->value,
+        ]);
+    }
+}

+ 30 - 0
app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderPaymentData/PagarmeOrderPixData.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData;
+
+use App\Data\Pagarme\PagarmeData;
+
+final readonly class PagarmeOrderPixData extends PagarmeData
+{
+    /**
+     * @param  PagarmeOrderPixAdditionalInformationData[]|null  $additionalInformation
+     */
+    public function __construct(
+        public ?int   $expiresIn             = null,
+        public ?array $additionalInformation = null,
+    ) {
+        if ($this->expiresIn === null) {
+            throw new \InvalidArgumentException(
+                'pix.expires_in e obrigatorio.'
+            );
+        }
+    }
+
+    public function toArray(): array
+    {
+        return $this->filterFilledRecursive([
+            'expires_in'             => $this->expiresIn,
+            'additional_information' => $this->additionalInformation,
+        ]);
+    }
+}

+ 29 - 0
app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderPaymentData/PagarmeOrderSplitData.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData;
+
+use App\Data\Pagarme\PagarmeData;
+
+final readonly class PagarmeOrderSplitData extends PagarmeData
+{
+    public function __construct(
+        public int                           $amount,
+        public string                        $recipientId,
+        public string                        $type    = 'flat',
+        public ?PagarmeOrderSplitOptionsData $options = null,
+    ) {
+        self::requirePositiveInt($this->amount, 'split.amount');
+        self::requireFilled($this->recipientId, 'split.recipient_id');
+        self::requireFilled($this->type, 'split.type');
+    }
+
+    public function toArray(): array
+    {
+        return $this->filterFilledRecursive([
+            'amount'       => $this->amount,
+            'recipient_id' => $this->recipientId,
+            'type'         => $this->type,
+            'options'      => $this->options,
+        ]);
+    }
+}

+ 23 - 0
app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderPaymentData/PagarmeOrderSplitOptionsData.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData;
+
+use App\Data\Pagarme\PagarmeData;
+
+final readonly class PagarmeOrderSplitOptionsData extends PagarmeData
+{
+    public function __construct(
+        public bool $chargeProcessingFee = false,
+        public bool $chargeRemainderFee  = false,
+        public bool $liable              = false,
+    ) {}
+
+    public function toArray(): array
+    {
+        return $this->filterFilledRecursive([
+            'charge_processing_fee' => $this->chargeProcessingFee,
+            'charge_remainder_fee'  => $this->chargeRemainderFee,
+            'liable'                => $this->liable,
+        ]);
+    }
+}

+ 62 - 173
app/Data/Pagarme/Request/PagarmeOrderRequestData/PagarmeOrderRequestData.php

@@ -3,26 +3,31 @@
 namespace App\Data\Pagarme\Request\PagarmeOrderRequestData;
 
 use App\Data\Pagarme\PagarmeData;
+use App\Data\Pagarme\Request\PagarmeCustomerRequestData\PagarmeCustomerRequestData as CustomerData;
+use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData\PagarmeOrderCreditCardData;
+use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData\PagarmeOrderPaymentData;
+use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData\PagarmeOrderPixData;
+use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData\PagarmeOrderSplitData;
+use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData\PagarmeOrderSplitOptionsData;
 use App\Models\PaymentSplit;
 use Illuminate\Support\Collection;
 
-/**
- * @param  array<int, array{code?: string, amount?: int, quantity?: int, description?: string, ...}>  $items  Lista de itens do pedido
- * @param  array<int, array{payment_method: string, ...}>  $payments  Lista de formas de pagamento
- * @param  array<string, mixed>  $metadata  Metadados do pedido (ex: payment_id, schedule_id, client_id, provider_id)
- * @param  array<string, mixed>|null  $customer  Dados do cliente (name, email, document, type, etc.)
- */
 final readonly class PagarmeOrderRequestData extends PagarmeData
 {
+    /**
+     * @param  PagarmeOrderItemData[]  $items
+     * @param  PagarmeOrderPaymentData[]  $payments
+     */
     public function __construct(
-        public string $code,
-        public array $items,
-        public array $payments,
-        public array $metadata,
-        public ?array $customer = null,
+        public string  $code,
+        public array   $items,
+        public array   $payments,
+        public array   $metadata,
         public ?string $customerId = null,
-        public bool $closed = true,
-        public ?string $channel = null,
+        public ?string $channel    = null,
+        public bool    $closed     = true,
+
+        public ?CustomerData $customer = null,
     ) {
         self::requireFilled($this->code, 'code');
 
@@ -34,58 +39,40 @@ final readonly class PagarmeOrderRequestData extends PagarmeData
             throw new \InvalidArgumentException('payments nao pode estar vazio.');
         }
 
-        foreach ($this->payments as $index => $payment) {
-            if (! is_array($payment) || empty($payment['payment_method'])) {
-                throw new \InvalidArgumentException("payments.{$index}.payment_method e obrigatorio.");
-            }
-
-            self::requireIn($payment['payment_method'], ['credit_card', 'pix'], "payments.{$index}.payment_method");
-        }
-
-        if (! $this->customerId && empty($this->customer)) {
+        if (! $this->customerId && ! $this->customer) {
             throw new \InvalidArgumentException('customer ou customer_id e obrigatorio.');
         }
     }
 
     public static function fromOrderPayload(
-        string $code,
-        array $items,
-        array $customer,
-        array $paymentMethod,
-        array $metadata,
-        mixed $customerId = null,
-        bool $closed = true,
-        ?string $channel = null,
+        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.');
         }
 
-        if (empty($paymentMethod['payment_method'])) {
-            throw new \InvalidArgumentException('payment_method e obrigatorio.');
-        }
-
-        if (! in_array($paymentMethod['payment_method'], ['credit_card', 'pix'], true)) {
-            throw new \InvalidArgumentException('payment_method deve ser credit_card ou pix.');
-        }
-
         $customerIdPayload = self::filled($customerId) ? (string) $customerId : null;
 
-        $customerPayload = self::filterFilledRecursiveStatic($customer);
-
-        if (! $customerIdPayload && empty($customerPayload)) {
+        if (! $customerIdPayload && ! $customer) {
             throw new \InvalidArgumentException('customer ou customer_id e obrigatorio.');
         }
 
         return new self(
-            code: $code,
-            items: self::validateItems($items),
-            payments: [self::filterFilledRecursiveStatic($paymentMethod)],
-            metadata: $metadata,
-            customer: ! empty($customerPayload) ? $customerPayload : null,
+            code:       $code,
+            items:      self::validateItems($items),
+            payments:   [$paymentMethod],
+            metadata:   $metadata,
             customerId: $customerIdPayload,
-            closed: $closed,
-            channel: $channel,
+            closed:     $closed,
+            channel:    $channel,
+            customer:   $customer,
         );
     }
 
@@ -96,38 +83,41 @@ final readonly class PagarmeOrderRequestData extends PagarmeData
         return (int) round($amount * 100);
     }
 
-    public static function creditCardPaymentMethod(array $creditCard, ?array $split = null): array
+    /**
+     * @param  PagarmeOrderSplitData[]|null  $split
+     */
+    public static function creditCardPaymentMethod(PagarmeOrderCreditCardData $creditCard, ?array $split = null): PagarmeOrderPaymentData
     {
-        return self::paymentMethodWithOptionalSplit([
-            'payment_method' => 'credit_card',
-            'credit_card'    => self::buildCreditCardPayload($creditCard),
-        ], $split);
+        return PagarmeOrderPaymentData::creditCard($creditCard, $split);
     }
 
-    public static function pixPaymentMethod(array $pix, ?array $split = null): array
+    /**
+     * @param  PagarmeOrderSplitData[]|null  $split
+     */
+    public static function pixPaymentMethod(PagarmeOrderPixData $pix, ?array $split = null): PagarmeOrderPaymentData
     {
-        return self::paymentMethodWithOptionalSplit([
-            'payment_method' => 'pix',
-            'pix'            => self::buildPixPayload($pix),
-        ], $split);
+        return PagarmeOrderPaymentData::pix($pix, $split);
     }
 
+    /**
+     * @param  Collection<PaymentSplit>  $transfers
+     * @return PagarmeOrderSplitData[]
+     */
     public static function splitFromTransfers(Collection $transfers): array
     {
         return $transfers
             ->filter(fn (PaymentSplit $split) => ! empty($split->gateway_transfer_target_reference))
             ->map(function (PaymentSplit $split) {
-                return [
-                    'amount'       => self::amountInCents((float) $split->gross_amount),
-                    'recipient_id' => $split->gateway_transfer_target_reference,
-                    'type'         => 'flat',
-
-                    'options' => [
-                        'charge_processing_fee' => false,
-                        'charge_remainder_fee'  => false,
-                        'liable'                => false,
-                    ],
-                ];
+                return new PagarmeOrderSplitData(
+                    amount:      self::amountInCents((float) $split->gross_amount),
+                    recipientId: $split->gateway_transfer_target_reference,
+                    type:        'flat',
+                    options:     new PagarmeOrderSplitOptionsData(
+                        chargeProcessingFee: false,
+                        chargeRemainderFee:  false,
+                        liable:              false,
+                    ),
+                );
             })
             ->values()
             ->all();
@@ -144,124 +134,23 @@ final readonly class PagarmeOrderRequestData extends PagarmeData
             'closed'      => $this->closed,
             'metadata'    => $this->metadata,
             'customer_id' => $this->customerId,
-            'customer'    => $this->customer,
             'channel'     => $this->channel,
+            'customer'    => $this->customer,
         ]);
     }
 
     //
 
-    private static function buildCreditCardPayload(array $creditCard): array
-    {
-        $payload = [];
-
-        foreach ([
-            'installments',
-            'statement_descriptor',
-            'operation_type',
-            'recurrence_cycle',
-            'metadata',
-            'extended_limit_enabled',
-            'extended_limit_code',
-            'merchant_category_code',
-            'authentication',
-            'auto_recovery',
-            'payload',
-            'payment_type',
-            'funding_source',
-            'initiated_type',
-            'recurrence_model',
-            'channel',
-            'payment_origin',
-        ] as $field) {
-            if (array_key_exists($field, $creditCard) && self::filled($creditCard[$field])) {
-                $payload[$field] = $creditCard[$field];
-            }
-        }
-
-        $allowedCardOptions = ['card', 'card_id', 'card_token', 'network_token'];
-
-        $provided = array_values(array_filter(
-            $allowedCardOptions,
-            static fn (string $field) => ! empty($creditCard[$field])
-        ));
-
-        if (count($provided) !== 1) {
-            throw new \InvalidArgumentException('Informe exatamente uma opcao entre card, card_id, card_token ou network_token.');
-        }
-
-        $selected = $provided[0];
-
-        $payload[$selected] = $creditCard[$selected];
-
-        return $payload;
-    }
-
-    private static function buildPixPayload(array $pix): array
-    {
-        if (! self::filled($pix['expires_in'] ?? null) && ! self::filled($pix['expires_at'] ?? null)) {
-            throw new \InvalidArgumentException('pix.expires_in ou pix.expires_at e obrigatorio.');
-        }
-
-        $payload = [];
-
-        foreach (['expires_in', 'expires_at', 'additional_information'] as $field) {
-            if (array_key_exists($field, $pix) && self::filled($pix[$field])) {
-                $payload[$field] = $pix[$field];
-            }
-        }
-
-        return $payload;
-    }
-
-    //
-
     private static function filled(mixed $value): bool
     {
         return $value !== null && $value !== '' && $value !== [];
     }
 
-    private static function filterFilledRecursiveStatic(array $data): array
-    {
-        $filtered = [];
-
-        foreach ($data as $key => $value) {
-            if (is_array($value)) {
-                $value = self::filterFilledRecursiveStatic($value);
-            }
-
-            if (self::filled($value)) {
-                $filtered[$key] = $value;
-            }
-        }
-
-        return $filtered;
-    }
-
-    private static function paymentMethodWithOptionalSplit(array $paymentMethod, ?array $split): array
-    {
-        if (! empty($split)) {
-            $paymentMethod['split'] = $split;
-        }
-
-        return $paymentMethod;
-    }
-
     private static function validateItems(array $items): array
     {
         return collect($items)
-            ->map(function (array $item, int $index) {
-                foreach (['code', 'amount', 'quantity'] as $field) {
-                    if (! array_key_exists($field, $item) || ! self::filled($item[$field])) {
-                        throw new \InvalidArgumentException("items.{$index}.{$field} e obrigatorio.");
-                    }
-                }
-
-                if ((int) $item['amount'] <= 0 || (int) $item['quantity'] <= 0) {
-                    throw new \InvalidArgumentException("items.{$index}.amount e quantity devem ser maiores que zero.");
-                }
-
-                return self::filterFilledRecursiveStatic($item);
+            ->map(function (PagarmeOrderItemData $item) {
+                return $item;
             })
             ->values()
             ->all();

+ 17 - 18
app/Data/Pagarme/Request/PagarmeRecipientRequestData/PagarmeRecipientBankAccountData.php

@@ -8,15 +8,15 @@ use Illuminate\Support\Str;
 final readonly class PagarmeRecipientBankAccountData extends PagarmeData
 {
     public function __construct(
-        public string $holderName,
-        public string $holderType,
-        public string $holderDocument,
-        public string $bank,
-        public string $branchNumber,
+        public string  $holderName,
+        public string  $holderType,
+        public string  $holderDocument,
+        public string  $bank,
+        public string  $branchNumber,
         public ?string $branchCheckDigit,
-        public string $accountNumber,
-        public string $accountCheckDigit,
-        public string $type,
+        public string  $accountNumber,
+        public string  $accountCheckDigit,
+        public string  $type,
     ) {
         self::requireFilled($this->holderName, 'holder_name');
         self::requireIn($this->holderType, ['individual', 'company'], 'holder_type');
@@ -31,15 +31,15 @@ final readonly class PagarmeRecipientBankAccountData extends PagarmeData
     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'],
+            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'],
+            type:              $payload['type'],
         );
     }
 
@@ -72,8 +72,7 @@ final readonly class PagarmeRecipientBankAccountData extends PagarmeData
 
         if (count($parts) >= 3) {
             $firstName = array_shift($parts);
-
-            $lastName = array_pop($parts);
+            $lastName  = array_pop($parts);
 
             $initials = array_map(
                 static fn (string $part): string => Str::upper(Str::substr($part, 0, 1)),

+ 6 - 6
app/Data/Pagarme/Request/PagarmeRecipientRequestData/PagarmeRecipientRegisterInformationData/PagarmeRecipientAddressData.php

@@ -7,14 +7,14 @@ use App\Data\Pagarme\PagarmeData;
 final readonly class PagarmeRecipientAddressData extends PagarmeData
 {
     public function __construct(
-        public string $street,
-        public string $complementary,
-        public string $streetNumber,
-        public string $neighborhood,
+        public string  $street,
+        public string  $complementary,
+        public string  $streetNumber,
+        public string  $neighborhood,
         public ?string $city,
         public ?string $state,
-        public string $zipCode,
-        public string $referencePoint,
+        public string  $zipCode,
+        public string  $referencePoint,
     ) {
         self::requireFilled($this->street, 'register_information.address.street');
         self::requireFilled($this->streetNumber, 'register_information.address.street_number');

+ 8 - 8
app/Data/Pagarme/Request/PagarmeRecipientRequestData/PagarmeRecipientRegisterInformationData/PagarmeRecipientRegisterInformationData.php

@@ -8,15 +8,15 @@ use App\Data\Pagarme\Request\PagarmeRecipientRequestData\PagarmeRecipientRegiste
 final readonly class PagarmeRecipientRegisterInformationData extends PagarmeData
 {
     public function __construct(
-        public string $name,
-        public string $email,
-        public string $document,
-        public string $type,
-        public ?string $birthdate,
-        public int $monthlyIncome,
-        public string $professionalOccupation,
+        public string                           $name,
+        public string                           $email,
+        public string                           $document,
+        public string                           $type,
+        public ?string                          $birthdate,
+        public int                              $monthlyIncome,
+        public string                           $professionalOccupation,
         public PagarmeRecipientPhoneNumbersData $phoneNumbers,
-        public PagarmeRecipientAddressData $address,
+        public PagarmeRecipientAddressData      $address,
     ) {
         self::requireFilled($this->name, 'register_information.name');
         self::requireFilled($this->email, 'register_information.email');

+ 37 - 29
app/Data/Pagarme/Request/PagarmeRecipientRequestData/PagarmeRecipientRequestData.php

@@ -12,10 +12,10 @@ use Carbon\Carbon;
 final readonly class PagarmeRecipientRequestData extends PagarmeData
 {
     public function __construct(
-        public string $code,
-        public PagarmeRecipientRegisterInformationData $registerInformation,
-        public PagarmeRecipientBankAccountData $defaultBankAccount,
-        public PagarmeRecipientTransferSettingsData $transferSettings,
+        public string                                            $code,
+        public PagarmeRecipientRegisterInformationData           $registerInformation,
+        public PagarmeRecipientBankAccountData                   $defaultBankAccount,
+        public PagarmeRecipientTransferSettingsData              $transferSettings,
         public PagarmeRecipientAutomaticAnticipationSettingsData $automaticAnticipationSettings,
     ) {
         self::requireFilled($this->code, 'code');
@@ -27,32 +27,42 @@ final readonly class PagarmeRecipientRequestData extends PagarmeData
 
         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,
+                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)),
+
+                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),
+                    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']),
+
+            defaultBankAccount: PagarmeRecipientBankAccountData::fromArray(
+                $data['recipient_default_bank_account'],
+            ),
+
             transferSettings: new PagarmeRecipientTransferSettingsData(
-                transferEnabled: false,
+                transferEnabled:  false,
                 transferInterval: 'Daily',
-                transferDay: 0,
+                transferDay:      0,
             ),
+
             automaticAnticipationSettings: new PagarmeRecipientAutomaticAnticipationSettingsData(
                 enabled: false,
             ),
@@ -74,10 +84,8 @@ final readonly class PagarmeRecipientRequestData extends PagarmeData
 
     private static function extractAddressParts(array $data): array
     {
-        $addressLine = trim((string) ($data['address'] ?? ''));
-
-        $segments = array_map('trim', explode(',', $addressLine));
-
+        $addressLine   = trim((string) ($data['address'] ?? ''));
+        $segments      = array_map('trim', explode(',', $addressLine));
         $streetSegment = $segments[0] ?? '';
 
         if (($data['number'] ?? null) === null) {
@@ -121,9 +129,9 @@ final readonly class PagarmeRecipientRequestData extends PagarmeData
 
         if (strlen($digits) < 10) {
             return new PagarmeRecipientPhoneData(
-                ddd: '11',
+                ddd:    '11',
                 number: '999999999',
-                type: 'mobile',
+                type:   'mobile',
             );
         }
 
@@ -132,9 +140,9 @@ final readonly class PagarmeRecipientRequestData extends PagarmeData
         }
 
         return new PagarmeRecipientPhoneData(
-            ddd: substr($digits, 0, 2),
+            ddd:    substr($digits, 0, 2),
             number: substr($digits, 2),
-            type: 'mobile',
+            type:   'mobile',
         );
     }
 }

+ 2 - 2
app/Data/Pagarme/Request/PagarmeRecipientRequestData/PagarmeRecipientTransferSettingsData.php

@@ -7,9 +7,9 @@ use App\Data\Pagarme\PagarmeData;
 final readonly class PagarmeRecipientTransferSettingsData extends PagarmeData
 {
     public function __construct(
-        public bool $transferEnabled,
+        public bool   $transferEnabled,
         public string $transferInterval,
-        public int $transferDay,
+        public int    $transferDay,
     ) {
         self::requireIn($this->transferInterval, ['Daily', 'Weekly', 'Monthly'], 'transfer_interval');
 

+ 1 - 3
app/Data/Pagarme/Request/PagarmeTransferRequestData.php

@@ -7,9 +7,8 @@ use App\Data\Pagarme\PagarmeData;
 final readonly class PagarmeTransferRequestData extends PagarmeData
 {
     public function __construct(
-        public int $amount,
+        public int    $amount,
         public string $recipientId,
-        public ?array $metadata = null,
     ) {
         self::requirePositiveInt($this->amount, 'amount');
         self::requireFilled($this->recipientId, 'recipient_id');
@@ -20,7 +19,6 @@ final readonly class PagarmeTransferRequestData extends PagarmeData
         return $this->filterFilledRecursive([
             'amount'       => $this->amount,
             'recipient_id' => $this->recipientId,
-            'metadata'     => $this->metadata,
         ]);
     }
 }

+ 11 - 11
app/Data/Pagarme/Response/PagarmeCardResponseData.php

@@ -10,8 +10,8 @@ final readonly class PagarmeCardResponseData
         public ?string $lastFourDigits,
         public ?string $brand,
         public ?string $holderName,
-        public ?int $expMonth,
-        public ?int $expYear,
+        public ?int    $expMonth,
+        public ?int    $expYear,
         public ?string $status,
         public ?string $type,
         public ?string $createdAt = null,
@@ -47,17 +47,17 @@ final readonly class PagarmeCardResponseData
     public static function fromArray(array $payload): self
     {
         return new self(
-            id: $payload['id'] ?? null,
+            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,
+            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,
         );
     }
 

+ 8 - 8
app/Data/Pagarme/Response/PagarmeCustomerResponseData/PagarmeCustomerAddressResponseData.php

@@ -24,14 +24,14 @@ final readonly class PagarmeCustomerAddressResponseData
         }
 
         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,
+            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,
         );

+ 1 - 1
app/Data/Pagarme/Response/PagarmeCustomerResponseData/PagarmeCustomerPhonesResponseData/PagarmeCustomerPhonesResponseData.php

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

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

@@ -18,8 +18,8 @@ final readonly class PagarmePhoneResponseData
 
         return new self(
             countryCode: $payload['country_code'] ?? null,
-            areaCode: $payload['area_code'] ?? null,
-            number: $payload['number'] ?? null,
+            areaCode:    $payload['area_code']    ?? null,
+            number:      $payload['number']       ?? null,
         );
     }
 

+ 22 - 22
app/Data/Pagarme/Response/PagarmeCustomerResponseData/PagarmeCustomerResponseData.php

@@ -7,18 +7,18 @@ use App\Data\Pagarme\Response\PagarmeCustomerResponseData\PagarmeCustomerPhonesR
 final readonly class PagarmeCustomerResponseData
 {
     public function __construct(
-        public ?string $id,
-        public ?string $name,
-        public ?string $email,
-        public ?string $code,
-        public ?string $document,
-        public ?string $documentType,
-        public ?string $type,
-        public ?bool $delinquent,
+        public ?string                             $id,
+        public ?string                             $name,
+        public ?string                             $email,
+        public ?string                             $code,
+        public ?string                             $document,
+        public ?string                             $documentType,
+        public ?string                             $type,
+        public ?bool                               $delinquent,
         public ?PagarmeCustomerAddressResponseData $address,
-        public PagarmeCustomerPhonesResponseData $phones,
-        public ?string $createdAt = null,
-        public ?string $updatedAt = null,
+        public PagarmeCustomerPhonesResponseData   $phones,
+        public ?string                             $createdAt = null,
+        public ?string                             $updatedAt = null,
     ) {}
 
     public function id(): ?string
@@ -38,18 +38,18 @@ final readonly class PagarmeCustomerResponseData
     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,
+            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,
+            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,
         );
     }
 

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

@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Data\Pagarme\Response\PagarmeOrderResponseData\PagarmeOrderChargeResponseData;
+
+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 ?PagarmeOrderTransactionResponseData $lastTransaction,
+    ) {}
+
+    public function transaction(): ?PagarmeOrderTransactionResponseData
+    {
+        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([
+            'id'               => $this->id,
+            'status'           => $this->status,
+            'amount'           => $this->amount,
+            'currency'         => $this->currency,
+            'paid_at'          => $this->paidAt,
+            'created_at'       => $this->createdAt,
+            'last_transaction' => $this->lastTransaction?->toArray(),
+        ], static fn ($v) => $v !== null);
+    }
+}

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

@@ -0,0 +1,39 @@
+<?php
+
+namespace App\Data\Pagarme\Response\PagarmeOrderResponseData\PagarmeOrderChargeResponseData;
+
+final readonly class PagarmeOrderTransactionResponseData
+{
+    public function __construct(
+        public ?string $id,
+        public ?string $status,
+        public ?int    $amount,
+        public ?string $createdAt,
+        public ?string $acquirerMessage,
+        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 [
+            'id'               => $this->id,
+            'status'           => $this->status,
+            'amount'           => $this->amount,
+            'created_at'       => $this->createdAt,
+            'acquirer_message' => $this->acquirerMessage,
+            'gateway_response' => $this->gatewayResponse,
+        ];
+    }
+}

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

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Data\Pagarme\Response\PagarmeOrderResponseData;
+
+final readonly class PagarmeOrderCheckoutResponseData
+{
+    public function __construct(
+        public ?string $id,
+        public ?string $status,
+        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 [
+            'id'     => $this->id,
+            'status' => $this->status,
+            'url'    => $this->url,
+        ];
+    }
+}

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

@@ -0,0 +1,39 @@
+<?php
+
+namespace App\Data\Pagarme\Response\PagarmeOrderResponseData;
+
+final readonly class PagarmeOrderItemResponseData
+{
+    public function __construct(
+        public ?string $id,
+        public ?string $code,
+        public ?int    $amount,
+        public ?int    $quantity,
+        public ?string $description,
+        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 [
+            'id'          => $this->id,
+            'code'        => $this->code,
+            'amount'      => $this->amount,
+            'quantity'    => $this->quantity,
+            'description' => $this->description,
+            'status'      => $this->status,
+        ];
+    }
+}

+ 112 - 69
app/Data/Pagarme/Response/PagarmeOrderResponseData/PagarmeOrderResponseData.php

@@ -2,42 +2,45 @@
 
 namespace App\Data\Pagarme\Response\PagarmeOrderResponseData;
 
+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\Enums\PaymentStatusEnum;
 
 /**
- * @param  array<int, array>  $items  Itens do pedido (code, amount, quantity, description, etc.)
- * @param  array<string, mixed>|null  $customer  Dados do cliente retornados pela API
- * @param  array<int, array>  $charges  Cobrancas do pedido (status, amount, payment_method, last_transaction, etc.)
- * @param  array<int, array>  $checkouts  Checkouts do pedido
- * @param  array<string, mixed>  $metadata  Metadados retornados pela API
+ * @param  PagarmeOrderItemResponseData[]  $items
+ * @param  PagarmeOrderChargeResponseData[]  $charges
+ * @param  PagarmeOrderCheckoutResponseData[]  $checkouts
  */
 final readonly class PagarmeOrderResponseData
 {
     public function __construct(
-        public ?string $id,
-        public ?string $code,
-        public ?int $amount,
-        public ?string $currency,
-        public ?bool $closed,
-        public ?string $status,
-        public array $items,
-        public ?array $customer,
-        public array $charges,
-        public array $checkouts,
-        public array $metadata,
-        public ?string $createdAt = null,
-        public ?string $updatedAt = null,
-        public ?string $closedAt = null,
+        public ?string                        $id,
+        public ?string                        $code,
+        public ?int                           $amount,
+        public ?string                        $currency,
+        public ?bool                          $closed,
+        public ?string                        $status,
+        public array                          $items,
+        public ?PagarmeCustomerResponseData   $customer,
+        public array                          $charges,
+        public array                          $checkouts,
+        public array                          $metadata,
+        public ?string                        $createdAt = null,
+        public ?string                        $updatedAt = null,
+        public ?string                        $closedAt  = null,
     ) {}
 
     public function authorizedAt(): ?string
     {
         $transaction = $this->lastTransaction();
 
-        $transactionStatus = $transaction['status'] ?? null;
+        if (! $transaction) {
+            return null;
+        }
 
-        if (in_array($transactionStatus, ['authorized_pending_capture', 'captured', 'partial_capture'], true)) {
-            return $this->filledArrayValue($transaction, 'created_at');
+        if (in_array($transaction->status, ['authorized_pending_capture', 'captured', 'partial_capture'], true)) {
+            return $transaction->createdAt;
         }
 
         return null;
@@ -45,20 +48,30 @@ final readonly class PagarmeOrderResponseData
 
     public function failureCode(): ?string
     {
-        return $this->filledArrayValue($this->lastTransaction()['gateway_response'] ?? [], 'code');
+        $transaction = $this->lastTransaction();
+
+        if (! $transaction) {
+            return null;
+        }
+
+        return $this->filledValue($transaction->gatewayResponse['code'] ?? null);
     }
 
     public function failureMessage(): ?string
     {
         $transaction = $this->lastTransaction();
 
-        $acquirerMessage = $this->filledArrayValue($transaction, 'acquirer_message');
+        if (! $transaction) {
+            return null;
+        }
+
+        $acquirerMessage = $this->filledValue($transaction->acquirerMessage);
 
         if ($acquirerMessage) {
             return $acquirerMessage;
         }
 
-        $gatewayErrors = $transaction['gateway_response']['errors'] ?? [];
+        $gatewayErrors = $transaction->gatewayResponse['errors'] ?? [];
 
         if (! is_array($gatewayErrors) || empty($gatewayErrors)) {
             return null;
@@ -76,39 +89,39 @@ final readonly class PagarmeOrderResponseData
         return $message;
     }
 
-    public function firstCharge(): array
+    public function firstCharge(): ?PagarmeOrderChargeResponseData
     {
-        return $this->charges[0] ?? [];
+        return $this->charges[0] ?? null;
     }
 
     public function gatewayEntityLabel(): string
     {
-        return isset($this->firstCharge()['id']) ? 'charge' : 'order';
+        $charge = $this->firstCharge();
+
+        return $charge?->id ? 'charge' : 'order';
     }
 
     public function gatewayEntityReference(): ?string
     {
         $charge = $this->firstCharge();
 
-        return $charge['id'] ?? $this->id;
+        return $charge?->id ?? $this->id;
     }
 
     public function gatewayOperationLabel(): string
     {
-        $charge = $this->firstCharge();
-
+        $charge      = $this->firstCharge();
         $transaction = $this->lastTransaction();
 
-        return isset($transaction['id']) ? 'transaction' : (isset($charge['id']) ? 'charge' : 'order');
+        return $transaction?->id ? 'transaction' : ($charge?->id ? 'charge' : 'order');
     }
 
     public function gatewayOperationReference(): ?string
     {
-        $charge = $this->firstCharge();
-
+        $charge      = $this->firstCharge();
         $transaction = $this->lastTransaction();
 
-        return $transaction['id'] ?? $charge['id'] ?? $this->id;
+        return $transaction?->id ?? $charge?->id ?? $this->id;
     }
 
     public function id(): ?string
@@ -116,26 +129,26 @@ final readonly class PagarmeOrderResponseData
         return $this->id;
     }
 
-    public function lastTransaction(): array
+    public function lastTransaction(): ?PagarmeOrderTransactionResponseData
     {
-        return $this->firstCharge()['last_transaction'] ?? [];
+        return $this->firstCharge()?->transaction();
     }
 
     public function paymentStatus(): PaymentStatusEnum
     {
-        $charge = $this->firstCharge();
-
+        $charge      = $this->firstCharge();
         $transaction = $this->lastTransaction();
-
-        $status = strtolower((string) (($transaction['status'] ?? null) ?: ($charge['status'] ?? null)));
+        $status      = strtolower((string) ($transaction?->status ?: $charge?->status));
 
         return match ($status) {
-            'captured', 'paid', 'overpaid' => PaymentStatusEnum::PAID,
+            'captured', 'paid', 'overpaid'                  => PaymentStatusEnum::PAID,
             'authorized_pending_capture', 'waiting_capture' => PaymentStatusEnum::AUTHORIZED,
-            'pending', 'waiting_payment' => PaymentStatusEnum::PENDING,
-            'processing' => PaymentStatusEnum::PROCESSING,
+            'pending', 'waiting_payment'                    => PaymentStatusEnum::PENDING,
+            'processing'                                    => PaymentStatusEnum::PROCESSING,
+
             'not_authorized', 'with_error', 'failed',
             'underpaid', 'chargedback' => PaymentStatusEnum::FAILED,
+
             'voided', 'partial_void', 'canceled',
             'cancelled', 'refunded', 'partial_refunded',
             'partial_canceled' => PaymentStatusEnum::CANCELLED,
@@ -145,7 +158,7 @@ final readonly class PagarmeOrderResponseData
 
     public function paidAt(): ?string
     {
-        return $this->filledArrayValue($this->firstCharge(), 'paid_at');
+        return $this->firstCharge()?->paidAt;
     }
 
     public function requireId(): string
@@ -162,51 +175,81 @@ 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: $payload['items'] ?? [],
-            customer: ! empty($payload['customer']) ? $payload['customer'] : null,
-            charges: $payload['charges'] ?? [],
-            checkouts: $payload['checkouts'] ?? [],
-            metadata: $payload['metadata'] ?? [],
+            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,
+            closedAt:  $payload['closed_at']  ?? null,
         );
     }
 
     public function toArray(): array
     {
         return [
-            'id'         => $this->id,
-            'code'       => $this->code,
-            'amount'     => $this->amount,
-            'currency'   => $this->currency,
-            'closed'     => $this->closed,
-            'items'      => $this->items,
-            'customer'   => $this->customer,
+            'id'       => $this->id,
+            'code'     => $this->code,
+            'amount'   => $this->amount,
+            'currency' => $this->currency,
+            'closed'   => $this->closed,
+
+            'items' => array_map(
+                static fn (PagarmeOrderItemResponseData $item) => $item->toArray(),
+                $this->items,
+            ),
+
+            'customer'   => $this->customer?->toArray(),
             'status'     => $this->status,
             'created_at' => $this->createdAt,
             'updated_at' => $this->updatedAt,
             'closed_at'  => $this->closedAt,
-            'charges'    => $this->charges,
-            'checkouts'  => $this->checkouts,
+
+            'charges' => array_map(
+                static fn (PagarmeOrderChargeResponseData $charge) => $charge->toArray(),
+                $this->charges,
+            ),
+
+            'checkouts' => array_map(
+                static fn (PagarmeOrderCheckoutResponseData $checkout) => $checkout->toArray(),
+                $this->checkouts,
+            ),
+
             'metadata'   => $this->metadata,
         ];
     }
 
     //
 
-    private function filledArrayValue(array $data, string $field): ?string
+    private function filledValue(mixed $value): ?string
     {
-        if (! array_key_exists($field, $data) || $data[$field] === null || $data[$field] === '' || $data[$field] === []) {
+        if ($value === null || $value === '' || $value === []) {
             return null;
         }
 
-        return (string) $data[$field];
+        return (string) $value;
     }
 }

+ 8 - 8
app/Data/Pagarme/Response/PagarmeRecipientResponseData/PagarmeRecipientBankAccountResponseData.php

@@ -19,15 +19,15 @@ final readonly class PagarmeRecipientBankAccountResponseData
     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,
+            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,
+            type:              $payload['type']                ?? null,
         );
     }
 

+ 16 - 14
app/Data/Pagarme/Response/PagarmeRecipientResponseData/PagarmeRecipientResponseData.php

@@ -5,15 +5,15 @@ 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 ?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 ?string                                  $createdAt          = null,
+        public ?string                                  $updatedAt          = null,
     ) {}
 
     public function defaultBankAccount(): ?PagarmeRecipientBankAccountResponseData
@@ -40,15 +40,17 @@ 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,
+            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,
         );

+ 15 - 15
app/Data/Pagarme/Response/PagarmeTransferResponseData.php

@@ -6,18 +6,18 @@ final readonly class PagarmeTransferResponseData
 {
     public function __construct(
         public ?string $id,
-        public ?int $amount,
+        public ?int    $amount,
         public ?string $type,
         public ?string $status,
-        public ?int $fee,
+        public ?int    $fee,
         public ?string $fundingDate,
         public ?string $fundingEstimatedDate,
-        public ?array $bankAccount,
+        public ?array  $bankAccount,
         public ?string $bankResponse,
         public ?string $createdAt,
-        public ?array $metadata,
+        public ?array  $metadata,
     ) {}
-    
+
     public function id(): ?string
     {
         return $this->id;
@@ -33,17 +33,17 @@ 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,
+            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,
+            bankAccount:          $payload['bank_account']           ?? null,
+            bankResponse:         $payload['bank_response']          ?? null,
+            createdAt:            $payload['created_at']             ?? $payload['date_created'] ?? null,
+            metadata:             $payload['metadata']               ?? null,
         );
     }
 

+ 11 - 6
app/Services/Pagarme/PagarmePaymentService.php

@@ -2,6 +2,11 @@
 
 namespace App\Services\Pagarme;
 
+use App\Data\Pagarme\Request\PagarmeCustomerRequestData\PagarmeCustomerRequestData;
+use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderItemData;
+use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData\PagarmeOrderCreditCardData;
+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\PagarmeOrderResponseData\PagarmeOrderResponseData;
 use App\Enums\PaymentSplitStatusEnum;
@@ -18,8 +23,8 @@ class PagarmePaymentService
     public function createOrderWithCreditCard(
         Payment $payment,
         array $items,
-        array $customer,
-        array $creditCard,
+        PagarmeCustomerRequestData $customer,
+        PagarmeOrderCreditCardData $creditCard,
         array $options = []
     ): array {
         return $this->createOrder(
@@ -37,8 +42,8 @@ class PagarmePaymentService
     public function createOrderWithPix(
         Payment $payment,
         array $items,
-        array $customer,
-        array $pix,
+        PagarmeCustomerRequestData $customer,
+        PagarmeOrderPixData $pix,
         array $options = []
     ): array {
         return $this->createOrder(
@@ -58,8 +63,8 @@ class PagarmePaymentService
     public function createOrder(
         Payment $payment,
         array $items,
-        array $customer,
-        array $paymentMethod,
+        PagarmeCustomerRequestData $customer,
+        PagarmeOrderPaymentData $paymentMethod,
         array $options = []
     ): array {
         $requestData = PagarmeOrderRequestData::fromOrderPayload(

+ 71 - 49
app/Services/PaymentService.php

@@ -2,6 +2,16 @@
 
 namespace App\Services;
 
+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\Request\PagarmeOrderRequestData\PagarmeOrderItemData;
+use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData\PagarmeOrderCreditCardData;
+use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData\PagarmeOrderPixAdditionalInformationData;
+use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData\PagarmeOrderPixData;
+use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData\PagarmeOrderSplitData;
+use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderPaymentData\PagarmeOrderSplitOptionsData;
 use App\Data\Pagarme\Request\PagarmeOrderRequestData\PagarmeOrderRequestData;
 use App\Enums\PaymentSplitStatusEnum;
 use App\Enums\PaymentStatusEnum;
@@ -208,17 +218,16 @@ class PaymentService
         $split = PagarmeOrderRequestData::splitFromTransfers(collect([$transfer]));
 
         if ($platformFee > 0) {
-            $split[] = [
-                'amount'       => PagarmeOrderRequestData::amountInCents($platformFee),
-                'recipient_id' => $platformRecipientId,
-                'type'         => 'flat',
-
-                'options' => [
-                    'charge_processing_fee' => true,
-                    'charge_remainder_fee'  => true,
-                    'liable'                => true,
-                ],
-            ];
+            $split[] = new PagarmeOrderSplitData(
+                amount:      PagarmeOrderRequestData::amountInCents($platformFee),
+                recipientId: $platformRecipientId,
+                type:        'flat',
+                options:     new PagarmeOrderSplitOptionsData(
+                    chargeProcessingFee: true,
+                    chargeRemainderFee:  true,
+                    liable:              true,
+                ),
+            );
         }
 
         $pixOptions = config('services.pagarme.pix_disable_split')
@@ -235,11 +244,12 @@ class PaymentService
                     payment: $payment,
                     items: $items,
                     customer: $customer,
-                    creditCard: [
-                        'installments'         => 1,
-                        'statement_descriptor' => Str::limit((string) config('app.name', 'SOFTPAR'), 13, ''),
-                        'operation_type'       => 'auth_and_capture',
-                    ] + $creditCardReference,
+                    creditCard: new PagarmeOrderCreditCardData(
+                        installments: 1,
+                        statementDescriptor: Str::limit((string) config('app.name', 'SOFTPAR'), 13, ''),
+                        operationType: 'auth_and_capture',
+                        cardId: $creditCardReference['card_id'],
+                    ),
                     options: [
                         'split' => $split,
                     ],
@@ -248,15 +258,15 @@ class PaymentService
                     payment: $payment,
                     items: $items,
                     customer: $customer,
-                    pix: [
-                        'expires_in'             => '1800',
-                        'additional_information' => [
-                            [
-                                'name'  => 'Agendamento',
-                                'value' => (string) $schedule->id,
-                            ],
+                    pix: new PagarmeOrderPixData(
+                        expiresIn: 1800,
+                        additionalInformation: [
+                            new PagarmeOrderPixAdditionalInformationData(
+                                name:  'Agendamento',
+                                value: (string) $schedule->id,
+                            ),
                         ],
-                    ],
+                    ),
                     options: $pixOptions,
                 );
         } catch (\Throwable $e) {
@@ -285,19 +295,19 @@ class PaymentService
         $description = $schedule->customSchedule?->serviceType?->description
             ?? "Servico {$schedule->id}";
 
-        return [[
-            'amount'      => PagarmeOrderRequestData::amountInCents($grossAmount),
-            'description' => $description,
-            'quantity'    => 1,
-            'code'        => "schedule-{$schedule->id}",
-        ]];
+        return [new PagarmeOrderItemData(
+            code: "schedule-{$schedule->id}",
+            amount: PagarmeOrderRequestData::amountInCents($grossAmount),
+            quantity: 1,
+            description: $description,
+        )];
     }
 
     private function buildCustomerPayload(
         Schedule $schedule,
         array $options = [],
         bool $requirePhone = true
-    ): array {
+    ): PagarmeCustomerRequestData {
         $client = $schedule->client;
         $user = $client->user()->first(['id', 'name', 'email', 'phone']);
         $address = Address::with(['city.state', 'state'])->find($schedule->address_id);
@@ -349,25 +359,37 @@ class PaymentService
             }
         }
 
-        return [
-            'name'          => $user->name,
-            'email'         => $user->email,
-            'code'          => "client-{$client->id}",
-            'document'      => $document,
-            'document_type' => strlen($document) === 14 ? 'CNPJ' : 'CPF',
-            'type'          => strlen($document) === 14 ? 'company' : 'individual',
-
-            'address' => [
-                'country'  => 'BR',
-                'state'    => $state,
-                'city'     => $city,
-                'zip_code' => $zipCode,
-                'line_1'   => $line1,
-                'line_2'   => $address->complement ?: $address->instructions,
-            ],
+        $customerAddress = new PagarmeCustomerAddressRequestData(
+            line1: $line1,
+            line2: $address->complement ?: $address->instructions,
+            zipCode: $zipCode,
+            city: $city,
+            state: $state,
+            country: 'BR',
+        );
 
-            'phones' => $phone ? ['mobile_phone' => $phone] : null,
-        ];
+        $customerPhones = null;
+
+        if ($phone) {
+            $customerPhones = new PagarmeCustomerPhonesRequestData(
+                mobilePhone: new PagarmeCustomerPhoneData(
+                    countryCode: $phone['country_code'],
+                    areaCode: $phone['area_code'],
+                    number: $phone['number'],
+                ),
+            );
+        }
+
+        return new PagarmeCustomerRequestData(
+            name: $user->name,
+            email: $user->email,
+            document: $document,
+            type: strlen($document) === 14 ? 'company' : 'individual',
+            documentType: strlen($document) === 14 ? 'CNPJ' : 'CPF',
+            code: "client-{$client->id}",
+            address: $customerAddress,
+            phones: $customerPhones,
+        );
     }
 
     private function buildPhonePayload(?string $phone): ?array

+ 2 - 1
pint.json

@@ -5,7 +5,8 @@
         "routes",
         "app/Models",
         "app/Enums",
-        "app/Http/Requests"
+        "app/Http/Requests",
+        "app/Data/Pagarme"
     ],
     "rules": {
         "binary_operator_spaces": {