Change test to use preferred methods, fix revealed money bug
authoreileen <emcnaughton@wikimedia.org>
Sat, 26 Oct 2019 23:56:01 +0000 (12:56 +1300)
committereileen <emcnaughton@wikimedia.org>
Sun, 27 Oct 2019 00:02:47 +0000 (13:02 +1300)
In switching this test over I found that Payment.create does not handle cleaning money - which it should to bring it
into line with Contribution.create api

CRM/Contribute/Form/AdditionalPayment.php
api/v3/Payment.php
tests/phpunit/CRM/Contribute/BAO/ContributionTest.php

index 4b8cf620a9befb180114f1fec548a77b2175b6a4..3bfda8b13a5cba40398cdce1a5b54b6e0bf50680 100644 (file)
@@ -349,6 +349,7 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
       $this->processCreditCard();
     }
 
+    // @todo we should clean $ on the form & pass in skipCleanMoney
     $trxnsData = $this->_params;
     if ($this->_paymentType == 'refund') {
       $trxnsData['total_amount'] = -$trxnsData['total_amount'];
index b9b65084be6bc307d9029775175eccf5d486ac56..84023028667580f8889d065ff9522fe6037cb74f 100644 (file)
@@ -137,6 +137,13 @@ function civicrm_api3_payment_cancel($params) {
  * @throws \CiviCRM_API3_Exception
  */
 function civicrm_api3_payment_create($params) {
+  if (empty($params['skipCleanMoney'])) {
+    foreach (['total_amount', 'net_amount', 'fee_amount'] as $field) {
+      if (isset($params[$field])) {
+        $params[$field] = CRM_Utils_Rule::cleanMoney($params[$field]);
+      }
+    }
+  }
   // Check if it is an update
   if (!empty($params['id'])) {
     $amount = $params['total_amount'];
index a8cde6d236de031a5a136512769e68e733f25c86..4c261d38d80f2873c75b005607f7acc95f42b55a 100644 (file)
@@ -1168,6 +1168,8 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2";
 
   /**
    * Test recording of amount with comma separator.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testCommaSeparatorAmount() {
     $contactId = $this->individualCreate();
@@ -1176,16 +1178,15 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2";
       'contact_id' => $contactId,
       'currency' => 'USD',
       'financial_type_id' => 1,
-      'contribution_status_id' => 8,
+      'contribution_status_id' => 'Pending',
       'payment_instrument_id' => 1,
       'receive_date' => '20080522000000',
       'receipt_date' => '20080522000000',
-      'total_amount' => '20000.00',
-      'partial_payment_total' => '20,000.00',
-      'partial_amount_to_pay' => '8,000.00',
+      'total_amount' => '20,000.00',
+      'api.Payment.create' => ['total_amount' => '8,000.00'],
     ];
 
-    $contribution = $this->callAPISuccess('Contribution', 'create', $params);
+    $contribution = $this->callAPISuccess('Order', 'create', $params);
     $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
     $financialTrxn = $this->callAPISuccessGetSingle(
       'FinancialTrxn',
@@ -1194,7 +1195,7 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2";
         'return' => ['total_amount'],
       ]
     );
-    $this->assertEquals($financialTrxn['total_amount'], 8000, 'Invalid Tax amount.');
+    $this->assertEquals($financialTrxn['total_amount'], 8000, 'Invalid amount.');
   }
 
   /**