Paypal Currency Conversion

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 years ago
Hey

I'm aware paypal only accepts payments in certain currencies.
They currently don't support South African Rands (ZAR).
This means I have to have USD as my primary currency.

Can I have my primary Currency in ZAR so that all my database records is in Rands but do a conversion to USD just before checkout for Paypals benifit?

Maintaining a database in USD when we trade in Rands is a big problem for us.
14 years ago
Think I got this working...

At checkout I do a check if the primary currency is supported by PayPal.
If not I do a conversion using the database conversion rates to USD.
I pass this converted USD amount to PayPal.

Payment is recorded successfully but still testing.

I see the PDT and IPN handlers also adds records for OrderNotes to the database.
Will this cause any problems say for example the following:
1. Customer checkout and primaryrate is converted for PayPal using rate x.
2. PDT handler is called and Order Note is added using rate x.
3. Currency Rates are updated and now rate is y.
4. IPN handler is called by PayPal using rate y - rates are now different.

Will this affect the transaction or are Order Notes only additional info and do not affect transactions?

Alot of people I spoke to are currently are not using PayPay because it doesn't have their primary currency supported.
This will solve that problem...
13 years ago
mcassim wrote:
Think I got this working...

At checkout I do a check if the primary currency is supported by PayPal.
If not I do a conversion using the database conversion rates to USD.
I pass this converted USD amount to PayPal.

Payment is recorded successfully but still testing.

I see the PDT and IPN handlers also adds records for OrderNotes to the database.
Will this cause any problems say for example the following:
1. Customer checkout and primaryrate is converted for PayPal using rate x.
2. PDT handler is called and Order Note is added using rate x.
3. Currency Rates are updated and now rate is y.
4. IPN handler is called by PayPal using rate y - rates are now different.

Will this affect the transaction or are Order Notes only additional info and do not affect transactions?

Alot of people I spoke to are currently are not using PayPay because it doesn't have their primary currency supported.
This will solve that problem...


Hi there,

I realise that this post a bit old, but I need to do exactly what you say you have done. Would you mind posting the code that you used to do the currency conversion to USD. I need to convert to GBP, but I'm sure I would only need to make minor changes to your code to convert from the default store currency to any other one.

Much appreciated.
13 years ago
Hello

I am waiting for the same code

Please send me

Thanks
13 years ago
Hi,

This is what I did eventually...I added the following code at the top of the PostProcessPayment() method in the PayPalStandardPaymentProcessor.cs file:


decimal OrderTotal = order.OrderTotal;
Currency StoreCurr = CurrencyManager.PrimaryStoreCurrency;
if (StoreCurr.CurrencyCode.ToUpper() != "GBP") {
  // Convert Order Total to GBP
  Currency gbp = CurrencyManager.GetCurrencyByCode("GBP");
  if (gbp == null) {
    throw new NopException("Could not find 'GBP' currency needed for the PayPal payment gateway.");
  }
  OrderTotal = CurrencyManager.ConvertCurrency(OrderTotal, StoreCurr, gbp);
  StoreCurr = gbp;
}


I then changed the following lines:

builder.AppendFormat("&amount={0}", order.OrderTotal.ToString("N", new CultureInfo("en-us")));
builder.Append(string.Format("&no_note=1&currency_code={0}", HttpUtility.UrlEncode(CurrencyManager.PrimaryStoreCurrency.CurrencyCode)));


to:

builder.AppendFormat("&amount={0}", OrderTotal.ToString("N", new CultureInfo("en-gb")));
builder.AppendFormat("&no_note=1&currency_code={0}", HttpUtility.UrlEncode(StoreCurr.CurrencyCode));


This works perfectly seeing as my Store Currency is not GBP but the PayPal account is. Of course, you'll need to change GBP to whatever currency you need to pass to PayPal.

Hope this helps.
13 years ago
Awesome...thanks so much ....appreciate it
13 years ago
Does this work for nop 1.9, i could could find the the second part of code to replace, please assist..

thanks in advance
Kakoli
13 years ago
Hi Kakoli,

It works in 1.6. I have not upgraded to 1.9 so I don't know if the PayPalStandardPaymentProcessor.cs is the same in the newer version.

Sorry I can't help.
13 years ago
Thanks!

Hope if somebody can help with this for nop 1.9 :(
13 years ago
Hey,

I have successfully done this but now my PDT handler is breaking as the amount returned from paypal is in $ and not what the customer purchased in. Did anyone get this working? Do we need to convert the $ amount to rand (store default) or to the currency that the customer purchased in?

Thanks
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.