Skip to content

Commit

Permalink
Use template contribution for contribution.repeattransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Jan 12, 2022
1 parent b2d2768 commit cc63dda
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CRM/Contribute/BAO/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public static function ensureTemplateContributionExists(int $id) {
*
* @param int $id
* @param array $overrides
* Parameters that should be overriden. Add unit tests if using parameters other than total_amount & financial_type_id.
* Parameters that should be overridden. Add unit tests if using parameters other than total_amount & financial_type_id.
*
* @return array
*
Expand Down
13 changes: 5 additions & 8 deletions api/v3/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,11 @@ function _civicrm_api3_contribution_completetransaction_spec(&$params) {
function civicrm_api3_contribution_repeattransaction($params) {
civicrm_api3_verify_one_mandatory($params, NULL, ['contribution_recur_id', 'original_contribution_id']);
if (empty($params['original_contribution_id'])) {
// CRM-19873 call with test mode.
$params['original_contribution_id'] = civicrm_api3('contribution', 'getvalue', [
'return' => 'id',
'contribution_status_id' => ['IN' => ['Completed']],
'contribution_recur_id' => $params['contribution_recur_id'],
'contribution_test' => CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionRecur', $params['contribution_recur_id'], 'is_test'),
'options' => ['limit' => 1, 'sort' => 'id DESC'],
]);
$templateContribution = CRM_Contribute_BAO_ContributionRecur::getTemplateContribution($params['contribution_recur_id']);
if (empty($templateContribution)) {
throw new CiviCRM_API3_Exception('Contribution.repeattransaction failed to get original_contribution_id for recur with ID: ' . $params['contribution_recur_id']);
}
$params['original_contribution_id'] = $templateContribution['id'];
}
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $params['original_contribution_id'];
Expand Down

0 comments on commit cc63dda

Please sign in to comment.