diff --git a/CRM/Financial/BAO/Payment.php b/CRM/Financial/BAO/Payment.php index c697606dd75f..84f77b7a03e8 100644 --- a/CRM/Financial/BAO/Payment.php +++ b/CRM/Financial/BAO/Payment.php @@ -216,6 +216,7 @@ public static function getConfirmationTemplateParameters($entities) { '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,10 @@ public static function getConfirmationTemplateParameters($entities) { '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), + 'paymentsComplete' => ($entities['payment']['balance'] == 0), ]; return self::filterUntestedTemplateVariables($templateVariables); @@ -253,22 +258,23 @@ public static function filterUntestedTemplateVariables($params) { 'paidBy', 'isShowLocation', 'location', - ]; - // Need to do these before switching the form over... - $todoParams = [ 'isRefund', - 'totalPaid', + 'isAmountzero', 'refundAmount', + 'totalPaid', 'paymentsComplete', + ]; + // These are assigned by the payment form - they still 'get through' from the + // form for now without being in here but we should ideally load + // and assign. Note we should update the tpl to use {if $billingName} + // and ditch contributeMode - although it might need to be deprecated rather than removed. + $todoParams = [ 'contributeMode', - 'isAmountzero', 'billingName', 'address', 'credit_card_type', 'credit_card_number', 'credit_card_exp_date', - 'eventEmail', - '$event.participant_role', ]; $filteredParams = []; foreach ($testedTemplateVariables as $templateVariable) { diff --git a/tests/phpunit/api/v3/PaymentTest.php b/tests/phpunit/api/v3/PaymentTest.php index 59e83b08d55e..737d27010ead 100644 --- a/tests/phpunit/api/v3/PaymentTest.php +++ b/tests/phpunit/api/v3/PaymentTest.php @@ -112,12 +112,12 @@ public function testPaymentEmailReceipt() { 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'] => [ @@ -144,6 +144,85 @@ public function testPaymentEmailReceipt() { 'streety street', )); $mut->stop(); + $mut->clearMessages(); + } + + /** + * Test email receipt for partial payment. + */ + public function testPaymentEmailReceiptFullyPaid() { + $mut = new CiviMailUtils($this); + list($lineItems, $contribution) = $this->createParticipantWithContribution(); + + $params = [ + 'contribution_id' => $contribution['id'], + 'total_amount' => 150, + ]; + $payment = $this->callAPISuccess('payment', 'create', $params); + + $this->callAPISuccess('Payment', 'sendconfirmation', ['id' => $payment['id']]); + $mut->assertSubjects(['Payment Receipt - Annual CiviCRM meet']); + $mut->checkMailLog(array( + 'Dear Mr. Anthony Anderson II', + 'A payment has been received.', + 'Total Fees: $ 300.00', + 'This Payment Amount: $ 150.00', + 'Balance Owed: $ 0.00', + 'Thank you for completing payment.', + )); + $mut->stop(); + $mut->clearMessages(); + } + + /** + * Test email receipt for partial payment. + * + * @dataProvider getThousandSeparators + * + * @param string $thousandSeparator + */ + public function testRefundEmailReceipt($thousandSeparator) { + $this->setCurrencySeparators($thousandSeparator); + $decimalSeparator = ($thousandSeparator === ',' ? '.' : ','); + $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', + 'A refund has been issued based on changes in your registration selections.', + 'Total Fees: $ 300' . $decimalSeparator . '00', + 'Refund Amount: $ -30' . $decimalSeparator . '00', + 'Event Information and Location', + 'Paid By: Check', + 'Transaction Date: November 13th, 2018 12:01 PM', + 'You Paid: $ 170' . $decimalSeparator . '00', + )); + $mut->stop(); + $mut->clearMessages(); } /**