fix: Eliminar pagos duplicados y actualizar a v1.3.1

- Se eliminó la lógica de registro de pago manual para evitar duplicados. - Se alinearon los metadatos con la integración nativa de UCRM (createdBy => 'UCRM'). - Se actualizó la versión a 1.3.1 en manifest.json, README y CHANGELOG. - Optimización de logs de diagnóstico en producción.
This commit is contained in:
DANYDHSV 2026-01-06 14:21:39 -06:00
parent 070fb757d2
commit 7bb6d7c0e2
6 changed files with 26 additions and 34 deletions

View File

@ -1,5 +1,10 @@
# Changelog # 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 ## [1.3.0] - 06-01-2026
### Fixed ### Fixed
- Corrección de la URL base de UCRM (faltaba prefijo `/crm`). - Corrección de la URL base de UCRM (faltaba prefijo `/crm`).

View File

@ -1,6 +1,6 @@
# SIIP - Generador de Payment Intents Stripe # 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) ![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) ![PHP](https://img.shields.io/badge/PHP-7.4%2B-777bb4.svg)
![License](https://img.shields.io/badge/license-MIT-green.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. - 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. **Copyright**: © 2024 SIIP Internet. Todos los derechos reservados.

View File

@ -5,7 +5,7 @@
"displayName": "SIIP - Generador de Payment Intents Stripe", "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", "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", "url": "https://siip.mx",
"version": "1.3.0", "version": "1.3.1",
"ucrmVersionCompliancy": { "ucrmVersionCompliancy": {
"min": "1.0.0", "min": "1.0.0",
"max": null "max": null
@ -56,7 +56,7 @@
"menu": [ "menu": [
{ {
"key": "Reports", "key": "Reports",
"label": "Generar Payment Intent", "label": "Generar Intenciones de pago Stripe",
"type": "admin", "type": "admin",
"target": "iframe" "target": "iframe"
} }

View File

@ -19,6 +19,8 @@ $baseUrl = 'https://' . $ipServer . '/crm';
$apiUcrmKey = $config['apiTokenUcrm'] ?? ''; $apiUcrmKey = $config['apiTokenUcrm'] ?? '';
$stripeApiKey = $config['apiTokenStripe'] ?? ''; $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); $service = new PaymentIntentService($baseUrl, $apiUcrmKey, $stripeApiKey, $log);
// --- ROUTER --- // --- ROUTER ---
@ -121,9 +123,7 @@ if ($action === 'webhook') {
$currency = $paymentIntent->currency; $currency = $paymentIntent->currency;
if ($clientId) { if ($clientId) {
$notes = "Pago procesado via Stripe PaymentIntent: " . $paymentIntent->id; $log->appendLog("Info: PI {$paymentIntent->id} succeeded for Client $clientId. UCRM native integration should handle registration.");
$res = $service->registerPayment($clientId, $amount, $currency, $notes);
$log->appendLog("Payment Register UCRM ($clientId) for PI {$paymentIntent->id}: " . ($res ? 'Success' : 'Fail'));
} else { } else {
$log->appendLog("Warning: No clientId found in metadata for PI: " . $paymentIntent->id); $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 // Check if money was applied to a payment object
if (isset($txn->applied_to_payment) && isset($txn->applied_to_payment->payment_intent)) { if (isset($txn->applied_to_payment) && isset($txn->applied_to_payment->payment_intent)) {
$piId = $txn->applied_to_payment->payment_intent; $piId = $txn->applied_to_payment->payment_intent;
$log->appendLog("Transaction applied to PI: " . $piId); $log->appendLog("Transaction applied to PI: " . $piId . ". UCRM native integration will handle PI success.");
$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");
}
} else { } else {
$log->appendLog("Info: Cash Balance Transaction " . $txn->id . " not directly applied to a PaymentIntent yet."); $log->appendLog("Info: Cash Balance Transaction " . $txn->id . " not directly applied to a PaymentIntent yet.");
} }

View File

@ -147,13 +147,18 @@ class PaymentIntentService
], ],
'metadata' => [ 'metadata' => [
'clientId' => $clientId, 'clientId' => $clientId,
'createdBy' => 'UCRM Plugin', 'createdBy' => 'UCRM',
'paymentType' => 'card.one_time', 'paymentType' => 'card.one_time',
'signedInAdminId' => $adminId, // Will be passed from session or fixed 'signedInAdminId' => $adminId,
'tipoPago' => 'Transferencia Bancaria Manual' '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 [ return [
'success' => true, 'success' => true,
'id' => $paymentIntent->id, 'id' => $paymentIntent->id,
@ -228,8 +233,10 @@ class PaymentIntentService
} }
} }
} catch (\Exception $e) { } 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; return null;
} }
} }

View File

@ -5,7 +5,7 @@
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
'reference' => '7e4a5350383f1e7179ecb80a2036c1fd1b890256', 'reference' => '070fb757d2f83111f7d49baa82baeade35c7bffa',
'name' => '__root__', 'name' => '__root__',
'dev' => false, 'dev' => false,
), ),
@ -16,7 +16,7 @@
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
'reference' => '7e4a5350383f1e7179ecb80a2036c1fd1b890256', 'reference' => '070fb757d2f83111f7d49baa82baeade35c7bffa',
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'guzzlehttp/guzzle' => array( 'guzzlehttp/guzzle' => array(