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

[WIP] Modify backend Record Payment forms to use payment create API. #13330

Closed
wants to merge 2 commits into from

Conversation

jitendrapurohit
Copy link
Contributor

Overview

Modify backend Record Payment forms to use payment create API and move API code to BAO layer.

Before

  1. payment create api exists but is not used by backend record payment forms.
  2. Email receipt is only accessible by backend forms.

After

Payment create API is used to records payments for pending or partially paid contributions.
Email receipt function is separated so that it can be also used by front-end payments.

Comments

This is a part of #12319 PR and it only contains fix for the backend payment forms. I'll create another PR to fix partial payment in front end contribution pages.

@magnolia61 Can you confirm if this works fine in your testing? Note that front end fix is yet to be created separately. Thanks.

ping @monishdeb @eileenmcnaughton

@civibot
Copy link

civibot bot commented Dec 20, 2018

(Standard links)

@magnolia61
Copy link
Contributor

magnolia61 commented Dec 21, 2018

I tested this PR on the RC and the scenario of a 50 euro event fee paid for and changed to 30 extra so the balance is 30.
Result when I use 'record payment' from the backend:

  1. The contribution as a whole changes to 'Completed'
  2. The line-item for the 30 euro extra keeps the status 'partially paid'
  3. An extra line item is created with status Complete
  4. Event status changes from Pending to Registered
  5. No confirmation email is being sent (maybe this is current and expected behavior). And by this I mean no confirmation email of the payment, nor of the event registration status change.

Note about nr.5 I think when using the backend it would be ideal if one submits a payment that completes the contribution for an event or membership, an option is given to either send an confirmation email or not. Sometimes am administrator just wants to register payments without sending emails to the participants. So either an optional confirmation mail or the current behavior: no mail after backend completion of an event contribution is ok I think.

eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Dec 30, 2018
This is a partial of civicrm#13330 - trying
to separate out the main code move from the changes. My only change was to change the name to
addPayment since that is what we are doing but here are some additionaly thoughts.

1) I'm inclined to put the class onto a new pseudo-bao CRM_Finanial_BAO_Payment. We already have this
pseudo-entity on the api level & it gives us a way to build up a place for the functions we are migrating
towards.

2) I think we should consider changing the input parameters to this function to be
- contributionID, total_amount & line_items or in some way limiting the parameters tha
t get passed through. We have historically gotten ourselves in trouble by
having people hacking in another parameter to go through whereas the strength of the api
is clear inputs & outputs. I note the api will need to support
'is_email_receipt' as will this fn & the CRM_Contribute_Form_AdditionalPayment::emailReceipt
should be moved off the form layer - possibly to our new BAO

3) I think the exceptions need to be CRM_Core_Exceptions if thrown in the BAO although this is kinda cosmetic
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Dec 31, 2018
This is a partial of civicrm#13330 - trying
to separate out the main code move from the changes. My only change was to change the name to
addPayment since that is what we are doing but here are some additionaly thoughts.

1) I'm inclined to put the class onto a new pseudo-bao CRM_Finanial_BAO_Payment. We already have this
pseudo-entity on the api level & it gives us a way to build up a place for the functions we are migrating
towards.

2) I think we should consider changing the input parameters to this function to be
- contributionID, total_amount & line_items or in some way limiting the parameters tha
t get passed through. We have historically gotten ourselves in trouble by
having people hacking in another parameter to go through whereas the strength of the api
is clear inputs & outputs. I note the api will need to support
'is_email_receipt' as will this fn & the CRM_Contribute_Form_AdditionalPayment::emailReceipt
should be moved off the form layer - possibly to our new BAO

3) I think the exceptions need to be CRM_Core_Exceptions if thrown in the BAO although this is kinda cosmetic
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Dec 31, 2018
This is a partial of civicrm#13330 - trying
to separate out the main code move from the changes. My only change was to change the name to
addPayment since that is what we are doing but here are some additionaly thoughts.

1) I'm inclined to put the class onto a new pseudo-bao CRM_Finanial_BAO_Payment. We already have this
pseudo-entity on the api level & it gives us a way to build up a place for the functions we are migrating
towards.

2) I think we should consider changing the input parameters to this function to be
- contributionID, total_amount & line_items or in some way limiting the parameters tha
t get passed through. We have historically gotten ourselves in trouble by
having people hacking in another parameter to go through whereas the strength of the api
is clear inputs & outputs. I note the api will need to support
'is_email_receipt' as will this fn & the CRM_Contribute_Form_AdditionalPayment::emailReceipt
should be moved off the form layer - possibly to our new BAO

3) I think the exceptions need to be CRM_Core_Exceptions if thrown in the BAO although this is kinda cosmetic

Change-Id: Ib5caf0d878e9c5cc735cb1a20c640f61da2dbfc6
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Dec 31, 2018
This is a partial of civicrm#13330 - trying
to separate out the main code move from the changes. My only change was to change the name to
addPayment since that is what we are doing but here are some additionaly thoughts.

1) I'm inclined to put the class onto a new pseudo-bao CRM_Finanial_BAO_Payment. We already have this
pseudo-entity on the api level & it gives us a way to build up a place for the functions we are migrating
towards.

2) I think we should consider changing the input parameters to this function to be
- contributionID, total_amount & line_items or in some way limiting the parameters tha
t get passed through. We have historically gotten ourselves in trouble by
having people hacking in another parameter to go through whereas the strength of the api
is clear inputs & outputs. I note the api will need to support
'is_email_receipt' as will this fn & the CRM_Contribute_Form_AdditionalPayment::emailReceipt
should be moved off the form layer - possibly to our new BAO

3) I think the exceptions need to be CRM_Core_Exceptions if thrown in the BAO although this is kinda cosmetic
@eileenmcnaughton
Copy link
Contributor

Seamus merged my 'move code only' sub-cut of this - so https://github.com/civicrm/civicrm-core/compare/master...eileenmcnaughton:payment_j?expand=1 is the rebased commit from this PR

I feel like the 2 things I feel I want clarity on at this stage are

  1. should we create a new class - per comments on the on [REF] extract internals of Payment.create into function on BAO class. #13370 for the payments functions we re migrating towards
  2. what is the correct email to send when a payment is received - ie. I assume that when a payment is received and we are fully paid we send the same email as we do for a normal contribution receipt but we use a separate email for a part payment? It might make sense to wrap this action in a sendconfirmation action like we do on Contribution - I see @magnolia61 has suggested we add a checkbox to determine whether to send an email on the form.

@monishdeb
Copy link
Member

@jitendrapurohit can you please rebase your PR

@eileenmcnaughton
Copy link
Contributor

eileenmcnaughton commented Jan 4, 2019

@jitendrapurohit @monishdeb I actually did a rebase - there was a link to it from the other PR - I didn't open it because I wanted to discuss the question of a new class for these functions first - per the #13370 comments & also the question about the email will affect a lot of things

eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Jan 13, 2019
… it.

This is per discussions coming off civicrm#13330

Note that this ONLY moves the code - that PR does other things as well that still need to be worked through
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Jan 13, 2019
… it.

This is per discussions coming off civicrm#13330

Note that this ONLY moves the code - that PR does other things as well that still need to be worked through
jgillmanjr pushed a commit to jgillmanjr/civicrm-core that referenced this pull request Jan 14, 2019
… it.

This is per discussions coming off civicrm#13330

Note that this ONLY moves the code - that PR does other things as well that still need to be worked through
@jitendrapurohit
Copy link
Contributor Author

I've rebased the PR with the current status of master. This now contains fixes related to

  • migration of email confirmation code to the newly added financial bao payment.php
  • Uses payment create API for backend payments.

@monishdeb
Copy link
Member

monishdeb commented Jan 23, 2019

I like this patch as it moves the code to process refund or owed payment into Payment.create API. Did a quick test with partial and refund payment in UI and it works fine, also with the Send Email reciept. Added UT looks good. @eileenmcnaughton @mattwire @magnolia61 any final thoughts before merging this PR?

On a separate note, how about moving CRM_Contribute_BAO_Contribution::recordAdditionalPayment to CRM_Financial_BAO_Payment::recordAdditionalPayment in a separate PR

if ($sendReceipt) {
$statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
}
if (empty($payment['is_error']) && !empty($this->_params['is_email_receipt'])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

So I think the payment params could be modified by hooks once Payment.create has been called but we are relying on the value of is_email_receipt from before that function is called. Are we able to use the returned parameters of Payment.create to check if is_email_receipt stayed TRUE and therefore an email actually got sent?

Copy link
Member

Choose a reason for hiding this comment

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

@mattwire I don't think payment params can be modified by any hooks, as I don't see pre/post hook are invoked inside Payment::create() BAO fn, or is there any at API level which I am unaware of?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, then I'm ok with this.

Copy link
Contributor

@mattwire mattwire left a comment

Choose a reason for hiding this comment

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

Just one comment about the is_email_receipt parameter. Apart from that all fine from me - nice cleanup too!

@eileenmcnaughton
Copy link
Contributor

So where I'm at with this in general is that the Payment.create function should send appropriate email receipts parameter dependent & I want to clarify that & get the tests sorted for that .

The current blocker for me is clarifying exactly what emails should go out (and getting that separately committed & tested in preparation). The Payment.create api would ideally be called from many forms - ie. we should anticipate that eventually we would replace all the places in the code that call Contribution.completetransaction with Payment.create (with the latter being called if the payment does complete a transaction.)

It seems to me we have 3 scenarios

  1. we don't want any emails to go out - the current bool seems adequate for this one :-)
  2. we want emails to go out and we are adding a payment but it does NOT complete the contribution
  3. we want emails to go out and we are adding a payment but it DOES complete the contribution - in this case what combination of payment receipt, contribution completed receipt, event receipt do we send out?

In the latter case do we send out the online invoice receipt as we would when calling Contribution.completeorder or some other one or do they get 2 receipts. What about in case 2? Is the off/on is_email_receipt the right parameter to pass in

@JoeMurray I pinged the above question to you somewhere else in the discussions around this but it got lost along the way

Note
At the moment 'payment_type' and 'participant_id' are being added to what is passed into payment.create but these seem like things that could be calculated from Payment create.

@monishdeb
Copy link
Member

monishdeb commented Jan 31, 2019

@eileenmcnaughton I have a concern in handling both partial and refund payment in a single Payment::create API rather than handling them in Payment::partial and Payment::refund, BAO fns and APIs respectively. Actually as per the refund spec here I suppose to have a separate API but if we I go with this PR fix then I shouldn't need to have separate API. What do you think? Or we should bring the separation in a separate PR ?

NOTE: The Payment::create should be restricted to Contribution.completetransaction + handling financial record on Complete payment.

@JoeMurray
Copy link
Contributor

Re: separate API for refund vs include in existing payment.create as a negative payment.

We're moving from merely recording refunds in CiviCRM to actually sending the money out in some current work.

Sending money out tends to need a separate permission. I would prefer for refunds to be in a separate BAO / api to facilitate this.

@JoeMurray
Copy link
Contributor

Eileen wrote:

3. we want emails to go out and we are adding a payment but it DOES complete the contribution - in this case what combination of payment receipt, contribution completed receipt, event receipt do we send out?
In the latter case do we send out the online invoice receipt as we would when calling Contribution.completeorder or some other one or do they get 2 receipts.

Reviewing the message templates, I don't see one that is specific to just a payment being received (not that we shouldn't have one, it's just that we don't at present):
2019-02-06_12-33-49

So my sense at this point is that we should have a receipt go out for any payment received, and I bet it will be the same template whether the payment is partial or complete or overpaid. For events and memberships, I think those should go out only when the object is completely paid for. So at most two emails currently unless there is a hack to produce price sets that include events and memberships, in which case it's conceivable there could be three eventually.

NB: I haven't reviewed code for this; these are my thoughts on business process objectives given my understanding of how things are.

@JoeMurray
Copy link
Contributor

Eileen wrote:

At the moment 'payment_type' and 'participant_id' are being added to what is passed into payment.create but these seem like things that could be calculated from Payment create.

+1

eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Feb 11, 2019
This adds a new api Payment.sendconfirmation intended to be an equivalent of
Contribution.sendconfirmation.

The key thing this needs to be able to do is to load up all
related information to assign to the template - this is not all covered in this
PR & until it is functionally equivalent to AdditionalPayment::sendEmail
we can't switch over but since it's new functionality we should be able to
merge & keep working on it.

Note that there is discussion on the PR this relates to (civicrm#13330) about what should
happen if 'Payment.create' api accepts 'is_email_receipt'. I think the most logical
outcome is that receipts would go out if it caused the contribution to be completed
(ie. we pass is_email_receipt into completetransaction api).

However, I don't feel like that is 'settled' yet - separating into a second api
(Payment.sendnotification) means we will have 2 generic function which can be called
from multiple places in the code rather than 2 functions tightly tied to the form layer.
I think it's OK if it is 2 not one
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Feb 11, 2019
This adds a new api Payment.sendconfirmation intended to be an equivalent of
Contribution.sendconfirmation.

The key thing this needs to be able to do is to load up all
related information to assign to the template - this is not all covered in this
PR & until it is functionally equivalent to AdditionalPayment::sendEmail
we can't switch over but since it's new functionality we should be able to
merge & keep working on it.

Note that there is discussion on the PR this relates to (civicrm#13330) about what should
happen if 'Payment.create' api accepts 'is_email_receipt'. I think the most logical
outcome is that receipts would go out if it caused the contribution to be completed
(ie. we pass is_email_receipt into completetransaction api).

However, I don't feel like that is 'settled' yet - separating into a second api
(Payment.sendnotification) means we will have 2 generic function which can be called
from multiple places in the code rather than 2 functions tightly tied to the form layer.
I think it's OK if it is 2 not one
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Feb 11, 2019
This adds a new api Payment.sendconfirmation intended to be an equivalent of
Contribution.sendconfirmation.

The key thing this needs to be able to do is to load up all
related information to assign to the template - this is not all covered in this
PR & until it is functionally equivalent to AdditionalPayment::sendEmail
we can't switch over but since it's new functionality we should be able to
merge & keep working on it.

Note that there is discussion on the PR this relates to (civicrm#13330) about what should
happen if 'Payment.create' api accepts 'is_email_receipt'. I think the most logical
outcome is that receipts would go out if it caused the contribution to be completed
(ie. we pass is_email_receipt into completetransaction api).

However, I don't feel like that is 'settled' yet - separating into a second api
(Payment.sendnotification) means we will have 2 generic function which can be called
from multiple places in the code rather than 2 functions tightly tied to the form layer.
I think it's OK if it is 2 not one
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Feb 13, 2019
This adds a new api Payment.sendconfirmation intended to be an equivalent of
Contribution.sendconfirmation.

The key thing this needs to be able to do is to load up all
related information to assign to the template - this is not all covered in this
PR & until it is functionally equivalent to AdditionalPayment::sendEmail
we can't switch over but since it's new functionality we should be able to
merge & keep working on it.

Note that there is discussion on the PR this relates to (civicrm#13330) about what should
happen if 'Payment.create' api accepts 'is_email_receipt'. I think the most logical
outcome is that receipts would go out if it caused the contribution to be completed
(ie. we pass is_email_receipt into completetransaction api).

However, I don't feel like that is 'settled' yet - separating into a second api
(Payment.sendnotification) means we will have 2 generic function which can be called
from multiple places in the code rather than 2 functions tightly tied to the form layer.
I think it's OK if it is 2 not one
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Feb 13, 2019
This adds a new api Payment.sendconfirmation intended to be an equivalent of
Contribution.sendconfirmation.

The key thing this needs to be able to do is to load up all
related information to assign to the template - this is not all covered in this
PR & until it is functionally equivalent to AdditionalPayment::sendEmail
we can't switch over but since it's new functionality we should be able to
merge & keep working on it.

Note that there is discussion on the PR this relates to (civicrm#13330) about what should
happen if 'Payment.create' api accepts 'is_email_receipt'. I think the most logical
outcome is that receipts would go out if it caused the contribution to be completed
(ie. we pass is_email_receipt into completetransaction api).

However, I don't feel like that is 'settled' yet - separating into a second api
(Payment.sendnotification) means we will have 2 generic function which can be called
from multiple places in the code rather than 2 functions tightly tied to the form layer.
I think it's OK if it is 2 not one
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Feb 13, 2019
This adds a new api Payment.sendconfirmation intended to be an equivalent of
Contribution.sendconfirmation.

The key thing this needs to be able to do is to load up all
related information to assign to the template - this is not all covered in this
PR & until it is functionally equivalent to AdditionalPayment::sendEmail
we can't switch over but since it's new functionality we should be able to
merge & keep working on it.

Note that there is discussion on the PR this relates to (civicrm#13330) about what should
happen if 'Payment.create' api accepts 'is_email_receipt'. I think the most logical
outcome is that receipts would go out if it caused the contribution to be completed
(ie. we pass is_email_receipt into completetransaction api).

However, I don't feel like that is 'settled' yet - separating into a second api
(Payment.sendnotification) means we will have 2 generic function which can be called
from multiple places in the code rather than 2 functions tightly tied to the form layer.
I think it's OK if it is 2 not one
@monishdeb
Copy link
Member

@eileenmcnaughton @jitendrapurohit I have rebased this PR. Can you please indicate what is the outstanding issue remaining in this patch?

@eileenmcnaughton
Copy link
Contributor

@monishdeb I think we should pull all the email receipt changes out of it - with that last email receipt change I made I think we can simply call the api from the form & then remove all the entire email function - which will simplify this PR a lot

@monishdeb
Copy link
Member

Hmm seems like I need to flesh out those code in a separate PR which only contains the Payment.create call on forms w/o email receipt changes. And after that PR is merged, we can rebase this PR

@eileenmcnaughton
Copy link
Contributor

@monishdeb I'm happy to throw up a PR doing the send change - if you merge the pre-requisite PR first

@eileenmcnaughton
Copy link
Contributor

(that might make what I mean clearer too :-)

@monishdeb
Copy link
Member

Will do 👍

@eileenmcnaughton
Copy link
Contributor

just adding the link for 'the prerequisit one' #13610

@monishdeb
Copy link
Member

@eileenmcnaughton submitted a sub-PR #13647

@monishdeb monishdeb changed the title Modify backend Record Payment forms to use payment create API. [WIP] Modify backend Record Payment forms to use payment create API. Feb 20, 2019
@eileenmcnaughton
Copy link
Contributor

Closing this as it has been superceded by later work - currently stalled pending review on #14673

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

Successfully merging this pull request may close these issues.

6 participants