$totalAmount = $membershipParams['amount'];
if ($isPaidMembership) {
- if ($isProcessSeparateMembershipTransaction) {
+ if ($this->isSeparatePaymentSelected()) {
// If we have 2 transactions only one can use the invoice id.
$membershipParams['invoiceID'] .= '-2';
if (!empty($membershipParams['auto_renew'])) {
}
}
- if ($isProcessSeparateMembershipTransaction) {
+ if ($this->isSeparatePaymentSelected()) {
try {
$this->_lineItem = $unprocessedLineItems;
if (empty($this->_params['auto_renew']) && !empty($membershipParams['is_recur'])) {
$this->_useForMember = $this->get('useForMember');
// store the fact that this is a membership and membership type is selected
- if ($this->isMembershipSelected($membershipParams)) {
+ if ($this->isMembershipSelected()) {
$this->doMembershipProcessing($contactID, $membershipParams, $premiumParams);
}
else {
/**
* Return True/False if we have a membership selected on the contribution page
- * @param array $membershipParams
*
* @return bool
*/
- private function isMembershipSelected($membershipParams) {
- $priceFieldIds = $this->get('memberPriceFieldIDS');
- if ((!empty($membershipParams['selectMembership']) && $membershipParams['selectMembership'] != 'no_thanks')
- && empty($priceFieldIds)) {
- return TRUE;
- }
- else {
- $membershipParams = $this->getMembershipParamsFromPriceSet($membershipParams);
- }
- return !empty($membershipParams['selectMembership']);
+ private function isMembershipSelected(): bool {
+ return !empty($this->getMembershipLineItems());
}
/**
}
$membershipParams = $this->getMembershipParamsFromPriceSet($membershipParams);
- if (!empty($membershipParams['selectMembership'])) {
+ if ($this->isMembershipSelected()) {
// CRM-12233
$membershipLineItems = [$this->getPriceSetID() => $this->getLineItems()];;
- if ($this->_separateMembershipPayment && $this->isFormSupportsNonMembershipContributions()) {
+ if ($this->isSeparatePaymentSelected()) {
$membershipLineItems = [];
foreach ($this->_values['fee'] as $key => $feeValues) {
if ($feeValues['name'] == 'membership_amount') {
return $mainContributionLineItems;
}
+ /**
+ * Is the form separate payment AND has the user selected 2 options,
+ * resulting in 2 payments.
+ *
+ * @throws \CRM_Core_Exception
+ */
+ protected function isSeparatePaymentSelected(): bool {
+ return (bool) $this->getSecondaryMembershipContributionLineItems();
+ }
+
/**
* Set the line items for the secondary membership contribution.
*
$lineItems[$index] = $lineItem;
}
}
- if (empty($lineItems) || count($lineItems) === $this->getLineItems()) {
+ if (empty($lineItems) || count($lineItems) === count($this->getLineItems())) {
return FALSE;
}
return $lineItems;
}
/**
- * Test non-recur contribution with membership payment
+ * Test non-recur contribution with membership payment selected.
+ *
+ * In this scenario the contribution option was not selected so only
+ * one contribution is actually created.
*
* @throws \CRM_Core_Exception
- * @throws \Civi\API\Exception\UnauthorizedException
*/
- public function testSubmitMembershipIsSeparatePaymentNotRecur(): void {
+ public function testSubmitMembershipIsSeparatePaymentNotRecurMembershipOnly(): void {
$this->setUpMembershipContributionPage(TRUE, TRUE);
$dummyPP = Civi\Payment\System::singleton()->getById($this->ids['PaymentProcessor']['dummy']);
$dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_first_success']);