From 96fecb42734f74add2ee6a44e15a00833a6f5dd0 Mon Sep 17 00:00:00 2001 From: vSchoener Date: Mon, 24 Oct 2011 15:17:07 +0000 Subject: [PATCH] [-] MO: Add infos to Payment_cc table after validate payment and fix test account test, url generation) --- modules/authorizeaim/authorizeaim.php | 74 +++++++++++++++++++++++---- modules/authorizeaim/authorizeaim.tpl | 10 +++- modules/authorizeaim/validation.php | 24 +++++---- 3 files changed, 89 insertions(+), 19 deletions(-) diff --git a/modules/authorizeaim/authorizeaim.php b/modules/authorizeaim/authorizeaim.php index c204e2eaf..554039406 100755 --- a/modules/authorizeaim/authorizeaim.php +++ b/modules/authorizeaim/authorizeaim.php @@ -25,6 +25,14 @@ * International Registered Trademark & Property of PrestaShop SA */ +function logvardump($var) +{ + ob_start(); + var_dump($var); + $result = ob_get_clean(); + file_put_contents(dirname(__FILE__).'/debugValidation.txt', $result, FILE_APPEND); +} + if (!defined('_PS_VERSION_')) exit; @@ -34,19 +42,31 @@ class authorizeAIM extends PaymentModule { $this->name = 'authorizeaim'; $this->tab = 'payments_gateways'; - $this->version = '1.2.2'; + $this->version = '1.3'; $this->author = 'PrestaShop'; $this->limited_countries = array('us'); $this->need_instance = 0; - parent::__construct(); + parent::__construct(); - $this->displayName = 'Authorize.net AIM (Advanced Integration Method)'; - $this->description = $this->l('Receive payment with Authorize.net'); + $this->displayName = 'Authorize.net AIM (Advanced Integration Method)'; + $this->description = $this->l('Receive payment with Authorize.net'); /* For 1.4.3 and less compatibility */ - $updateConfig = array('PS_OS_CHEQUE' => 1, 'PS_OS_PAYMENT' => 2, 'PS_OS_PREPARATION' => 3, 'PS_OS_SHIPPING' => 4, 'PS_OS_DELIVERED' => 5, 'PS_OS_CANCELED' => 6, - 'PS_OS_REFUND' => 7, 'PS_OS_ERROR' => 8, 'PS_OS_OUTOFSTOCK' => 9, 'PS_OS_BANKWIRE' => 10, 'PS_OS_PAYPAL' => 11, 'PS_OS_WS_PAYMENT' => 12); + $updateConfig = array( + 'PS_OS_CHEQUE' => 1, + 'PS_OS_PAYMENT' => 2, + 'PS_OS_PREPARATION' => 3, + 'PS_OS_SHIPPING' => 4, + 'PS_OS_DELIVERED' => 5, + 'PS_OS_CANCELED' => 6, + 'PS_OS_REFUND' => 7, + 'PS_OS_ERROR' => 8, + 'PS_OS_OUTOFSTOCK' => 9, + 'PS_OS_BANKWIRE' => 10, + 'PS_OS_PAYPAL' => 11, + 'PS_OS_WS_PAYMENT' => 12); + foreach ($updateConfig as $u => $v) if (!Configuration::get($u) || (int)Configuration::get($u) < 1) { @@ -54,7 +74,7 @@ class authorizeAIM extends PaymentModule Configuration::updateValue($u, constant('_'.$u.'_')); else Configuration::updateValue($u, $v); - } + } /* Check if cURL is enabled */ if (!is_callable('curl_exec')) @@ -63,7 +83,8 @@ class authorizeAIM extends PaymentModule public function install() { - return (parent::install() AND $this->registerHook('orderConfirmation') AND $this->registerHook('payment') AND Configuration::updateValue('AUTHORIZE_AIM_DEMO', 1)); + return (parent::install() AND $this->registerHook('orderConfirmation') AND + $this->registerHook('payment') AND Configuration::updateValue('AUTHORIZE_AIM_DEMO', 1)); } public function uninstall() @@ -184,6 +205,41 @@ class authorizeAIM extends PaymentModule return $this->display(__FILE__, 'authorizeaim.tpl'); } - } + } + + /** + * Set the detail of a payment - Call after un validateOrder + * See Authorize documentation to know the associated key => value + * @param array fields + * @return bool success state + */ + public function setTransactionDetail($response) + { + $pcc = new PaymentCC(); + + $order = Db::getInstance()->getRow(' + SELECT * + FROM '._DB_PREFIX_.'orders + WHERE id_cart = '.(int)$response[7]); + + $pcc->id_order = (int)$order['id_order']; + $pcc->id_currency = (int)$order['id_currency']; + $pcc->amount = (float)$response[9]; + $pcc->transaction_id = (string)$response[6]; + + // 50 => Card number (XXXX0000) + $pcc->card_number = (string)$response[50]; + + // 51 => Card Mark (Visa, Master card) + $pcc->card_brand = (string)$response[51]; + + $pcc->card_expiration = (string)Tools::getValue('x_exp_date'); + + // 68 => Owner name + $pcc->card_holder = (string)$response[68]; + $pcc->add(); + + unset($pcc); + } } ?> diff --git a/modules/authorizeaim/authorizeaim.tpl b/modules/authorizeaim/authorizeaim.tpl index 41009157c..41ef2305c 100755 --- a/modules/authorizeaim/authorizeaim.tpl +++ b/modules/authorizeaim/authorizeaim.tpl @@ -63,7 +63,7 @@



- {section name=date_m start=01 loop=13} {/section} / @@ -82,6 +82,14 @@ var mess_error = "{l s='Your card number is false' mod='authorizeaim' js=1}"; {literal} $(document).ready(function(){ + $('#x_exp_date_m').children('option').each(function() + { + if ($(this).val() < 10) + { + $(this).val('0' + $(this).val()); + $(this).html($(this).val()) + } + }); $('#click_authorizeaim').click(function(e){ e.preventDefault(); $('#click_authorizeaim').fadeOut("fast",function(){ diff --git a/modules/authorizeaim/validation.php b/modules/authorizeaim/validation.php index 17e3e4832..c8b96ffa2 100755 --- a/modules/authorizeaim/validation.php +++ b/modules/authorizeaim/validation.php @@ -29,24 +29,27 @@ include(dirname(__FILE__). '/../../init.php'); include(dirname(__FILE__). '/authorizeaim.php'); /* Transform the POST from the template to a GET for the CURL */ -if (isset($_POST['x_exp_date']) && isset($_POST['x_exp_date_m']) && isset($_POST['x_exp_date_y']) && isset($_POST['x_exp_date_y']) && isset($_POST['name'])) +if (isset($_POST['x_exp_date_m']) && isset($_POST['x_exp_date_y'])) { $_POST['x_exp_date'] = $_POST['x_exp_date_m'].$_POST['x_exp_date_y']; unset($_POST['x_exp_date_m']); unset($_POST['x_exp_date_y']); - unset($_POST['name']); } $postString = ''; -foreach ($_POST AS $key => $value) - if ($key != "x_exp_date_m" OR $key != "x_exp_date_m") - $postString .= $key.'='.urlencode($value).'&'; -$postString .= 'x_exp_date='.str_pad($_POST["x_exp_date_m"], 2, "0",STR_PAD_LEFT).$_POST["x_exp_date_y"]; +foreach ($_POST as $key => $value) + $postString .= $key.'='.urlencode($value).'&'; -if (Tools::getValue('AUTHORIZE_AIM_DEMO')) - $postString .= 'Test_Mode=TRUE'; +$postString = trim($postString, '&'); + +$url = 'https://secure.authorize.net/gateway/transact.dll'; +if (Configuration::get('AUTHORIZE_AIM_DEMO')) +{ + $postString .= '&x_test_request=TRUE'; + $url = 'https://test.authorize.net/gateway/transact.dll'; +} /* Do the CURL request ro Authorize.net */ -$request = curl_init('https://secure.authorize.net/gateway/transact.dll'); +$request = curl_init($url); curl_setopt($request, CURLOPT_HEADER, 0); curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($request, CURLOPT_POSTFIELDS, $postString); @@ -79,7 +82,10 @@ else $authorizeaim = new authorizeaim(); $message = $response[3]; if ($response[0] == 1) + { $authorizeaim->validateOrder((int)$cart->id, Configuration::get('PS_OS_PAYMENT'), (float)$response[9], $authorizeaim->displayName, $message, NULL, NULL, false, $customer->secure_key); + $authorizeaim->setTransactionDetail($response); + } else $authorizeaim->validateOrder((int)$cart->id, Configuration::get('PS_OS_ERROR'), (float)$response[9], $authorizeaim->displayName, $message, NULL, NULL, false, $customer->secure_key);