2 Commits 7eec42feee ... 76f840a88c

Auteur SHA1 Message Date
  ebagabee 76f840a88c fix: add missing line breaks to franchisee account receive detail creation logic il y a 1 semaine
  ebagabee a0195e7f8b fix: validação de telefone na integração com Asaas il y a 1 semaine

+ 1 - 0
.gitignore

@@ -18,3 +18,4 @@ yarn-error.log
 /.fleet
 /.idea
 /.vscode
+dev_scripts/

+ 7 - 1
app/Services/Integrations/Asaas/AsaasCustomerService.php

@@ -38,13 +38,19 @@ public function ensureFranchiseeCustomer(Unit $unit): string
             'name' => $unit->social_reason ?? $unit->fantasy_name ?? 'Franquia',
             'cpfCnpj' => $cpfCnpj,
             'email' => $unit->email,
-            'mobilePhone' => preg_replace('/[^0-9]/', '', $unit->cell_number ?? $unit->phone_number ?? ''),
             'postalCode' => preg_replace('/[^0-9]/', '', $unit->postal_code),
             'address' => $unit->street,
             'addressNumber' => $unit->address_number ?? 'S/N',
             'province' => $unit->neighborhood,
         ];
 
+        // Só envia telefone se for um número que pareça válido (10 a 11 dígitos), 
+        // para não travar a API do Asaas com lixo do cadastro.
+        $mobilePhone = preg_replace('/[^0-9]/', '', $unit->cell_number ?? $unit->phone_number ?? '');
+        if (strlen($mobilePhone) >= 10 && strlen($mobilePhone) <= 11) {
+            $payload['mobilePhone'] = $mobilePhone;
+        }
+
         $response = $this->client->post('/customers', $payload);
 
         return $response['id'];

+ 2 - 0
app/Services/TbrCalculationService.php

@@ -344,11 +344,13 @@ private function buildReceivable(TbrCalculation $calculation, ?FranchiseeContrac
             'value'                         => $calculation->royalties_effective_value,
             'history'                       => 'Royalties ' . $referenceLabel,
         ]);
+
         FranchiseeAccountReceiveDetail::create([
             'franchisee_account_receive_id' => $receive->id,
             'value'                         => $calculation->fnm_effective_value,
             'history'                       => 'FNM ' . $referenceLabel,
         ]);
+        
         FranchiseeAccountReceiveDetail::create([
             'franchisee_account_receive_id' => $receive->id,
             'value'                         => $calculation->maintenance_effective_value,