Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to Call contribution api #20041

Merged
merged 1 commit into from
Apr 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 7 additions & 39 deletions CRM/Member/Form/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ public function submit(): void {
if ($this->isCreateRecurringContribution()) {
$this->_params = $formValues;

$contribution = $this->processContribution(
$contribution = civicrm_api3('Contribution', 'create',
[
'contact_id' => $this->_contributorContactID,
'line_item' => [$this->order->getPriceSetID() => $this->order->getLineItems()],
Expand All @@ -1147,29 +1147,29 @@ public function submit(): void {
'source' => CRM_Utils_Array::value('source', $paymentParams, CRM_Utils_Array::value('description', $paymentParams)),
'payment_instrument_id' => $this->getPaymentInstrumentID(),
'financial_type_id' => $this->getFinancialTypeID(),
'receive_date' => CRM_Utils_Time::date('YmdHis'),
'receive_date' => $this->getReceiveDate(),
'tax_amount' => $this->order->getTotalTaxAmount(),
'total_amount' => $this->order->getTotalAmount(),
'invoice_id' => $this->getInvoiceID(),
'currency' => $this->getCurrency(),
'is_pay_later' => $params['is_pay_later'] ?? 0,
'skipLineItem' => $params['skipLineItem'] ?? 0,
'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'),
'contribution_status_id' => 'Pending',
'receipt_date' => $this->getSubmittedValue('send_receipt') ? date('YmdHis') : NULL,
'contribution_recur_id' => $this->getContributionRecurID(),
'skipCleanMoney' => TRUE,
]
);

//create new soft-credit record, CRM-13981
if ($softParams) {
$softParams['contribution_id'] = $contribution->id;
$softParams['contribution_id'] = $contribution['id'];
$softParams['currency'] = $this->getCurrency();
$softParams['amount'] = $this->order->getTotalAmount();
CRM_Contribute_BAO_ContributionSoft::add($softParams);
}

$paymentParams['contactID'] = $this->_contactID;
$paymentParams['contributionID'] = $contribution->id;
$paymentParams['contributionID'] = $contribution['id'];

$paymentParams['contributionRecurID'] = $this->getContributionRecurID();
$paymentParams['is_recur'] = $this->isCreateRecurringContribution();
$params['contribution_id'] = $paymentParams['contributionID'];
Expand Down Expand Up @@ -1679,38 +1679,6 @@ protected function getContributionRecurID():?int {
return $this->ids['ContributionRecur'];
}

/**
* Legacy contribution processing function.
*
* This is copied from a shared function in order to clean it up. Most of the
* stuff in it, maybe all except the ContributionRecur create is
* not applicable to this form & can be removed in follow up cleanup.
*
* It's like the contribution create being done here is actively bad and
* being fixed later.
*
* @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
* passed consistently & 2) documenting them here.
* - contact_id
* - line_item
* - is_test
* - campaign_id
* - source
* - payment_type_id
*
* @return \CRM_Contribute_DAO_Contribution
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
protected function processContribution(
$contributionParams
) {
return CRM_Contribute_BAO_Contribution::add($contributionParams);
}

/**
* Create the recurring contribution record if the form submission requires it.
*
Expand Down