From 7bb6d7c0e2dcfaf848eb1c1b4bc72d81af970cef Mon Sep 17 00:00:00 2001 From: DANYDHSV Date: Tue, 6 Jan 2026 14:21:39 -0600 Subject: [PATCH] =?UTF-8?q?fix:=20Eliminar=20pagos=20duplicados=20y=20actu?= =?UTF-8?q?alizar=20a=20v1.3.1=20-=20Se=20elimin=C3=B3=20la=20l=C3=B3gica?= =?UTF-8?q?=20de=20registro=20de=20pago=20manual=20para=20evitar=20duplica?= =?UTF-8?q?dos.=20-=20Se=20alinearon=20los=20metadatos=20con=20la=20integr?= =?UTF-8?q?aci=C3=B3n=20nativa=20de=20UCRM=20(createdBy=20=3D>=20'UCRM').?= =?UTF-8?q?=20-=20Se=20actualiz=C3=B3=20la=20versi=C3=B3n=20a=201.3.1=20en?= =?UTF-8?q?=20manifest.json,=20README=20y=20CHANGELOG.=20-=20Optimizaci?= =?UTF-8?q?=C3=B3n=20de=20logs=20de=20diagn=C3=B3stico=20en=20producci?= =?UTF-8?q?=C3=B3n.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 +++++ README.md | 4 ++-- manifest.json | 4 ++-- public.php | 28 ++++------------------------ src/PaymentIntentService.php | 15 +++++++++++---- vendor/composer/installed.php | 4 ++-- 6 files changed, 26 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 166a773..688bd1d 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [1.3.1] - 06-01-2026 +### Fixed +- Eliminación de pagos duplicados: Delegación del registro de pagos a la integración nativa de UCRM mediante el ajuste de metadatos (`createdBy => UCRM`). +- Refactorización del servicio para eliminar lógica de registro manual redundante. + ## [1.3.0] - 06-01-2026 ### Fixed - Corrección de la URL base de UCRM (faltaba prefijo `/crm`). diff --git a/README.md b/README.md index 2209be4..6ba20e5 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # SIIP - Generador de Payment Intents Stripe -![Version](https://img.shields.io/badge/version-1.3.0-blue.svg) +![Version](https://img.shields.io/badge/version-1.3.1-blue.svg) ![UCRM Compliancy](https://img.shields.io/badge/UCRM-v1.0.0%2B-success.svg) ![PHP](https://img.shields.io/badge/PHP-7.4%2B-777bb4.svg) ![License](https://img.shields.io/badge/license-MIT-green.svg) @@ -45,5 +45,5 @@ Para que los pagos se registren automáticamente en UCRM, debe configurar un Web - Si el cliente no tiene un "Stripe Customer ID", no se permitirá generar el pago. --- -**Versión**: 1.3.0 +**Versión**: 1.3.1 **Copyright**: © 2024 SIIP Internet. Todos los derechos reservados. diff --git a/manifest.json b/manifest.json index 6febaf6..432fdd1 100755 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "displayName": "SIIP - Generador de Payment Intents Stripe", "description": "Generador manual de Payment Intents Stripe para los clientes de UISP CRM, útil para conciliación de pagos no registrados en UISP CRM", "url": "https://siip.mx", - "version": "1.3.0", + "version": "1.3.1", "ucrmVersionCompliancy": { "min": "1.0.0", "max": null @@ -56,7 +56,7 @@ "menu": [ { "key": "Reports", - "label": "Generar Payment Intent", + "label": "Generar Intenciones de pago Stripe", "type": "admin", "target": "iframe" } diff --git a/public.php b/public.php index 459ff20..8ebb03b 100755 --- a/public.php +++ b/public.php @@ -19,6 +19,8 @@ $baseUrl = 'https://' . $ipServer . '/crm'; $apiUcrmKey = $config['apiTokenUcrm'] ?? ''; $stripeApiKey = $config['apiTokenStripe'] ?? ''; +$log->appendLog("Plugin Config Loaded: Server=$ipServer, UCRM Token=" . substr($apiUcrmKey, 0, 5) . "..., Stripe Token=" . substr($stripeApiKey, 0, 7) . "..."); + $service = new PaymentIntentService($baseUrl, $apiUcrmKey, $stripeApiKey, $log); // --- ROUTER --- @@ -121,9 +123,7 @@ if ($action === 'webhook') { $currency = $paymentIntent->currency; if ($clientId) { - $notes = "Pago procesado via Stripe PaymentIntent: " . $paymentIntent->id; - $res = $service->registerPayment($clientId, $amount, $currency, $notes); - $log->appendLog("Payment Register UCRM ($clientId) for PI {$paymentIntent->id}: " . ($res ? 'Success' : 'Fail')); + $log->appendLog("Info: PI {$paymentIntent->id} succeeded for Client $clientId. UCRM native integration should handle registration."); } else { $log->appendLog("Warning: No clientId found in metadata for PI: " . $paymentIntent->id); } @@ -135,27 +135,7 @@ if ($action === 'webhook') { // Check if money was applied to a payment object if (isset($txn->applied_to_payment) && isset($txn->applied_to_payment->payment_intent)) { $piId = $txn->applied_to_payment->payment_intent; - $log->appendLog("Transaction applied to PI: " . $piId); - - $paymentIntent = $service->getPaymentIntent($piId); - - if ($paymentIntent) { - $clientId = $paymentIntent->metadata->clientId ?? null; - // In cash balance txn, net_amount is what was received (negative for withdrawals, positive for deposits/applications) - // Usually it's negative when applied to a PI, so we take abs - $amount = abs($txn->net_amount) / 100; - $currency = $txn->currency; - - if ($clientId) { - $notes = "Pago via Transferencia (Cash Balance) aplicado a Intent: " . $piId . " (Txn: " . $txn->id . ")"; - $res = $service->registerPayment($clientId, $amount, $currency, $notes); - $log->appendLog("Cash Balance Payment Register UCRM ($clientId) for PI $piId: " . ($res ? 'Success' : 'Fail')); - } else { - $log->appendLog("Error: No clientId found in metadata for PI: $piId"); - } - } else { - $log->appendLog("Error: Could not retrieve PaymentIntent $piId from Stripe"); - } + $log->appendLog("Transaction applied to PI: " . $piId . ". UCRM native integration will handle PI success."); } else { $log->appendLog("Info: Cash Balance Transaction " . $txn->id . " not directly applied to a PaymentIntent yet."); } diff --git a/src/PaymentIntentService.php b/src/PaymentIntentService.php index d629c2d..85df4dd 100755 --- a/src/PaymentIntentService.php +++ b/src/PaymentIntentService.php @@ -147,13 +147,18 @@ class PaymentIntentService ], 'metadata' => [ 'clientId' => $clientId, - 'createdBy' => 'UCRM Plugin', + 'createdBy' => 'UCRM', 'paymentType' => 'card.one_time', - 'signedInAdminId' => $adminId, // Will be passed from session or fixed - 'tipoPago' => 'Transferencia Bancaria Manual' + 'signedInAdminId' => $adminId, + 'tipoPago' => 'Transferencia Bancaria' ], ]); + $this->log("PaymentIntent created: " . $paymentIntent->id . " Status: " . $paymentIntent->status); + + // Synchronous registration removed to avoid duplicates. + // UCRM's native integration handles registration automatically via metadata. + return [ 'success' => true, 'id' => $paymentIntent->id, @@ -228,8 +233,10 @@ class PaymentIntentService } } } catch (\Exception $e) { - error_log("Error fetching payment methods: " . $e->getMessage()); + $this->log("Error fetching payment methods: " . $e->getMessage()); } + + $this->log("Payment method '$name' not found. Available methods: " . json_encode($methods ?? [])); return null; } } diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 9928f1e..f96983b 100755 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -5,7 +5,7 @@ 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), - 'reference' => '7e4a5350383f1e7179ecb80a2036c1fd1b890256', + 'reference' => '070fb757d2f83111f7d49baa82baeade35c7bffa', 'name' => '__root__', 'dev' => false, ), @@ -16,7 +16,7 @@ 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), - 'reference' => '7e4a5350383f1e7179ecb80a2036c1fd1b890256', + 'reference' => '070fb757d2f83111f7d49baa82baeade35c7bffa', 'dev_requirement' => false, ), 'guzzlehttp/guzzle' => array(