Jump to content
MCyril

WORLDPAY - Payment confirmation error with multiple currencies

Recommended Posts

Hello,

I've just run into a slight problem with my Prestashop 1.3 / Worldpay 0.6 install. I display currencies in €, $ and £, but payments are all made in £ (as per WorldPay standard).

When a client confirms an order displayed in Euros (742,50 €), he actually pays the equivalent in pounds (631,13 £) through WorldPay. But then WorldPay confirms the payment amount in the display currency (631,13 €) which tells Prestashop that only a partial payment was made...

So we get a nice warning : 631,13 € paid instead of 742,50 € and an error message sent to clients.

What is going on? Does anybody know what could be happening? I've looked everywhere I could think of and am really stuck here.

I would really appreciate any guidance.

Best,
C.

Share this post


Link to post
Share on other sites

I have got the exact same problem with the WorldPay module. I use the prestashop currency changer and switch it to US Dollars. When I am taken to the Worldpay payment page it still shows EURO instead of USD. Can somebody I mean The developers of the module "Jason" or "Martin" can help us out over here ?

Share this post


Link to post
Share on other sites

Never mind . Found the problem. It lies with the currency conversion that happens in the worldpay.php file. I will upload a working copy of worldpay.php file that has currency conversion disabled. All you need to do is from the BACK OFFICE enable Customer Currency for Worldpay.

Backoffice > Payment > Currency Restrictions

Share this post


Link to post
Share on other sites

But that isn't allowed by WorldPay with single currency accounts.

They require that the currency restriction be set to the RBS account currency (i.e. Pounds).

So when people get a total of 750€ and go to the secure payment page to process their payment, RBS is requesting 750£... obviously this doesn't work for me. What is the deal?

Currency conversion display works fine in PrestaShop, but i'm getting the impression its sending the wrong information to WorldPay.

Help please ;-))))

Share this post


Link to post
Share on other sites

Never mind . Found the problem. It lies with the currency conversion that happens in the worldpay.php file. I will upload a working copy of worldpay.php file that has currency conversion disabled. All you need to do is from the BACK OFFICE enable Customer Currency for Worldpay.

Backoffice > Payment > Currency Restrictions

 

Hello Arkod,

did you ever get around to uploading the modified worldpay.php file?

Where can we find it?

Thank you for this,

C.

Share this post


Link to post
Share on other sites

Hi there, for any soldiers out there trying to get this old free worldpay module to work on their websites, here is the correction to the missing currency transformation. I also disabled the currency choice so if you select one currency that's the one you paying!

Hope this helps any lost souls out there, let me know if this worked for you :) PM if you need any help as I got it fully working !!

<?php

class Worldpay extends PaymentModule
{
	private	$_html = '';
	private $_postErrors = array();

	public function __construct()
	{
		$this->name = 'worldpay';
		$this->tab = 'payments_gateways';
		$this->version = '0.6';
		
		$this->currencies = true;
		$this->currencies_mode = 'radio';

        parent::__construct();

        /* The parent construct is required for translations */
	$this->page = basename(__FILE__, '.php');
        $this->displayName = $this->l('Worldpay');
        $this->description = $this->l('Accepts payments by Worldpay');
	$this->confirmUninstall = $this->l('Are you sure you want to delete your details ?');
	}

        public function getWPurl()
        {
	  return Configuration::get('WORLDPAY_TEST') ? 'https://select-test.worldpay.com/wcc/purchase' : 'https://select.worldpay.com/wcc/purchase';
        }

        public function getWPinstID()
        {
	  return Configuration::get('WORLDPAY_INSTID');
        }

        public function getWPtestmode()
        {
	  return Configuration::get('WORLDPAY_TEST');
        }
	
        public function getWPcallbackPW()
        {
	  return Configuration::get('WORLDPAY_CALLBACKPW');
        }
	
        public function getWPcancelMsg()
        {
 
	  $myFile = Configuration::get('WORLDPAY_CANCELMSG');
	  $fh = fopen($myFile, 'r');
	  if ($fh) {
	    $theData = fread($fh, filesize($myFile));
	    fclose($fh);
	    echo $theData;
	  }
	  return;
        }

        public function getWPsuccessMsg()
        {
 
	  $myFile = Configuration::get('WORLDPAY_SUCCESSMSG');
	  $fh = fopen($myFile, 'r');
	  if ($fh) {
	    $theData = fread($fh, filesize($myFile));
	    fclose($fh);
	    echo $theData;
	  }
	  return;
        }

	public function install()
	{
	  if (!parent::install() 
	      OR !Configuration::updateValue('WORLDPAY_INSTID', 0)
	      OR !Configuration::updateValue('WORLDPAY_TEST', 1) 
	      OR !Configuration::updateValue('WORLDPAY_CALLBACKPW', '') 
	      OR !Configuration::updateValue('WORLDPAY_CANCELMSG', 'resultC.html') 
	      OR !Configuration::updateValue('WORLDPAY_SUCCESSMSG', 'resultY.html') 
	      OR !$this->registerHook('payment'))
	    return false;
	  return true;
 	}

        public function uninstall()
        {
	  if (!Configuration::deleteByName('WORLDPAY_INSTID')  
	      OR !Configuration::deleteByName('WORLDPAY_TEST')
	      OR !Configuration::deleteByName('WORLDPAY_CALLBACKPW')
	      OR !Configuration::deleteByName('WORLDPAY_CANCELMSG')
	      OR !Configuration::deleteByName('WORLDPAY_SUCCESSMSG')
	      OR !parent::uninstall())
	    return false;
	  return true;
        }

        public function getContent()
        {
	  $this->_html = '<h2>Worldpay</h2>';
	  if (isset($_POST['submitWorldpay']))
	    {
	      if (empty($_POST['instid']))
		$this->_postErrors[] = $this->l('Worldpay Installation Id is required.');
	      if (!Validate::isInt($_POST['instid']))
		$this->_postErrors[] = $this->l('Worldpay Installation Id must be an numeric.');
	      if (empty($_POST['callbackPW']))
		$this->_postErrors[] = $this->l('Payment Response Password required.');
	      if (!isset($_POST['testmode']))
		$_POST['testmode'] = 1;
	      	if (!sizeof($this->_postErrors))
			{
			  Configuration::updateValue('WORLDPAY_INSTID', intval($_POST['instid']));
			  Configuration::updateValue('WORLDPAY_TEST', intval($_POST['testmode']));
			  Configuration::updateValue('WORLDPAY_CALLBACKPW', $_POST['callbackPW']);
			  Configuration::updateValue('WORLDPAY_CANCELMSG', $_POST['cancelMsg']);
			  Configuration::updateValue('WORLDPAY_SUCCESSMSG', $_POST['successMsg']);
			  $this->displayConf();
			}
			else{
				//$this->displayErrors();
				$this->_html .= '<div class="alert error" style="background:#FACBC7;"><h3>'.$this->l('Error').'</h3>';
				for($i=0;$i<sizeof($this->_postErrors);$i++){					  	
					$this->_html .= '- '.$this->_postErrors[$i].'<br>';									  	  	
				}
				$this->_html .= '</div>';
			}
			  
	    }

	  $this->displayWorldPay();
	  $this->displayFormSettings();
	  return $this->_html;
        }
	
        public function displayConf()
        {
               $this->_html .= '                                                                                                                                    
               <div class="conf confirm">                                                                                                                           
                       <img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />                                                                         
                       '.$this->l('Settings updated').'                                                                                                             
               </div>';
        }

        public function displayFormSettings()
        {
	  $conf = Configuration::getMultiple(array('WORLDPAY_INSTID', 'WORLDPAY_TEST', 'WORLDPAY_CALLBACKPW', 'WORLDPAY_CANCELMSG', 'WORLDPAY_SUCCESSMSG'));
	  $testmode = array_key_exists('testmode', $_POST) ? $_POST['testmode'] : (array_key_exists('WORLDPAY_TEST', $conf) ? $conf['WORLDPAY_TEST'] : '');
	  $instid = array_key_exists('instid', $_POST) ? $_POST['instid'] : (array_key_exists('WORLDPAY_INSTID', $conf) ? $conf['WORLDPAY_INSTID'] : '');
	  $callbackPW = array_key_exists('callbackPW', $_POST) ? $_POST['callbackPW'] : (array_key_exists('WORLDPAY_CALLBACKPW', $conf) ? $conf['WORLDPAY_CALLBACKPW'] : '');
	  $cancelMsg = array_key_exists('cancelMsg', $_POST) ? $_POST['cancelMsg'] : (array_key_exists('WORLDPAY_CANCELMSG', $conf) ? $conf['WORLDPAY_CANCELMSG'] : '');
	  $successMsg = array_key_exists('successMsg', $_POST) ? $_POST['successMsg'] : (array_key_exists('WORLDPAY_SUCCESSMSG', $conf) ? $conf['WORLDPAY_SUCCESSMSG'] : '');

               $this->_html .= '                                                                                                                                    
               <form action="'.$_SERVER['REQUEST_URI'].'" method="post">                                                                                            
               <fieldset>                                                                                                                                           
                       <legend><img src="../img/admin/contact.gif" />'.$this->l('Settings').'</legend>                                                              
                       <br /><label>'.$this->l('Worldpay Installation Id.').'</label>
                       <div class="margin-form"><input type="text" size="8" name="instid" value="'.htmlentities($instid, ENT_COMPAT, 'UTF-8').'" /></div>      
                       <label>'.$this->l('Test Mode.').'</label>                                                                                                  
                       <div class="margin-form">                                                                                                                    
                               <input type="radio" name="testmode" value="1" '.($testmode ? 'checked="checked"' : '').' /> '.$this->l('Yes').'
                               <input type="radio" name="testmode" value="0" '.(!$testmode ? 'checked="checked"' : '').' /> '.$this->l('No').'
                       </div>             
                       <label>'.$this->l('Response Password.').'</label>
                       <div class="margin-form">
                       <input type="text" size="24" name="callbackPW" value="'.htmlentities($callbackPW, ENT_COMPAT, 'UTF-8').'" />      
                       </div>
                       <label>'.$this->l('Success HTML file.').'</label>
                       <div class="margin-form">
                       <input type="text" size="48" name="successMsg" value="'.htmlentities($successMsg, ENT_COMPAT, 'UTF-8').'" />      
                       </div>
                       <label>'.$this->l('Cancel HTML file.').'</label>
                       <div class="margin-form">
                       <input type="text" size="48" name="cancelMsg" value="'.htmlentities($cancelMsg, ENT_COMPAT, 'UTF-8').'" />      
                       </div>
                       <br /><center><input type="submit" name="submitWorldpay" value="'.$this->l('Update settings').'" class="button" /></center>
               </fieldset>                                                                                                                                          

               </form><br /><br />  
               <fieldset class="width3">                                                                                                                            
                     <legend><img src="../img/admin/warning.gif" />'.$this->l('Information').'</legend>                                                           
                     '.$this->l('In order to use the Worldpay payment module, you will have to configure your Worldpay accounts (Test & Production)').'<br /><br />
                     '.$this->l('1. Add http://www.yoursite.com/modules/worldpay/validation.php to the "Payment Response URL" field.').'<br /><br />
                     '.$this->l('2. Check the "Payment Response enabled?" box.').'<br /><br />
                     '.$this->l('3. Enter a Payment Response password, ensure it matches password above.').'<br /><br />
                     '.$this->l('4. If you would like Worldpay to display the transaction response on your site check "Enable Shopper Response".
You will then need to specifiy a valid resultC and resultY html file using the settings above or upload these files separately to your Worldpay account.').'<br /><br />
                     <b style="color: red;">'.$this->l('All PrestaShop currencies must be also configured</b><br /> Profile > Financial Information > Currency balances').'<br />                                                                                                                                                 
               </fieldset>';
       }

	public function displayWorldPay()
	{
		$this->_html .= '
		<img src="../modules/worldpay/worldpay.gif" style="float:left; margin-right:15px;" />
		<b>'.$this->l('This module allows you to accept payments by WorldPay.').'</b><br /><br />
		'.$this->l('If the client chooses this payment mode, your WorldPay account will be automatically credited.').'<br />
		'.$this->l('You need to configure your WorldPay account first before using this module.').'
		<br /><br /><br />';
	}

	public function hookPayment($params)
	{
		global $smarty;

		$address = new Address(intval($params['cart']->id_address_invoice));
		$customer = new Customer(intval($params['cart']->id_customer));
		$currency = $this->getCurrency();
		$products = $params['cart']->getProducts();
		
		foreach ($products as $key => $product)
		{
			$products[$key]['name'] = str_replace('"', '\'', $product['name']);
			if (isset($product['attributes']))
				$products[$key]['attributes'] = str_replace('"', '\'', $product['attributes']);
			$products[$key]['name'] = htmlentities(utf8_decode($product['name']));
			$products[$key]['worldpayAmount'] = number_format($product['price_wt'], 2, '.', '');
		}
		$smarty->assign(array(
			'address' => $address,
			'country' => new Country(intval($address->id_country)),
			'customer' => $customer,
			'testmode' => $this->getWPtestmode(),
			'instid' => $this->getWPinstID(),
                        'worldpayUrl' => $this->getWPurl(),
			'currency' => $currency,
			'amount' => number_format($params['cart']->getOrderTotal(true, 4), 2, '.', ''),
			'shipping' =>  number_format(Tools::convertPrice(($params['cart']->getOrderShippingCost() + $params['cart']->getOrderTotal(true, 6)), $currency), 2, '.', ''),
			'discounts' => $params['cart']->getDiscounts(),
			'products' => $products,
			'total' => number_format($params['cart']->getOrderTotal(true, 3), 2, '.', ''),
			'id_cart' => intval($params['cart']->id),
			'goBackUrl' => 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'order-confirmation.php?key='.$customer->secure_key.'&id_cart='.intval($params['cart']->id).'&id_module='.intval($this->id),
			'returnUrl' => 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/worldpay/validation.php',
			'this_path' => $this->_path
		));

		return $this->display(__FILE__, 'worldpay.tpl');
    }	
	
}

?>

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More