dev/core#1333 Fix incorrect balance amount on fully paid payment
authoreileen <emcnaughton@wikimedia.org>
Mon, 21 Oct 2019 00:46:55 +0000 (13:46 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 21 Oct 2019 00:46:55 +0000 (13:46 +1300)
Per https://lab.civicrm.org/dev/core/issues/1333 this is resulting in an incorrect balance.

The code was previously marked as highly dubious

CRM/Contribute/BAO/Contribution.php
CRM/Financial/BAO/Payment.php
tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php

index 58efcf8f3af3e954e8264b5ba74754f7a03d8b0d..dbd9f22a93e1bdf8dbdb08d8fff5235e891f0ce5 100644 (file)
@@ -4053,13 +4053,6 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
     $financialTypeId = $contribution['financial_type_id'];
     $feeFinancialAccount = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($financialTypeId, 'Expense Account is');
 
-    if ($paymentBalance == 0 && $info['payLater']) {
-      // @todo - review - this looks very unlikely to be correct.
-      // the balance should be correct based on payment transactions not
-      // assumptions.
-      $paymentBalance = $total;
-    }
-
     $info['total'] = $total;
     $info['paid'] = $total - $paymentBalance;
     $info['balance'] = $paymentBalance;
index e89266fa3b2632787a67f2ea5ba2040438611438..30cde95f511ad2461c29693d48b9f2f9ce0ffc49 100644 (file)
@@ -239,6 +239,7 @@ class CRM_Financial_BAO_Payment {
    *   - event = [.... full event details......]
    *   - contribution = ['id' => x],
    *   - payment = [payment info + payment summary info]
+   * @throws \CiviCRM_API3_Exception
    */
   protected static function loadRelatedEntities($id) {
     $entities = [];
index 0f294a7b868344862bcb5dfc60ded4ca42925164..93b322a9a1db302d7168e2e10e3e1db9c2360deb 100644 (file)
@@ -197,6 +197,8 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
 
   /**
    * Test the submit function that completes the partially paid Contribution with multiple payments.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testMultiplePaymentForPartiallyPaidContributionWithOneCreditCardPayment() {
     $mut = new CiviMailUtils($this, TRUE);
@@ -238,13 +240,31 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
 
   /**
    * Test the submit function that completes the pending pay later Contribution using Credit Card.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testAddPaymentUsingCreditCardForPendingPayLaterContribution() {
+    $mut = new CiviMailUtils($this, TRUE);
     $this->createContribution('Pending');
 
     // pay additional amount by using Credit Card
-    $this->submitPayment(100, 'live');
+    $this->submitPayment(100, 'live', TRUE);
     $this->checkResults([100], 1);
+
+    $mut->checkMailLog([
+      'A payment has been received',
+      'Total Fees: $ 100.00',
+      'This Payment Amount: $ 100.00',
+      'Balance Owed: $ 0.00 ',
+      'Paid By: Credit Card',
+      '***********1111',
+      'Billing Name and Address',
+      'Vancouver, AE 1321312',
+      'Expires: May 2025',
+
+    ]);
+    $mut->stop();
+    $mut->clearMessages();
   }
 
   /**