Author Topic: Currency Conversion to Suit Payment Module  (Read 10228 times)

skippy31

  • Beginner
  • *
  • Posts: 33
    • The Web Design Guy
Currency Conversion to Suit Payment Module
« on: August 04, 2008, 19:57:21 pm »
My Web site uses two payment modules.  PayPal which is set for US Dollars, and Virtual Merchant (credit card processing) which is in Canadian Dollars.

I'd like to have each module automatically switch to it's currency when someone uses that module to check out.  By allowing the module to force the currency switch it would allow me to activate various other currencies but not accept them at checkout.  Basically this allows the user to see their prices in one currency, but checkout in another. For example I could then add euros, pounds etc but not actually have the user checkout in those currencies.

I'm currently looking at the mod_virtuemart_currencies module and the payment modules to see if I can come up with an easy hack.  I'm not a PHP gury (yet) so if anyone else has done this is knows how to quickly make the change do let me know.

Thanks,

Mat.

skippy31

  • Beginner
  • *
  • Posts: 33
    • The Web Design Guy
Re: Currency Conversion to Suit Payment Module
« Reply #1 on: August 12, 2008, 22:15:41 pm »
Well I've spent some time looking through the virtuemart code.  My impression is that the best place to make this change is in the ro_basket.php file. The change would go right after the "$payment_method_id =" statement.

Problem is I've been going through the currency code, but I'm not clear on how to set the currency to my desired currency in the code.  My PHP is still too rusty.  I've gone through the various currency modules for display and setting the currency, but it's not obvious to me how to set the current currency.

Mat.

Quote
/* make sure this is the checkout screen */
if ($cart["idx"] == 0) {
   echo $VM_LANG->_('PHPSHOP_EMPTY_CART');
   $checkout = False;
}
else {
   $checkout = True;
   $payment_method_id = vmGet( $_REQUEST, "payment_method_id" );
   
   $total = 0;
   // Added for the zone shipping module
   $vars["zone_qty"] = 0;
   $weight_total = 0;
   $weight_subtotal = 0;
   $tax_total = 0;
   $shipping_total = $shipping_tax = 0;
   $order_total = 0;
   $coupon_discount = vmGet( $_SESSION, 'coupon_discount', 0 );
   $coupon_discount_before=$coupon_discount_after=$payment_discount_before=$payment_discount_after=$tax=$shipping=false;
   $product_rows = Array();

skippy31

  • Beginner
  • *
  • Posts: 33
    • The Web Design Guy
Re: Currency Conversion to Suit Payment Module
« Reply #2 on: August 13, 2008, 22:32:34 pm »
Well I'm nearly there.  I've added the following code to ro_basket to handle the currency conversion change.  I works (sort of).  The current screen does not reflect the currency change, but if I go back one screen it shows the change.  Only thing left to do is to figure out how to make the currency change immediately.

Any suggestions are appreciated...

Mat.

Quote
/* make sure this is the checkout screen */
if ($cart["idx"] == 0) {
   echo $VM_LANG->_('PHPSHOP_EMPTY_CART');
   $checkout = False;
}
else {
   $checkout = True;
   $payment_method_id = vmGet( $_REQUEST, "payment_method_id" );
   
   // Changes to handle currency change to USD for PayPal Checkout and
   // to CAD for Virtual Merchant Checkout

   if($payment_method_id == 4 )
   {
        $GLOBALS['product_currency'] = 'USD';
           $_SESSION['product_currency'] = 'USD';

        echo ">>> Forced Currency to USD for PayPal (PayPal Checkout is always in USD)";
     }
     
     if($payment_method_id == 17)
   {
        $GLOBALS['product_currency'] = 'CAD';
           $_SESSION['product_currency'] = 'CAD';
        echo ">>> Forced Currency to CAD for Visa / Mastercard (Virtual Merchant Checkout is always in CAD)";
     }
   
   $total = 0;
   // Added for the zone shipping module
   $vars["zone_qty"] = 0;

skippy31

  • Beginner
  • *
  • Posts: 33
    • The Web Design Guy
Re: Currency Conversion to Suit Payment Module
« Reply #3 on: August 13, 2008, 23:18:49 pm »
On testing the code more carefully the changes are in fact taking effect, but the currency symbol is not being updated.  I'm getting pretty near the end of this change now lol.  Just need to figure out why the currency symbol is not updating...

Mat.

skippy31

  • Beginner
  • *
  • Posts: 33
    • The Web Design Guy
Re: Currency Conversion to Suit Payment Module
« Reply #4 on: August 18, 2008, 00:43:58 am »
Ok figured out the last part of this change.  Here is the final version of my hack to ro_checkout.php

Again if anyone has ways to improve on this let me know.  In the mean time this seems to be working for me.

Mat.

Quote
/* make sure this is the checkout screen */
if ($cart["idx"] == 0) {
   echo $VM_LANG->_('PHPSHOP_EMPTY_CART');
   $checkout = False;
}
else {
   $checkout = True;
   $payment_method_id = vmGet( $_REQUEST, "payment_method_id" );
   
   // Changes to handle currency change to USD for PayPal Checkout and
   // to CAD for Virtual Merchant Checkout

   if($payment_method_id == 4 )
   {
        $GLOBALS['product_currency'] = 'USD';
           $_SESSION['product_currency'] = 'USD';
           
           $GLOBALS['CURRENCY_DISPLAY']->symbol = 'US $';


        echo ">>> Forced Currency to USD for PayPal (PayPal Checkout is always in USD)";
     }
     
     if($payment_method_id == 17)
   {
        $GLOBALS['product_currency'] = 'CAD';
           $_SESSION['product_currency'] = 'CAD';
           $GLOBALS['CURRENCY_DISPLAY']->symbol = 'CAD $';

        echo ">>> Forced Currency to CAD for Visa / Mastercard (Virtual Merchant Checkout is always in CAD)";
     }
   
   $total = 0;
   // Added for the zone shipping module
   $vars["zone_qty"] = 0;
   $weight_total = 0;
   $weight_subtotal = 0;
   $tax_total = 0;
   $shipping_total = $shipping_tax = 0;
   $order_total = 0;

chac416

  • Jr. Member
  • **
  • Posts: 80
Re: Currency Conversion to Suit Payment Module
« Reply #5 on: May 04, 2009, 18:59:47 pm »
which file to edit and which lines?
I found ps_checkout.php file but no ro_checkout.php


Ok figured out the last part of this change.  Here is the final version of my hack to ro_checkout.php

Again if anyone has ways to improve on this let me know.  In the mean time this seems to be working for me.

Mat.

Quote
/* make sure this is the checkout screen */
if ($cart["idx"] == 0) {
   echo $VM_LANG->_('PHPSHOP_EMPTY_CART');
   $checkout = False;
}
else {
   $checkout = True;
   $payment_method_id = vmGet( $_REQUEST, "payment_method_id" );
   
   // Changes to handle currency change to USD for PayPal Checkout and
   // to CAD for Virtual Merchant Checkout

   if($payment_method_id == 4 )
   {
        $GLOBALS['product_currency'] = 'USD';
           $_SESSION['product_currency'] = 'USD';
          
           $GLOBALS['CURRENCY_DISPLAY']->symbol = 'US $';


        echo ">>> Forced Currency to USD for PayPal (PayPal Checkout is always in USD)";
     }
     
     if($payment_method_id == 17)
   {
        $GLOBALS['product_currency'] = 'CAD';
           $_SESSION['product_currency'] = 'CAD';
           $GLOBALS['CURRENCY_DISPLAY']->symbol = 'CAD $';

        echo ">>> Forced Currency to CAD for Visa / Mastercard (Virtual Merchant Checkout is always in CAD)";
     }
   
   $total = 0;
   // Added for the zone shipping module
   $vars["zone_qty"] = 0;
   $weight_total = 0;
   $weight_subtotal = 0;
   $tax_total = 0;
   $shipping_total = $shipping_tax = 0;
   $order_total = 0;

skippy31

  • Beginner
  • *
  • Posts: 33
    • The Web Design Guy
Re: Currency Conversion to Suit Payment Module
« Reply #6 on: September 09, 2009, 21:10:24 pm »
The file is /administrator/components/com_virtuemart/html/ro_basket.php

"checkout" is a typo...

Mat.

MCMuckle

  • Jr. Member
  • **
  • Posts: 58
Re: Currency Conversion to Suit Payment Module
« Reply #7 on: October 15, 2009, 15:24:17 pm »
I think this is exactly what I have been looking for.  I live in Kenya and would like to offer payment in both Kenya Shillings via a local (KES only) gateway, and my Moneybookers account (in GBP).

I would like to force the correct currency depending on which payment method is selected.

I think that you have cracked it but would just like to ask a couple of things

1. are the code and instructions you have posted above all that is needed
2. how is the currency conversion handled?

Many thanks

akeem76

  • Beginner
  • *
  • Posts: 18
Re: Currency Conversion to Suit Payment Module
« Reply #8 on: January 09, 2010, 18:26:05 pm »
Hi Skippy,

This is what I had been searching for. I had tried to incorporate it in my VM, but apparently the shipping is not calculated correctly after it had converted. Any ideas why?

Many thanks.

akeem

akeem76

  • Beginner
  • *
  • Posts: 18
Re: Currency Conversion to Suit Payment Module
« Reply #9 on: January 10, 2010, 22:46:59 pm »
I found the solution here.
http://dev.virtuemart.net/cb/issue/2300#

Need to replace the standard_shipping.php

Apparently the shipping cost was not converted during currency conversion at checkout.

jwp

  • Beginner
  • *
  • Posts: 2
Re: Currency Conversion to Suit Payment Module
« Reply #10 on: November 14, 2010, 22:16:52 pm »
Thanks to Mat (Skippy31) for this fix, works a treat!

I did make a small modification to Mat's code for the purpose of keeping the currency change notification 'silent' for customers who are already paying in the default checkout currency.
For those of you who wish to use this, here is the change:

if($payment_method_id == 4 )
   {
   if ($GLOBALS['product_currency'] != 'USD') {

           echo ">>> Forced Currency to USD for PayPal (PayPal Checkout is always in USD)";

        $GLOBALS['product_currency'] = 'USD';
           $_SESSION['product_currency'] = 'USD';
           $GLOBALS['CURRENCY_DISPLAY']->symbol = '$';
         }
     }

-jp
Using VirtueMart 1.1.3

antonitus

  • Jr. Member
  • **
  • Posts: 126
Re: Currency Conversion to Suit Payment Module
« Reply #11 on: April 20, 2012, 18:02:17 pm »
Excellent piece of code because of the blooming problems we are having with currency conversions that are not included with PayPal.

However people can exploit a bug in the system when it comes to shipping costs.  For example, if you convert the currency to USD before this code, it will re-convert the shipping costs again and make it much lower in price.  Is there a way to resolve this issue?  If not, does anyone know if the currency converter can automatically convert to the set currency, for example AED after executing this script, that's if a customer wishes to purchase again, because if they do, the currency would still be in USD currency.  I wish VM could sort this on-going problem that a lot of people have, even if it is VM1.19.

My versions:
J1.5.26
VM1.1.9
Joomla V3.5.1
Virtuemart V3.0.16