*
* @param array $params
* Submitted values.
+ *
+ * @throws \CiviCRM_API3_Exception
*/
public function submit($params) {
//carry campaign from profile.
}
$params['separate_amount'] = $params['amount'];
- $memFee = NULL;
- if (!empty($params['selectMembership'])) {
- if (empty($this->_membershipTypeValues)) {
- $this->_membershipTypeValues = CRM_Member_BAO_Membership::buildMembershipTypeValues($this,
- (array) $params['selectMembership']
- );
- }
- $membershipTypeValues = $this->_membershipTypeValues[$params['selectMembership']];
- $memFee = $membershipTypeValues['minimum_fee'];
- if (!$params['amount'] && !$this->_separateMembershipPayment) {
- $params['amount'] = $memFee ? $memFee : 0;
- }
- }
+ // @todo - stepping through the code indicates that amount is always set before this point so it never matters.
+ // Move more of the above into this function...
+ $params['amount'] = $this->getMainContributionAmount($params);
//If the membership & contribution is used in contribution page & not separate payment
$memPresent = $membershipLabel = $fieldOption = $is_quick_config = NULL;
$proceFieldAmount = 0;
$params['description'] = ts('Online Contribution') . ': ' . ((!empty($this->_pcpInfo['title']) ? $this->_pcpInfo['title'] : $title));
$params['button'] = $this->controller->getButtonName();
// required only if is_monetary and valid positive amount
- // @todo it seems impossible for $memFee to be greater than 0 & $params['amount'] not to
- // be & by requiring $memFee down here we make it harder to do a sensible refactoring of the function
- // above (ie. extract the amount in a small function).
if ($this->_values['is_monetary'] &&
!empty($this->_paymentProcessor) &&
- ((float ) $params['amount'] > 0.0 || $memFee > 0.0)
+ ((float) $params['amount'] > 0.0 || $this->hasSeparateMembershipPaymentAmount($params))
) {
// The concept of contributeMode is deprecated - as should be the 'is_monetary' setting.
$this->setContributeMode();
* Function for unit tests on the postProcess function.
*
* @param array $params
+ *
+ * @throws \CiviCRM_API3_Exception
*/
public function testSubmit($params) {
$_SERVER['REQUEST_METHOD'] = 'GET';
$this->submit($params);
}
+ /**
+ * Has a separate membership payment amount been configured.
+ *
+ * @param array $params
+ *
+ * @return mixed
+ * @throws \CiviCRM_API3_Exception
+ */
+ protected function hasSeparateMembershipPaymentAmount($params) {
+ return $this->_separateMembershipPayment && (int) CRM_Member_BAO_MembershipType::getMembershipType($params['selectMembership'])['minimum_fee'];
+ }
+
}
'billing_first_name' => 'Billy',
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
];
$this->callAPIAndDocument('ContributionPage', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
$submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
- 'amount' => 10,
'billing_first_name' => 'Billy',
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
$submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
- 'amount' => 10,
'billing_first_name' => 'Billy',
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
'email-Primary' => 'billy-goat@the-bridge.net',
'payment_processor_id' => $this->_paymentProcessor['id'],
'credit_card_number' => '4111111111111111',
'billing_first_name' => 'Billy',
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruffier',
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
'email-Primary' => 'billy-goat@the-new-bridge.net',
'payment_processor_id' => $this->params['payment_processor_id'],
];
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
'is_pay_later' => 1,
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
'email-Primary' => 'billy-goat@the-bridge.net',
];
$submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
- 'amount' => 10,
'billing_first_name' => 'Billy',
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
+ 'amount' => 10,
];
- $this->callAPISuccess('contribution_page', 'submit', $submitParams);
+ $this->callAPISuccess('ContributionPage', 'submit', $submitParams);
$contributions = $this->callAPISuccess('contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page']]);
$this->assertCount(2, $contributions['values']);
$lines = $this->callAPISuccess('LineItem', 'get', ['sequential' => 1]);
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
'email' => 'billy@goat.gruff',
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
'email' => 'billy@goat.gruff',
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
'email' => 'billy@goat.gruff',
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',