pylenas Posted February 8, 2012 Share Posted February 8, 2012 For clients who pay from foreigns countries I need to count aditional fee (3 EUR) to bankwire payment method. I use if clause. If user is paying by EUR I add to $total += 3; 3 euros, everything seems ok - three euros counts, shows, but I get error that something wrong is gone with a payment. I think so that is some kind of protection if total amount changes - it shows this error. How to bypass such a thing? Link to comment Share on other sites More sharing options...
bellini13 Posted February 9, 2012 Share Posted February 9, 2012 where did you add 3 euros to the total? if it was inside the bankwire module, did you save the new order amount back to the database? where did you store the extra 3 euros? Link to comment Share on other sites More sharing options...
pylenas Posted February 9, 2012 Author Share Posted February 9, 2012 I modified bankwire.php and added lines in 175 row: $viso = $cart->getOrderTotal(true, Cart::BOTH); if ($cart->id_currency == 5){ $viso += 3; } and in 212 line if ($cart->id_currency == 5){ $params['total_to_pay'] += 3; } so it looks like this <?php /* * 2007-2011 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 1.4 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_CAN_LOAD_FILES_')) exit; class BankWire extends PaymentModule { private $_html = ''; private $_postErrors = array(); public $details; public $owner; public $address; public function __construct() { $this->name = 'bankwire'; $this->tab = 'payments_gateways'; $this->version = '0.5'; $this->author = 'PrestaShop'; $this->currencies = true; $this->currencies_mode = 'checkbox'; $config = Configuration::getMultiple(array('BANK_WIRE_DETAILS', 'BANK_WIRE_OWNER', 'BANK_WIRE_ADDRESS')); if (isset($config['BANK_WIRE_OWNER'])) $this->owner = $config['BANK_WIRE_OWNER']; if (isset($config['BANK_WIRE_DETAILS'])) $this->details = $config['BANK_WIRE_DETAILS']; if (isset($config['BANK_WIRE_ADDRESS'])) $this->address = $config['BANK_WIRE_ADDRESS']; parent::__construct(); $this->displayName = $this->l('Bank Wire'); $this->description = $this->l('Accept payments by bank wire.'); $this->confirmUninstall = $this->l('Are you sure you want to delete your details?'); if (!isset($this->owner) OR !isset($this->details) OR !isset($this->address)) $this->warning = $this->l('Account owner and details must be configured in order to use this module correctly.'); if (!sizeof(Currency::checkPaymentCurrencies($this->id))) $this->warning = $this->l('No currency set for this module'); } public function install() { if (!parent::install() OR !$this->registerHook('payment') OR !$this->registerHook('paymentReturn')) return false; return true; } public function uninstall() { if (!Configuration::deleteByName('BANK_WIRE_DETAILS') OR !Configuration::deleteByName('BANK_WIRE_OWNER') OR !Configuration::deleteByName('BANK_WIRE_ADDRESS') OR !parent::uninstall()) return false; return true; } private function _postValidation() { if (isset($_POST['btnSubmit'])) { if (empty($_POST['details'])) $this->_postErrors[] = $this->l('Account details are required.'); elseif (empty($_POST['owner'])) $this->_postErrors[] = $this->l('Account owner is required.'); } } private function _postProcess() { if (isset($_POST['btnSubmit'])) { Configuration::updateValue('BANK_WIRE_DETAILS', $_POST['details']); Configuration::updateValue('BANK_WIRE_OWNER', $_POST['owner']); Configuration::updateValue('BANK_WIRE_ADDRESS', $_POST['address']); } $this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('ok').'" /> '.$this->l('Settings updated').'</div>'; } private function _displayBankWire() { $this->_html .= '<img src="../modules/bankwire/bankwire.jpg" style="float:left; margin-right:15px;"><b>'.$this->l('This module allows you to accept payments by bank wire.').'</b><br /><br /> '.$this->l('If the client chooses this payment mode, the order will change its status into a \'Waiting for payment\' status.').'<br /> '.$this->l('Therefore, you must manually confirm the order as soon as you receive the wire.').'<br /><br /><br />'; } private function _displayForm() { $this->_html .= '<form action="'.$_SERVER['REQUEST_URI'].'" method="post"> <fieldset> <legend><img src="../img/admin/contact.gif" />'.$this->l('Contact details').'</legend> <table border="0" width="500" cellpadding="0" cellspacing="0" id="form"> <tr><td colspan="2">'.$this->l('Please specify the bank wire account details for customers').'.<br /><br /></td></tr> <tr><td width="130" style="height: 35px;">'.$this->l('Account owner').'</td><td><input type="text" name="owner" value="'.htmlentities(Tools::getValue('owner', $this->owner), ENT_COMPAT, 'UTF-8').'" style="width: 300px;" /></td></tr> <tr> <td width="130" style="vertical-align: top;">'.$this->l('Details').'</td> <td style="padding-bottom:15px;"> <textarea name="details" rows="4" cols="53">'.htmlentities(Tools::getValue('details', $this->details), ENT_COMPAT, 'UTF-8').'</textarea> <p>'.$this->l('Such as bank branch, IBAN number, BIC, etc.').'</p> </td> </tr> <tr> <td width="130" style="vertical-align: top;">'.$this->l('Bank address').'</td> <td style="padding-bottom:15px;"> <textarea name="address" rows="4" cols="53">'.htmlentities(Tools::getValue('address', $this->address), ENT_COMPAT, 'UTF-8').'</textarea> </td> </tr> <tr><td colspan="2" align="center"><input class="button" name="btnSubmit" value="'.$this->l('Update settings').'" type="submit" /></td></tr> </table> </fieldset> </form>'; } public function getContent() { $this->_html = '<h2>'.$this->displayName.'</h2>'; if (!empty($_POST)) { $this->_postValidation(); if (!sizeof($this->_postErrors)) $this->_postProcess(); else foreach ($this->_postErrors AS $err) $this->_html .= '<div class="alert error">'. $err .'</div>'; } else $this->_html .= '<br />'; $this->_displayBankWire(); $this->_displayForm(); return $this->_html; } public function execPayment($cart) { if (!$this->active) return ; if (!$this->_checkCurrency($cart)) Tools::redirectLink(__PS_BASE_URI__.'order.php'); global $cookie, $smarty; $viso = $cart->getOrderTotal(true, Cart::BOTH); if ($cart->id_currency == 5){ $viso += 3; } $smarty->assign(array( 'nbProducts' => $cart->nbProducts(), 'cust_currency' => $cart->id_currency, 'currencies' => $this->getCurrency((int)$cart->id_currency), 'total' => $viso, 'this_path' => $this->_path, 'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/' )); return $this->display(__FILE__, 'payment_execution.tpl'); } public function hookPayment($params) { if (!$this->active) return ; if (!$this->_checkCurrency($params['cart'])) return ; global $smarty; $smarty->assign(array( 'this_path' => $this->_path, 'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/' )); return $this->display(__FILE__, 'payment.tpl'); } public function hookPaymentReturn($params) { if (!$this->active) return ; global $smarty; if ($cart->id_currency == 5){ $params['total_to_pay'] += 3; } $state = $params['objOrder']->getCurrentState(); if ($state == _PS_OS_BANKWIRE_ OR $state == _PS_OS_OUTOFSTOCK_) $smarty->assign(array( 'total_to_pay' => Tools::displayPrice($params['total_to_pay'], $params['currencyObj'], false, false), 'bankwireDetails' => nl2br2($this->details), 'bankwireAddress' => nl2br2($this->address), 'bankwireOwner' => $this->owner, 'status' => 'ok', 'id_order' => $params['objOrder']->id )); else $smarty->assign('status', 'failed'); return $this->display(__FILE__, 'payment_return.tpl'); } private function _checkCurrency($cart) { $currency_order = new Currency((int)($cart->id_currency)); $currencies_module = $this->getCurrency((int)$cart->id_currency); $currency_default = Configuration::get('PS_CURRENCY_DEFAULT'); if (is_array($currencies_module)) foreach ($currencies_module AS $currency_module) if ($currency_order->id == $currency_module['id_currency']) return true; } } And modified validation.php in line 43 addint this code: if ($cart->id_currency == 5){ $total += 3; } so it looks like this <?php /* * 2007-2011 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 1.4 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ include(dirname(__FILE__).'/../../config/config.inc.php'); include(dirname(__FILE__).'/../../header.php'); include(dirname(__FILE__).'/bankwire.php'); $bankwire = new BankWire(); if ($cart->id_customer == 0 OR $cart->id_address_delivery == 0 OR $cart->id_address_invoice == 0 OR !$bankwire->active) Tools::redirectLink(__PS_BASE_URI__.'order.php?step=1'); $customer = new Customer((int)$cart->id_customer); if (!Validate::isLoadedObject($customer)) Tools::redirectLink(__PS_BASE_URI__.'order.php?step=1'); $currency = new Currency((int)(isset($_POST['currency_payement']) ? $_POST['currency_payement'] : $cookie->id_currency)); if ($cart->id_currency == 5){ $total += 3; } $total = (float)($cart->getOrderTotal(true, Cart::BOTH)); $mailVars = array( '{bankwire_owner}' => Configuration::get('BANK_WIRE_OWNER'), '{bankwire_details}' => nl2br(Configuration::get('BANK_WIRE_DETAILS')), '{bankwire_address}' => nl2br(Configuration::get('BANK_WIRE_ADDRESS')) ); $bankwire->validateOrder($cart->id, _PS_OS_BANKWIRE_, $total, $bankwire->displayName, NULL, $mailVars, (int)$currency->id, false, $customer->secure_key); $order = new Order($bankwire->currentOrder); Tools::redirectLink(__PS_BASE_URI__.'order-confirmation.php?id_cart='.$cart->id.'&id_module='.$bankwire->id.'&id_order='.$bankwire->currentOrder.'&key='.$customer->secure_key); But I get an error, where I want to pay by bankwire with added 3 euros, that something went wrong Link to comment Share on other sites More sharing options...
bellini13 Posted February 11, 2012 Share Posted February 11, 2012 in validation.php, you put your if statement above this line. so it just gets overridden. $total = (float)($cart->getOrderTotal(true, Cart::BOTH)); however i don't think that is the problem. the issue you need to solve for, is how are you going to store the extra 3 in the database? the order and invoice information is not going to reflect the extra 3, so when you call validateOrder it tries to compare the original order amount to, amount+3. They do not match and it fails. Link to comment Share on other sites More sharing options...
pylenas Posted February 13, 2012 Author Share Posted February 13, 2012 Yes this is the question that I want to solve - how to update orders total amount. As I can see you dont know how to do it too? Link to comment Share on other sites More sharing options...
bellini13 Posted February 14, 2012 Share Posted February 14, 2012 you have to add a new field to the database to track the fee amount, and then add respective coding to record the value when applicable, and then to use the value when displaying in order history, invoices etc... if you are looking for someone to do this for you, then you just need to ask. if you would like to hire a professional, you can send me a PM and we can discuss those details and prices. otherwise i would suggest you start looking at the database to determine where you could store this value, and then next in the code to determine where to use this value. Link to comment Share on other sites More sharing options...
Didrik70 Posted February 28, 2012 Share Posted February 28, 2012 Any developments here? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now