[-] MO: Add infos to Payment_cc table after validate payment and fix test account test, url generation)

This commit is contained in:
vSchoener
2011-10-24 15:17:07 +00:00
parent 6cbe60b948
commit 96fecb4273
3 changed files with 89 additions and 19 deletions
+65 -9
View File
@@ -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);
}
}
?>
+9 -1
View File
@@ -63,7 +63,7 @@
<label style="margin-left: 50px;display: block;width: 85px;float: left;">{l s='Full name' mod='authorizeaim'}</label> <input type="text" name="name" size="20" maxlength="25S" /><img src="{$module_dir}secure.png" alt="" style="margin-left: 5px;" /><br /><br />
<label style="margin-left: 50px;display: block;width: 85px;float: left;">{l s='Card number' mod='authorizeaim'}</label> <input type="text" id="ccn" name="x_card_num" size="16" maxlength="16" autocomplete="Off"/><img src="{$module_dir}secure.png" alt="" style="margin-left: 5px;" /><br /><br />
<label style="margin-left: 50px;display: block;width: 85px;float: left;">{l s='Expiration date' mod='authorizeaim'}</label>
<select name="x_exp_date_m" style="width: 40px;">{section name=date_m start=01 loop=13}
<select id="x_exp_date_m" name="x_exp_date_m" style="width:60px;">{section name=date_m start=01 loop=13}
<option value="{$smarty.section.date_m.index}">{$smarty.section.date_m.index}</option>{/section}
</select>
/
@@ -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(){
+15 -9
View File
@@ -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);