Skip to content

Commit

Permalink
Merge pull request #17975 from eileenmcnaughton/matt_yet_another
Browse files Browse the repository at this point in the history
Fix repeattransaction api to use custom data from the template contribution
  • Loading branch information
colemanw authored Jul 30, 2020
2 parents 1507408 + b2250d1 commit 0ae23b9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -2636,7 +2636,7 @@ protected static function repeatTransaction(&$contribution, &$input, $contributi

$createContribution = civicrm_api3('Contribution', 'create', $contributionParams);
$contribution->id = $createContribution['id'];
CRM_Contribute_BAO_ContributionRecur::copyCustomValues($contributionParams['contribution_recur_id'], $contribution->id);
$contribution->copyCustomFields($templateContribution['id'], $contribution->id);
self::handleMembershipIDOverride($contribution->id, $input);
return TRUE;
}
Expand Down
2 changes: 2 additions & 0 deletions CRM/Contribute/BAO/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@ public static function sendRecurringStartOrEndNotification($ids, $recur, $isFirs
/**
* Copy custom data of the initial contribution into its recurring contributions.
*
* @deprecated
*
* @param int $recurId
* @param int $targetContributionId
*/
Expand Down
45 changes: 44 additions & 1 deletion tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
+--------------------------------------------------------------------+
*/

use Civi\Api4\Contribution;

/**
* Test APIv3 civicrm_contribute_* functions
*
Expand Down Expand Up @@ -107,7 +109,7 @@ public function setUp() {
*/
public function tearDown() {
$this->quickCleanUpFinancialEntities();
$this->quickCleanup(['civicrm_uf_match']);
$this->quickCleanup(['civicrm_uf_match'], TRUE);
$financialAccounts = $this->callAPISuccess('FinancialAccount', 'get', []);
foreach ($financialAccounts['values'] as $financialAccount) {
if ($financialAccount['name'] === 'Test Tax financial account ' || $financialAccount['name'] === 'Test taxable financial Type') {
Expand Down Expand Up @@ -2326,6 +2328,46 @@ public function testRepeatTransaction() {
], 'online');
}

/**
* Test custom data is copied over from the template transaction.
*
* (Over time various discussions have deemed this to be the most recent one, allowing
* users to alter custom data going forwards. This is implemented for line items already.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public function testRepeatTransactionWithCustomData() {
$this->createCustomGroupWithFieldOfType(['extends' => 'Contribution', 'name' => 'Repeat'], 'text');
$originalContribution = $this->setUpRepeatTransaction([], 'single', [$this->getCustomFieldName('text') => 'first']);
$this->callAPISuccess('contribution', 'repeattransaction', [
'contribution_recur_id' => $originalContribution['contribution_recur_id'],
'contribution_status_id' => 'Completed',
'trxn_id' => 'my_trxn',
]);

$contribution = Contribution::get()
->addWhere('trxn_id', '=', 'my_trxn')
->addSelect('Custom_Group.Enter_text_here')
->addSelect('id')
->execute()->first();
$this->assertEquals('first', $contribution['Custom_Group.Enter_text_here']);

Contribution::update()->setValues(['Custom_Group.Enter_text_here' => 'second'])->addWhere('id', '=', $contribution['id'])->execute();

$this->callAPISuccess('contribution', 'repeattransaction', [
'original_contribution_id' => $originalContribution['id'],
'contribution_status_id' => 'Completed',
'trxn_id' => 'number_3',
]);

$contribution = Contribution::get()
->addWhere('trxn_id', '=', 'number_3')
->setSelect(['id', 'Custom_Group.Enter_text_here'])
->execute()->first();
$this->assertEquals('second', $contribution['Custom_Group.Enter_text_here']);
}

/**
* Test repeat contribution successfully creates line items (plural).
*
Expand Down Expand Up @@ -4177,6 +4219,7 @@ protected function setUpRepeatTransaction($recurParams = [], $flag, $contributio
$params = array_merge($params, $contributionParams);
$originalContribution = $this->callAPISuccess('contribution', 'create', $params);
}
$originalContribution['contribution_recur_id'] = $contributionRecur['id'];
$originalContribution['payment_processor_id'] = $paymentProcessorID;
return $originalContribution;
}
Expand Down

0 comments on commit 0ae23b9

Please sign in to comment.