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

Minor code cleanup to Order API #18217

Merged
merged 1 commit into from
Aug 21, 2020
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
8 changes: 2 additions & 6 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4819,19 +4819,15 @@ public static function checkLineItems(&$params) {
if (empty($item['financial_type_id'])) {
$item['financial_type_id'] = $params['financial_type_id'];
}
$lineItemAmount += $item['line_total'] + CRM_Utils_Array::value('tax_amount', $item, 0.00);
$lineItemAmount += $item['line_total'] + ($item['tax_amount'] ?? 0.00);
}
}

if (!isset($totalAmount)) {
$params['total_amount'] = $lineItemAmount;
}
else {
$currency = CRM_Utils_Array::value('currency', $params, '');

if (empty($currency)) {
$currency = CRM_Core_Config::singleton()->defaultCurrency;
}
$currency = $params['currency'] ?? CRM_Core_Config::singleton()->defaultCurrency;

if (!CRM_Utils_Money::equals($totalAmount, $lineItemAmount, $currency)) {
throw new CRM_Contribute_Exception_CheckLineItemsException();
Expand Down
8 changes: 4 additions & 4 deletions api/v3/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function civicrm_api3_order_create($params) {
$priceSetID = NULL;
CRM_Contribute_BAO_Contribution::checkLineItems($params);
foreach ($params['line_items'] as $lineItems) {
$entityParams = CRM_Utils_Array::value('params', $lineItems, []);
$entityParams = $lineItems['params'] ?? [];
if (!empty($entityParams) && !empty($lineItems['line_item'])) {
$item = reset($lineItems['line_item']);
$entity = str_replace('civicrm_', '', $item['entity_table']);
Expand All @@ -105,7 +105,7 @@ function civicrm_api3_order_create($params) {
}
if (empty($priceSetID)) {
$item = reset($lineItems['line_item']);
$priceSetID = civicrm_api3('PriceField', 'getvalue', [
$priceSetID = (int) civicrm_api3('PriceField', 'getvalue', [
'return' => 'price_set_id',
'id' => $item['price_field_id'],
]);
Expand Down Expand Up @@ -142,10 +142,10 @@ function civicrm_api3_order_create($params) {
elseif ($entity == 'membership') {
$paymentParams['isSkipLineItem'] = TRUE;
}
$payments = civicrm_api3($entity . '_payment', 'create', $paymentParams);
civicrm_api3($entity . '_payment', 'create', $paymentParams);
}
}
return civicrm_api3_create_success(CRM_Utils_Array::value('values', $contribution), $params, 'Order', 'create');
return civicrm_api3_create_success($contribution['values'] ?? [], $params, 'Order', 'create');
}

/**
Expand Down