From e10ecaf136873c78b68d679c31ebd6b48e9996ba Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sun, 26 Nov 2023 17:40:06 +1300 Subject: [PATCH] Fix tax when selection a contribution with the membership, test --- CRM/Contribute/Form/Contribution/Confirm.php | 3 +++ .../Form/Contribution/ConfirmTest.php | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 864a6ea927..1f06c73a27 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -1431,6 +1431,9 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr // Skip line items in the contribution processing transaction. // We will create them with the membership for proper linking. $membershipParams['skipLineItem'] = 1; + // Since we are not letting Contribution::create set up the line items + // we need to specify the tax. + $membershipParams['tax_amount'] = $this->order->getTotalTaxAmount(); } $paymentResult = $this->processConfirm( diff --git a/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php b/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php index dd4baca3ec..521252c5f2 100644 --- a/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php @@ -219,6 +219,27 @@ class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase { $this->assertEquals(655, $contribution['total_amount']); } + /** + * Test the tax calculation when using a quick config price set with a membership selection & a contribution (radio) selection. + * + * Expected amount is $100 non-tax deductible + $25 with an additional $2.50 tax. + */ + public function testSeparatePaymentWithTax(): void { + $this->enableTaxAndInvoicing(); + $this->addTaxAccountToFinancialType(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Donation')); + $this->contributionPageQuickConfigCreate([], [], FALSE, TRUE, TRUE, TRUE); + $this->submitOnlineContributionForm([ + 'payment_processor_id' => $this->ids['PaymentProcessor']['dummy'], + 'price_' . $this->ids['PriceField']['contribution_amount'] => $this->ids['PriceFieldValue']['contribution_amount_25'], + 'price_' . $this->ids['PriceField']['membership_amount'] => $this->ids['PriceFieldValue']['membership_general'], + 'id' => $this->getContributionPageID(), + ] + $this->getBillingSubmitValues(), $this->getContributionPageID()); + + $contribution = $this->callAPISuccessGetSingle('Contribution', ['contribution_page_id' => $this->getContributionPageID(), 'version' => 4]); + $this->assertEquals(2.5, $contribution['tax_amount']); + $this->assertEquals(127.5, $contribution['total_amount']); + } + /** * Test the confirm form with a separate membership payment configured. */ -- 2.25.1