Hi, I am grateful for your work on this module as I am no programmer, so thank you in advance.

I only need UK pounds on my site and would like to take out the field which gives options to change currency. It doesn't make sense to have a drop down menu when there is only one option in the array. That is not problem but it defaults to USD when the field is removed.

I have simple paypal set to UK pounds and have removed the USD and EUR options from the array in the Simple Paypal module.

I also changed the default currency in the database to GBP in donate but it still comes up as $ when it reaches paypal.

Can you advise? I am sure I must be missing something simple to do.

Comments

kbahey’s picture

Priority: Critical » Normal

It requires code changes to do this.

These can either be via a form_alter, or changes to the module itself.

fibie’s picture

Ok for the benefit of newbies like me here is what I changed

The lines I removed from the code are:

$form['currency_code'] = array(
'#type' => 'select',
'#title' => t('Currency'),
'#options' => simple_paypal_get_currencies(),
'#name' => 'currency_code',
'#description' => t('The Drupal Association accepts payments in these two currencies.'),
);

and I replaced this with:

$form['currency_code'] = array(
'#type' => 'hidden',
'#value' => 'GBP',
'#name' => 'currency_code'
);

Seems to work but if anyone could tell me if I have done anything fundmentally wrong here it would be appreciated :)

kbahey’s picture

Your solution is good enough. The fact that you looked up FAPI options and selected hidden is worthy of admiration.

However, if you upgrade the module, you have to redo the changes every time.

Ideally, this would be two options in the settings page: which currency is the default currency, and whether to show the currency selection box or not.

fibie’s picture

Thank you for your comments and for a great module.

I agree it would be best if these options were built in to the module for upgrade-ability so will add this as a feature request,

Thanks :)

kbahey’s picture

The other option I mentioned, which does not modify the module's code, is using hook_form_alter() in a separate module to modify the currency and make it hidden. It is a bit more work, but avoids changing the source of the module.

jbomb’s picture

StatusFileSize
new2.73 KB

Ideally, this would be two options in the settings page: which currency is the default currency, and whether to show the currency selection box or not.

Here's a patch that adds those two fields

jbomb’s picture

Status: Active » Needs review
kbahey’s picture

Version: 5.x-1.0 » 5.x-1.x-dev
Status: Needs review » Needs work
$ patch -p0 < donation-5.x-1.0_default_currency.patch
patching file donation.module
Hunk #1 succeeded at 118 (offset 5 lines).
Hunk #2 FAILED at 535.
1 out of 2 hunks FAILED -- saving rejects to file donation.module.rej

Please reroll against what is in -dev.

jbomb’s picture

StatusFileSize
new4.63 KB
jbomb’s picture

Status: Needs work » Needs review
kbahey’s picture

Status: Needs review » Needs work

- Please make the variable_get() as defines to be consistent.

- This is redundant if (variable_get('donation_force_default', 0) == 1) {. No need to == 1 part.

- There are many places with too much inlining, such as array_intersect_key(donation_get_currencies(), array_flip(variable_get(DONATION_CURRENCY_OPTIONS, array('USD', 'GBP')))),. Better separate that into its own function for more readability.

- I presume that this patch is fully tested and working. Right?

jbomb’s picture

StatusFileSize
new5.46 KB

kbahey:

i've made the changes that you suggested in your previous comment.

In regards to testing, I have tried it out with the gateway in Simple PayPal Framework set to sandbox, and have received the expected IPN messages in the logs. I have not tested the patch in a production environment because I'm not currently supporting any sites that are accepting any currency other that USD. If you think it's necessary I'd be happy to roll it out on a test site and donate a few dollars to myself, but that's as far as I can go without peer review.

The dev snapshot looks like the project was heading towards supporting other currencies out of the box. If nothing else perhaps this patch can assist in those efforts.

Note: I didn't change the status to "needs review" because the patch doesn't include the following declaration in the currency_code field on the donation form.

   '#description' => variable_get(DONATION_CURRENCY_TEXT, DONATION_CURRENCY_DEFAULT_TEXT), 

I should point out that it appears that the constant DONATION_CURRENCY_TEXT is not defined.

kbahey’s picture

Fails ...

$ patch -p0 --dry-run < donation-5.x-dev-currency-options1.patch 
patching file donation.module
Hunk #2 FAILED at 121.
Hunk #3 FAILED at 198.
Hunk #4 FAILED at 554.
Hunk #5 succeeded at 652 (offset 53 lines).
3 out of 5 hunks FAILED -- saving rejects to file donation.module.rej
jbomb’s picture

Title: Make currencies configurable » How to lose the currency options?
Status: Fixed » Needs work

I'm sorry.

kbahey’s picture

Title: How to lose the currency options? » Make currencies configurable
Status: Needs work » Fixed

My mistake. My sandbox contained a patched version from earlier tries.

I applied the patch in #12, and fixed the undefined variables. Also removed the t() from variables.

The changes should be in -dev in about 8 hours from now.

Please disable then uninstall the version you have and download the new version and test it.

venkat-rk’s picture

Title: How to lose the currency options? » Make currencies configurable
Status: Needs work » Fixed

Currency configuration works as expected in the dev version. I haven't tested it in a live transaction, but only the configured currencies are displayed at /donate and the default currency setting also works.

This patch puts the currency configuration in the donation module instead of the simple_paypal module (there was a discussion about this - the relevant comments are: http://drupal.org/node/164807#comment-960438 and http://drupal.org/node/164807#comment-1189408), but that is a call for kbahey to take, I guess.

jbomb, thanks a ton for your patches!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.