Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for api money, fix net_amount calc #11801

Merged
merged 1 commit into from
Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static function add(&$params, $ids = array()) {

//if priceset is used, no need to cleanup money
if (!empty($params['skipCleanMoney'])) {
unset($moneyFields[0]);
$moneyFields = [];
}
else {
// @todo put a deprecated here - this should be done in the form layer.
Expand Down
7 changes: 7 additions & 0 deletions api/v3/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ function civicrm_api3_contribution_create(&$params) {
$params = array_merge($params, $values);
// The BAO should not clean money - it should be done in the form layer & api wrapper
// (although arguably the api should expect pre-cleaned it seems to do some cleaning.)
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]);
}
}
}
$params['skipCleanMoney'] = TRUE;

if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
Expand Down
17 changes: 14 additions & 3 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,15 +682,26 @@ public function testCreateContributionSource() {

/**
* Create test with unique field name on source.
*
* @param string $thousandSeparator
* punctuation used to refer to thousands.
*
* @dataProvider getThousandSeparators
*/
public function testCreateDefaultNow() {

public function testCreateDefaultNow($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
$params = $this->_params;
unset($params['receive_date']);
unset($params['receive_date'], $params['net_amount']);

$params['total_amount'] = $this->formatMoneyInput(5000.77);
$params['fee_amount'] = $this->formatMoneyInput(.77);

$contribution = $this->callAPISuccess('contribution', 'create', $params);
$contribution = $this->callAPISuccessGetSingle('contribution', array('id' => $contribution['id']));
$this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receive_date'])));
$this->assertEquals(5000.77, $contribution['total_amount'], 'failed to handle ' . $this->formatMoneyInput(5000.77));
$this->assertEquals(.77, $contribution['fee_amount']);
$this->assertEquals(5000, $contribution['net_amount']);
}

/**
Expand Down