Magento PayPal Standard – How to pay with currency other than base one and do it in your language

Featured Image

Let’s assume that you have a task to implement multiple currency feature in some Magento based project.
What will happen if your client choses PayPal standard as payment method?!
Well, you might be a little dissapointed to see that there is no way to pay in chosen currency. :(
Magento tells you that order was placed using chosen currency, but is it true?
It is not.
I wouldn’t be writing this article if customer is charged in currency he has chosen.
Let me start from beginning.

First you managed to enable multiple currency in Magento in really strange and funny way.
Then you managed to set PayPal up. Did you?!
Well after countless bugfixes in PayPal and lots of code refactoring in that module, Magento finally has somewhat usable PayPal module. With a little luck you it might happen you don’t need to spend hours setting it up anymore.

Ok, now you have everything set and you are making test order (once you realised that development/production account doesn’t work in the same way as you thought).
You chose product (probably cheapest one specially made to test production order XD), you chose currency, add product to cart, pass through the checkout, place order and when you go to PayPal you see Magento PayPal Standard payment in all it’s glory: You can only pay in base currency… -_-’

I’m sure you are surprised at that point XD. Why do we have possibility to use multiple currency if we are going to pay in only one?!
Well, it doesn’t have to be that way.

What I’m going to do now is to give you one way of fixing that up.
You will probably need to test everything and probably even make it more stable before using it on production sites, but you might find it usefull as starting point.

Here we go:
Add this in “models” section of your module config.xml

<paypal>
    <rewrite>
        <standard>Yourpackage_Yourmodule_Model_Standard</standard>
    </rewrite>
</paypal>

Make Standard.php in the “Model” directory of your module and place this code in it:

<?php
class Yourpackage_Yourmodule_Model_Standard extends Mage_Paypal_Model_Standard
{
    public function getStandardCheckoutFormFields()
    {
        $orderIncrementId = $this->getCheckout()->getLastRealOrderId();
        $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
        $api = Mage::getModel('paypal/api_standard')->setConfigObject($this->getConfig());
        $api->setOrderId($orderIncrementId)
            ->setCurrencyCode($order->getOrderCurrencyCode())
            //->setPaymentAction()
            ->setOrder($order)
            ->setNotifyUrl(Mage::getUrl('paypal/ipn/'))
            ->setReturnUrl(Mage::getUrl('paypal/standard/success'))
            ->setCancelUrl(Mage::getUrl('paypal/standard/cancel'));
        // export address
        $isOrderVirtual = $order->getIsVirtual();
        $address = $isOrderVirtual ? $order->getBillingAddress() : $order->getShippingAddress();
        if ($isOrderVirtual) {
            $api->setNoShipping(true);
        } elseif ($address->validate()) {
            $api->setAddress($address);
        }
        // add cart totals and line items
        $api->setPaypalCart(Mage::getModel('paypal/cart', array($order)))
            ->setIsLineItemsEnabled($this->_config->lineItemsEnabled)
        ;
        if (!$this->_config->lineItemsEnabled) {
            $api->setCartSummary($this->_getAggregatedCartSummary());
        }
        $result['amount'] = round($order->getGrandTotal(), 2);
		$j = 0;
		$items = $order->getAllItems();
		foreach ($items as $itemId => $item)
		{
			$j ++;
			$result['amount_'.$j] = round($item->getPrice(), 2);
		}
		$result['country'] = $order->getBillingAddress()->getCountryId();
        return $result;
    }
}

Yeah, it’s ugly, but it does the job and you need only few minutes to set it up, but as I said if you want more elegant solution, you will probably need some more time to do it before you add it to production.

This was tested on 1.4.2.0. Magento.

45
Top

Care to rate this post?

Author

Tomas Novoselic

Team Leader, Backend Developer

At Inchoo, Tomas is a Team Leader and Certified Magento Developer who handles Magento modifications at any level. He also works closely with clients on Magento projects of any size and difficulty.

Other posts from this author

Discussion 45 Comments

Add Comment
  1. kiatng

    [quote]Why do we have possibility to use multiple currency if we are going to pay in only one?![/quote] Exactly! I have been wondering about this. It’s not that difficult to remove the restriction, but why is it there? I couldn’t think of any reason why the payment has to be restricted to the base currency. Anyone knows?

  2. @all I got comment from Tsvetan Stoychev on my e-mail, but I don’t know why I can’t see it in WP. This is the comment:
    Hello Tomas.

    Great Article!

    I just want notice something.

    I finished something similar for a client before 2 days ago on Magento 1.4.0.1

    I inspected $result variable and found that we have next situation:

    $result['amount_*'] where * is number from number of all ordered products + 1 ( for shipping tax ). When I say number of all ordered items I don include the quantity of each.

    For example the value of $result['amount_1'] is (Price of first Item) * quantity ….

    I am not sure how it works on Magento 1.4.2.0, but something makes me think, that $result['amount] shouldn’t be there, because it is not set and we have $result['amount_1,2,3,4....'] and PayPal will sum $result['amount_1], $result['amount_2] ….

    If am wrong

  3. @Tsvetan Stoychev U really got me now.
    I actually wasn’t paying too much attention to this. I’ll update article as soon as possible (probably tomorrow) with some sort of order item handling, Thanks for noticing that.

  4. @kiatng I was wandering the same thing. :(

  5. @Tomas

    The reason, that you don’t see my comment is that I sent message to @inchoo in Twitter to delete it.

    I accidentally pressed “Add Comment”.

    I really wanted to do better research on Magento 1.4.2.0, because my case was on Magento 1.4.0.1.

    I just don’t want to make noise before I am 101% sure in my words! :)

  6. @Tsvetan Post updated. Tnx once again.

  7. niujiao

    it does not work, alway redirect to https://www.paypal.com/webscr
    on 1.4.2.0. Magento

  8. Lee S

    The reason you have multiple currency but one base currency is that all your accounting internally is done via the base currency for the website. The display currency is there for reference of the customer. If you want to allow purchase directly in multiple currencies, then you set up multiple websites, one for each currency. Otherwise if you have dynamically updating exchange rates you run the risk of losing lost of money if there is a large fluctuation. And the same if you use static exchange rates. If the real exchange rate swings wildly before you run the same risk. And, is your paypal merchant account set up for each currency? Is this what the business owner wants? Doing multi-currrency in Magento is a complex and painful process. Modifying the paypal module to use the display currency as what is actually charged is overall a bad idea.

  9. @Lee S –

    If you really can sell this story to a real client in order to not implement this functionality or get budget for making multiple websites on your project, then you are lucky man even though I’m not sure about “making multiple websites”.

    What happens if you get this request somewhere around project’s second birthday when you already have 7-8 store views on single store in single website.
    And your client will have to use per store view
    Languages with multiple currencies per each store view, not to mention that your client will have to add different prices all over the place. I think that’s doable in quite limited number of real cases.

    Paypal merchant account has nothing to do with this.
    I thought that’s obvious that we won’t restrict those currencies at PayPal and that both methods will depend on that fact.

    “Otherwise if you have dynamically updating exchange rates you run the risk of losing lost of money if there is a large fluctuation.”

    Isn’t there same risk if you are using multiple currencies using multiple websites method?

    Yes, business owner want’s that, and he also wants to be able to make language depend on geolocation and it would be great to pay in dollars even if you are viewing site in german.

    I think every customer should be able to chose in which currency he want’s to pay.

    This article is here just to suggest where to start.
    It is not suitable for everyone and we especialy can’t consider blog article fully developed software, that’s why it has a notice.

    Real problem is what Tsvetan Stoychev mentioned above so for now, this is my primary concern which I’ll try to fix soon.

    It works for virtual products though.

  10. niujiao

    I find out a way, test, it works, but I don’t know if there is any problem.
    for magento 1.4.2.0
    1.app\code\core\Mage\Paypal\Model\Standard.php line 124
    change from
    ->setCurrencyCode($order->getBaseCurrencyCode())
    to
    ->setCurrencyCode($order->getOrderCurrencyCode())

    2.app\code\core\Mage\Paypal\Model\Cart.php
    line 280 to line 283
    change from

    self::TOTAL_SUBTOTAL => $this->_salesEntity->getBaseSubtotal(),
    self::TOTAL_TAX => $this->_salesEntity->getBaseTaxAmount(),
    self::TOTAL_SHIPPING => $this->_salesEntity->getBaseShippingAmount(),
    self::TOTAL_DISCOUNT => abs($this->_salesEntity->getBaseDiscountAmount()),

    to

    self::TOTAL_SUBTOTAL => $this->_salesEntity->getSubtotal(),
    self::TOTAL_TAX => $this->_salesEntity->getTaxAmount(),
    self::TOTAL_SHIPPING => $this->_salesEntity->getShippingAmount(),
    self::TOTAL_DISCOUNT => abs($this->_salesEntity->getDiscountAmount()),

    line 291 to line 294
    change from

    self::TOTAL_SUBTOTAL => $this->_salesEntity->getBaseSubtotal(),
    self::TOTAL_TAX => $address->getBaseTaxAmount(),
    self::TOTAL_SHIPPING => $address->getBaseShippingAmount(),
    self::TOTAL_DISCOUNT => abs($address->getBaseDiscountAmount()),

    to

    self::TOTAL_SUBTOTAL => $this->_salesEntity->getSubtotal(),
    self::TOTAL_TAX => $address->getTaxAmount(),
    self::TOTAL_SHIPPING => $address->getShippingAmount(),
    self::TOTAL_DISCOUNT => abs($address->getDiscountAmount()),

  11. Leo

    @niujiao

    i try yr solution, the currency displayed in paypal has been changed, but the “amount” remains the same! any fix?

  12. niujiao

    @Leo
    you need to re-compiler

    backend/System/Tools/Compilation

  13. Leo

    @niujiao

    thanks, it works!!

    however, the shipping fee is charged twice!
    (charged in magento, and charged again in paypal)

    have you ever seen this problem?

  14. cheung

    Has anyone got this working on 1.5.0.1?

  15. Tino Castrillo

    Hi Tomas and y’all!!
    Thanx for this article, this is exactly what i´ve been needing for a while. Make no sense to have to create a different website and differetn URL for each currency, to be able to use Paypal Standard properly.
    I´m a bit confused though!!
    1 -What do you mean when (on the code) you type “Yourpackage_Yourmodule”?
    2 – When you say to insert that code on your “config.xml”… where? code/local/Mage/Paypal/etc/config.xml?
    3 – I already have the standar.php on the core… when you say to create that file… you mean to reacreate it on the “local” core folder?

    Sorry about my confusion… not really savy on Magento yet… so not erally sure how to make this implementation

    Thanx a lot again for this solution

    Tino

  16. @Tino Hello, seems that you are new to Magento and I will try to guide you. You have 2 chances to wrap this exmaple in Magento extension or just to put copy in the proper way in your app/code/local/ folder.

    If you decide to create extension, don’t forget to replace “Yourpackage_Yourmodule” with your own.

    Just google with next keywords: “magento override model” and I am sure, that you will find the solution … even more you can read: http://inchoo.net/ecommerce/magento/how_to_override_magento_model_classess also written by Tomas. And one advice don’t forget to read the comments … usually there are are hiding some interesting secrets!

    Good Luck.

  17. bsr

    @niujiao
    Even after recompilation I am not getting the amount converted in dollars on paypal site.

    Can you please help? I am on 1.4.2.0 version.
    Thanks

  18. adhwa

    it does not work, alway redirect to https://www.paypal.com/webscr

    any ideas?

  19. hou

    @niujiao

    it work. but the paypal IPN dont work, how to?

  20. chetan

    hi

    I am new with magento .

    How can I add page in footar and header like about us

  21. Works great! One issue is that while totals and item values are sent to PayPal using the selected currency, the tax component is sent in the base currency.

    To fix, after this line:

    $result['amount'] = round($order->getGrandTotal(), 2);

    Add:

    $result['tax'] = round($order->getTaxAmount(), 2);

  22. It is passing currency over fine but the amount it still in base currency not in local currency. I’ve tried forcing $result['amount'] = 20 to see if it is effected and nothing is changed so I am concluding that amount is set elsewhere in the process but currently I can’t find where. any tips?

  23. May

    Hi Alex,

    I’ll try your advice, I add:

    $result['tax'] = round($order->getTaxAmount(), 2);

    after

    $result['amount'] = round($order->getGrandTotal(), 2);

    But it’s not working.. how to make it work?

    thx

  24. May

    Ah I get it!

    paypal take the tax value from $result['tax_cart'] not $result['tax'] :)

  25. Guys, for sending to paypal using multiple currencies is this code the best solution at the moment ?

  26. Second Question, This Code actually need to be implemented in a new module right ?

  27. @Fixxi I guess, that you noticed, that this code is tested on Magento CE 1.4.2.0 … as I know there are some changes of PayPal module in latest Magento releases. So I am not sure how to answer on the question if the code is the best solution … may be it is the best solution as long as you don’t update Magento. Regarding you second question: Yes, you need to created new module … as I know there are also some commercial extensions, that solves the problem. Ask if you have another questions :)

  28. May

    @Fixxi
    FYI, Magento always send the value of base currency to paypal. This code help you to send current currency value to paypal :)

    no need to create a new module.. just copy the standard.php to your local folder :)

  29. @May I agree with you and for sure this will work, but there are some disadvantages of copying files in local folder. It makes the future development process harder. It is always good to wrap some new feature in extension. Let’s imagine, that some new developer or company are tacking over the project and they have to deal with PayPal. So this person or company will need some time for reverse engineering to understand what is the logic behind the file, that you’ve copied in local folder. One more reason why it is good to wrap the new future in module, is that we can easy disable the module from Magento admin panel. Anyway your approach works … just wanted to share my opinion :)

  30. May

    @Tsvetan Stoychev yup your opinion is true, I’ll make it to module from now :D
    Thx for your opinion :)

  31. Guys,

    I can pay small project, 30 – 50 usd, if someone can help me configure this on 1.62. ( we tried, didnt work by default).

    You need to know how to create a module out of this , have configured it. email me if interested. contact@fixxi.net !

  32. I am running a local website with base currency NPR (Nepalese Rupee) but when user redirects to paypal page they are shown exact price number in USD which has put me in big problem.

    So I need some way that magento will convert the base currency to USD while redirecting to the paypal payment page. Any solution?

  33. Meet the same problem with May after add this line:

    $result['tax'] = round($order->getTaxAmount(), 2);

    But after use $result['tax_cart'] instead of $result['tax'] , it work very well

    Tested in magento 1.6.1

  34. For those with redirection problem add on line 30:
    $result = $api->getStandardCheckoutRequest();
    I think this line is missing in code snipped.

  35. Keiron Roberts

    Has anybody got this working in Magento ver. 1.7.0.2? I have tried several attempts, but nothing seems to work. If I try the solution from @niujiao I get errors. Instead of writing a module I have been adapting the PayPal code (under local)

  36. mem

    Hi, all! Has “the shipping fee is charged twice! (charged in magento, and charged again in paypal)” issue resolved? I hit the same problem using the code above in Magento ver 1.7.0.2.

  37. Muhammad

    at this following line i am gettting error

    $api->setPaypalCart(Mage::getModel(‘paypal/cart’, array($order)))
    ->setIsLineItemsEnabled($this->_config->lineItemsEnabled)

    error:

    2013-05-11T23:21:06+00:00 ERR (3): Recoverable Error: Argument 1 passed to Mage_Paypal_Model_Api_Abstract::setPaypalCart() must be an instance of Mage_Paypal_Model_Cart, boolean given

    cart line items are not transfering to paypal standard, i enabled this option in magento admin configuration in paypal to transfer line items,
    please suggest thank whats causing this one

  38. Muhammad

    okay guys my last message i posted for cart line items not transfering to paypal standard and giving error.
    2013-05-11T23:21:06+00:00 ERR (3): Recoverable Error: Argument 1 passed to Mage_Paypal_Model_Api_Abstract::setPaypalCart() must be an instance of Mage_Paypal_Model_Cart, boolean given
    solution:
    actually if there is module which is overwriting this Mage_Paypal_Model_Cart and class is not defined then it will give this error.
    i solved this issue and cart line items transferring to paypal standard

  39. Dear Friend,

    I am using magneto 1.7.0.2 and Themeforest shopper theme v 1.1 which is available to download, I am updating my site

    to this theme right now I am working on my localhost xampp on windows xp.

    The problem i am facing is this that i tried to set up PayPal payment option on the admin panel as paypal standard but

    paypal option is not visible on the payment option in the theme where we do payment.

    I have integrated cc avenue and it is working fine as i have to made changes after downloading the kit form the cc

    avenus as per the pdf document provided by them.

    There are other option which are visible in the front end when i select yes option on the admin panel like :- saved

    cc, cash on payment etc but only pay pal is not visible in the front.

    Just to add in i have used all different currency like Indian Rupee, USD, Pound etc but still paypal option is not

    visible, I want to use pay pal for all the currency even for Indian Rupee is it possible.

    I am attaching an attachment showing options but no Paypal and I am using USD as a currency option.

    Need help as i am trying to change to this theme of shopper by this month of may.

    Photo Attached : – http://www.flickr.com/photos/84479482@N06/

    Regards,
    Abhishek

  40. Dear Abhishek
    I think, you need to set your base currency to USD/EURO to get paypal active in frontend.

  41. Dian

    i tried the above code on 1.7 , but nothing changed.
    Is it possible?
    Standard.php was already in the model directory, i just added the code at the end

  42. Hi,

    I My base currency is INR(indian Rupees),

    My display currency is USD/INR/EUR

    For eg:

    If any one select INR and use paypal payment option INR 6000 converted in to 100$ in paypal

    But if any one select USD or EUR

    EG: 100$/80EUR it convert as $6000 / 6000 EUR

    how to send selected currency code and selected value to paypal payment gateway or is there any other alternate solution..

    Thankyou

  43. I My base currency is INR(indian Rupees),

    My display currency is USD/INR/EUR

    For eg:

    If any one select INR and use paypal payment option INR 6000 converted in to 100$ in paypal

    But if any one select USD or EUR

    EG: 100$/80EUR it convert as $6000 / 6000 EUR

    how to send selected currency code and selected value to paypal payment gateway or is there any other alternate solution..

    Thankyou

  44. tejas

    sir, i got one problem in my magento site.
    i set more domain site. and pay pal base currency set us dollar. but problem is that when Indian client buy some thing on it. under check out page “you credit card will be charger for $20″ . we describe this line but after converted “rupees”. so , suggest me any ideas you have.
    thank you.

  45. bhargav

    i need a help. my question is that when i purchase from UK store and i live in Germany so during payment in paypal how can i get automatic currency change from Pound To Euro. How?

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top