Currency convertion on payment plugin

  • Posts: 14
  • Thank you received: 2
  • Hikamarket Multivendor Hikashop Business
8 years 7 months ago #237424

-- HikaShop version -- : 2.6.0
-- Joomla version -- : 3.4.8
-- PHP version -- : 5.6.20
-- Browser(s) name and version -- : firefox 45
-- Error-message(debug-mod must be tuned on) -- : none

Hi, I have developed a payment plugin for south american MercadoPago gateway, and I wonder if I can convert the currency of the whole cart to the currency expected by the gateway, that differs from the cart currency.

IE: I have a product valued u$s10 but if I choose MercadoPago payment I expect that value to be converted to BRL for example, which is $35 BRL. Is that possible using the built in currency converter?

Thanks in advise

Last edit: 8 years 7 months ago by ghiamar.

Please Log in or Create an account to join the conversation.

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
8 years 7 months ago #237430

Hi,

Yes. Usually what you do is that you disable the USD currency but keep it displayed and configure BRL as the main currency. That way, when the customer browse the website with the USD currency and then arrives on the checkout, the system automatically converts the prices to BRL.

If you want to convert a price in your code using the currency converter system in place, you can do like that:

$class = hikashop_get('class.currency');
$srcCurrency = $class->get('USD');
$dstCurrency = $class->get('BRL');
$convertedPrice = $class->convertUniquePrice($price, $srcCurrency->currency_id, $dstCurrency->currency_id);

The following user(s) said Thank You: ghiamar

Please Log in or Create an account to join the conversation.

  • Posts: 14
  • Thank you received: 2
  • Hikamarket Multivendor Hikashop Business
8 years 7 months ago #237699

Thanks! it turns out that I already applyed that code before, but for some reason it doesn't convert the ammount, just let me double check my setup and will ask if I found something.

Thanks again!

Please Log in or Create an account to join the conversation.

  • Posts: 14
  • Thank you received: 2
  • Hikamarket Multivendor Hikashop Business
8 years 7 months ago #237732

nicolas wrote: Hi,

$class = hikashop_get('class.currency');
$srcCurrency = $class->get('USD');
$dstCurrency = $class->get('BRL');
$convertedPrice = $class->convertUniquePrice($price, $srcCurrency->currency_id, $dstCurrency->currency_id);

I confirm this snippet does the trick, I already had in my payment plugin, but I have set a product with several currencyes and that was causing the issue.

Thanks a lot!

Please Log in or Create an account to join the conversation.

Time to create page: 0.058 seconds
Powered by Kunena Forum