-
-
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
Modify backend Record Payment forms to use payment create API #13647
Conversation
(Standard links)
|
api/v3/Payment.php
Outdated
'type' => CRM_Utils_Type::T_STRING, | ||
'description' => ts("Type of payment - 'owed' or 'refund'."), | ||
), | ||
'is_email_receipt' => array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@monishdeb so the thing I've been saying is I think instead of adding these 2 parameters we should add a call above to Payment.sendconfirmation
- the reason being I'm not convinced that is_email_receipt should sent the payment notification - I think it should likely be a bool for whether completetransaction type emails go out - but we can punt that decision by using the payment.sendconfirmation for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops I missed it, removing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@monishdeb once you merge this #13610 we can switch over to Payment.sendconfirmation
@@ -609,10 +591,12 @@ public function testSubmit($params, $creditCardMode = NULL, $entityType = 'contr | |||
if (!empty($paymentInfo['refund_due'])) { | |||
$this->_refund = $paymentInfo['refund_due']; | |||
$this->_paymentType = 'refund'; | |||
$this->paymentAmount = $paymentInfo['refund_due']; |
There was a problem hiding this comment.
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 need this once we start calling sendconfirmation per below
$payment = civicrm_api3('Payment', 'create', array_merge([ | ||
'contribution_id' => $this->_contributionId, | ||
'total_amount' => $this->_params['total_amount'], | ||
'payment_type' => $this->_paymentType, |
There was a problem hiding this comment.
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 need to pass this in per below
$this->_paymentType = 'refund'; | ||
} | ||
elseif (!empty($paymentInfo['amount_owed'])) { | ||
$paymentAmt = $this->_owed = $paymentInfo['amount_owed']; | ||
$this->paymentAmount = $this->_owed = $paymentInfo['amount_owed']; |
There was a problem hiding this comment.
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 need this - per below
@@ -110,11 +110,11 @@ public function preProcess() { | |||
$this->_amtTotal = $paymentDetails['total']; | |||
|
|||
if (!empty($paymentInfo['refund_due'])) { | |||
$paymentAmt = $this->_refund = $paymentInfo['refund_due']; |
There was a problem hiding this comment.
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 need this - per below
@@ -130,7 +130,7 @@ public function preProcess() { | |||
$this->assign('contributionMode', $this->_mode); | |||
$this->assign('contactId', $this->_contactID); | |||
$this->assign('paymentType', $this->_paymentType); | |||
$this->assign('paymentAmt', abs($paymentAmt)); | |||
$this->assign('paymentAmt', abs($this->paymentAmount)); |
There was a problem hiding this comment.
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 need this - per below
'total_amount' => $this->_params['total_amount'], | ||
'payment_type' => $this->_paymentType, | ||
'participant_id' => $participantId, | ||
'mode' => $this->_mode, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think payment.create uses mode or participant_id
api/v3/Payment.php
Outdated
@@ -169,6 +169,16 @@ function _civicrm_api3_payment_create_spec(&$params) { | |||
'type' => CRM_Utils_Type::T_INT, | |||
'api.aliases' => array('payment_id'), | |||
), | |||
'payment_type' => array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this param is only for the receipts too - not needed
51df384
to
2f3264b
Compare
@eileenmcnaughton can you please check now? |
@@ -218,17 +218,28 @@ public function testTransactionInfo() { | |||
$submittedValues = array( | |||
'total_amount' => 20, | |||
'payment_instrument_id' => 3, | |||
'payment_type' => 'owed', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's only add contribution_id here as the other payment_type etc aren't needed
|
||
//Record a refund of the remaining amount. | ||
$submittedValues['total_amount'] = 50; | ||
CRM_Contribute_BAO_Contribution::recordAdditionalPayment($contributionID, $submittedValues, 'refund', $result['participant']['id']); | ||
$paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($result['participant']['id'], 'event', TRUE); | ||
$submittedValues['payment_type'] = 'refund'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto here - no payment_type
'payment_type' => 'owed', | ||
'participant_id' => $participant['id'], | ||
'contribution_id' => $contributionID, | ||
'is_email_receipt' => TRUE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok let me remove these 3 except contribution_id
@monishdeb OK - let's see how the test goes - i think merging #13610 is going to help us here though |
6508fd1
to
b8c418f
Compare
@monishdeb do I feel like we were expecting some fails - the first one should be resolved if we can get the payment.sendconfirmation pr/s merged |
test this please |
I think the other PR will have fixed one fail. Once tests are passing my thoughts here is we should do a mini-audit of differences between recordAdditionalPayment & Payment.create - & perhaps a few UI tests (although test cover is pretty good) and we should probably cleanup the form a little & remove unneeded stuff & them not make any more payment related changes until the next rc is cut |
$params = array('id' => $this->_contributionId); | ||
$contribution = CRM_Contribute_BAO_Contribution::retrieve($params, $defaults, $params); | ||
CRM_Contribute_BAO_Contribution::addPayments(array($contribution), $contributionStatusId); | ||
$payment = civicrm_api3('Payment', 'create', array_merge([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we now need to sync this with below (which expects a var called $result) - this would do it
index e168ff4adf..0143de2658 100644
--- a/CRM/Contribute/Form/AdditionalPayment.php
+++ b/CRM/Contribute/Form/AdditionalPayment.php
@@ -362,8 +362,8 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
$statusMsg = ts('The payment record has been processed.');
// send email
- if (!empty($result) && !empty($this->_params['is_email_receipt'])) {
- $sendResult = civicrm_api3('Payment', 'sendconfirmation', ['id' => $result->id])['values'][$result->id];
+ if (!empty($this->_params['is_email_receipt'])) {
+ $sendResult = civicrm_api3('Payment', 'sendconfirmation', ['id' => $payment['id']])['values'][$payment['id]'];
if ($sendResult['is_sent']) {
$statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
}
OK - I added a comment about the top test fail. However, after fixing that it now sends out TWO emails - the payment notification AND a contribution notification - this was what I was talking about before - ie. what should be sent when payment.create api is called. Perhaps the param we want here on Payment.create is 'is_send_confirmation_on_completed_contribution' = > 0
We could perhaps find something shorter but is_email_receipt is ambiguous & abbreviations can be hard to remember. |
@eileenmcnaughton I have encountered multiple issues with the original issue fix:
So I am thinking of extracting the refund code for |
@monishdeb I think that what the form is doing is what we want the api to support - the api is immature :-( I think we can update it to support the other scenarios - the goal here is to get to a point where we have one reliable thing that works & which we can use from various places. I'm just trying to get my head around the functions involved.... |
@monishdeb so RecordAdditionalPayment is only called twice outside of the unit tests - that's good |
@monishdeb what about tackling it this way - #13689 - ie. resolve getting the cancel right via the api before we touch the form |
Hmm - maybe this is what you are suggesting.... |
Our current blocker on this is #13689 - let's close this one down until we've finished merging recordAdditionalPayment with Payment.create since it can't be reviewed until we have finished that (& this part is the easy part :-) |
Overview
Modify backend Record Payment forms to use payment create API and move API code to BAO layer.
Before
Payment create api exists but is not used by backend record payment forms.
After
Payment create API is used to records payments for pending or partially paid contributions.
Comments
This is a sub-PR of #13330
ping @monishdeb @eileenmcnaughton