Skip to content

Commit

Permalink
fix plugin and add message for error 401
Browse files Browse the repository at this point in the history
  • Loading branch information
marti1125 committed Feb 17, 2017
1 parent b5b2065 commit bb3b30e
Show file tree
Hide file tree
Showing 39 changed files with 131 additions and 128 deletions.
1 change: 0 additions & 1 deletion assets/css/img.svg

This file was deleted.

12 changes: 8 additions & 4 deletions controllers/front/chargeajax.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<?php

class CulqiChargeAjaxModuleFrontController extends ModuleFrontController {
public function initContent() {
class CulqiChargeAjaxModuleFrontController extends ModuleFrontController
{

public function initContent()
{
parent::initContent();
$this->ajax = true;
}

public function displayAjax(){
$result = $this->module->charge($_POST["token_id"], $_POST["installments"]);
public function displayAjax()
{
$result = $this->module->charge(Tools::getValue("token_id"), Tools::getValue("installments")); //$_POST["token_id"], $_POST["installments"]
die(Tools::jsonEncode($result));
}

Expand Down
1 change: 1 addition & 0 deletions controllers/front/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
17 changes: 10 additions & 7 deletions controllers/front/payment.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

class CulqiPaymentModuleFrontController extends ModuleFrontController {
class CulqiPaymentModuleFrontController extends ModuleFrontController
{

public $ssl = true;
public $display_column_left = false;
Expand All @@ -9,21 +10,23 @@ class CulqiPaymentModuleFrontController extends ModuleFrontController {
/**
* @see FrontController::initContent()
*/
public function initContent() {
public function initContent()
{

parent::initContent();

// se agrega js y css necesarios
$this->context->controller->addCSS(__PS_BASE_URI__.'modules/'.$this->module->name.'/assets/css/culqi.css');
$this->context->controller->addCSS(__PS_BASE_URI__.'modules/'.$this->module->name.'/assets/css/waitMe.min.css');
$this->context->controller->addCSS(__PS_BASE_URI__.'modules/'.$this->module->name.'/views/css/culqi.css');
$this->context->controller->addCSS(__PS_BASE_URI__.'modules/'.$this->module->name.'/views/css/waitMe.min.css');
$this->context->controller->addJS('https://checkout.culqi.com/plugins/v2/');
$this->context->controller->addJS('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js');
$this->context->controller->addJS(__PS_BASE_URI__.'modules/'.$this->module->name.'/assets/js/waitMe.min.js');
$this->context->controller->addJS(__PS_BASE_URI__.'modules/'.$this->module->name.'/views/js/waitMe.min.js');

$cart = $this->context->cart;

if (!$this->module->checkCurrency($cart)) {
Tools::redirect('index.php?controller=order');
if (!$this->module->checkCurrency($cart))
{
Tools::redirect('index.php?controller=order');
}

$this->context->smarty->assign(array(
Expand Down
14 changes: 6 additions & 8 deletions controllers/front/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
class CulqiValidationModuleFrontController extends ModuleFrontController
{

public function initContent() {
public function initContent()
{
parent::initContent();
$this->ajax = true;
}

public function displayAjax() {
$smarty = $this->context->smarty;

public function displayAjax()
{
$respuesta = $this->module->postPayment(Tools::getValue('respuesta'));
$array = json_decode(json_encode($respuesta), true);

die(Tools::jsonEncode($array));
die(Tools::jsonEncode($respuesta));
}

}
}
1 change: 1 addition & 0 deletions controllers/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
79 changes: 46 additions & 33 deletions culqi.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
include_once dirname(__FILE__).'/libraries/culqi-php/lib/culqi.php';


class Culqi extends PaymentModule {
class Culqi extends PaymentModule
{

private $_postErrors = array();

Expand All @@ -24,20 +25,20 @@ class Culqi extends PaymentModule {

public function __construct()
{
$this->name = self::MODULE_NAME;
$this->name = 'culqi';
$this->tab = 'payments_gateways';
$this->version = '2.0.0';
$this->controllers = array('chargeajax' ,'payment', 'validation', 'postpayment');
$this->author = self::MODULE_AUTHOR;
$this->author = 'Team Culqi (Brayan Cruces, Willy Aguirre)';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.5', 'max' => _PS_VERSION_);
$this->bootstrap = true;

parent::__construct();

$this->displayName = self::MODULE_NAME_DISP;
$this->displayName = 'Culqi';
$this->description = $this->l('Acepta tarjetas de crédito y débito en tu tienda online.');
$this->confirmUninstall = $this->l('¿Estás seguro que quieres desintalar el módulo de ' . self::MODULE_NAME_DISP . '?');
$this->confirmUninstall = $this->l('¿Estás seguro que quieres desintalar el módulo de Culqi?');

}

Expand All @@ -54,49 +55,50 @@ public function install()
);
}

private function getAddress($address) {
private function getAddress($address)
{
if(empty($address->address1)) {
return $address->address2;
} else {
return $address->address1;
}
}

private function getPhone($address) {
if(empty($address->phone_mobile)) {
private function getPhone($address)
{
if(empty($address->phone_mobile))
{
return $address->phone;
} else {
return $address->phone_mobile;
}
}

private function getCustomerId() {
if ($this->context->customer->isLogged()) {
private function getCustomerId()
{
if ($this->context->customer->isLogged())
{
return (int) $this->context->customer->id;
} else {
return 0;
}
}

public function postPayment($respuestaCliente) {
CulqiPago::$codigoComercio = Configuration::get('CULQI_CODIGO_COMERCIO');
CulqiPago::$llaveSecreta = Configuration::get('CULQI_LLAVE_COMERCIO');
return json_decode(CulqiPago::decifrar($respuestaCliente));
}

public function errorPayment($mensaje) {
public function errorPayment($mensaje)
{
$smarty = $this->context->smarty;
$smarty->assign('culqi_error_pago', $mensaje);
}

/* Se crea un Cargo con la nueva api v2 de Culqi PHP */
public function charge($token_id, $installments){
public function charge($token_id, $installments)
{
try {

$cart = $this->context->cart;

$userAddress = new Address(intval($cart->id_address_invoice));
$userCountry = new Country(intval($userAddress->id_country));
$userAddress = new Address((int)$cart->id_address_invoice);
$userCountry = new Country((int)$userAddress->id_country);

$culqi = new Culqi\Culqi(array('api_key' => Configuration::get('CULQI_LLAVE_COMERCIO')));

Expand Down Expand Up @@ -128,10 +130,12 @@ public function charge($token_id, $installments){

public function hookPayment($params)
{
if (!$this->active) {
if (!$this->active)
{
return;
}
if (!$this->checkCurrency($params['cart'])) {
if (!$this->checkCurrency($params['cart']))
{
return;
}
$this->smarty->assign(array(
Expand All @@ -143,7 +147,8 @@ public function hookPayment($params)

public function hookPaymentReturn($params)
{
if (!$this->active) {
if (!$this->active)
{
return;
}
$this->smarty->assign(
Expand All @@ -159,9 +164,12 @@ public function checkCurrency($cart)
$currency_order = new Currency((int)($cart->id_currency));
$currencies_module = $this->getCurrency((int)$cart->id_currency);

if (is_array($currencies_module)) {
foreach ($currencies_module as $currency_module) {
if ($currency_order->id == $currency_module['id_currency']) {
if (is_array($currencies_module))
{
foreach ($currencies_module as $currency_module)
{
if ($currency_order->id == $currency_module['id_currency'])
{
return true;
}
}
Expand All @@ -170,7 +178,8 @@ public function checkCurrency($cart)
return false;
}

public function uninstallStates() {
public function uninstallStates()
{
if (Db::getInstance()->Execute("DELETE FROM " . _DB_PREFIX_ . "order_state WHERE id_order_state = ( SELECT value
FROM " . _DB_PREFIX_ . "configuration WHERE name = 'CULQI_STATE_OK' )") &&
Db::getInstance()->Execute("DELETE FROM " . _DB_PREFIX_ . "order_state_lang WHERE id_order_state = ( SELECT value
Expand Down Expand Up @@ -199,11 +208,13 @@ private function _postValidation()
{
if (Tools::isSubmit('btnSubmit'))
{
if (!Tools::getValue('CULQI_LLAVE_COMERCIO')) {
if (!Tools::getValue('CULQI_LLAVE_COMERCIO'))
{
$this->_postErrors[] = $this->l('El campo llave de comercio es requerido.');
}

if (!Tools::getValue('CULQI_CODIGO_COMERCIO')) {
if (!Tools::getValue('CULQI_CODIGO_COMERCIO'))
{
$this->_postErrors[] = $this->l('El campo código de comercio es requerido.');
}
}
Expand All @@ -221,7 +232,8 @@ public function getContent()
if (Tools::isSubmit('btnSubmit'))
{
$this->_postValidation();
if (!count($this->_postErrors)) {
if (!count($this->_postErrors))
{
$this->_postProcess();
} else {
foreach ($this->_postErrors as $err) {
Expand All @@ -236,7 +248,8 @@ public function getContent()
return $this->_html;
}

private function createStates() {
private function createStates()
{
if (!Configuration::get('CULQI_STATE_OK'))
{
$order_state = new OrderState();
Expand All @@ -262,7 +275,7 @@ private function createStates() {
$order_state->name = array();
foreach (Language::getLanguages() as $language) {
$order_state->name[$language['id_lang']] = 'Incorrecto';
}
}
$order_state->send_email = false;
$order_state->color = '#FF2843';
$order_state->module_name = 'culqi';
Expand Down Expand Up @@ -347,7 +360,7 @@ private function _postProcess()
}

public function removeComma($amount) {
return str_replace(".","",str_replace( ',', '', number_format($amount,2,'.',',')));
return str_replace(".","",str_replace(',', '', number_format($amount,2,'.',',')));
}

}
Expand Down
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/Requests/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/Requests/library/Requests/Auth/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/Requests/library/Requests/Cookie/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/Requests/library/Requests/Exception/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/Requests/library/Requests/Proxy/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/Requests/library/Requests/Response/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/Requests/library/Requests/Transport/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/Requests/library/Requests/Utility/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/Requests/library/Requests/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/Requests/library/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/culqi-php/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/culqi-php/lib/Culqi/Error/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/culqi-php/lib/Culqi/Lang/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/culqi-php/lib/Culqi/Lang/messages/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/culqi-php/lib/Culqi/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/culqi-php/lib/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions libraries/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
File renamed without changes.
1 change: 1 addition & 0 deletions views/css/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
File renamed without changes.
1 change: 1 addition & 0 deletions views/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions views/js/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
File renamed without changes.
1 change: 1 addition & 0 deletions views/templates/front/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
Loading

0 comments on commit bb3b30e

Please sign in to comment.