Membership and Auto-Renew issues
Overview WORK IN PROGRESS Parts of this are gradually being extracted into smaller, easier to review PRs. Once this is fully reviewed and merged documentation will also need updating. Ref: https://github.com/civicrm/civicrm-core/pull/12315
This is mostly code cleanup and an attempt to understand exactly what happens when a membership is automatically renewed!
Fixes (and this needs adding to Civi docs somewhere as it's currently undocumented and unclear what it does):
Before
- Membership will be renewed when contribution is in ANY state except "Pending."
- All parameters of recurring contribution are ignored, ie installments, frequency mismatch (eg. monthly recurring, annual membership) so every new contribution will trigger a membership renewal.
- When repeattransaction is called ONLY the membership linked to the original contribution will be renewed (if the contribution is in the correct state (ie. Completed - see Before/After)). loadRelatedObjects only loads one membership but the code is expected all memberships to be loaded so does handle multiple memberships if passed in.
After
- Membership will be renewed ONLY when contribution is in state "Completed".
- Membership will be renewed ONLY if the recurring and membership type frequencies match. Installments parameter has no effect.
- When repeattransaction is called: If the contribution has a recurring contribution ID then ALL memberships linked to that recurring contribution will be renewed. If the contribution has no recurring contribution then the membership linked to the original contribution will be renewed (if the contribution is in the correct state (ie. Completed - see Before/After) AND the other conditions are met (ie. state, frequency)).
Documentation (After)
- Membership will be renewed ONLY when contribution is in state "Completed" - https://github.com/civicrm/civicrm-core/pull/12315 (5.5.0)
- Membership will be renewed ONLY if the recurring and membership type frequencies match (Installments are ignored).
- When repeattransaction is called any linked memberships will be renewed if the contribution is in the correct state. If there is a recurring contribution then the frequencies must also match (installments are ignored).
- A recurring contribution can be linked to multiple memberships and all memberships will be updated/renewed if all other conditions are met - https://github.com/civicrm/civicrm-core/pull/12542 (pending merge)