diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 721662865694..f617765c49dc 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -13,6 +13,7 @@ use Civi\Api4\ContributionPage; use Civi\Api4\ContributionRecur; use Civi\Api4\Participant; +use Civi\Api4\PaymentProcessor; /** * @@ -4409,10 +4410,8 @@ public static function completeOrder($input, $ids, $objects, $isPostPaymentCreat $contributionParams['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']; + $contributionParams['payment_instrument_id'] = PaymentProcessor::get()->addWhere('id', '=', $paymentProcessorId)->addSelect('payment_instrument_id')->execute()->first()['payment_instrument_id']; } if ($recurringContributionID) { diff --git a/tests/phpunit/CRM/Member/BAO/MembershipTest.php b/tests/phpunit/CRM/Member/BAO/MembershipTest.php index 8cebb74c1c40..1da7704d03e0 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipTest.php @@ -757,7 +757,9 @@ public function testMembershipPaymentForSingleContributionMultipleMembership() { 'original_contribution_id' => $contribution['id'], 'contribution_status_id' => 'Completed', ]); - $this->callAPISuccessGetCount('Contribution', [], 2); + $contributions = $this->callAPISuccess('Contribution', 'get', ['sequential' => 1])['values']; + $this->assertCount(2, $contributions); + $this->assertEquals('Debit Card', CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', $contributions[1]['payment_instrument_id'])); // @todo this fails depending on what tests it is run with due some bad stuff in Membership.create // It needs to be addressed but might involve the switch to ORDER. Membership BAO does bad line item stuff. // $this->callAPISuccessGetCount('LineItem', [], 6);