[+] CORE: Add a way to add easily transaction details (last method changed)
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9663 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -32,6 +32,9 @@ abstract class PaymentModuleCore extends Module
|
|||||||
public $currencies = true;
|
public $currencies = true;
|
||||||
public $currencies_mode = 'checkbox';
|
public $currencies_mode = 'checkbox';
|
||||||
|
|
||||||
|
/* @var object PaymentCC */
|
||||||
|
public $pcc = null;
|
||||||
|
|
||||||
public function install()
|
public function install()
|
||||||
{
|
{
|
||||||
if (!parent::install())
|
if (!parent::install())
|
||||||
@@ -76,6 +79,18 @@ abstract class PaymentModuleCore extends Module
|
|||||||
return parent::uninstall();
|
return parent::uninstall();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->pcc = new PaymentCC();
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __destruct()
|
||||||
|
{
|
||||||
|
unset($this->pcc);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate an order in database
|
* Validate an order in database
|
||||||
* Function called from a payment module
|
* Function called from a payment module
|
||||||
@@ -86,9 +101,12 @@ abstract class PaymentModuleCore extends Module
|
|||||||
* @param string $paymentMethod Payment method (eg. 'Credit card')
|
* @param string $paymentMethod Payment method (eg. 'Credit card')
|
||||||
* @param string $message Message to attach to order
|
* @param string $message Message to attach to order
|
||||||
*/
|
*/
|
||||||
public function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false, $secure_key = false, Shop $shop = null)
|
public function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown',
|
||||||
|
$message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false,
|
||||||
|
$secure_key = false, Shop $shop = null)
|
||||||
{
|
{
|
||||||
$cart = new Cart((int)($id_cart));
|
$cart = new Cart((int)($id_cart));
|
||||||
|
|
||||||
if (!$shop)
|
if (!$shop)
|
||||||
$shop = Context::getContext()->shop;
|
$shop = Context::getContext()->shop;
|
||||||
// Does order already exists ?
|
// Does order already exists ?
|
||||||
@@ -177,12 +195,13 @@ abstract class PaymentModuleCore extends Module
|
|||||||
$orderDetail = new OrderDetail($this->context);
|
$orderDetail = new OrderDetail($this->context);
|
||||||
$orderDetail->createList($order, $cart, $id_order_state);
|
$orderDetail->createList($order, $cart, $id_order_state);
|
||||||
|
|
||||||
|
$this->addPCC($order->id, $order->id_currency, $amountPaid);
|
||||||
|
|
||||||
// Insert products from cart into order_detail table
|
// Insert products from cart into order_detail table
|
||||||
$productsList = '';
|
$productsList = '';
|
||||||
$products = $cart->getProducts();
|
$products = $cart->getProducts();
|
||||||
foreach ($products AS $key => $product)
|
foreach ($products AS $key => $product)
|
||||||
{
|
{
|
||||||
|
|
||||||
$price = Product::getPriceStatic((int)($product['id_product']), false, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 6, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
$price = Product::getPriceStatic((int)($product['id_product']), false, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 6, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
||||||
$price_wt = Product::getPriceStatic((int)($product['id_product']), true, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 2, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
$price_wt = Product::getPriceStatic((int)($product['id_product']), true, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 2, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
||||||
|
|
||||||
@@ -303,8 +322,6 @@ abstract class PaymentModuleCore extends Module
|
|||||||
$history->addWithemail();
|
$history->addWithemail();
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($orderDetail);
|
|
||||||
|
|
||||||
// Set order state in order history ONLY even if the "out of stock" status has not been yet reached
|
// Set order state in order history ONLY even if the "out of stock" status has not been yet reached
|
||||||
// So you migth have two order states
|
// So you migth have two order states
|
||||||
$new_history = new OrderHistory();
|
$new_history = new OrderHistory();
|
||||||
@@ -312,6 +329,8 @@ abstract class PaymentModuleCore extends Module
|
|||||||
$new_history->changeIdOrderState((int)$id_order_state, (int)$order->id);
|
$new_history->changeIdOrderState((int)$id_order_state, (int)$order->id);
|
||||||
$new_history->addWithemail(true, $extraVars);
|
$new_history->addWithemail(true, $extraVars);
|
||||||
|
|
||||||
|
unset($orderDetail, $pcc);
|
||||||
|
|
||||||
// Order is reloaded because the status just changed
|
// Order is reloaded because the status just changed
|
||||||
$order = new Order($order->id);
|
$order = new Order($order->id);
|
||||||
|
|
||||||
@@ -406,6 +425,22 @@ abstract class PaymentModuleCore extends Module
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new PaymentCC to the order
|
||||||
|
* @var int id_order
|
||||||
|
* @var int id_currency
|
||||||
|
* @var float amount
|
||||||
|
*/
|
||||||
|
private function addPCC($id_order, $id_currency, $amount)
|
||||||
|
{
|
||||||
|
// Other information are set by the module
|
||||||
|
|
||||||
|
$this->pcc->id_order = (int)$id_order;
|
||||||
|
$this->pcc->id_currency = (int)$id_currency;
|
||||||
|
$this->pcc->amount = (float)$amount;
|
||||||
|
$this->pcc->add();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Object Address $the_address that needs to be txt formated
|
* @param Object Address $the_address that needs to be txt formated
|
||||||
* @return String the txt formated address block
|
* @return String the txt formated address block
|
||||||
|
|||||||
@@ -200,38 +200,29 @@ class authorizeAIM extends PaymentModule
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the detail of a payment - Call after un validateOrder
|
* Set the detail of a payment - Call before the validate order init
|
||||||
|
* correctly the pcc object
|
||||||
* See Authorize documentation to know the associated key => value
|
* See Authorize documentation to know the associated key => value
|
||||||
* @param array fields
|
* @param array fields
|
||||||
* @return bool success state
|
|
||||||
*/
|
*/
|
||||||
public function setTransactionDetail($response)
|
public function setTransactionDetail($response)
|
||||||
{
|
{
|
||||||
$pcc = new PaymentCC();
|
// If Exist we can store the details
|
||||||
|
if (isset($this->pcc))
|
||||||
|
{
|
||||||
|
$this->pcc->transaction_id = (string)$response[6];
|
||||||
|
|
||||||
$order = Db::getInstance()->getRow('
|
// 50 => Card number (XXXX0000)
|
||||||
SELECT *
|
$this->pcc->card_number = (string)substr($response[50], -4);
|
||||||
FROM '._DB_PREFIX_.'orders
|
|
||||||
WHERE id_cart = '.(int)$response[7]);
|
|
||||||
|
|
||||||
$pcc->id_order = (int)$order['id_order'];
|
// 51 => Card Mark (Visa, Master card)
|
||||||
$pcc->id_currency = (int)$order['id_currency'];
|
$this->pcc->card_brand = (string)$response[51];
|
||||||
$pcc->amount = (float)$response[9];
|
|
||||||
$pcc->transaction_id = (string)$response[6];
|
|
||||||
|
|
||||||
// 50 => Card number (XXXX0000)
|
$this->pcc->card_expiration = (string)Tools::getValue('x_exp_date');
|
||||||
$pcc->card_number = (string)substr($response[50], -4);
|
|
||||||
|
|
||||||
// 51 => Card Mark (Visa, Master card)
|
// 68 => Owner name
|
||||||
$pcc->card_brand = (string)$response[51];
|
$this->pcc->card_holder = (string)$response[68];
|
||||||
|
}
|
||||||
$pcc->card_expiration = (string)Tools::getValue('x_exp_date');
|
|
||||||
|
|
||||||
// 68 => Owner name
|
|
||||||
$pcc->card_holder = (string)$response[68];
|
|
||||||
$pcc->add();
|
|
||||||
|
|
||||||
unset($pcc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -83,8 +83,8 @@ else
|
|||||||
$message = $response[3];
|
$message = $response[3];
|
||||||
if ($response[0] == 1)
|
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);
|
$authorizeaim->setTransactionDetail($response);
|
||||||
|
$authorizeaim->validateOrder((int)$cart->id, Configuration::get('PS_OS_PAYMENT'), (float)$response[9], $authorizeaim->displayName, $message, NULL, NULL, false, $customer->secure_key);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$authorizeaim->validateOrder((int)$cart->id, Configuration::get('PS_OS_ERROR'), (float)$response[9], $authorizeaim->displayName, $message, NULL, NULL, false, $customer->secure_key);
|
$authorizeaim->validateOrder((int)$cart->id, Configuration::get('PS_OS_ERROR'), (float)$response[9], $authorizeaim->displayName, $message, NULL, NULL, false, $customer->secure_key);
|
||||||
|
|||||||
Reference in New Issue
Block a user