$capabilities[] = (ucfirst($form->_mode) . 'Mode');
}
$form->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors($capabilities);
- $form->_params['payment_processor_id'] = !empty($params['payment_processor_id']) ? $params['payment_processor_id'] : 0;
- $form->_paymentProcessor = $form->_paymentProcessors[$form->_params['payment_processor_id']];
+ $form->_params['payment_processor_id'] = isset($params['payment_processor_id']) ? $params['payment_processor_id'] : 0;
+ if ($form->_params['payment_processor_id'] !== '') {
+ // It can be blank with a $0 transaction - then no processor needs to be selected
+ $form->_paymentProcessor = $form->_paymentProcessors[$form->_params['payment_processor_id']];
+ }
if (!empty($params['payment_processor_id'])) {
// The concept of contributeMode is deprecated as is the billing_mode concept.
if ($form->_paymentProcessor['billing_mode'] == 1) {
if (!empty($params['payment_processor_id'])) {
$params['is_pay_later'] = 0;
}
- else {
+ elseif ($params['amount'] !== 0) {
$params['is_pay_later'] = civicrm_api3('contribution_page', 'getvalue', array(
'id' => $id,
'return' => 'is_pay_later',
$this->postProcessPremium($premiumParams, $result['contribution']);
}
if (!empty($result['contribution'])) {
- // Not quite sure why it would be empty at this stage but tests show it can be ... at least in tests.
+ // It seems this line is hit when there is a zero dollar transaction & in tests, not sure when else.
$this->completeTransaction($result, $result['contribution']->id);
}
return $result;
civicrm_api3('contribution', 'completetransaction', array(
'id' => $contributionID,
'trxn_id' => CRM_Utils_Array::value('trxn_id', $result),
- 'payment_processor_id' => $this->_paymentProcessor['id'],
+ 'payment_processor_id' => CRM_Utils_Array::value('payment_processor_id', $result, $this->_paymentProcessor['id']),
'is_transactional' => FALSE,
'fee_amount' => CRM_Utils_Array::value('fee_amount', $result),
'receive_date' => CRM_Utils_Array::value('receive_date', $result),
$this->assertEquals(5.00, $contribution['non_deductible_amount']);
}
+ /**
+ * Test form submission with basic price set.
+ */
+ public function testSubmitZeroDollar() {
+ $this->setUpContributionPage();
+ $priceFieldID = reset($this->_ids['price_field']);
+ $submitParams = [
+ 'price_' . $priceFieldID => $this->_ids['price_field_value']['cheapskate'],
+ 'id' => (int) $this->_ids['contribution_page'],
+ 'amount' => 0,
+ 'priceSetId' => $this->_ids['price_set'][0],
+ 'payment_processor_id' => '',
+ ];
+
+ $this->callAPISuccess('contribution_page', 'submit', $submitParams);
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
+
+ $this->assertEquals($this->formatMoneyInput(0), $contribution['non_deductible_amount']);
+ $this->assertEquals($this->formatMoneyInput(0), $contribution['total_amount']);
+ }
+
/**
* Test form submission with billing first & last name where the contact does NOT
* otherwise have one.
)
);
$this->_ids['price_field_value'] = array($priceFieldValue['id']);
+
+ $this->_ids['price_field_value']['cheapskate'] = $this->callAPISuccess('price_field_value', 'create', array(
+ 'price_set_id' => $priceSetID,
+ 'price_field_id' => $priceField['id'],
+ 'label' => 'Stingy Goat',
+ 'financial_type_id' => 'Donation',
+ 'amount' => 0,
+ 'non_deductible_amount' => 0,
+ )
+ )['id'];
}
$this->_ids['contribution_page'] = $contributionPageResult['id'];
}