From d299e1ef517ebdd0ba8799e5a9e6297e740d7e6c Mon Sep 17 00:00:00 2001
From: Jesus Suarez
Date: Wed, 13 Aug 2025 16:37:03 -0500
Subject: [PATCH] Update epayco.php
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Función getLinkPago reescrita para que nunca se rompa el JavaScript, usando json_encode para inyectar el objeto data (name/description quedan correctamente escapados aunque tengan saltos de línea o caracteres especiales). También limpié un warning por $enlace inexistente.
---
.../modules/gateways/epayco/epayco.php | 415 +++++++++---------
1 file changed, 203 insertions(+), 212 deletions(-)
diff --git a/payco_whmcs/modules/gateways/epayco/epayco.php b/payco_whmcs/modules/gateways/epayco/epayco.php
index bc2f3e3..e1741bf 100644
--- a/payco_whmcs/modules/gateways/epayco/epayco.php
+++ b/payco_whmcs/modules/gateways/epayco/epayco.php
@@ -187,236 +187,227 @@ function getConfigModulo()
}
function getLinkPago($params)
- {
- $companyname = $params["companyname"];
- $systemurl = $params["systemurl"];
- $bh_texto = $params["bh_texto"];
- $bh_nota = $params["bh_nota"];
- $color = $params["color"];
- $nota = "";
- if (!empty($bh_nota)) {
- $nota = "" . $bh_nota . "
";
- }
+{
+ $companyname = $params["companyname"];
+ $systemurl = $params["systemurl"];
+ $bh_texto = $params["bh_texto"];
+ $bh_nota = $params["bh_nota"];
+ $color = $params["color"];
- if ($params["testMode"] == "on") {
- $mododeprueba = true;
- } else {
- $mododeprueba = false;
- }
-
-
- $bh_success = $params["bh_success"];
- $bh_pending = $params["bh_pending"];
- $bh_failure = $params["bh_failure"];
- $bh_error_mp = $params["bh_error_mp"];
- if (empty($bh_success)) {
- $bh_success = $systemurl . "viewinvoice.php?id=" . $params["invoiceid"];
- }
- if (empty($bh_pending)) {
- $bh_pending = $systemurl . "viewinvoice.php?id=" . $params["invoiceid"];
- }
- if (empty($bh_failure)) {
- $bh_failure = $systemurl . "viewinvoice.php?id=" . $params["invoiceid"];
- }
+ $nota = "";
+ if (!empty($bh_nota)) {
+ $nota = "" . $bh_nota . "
";
+ }
-
- $countryCode = 'CO';
- $firstname = $params['clientdetails']['firstname'];
- $lastname = $params['clientdetails']['lastname'];
- $email = $params['clientdetails']['email'];
- $address1 = $params['clientdetails']['address1'];
- $returnUrl = $params['returnurl'];
- $billing_name = $firstname." ".$lastname;
- if($params['currencyCode'] == 'default'){
- $clientDetails = localAPI("getclientsdetails", ["clientid" => $params['clientdetails']['userid'], "responsetype" => "json"], $params['WHMCSAdminUser']);
- $currencyCode = strtolower($clientDetails['currency_code']);
- }else {
- $currencyCode = $params['currencyCode'];
- }
-
- $testMode = $params['testMode'] == 'on' ? 'true' : 'false';
-
- $externalMode = $params['externalMode'] == 'on' ? 'true' : 'false';
-
- $invoice = localAPI("getinvoice", array('invoiceid' => $params['invoiceid']), $params['WHMCSAdminUser']);
- $invoiceData = Capsule::table('tblorders')
- ->select('tblorders.id')
- ->where('tblorders.invoiceid', '=', $params['invoiceid'])
- ->get();
-
- $description = $this->epayco_getChargeDescription($invoice['items']['item']);
- if(floatval($invoice["subtotal"]) > 0.0 ){
- $tax=floatval($invoice["tax"]);
- $sub_total = floatval($invoice["subtotal"]);
- $amount = floatval($invoice["total"]);
- }else{
- $tax="0";
- $sub_total = $params["amount"];
- $amount = $params["amount"];
- }
- $sub_total = $amount - $tax;
- $confirmationUrl = $systemurl . "modules/gateways/callback/" . $params["paymentmethod"] . ".php?source_news=webhooks";
- $lang = $params['lang'];
- if ($lang === "en") {
- $epaycoButtonImage = 'https://multimedia.epayco.co/epayco-landing/btns/Boton-epayco-color-Ingles.png';
- }else{
- $epaycoButtonImage = 'https://multimedia.epayco.co/epayco-landing/btns/Boton-epayco-color1.png';
- }
- $ip=$this->getCustomerIp();
- $logo = $params['systemurl'].'/modules/gateways/epayco/logo.png';
- $code = "
" . $bh_texto . "" . $nota;
- $code = sprintf('
-
-
-
+ $bh_success = $params["bh_success"] ?: $systemurl . "viewinvoice.php?id=" . $params["invoiceid"];
+ $bh_pending = $params["bh_pending"] ?: $systemurl . "viewinvoice.php?id=" . $params["invoiceid"];
+ $bh_failure = $params["bh_failure"] ?: $systemurl . "viewinvoice.php?id=" . $params["invoiceid"];
+ $bh_error_mp = $params["bh_error_mp"];
+
+ $countryCode = 'CO';
+ $firstname = $params['clientdetails']['firstname'];
+ $lastname = $params['clientdetails']['lastname'];
+ $email = $params['clientdetails']['email'];
+ $address1 = $params['clientdetails']['address1'];
+ $billing_name = $firstname . " " . $lastname;
+
+ if ($params['currencyCode'] == 'default') {
+ $clientDetails = localAPI("getclientsdetails", ["clientid" => $params['clientdetails']['userid'], "responsetype" => "json"], $params['WHMCSAdminUser']);
+ $currencyCode = strtolower($clientDetails['currency_code']);
+ } else {
+ $currencyCode = $params['currencyCode'];
+ }
+
+ // Mantengo el tipo string "true"/"false" porque el resto del código lo usa así
+ $testMode = $params['testMode'] == 'on' ? 'true' : 'false';
+ $externalMode = $params['externalMode'] == 'on' ? 'true' : 'false';
+
+ $invoice = localAPI("getinvoice", ['invoiceid' => $params['invoiceid']], $params['WHMCSAdminUser']);
+ $invoiceData = Capsule::table('tblorders')
+ ->select('tblorders.id')
+ ->where('tblorders.invoiceid', '=', $params['invoiceid'])
+ ->get();
+
+ $description = $this->epayco_getChargeDescription($invoice['items']['item']);
+
+ if (floatval($invoice["subtotal"]) > 0.0) {
+ $tax = floatval($invoice["tax"]);
+ $sub_total = floatval($invoice["subtotal"]);
+ $amount = floatval($invoice["total"]);
+ } else {
+ $tax = "0";
+ $sub_total = $params["amount"];
+ $amount = $params["amount"];
+ }
+ $sub_total = $amount - $tax;
+
+ $confirmationUrl = $systemurl . "modules/gateways/callback/" . $params["paymentmethod"] . ".php?source_news=webhooks";
+ $lang = $params['lang'];
+
+ if ($lang === "en") {
+ $epaycoButtonImage = 'https://multimedia.epayco.co/epayco-landing/btns/Boton-epayco-color-Ingles.png';
+ } else {
+ $epaycoButtonImage = 'https://multimedia.epayco.co/epayco-landing/btns/Boton-epayco-color1.png';
+ }
+
+ $ip = $this->getCustomerIp();
+ $logo = $params['systemurl'] . '/modules/gateways/epayco/logo.png';
+
+ // Sanitiza y limita name/description (opcional pero recomendable)
+ // Sustituye saltos de línea por " / " para que sea legible
+ $descClean = preg_replace("/\r\n|\r|\n/u", " / ", (string)$description);
+ // Si quieres límite estricto (ej. API o UI): 254 caracteres
+ $descClean = mb_substr($descClean, 0, 254, 'UTF-8');
+
+ // Construye el payload que irá a JS como JSON literal
+ $payload = [
+ 'amount' => (string)$amount,
+ 'tax_base' => (string)$sub_total,
+ 'tax' => (string)$tax,
+ 'name' => $descClean,
+ 'description' => $descClean,
+ 'currency' => strtolower($currencyCode),
+ 'test' => (string)$testMode,
+ 'invoice' => (string)$params['invoiceid'],
+ 'country' => $countryCode,
+ 'response' => $confirmationUrl,
+ 'confirmation' => $confirmationUrl,
+ 'external' => (string)$externalMode,
+ 'email_billing' => $email,
+ 'name_billing' => $billing_name,
+ 'address_billing' => $address1,
+ 'extra1' => (string)$params['invoiceid'],
+ 'extra2' => isset($invoiceData[0]) ? (string)$invoiceData[0]->id : "",
+ 'lang' => $lang,
+ 'ip' => $ip,
+ 'taxIco' => "0",
+ 'autoclick' => "true",
+ 'extras_epayco' => ['extra5' => 'P34'],
+ 'method_confirmation' => "POST",
+ 'checkout_version' => "1",
+ ];
+
+ // JSON sin escapar Unicode ni slashes, para que quede limpio y válido en JS
+ $dataJson = json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
+
+ $code = sprintf('
+
+
+
+
-
+
-
-
-
-
+
+ });
+
%s
- ',
+ ',
+ htmlspecialchars($logo, ENT_QUOTES, 'UTF-8'),
+ $epaycoButtonImage,
$params['publicKey'],
$testMode,
- $amount,
- $sub_total,
- $tax,
- $description,
- $description,
- strtolower($currencyCode),
- $testMode,
- $params['invoiceid'],
- $countryCode,
- $confirmationUrl,
- $confirmationUrl,
- $externalMode,
- $email,
- $billing_name,
- $address1,
- $params['invoiceid'],
- $invoiceData[0]->id,
- $lang,
- $ip,
+ $dataJson,
$params['publicKey'],
$params['privateKey'],
$nota
);
- return $code;
- }
+
+ return $code;
+}
+
function epayco_getChargeDescription($invoceItems){
$descriptions = array();
foreach($invoceItems as $item){