Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use order api when creating a recurring membership from the Membershi… #20077

Merged
merged 1 commit into from
May 13, 2021

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Apr 16, 2021

Overview

Use order api + payment api when creating a recurring membership from the Membership back office form

Before

Layers of cludges to get it to do the right thing - there is a scary thing going on where the form passes the BAO a value to tell it to create the membership payment records - but only for the first membership (because the first one creates them all & it crashes if you do it for the second)

https://github.com/civicrm/civicrm-core/pull/20077/files#diff-7bf0a482fe0659604e1fc7d265db9eb60b0fcc0e24557f19a68747d402393fd2L352-L362

After

The flow we have been recommending is actually used - albeit narrowly - for card+recurring cases only

Order.create
Payment.create

Not this adds a feature Matt previously requested - ie the created membership id is returned from the order api. This
is only done for memberships at the moment in order to manage the scope but would be the pattern for other entities too as test cover is added (the pre-existing tests do specifically cover this in the context of this change - ie I added it to make the tests pass)

Technical Details

This removes the need for some 'magic' code from the membership BAO that was really only
there to support the fact that this code was doing some particularly convoluted
manoevering in order to share code with the front end form (since unshared).

Comments

@civibot
Copy link

civibot bot commented Apr 16, 2021

(Standard links)

@civibot civibot bot added the master label Apr 16, 2021
@eileenmcnaughton eileenmcnaughton force-pushed the mem_order branch 6 times, most recently from fef238d to ca52f33 Compare April 16, 2021 04:46
@eileenmcnaughton
Copy link
Contributor Author

Closing for now

CRM_Member_Form_MembershipTest::testSubmitRecur
CiviCRM_API3_Exception: invalid criteria for IN

/home/jenkins/bknix-dfl/build/core-20077-ogly/web/sites/all/modules/civicrm/api/api.php:134
/home/jenkins/bknix-dfl/build/core-20077-ogly/web/sites/all/modules/civicrm/CRM/Member/Form/Membership.php:1844
/home/jenkins/bknix-dfl/build/core-20077-ogly/web/sites/all/modules/civicrm/CRM/Member/Form/Membership.php:1530
/home/jenkins/bknix-dfl/build/core-20077-ogly/web/sites/all/modules/civicrm/CRM/Member/Form/Membership.php:1321
/home/jenkins/bknix-dfl/build/core-20077-ogly/web/sites/all/modules/civicrm/CRM/Member/Form.php:528
/home/jenkins/bknix-dfl/build/core-20077-ogly/web/sites/all/modules/civicrm/tests/phpunit/CRM/Member/Form/MembershipTest.php:795
/home/jenkins/bknix-dfl/build/core-20077-ogly/web/sites/all/modules/civicrm/tests/phpunit/CiviTest/CiviUnitTestCase.php:226
/home/jenkins/bknix-dfl/extern/phpunit7/phpunit7.phar:615

@eileenmcnaughton eileenmcnaughton force-pushed the mem_order branch 4 times, most recently from 999ec2c to 626b5f7 Compare April 17, 2021 01:26
@eileenmcnaughton
Copy link
Contributor Author

@monishdeb @kcristiano this is the PR that actually switches us over to using the Order api for the membership create (specifically in the recurring flow) - it also enables us to add one of the particularly weird chunks of code in the Membership BAO

With this done I can finally fix membership bao create to not use $ids & finish that part of the clean up & then figure out the next part that needs to be done

@eileenmcnaughton
Copy link
Contributor Author

@monishdeb @kcristiano are either of you able to find time to review / test this one?

@eileenmcnaughton
Copy link
Contributor Author

I guess I could put up a sub-pr to simplify it more

@kcristiano
Copy link
Member

@eileenmcnaughton I have taken a walk through it, I have built a tarball with the PR and deployed on test sites. So far so good. I do want to push on the recurring and a good r-run takes time. I've assumed you are ok with existing test cover as you've only tweak the test, not added anything new.

eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Apr 26, 2021
This is intended to simplify civicrm#20077
by switching to using functions to retrieve membership (as an array) and membershipID
rather than passing around variables
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Apr 27, 2021
This is intended to simplify civicrm#20077
by switching to using functions to retrieve membership (as an array) and membershipID
rather than passing around variables
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Apr 27, 2021
This is intended to simplify civicrm#20077
by switching to using functions to retrieve membership (as an array) and membershipID
rather than passing around variables
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Apr 27, 2021
This is intended to simplify civicrm#20077
by switching to using functions to retrieve membership (as an array) and membershipID
rather than passing around variables
@eileenmcnaughton
Copy link
Contributor Author

@kcristiano yes - I built up the test cover in advance of doing the refactor!

eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Apr 27, 2021
This is intended to simplify civicrm#20077
by switching to using functions to retrieve membership (as an array) and membershipID
rather than passing around variables
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Apr 27, 2021
This is intended to simplify civicrm#20077
by switching to using functions to retrieve membership (as an array) and membershipID
rather than passing around variables
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Apr 27, 2021
This is intended to simplify civicrm#20077
by switching to using functions to retrieve membership (as an array) and membershipID
rather than passing around variables
@eileenmcnaughton
Copy link
Contributor Author

@kcristiano I separated out #20153 - which is more 'just a refactor' - and once merged the actual changes in this should be pretty readable. I'll rebase this over that if it won't mess up your testing (ie rebase it into this PR & out again once merged) - but not if it will invalidate testing to date

@kcristiano
Copy link
Member

kcristiano commented Apr 30, 2021 via email

$memInfo = array_merge($params, ['membership_id' => $membership->id]);
$params['contribution'] = self::recordMembershipContribution($memInfo);
}

// Add/update MembershipPayment record for this membership if it is a related contribution
// @todo remove this - called from one remaining place in CRM_Member_Form_Membership
if (!empty($params['relate_contribution_id'])) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything to do with 'relate_contribution_id' is the weird magic that made it work despite doing things all out of order - getting rid of this sticky tape is 'the goal'

…p backoffice form

This removes the need for some 'magic' code from the membership BAO that was really only
there to support the fact that this code was doing some particularly convoluted
manoevering in order to share code with the front end form (since unshared).

Not this adds a feature Matt requested - the created membership id is returned. This
is only done for memberships at the moment but could be other entities too as
test cover is added (the membership tests fail without the change in this
PR so it has cover in the context it is added
@JoeMurray
Copy link
Contributor

@monishdeb please make this a priority. @eileenmcnaughton this is a very big achievement to get this PR together! Thanks.

Just to confirm the scope for run testing: we should be able to create and renew memberships with recurring payments on the backend. Presumably different types of payment processors from IPN callback ones to EFT ones should all work.

@eileenmcnaughton
Copy link
Contributor Author

eileenmcnaughton commented May 12, 2021

This PR only touches new membership and this code change focusses on new recurring payment processor memberships (recurring is not available on this form if not a payment processor membership)

Note that I think the logic could be fairly easily extended to all payment processor payments on this form (new membership) - although I had thought to include that in the following release

@monishdeb
Copy link
Member

I have tested this patch in my local, and it works fine. Tested with auto-renewal membership in live mode and the financial entries were recorded correctly. Doesn't seem to cause any breakage/regression. The Order.create API change make sense. Checked the related unit-test coverage and passed on local.

Overall
General standards
[r-explain] PASS
[r-user] PASS
[r-run] PASS

Developer standards
[r-tech] PASS
[r-code] PASS
[r-test] PASS

@monishdeb monishdeb merged commit b522e00 into civicrm:master May 13, 2021
@eileenmcnaughton
Copy link
Contributor Author

Thanks @monishdeb - yay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants