From 7e582da71413a2c7657e115e5686c01e766838f3 Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Fri, 24 Dec 2021 14:27:51 +0530 Subject: [PATCH] Wrong amount in the payment gateway PaymentReturn Hook --- classes/order/Order.php | 22 ++++++++++-------- modules/bankwire/bankwire.php | 42 ++++++++++++++++++++--------------- modules/cheque/cheque.php | 37 +++++++++++++++++------------- 3 files changed, 58 insertions(+), 43 deletions(-) diff --git a/classes/order/Order.php b/classes/order/Order.php index 6b16d5afe..8a011ef90 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -1911,18 +1911,22 @@ public function getTotalPaid($currency = null) } /** - * Get the sum of total_paid_tax_incl of the orders with similar reference - * - * @since 1.5.0.1 + * Get the sum of total_paid_tax_incl/advance_paid_amount of the orders with similar reference + * @param integer $getAdvancePaid (send 1 if want total advance paid amount) * @return float */ - public function getOrdersTotalPaid() + public function getOrdersTotalPaid($getAdvancePaid = 0) { - return Db::getInstance()->getValue(' - SELECT SUM(total_paid_tax_incl) - FROM `'._DB_PREFIX_.'orders` - WHERE `reference` = \''.pSQL($this->reference).'\' - AND `id_cart` = '.(int)$this->id_cart); + $sql = 'SELECT'; + if ($getAdvancePaid) { + $sql .= ' SUM(advance_paid_amount)'; + } else { + $sql .= ' SUM(total_paid_tax_incl)'; + } + $sql .= 'FROM `'._DB_PREFIX_.'orders` WHERE `reference` = \''.pSQL($this->reference). + '\' AND `id_cart` = '.(int)$this->id_cart; + + return Db::getInstance()->getValue($sql); } /** diff --git a/modules/bankwire/bankwire.php b/modules/bankwire/bankwire.php index c1d8789ef..8be2d6214 100644 --- a/modules/bankwire/bankwire.php +++ b/modules/bankwire/bankwire.php @@ -188,31 +188,37 @@ public function hookPaymentReturn($params) if (!$this->active) { return; } + $objOrder = $params['objOrder']; - $cart = new Cart($objOrder->id_cart); - $state = $objOrder->getCurrentState(); - if (in_array($state, array(Configuration::get('PS_OS_BANKWIRE'), Configuration::get('PS_OS_OUTOFSTOCK'), Configuration::get('PS_OS_OUTOFSTOCK_UNPAID')))) { - if ($objOrder->is_advance_payment) { - $order_total = $objOrder->advance_paid_amount; + $orderState = $objOrder->getCurrentState(); + $smartyVars = array(); + if (in_array( + $orderState, + array( + Configuration::get('PS_OS_BANKWIRE'), + Configuration::get('PS_OS_OUTOFSTOCK'), + Configuration::get('PS_OS_OUTOFSTOCK_UNPAID') + ) + )) { + $objCart = new Cart($objOrder->id_cart); + if ($objCart->is_advance_payment) { + $cartTotal = $objOrder->getOrdersTotalPaid(1); } else { - $order_total = $objOrder->total_paid; + $cartTotal = $objOrder->getOrdersTotalPaid(); } - $this->smarty->assign(array( - 'total_to_pay' => Tools::displayPrice($order_total, $params['currencyObj'], false), - 'bankwireDetails' => Tools::nl2br($this->details), - 'bankwireAddress' => Tools::nl2br($this->address), - 'bankwireOwner' => $this->owner, - 'status' => 'ok', - 'id_order' => $objOrder->id - )); - if (isset($objOrder->reference) && !empty($objOrder->reference)) { - $this->smarty->assign('reference', $objOrder->reference); - } + $smartyVars['total_to_pay'] = Tools::displayPrice($cartTotal, $params['currencyObj'], false); + $smartyVars['bankwireDetails'] = Tools::nl2br($this->details); + $smartyVars['bankwireAddress'] = Tools::nl2br($this->address); + $smartyVars['bankwireOwner'] = $this->owner; + $smartyVars['status'] = 'ok'; + $smartyVars['id_order'] = $objOrder->id; + $smartyVars['reference'] = $objOrder->reference; } else { - $this->smarty->assign('status', 'failed'); + $smartyVars['status'] = 'failed'; } + $this->smarty->assign($smartyVars); return $this->display(__FILE__, 'payment_return.tpl'); } diff --git a/modules/cheque/cheque.php b/modules/cheque/cheque.php index 6cd01053c..4c5591669 100644 --- a/modules/cheque/cheque.php +++ b/modules/cheque/cheque.php @@ -173,28 +173,33 @@ public function hookPaymentReturn($params) return; } $objOrder = $params['objOrder']; - $cart = new Cart($objOrder->id_cart); - $state = $objOrder->getCurrentState(); - if (in_array($state, array(Configuration::get('PS_OS_CHEQUE'), Configuration::get('PS_OS_OUTOFSTOCK'), Configuration::get('PS_OS_OUTOFSTOCK_UNPAID')))) { - if ($objOrder->is_advance_payment) { - $order_total = $objOrder->advance_paid_amount; + $orderState = $objOrder->getCurrentState(); + if (in_array( + $orderState, + array( + Configuration::get('PS_OS_CHEQUE'), + Configuration::get('PS_OS_OUTOFSTOCK'), + Configuration::get('PS_OS_OUTOFSTOCK_UNPAID') + ) + )) { + $objCart = new Cart($objOrder->id_cart); + if ($objCart->is_advance_payment) { + $cartTotal = $objOrder->getOrdersTotalPaid(1); } else { - $order_total = $objOrder->total_paid; + $cartTotal = $objOrder->getOrdersTotalPaid(); } - $this->smarty->assign(array( - 'total_to_pay' => Tools::displayPrice($order_total, $params['currencyObj'], false), - 'chequeName' => $this->chequeName, - 'chequeAddress' => Tools::nl2br($this->address), - 'status' => 'ok', - 'id_order' => $objOrder->id - )); - if (isset($objOrder->reference) && !empty($objOrder->reference)) - $this->smarty->assign('reference', $objOrder->reference); + $smartyVars['total_to_pay'] = Tools::displayPrice($cartTotal, $params['currencyObj'], false); + $smartyVars['chequeName'] = $this->chequeName; + $smartyVars['chequeAddress'] = Tools::nl2br($this->address); + $smartyVars['status'] = 'ok'; + $smartyVars['id_order'] = $objOrder->id; + $smartyVars['reference'] = $objOrder->reference; } else { - $this->smarty->assign('status', 'failed'); + $smartyVars['status'] = 'failed'; } + $this->smarty->assign($smartyVars); return $this->display(__FILE__, 'payment_return.tpl'); }