}
}
+ /**
+ * Get suitable values for submitting the contribution form with a billing block.
+ *
+ * @param string $processorIdentifier
+ *
+ * @return array
+ */
+ protected function getBillingSubmitValues(string $processorIdentifier = 'dummy'): array {
+ // @todo determine the fields from the processor.
+ return [
+ 'billing_first_name' => 'Dave',
+ 'billing_middle_name' => 'Joseph',
+ 'billing_last_name' => 'Wong',
+ 'email' => 'dave@example.com',
+ 'payment_processor_id' => $this->ids['PaymentProcessor'][$processorIdentifier],
+ 'credit_card_number' => '4111111111111111',
+ 'credit_card_type' => 'Visa',
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040],
+ 'cvv2' => 123,
+ ];
+ }
+
}
+--------------------------------------------------------------------+
*/
+use Civi\Api4\Contribution;
use Civi\Api4\LineItem;
use Civi\Api4\PriceSetEntity;
use Civi\Test\ContributionPageTestTrait;
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/
- protected function createContributionPage(array $params, $isDefaultContributionPriceSet = TRUE): int {
+ protected function createContributionPage(array $params, bool $isDefaultContributionPriceSet = TRUE): int {
$contributionPageID = (int) $this->callAPISuccess('ContributionPage', 'create', array_merge([
'title' => 'Test Contribution Page',
'financial_type_id' => 'Campaign Contribution',
'year' => 2021,
'month' => 2,
];
- $form = $this->submitOnlineContributionForm($submittedValues, $contributionPageID);
- return $form;
+ return $this->submitOnlineContributionForm($submittedValues, $contributionPageID);
}
/**
*
* @dataProvider getThousandSeparators
*/
- public function testSubmitContributionPageWithPriceSetQuantity(string $thousandSeparator): void {
+ public function testSubmitContributionComplexPriceSetPayLater(string $thousandSeparator): void {
$this->setCurrencySeparators($thousandSeparator);
$this->enableTaxAndInvoicing();
$this->contributionPageWithPriceSetCreate([], ['is_quick_config' => FALSE]);
$mailUtil->checkMailLog([\Civi::format()->money(337.55), 'Tax Rate', 'Subtotal']);
}
+ /**
+ * Test form submission with multiple option price set.
+ *
+ * @param string $thousandSeparator
+ * punctuation used to refer to thousands.
+ *
+ * @dataProvider getThousandSeparators
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testSubmitContributionPageWithPriceSetTaxEnabled(string $thousandSeparator): void {
+ $this->setCurrencySeparators($thousandSeparator);
+ $this->enableTaxAndInvoicing();
+ $this->contributionPageWithPriceSetCreate([], ['is_quick_config' => FALSE]);
+ // This function sets the Tax Rate at 10% - it currently has no way to pass Tax Rate into it - so let's work with 10%
+ $this->addTaxAccountToFinancialType($this->ids['FinancialType']['second']);
+ $this->submitOnlineContributionForm([
+ 'id' => $this->getContributionPageID(),
+ 'first_name' => 'Billy',
+ 'last_name' => 'Gruff',
+ 'email-5' => 'billy@goat.gruff',
+ 'receive_date' => date('Y-m-d H:i:s'),
+ 'payment_processor_id' => 0,
+ 'priceSetId' => $this->getPriceSetID('ContributionPage'),
+ // qty = 1 * unit_price = $10.00 = 10. No sales tax.
+ 'price_' . $this->ids['PriceField']['radio_field'] => $this->ids['PriceFieldValue']['10_dollars'],
+ // qty = 2 * unit_price = $16.95 = 33.90. Tax = $3.39.
+ 'price_' . $this->ids['PriceField']['text_field_16.95'] => 2,
+ ] + $this->getBillingSubmitValues(),
+ $this->getContributionPageID()
+ );
+
+ $contribution = Contribution::get()->addWhere('contribution_page_id', '=', $this->getContributionPageID())->execute()->first();
+ $this->assertEquals(47.29, $contribution['total_amount']);
+ $lineItems = $this->callAPISuccess('LineItem', 'get', [
+ 'contribution_id' => $contribution['id'],
+ ]);
+ $this->assertEquals(2, $lineItems['count']);
+ $totalLineAmount = 0;
+ foreach ($lineItems['values'] as $lineItem) {
+ $totalLineAmount += $lineItem['line_total'];
+ }
+ $this->assertEquals(43.90, $totalLineAmount);
+ $this->assertMailSentContainingStrings([
+ \Civi::format()->money(3.39),
+ 'Tax Rate',
+ 'Subtotal',
+ ]);
+
+ }
+
}
$this->assertEquals($contribution['id'], $pledgePayment[2]['contribution_id']);
}
- /**
- * Test form submission with multiple option price set.
- *
- * @param string $thousandSeparator
- * punctuation used to refer to thousands.
- *
- * @dataProvider getThousandSeparators
- */
- public function testSubmitContributionPageWithPriceSet(string $thousandSeparator): void {
- $this->setCurrencySeparators($thousandSeparator);
- $this->setUpContributionPage([], ['is_quick_config' => FALSE]);
- $submitParams = [
- 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
- 'id' => $this->getContributionPageID(),
- 'first_name' => 'Billy',
- 'last_name' => 'Gruff',
- 'email' => 'billy@goat.gruff',
- 'is_pay_later' => TRUE,
- ];
- $this->addPriceFields($submitParams);
-
- $this->callAPISuccess('ContributionPage', 'submit', $submitParams);
- $contribution = $this->callAPISuccessGetSingle('contribution', [
- 'contribution_page_id' => $this->getContributionPageID(),
- 'contribution_status_id' => 'Pending',
- ]);
- $this->assertEquals(80, $contribution['total_amount']);
- $lineItems = $this->callAPISuccess('LineItem', 'get', [
- 'contribution_id' => $contribution['id'],
- ]);
- $this->assertEquals(3, $lineItems['count']);
- $totalLineAmount = 0;
- foreach ($lineItems['values'] as $lineItem) {
- $totalLineAmount += $lineItem['line_total'];
- }
- $this->assertEquals(80, $totalLineAmount);
- }
-
/**
* Function to add additional price fields to price set.
*