5

I have a situation where the Contributions are being set to Cancelled when the user contribution fails (payment processor fails the transaction). So, the user is blocked to try a new contribution until an administrator excludes that Membership with Cancelled status.

I took a look at documentation and understood that Membership Cancelled status would only be set manually, so I can't figure out why this situation is happening. I assured that "Override status" is not checked in the Membership edit panel, so it looks like something in the system is setting the Membership to Cancelled status. I wonder why and I need to fix it. Any clues?

Ps: The Payment processor IPN could be doing this?

PS2: I'm using Joomla! and the Payment Processor is PagSeguro.

3
  • I think I have a 'i have this problem too' and don't want to open a new ticket. I see Luciano's answer was accepted but not sure about that. Scenario - existing member goes to renew, enters incorrect cc - their Contribution is set to FAILED and their Membership (which might have been Current, or Grace) is set to CANCELLED. They are then disallowed from renewing again. I do not think this is correct outcome
    – petednz - fuzion
    Commented Mar 7, 2016 at 22:06
  • Trying to gather more examples of Payment Processors this is happening with to help confirm where this problem is kicking in since it can't be replicated with those on dmaster.
    – petednz - fuzion
    Commented Mar 21, 2017 at 8:18
  • This issue has recurred recently, being worked on here: lab.civicrm.org/dev/core/-/issues/2517
    – Alan Dixon
    Commented Apr 30, 2021 at 13:30

3 Answers 3

3
+50

This is the expected behavior in CiviCRM, when you have a Contribution related to a Membership, and you set its Contribution status as Cancelled (manually or automatically through a ipn payment processor) it will cancel the Membership too. You can take a look to source code (4.6.x) where this is happening

https://github.com/civicrm/civicrm-core/blob/4.6/CRM/Contribute/BAO/Contribution.php#L1512

You can patch civicrm core to avoid Membership to be Cancelled when Contribution around this line:

https://github.com/civicrm/civicrm-core/blob/4.6/CRM/Contribute/BAO/Contribution.php#L1484

if (!$baseIPN->validateData($input, $ids, $objects, FALSE)) {
  CRM_Core_Error::fatal();
}

// ## Patch Begin ## Fix to not update membership status when updating contribution status
$memberships   = array(); //&$objects['membership'];
// ## Patch End ##
$participant   = &$objects['participant'];
$pledgePayment = &$objects['pledge_payment'];

There is a forum thread discussing this:

http://forum.civicrm.org/index.php/topic,34082.msg154608.html#msg154608

5
  • I do think this patch is good to solve the functional need in your project. However keep in mind that when you are patching CiviCRM your upgrades to a newer version requires you to review all the patches you have made. So from maintancability I would suggest to try to implment this in an extension. That is probably a little bit more complex. However it probably saves your headaches in the futrure when upgrading civicrm. Commented May 25, 2015 at 16:33
  • I agree, definitely patching civicrm core needs a lot of care when you upgrade CiviCRM versions. But I didn't find a better way to fix this. In an extension you would have to override CRM_Contribute_BAO_Contribution anyway to avoid this behavior with the same consequences
    – luciano_s
    Commented May 25, 2015 at 16:37
  • Thank you Luciano, but I checked in my system that the contributions are not Cancelled, but Failed, another kind of status. I took a look at Contribution.php#L1542 and saw that a failed Contribution should result in an expired Membership, is my understand correct? If so, I still can't see why those Memberships are being Cancelled by the system. Could it be a bug?
    – diegov
    Commented May 25, 2015 at 17:24
  • When the Contribution is Canceled it sets the Membership status to Canceled, when the Contribution is Failed it changes the Membership status to Expired. As I said, it is the expected behavior of CiviCRM by design. you can check in source code where the Membership is expired: github.com/civicrm/civicrm-core/blob/4.6/CRM/Contribute/BAO/…
    – luciano_s
    Commented May 26, 2015 at 8:25
  • The proposed patch removes all updates from contribution status to membership status. If you only want to remove the canceled contribution from being applied to the membership, you should only deactivate the part in : if ($contributionStatusId == array_search('Cancelled', $contributionStatuses)) { ... }
    – samuelsov
    Commented Mar 2, 2016 at 17:36
2

I believe there is some incorrect logic here and have opened a JIRA issue and am hoping client will fund.

If an existing user goes to renew a membership, makes an error with their CC - and hence has a Failed contribution, then there is no reason that i can think of why their existing membership should be set to Cancelled. Currently it means they are prevented from trying to renew again.

Outcome, imo, should be that if a Membership exists, and a payment Fails, then the membership status should be left how it was.

1

Whenever a transaction fails in payment processor the corresponding contribution gets cancelled. This is done by IPN.

But this shouldn't restrict the user from making a payment again or login (I guess you are using WordPress and SagePay).

If this happens, you should be checking the user permissions (roles) and you should be providing access for cancelled membership, saying if the member has a cancelled membership we should still allow the member to login.

5
  • No, the element that gets Cancelled status is the Membership, not the Contribution, this one gets Failed. It's expected that Cancelled membership blocks the user, as it should be an administrative status. The problem is that Cancelled should not be set in the event of failed contribution. BTW, I'm using Joomla and PagSeguro, a Brazilian Payment processor.
    – diegov
    Commented May 19, 2015 at 11:50
  • if you are getting failed it mean the user has tried to make a payment and the Card is not a valid one. so, the transaction is set to Failed. Commented May 19, 2015 at 13:16
  • I had a same issue once, in this case, I just deleted the new membership which has a status as failed and allowed the user to make a new application. Please, try and let me know the status. thanks Commented May 19, 2015 at 13:25
  • 1
    Membership doesn't have a Failed status, only Cancelled. Contribution has a Failed status. If I delete the Cancelled membership sure that the user can make a new one, that's not my problem, the problem is to stop that of happen, I can't stay removing the membership every time it happens.
    – diegov
    Commented May 19, 2015 at 15:25
  • when user cancels the transaction we get failed status. if you don't want to get failed status then in IPN change the status to something else and update the contribution Commented May 20, 2015 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.