From b4c488312cb40814c8b54c30787fb793dedbf733 Mon Sep 17 00:00:00 2001 From: eileen Date: Sun, 27 Oct 2019 12:56:01 +1300 Subject: [PATCH] Change test to use preferred methods, fix revealed money bug 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 | 1 + api/v3/Payment.php | 7 +++++++ .../phpunit/CRM/Contribute/BAO/ContributionTest.php | 13 +++++++------ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CRM/Contribute/Form/AdditionalPayment.php b/CRM/Contribute/Form/AdditionalPayment.php index 4b8cf620a9..3bfda8b13a 100644 --- a/CRM/Contribute/Form/AdditionalPayment.php +++ b/CRM/Contribute/Form/AdditionalPayment.php @@ -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']; diff --git a/api/v3/Payment.php b/api/v3/Payment.php index b9b65084be..8402302866 100644 --- a/api/v3/Payment.php +++ b/api/v3/Payment.php @@ -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']; diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index a8cde6d236..4c261d38d8 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -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.'); } /** -- 2.25.1