1
Vote

Issue with Paypal express checkout plugin

description

Hello,

I have downloaded Paypal express checkout plugin for nopcommerce 3.60. In my store we have scenario like we round up item price to whole number. In currency setting I have customized format currency string "$0" so it works fine in entire website as per requirement but while performing transaction through paypal express checkout plugin the amount passed in "$0.00" format due to hard coded culture code.

you code in PaypalHelper.cs

...
public static BasicAmountType GetBasicAmountType(this decimal value, CurrencyCodeType currencyCodeType, Currency targetCurrency)
    {
        if (targetCurrency == null)
            throw new ArgumentNullException("targetCurrency");

        return new BasicAmountType
                   {
                       currencyID = currencyCodeType,
                       Value = Math.Round(value, 2).ToString("N", new CultureInfo("en-us"))
                   };
    }

My suggestion to change it like nop team did price formatter

public static BasicAmountType GetBasicAmountType(this decimal value, CurrencyCodeType currencyCodeType, Currency targetCurrency)
    {
        if (targetCurrency == null)
            throw new ArgumentNullException("targetCurrency");

        return new BasicAmountType
                   {
                       currencyID = currencyCodeType,
                       Value = GetCurrencyString(value, true, targetCurrency)
                   };
    }


    private static string GetCurrencyString(decimal amount, bool showCurrency, Currency targetCurrency)
    {
        if (targetCurrency == null)
            throw new ArgumentNullException("targetCurrency");

        string result = "";
        if (!String.IsNullOrEmpty(targetCurrency.CustomFormatting))
        {
            result = amount.ToString(targetCurrency.CustomFormatting);
        }
        else
        {
            if (!String.IsNullOrEmpty(targetCurrency.DisplayLocale))
            {
                result = amount.ToString("C", new CultureInfo(targetCurrency.DisplayLocale));
            }
            else
            {
                result = String.Format("{0} ({1})", amount.ToString("N"), targetCurrency.CurrencyCode);
                //return result;
            }
        }

        Regex pattern = new Regex(@"\d+(\.\d+)?");
        Match m = pattern.Match(result);
        return m.Value;
    }
...

This is my idea, kindly provide feedback on this or is there any better idea to do above

comments