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

Modify backend Record Payment forms to use payment create API #13647

Closed
wants to merge 1 commit into from

Conversation

monishdeb
Copy link
Member

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

@civibot
Copy link

civibot bot commented Feb 20, 2019

(Standard links)

'type' => CRM_Utils_Type::T_STRING,
'description' => ts("Type of payment - 'owed' or 'refund'."),
),
'is_email_receipt' => array(
Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Contributor

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'];
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 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,
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 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'];
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 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'];
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 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));
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 need this - per below

'total_amount' => $this->_params['total_amount'],
'payment_type' => $this->_paymentType,
'participant_id' => $participantId,
'mode' => $this->_mode,
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 payment.create uses mode or participant_id

@@ -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(
Copy link
Contributor

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

@monishdeb monishdeb force-pushed the partial-2 branch 4 times, most recently from 51df384 to 2f3264b Compare February 20, 2019 11:31
@monishdeb
Copy link
Member Author

@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',
Copy link
Contributor

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';
Copy link
Contributor

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,
Copy link
Member Author

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

@eileenmcnaughton
Copy link
Contributor

@monishdeb OK - let's see how the test goes - i think merging #13610 is going to help us here though

@monishdeb monishdeb force-pushed the partial-2 branch 5 times, most recently from 6508fd1 to b8c418f Compare February 21, 2019 03:09
@eileenmcnaughton
Copy link
Contributor

@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

@eileenmcnaughton
Copy link
Contributor

test this please

@eileenmcnaughton
Copy link
Contributor

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([
Copy link
Contributor

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.');
       }

@eileenmcnaughton
Copy link
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

  • that would be passed through to the Contribution.completetransaction api.

We could perhaps find something shorter but is_email_receipt is ambiguous & abbreviations can be hard to remember.

@eileenmcnaughton eileenmcnaughton self-assigned this Feb 24, 2019
@monishdeb
Copy link
Member Author

monishdeb commented Feb 25, 2019

@eileenmcnaughton I have encountered multiple issues with the original issue fix:

  1. The original PR which extends a UT to assert the refund financial trxns on fee-change was not working.
  2. Payment.create API doesn't handle refund payment via backoffice form unlike partial payment for which we got FinancialTrxn::getPartialPaymentTrxn();
  3. Via 'Record refund' backoffice form if we submit the refund amount, it creates extraneous records in FinancialTrxn table.

So I am thinking of extracting the refund code for recordAdditionalPayment() into separate fn say FinancialTrxn::getPartialPaymentTrxn() and handle the refund payment there? And at last it will call completetransaction API to complete the tied contribution?

@eileenmcnaughton
Copy link
Contributor

@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....

@eileenmcnaughton
Copy link
Contributor

@monishdeb so RecordAdditionalPayment is only called twice outside of the unit tests - that's good

@eileenmcnaughton
Copy link
Contributor

@monishdeb what about tackling it this way - #13689 - ie. resolve getting the cancel right via the api before we touch the form

@eileenmcnaughton
Copy link
Contributor

Hmm - maybe this is what you are suggesting....

@eileenmcnaughton
Copy link
Contributor

#13690

@eileenmcnaughton
Copy link
Contributor

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 :-)

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