When trying to apply a "free trial" coupon code, the following error is returned: "The coupon code you have entered is not valid in EUR.".

Looking up this error I traced it to the following lines starting at build/sites/all/modules/contrib/recurly/modules/recurlyjs/includes/recurlyjs.pages.inc:668, where only amount discounts are allowed. A check for free trial coupons should be added and allowed (see https://docs.recurly.com/v1.0/docs/coupons#section-free-trial-coupons).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andreigg created an issue. See original summary.

andreigg’s picture

The following patch fixes the problem traced in recurlyjs/recurlys.pages.inc

diff --git a/sites/all/modules/contrib/recurly/modules/recurlyjs/includes/recurlyjs.pages.inc b/sites/all/modules/contrib/recurly/modules/recurlyjs/includes/recurlyjs.pages.inc
index e1e4b91..a7251e4 100644
--- a/sites/all/modules/contrib/recurly/modules/recurlyjs/includes/recurlyjs.pages.inc
+++ b/sites/all/modules/contrib/recurly/modules/recurlyjs/includes/recurlyjs.pages.inc
@@ -666,7 +666,7 @@ function _recurlyjs_element_validate_coupon_code($element, &$form_state, $form)
     return;
   }
   // Check that the coupon is available in the specified currency.
-  if ($coupon && $coupon->discount_type !== 'percent') {
+  if ($form_state['coupon'] && !in_array($form_state['coupon']->discount_type, array('percent', 'free_trial'))) {
     if (!$coupon->discount_in_cents->offsetExists($currency)) {
       form_error($element, t('The coupon code you have entered is not valid in @currency.', array('@currency' => $currency)));
       return;
andreigg’s picture

The code exists already in includes/recurly.pages.inc but did not exist in modules/recurlyjs/includes/recurlyjs.pages.inc. The patch above fixes the issue reported in this ticket.

markdorison’s picture

Version: 7.x-3.0 » 7.x-3.x-dev
Status: Active » Needs work

@andreigg

If you could attach those changes in a patch file it would be much appreciated. Documentation: Making a Drupal patch with Git

tibezh’s picture

Status: Needs work » Needs review
FileSize
812 bytes

Here is a patch

markdorison’s picture

+++ b/modules/recurlyjs/includes/recurlyjs.pages.inc
@@ -667,7 +667,7 @@ function _recurlyjs_element_validate_coupon_code($element, &$form_state, $form)
+  if ($form_state['coupon'] && !in_array($form_state['coupon']->discount_type, array('percent', 'free_trial'))) {

You are now examining the $form_state['coupon'] object instead of $coupon; is that intentional?

tibezh’s picture

Oh, sorry, I hurried
Take a look for a new patch please

markdorison’s picture

Status: Needs review » Reviewed & tested by the community

The patch in #7 looks good. It also looks like this fix is already included in 8.x-1.x.

  • markdorison committed 68117d3 on 7.x-3.x authored by andreigg
    Issue #2928302 by tibezh, andreigg: Cannot use free_trial coupon code
    
markdorison’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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