[+] 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:
vSchoener
2011-10-27 00:58:24 +00:00
parent 4c93b5fea5
commit 2804ac0d2a
3 changed files with 62 additions and 36 deletions
+41 -6
View File
@@ -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())
@@ -75,6 +78,18 @@ abstract class PaymentModuleCore extends Module
return false; return false;
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
@@ -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 ?
@@ -153,7 +171,7 @@ abstract class PaymentModuleCore extends Module
Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($order->id_cart)); Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($order->id_cart));
die($errorMessage); die($errorMessage);
} }
// Next ! // Next !
if ($result AND isset($order->id)) if ($result AND isset($order->id))
{ {
@@ -176,13 +194,14 @@ abstract class PaymentModuleCore extends Module
// Insert new Order detail list using cart for the current order // Insert new Order detail list using cart for the current order
$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);
@@ -405,6 +424,22 @@ abstract class PaymentModuleCore extends Module
die($errorMessage); die($errorMessage);
} }
} }
/**
* 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
+18 -27
View File
@@ -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))
$order = Db::getInstance()->getRow(' {
SELECT * $this->pcc->transaction_id = (string)$response[6];
FROM '._DB_PREFIX_.'orders
WHERE id_cart = '.(int)$response[7]); // 50 => Card number (XXXX0000)
$this->pcc->card_number = (string)substr($response[50], -4);
$pcc->id_order = (int)$order['id_order'];
$pcc->id_currency = (int)$order['id_currency']; // 51 => Card Mark (Visa, Master card)
$pcc->amount = (float)$response[9]; $this->pcc->card_brand = (string)$response[51];
$pcc->transaction_id = (string)$response[6];
$this->pcc->card_expiration = (string)Tools::getValue('x_exp_date');
// 50 => Card number (XXXX0000)
$pcc->card_number = (string)substr($response[50], -4); // 68 => Owner name
$this->pcc->card_holder = (string)$response[68];
// 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);
} }
} }
?> ?>
+3 -3
View File
@@ -82,9 +82,9 @@ else
$authorizeaim = new authorizeaim(); $authorizeaim = new authorizeaim();
$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);