From c9696db9e60b6e0e1e61d9a91e779d94a7686fb0 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 26 May 2020 19:21:21 +1200 Subject: [PATCH] [REF] Pass an array of correct params to the function to create a recurring contribution. This is getting away from 'passing whatever params we have' to 'passing the right params', which makes it easier to see what can and can't be altered. Note that from https://issues.civicrm.org/jira/browse/CRM-17636 we can see that is_email_receipt is not set for payment purposes but contributionRecur purposes and since it's not a propertyBag param we can leave it off here --- CRM/Member/Form.php | 19 +++---------------- CRM/Member/Form/MembershipRenewal.php | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index a2e2ec3aa0..73f7cb46a9 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -356,27 +356,14 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { /** * Create a recurring contribution record. * - * Recurring contribution parameters are set explicitly rather than merging paymentParams because it's hard - * to know the downstream impacts if we keep passing around the same array. + * @param array $contributionRecurParams * - * @param $paymentParams + * @param int $membershipID * * @return array * @throws \CiviCRM_API3_Exception */ - protected function processRecurringContribution($paymentParams) { - $membershipID = $paymentParams['membership_type_id'][1]; - $contributionRecurParams = [ - 'contact_id' => $paymentParams['contactID'], - 'amount' => $paymentParams['total_amount'], - 'contribution_status_id' => 'Pending', - 'payment_processor_id' => $paymentParams['payment_processor_id'], - 'campaign_id' => $paymentParams['campaign_id'], - 'financial_type_id' => $paymentParams['financial_type_id'], - 'is_email_receipt' => $paymentParams['is_email_receipt'], - 'payment_instrument_id' => $paymentParams['payment_instrument_id'], - 'invoice_id' => $paymentParams['invoice_id'], - ]; + protected function processRecurringContribution($contributionRecurParams, $membershipID) { $mapping = [ 'frequency_interval' => 'duration_interval', diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index 04287f6bfe..0d7e13eab2 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -537,20 +537,30 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { if (!empty($this->_params['send_receipt'])) { $paymentParams['email'] = $this->_contributorEmail; } - $paymentParams['is_email_receipt'] = !empty($this->_params['send_receipt']); $paymentParams['contactID'] = $this->_contributorContactID; CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE); - $payment = $this->_paymentProcessor['object']; - if (!empty($this->_params['auto_renew'])) { - $contributionRecurParams = $this->processRecurringContribution($paymentParams); + + $contributionRecurParams = $this->processRecurringContribution([ + 'contact_id' => $this->_contributorContactID, + 'amount' => $this->_params['total_amount'], + 'contribution_status_id' => 'Pending', + 'payment_processor_id' => $this->_params['payment_processor_id'], + 'campaign_id' => $this->_params['campaign_id'], + 'financial_type_id' => $this->_params['financial_type_id'], + 'is_email_receipt' => !empty($this->_params['send_receipt']), + 'payment_instrument_id' => $this->_params['payment_instrument_id'], + 'invoice_id' => $this->_params['invoice_id'], + ], $membershipID = $paymentParams['membership_type_id'][1]); + $contributionRecurID = $contributionRecurParams['contributionRecurID']; $paymentParams = array_merge($paymentParams, $contributionRecurParams); } + $payment = $this->_paymentProcessor['object']; $result = $payment->doPayment($paymentParams); $this->_params = array_merge($this->_params, $result); -- 2.25.1