From f4ee14f91548e4c86ad076f4ba9a8592f491c05a Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 26 Mar 2021 12:43:21 +1300 Subject: [PATCH] Extract out getReceiveDate --- CRM/Member/Form/Membership.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index c435bde7294f..5010f8776db5 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1133,7 +1133,6 @@ public function submit(): void { $this->_params = $formValues; $contribution = $this->processContribution( - $paymentParams, [ 'contact_id' => $this->_contributorContactID, 'line_item' => [$this->order->getPriceSetID() => $this->order->getLineItems()], @@ -1661,7 +1660,6 @@ protected function getSelectedMembershipLabels(): string { * It's like the contribution create being done here is actively bad and * being fixed later. * - * @param array $params * @param array $contributionParams * Parameters to be passed to contribution create action. * This differs from params in that we are currently adding params to it and 1) ensuring they are being @@ -1679,10 +1677,9 @@ protected function getSelectedMembershipLabels(): string { * @throws \CiviCRM_API3_Exception */ protected function processContribution( - $params, $contributionParams ) { - $contributionParams['contribution_recur_id'] = $this->legacyProcessRecurringContribution($params); + $contributionParams['contribution_recur_id'] = $this->legacyProcessRecurringContribution(); return CRM_Contribute_BAO_Contribution::add($contributionParams); } @@ -1691,12 +1688,10 @@ protected function processContribution( * * This function was copied from another form & needs cleanup. * - * @param array $params - * * @return int|null * @throws \CiviCRM_API3_Exception */ - protected function legacyProcessRecurringContribution(array $params): ?int { + protected function legacyProcessRecurringContribution(): ?int { if (!$this->isCreateRecurringContribution()) { return NULL; } @@ -1711,10 +1706,8 @@ protected function legacyProcessRecurringContribution(array $params): ?int { $recurParams['payment_instrument_id'] = $this->getPaymentInstrumentID(); $recurParams['is_test'] = $this->isTest(); - $recurParams['start_date'] = $recurParams['create_date'] = $recurParams['modified_date'] = CRM_Utils_Time::date('YmdHis'); - if (!empty($params['receive_date'])) { - $recurParams['start_date'] = date('YmdHis', CRM_Utils_Time::strtotime($params['receive_date'])); - } + $recurParams['create_date'] = $recurParams['modified_date'] = CRM_Utils_Time::date('YmdHis'); + $recurParams['start_date'] = $this->getReceiveDate(); $recurParams['invoice_id'] = $this->getInvoiceID(); $recurParams['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'); $recurParams['payment_processor_id'] = $this->getPaymentProcessorID(); @@ -1907,4 +1900,13 @@ protected function getContributionSource(): string { ]); } + /** + * Get the receive date for the contribution. + * + * @return string $receive_date + */ + protected function getReceiveDate(): string { + return $this->getSubmittedValue('receive_date') ?: date('YmdHis'); + } + }