From b5a442ed0ec207d3996bdd6c484da74f5a8815fa Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 16 Feb 2019 09:35:50 +1300 Subject: [PATCH] Add refund relevant fields & tests to payment.sendconfirmation --- CRM/Financial/BAO/Payment.php | 15 ++++++--- tests/phpunit/api/v3/PaymentTest.php | 47 ++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/CRM/Financial/BAO/Payment.php b/CRM/Financial/BAO/Payment.php index c697606dd7..b9b287b7ec 100644 --- a/CRM/Financial/BAO/Payment.php +++ b/CRM/Financial/BAO/Payment.php @@ -216,6 +216,7 @@ class CRM_Financial_BAO_Payment { 'contactDisplayName' => $entities['contact']['display_name'], 'totalAmount' => $entities['payment']['total'], 'amountOwed' => $entities['payment']['balance'], + 'totalPaid' => $entities['payment']['paid'], 'paymentAmount' => $entities['payment']['total_amount'], 'checkNumber' => CRM_Utils_Array::value('check_number', $entities['payment']), 'receive_date' => $entities['payment']['trxn_date'], @@ -224,6 +225,9 @@ class CRM_Financial_BAO_Payment { 'location' => CRM_Utils_Array::value('location', $entities), 'event' => CRM_Utils_Array::value('event', $entities), 'component' => (!empty($entities['event']) ? 'event' : 'contribution'), + 'isRefund' => $entities['payment']['total_amount'] < 0, + 'isAmountzero' => $entities['payment']['total_amount'] === 0, + 'refundAmount' => ($entities['payment']['total_amount'] < 0 ? $entities['payment']['total_amount'] : NULL), ]; return self::filterUntestedTemplateVariables($templateVariables); @@ -253,15 +257,18 @@ class CRM_Financial_BAO_Payment { 'paidBy', 'isShowLocation', 'location', + 'isRefund', + 'isAmountzero', + 'refundAmount', + 'totalPaid', ]; // Need to do these before switching the form over... $todoParams = [ - 'isRefund', - 'totalPaid', - 'refundAmount', + + + 'paymentsComplete', 'contributeMode', - 'isAmountzero', 'billingName', 'address', 'credit_card_type', diff --git a/tests/phpunit/api/v3/PaymentTest.php b/tests/phpunit/api/v3/PaymentTest.php index 59e83b08d5..d28231cae5 100644 --- a/tests/phpunit/api/v3/PaymentTest.php +++ b/tests/phpunit/api/v3/PaymentTest.php @@ -112,12 +112,12 @@ class api_v3_PaymentTest extends CiviUnitTestCase { list($lineItems, $contribution) = $this->createParticipantWithContribution(); $event = $this->callAPISuccess('Event', 'get', []); $this->addLocationToEvent($event['id']); - $params = array( + $params = [ 'contribution_id' => $contribution['id'], 'total_amount' => 50, 'check_number' => '345', 'trxn_date' => '2018-08-13 17:57:56', - ); + ]; $payment = $this->callAPISuccess('payment', 'create', $params); $this->checkPaymentResult($payment, [ $payment['id'] => [ @@ -146,6 +146,49 @@ class api_v3_PaymentTest extends CiviUnitTestCase { $mut->stop(); } + /** + * Test email receipt for partial payment. + */ + public function testRefundEmailReceipt() { + $mut = new CiviMailUtils($this); + list($lineItems, $contribution) = $this->createParticipantWithContribution(); + $this->callAPISuccess('payment', 'create', [ + 'contribution_id' => $contribution['id'], + 'total_amount' => 50, + 'check_number' => '345', + 'trxn_date' => '2018-08-13 17:57:56', + ]); + + $payment = $this->callAPISuccess('payment', 'create', [ + 'contribution_id' => $contribution['id'], + 'total_amount' => -30, + 'trxn_date' => '2018-11-13 12:01:56', + ]); + + $this->checkPaymentResult($payment, [ + $payment['id'] => [ + 'from_financial_account_id' => 7, + 'to_financial_account_id' => 6, + 'total_amount' => -30, + 'status_id' => 1, + 'is_payment' => 1, + ], + ]); + + $this->callAPISuccess('Payment', 'sendconfirmation', ['id' => $payment['id']]); + $mut->assertSubjects(['Refund Notification - Annual CiviCRM meet']); + $mut->checkMailLog(array( + 'Dear Mr. Anthony Anderson II', + 'Total Fees: $ 300.00', + 'Refund Amount: $ -30.00', + 'Event Information and Location', + 'Paid By: Check', + 'Transaction Date: November 13th, 2018 12:01 PM', + 'You Paid: $ 170.00', + )); + $mut->stop(); + } + /** * Test create payment api with no line item in params */ -- 2.25.1