Turn off Payment method based on currency used

By | June 10, 2011

Had an email overnight from an osCommerce user who needs to turn on and off payment methods based on what currency is being used in the checkout. I thought I had covered this already in the blog, but could not find it. So here we go;

1. Add an extra input to each payment method used

This allows us to add a list of currencies supported by the payment method.

As you can see in the example above, I have set the currencies to GBP (British Pounds) and EUR (European Euros).

Code changes (taking cod.php as the example):

Find:
function install() {

Add an extra line of code, as so:
tep_db_query(“insert into ” . TABLE_CONFIGURATION . ” (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values (‘Currencies available for this payment method.’, ‘MODULE_PAYMENT_COD_CURRENCIES_ACCEPTED’, ”, ‘Comma separated list of accepted Currencies.’, ‘6’, ‘0’, now())”);

Find:
function keys() {

Add:
‘MODULE_PAYMENT_COD_CURRENCIES_ACCEPTED’,

After:
‘MODULE_PAYMENT_COD_ZONE’,

Turn off the COD module if you already have it turned on. Turn it on again to reset it. You now have the necessary input box to allow you to add the currencies acceptable.

2. Turn the module off if an unacceptable currency is used

Still working on cod.php ….

Find:
// disable the module if the order only contains virtual products

Above this, add:
[php]// disable the module based on available currencies
$good_currencies = explode(‘,’, MODULE_PAYMENT_COD_CURRENCIES_ACCEPTED);
if (!in_array($order->info[‘currency’], $good_currencies)) {
$this->enabled = false;
}[/php]

Here, we create an array of acceptable currencies using explode. We then compare the currency being used to those acceptable currencies. If the currency being used is NOT found in the list, then the module is turned off.

Easy as 123.

You would need to do similar for every payment module that you use. Make sure to change this: _COD_ to reflect the name of the module you are amending.

2 thoughts on “Turn off Payment method based on currency used

  1. Agus Halim

    hi,
    i’m looking for this plugin/module for oscommerce where can i get this?

    thanks

  2. Gary Post author

    You can follow the instructions…it’s straightforward.

Leave a Reply

Your email address will not be published.