-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
Make contribution_id mandatory for PaymentProcessor.Pay API #15477
Conversation
(Standard links)
|
be03826
to
6713ef6
Compare
Looks like I looked at these back to front :-) I'm just trying to think about whether there are some cases where the payment needs to be started on the first page (before the contribution id exists) or whether we can always use a separate preApprove action there (which might need to be in core as an api) |
@eileenmcnaughton I was tasked with documenting this API so thought I'd better actually try using it :-) As this API is basically a thin wrapper for We've agreed in https://lab.civicrm.org/dev/financial/issues/53 that we must always have a contribution before processing payment so by definition we must have a contribution ID when calling |
6713ef6
to
a4b3f79
Compare
Ok - I took a look at the 2 places I know of using this api (which is probably the only 2). Omnipay looks like this
contributionID has some 'credibility' as an input for doPayment & I think it makes sense to add it as an alias so either / or are supported. @ejegg the only other place is in SmashPig. To comply with this change the flow would need to change from
to creating the pending payment first & updating it after. This is the agreed flow & I think it makes sense for us to change SmashPig when we next update to comply. |
@eileenmcnaughton But this is a "new" API. Historically we've ended in a huge mess where you might need to retrieve the contribution ID from various places. Can we just standardise at the API interface and support ONLY one parameter - |
@mattwire yes - so the issue is the parameters are passed through to doPayment from various places currently & the list above kinda reflects those. It would be good to normalise those but I think we'd need to add getters & setters on CRM_Core_Payment like
|
@eileenmcnaughton Right, I misunderstood your comment. The API should only accept |
a4b3f79
to
dac0e11
Compare
@eileenmcnaughton I've pushed a change that sets contributionID |
@mattwire I'd rather see us put some getters & setters in the CRM_Core_Payment than wrangle it in the api but I'd merge this now if it had a test |
@eileenmcnaughton Do we have any existing tests in core for PaymentProcessor.Pay API? I can't find anything. |
@mattwire maybe not! What we can use to check what is happening within it is the alterPaymentProcessorParams hook - to check doDirectPayment receives contributionID I think next we should define a bunch of getters & setters for the params we expect to be available to CRM_Core_Payment - we have done amount in the past which standardised that |
@eileenmcnaughton our recurring processor has an option to either create the donations directly or send them to a queue. We're running it with the queue setting as the queue consumer does some pre-processing to fill in a bunch of our custom fields. This change would mean we'd need to either let the queue consumer update a transaction from Pending to Completed while adding the custom fields (current code would drop the queue message as a duplicate txn) or, if we got rid of the 'send to queue' option, move that pre-processing to a Civi save hook. Ours is a pretty odd use case, so it doesn't feel right to block a core change if it would be more correct for the vast majority of users. |
@sarvesh211999 Can you write a unit test for this? An example can be found in api/v3/ContributionPageTest.php: |
@mattwire do you want to add a call to $processor->setContributionID() - it will duplicate passing it in but I think that is how we transition. |
…t is required by doPayment
dac0e11
to
95e1614
Compare
…or.pay, pass incoieID Replaces civicrm#15477 & also resolves https://lab.civicrm.org/dev/financial/issues/77 by requiring contribution_id for PaymentProcessor.pay as a way to ensure that it is only called after the order is created per our preferred flow (people could still get past this but it feels like they would at least know they werre hacking our process & take responsibility for any issues if it breaks or we suddenly start enforcing that it is a valid contribution. This also sets some of the recommended variables. Note that I had to use a few more lines to ensure we were always setting contactID, contributionRecurID to an integer. I do think this stricter approach is better but it wound up more verbose
I did the test in #15639 so closing this |
…or.pay, pass incoieID Replaces civicrm#15477 & also resolves https://lab.civicrm.org/dev/financial/issues/77 by requiring contribution_id for PaymentProcessor.pay as a way to ensure that it is only called after the order is created per our preferred flow (people could still get past this but it feels like they would at least know they werre hacking our process & take responsibility for any issues if it breaks or we suddenly start enforcing that it is a valid contribution. This also sets some of the recommended variables. Note that I had to use a few more lines to ensure we were always setting contactID, contributionRecurID to an integer. I do think this stricter approach is better but it wound up more verbose
Overview
Make contribution_id mandatory for API PaymentProcessor.pay. Per https://lab.civicrm.org/dev/financial/issues/53 we should always have a contribution before calling doPayment - that means we must pass in a contribution_id.
Before
contribution_id
not required by API PaymentProcessor.pay.After
contribution_id
required by API PaymentProcessor.pay.Technical Details
See https://lab.civicrm.org/dev/financial/issues/53.
Comments
@JoeMurray @eileenmcnaughton I'm trying to clear off a few "simple" fixes and backport them to the 5.19 RC so we've got a set of more useable APIs from 5.19 on. These should all be "safe" changes.