* The input form values.
* @param array $files
* The uploaded files if any.
- * @param CRM_Core_Form $self
+ * @param \CRM_Contribute_Form_Contribution_Main $self
*
* @return bool|array
* true if no errors, else array of errors
$previousId = $otherAmount = FALSE;
while ($priceField->fetch()) {
- if ($self->_quickConfig && ($priceField->name == 'contribution_amount' || $priceField->name == 'membership_amount')) {
+ if ($self->isQuickConfig() && ($priceField->name == 'contribution_amount' || $priceField->name == 'membership_amount')) {
$previousId = $priceField->id;
if ($priceField->name == 'membership_amount' && !$priceField->is_active) {
$membershipIsActive = FALSE;
return $errors;
}
- if (CRM_Utils_Array::value('payment_processor_id', $fields) == NULL) {
+ if (CRM_Utils_Array::value('payment_processor_id', $fields) === NULL) {
$errors['payment_processor_id'] = ts('Payment Method is a required field.');
}
else {
return civicrm_api3_create_success($result, $params, 'ContributionPage', 'submit');
}
+/**
+ * Validate ContributionPage submission parameters.
+ *
+ * @param array $params
+ * Array per getfields metadata.
+ *
+ * @return array
+ * API result array
+ */
+function civicrm_api3_contribution_page_validate($params) {
+ $form = new CRM_Contribute_Form_Contribution_Main();
+ $form->controller = new CRM_Core_Controller();
+ $form->set('id', $params['id']);
+ $form->preProcess();
+ $errors = CRM_Contribute_Form_Contribution_Main::formRule($params, [], $form);
+ if ($errors === TRUE) {
+ $errors = [];
+ }
+ return civicrm_api3_create_success($errors, $params, 'ContributionPage', 'validate');
+}
/**
* Set default getlist parameters.
*/
public function testSubmit() {
$this->setUpContributionPage();
- $priceFieldID = reset($this->_ids['price_field']);
- $priceFieldValueID = reset($this->_ids['price_field_value']);
- $submitParams = array(
- 'price_' . $priceFieldID => $priceFieldValueID,
- 'id' => (int) $this->_ids['contribution_page'],
- 'amount' => 10,
- );
+ $submitParams = $this->getBasicSubmitParams();
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
$contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
$this->assertEquals($lineItem_TaxAmount, round(180 * 16.95 * 0.10, 2), 'Wrong Sales Tax Amount is calculated and stored.');
}
+
+ /**
+ * Test validating a contribution page submit.
+ */
+ public function testValidate() {
+ $this->setUpContributionPage();
+ $errors = $this->callAPISuccess('ContributionPage', 'validate', array_merge($this->getBasicSubmitParams(), ['action' => 'submit']))['values'];
+ $this->assertEmpty($errors);
+ }
+
+ /**
+ * Implements hook_civicrm_alterPaymentProcessorParams().
+ *
+ * @throws \Exception
+ */
public function hook_civicrm_alterPaymentProcessorParams($paymentObj, &$rawParams, &$cookedParams) {
// Ensure total_amount are the same if they're both given.
$total_amount = CRM_Utils_Array::value('total_amount', $rawParams);
$log->debug($message, $_REQUEST);
}
+ /**
+ * Get the params for a basic simple submit.
+ *
+ * @return array
+ */
+ protected function getBasicSubmitParams() {
+ $priceFieldID = reset($this->_ids['price_field']);
+ $priceFieldValueID = reset($this->_ids['price_field_value']);
+ $submitParams = [
+ 'price_' . $priceFieldID => $priceFieldValueID,
+ 'id' => (int) $this->_ids['contribution_page'],
+ 'amount' => 10,
+ 'priceSetId' => $this->_ids['price_set'][0],
+ 'payment_processor_id' => 0,
+ ];
+ return $submitParams;
+ }
+
}