3

I have magento2 with base currency NPR I want to use Paypal as another payment option. where as papal doesn't support NPR i want to pay it in droller.

for that I have added "NPR" in $_supportedCurrencyCodes variable in vendor/magento/module-paypal/Model/Config.php

add logic for sending currency code "USD" instead of "NPR" and change amount to USD in vendor/magento/module-paypal/Model/Express/Checkout.php in "start" function while checkout it give me error for Paypal doesn't support for shipping to Nepal. Is their any way to resolve this?

3 Answers 3

8

Here is the example of use AED currency in PayPal. You can use same for other currencies.

Follow this step to support other currencies in paypal:

1) Override Config.php and Nvp.php

app/code/{Vendor}/{Module}/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Paypal\Model\Config" type="{Vendor}\{Module}\Model\Magento\Paypal\Config" />
    <preference for="Magento\Paypal\Model\Api\Nvp" type="{Vendor}\{Module}\Model\Magento\Paypal\Api\Nvp" />
</config>

2) Add your currency in $_supportedCurrencyCodes

app/code/{Vendor}/{Module}/Model/Magento/Paypal/Config

protected $_supportedCurrencyCodes = [
    'AUD',
    'CAD',
    'CZK',
    'DKK',
    'EUR',
    'HKD',
    'HUF',
    'ILS',
    'JPY',
    'MXN',
    'NOK',
    'NZD',
    'PLN',
    'GBP',
    'RUB',
    'SGD',
    'SEK',
    'CHF',
    'TWD',
    'THB',
    'USD',
    'AED', // Add currency
];

3) Now convert currency amount to USD amount in API request

app/code/{Vendor}/{Module}/Model/Magento/Paypal/Api/Nvp.php

Inject \Magento\Directory\Helper\Data class for convert currency rate

Approx after line: 1175

//print_r($request);

if ($request["METHOD"] == "SetExpressCheckout" || $request["METHOD"] == "DoExpressCheckoutPayment")
{
    if($request['CURRENCYCODE'] == "AED") {

        $payAmt = $request['AMT'];
        $payShippingAmt = $request['SHIPPINGAMT'];
        $payItemAmt = $request['ITEMAMT'];
        $payTaxAmt = $request['TAXAMT'];
        $conAmt = round($this->_currencyHelper->currencyConvert($payAmt, "AED", "USD"), 2);
        $conShippingAmt = round($this->_currencyHelper->currencyConvert($payShippingAmt, "AED", "USD"), 2);
        $conItemAmt = round($this->_currencyHelper->currencyConvert($payItemAmt, "AED", "USD"), 2);
        $conTaxAmt = round($this->_currencyHelper->currencyConvert($payTaxAmt, "AED", "USD"), 2);

        //set converted USD amount to request api

        $request['CURRENCYCODE'] = "USD";
        $request['AMT'] = $conAmt;
        $request['SHIPPINGAMT'] = $conShippingAmt;
        $request['ITEMAMT'] = $conItemAmt;
        $request['TAXAMT'] = $conTaxAmt;
    }
}

Note: set Transfer Cart Line Items to No From

Store->Configuration->Sales->PaymentMethod->Paypal->Configure->Advanced Settings

To pass only order, shipping and tax amount

If you set yes from this config setting. Magento passes all cart item amount to PayPal request and you have to change the logic of converting price.

7
  • In Magento2.2.4 EE I have edited above files and configured as defined by you. Now on checkout page at order placing time I am getting that message "PayPal gateway has rejected request. Receiving country does not support the transaction currency (#10605: Transaction refused because of an invalid argument. See additional error messages for details)." Please help me what can I do to resolve it. Merchant country = UAE and default currency = AED. Commented May 27, 2019 at 5:23
  • @Prince Patel Have you tried and tested your solution?
    – Nafsss
    Commented Jul 3, 2019 at 6:34
  • @Nafisa My 90% answers in MSE is tested. Commented Jul 3, 2019 at 6:51
  • @PrincePatel How can i override the class in app/code/{Vendor}/{Module}/Model/Magento/Paypal/Config and app/code/{Vendor}/{Module}/Model/Magento/Paypal/Api/Nvp.php. Can you give me full code
    – Nafsss
    Commented Jul 3, 2019 at 7:55
  • @PrincePatel This is not working for me. please help
    – Nafsss
    Commented Jul 3, 2019 at 10:26
2

I've created a simple M2 module to handle this. You can use it https://github.com/zamoroka/Magento-2-Paypal-All-Currencies-extension

3
  • Thanks, After I installed your extension, Paypal show up, But I have an issue "PayPal gateway has rejected request. Order total is invalid (#10401: Transaction refused because of an invalid argument. See additional error messages for details)." Do you know how to fix it? Commented Oct 22, 2020 at 3:32
  • Hi @DavidDuong This module was developed 3 years ago just for fun. Unfortunately, I don't have time currently to maintain it but feel free to create an issue in github repo or even fix it, I'll review PR and approve it if there is a good fix :) Commented Oct 23, 2020 at 5:58
  • I have fixed it. Thanks! Commented Oct 23, 2020 at 8:26
0

My base currency is INR and PayPal currency set to USD. On purchasing INR as the base it's working but on switching the currency to USD from frontend currency switcher. Paypal rejects with an error message.Do you have any idea to solve this. My requirement is if the current active currency is USD no need to convert.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.