Currency conflicts with 2checkout

(1/2) > >>

Ruppert:

If you're having problems with 2Checkout's default currency then read on.

In 2CO, you have to set a default currency. The orders sent by VM to 2CO must therefore be in that 2CO's default currency, otherwise 2CO interprets them as being in that currency no matter what you submit your order in.

The Paypal module solves this by sending a currency code with the order:

Code:

"currency_code" => $_SESSION['vendor_currency'],

2CO doesn't support currency codes, so here's how to fix this:

1/ Go to VM / Store / List Payment Methods / 2Checkout / Configuration / Payment Extra Info

2/ Replace

Code:

$formdata['x_amount'] = number_format($db->f("order_total"), 2, '.', '');

with :

Code:

    //Convert the currency
    $my_2co_default_currency = 'USD';
    $order_total = $db->f("order_total");
    if ($db->f('order_currency') != $my_2co_default_currency ) {
      $order_total = $GLOBALS['CURRENCY']->convert( $db->f("order_total") , $db->f('order_currency'), $my_2co_default_currency );
    }
    $formdata['x_amount'] = number_format($order_total, 2, '.', '');


3/ Replace the value of $my_2co_default_currency with that set in 2CO Admin. In my case, I set it to 'USD' because it's set to US Dollar.


Here is a copy of my complete 2Checkout file which also fixes the redirecting issue and the non-forwarded billing address:

Code:

<?php

       // Get ship_to information
    if( $db->f("user_info_id") != $dbbt->f("user_info_id")) {
         $q2  = "SELECT * FROM #__vm_user_info WHERE user_info_id='".$db->f("user_info_id")."'"; 
    $dbst = new ps_DB;
   $dbst->setQuery($q2);
       $dbst->query();
      $dbst->next_record();
      }
     else  {
         $dbst = $dbbt;
    } 
              
      //Authnet vars to send
        $formdata = array (
   'x_login' => TWOCO_LOGIN,
   'x_email_merchant' => ((TWOCO_MERCHANT_EMAIL == 'True') ? 'TRUE' : 'FALSE'),
                  
      // Customer Name and Billing Address
  'x_first_name' => $dbbt->f("first_name"),
        'x_last_name' => $dbbt->f("last_name"),
  'x_company' => $dbbt->f("company"),
      'x_address' => $dbbt->f("address_1"),
    'x_city' => $dbbt->f("city"),
    'x_state' => $dbbt->f("state"),
  'x_zip' => $dbbt->f("zip"),
      'x_country' => $dbbt->f("country"),
      'x_phone' => $dbbt->f("phone_1"),
        'x_fax' => $dbbt->f("fax"),
      'x_email' => $dbbt->f("email"),
 
       // Customer Shipping Address
  'x_ship_to_first_name' => $dbst->f("first_name"),
        'x_ship_to_last_name' => $dbst->f("last_name"),
  'x_ship_to_company' => $dbst->f("company"),
      'x_ship_to_address' => $dbst->f("address_1"),
    'x_ship_to_city' => $dbst->f("city"),
    'x_ship_to_state' => $dbst->f("state"),
  'x_ship_to_zip' => $dbst->f("zip"),
      'x_ship_to_country' => $dbst->f("country"),
     
       'x_invoice_num' => $db->f("order_number"),
       'x_receipt_link_url' => SECUREURL."2checkout_notify.php",
       'product_description' => $VM_LANG->_('PHPSHOP_ORDER_PRINT_PO_NUMBER').": ". $db->f("order_id") ,
       'sh_cost' => sprintf("%.2f", $db->f("order_shipping"))
  );
    
     if( TWOCO_TESTMODE == "Y" )
   $formdata['demo'] = "Y";
       
       $version = "2";
    $url = "https://www2.2checkout.com/2co/buyer/purchase";
    
    //Convert the currency 
    $my_2co_default_currency = 'USD';
    $order_total = $db->f("order_total");
    if ($db->f('order_currency') != $my_2co_default_currency ) {
      $order_total = $GLOBALS['CURRENCY']->convert( $db->f("order_total") , $db->f('order_currency'), $my_2co_default_currency );
    }
    $formdata['x_amount'] = number_format($order_total, 2, '.', '');
       
    
if( $page == "checkout.thankyou" ) {
    $query_string = "?";
    foreach( $formdata as $name => $value ) {
     $query_string .= $name. "=" . urlencode($value) ."&";
    }
    vmRedirect( $url . $query_string );
}
else {

//build the post string
       $poststring = '';
       
   foreach($formdata AS $key => $val){
          $poststring .= "<input type='hidden' name='$key' value='$val' />
          ";
    } 
   
    //old buy logo: https://www.2checkout.com/images/buy_logo.gif
?>
    <form id="cho" action="<?php echo $url ?>" method="post" target="_blank">
       <?php echo $poststring ?>
    <p><font size=+1>Click on the Image below to pay...</font></p>
     <input type="image" name="submit" src="https://www2.2checkout.com/static/checkout/CheckoutButton2COCards.gif" border="0" alt="Make payments with 2Checkout, it's fast and secure!" title="Pay your Order with 2Checkout, it's fast and secure!" />
      </form>

   <!-- Uncomment if you want to try a javascript redirect no matter what -->
   <!--script language="JavaScript" type="text/javascript">
   document.getElementById('cho').submit();
   </script-->
   
<?php 
}
?>


Let me know if that works for you.

Ruppert.


jmwaniki:
Thanks. This uses the ecb currency converter which does not have many currencies supported.Is it possible to use xe.com converter? What can i change.

Ruppert:
If Xe.com has an currency XML feed, then yes.

You'd need to implement your own currency conversion class. You could either update the currency conversion class in VirtueMart or this example class to use the XE.com feed.

But you'll need some programming skills.

crashtackle:
Hi, I used the code above but the conversion rate is way out - by about 28%...

Any ideas on using a more accurate conversion?

Ruppert:
Quote from: crashtackle on November 13, 2009, 07:17:58 AM

Hi, I used the code above but the conversion rate is way out - by about 28%...

Any ideas on using a more accurate conversion?


Be aware that 2Checkout.com charges much higher fees for currency conversions than those displayed on www.xe.com for example. Like 10% more sometimes. That might be the reason.

I would advise your customers to pay in USD and let their credit card issuer do the currency conversion, as they will pay a lot less than if 2Checkout does it.

This is a bit of sneaky way for 2Checkout to make more profit off of international customers...



Navigation

[0] Message Index

[#] Next page