Skip to content

Commit

Permalink
Merge pull request civicrm#9826 from seamuslee001/CRM-20007
Browse files Browse the repository at this point in the history
CRM-20007 Add test to prove that repeatTransaction does not use the P…
  • Loading branch information
eileenmcnaughton authored Feb 13, 2017
2 parents 452fb60 + 22ca4b7 commit 21e44ef
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4467,6 +4467,12 @@ public static function completeOrder(&$input, &$ids, $objects, $transaction, $re
));
$contributionParams['payment_processor'] = $input['payment_processor'] = $paymentProcessorId;

// If paymentProcessor is not set then the payment_instrument_id would not be correct.
// not clear when or if this would occur if you encounter this please fix here & add a unit test.
if (empty($contributionParams['payment_instrument_id']) && isset($contribution->_relatedObjects['paymentProcessor']['payment_instrument_id'])) {
$contributionParams['payment_instrument_id'] = $contribution->_relatedObjects['paymentProcessor']['payment_instrument_id'];
}

if ($recurringContributionID) {
$contributionParams['contribution_recur_id'] = $recurringContributionID;
}
Expand Down
29 changes: 29 additions & 0 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3323,4 +3323,33 @@ protected function setUpForCompleteTransaction() {
return $contribution;
}

/**
* Test repeat contribution uses the Payment Processor' payment_instrument setting.
*/
public function testRepeatTransactionWithNonCreditCardDefault() {
$contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
'contact_id' => $this->_individualId,
'installments' => '12',
'frequency_interval' => '1',
'amount' => '100',
'contribution_status_id' => 1,
'start_date' => '2012-01-01 00:00:00',
'currency' => 'USD',
'frequency_unit' => 'month',
'payment_processor_id' => $this->paymentProcessorID,
));
$contribution1 = $this->callAPISuccess('contribution', 'create', array_merge(
$this->_params,
array('contribution_recur_id' => $contributionRecur['id'], 'payment_instrument_id' => 2))
);
$paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument('name');
$contribution2 = $this->callAPISuccess('contribution', 'repeattransaction', array(
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
'original_contribution_id' => $contribution1,
));
$this->assertEquals(array_search('Debit Card', $paymentInstruments), $contribution2['values'][$contribution2['id']]['payment_instrument_id']);
$this->quickCleanUpFinancialEntities();
}

}

0 comments on commit 21e44ef

Please sign in to comment.