Skip to content

Commit

Permalink
Change test to use preferred methods, fix revealed money bug
Browse files Browse the repository at this point in the history
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
eileenmcnaughton committed Oct 27, 2019
1 parent cb4793e commit b4c4883
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions CRM/Contribute/Form/AdditionalPayment.php
Original file line number Diff line number Diff line change
@@ -349,6 +349,7 @@ public function submit($submittedValues) {
$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'];
7 changes: 7 additions & 0 deletions api/v3/Payment.php
Original file line number Diff line number Diff line change
@@ -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'];
13 changes: 7 additions & 6 deletions tests/phpunit/CRM/Contribute/BAO/ContributionTest.php
Original file line number Diff line number Diff line change
@@ -1168,6 +1168,8 @@ public function testcalculateFinancialItemAmount() {

/**
* Test recording of amount with comma separator.
*
* @throws \CRM_Core_Exception
*/
public function testCommaSeparatorAmount() {
$contactId = $this->individualCreate();
@@ -1176,16 +1178,15 @@ public function testCommaSeparatorAmount() {
'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 @@ public function testCommaSeparatorAmount() {
'return' => ['total_amount'],
]
);
$this->assertEquals($financialTrxn['total_amount'], 8000, 'Invalid Tax amount.');
$this->assertEquals($financialTrxn['total_amount'], 8000, 'Invalid amount.');
}

/**

0 comments on commit b4c4883

Please sign in to comment.