To fix the difference between the 2Checkout foreign exchange rates and those of the ECB (used by default in virtuemart), then I suggest the following hack:
replace the line in /administrator/components/com_virtuemart/classes/currency/convertECB.php
$val = $amountA * $valB / $valA;
with
//modification to fix 2CO and ECB currency exchange difference
//compensated in VM / Store / List Payment Methods / 2Checkout / Configuration / Payment Extra Info
$val = ( $amountA * $valB / $valA ) * 1.05;
I have found that a multiplier of 1.05 (i.e. +5%) roughly matches the 2Checkout - probably spam - margin.
(Note that this change will affect all currency conversions in Virtuemart. So if you support several payment systems other than 2Checkout, you will need to apply similar the modifications to them than I am doing below.)
Next, you will also need to modify my previous modification to VM / Store / List Payment Methods / 2Checkout / Configuration / Payment Extra Info
//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 );
//to compensate for 2CO's high currency xchange rates, values are multiplied by 1.05 when in another currency
//need to remove that surplus before sending to 2CO a USD value which will have 2CO current xchange multiplier applied
// error_log("Foreign currency selected, so changing total from : ". $order_total, 0);
$order_total = floatval($order_total) * (1/1.05)* (1/1.05); //need to apply it twice as 2 conversions were applied to it: USD->FOREIGN(1.05)->USD(1.05) so need to rectify that twice
// error_log("to : ". $order_total, 0);
}
$formdata['x_amount'] = number_format($order_total, 2, '.', '');
So basically this code returns the original order total back to its normal value without the additional +5% conversions. It then sends that to 2Checkout, which in turns adds its 5% onto it. If we didn't subtract the value, we'd have the additional +5% margin applied multiple times.
Hope this helps.