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

[REF] Extract determination of subscription status information #19193

Merged
merged 1 commit into from
Dec 12, 2020
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
38 changes: 32 additions & 6 deletions CRM/Core/Payment/PayPalIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ public function recur($input, $ids, $recur, $contribution, $first) {

$now = date('YmdHis');

$subscriptionPaymentStatus = NULL;
// set transaction type
$txnType = $this->retrieve('txn_type', 'String');
$txnType = $this->getTrxnType();
$contributionStatuses = array_flip(CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id', 'validate'));
switch ($txnType) {
case 'subscr_signup':
Expand All @@ -112,15 +111,13 @@ public function recur($input, $ids, $recur, $contribution, $first) {
}
$recur->processor_id = $this->retrieve('subscr_id', 'String');
$recur->trxn_id = $recur->processor_id;
$subscriptionPaymentStatus = CRM_Core_Payment::RECURRING_PAYMENT_START;
break;

case 'subscr_eot':
if ($recur->contribution_status_id != $contributionStatuses['Cancelled']) {
$recur->contribution_status_id = $contributionStatuses['Completed'];
}
$recur->end_date = $now;
$subscriptionPaymentStatus = CRM_Core_Payment::RECURRING_PAYMENT_END;
break;

case 'subscr_cancel':
Expand Down Expand Up @@ -156,7 +153,7 @@ public function recur($input, $ids, $recur, $contribution, $first) {

$recur->save();

if (in_array($this->retrieve('txn_type', 'String'), ['subscr_signup', 'subscr_eot'])) {
if ($this->getFirstOrLastInSeriesStatus()) {
$autoRenewMembership = FALSE;
if ($recur->id &&
isset($ids['membership']) && $ids['membership']
Expand All @@ -165,7 +162,7 @@ public function recur($input, $ids, $recur, $contribution, $first) {
}

//send recurring Notification email for user
CRM_Contribute_BAO_ContributionPage::recurringNotify($subscriptionPaymentStatus,
CRM_Contribute_BAO_ContributionPage::recurringNotify($this->getFirstOrLastInSeriesStatus(),
$ids['contact'],
$ids['contributionPage'],
$recur,
Expand Down Expand Up @@ -502,4 +499,33 @@ public function getPayPalPaymentProcessorID($input, $ids) {
return $paymentProcessorID;
}

/**
* @return mixed
* @throws \CRM_Core_Exception
*/
protected function getTrxnType() {
$txnType = $this->retrieve('txn_type', 'String');
return $txnType;
}

/**
* Get status code for first or last recurring in the series.
*
* If this is the first or last then return the status code, else
* null.
*
* @return string|null
* @throws \CRM_Core_Exception
*/
protected function getFirstOrLastInSeriesStatus(): ?string {
$subscriptionPaymentStatus = NULL;
if ($this->getTrxnType() === 'subscr_signup') {
return CRM_Core_Payment::RECURRING_PAYMENT_START;
}
if ($this->getTrxnType() === 'subscr_eot') {
return CRM_Core_Payment::RECURRING_PAYMENT_END;
}
return NULL;
}

}