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

REF Deprecate API3 _ipn_process_transaction() #22488

Merged
merged 1 commit into from
Feb 18, 2022
Merged
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
73 changes: 71 additions & 2 deletions api/v3/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,40 @@ function civicrm_api3_contribution_completetransaction($params) {
throw new API_Exception('failed to load related objects');
}

return _ipn_process_transaction($params, $contribution, $input, $ids);
// @todo Copied from _ipn_process_transaction - needs cleanup/refactor
$objects = $contribution->_relatedObjects;
$objects['contribution'] = &$contribution;
$input['component'] = $contribution->_component;
$input['is_test'] = $contribution->is_test;
$input['amount'] = empty($input['total_amount']) ? $contribution->total_amount : $input['total_amount'];

if (isset($params['is_email_receipt'])) {
$input['is_email_receipt'] = $params['is_email_receipt'];
}
if (!empty($params['trxn_date'])) {
$input['trxn_date'] = $params['trxn_date'];
}
if (!empty($params['receive_date'])) {
$input['receive_date'] = $params['receive_date'];
}
if (empty($contribution->contribution_page_id)) {
static $domainFromName;
static $domainFromEmail;
if (empty($domainFromEmail) && (empty($params['receipt_from_name']) || empty($params['receipt_from_email']))) {
[$domainFromName, $domainFromEmail] = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
}
$input['receipt_from_name'] = CRM_Utils_Array::value('receipt_from_name', $params, $domainFromName);
$input['receipt_from_email'] = CRM_Utils_Array::value('receipt_from_email', $params, $domainFromEmail);
}
$input['card_type_id'] = $params['card_type_id'] ?? NULL;
$input['pan_truncation'] = $params['pan_truncation'] ?? NULL;
if (!empty($params['payment_instrument_id'])) {
$input['payment_instrument_id'] = $params['payment_instrument_id'];
}
return CRM_Contribute_BAO_Contribution::completeOrder($input,
!empty($objects['contributionRecur']) ? $objects['contributionRecur']->id : NULL,
$objects['contribution']->id ?? NULL,
$params['is_post_payment_create'] ?? NULL);
}

/**
Expand Down Expand Up @@ -632,7 +665,40 @@ function civicrm_api3_contribution_repeattransaction($params) {
unset($contribution->id, $contribution->receive_date, $contribution->invoice_id);
$contribution->receive_date = $params['receive_date'];

return _ipn_process_transaction($params, $contribution, $input, $ids);
// @todo Copied from _ipn_process_transaction - needs cleanup/refactor
$objects = $contribution->_relatedObjects;
$objects['contribution'] = &$contribution;
$input['component'] = $contribution->_component;
$input['is_test'] = $contribution->is_test;
$input['amount'] = empty($input['total_amount']) ? $contribution->total_amount : $input['total_amount'];

if (isset($params['is_email_receipt'])) {
$input['is_email_receipt'] = $params['is_email_receipt'];
}
if (!empty($params['trxn_date'])) {
$input['trxn_date'] = $params['trxn_date'];
}
if (!empty($params['receive_date'])) {
$input['receive_date'] = $params['receive_date'];
}
if (empty($contribution->contribution_page_id)) {
static $domainFromName;
static $domainFromEmail;
if (empty($domainFromEmail) && (empty($params['receipt_from_name']) || empty($params['receipt_from_email']))) {
[$domainFromName, $domainFromEmail] = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
}
$input['receipt_from_name'] = CRM_Utils_Array::value('receipt_from_name', $params, $domainFromName);
$input['receipt_from_email'] = CRM_Utils_Array::value('receipt_from_email', $params, $domainFromEmail);
}
$input['card_type_id'] = $params['card_type_id'] ?? NULL;
$input['pan_truncation'] = $params['pan_truncation'] ?? NULL;
if (!empty($params['payment_instrument_id'])) {
$input['payment_instrument_id'] = $params['payment_instrument_id'];
}
return CRM_Contribute_BAO_Contribution::completeOrder($input,
!empty($objects['contributionRecur']) ? $objects['contributionRecur']->id : NULL,
$objects['contribution']->id ?? NULL,
$params['is_post_payment_create'] ?? NULL);
}

/**
Expand All @@ -641,6 +707,8 @@ function civicrm_api3_contribution_repeattransaction($params) {
* The IPN function is overloaded with two purposes - this is simply a wrapper for that
* when separating them in the api layer.
*
* @deprecated
*
* @param array $params
* @param CRM_Contribute_BAO_Contribution $contribution
* @param array $input
Expand All @@ -652,6 +720,7 @@ function civicrm_api3_contribution_repeattransaction($params) {
* @throws \CiviCRM_API3_Exception
*/
function _ipn_process_transaction($params, $contribution, $input, $ids) {
CRM_Core_Error::deprecatedFunctionWarning('API3 contribution.completetransaction or contribution.repeattransaction');
$objects = $contribution->_relatedObjects;
$objects['contribution'] = &$contribution;
$input['component'] = $contribution->_component;
Expand Down