Magento – How to use paypal for other currency in Magento2

currencymagento2payment-methodspaypal

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?

Best Answer

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.