Skip to content

Commit

Permalink
Merge pull request #77 from culqi/feature/new-checkout-custom
Browse files Browse the repository at this point in the history
new changes checkout
  • Loading branch information
JoseHCalderon authored May 21, 2024
2 parents fdcab48 + f6d097d commit c896900
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 77 deletions.
2 changes: 1 addition & 1 deletion config_es.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>culqi</name>
<displayName><![CDATA[Culqi]]></displayName>
<version><![CDATA[3.0.3]]></version>
<version><![CDATA[3.1.0]]></version>
<description><![CDATA[Con&eacute;ctate a nuestra pasarela de pagos para aumentar tus ventas.]]></description>
<author><![CDATA[Culqi]]></author>
<tab><![CDATA[payments_gateways]]></tab>
Expand Down
1 change: 1 addition & 0 deletions controllers/front/payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function initContent()
$this->context->smarty->assign("currency", $this->context->currency->iso_code);
$this->context->smarty->assign("address", $address);
$this->context->smarty->assign("customer", $this->context->customer);
$this->context->smarty->assign("email", $this->context->customer->email);
$this->context->smarty->assign("commerce", Configuration::get('PS_SHOP_NAME'));
$this->context->smarty->assign("rsa_id", Configuration::get('CULQI_RSA_ID'));
$this->context->smarty->assign("rsa_pk", Configuration::get('CULQI_RSA_PK'));
Expand Down
6 changes: 3 additions & 3 deletions culqi.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
if (!defined('_PS_VERSION_'))
exit;

define('CULQI_PLUGIN_VERSION', '3.0.3');
define('CULQI_PLUGIN_VERSION', '3.1.0');

define('URLAPI_INTEG', 'https://integ-panel.culqi.com');
define('URLAPI_PROD', 'https://panel.culqi.com');
Expand All @@ -13,14 +13,14 @@
define('URLAPI_PROD_3DS', 'https://3ds.culqi.com');

define('URLAPI_ORDERCHARGES_INTEG', 'https://api.culqi.com/v2');
define('URLAPI_CHECKOUT_INTEG', 'https://checkout.culqi.com/js/v4');
define('URLAPI_CHECKOUT_INTEG', 'https://js.culqi.com/checkout-js');
define('URLAPI_LOGIN_INTEG', URLAPI_INTEG.'/user/login');
define('URLAPI_MERCHANT_INTEG', URLAPI_INTEG.'/secure/merchant/');
define('URLAPI_MERCHANTSINGLE_INTEG', URLAPI_INTEG.'/secure/keys/?merchant=');
define('URLAPI_WEBHOOK_INTEG', URLAPI_INTEG.'/secure/events');

define('URLAPI_ORDERCHARGES_PROD', 'https://api.culqi.com/v2');
define('URLAPI_CHECKOUT_PROD', 'https://checkout.culqi.com/js/v4');
define('URLAPI_CHECKOUT_PROD', 'https://js.culqi.com/checkout-js');
define('URLAPI_LOGIN_PROD', URLAPI_PROD.'/user/login');
define('URLAPI_MERCHANT_PROD', URLAPI_PROD.'/secure/merchant/');
define('URLAPI_MERCHANTSINGLE_PROD', URLAPI_PROD.'/secure/keys/?merchant=');
Expand Down
194 changes: 129 additions & 65 deletions views/templates/front/payment_execution_payme.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
$(document).ajaxComplete(function () {
});

var installments = (Culqi.token.metadata.installments == undefined) ? 0 : Culqi.token.metadata.installments;
var installments = (Culqi.token.metadata == undefined || Culqi.token.metadata.installments == undefined) ? 0 : Culqi.token.metadata.installments;

$.ajax({
url: fnReplace("{/literal}{$link->getModuleLink('culqi', 'chargeajax', [], true)|escape:'htmlall':'UTF-8'}{literal}"),
Expand Down Expand Up @@ -179,33 +179,6 @@
})
}, 100);

Culqi.publicKey = '{/literal}{$llave_publica|escape:'htmlall':'UTF-8'}{literal}';
Culqi.useClasses = true;
Culqi.init();

Culqi.options({
lang: 'auto',
paymentMethods: {
tarjeta: {/literal}{$tarjeta|escape:'htmlall':'UTF-8'}{literal},
bancaMovil: {/literal}{$banca_movil|escape:'htmlall':'UTF-8'}{literal},
yape: {/literal}{$yape|escape:'htmlall':'UTF-8'}{literal},
agente: {/literal}{$agente|escape:'htmlall':'UTF-8'}{literal},
billetera: {/literal}{$billetera|escape:'htmlall':'UTF-8'}{literal},
cuotealo: {/literal}{$cuetealo|escape:'htmlall':'UTF-8'}{literal}
},
installments: true,
style: {
bannerColor: '{/literal}{$color_pallete[0]|escape:'htmlall':'UTF-8'}{literal}',
imageBanner: '',
buttonBackground: '{/literal}{$color_pallete[1]|escape:'htmlall':'UTF-8'}{literal}',
menuColor: '{/literal}{$color_pallete[1]|escape:'htmlall':'UTF-8'}{literal}',
linksColor: '{/literal}{$color_pallete[1]|escape:'htmlall':'UTF-8'}{literal}',
buttontext: '{/literal}{$color_pallete[0]|escape:'htmlall':'UTF-8'}{literal}',
priceColor: '{/literal}{$color_pallete[1]|escape:'htmlall':'UTF-8'}{literal}',
logo: '{/literal}{$url_logo|escape:'htmlall':'UTF-8'}{literal}'
}
});

$('#payment-confirmation > .ps-shown-by-js > button').click(function (e) {
var myPaymentMethodSelected = $('.payment-options').find("input[data-module-name='culqi']").is(':checked');
if (myPaymentMethodSelected) {
Expand All @@ -215,6 +188,124 @@

});
});

var Culqi = null

function setCheckout() {
const publicKey = setPublicKey();
const config = setConfig();
Culqi = new CulqiCheckout(publicKey, config);
Culqi.culqi = culqi
Culqi.open();
}

function setConfig() {
const settings = setSetting();
const client = setClient();
const options = setOptions();
const appearance = setAppearance();
const config = {
settings,
client,
options,
appearance
};

return config
}

function setPublicKey() {
return '{/literal}{$llave_publica|escape:'htmlall':'UTF-8'}{literal}';
}

function setSetting() {
const setting = {
title: '{/literal}{$commerce|escape:'htmlall':'UTF-8'}{literal}',
currency: '{/literal}{$currency|escape:'htmlall':'UTF-8'}{literal}',
amount: {/literal}{$total|escape:'htmlall':'UTF-8'}{literal},
culqiclient: 'prestashop',
culqiclientversion:'{/literal}{$psversion|escape:'htmlall':'UTF-8'}{literal}',
culqipluginversion: '{/literal}{$culqipluginversion|escape:'htmlall':'UTF-8'}{literal}'
}

// Agregar el orden si existe
if (orderid != '') {
setting.order = orderid;
}

// Agregar llave publica si existe
if('{/literal}{$rsa_id|escape:'htmlall':'UTF-8'}{literal}' && `{/literal}{$rsa_pk|escape:'htmlall':'UTF-8'}{literal}`) {
setting.xculqirsaid = '{/literal}{$rsa_id|escape:'htmlall':'UTF-8'}{literal}';
setting.rsapublickey = `{/literal}{$rsa_pk|escape:'htmlall':'UTF-8'}{literal}`;
}

return setting;
}

function setClient() {
const client = {
email: '{/literal}{$email|escape:'htmlall':'UTF-8'}{literal}'
};

return client;
}

function setPaymentMethods() {
const paymentMethods = {
tarjeta: {/literal}{$tarjeta|escape:'htmlall':'UTF-8'}{literal},
yape: {/literal}{$yape|escape:'htmlall':'UTF-8'}{literal},
billetera: {/literal}{$billetera|escape:'htmlall':'UTF-8'}{literal},
bancaMovil: {/literal}{$banca_movil|escape:'htmlall':'UTF-8'}{literal},
agente: {/literal}{$agente|escape:'htmlall':'UTF-8'}{literal},
cuotealo: {/literal}{$cuetealo|escape:'htmlall':'UTF-8'}{literal},
}

return paymentMethods;
}

function setOptions() {
const paymentMethods = setPaymentMethods();

const options = {
lang: 'auto',
installments: true,
modal: true,
paymentMethods,
paymentMethodsSort: Object.keys(paymentMethods)
}
return options;
}

function setAppearance() {
const appearence = {
theme: "default",
hiddenCulqiLogo: false,
hiddenBannerContent: false,
hiddenBanner: false,
hiddenToolBarAmount: false,
menuType: "sidebar", // sidebar / sliderTop / select
logo: '{/literal}{$url_logo|escape:'htmlall':'UTF-8'}{literal}'
}

const colorPositionOne = '{/literal}{$color_pallete[0]|escape:'htmlall':'UTF-8'}{literal}';
const colorPositionTwo = '{/literal}{$color_pallete[1]|escape:'htmlall':'UTF-8'}{literal}';
if (colorPositionOne != '' && colorPositionTwo != '') {
const defaultStyle = {};
defaultStyle.bannerColor = colorPositionOne;
defaultStyle.buttonBackground = colorPositionTwo;
defaultStyle.menuColor = colorPositionTwo
defaultStyle.linksColor = colorPositionTwo;
defaultStyle.priceColor = colorPositionTwo;

appearence.defaultStyle = defaultStyle;
}

return appearence;
}

function fn_mc_sonic(){
$('body').append(`<div style="
width: 100%;
Expand Down Expand Up @@ -242,29 +333,6 @@
location.href = success_url;
}, 2000);
}
function getSettings(order = false) {
let args_settings = {
title: '{/literal}{$commerce|escape:'htmlall':'UTF-8'}{literal}',
currency: '{/literal}{$currency|escape:'htmlall':'UTF-8'}{literal}',
amount: {/literal}{$total|escape:'htmlall':'UTF-8'}{literal},
culqiclient: 'prestashop',
culqiclientversion: '{/literal}{$psversion|escape:'htmlall':'UTF-8'}{literal}',
culqipluginversion: '{/literal}{$culqipluginversion|escape:'htmlall':'UTF-8'}{literal}',
};

console.log(args_settings);

if(order) {
args_settings.order = order;
}

if('{/literal}{$rsa_id|escape:'htmlall':'UTF-8'}{literal}' && `{/literal}{$rsa_pk|escape:'htmlall':'UTF-8'}{literal}`) {
args_settings.xculqirsaid = '{/literal}{$rsa_id|escape:'htmlall':'UTF-8'}{literal}';
args_settings.rsapublickey = `{/literal}{$rsa_pk|escape:'htmlall':'UTF-8'}{literal}`;
}

Culqi.settings(args_settings);
}

function generateOrder(e, device) {
window.device = device;
Expand All @@ -275,31 +343,29 @@
type: "POST",
dataType: 'json',
success: function (response) {
console.log('response:::', response);
getSettings(response);
console.log('Se genero una orden:::', response);
orderid = response;
setCheckout()
$('#buyButton').removeAttr('disabled');
Culqi.open();
$('#showresult').hide();
e.preventDefault();
},
error: function (error) {
console.log('error:::', error);
console.log('Error al generar orden :::', error);
$('#showresult').show();
getSettings();
orderid = 'ungenereted';
orderid = ''
setCheckout()
$('#buyButton').removeAttr('disabled');
Culqi.open();
$('#showresult').hide();
e.preventDefault();
}
});
} else {
$('#showresult').show();
getSettings();
orderid = 'ungenereted';
console.log('No se genero orden');
orderid = ''
setCheckout()
$('#buyButton').removeAttr('disabled');
Culqi.open();
$('#showresult').hide();
e.preventDefault();
}
Expand Down Expand Up @@ -372,7 +438,7 @@
if (!Culqi.isOpen) {
run_waitMe();
clearInterval(id);
var orderid = Culqi.order['id'];
var orderid = culqi_order_id;
var url = fnReplace("{/literal}{$link->getModuleLink('culqi', 'postpaymentpending', [], true)|escape:'htmlall':'UTF-8'}{literal}");
location.href = url + '?ps_order_id=' + ps_order_id;
}
Expand All @@ -390,7 +456,7 @@
$(document).ajaxComplete(function () {
});

var installments = (Culqi.token.metadata.installments == undefined) ? 0 : Culqi.token.metadata.installments;
var installments = (Culqi.token.metadata == undefined || Culqi.token.metadata.installments == undefined) ? 0 : Culqi.token.metadata.installments;
$.ajax({
url: fnReplace("{/literal}{$link->getModuleLink('culqi', 'chargeajax', [], true)|escape:'htmlall':'UTF-8'}{literal}"),
data: {
Expand Down Expand Up @@ -474,8 +540,6 @@
}

}

window.culqi = culqi;

function run_waitMe() {
$('body').waitMe({
Expand Down
36 changes: 28 additions & 8 deletions views/templates/hook/setting.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,7 @@
<input required="true" type="text" name="CULQI_RSA_ID" id="CULQI_RSA_ID"
value="{$fields_value.CULQI_RSA_ID|escape:'htmlall':'UTF-8'}" class="">
<span id="errorrsaid" class="form-text text-muted"
style="display: none; color: red; font-size: 0.8rem !important;">RSA Id incorrecto.</span>
style="display: none; color: red; font-size: 0.8rem !important;">Ingrese el RSA Id.</span>
<span class="form-text text-muted"> Ingresa tu RSA Id. </span>
</div>
</div>
Expand All @@ -1919,8 +1919,8 @@
</label>
<div class="col-lg-8">
<textarea rows="9" required="true" type="text" name="CULQI_RSA_PK" id="CULQI_RSA_PK">{$fields_value.CULQI_RSA_PK|escape:'htmlall':'UTF-8'}</textarea>
<span id="errorrsaid" class="form-text text-muted"
style="display: none; color: red; font-size: 0.8rem !important;">RSA PK incorrecto.</span>
<span id="errorrsapk" class="form-text text-muted"
style="display: none; color: red; font-size: 0.8rem !important;">Ingrese el RSA Publickey.</span>
<span class="form-text text-muted"> Ingresa tu RSA Publickey. </span>
</div>
</div>
Expand Down Expand Up @@ -1951,7 +1951,7 @@
<div class="preview-checkout__banner" id="palette-left">
<div class="banner-logo">
<img id="logo"
src="https://culqi-static-files.s3.amazonaws.com/v4/v4-checkout/brand.svg"
src="https://static.culqi.com/v4/v4-checkout/brand.svg"
alt="logo">
</div>
<div class="banner-title">
Expand Down Expand Up @@ -2156,7 +2156,7 @@

</div>
<div class="image">
<img src="https://culqi-static-files.s3.amazonaws.com/v4/v4-checkout/brand.svg"
<img src="https://static.culqi.com/v4/v4-checkout/brand.svg"
alt="logo">
</div>
</div>
Expand Down Expand Up @@ -2705,7 +2705,7 @@
jQuery('#contact-popup').show()
}
jQuery('#module_form').submit(function (e) {
console.log('hi save');
var llavepublica = jQuery('#CULQI_LLAVE_PUBLICA').val().split('_');
var llaveprivada = jQuery('#CULQI_LLAVE_SECRETA').val().split('_');
var timexp = jQuery('#CULQI_TIMEXP').val();
Expand All @@ -2718,7 +2718,17 @@
jQuery('#errorseckey').css('display', 'none');
jQuery('#errortimeexp').css('display', 'none');
if (jQuery('#integracion').is(':checked')) {
if (llavepublica.length == 1) {
jQuery('#errorpubkey').html('Ingrese su llave pública');
jQuery('#errorpubkey').css('display', 'block');
hasError = '1';
}
if (llaveprivada.length == 1) {
jQuery('#errorseckey').html('Ingrese su llave privada');
jQuery('#errorseckey').css('display', 'block');
hasError = '1';
}
if (jQuery('#integracion').is(':checked') && hasError == '0') {
if (!(llavepublica.length == 3 && llavepublica[1] == 'test')) {
jQuery('#errorpubkey').html('La llave pública no pertenece al ambiente de integración');
jQuery('#errorpubkey').css('display', 'block');
Expand All @@ -2732,7 +2742,7 @@
hasError = '1';
}
}
if (jQuery('#produccion').is(':checked')) {
if (jQuery('#produccion').is(':checked') && hasError == '0') {
if (!(llavepublica.length == 3 && llavepublica[1] == 'live')) {
jQuery('#errorpubkey').html('La llave pública no pertenece al ambiente de producción');
jQuery('#errorpubkey').css('display', 'block');
Expand Down Expand Up @@ -2760,6 +2770,16 @@
hasError = '1';
}
if (jQuery('#CULQI_RSA_ID').val() === '' && jQuery('#CULQI_RSA_PK').val()){
jQuery('#errorrsaid').css('display', 'block');
hasError = '1';
}
if (jQuery('#CULQI_RSA_ID').val() && jQuery('#CULQI_RSA_PK').val() === '' ){
jQuery('#errorrsapk').css('display', 'block');
hasError = '1';
}
if (hasError == '1') {
e.preventDefault();
return false;
Expand Down

0 comments on commit c896900

Please sign in to comment.