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

Update docblock for doPayment function #13844

Merged
merged 1 commit into from
Apr 29, 2019

Conversation

mattwire
Copy link
Contributor

Overview

Further investigation and explanation into how and when contributions are created in relation to doPayment

Before

Less clear

After

More clear

Technical Details

Comments

Comments

@eileenmcnaughton This extends what I wrote, as I found out some more.

@civibot
Copy link

civibot bot commented Mar 16, 2019

(Standard links)

@civibot civibot bot added the master label Mar 16, 2019
* by those workflows. Ideally all workflows would create a pending contribution BEFORE calling doPayment (eg. https://github.com/civicrm/civicrm-core/pull/13763 for events)
* @fixme Creating a contribution record is inconsistent! We should always create a contribution BEFORE calling doPayment. However currently:
* * Contribution Pages: Creates a contribution before calling doPayment.
* * Contribution Pages with Membership: Does NOT create a contribution. UNLESS auto-renew=TRUE in which case both a recurring contribution
Copy link
Contributor

Choose a reason for hiding this comment

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

@mattwire I think that when there is no recurring it does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eileenmcnaughton When there is no recurring what does? contribution page with membership does not create a contribution if auto renew is disabled.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm - I'd have to spend a while digging to check but we have

  • membership with separate contribution
  • membership without separate contribution
  • the above with combinations of renew

My other worry about documenting the gaps here is we might not remember to remove them - perhaps we should instead be more aggressively documenting the places that should, but don't, create pending contributions or using an issue in gitlab to track the last status of the meta project 'make all places create pending & then call doPayment & then call Payment.create' and just point to that from here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eileenmcnaughton Every time I work on / develop a payment processor I have to go through and guess what might be returned and what should happen. I'm proposing adding these code comments because it's the only place a developer will actually find them! And better to start by documentation what is actually happening (with lot's of @fixme tags indicating this is not the preferred way). If we were going to fix all the "known" and the "unknown" workflows in the next release I'd agree, but realistically it's a year or two away and in the mean time we still need payment processors to try and actually work.

* 'payment_status_id' => {as above}
* 'trxn_id' => {trxn ref to link to record at payment processor}
* 'fee_amount' => {optional fee charged by processor}
* 'net_amount' => {optional net amount (ie. amount minus fee))}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should encourage returning net_amount - that can be calculated & will be elsewhere if not returned

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally we should be returning nothing but payment_status_id and the payment processor should be saving the other parameters. The workflows will only save certain parameters, net_amount is one of them. The comment states that these should only be passed if a contribution ID is not created - and it's marked as optional. In the long run when all flows are fixed this won't matter.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't think we should document net_amount as we don't want to be recommending something that is not preferred

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Problem we've got is that it's the only way you can actually record the amount - see eg. https://github.com/civicrm/civicrm-core/blob/master/CRM/Event/Form/Registration/Confirm.php#L1002

This comment is not meant to be "how it should be done" as that requires refactoring all these workflows so contribution is created first, at which point the payproc can take care of any/all of these params. But this is how it "has to be done" currently if you actually want to save these params.

Copy link
Contributor

Choose a reason for hiding this comment

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

if net_amount is empty it will still be calculated in the BAO no ?

@mattwire mattwire added the needs-work-not-review-ready Submitter required to take action, will be closed after 1-2 weeks in this state label Apr 4, 2019
@mattwire mattwire changed the title More essay about doPayment and contributions WIP More essay about doPayment and contributions Apr 4, 2019
@mattwire
Copy link
Contributor Author

mattwire commented Apr 4, 2019

Need to decide whether this sits in the code, the docs or a gitlab issue as it needs to be updated each time we improve the code.

@mattwire mattwire force-pushed the corepaymentmore_essay branch from d257800 to 278c5e1 Compare April 29, 2019 21:10
@mattwire mattwire changed the title WIP More essay about doPayment and contributions Update docblock for doPayment function Apr 29, 2019
@mattwire
Copy link
Contributor Author

@eileenmcnaughton I've add the detail to a gitlab issue and linked it from the docblock. Also cleaned up the existing docblock somewhat. If you are happy please merge :-)

@eileenmcnaughton eileenmcnaughton merged commit 64ee429 into civicrm:master Apr 29, 2019
@eileenmcnaughton eileenmcnaughton removed the needs-work-not-review-ready Submitter required to take action, will be closed after 1-2 weeks in this state label Apr 29, 2019
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.

2 participants