Skip to content

Commit

Permalink
Merge pull request #20007 from eileenmcnaughton/mem_rec
Browse files Browse the repository at this point in the history
Extract out getReceiveDate
  • Loading branch information
monishdeb authored Apr 9, 2021
2 parents 94f8692 + f4ee14f commit e053d1e
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions CRM/Member/Form/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,6 @@ public function submit(): void {
$this->_params = $formValues;

$contribution = $this->processContribution(
$paymentParams,
[
'contact_id' => $this->_contributorContactID,
'line_item' => [$this->order->getPriceSetID() => $this->order->getLineItems()],
Expand Down Expand Up @@ -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
Expand All @@ -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);
}

Expand All @@ -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;
}
Expand All @@ -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();
Expand Down Expand Up @@ -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');
}

}

0 comments on commit e053d1e

Please sign in to comment.