$this->set('amount_level', CRM_Utils_Array::value('amount_level', $params));
}
- $priceSetId = $params['priceSetId'] ?? NULL;
+ $priceSetID = $this->getPriceSetID();
if (!empty($this->_ccid)) {
$this->set('lineItem', [$this->getPriceSetID() => $this->getExistingContributionLineItems()]);
}
- elseif ($priceSetId) {
+ elseif ($priceSetID) {
$lineItem = [];
if ($this->isQuickConfig()) {
foreach ($this->_values['fee'] as $key => & $val) {
}
if ($this->_membershipBlock) {
- $this->processAmountAndGetAutoRenew($this->_values['fee'], $params, $lineItem[$priceSetId], $priceSetId);
+ $this->processAmountAndGetAutoRenew($this->_values['fee'], $params, $lineItem[$priceSetID]);
}
else {
- CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem[$priceSetId], $priceSetId);
+ CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem[$priceSetID], $priceSetID);
}
if ($proceFieldAmount) {
- $lineItem[$params['priceSetId']][$fieldOption]['unit_price'] = $proceFieldAmount;
- $lineItem[$params['priceSetId']][$fieldOption]['line_total'] = $proceFieldAmount;
- if (isset($lineItem[$params['priceSetId']][$fieldOption]['tax_amount'])) {
- $proceFieldAmount += $lineItem[$params['priceSetId']][$fieldOption]['tax_amount'];
+ $lineItem[$priceSetID][$fieldOption]['unit_price'] = $proceFieldAmount;
+ $lineItem[$priceSetID][$fieldOption]['line_total'] = $proceFieldAmount;
+ if (isset($lineItem[$priceSetID][$fieldOption]['tax_amount'])) {
+ $proceFieldAmount += $lineItem[$priceSetID][$fieldOption]['tax_amount'];
}
if (!$this->_membershipBlock['is_separate_payment']) {
//require when separate membership not used
* Params reflecting form input e.g with fields 'price_5' => 7, 'price_8' => array(7, 8)
* @param $lineItems
* Line item array to be altered.
- * @param int $priceSetID
*/
- public function processAmountAndGetAutoRenew($fields, &$params, &$lineItems, $priceSetID = NULL) {
- CRM_Price_BAO_PriceSet::processAmount($fields, $params, $lineItems, $priceSetID);
+ public function processAmountAndGetAutoRenew($fields, &$params, &$lineItems) {
+ CRM_Price_BAO_PriceSet::processAmount($fields, $params, $lineItems, $this->getPriceSetID());
$autoRenew = [];
$autoRenew[0] = $autoRenew[1] = $autoRenew[2] = 0;
foreach ($lineItems as $lineItem) {
return $this->_pcpId ? (int) $this->_pcpId : NULL;
}
+ /**
+ * Get the selected Contribution ID.
+ *
+ * @api This function will not change in a minor release and is supported for
+ * use outside of core. This annotation / external support for properties
+ * is only given where there is specific test cover.
+ *
+ * @noinspection PhpUnhandledExceptionInspection
+ */
+ public function getContributionID(): ?int {
+ if ($this->getExistingContributionID()) {
+ return $this->getExistingContributionID();
+ }
+ if (property_exists($this, '_contributionID')) {
+ // Available on Confirm form (which is tested), so this avoids
+ // accessing that directly & will work for ThankYou in time.
+ return $this->_contributionID;
+ }
+ return NULL;
+ }
+
}
*/
use Civi\Api4\PriceSetEntity;
+use Civi\Test\FormTrait;
/**
* Test APIv3 civicrm_contribute_* functions
class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase {
use CRMTraits_Financial_PriceSetTrait;
+ use FormTrait;
/**
* Clean up DB.
*/
public function testSeparatePaymentConfirm(): void {
$paymentProcessorID = $this->paymentProcessorCreate(['payment_processor_type_id' => 'Dummy', 'is_test' => FALSE]);
- $contributionPageID = $this->createContributionPage(['payment_processor' => $paymentProcessorID]);
+ $contributionPageID = $this->createContributionPage(['payment_processor' => $paymentProcessorID], FALSE);
$this->setUpMembershipBlockPriceSet(['minimum_fee' => 100]);
- $this->callAPISuccess('membership_block', 'create', [
+ $this->createTestEntity('PriceSetEntity', [
+ 'entity_table' => 'civicrm_contribution_page',
+ 'entity_id' => $contributionPageID,
+ 'price_set_id' => $this->ids['PriceSet']['membership_block'],
+ ]);
+ $this->callAPISuccess('MembershipBlock', 'create', [
'entity_id' => $contributionPageID,
'entity_table' => 'civicrm_contribution_page',
'is_required' => TRUE,
'is_separate_payment' => TRUE,
'membership_type_default' => $this->ids['MembershipType'],
]);
- /** @var CRM_Contribute_Form_Contribution_Confirm $form */
- $_REQUEST['id'] = $contributionPageID;
- $form = $this->getFormObject('CRM_Contribute_Form_Contribution_Confirm', [
+
+ $submittedValues = [
'credit_card_number' => 4111111111111111,
'cvv2' => 234,
'credit_card_exp_date' => [
'M' => 2,
'Y' => (int) (CRM_Utils_Time::date('Y')) + 1,
],
- $this->getPriceFieldLabelForContributionPage($contributionPageID) => 100,
- 'priceSetId' => $this->ids['PriceSet']['contribution_page' . $contributionPageID],
+ 'price_' . $this->ids['PriceField']['membership'] => $this->ids['PriceFieldValue']['membership_general'],
+ 'other_amount' => 100,
+ 'priceSetId' => $this->ids['PriceSet']['membership_block'],
'credit_card_type' => 'Visa',
'email-5' => 'test@test.com',
'payment_processor_id' => $paymentProcessorID,
'year' => 2021,
'month' => 2,
- ]);
- // @todo - the way amount is handled is crazy so we have to set here
- // but it should be calculated from submit variables.
- $form->set('amount', 100);
- $form->preProcess();
- $form->buildQuickForm();
- $form->postProcess();
- $financialTrxnId = $this->callAPISuccess('EntityFinancialTrxn', 'get', ['entity_id' => $form->_contributionID, 'entity_table' => 'civicrm_contribution', 'sequential' => 1])['values'][0]['financial_trxn_id'];
+ ];
+ $form = $this->submitOnlineContributionForm($submittedValues, $contributionPageID);
+ $financialTrxnId = $this->callAPISuccess('EntityFinancialTrxn', 'get', ['entity_id' => $form->getContributionID(), 'entity_table' => 'civicrm_contribution', 'sequential' => 1])['values'][0]['financial_trxn_id'];
$financialTrxn = $this->callAPISuccess('FinancialTrxn', 'get', [
'id' => $financialTrxnId,
])['values'][$financialTrxnId];
$this->assertEquals('1111', $financialTrxn['pan_truncation']);
$this->assertEquals(1, $financialTrxn['card_type_id']);
- $assignedVariables = $form->get_template_vars();
+ $assignedVariables = $form->getTemplateVariables();
$this->assertTrue($assignedVariables['is_separate_payment']);
}
* Create a basic contribution page.
*
* @param array $params
+ * @param bool $isDefaultContributionPriceSet
*
* @return int
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/
- protected function createContributionPage(array $params): int {
+ protected function createContributionPage(array $params, $isDefaultContributionPriceSet = TRUE): int {
$contributionPageID = (int) $this->callAPISuccess('ContributionPage', 'create', array_merge([
'title' => 'Test Contribution Page',
'financial_type_id' => 'Campaign Contribution',
'min_amount' => 20,
'max_amount' => 2000,
], $params))['id'];
- PriceSetEntity::create(FALSE)->setValues([
- 'entity_table' => 'civicrm_contribution_page',
- 'entity_id' => $contributionPageID,
- 'price_set_id:name' => 'default_contribution_amount',
- ])->execute();
+ if ($isDefaultContributionPriceSet) {
+ PriceSetEntity::create(FALSE)->setValues([
+ 'entity_table' => 'civicrm_contribution_page',
+ 'entity_id' => $contributionPageID,
+ 'price_set_id:name' => 'default_contribution_amount',
+ ])->execute();
+ }
return $contributionPageID;
}
+ /**
+ * @param array $submittedValues
+ * @param int $contributionPageID
+ *
+ * @return \Civi\Test\FormWrapper|\Civi\Test\FormWrappers\EventFormOnline|\Civi\Test\FormWrappers\EventFormParticipant|null
+ */
+ protected function submitOnlineContributionForm(array $submittedValues, int $contributionPageID) {
+ $form = $this->getTestForm('CRM_Contribute_Form_Contribution_Main', $submittedValues, ['id' => $contributionPageID])
+ ->addSubsequentForm('CRM_Contribute_Form_Contribution_Confirm');
+ $form->processForm();
+ return $form;
+ }
+
}