Payment.sendconfirmation - add tpl var for fully paid
authoreileen <emcnaughton@wikimedia.org>
Fri, 15 Feb 2019 20:51:51 +0000 (09:51 +1300)
committereileen <emcnaughton@wikimedia.org>
Tue, 19 Feb 2019 19:54:37 +0000 (08:54 +1300)
CRM/Financial/BAO/Payment.php
tests/phpunit/api/v3/PaymentTest.php

index 6c6aaed7ce57877a2cc7a5d7f7079666202d32f4..cbfccbc4a416df1bd194bddd0d1be53c5391556a 100644 (file)
@@ -228,6 +228,7 @@ class CRM_Financial_BAO_Payment {
       '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);
@@ -261,10 +262,10 @@ class CRM_Financial_BAO_Payment {
       'isAmountzero',
       'refundAmount',
       'totalPaid',
+      'paymentsComplete',
     ];
     // Need to do these before switching the form over...
     $todoParams = [
-      'paymentsComplete',
       'contributeMode',
       'billingName',
       'address',
index 1d43cf618649134d32ab73789f61285df48d2277..737d27010eadd50cdc4e3482eacbff0f9647c392 100644 (file)
@@ -147,6 +147,33 @@ class api_v3_PaymentTest extends CiviUnitTestCase {
     $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.
    *
@@ -186,6 +213,7 @@ class api_v3_PaymentTest extends CiviUnitTestCase {
     $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',