Skip to content

Commit

Permalink
Merge pull request #21 from Nicerova7/master
Browse files Browse the repository at this point in the history
Fixed postpayment
  • Loading branch information
william-muro-culqi authored Sep 1, 2020
2 parents 8147236 + 034a1cf commit 7e90166
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
5 changes: 3 additions & 2 deletions controllers/front/chargeajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function initContent()
public function displayAjax()
{
$result = $this->module->charge(Tools::getValue("token_id"), Tools::getValue("installments")); //$_POST["token_id"], $_POST["installments"]
if($result->id) Configuration::updateValue($result->id,'generatedCulqi');
die(Tools::jsonEncode($result));
}

Expand All @@ -20,8 +21,8 @@ public function displayAjaxOrder()
{
error_log('Actualizando orden');
$result = $this->module->updateOrder(Tools::getValue("order_id")); //$_POST["cart_id"]

if($result->id) Configuration::updateValue($result->id,'generatedCulqi');
die(Tools::jsonEncode($result));
}

}
}
1 change: 1 addition & 0 deletions controllers/front/orderajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public function displayAjax()
{
error_log('Actualizando orden');
$result = $this->module->updateOrder( Tools::getValue("order_id")); //$_POST["cart_id"]
if($result->id) Configuration::updateValue($result->id,'generatedCulqi');
die(Tools::jsonEncode($result));
}

Expand Down
4 changes: 4 additions & 0 deletions controllers/front/postpayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public function initContent()

$cart = $this->context->cart;
$customer = new Customer($cart->id_customer);

if(!Configuration::get(Tools::getValue('validation'))) die($this->l('Primero, debes pagar la order...'));
if(Configuration::get(Tools::getValue('validation')) !== 'generatedCulqi') die($this->l('Primero, debes pagar la orden... '));
Configuration::deleteByName(Tools::getValue('validation'));
$this->module->validateOrder((int)$cart->id, Configuration::get('CULQI_STATE_OK'), (float)$cart->getordertotal(true), 'Culqi', null, array(), (int)$cart->id_currency, false, $customer->secure_key);
Tools::redirect('index.php?controller=order-confirmation&id_cart=' . (int)$cart->id . '&id_module=' . (int)$this->module->id . '&id_order=' . $this->module->currentOrder . '&key=' . $customer->secure_key);

Expand Down
4 changes: 4 additions & 0 deletions controllers/front/postpendingpayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public function initContent()

$cart = $this->context->cart;
$customer = new Customer($cart->id_customer);

if(!Configuration::get(Tools::getValue('validation'))) die($this->l('Primero, debes pagar la order...'));
if(Configuration::get(Tools::getValue('validation')) !== 'generatedCulqi') die($this->l('Primero, debes pagar la orden... '));
Configuration::deleteByName(Tools::getValue('validation'));
$this->module->validateOrder((int)$cart->id, Configuration::get('CULQI_STATE_PENDING'), (float)$cart->getordertotal(true), 'Culqi', null, array(), (int)$cart->id_currency, false, $customer->secure_key);
Tools::redirect('index.php?controller=order-confirmation&id_cart=' . (int)$cart->id . '&id_module=' . (int)$this->module->id . '&id_order=' . $this->module->currentOrder . '&key=' . $customer->secure_key);

Expand Down
18 changes: 9 additions & 9 deletions views/templates/front/payment_execution.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
$('body').waitMe('hide');
showResult('green',result.outcome.user_message);
Culqi.close();
redirect();
redirect(result.id);
}
if(result.object === 'error'){
$('body').waitMe('hide');
Expand Down Expand Up @@ -132,7 +132,7 @@
if(result.object === 'order'){
$('body').waitMe('hide');
console.log('Redirigiendo....');
redirectPending();
redirectPending(result.id);
}
if(result.object === 'error'){
$('body').waitMe('hide');
Expand Down Expand Up @@ -174,14 +174,14 @@
$('#showresultcontent').html(message);
}

function redirect() {
function redirect(value) {
var url = fnReplace("{/literal}{$link->getModuleLink('culqi', 'postpayment', [], true)|escape:'htmlall':'UTF-8'}{literal}");
location.href = url;
location.href = url + '?validation=' + value;
};

function redirectPending() {
function redirectPending(value) {
var url = fnReplace("{/literal}{$link->getModuleLink('culqi', 'postpendingpayment', [], true)|escape:'htmlall':'UTF-8'}{literal}");
location.href = url;
location.href = url + '?validation=' + value;
};

function fnReplace(url) {
Expand Down Expand Up @@ -244,7 +244,7 @@
if(result.object === 'charge'){
$('body').waitMe('hide');
showResult('green',result.outcome.user_message);
redirect();
redirect(result.id);
}
if(result.object === 'error'){
$('body').waitMe('hide');
Expand Down Expand Up @@ -276,9 +276,9 @@
$('#showresultcontent').html(message);
}
function redirect() {
function redirect(value) {
var url = fnReplace("{/literal}{$link->getModuleLink('culqi', 'postpayment', [], true)|escape:'htmlall':'UTF-8'}{literal}");
location.href = url;
location.href = url + '?validation=' + value;
};
function fnReplace(url) {
Expand Down

0 comments on commit 7e90166

Please sign in to comment.