Answers.Body: <p>You should make sure that you have both membership_payment records and the contribution_recur_id set for both the contribution and the membership. There are <em>still</em> too many different code paths that can behave slightly differently - it's an area that's seen a lot of improvement but still has a long way to go.</p>
  
  <p><code>CRM_Member_BAO_Membership::recordMembershipContribution()</code> is an example of a function that creates a membership_payment.</p>
  
  <p>Note that <code>completetransaction</code> should only ever be called for the first contribution. Subsequent payments should call <code>Contribution.repeattransaction</code> API.</p>
  
  <p>Also of relevance is <code>CRM_Contribute_BAO_ContributionRecur::getTemplateContribution()</code> which controls how the next contribution is created - so if that returns a contribution that is not linked to a membership you won't get a membership renewal.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-31T18:14:48.450Z
Answers.Text: "Note that completetransaction should only ever be called for the first contribution. Subsequent payments should call Contribution.repeattransaction API." Sorry - that was my typo. It is calling repeattransaction.
Answers.UserDisplayName: michaelmcandrew
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-31T18:15:26.787Z
Answers.Text: "You should make sure that you have both membership_payment records and the contribution_recur_id set for both the contribution and the membership." Yes - that is what I am trying to do :)
Answers.UserDisplayName: michaelmcandrew
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-31T18:18:52.057Z
Answers.Text: "Also of relevance is CRM_Contribute_BAO_ContributionRecur::getTemplateContribution() which controls how the next contribution is created". Intriguing! I will investigate.
Answers.UserDisplayName: michaelmcandrew
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-26T21:54:55.167Z
Answers.LastActivityDate: 2020-03-26T21:54:55.167Z
Answers.UserDisplayName: Matthew Wire
Answers.Body: <p>Unfortunately CiviCRM doesn't look for civicrm_membership.contribution_recur_id t update the membership. I believe for membership to get auto renewed it should have</p>
  
  <ol>
  <li><p>The latest recurring contribution for the membership should be linked via civicrm_membership_payment</p></li>
  <li><p>civicrm_line_item.contribution_id should be set for the membership (the latest one)</p></li>
  </ol>
  
  <p>Since you had added membership to the standalone recurring contribution than you need to make sure that above 2 step is fixed before next subsequent payment is recorded.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-31T18:19:25.173Z
Answers.Text: Thanks Pradeep. I will take a look at the civicrm_line_item table.
Answers.UserDisplayName: michaelmcandrew
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-26T21:43:53.423Z
Answers.LastActivityDate: 2020-03-26T21:43:53.423Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I'm working with @wmortada debugging some recurring contribution membership renewal issues.</p>
  
  <p>We have lots of memberships with recurring contributions but some of the memberships are not updating as expected when the recurring contribution is received.</p>
  
  <p>The memberships that were not updating were not linked to the recurring contributions via the <code>civicrm_membership.contribution_recur_id</code> field. So we added recurring contribution the link manually. My assumption was that when a contribution for a recurring contribution linked to a membership in this way is received, it would be linked to the membership. But this is not happening for those where we added the field manually.</p>
  
  <p>As a result (as I understand it) <code>CRM_Contribute_BAO_Contribution::updateMembershipBasedOnCompletionOfContribution()</code> is unable to find the related membership and update the membership end date.</p>
  
  <p>We are using @artfulrobot's GoCardless extension for the recurring contribution. <code>CRM_GoCardless_Page_Webhook::doPaymentsConfirmed()</code> calls <code>civicrm_api3('Contribution', 'repeattransaction', $contribution);</code> passing in params for a contribution linked to the recurring contribution.</p>
  
  <p>Can anyone point me to the code that adds a membership payment for a contribution created by <code>Contribution.repeattransaction</code>. Or do I have the wrong end of the stick?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-02T18:12:04.413Z
Comments.Text: Possibly helpful analysis of a similar situation in paypal: [Recurring contribution fails with "ipn_payment_callback_exception", for membership auto-renewal via PayPalPro](https://lab.civicrm.org/dev/core/-/issues/1608)
Comments.UserDisplayName: TwoMice
Tags: <civimember><recurring-contributions><gocardless>
Title: some recurring contributions linked to memberships are not moving on the membership end date
ThreadText: # some recurring contributions linked to memberships are not moving on the membership end date
  
  (Asked by: username_0 on 2020-03-26)
  
  I'm working with @wmortada debugging some recurring contribution membership renewal issues.
  
  We have lots of memberships with recurring contributions but some of the memberships are not updating as expected when the recurring contribution is received.
  
  The memberships that were not updating were not linked to the recurring contributions via the `civicrm_membership.contribution_recur_id` field. So we added recurring contribution the link manually. My assumption was that when a contribution for a recurring contribution linked to a membership in this way is received, it would be linked to the membership. But this is not happening for those where we added the field manually.
  
  As a result (as I understand it) `CRM_Contribute_BAO_Contribution::updateMembershipBasedOnCompletionOfContribution()` is unable to find the related membership and update the membership end date.
  
  We are using @artfulrobot's GoCardless extension for the recurring contribution. `CRM_GoCardless_Page_Webhook::doPaymentsConfirmed()` calls `civicrm_api3('Contribution', 'repeattransaction', $contribution);` passing in params for a contribution linked to the recurring contribution.
  
  Can anyone point me to the code that adds a membership payment for a contribution created by `Contribution.repeattransaction`. Or do I have the wrong end of the stick?
  
  **Tags:** civimember, recurring-contributions, gocardless
  
  > **Comments:**
  > **username_1**: Possibly helpful analysis of a similar situation in paypal: [Recurring contribution fails with "ipn_payment_callback_exception", for membership auto-renewal via PayPalPro](https://lab.civicrm.org/dev/core/-/issues/1608)  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-03-26. Score: 4
  
  You should make sure that you have both membership\_payment records and the contribution\_recur\_id set for both the contribution and the membership. There are *still* too many different code paths that can behave slightly differently - it's an area that's seen a lot of improvement but still has a long way to go.
  
  `CRM_Member_BAO_Membership::recordMembershipContribution()` is an example of a function that creates a membership\_payment.
  
  Note that `completetransaction` should only ever be called for the first contribution. Subsequent payments should call `Contribution.repeattransaction` API.
  
  Also of relevance is `CRM_Contribute_BAO_ContributionRecur::getTemplateContribution()` which controls how the next contribution is created - so if that returns a contribution that is not linked to a membership you won't get a membership renewal.
  
  > **Comments:**
  > **username_0**: "Note that completetransaction should only ever be called for the first contribution. Subsequent payments should call Contribution.repeattransaction API." Sorry - that was my typo. It is calling repeattransaction.  
  > **username_0**: "You should make sure that you have both membership_payment records and the contribution_recur_id set for both the contribution and the membership." Yes - that is what I am trying to do :)  
  > **username_0**: "Also of relevance is CRM_Contribute_BAO_ContributionRecur::getTemplateContribution() which controls how the next contribution is created". Intriguing! I will investigate.  
  
  ---
  
  ### Answer by username_3 on 2020-03-26. Score: 2
  
  Unfortunately CiviCRM doesn't look for civicrm\_membership.contribution\_recur\_id t update the membership. I believe for membership to get auto renewed it should have
  
  1. The latest recurring contribution for the membership should be linked via civicrm\_membership\_payment
  2. civicrm\_line\_item.contribution\_id should be set for the membership (the latest one)
  
  Since you had added membership to the standalone recurring contribution than you need to make sure that above 2 step is fixed before next subsequent payment is recorded.
  
  > **Comments:**
  > **username_0**: Thanks username_3. I will take a look at the civicrm_line_item table.  
  
  ---
  
  