From 8252577e06eead3e4d14878fae802931cbb817bf Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 12 Feb 2017 12:08:39 +1100 Subject: [PATCH 1/3] CRM-20007 Add test to prove that repeatTransaction does not use the Payment Procesors Payment Instrument when creating contributions --- tests/phpunit/api/v3/ContributionTest.php | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 266c1f299ac2..c3dc905a9513 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -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'])) + ); + $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(); + } + } From 12f2ba057b3672141b8429c8e2b154ee885f5f50 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 12 Feb 2017 20:23:16 +1100 Subject: [PATCH 2/3] Set original contribution to be paid by Debit Card as well to prove that its using default payment instrument --- tests/phpunit/api/v3/ContributionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index c3dc905a9513..64e3ac18ce4c 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -3340,7 +3340,7 @@ public function testRepeatTransactionWithNonCreditCardDefault() { )); $contribution1 = $this->callAPISuccess('contribution', 'create', array_merge( $this->_params, - array('contribution_recur_id' => $contributionRecur['id'])) + array('contribution_recur_id' => $contributionRecur['id'], 'payment_instrument_id' => 2)) ); $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument('name'); $contribution2 = $this->callAPISuccess('contribution', 'repeattransaction', array( From 22ca4b75bd1c3db32f1f7b2864dfa482603a3fcb Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Mon, 13 Feb 2017 08:03:59 +1100 Subject: [PATCH 3/3] CRM-20007 Fix issue where contribution not getting correct payment instrument set --- CRM/Contribute/BAO/Contribution.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 09f57773ecf6..361ad3a37885 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -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; }