Answers.Body: <p>I believe there is some incorrect logic here and have opened a <a href="https://issues.civicrm.org/jira/browse/CRM-18177" rel="nofollow">JIRA issue</a> and am hoping client will fund.</p>
  
  <p>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.</p>
  
  <p>Outcome, imo, should be that if a Membership exists, and a payment Fails, then the membership status should be left how it was.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T22:18:01.873Z
Answers.LastActivityDate: 2016-03-08T03:14:42.727Z
Answers.LastEditDate: 2016-03-08T03:14:42.727Z
Answers.UserDisplayName: petednz - fuzion
Answers.Body: <p>Whenever a transaction fails in payment processor the corresponding contribution gets cancelled. This is done by IPN. </p>
  
  <p>But this shouldn't restrict the user from making a payment again or login 
  (I guess you are using WordPress and SagePay).</p>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-19T11:50:34.583Z
Answers.Text: 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.
Answers.UserDisplayName: diegov
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-19T13:16:40.967Z
Answers.Text: 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.
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-19T13:25:15.830Z
Answers.Text: 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
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-19T15:25:30.290Z
Answers.Text: 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.
Answers.UserDisplayName: diegov
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-20T09:55:32.077Z
Answers.Text: 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
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-19T11:47:01.337Z
Answers.LastActivityDate: 2015-05-28T02:22:16.997Z
Answers.LastEditDate: 2015-05-28T02:22:16.997Z
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Answers.Body: <p>This is the expected behavior in CiviCRM, when you have a Contribution related to a Membership, and you set its Contribution status as <strong>Cancelled</strong> (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</p>
  
  <p><a href="https://github.com/civicrm/civicrm-core/blob/4.6/CRM/Contribute/BAO/Contribution.php#L1512" rel="nofollow">https://github.com/civicrm/civicrm-core/blob/4.6/CRM/Contribute/BAO/Contribution.php#L1512</a></p>
  
  <p>You can patch civicrm core to avoid Membership to be Cancelled when Contribution around this line:</p>
  
  <p><a href="https://github.com/civicrm/civicrm-core/blob/4.6/CRM/Contribute/BAO/Contribution.php#L1484" rel="nofollow">https://github.com/civicrm/civicrm-core/blob/4.6/CRM/Contribute/BAO/Contribution.php#L1484</a></p>
  
  <pre><code>if (!$baseIPN-&gt;validateData($input, $ids, $objects, FALSE)) {
    CRM_Core_Error::fatal();
  }
  
  // ## Patch Begin ## Fix to not update membership status when updating contribution status
  $memberships   = array(); //&amp;$objects['membership'];
  // ## Patch End ##
  $participant   = &amp;$objects['participant'];
  $pledgePayment = &amp;$objects['pledge_payment'];
  </code></pre>
  
  <p>There is a forum thread discussing this:</p>
  
  <p><a href="http://forum.civicrm.org/index.php/topic,34082.msg154608.html#msg154608" rel="nofollow">http://forum.civicrm.org/index.php/topic,34082.msg154608.html#msg154608</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-02T17:36:45.570Z
Answers.Text: 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)) { ... }
Answers.UserDisplayName: samuelsov
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-25T16:33:21.377Z
Answers.Text: 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.
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-25T16:37:39.267Z
Answers.Text: 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
Answers.UserDisplayName: luciano_s
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-25T17:24:00.623Z
Answers.Text: 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?
Answers.UserDisplayName: diegov
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-26T08:25:56.597Z
Answers.Text: 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:   https://github.com/civicrm/civicrm-core/blob/4.6/CRM/Contribute/BAO/Contribution.php#L1542
Answers.UserDisplayName: luciano_s
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-25T14:50:14.033Z
Answers.LastActivityDate: 2015-05-25T14:57:34.047Z
Answers.LastEditDate: 2015-05-25T14:57:34.047Z
Answers.UserDisplayName: luciano_s
Body: <p>I have a situation where the Contributions are being set to <strong>Cancelled</strong> when the user contribution <strong>fails</strong> (payment processor fails the transaction). So, the user is blocked to try a new contribution until an administrator excludes that Membership with <strong>Cancelled</strong> status.</p>
  
  <p>I took a look at documentation and understood that Membership <strong>Cancelled</strong> 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 <strong>Membership to Cancelled</strong> status. I wonder why and I need to fix it. Any clues?</p>
  
  <p>Ps: The Payment processor IPN could be doing this?</p>
  
  <p>PS2: I'm using Joomla! and the Payment Processor is PagSeguro.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-07T22:06:38.623Z
Comments.Text: 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
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-21T08:18:41.523Z
Comments.Text: 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.
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-04-30T13:30:42.117Z
Comments.Text: This issue has recurred recently, being worked on here: https://lab.civicrm.org/dev/core/-/issues/2517
Comments.UserDisplayName: Alan Dixon
Tags: <civicontribute><civimember><contributions>
Title: Membership sets to Cancelled when Contribution Fails. Why?
ThreadText: # Membership sets to Cancelled when Contribution Fails. Why?
  
  (Asked by: username_0 on 2015-05-19)
  
  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.
  
  **Tags:** civicontribute, civimember, contributions
  
  > **Comments:**
  > **username_1**: 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  
  > **username_1**: 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.  
  > **username_2**: This issue has recurred recently, being worked on here: https://lab.civicrm.org/dev/core/-/issues/2517  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_4 on 2015-05-25. Score: 3 | Accepted answer
  
  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>
  
  > **Comments:**
  > **username_6**: 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.  
  > **username_4**: 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  
  > **username_0**: 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?  
  > **username_4**: 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:   https://github.com/civicrm/civicrm-core/blob/4.6/CRM/Contribute/BAO/Contribution.php#L1542  
  > **username_5**: 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)) { ... }  
  
  ---
  
  ### Answer by username_1 on 2016-03-07. Score: 2
  
  I believe there is some incorrect logic here and have opened a [JIRA issue](https://issues.civicrm.org/jira/browse/CRM-18177) 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.
  
  
  ---
  
  ### Answer by username_3 on 2015-05-19. Score: 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.
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_3**: 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.  
  > **username_3**: 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  
  > **username_0**: 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.  
  > **username_3**: 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  
  
  ---
  
  