Synopsis: PayPal payment module from Magento will not convert currency to USD or any paypal accepted currency if your base currency is other than those listed here https://www.paypal.com/us/webapps/helpcenter/helphub/article/?solutionId=FAQ2390
I have a Magento installation with 3 currencies installed.
I use PayPal standard payments as a payment option but the problem is that users are charged the same amount but in USD. For example if I have 100 RON and choose to pay by paypal i will be charged for 100 USD instead.
I checked the paypal module that makes the redirection available in
app/code/core/Mage/Paypal/Block/Standard/Redirect.php
and the variables related to currency and amount are correctly set and sent to paypal.
I do not know exactly how to tackle this issue and it is very frustrating as I guess the standard PayPal module in Magento is designed by PayPal (needs confirmation) and is verified for this kind of situations.
Info #1: PayPal does not accept some currencies (like Romanian Lei for example which happens to be the base currency for this shop) for transactions (allowed currencies are listed here https://www.paypal.com/us/webapps/helpcenter/helphub/article/?solutionId=FAQ2390) so by the time you click submit they will convert only the currency sign (to $) and not the amount. The amount you will have to change yourself, however the default PayPal module in Magento (v 1.5) is not doing this and this is why I opened this question.
EDIT #1
I tried the solution proposed down below but it did not work as in fact it replaces some of the variables but not in the desired way.
There are two options I see here:
Option #1: 'find and replace' option is where I find all the float values in the final form and replace them with the values converted to USD. However this is not a viable option because is not converting the values correctly and error may occur.
Option #2:
I found the functions that pop out the values in the form and it is located in spp/code/core/Mage/Paypal/Model/Api/Abstract.php
protected function _exportLineItems(array &$request, $i = 0)
{
if (!$this->_cart) {
return;
}
// always add cart totals, even if line items are not requested
if ($this->_lineItemTotalExportMap) {
foreach ($this->_cart->getTotals() as $key => $total) {
if (isset($this->_lineItemTotalExportMap[$key])) { // !empty($total)
$privateKey = $this->_lineItemTotalExportMap[$key];
$request[$privateKey] = $this->_filterAmount($total);
}
}
}
// add cart line items
$items = $this->_cart->getItems();
if (empty($items) || !$this->getIsLineItemsEnabled()) {
return;
}
$result = null;
foreach ($items as $item) {
foreach ($this->_lineItemExportItemsFormat as $publicKey => $privateFormat) {
$result = true;
$value = $item->getDataUsingMethod($publicKey);
if (isset($this->_lineItemExportItemsFilters[$publicKey])) {
$callback = $this->_lineItemExportItemsFilters[$publicKey];
$value = call_user_func(array($this, $callback), $value);
}
if (is_float($value)) {
$value = $this->_filterAmount($value);
}
$request[sprintf($privateFormat, $i)] = $value;
}
$i++;
}
return $result;
}
These 2 lines:
$request[$privateKey] = $this->_filterAmount($total);
$value = $this->_filterAmount($value);
print out the amount in the list of variables so instead of the function _filterAmount I have written the following function that should convert the amount from any base currency to USD based on the exchange rates defined in backend:
protected function _convertAmounttoUSD($value)
{
$baseCode = Mage::app()->getBaseCurrencyCode();
$fromCur = Mage::app()->getStore()->getCurrentCurrencyCode();
$toCur = 'USD';
$allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
$rates = Mage::getModel('directory/currency')->getCurrencyRates($baseCode, array_values($allowedCurrencies));
$output = ( $value * $rates[$toCur] ) / $rates[$fromCur];
return sprintf('%.2F', $output);
}
And I have replaced the lines above with the following:
$request[$privateKey] = $this->_convertAmounttoUSD($total);
$value = $this->_convertAmounttoUSD($value);
The problem is that the values do not get converted.