Skip to content

Commit

Permalink
fix for CRM-20750
Browse files Browse the repository at this point in the history
Get changes from civicrm#10920
with additional changes for recurring payment.
  • Loading branch information
Sunil Pawar authored and Sunil Pawar committed Feb 27, 2019
1 parent 7e7f065 commit 14c40df
Show file tree
Hide file tree
Showing 2 changed files with 63 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 @@ -2218,6 +2218,12 @@ protected static function repeatTransaction(&$contribution, &$input, $contributi
// CRM-17718 the campaign id on the contribution recur record should get precedence.
$contributionParams['financial_type_id'] = $recurringContribution['financial_type_id'];
}

// In case of recurring use payment instrument from recur record.
if (!empty($recurringContribution['payment_instrument_id'])) {
$contributionParams['payment_instrument_id'] = $recurringContribution['payment_instrument_id'];
}

}
$templateContribution = CRM_Contribute_BAO_ContributionRecur::getTemplateContribution(
$contributionParams['contribution_recur_id'],
Expand Down
57 changes: 57 additions & 0 deletions tests/phpunit/CRM/Contribute/Form/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ public function testSubmitCreditCardWithRecur() {
'frequency_unit' => 'month',
'installments' => 2,
'receive_date' => $receiveDate,
'receive_date_time' => '11:27PM',
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
'payment_processor_id' => $this->paymentProcessorID,
Expand Down Expand Up @@ -958,6 +959,62 @@ public function testSubmitUpdateChangePaymentInstrument($thousandSeparator) {
$lineItem = $this->callAPISuccessGetSingle('LineItem', array());
}

/**
* Test the submit function if only payment instrument is changed from 'Check' to 'Credit Card'
*/
public function testSubmitUpdateChangePaymentInstrument() {
$form = new CRM_Contribute_Form_Contribution();

$form->testSubmit(array(
'total_amount' => 50,
'financial_type_id' => 1,
'receive_date' => '04/21/2015',
'receive_date_time' => '11:27PM',
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'check_number' => '123AX',
'contribution_status_id' => 1,
'price_set_id' => 0,
),
CRM_Core_Action::ADD);
$contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId));
$form->testSubmit(array(
'total_amount' => 50,
'net_amount' => 50,
'financial_type_id' => 1,
'receive_date' => '04/21/2015',
'receive_date_time' => '11:27PM',
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
'card_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Financial_DAO_FinancialTrxn', 'card_type_id', 'Visa'),
'pan_truncation' => '1011',
'contribution_status_id' => 1,
'price_set_id' => 0,
'id' => $contribution['id'],
),
CRM_Core_Action::UPDATE);
$contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId));
$this->assertEquals(50, (int) $contribution['total_amount']);

$financialTransactions = $this->callAPISuccess('FinancialTrxn', 'get', array('sequential' => TRUE));
$this->assertEquals(3, $financialTransactions['count']);

list($oldTrxn, $reversedTrxn, $latestTrxn) = $financialTransactions['values'];

$this->assertEquals(50, $oldTrxn['total_amount']);
$this->assertEquals('123AX', $oldTrxn['check_number']);
$this->assertEquals(array_search('Check', $this->paymentInstruments), $oldTrxn['payment_instrument_id']);

$this->assertEquals(-50, $reversedTrxn['total_amount']);
$this->assertEquals('123AX', $reversedTrxn['check_number']);
$this->assertEquals(array_search('Check', $this->paymentInstruments), $reversedTrxn['payment_instrument_id']);

$this->assertEquals(50, $latestTrxn['total_amount']);
$this->assertEquals('1011', $latestTrxn['pan_truncation']);
$this->assertEquals(array_search('Credit Card', $this->paymentInstruments), $latestTrxn['payment_instrument_id']);
$lineItem = $this->callAPISuccessGetSingle('LineItem', array());
}

/**
* Get parameters for credit card submit calls.
*
Expand Down

0 comments on commit 14c40df

Please sign in to comment.