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

dev/core#2017 Move function only used by bin/ContributionProcessor to that class #18458

Merged
merged 1 commit into from
Sep 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
72 changes: 0 additions & 72 deletions CRM/Contribute/BAO/Contribution/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,78 +345,6 @@ public static function createCMSUser(&$params, $contactID, $mail) {
}
}

/**
* @param array $params
* @param string $type
*
* @return bool
*/
public static function _fillCommonParams(&$params, $type = 'paypal') {
if (array_key_exists('transaction', $params)) {
$transaction = &$params['transaction'];
}
else {
$transaction = &$params;
}

$params['contact_type'] = 'Individual';

$billingLocTypeId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', 'Billing', 'id', 'name');
if (!$billingLocTypeId) {
$billingLocTypeId = 1;
}
if (!CRM_Utils_System::isNull($params['address'])) {
$params['address'][1]['is_primary'] = 1;
$params['address'][1]['location_type_id'] = $billingLocTypeId;
}
if (!CRM_Utils_System::isNull($params['email'])) {
$params['email'] = [
1 => [
'email' => $params['email'],
'location_type_id' => $billingLocTypeId,
],
];
}

if (isset($transaction['trxn_id'])) {
// set error message if transaction has already been processed.
$contribution = new CRM_Contribute_DAO_Contribution();
$contribution->trxn_id = $transaction['trxn_id'];
if ($contribution->find(TRUE)) {
$params['error'][] = ts('transaction already processed.');
}
}
else {
// generate a new transaction id, if not already exist
$transaction['trxn_id'] = md5(uniqid(rand(), TRUE));
}

if (!isset($transaction['financial_type_id'])) {
$contributionTypes = array_keys(CRM_Contribute_PseudoConstant::financialType());
$transaction['financial_type_id'] = $contributionTypes[0];
}

if (($type == 'paypal') && (!isset($transaction['net_amount']))) {
$transaction['net_amount'] = $transaction['total_amount'] - CRM_Utils_Array::value('fee_amount', $transaction, 0);
}

if (!isset($transaction['invoice_id'])) {
$transaction['invoice_id'] = $transaction['trxn_id'];
}

$source = ts('ContributionProcessor: %1 API',
[1 => ucfirst($type)]
);
if (isset($transaction['source'])) {
$transaction['source'] = $source . ':: ' . $transaction['source'];
}
else {
$transaction['source'] = $source;
}

return TRUE;
}

/**
* @param int $contactID
*
Expand Down
76 changes: 74 additions & 2 deletions bin/ContributionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public static function formatAPIParams($apiParams, $mapper, $type = 'paypal', $c
$params += $transaction;
}

CRM_Contribute_BAO_Contribution_Utils::_fillCommonParams($params, $type);
self::_fillCommonParams($params, $type);

return $params;
}
Expand Down Expand Up @@ -383,7 +383,7 @@ public static function formatAPIParams($apiParams, $mapper, $type = 'paypal', $c
$params += $transaction;
}

CRM_Contribute_BAO_Contribution_Utils::_fillCommonParams($params, $type);
self::_fillCommonParams($params, $type);

return $params;
}
Expand Down Expand Up @@ -457,6 +457,78 @@ public static function processAPIContribution($params) {
return TRUE;
}

/**
* @param array $params
* @param string $type
*
* @return bool
*/
public static function _fillCommonParams(&$params, $type = 'paypal') {
if (array_key_exists('transaction', $params)) {
$transaction = &$params['transaction'];
}
else {
$transaction = &$params;
}

$params['contact_type'] = 'Individual';

$billingLocTypeId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', 'Billing', 'id', 'name');
if (!$billingLocTypeId) {
$billingLocTypeId = 1;
}
if (!CRM_Utils_System::isNull($params['address'])) {
$params['address'][1]['is_primary'] = 1;
$params['address'][1]['location_type_id'] = $billingLocTypeId;
}
if (!CRM_Utils_System::isNull($params['email'])) {
$params['email'] = [
1 => [
'email' => $params['email'],
'location_type_id' => $billingLocTypeId,
],
];
}

if (isset($transaction['trxn_id'])) {
// set error message if transaction has already been processed.
$contribution = new CRM_Contribute_DAO_Contribution();
$contribution->trxn_id = $transaction['trxn_id'];
if ($contribution->find(TRUE)) {
$params['error'][] = ts('transaction already processed.');
}
}
else {
// generate a new transaction id, if not already exist
$transaction['trxn_id'] = md5(uniqid(rand(), TRUE));
}

if (!isset($transaction['financial_type_id'])) {
$contributionTypes = array_keys(CRM_Contribute_PseudoConstant::financialType());
$transaction['financial_type_id'] = $contributionTypes[0];
}

if (($type == 'paypal') && (!isset($transaction['net_amount']))) {
$transaction['net_amount'] = $transaction['total_amount'] - CRM_Utils_Array::value('fee_amount', $transaction, 0);
}

if (!isset($transaction['invoice_id'])) {
$transaction['invoice_id'] = $transaction['trxn_id'];
}

$source = ts('ContributionProcessor: %1 API',
[1 => ucfirst($type)]
);
if (isset($transaction['source'])) {
$transaction['source'] = $source . ':: ' . $transaction['source'];
}
else {
$transaction['source'] = $source;
}

return TRUE;
}

}

// bootstrap the environment and run the processor
Expand Down