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] Use function to getContributionRecurID #20293

Merged
merged 1 commit into from
May 14, 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
41 changes: 25 additions & 16 deletions CRM/Core/Payment/PayPalIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function single($input, $ids, $contribution, $recur = FALSE) {
return;
}

CRM_Contribute_BAO_Contribution::completeOrder($input, $ids['contributionRecur'] ?? NULL, $contribution->id ?? NULL);
CRM_Contribute_BAO_Contribution::completeOrder($input, $this->getContributionRecurID(), $contribution->id ?? NULL);
}

/**
Expand All @@ -243,7 +243,6 @@ public function main() {
$ids['contact'] = $this->retrieve('contactID', 'Integer', TRUE);
$contributionID = $ids['contribution'] = $this->retrieve('contributionID', 'Integer', TRUE);
$membershipID = $this->retrieve('membershipID', 'Integer', FALSE);
$contributionRecurID = $this->retrieve('contributionRecurID', 'Integer', FALSE);

$this->getInput($input);

Expand All @@ -259,13 +258,13 @@ public function main() {
$ids['onbehalf_dupe_alert'] = $this->retrieve('onBehalfDupeAlert', 'Integer', FALSE);
}

$paymentProcessorID = $this->getPayPalPaymentProcessorID($input, $contributionRecurID);
$paymentProcessorID = $this->getPayPalPaymentProcessorID($input, $this->getContributionRecurID());

Civi::log()->debug('PayPalIPN: Received (ContactID: ' . $ids['contact'] . '; trxn_id: ' . $input['trxn_id'] . ').');

// Debugging related to possible missing membership linkage
if ($contributionRecurID && $this->retrieve('membershipID', 'Integer', FALSE)) {
$templateContribution = CRM_Contribute_BAO_ContributionRecur::getTemplateContribution($contributionRecurID);
if ($this->getContributionRecurID() && $this->retrieve('membershipID', 'Integer', FALSE)) {
$templateContribution = CRM_Contribute_BAO_ContributionRecur::getTemplateContribution($this->getContributionRecurID());
$membershipPayment = civicrm_api3('MembershipPayment', 'get', [
'contribution_id' => $templateContribution['id'],
'membership_id' => $membershipID,
Expand All @@ -285,12 +284,12 @@ public function main() {
Civi::log()->debug('PayPalIPN: Will attempt to compensate');
$input['membership_id'] = $this->retrieve('membershipID', 'Integer', FALSE);
}
if ($contributionRecurID) {
if ($this->getContributionRecurID()) {
$recurLinks = civicrm_api3('ContributionRecur', 'get', [
'membership_id' => $membershipID,
'contribution_recur_id' => $contributionRecurID,
'contribution_recur_id' => $this->getContributionRecurID(),
]);
Civi::log()->debug('PayPalIPN: Membership should be linked to contribution recur record ' . $contributionRecurID
Civi::log()->debug('PayPalIPN: Membership should be linked to contribution recur record ' . $this->getContributionRecurID()
. ' ' . $recurLinks['count'] . 'links found'
);
}
Expand Down Expand Up @@ -326,13 +325,11 @@ public function main() {

$input['payment_processor_id'] = $paymentProcessorID;

if ($contributionRecurID) {
if ($this->getContributionRecurID()) {
$contributionRecur = new CRM_Contribute_BAO_ContributionRecur();
$contributionRecur->id = $contributionRecurID;
$contributionRecur->id = $this->getContributionRecurID();
if (!$contributionRecur->find(TRUE)) {
CRM_Core_Error::debug_log_message("Could not find contribution recur record: {$ids['ContributionRecur']} in IPN request: " . print_r($input, TRUE));
echo "Failure: Could not find contribution recur record: {$ids['ContributionRecur']}<p>";
return FALSE;
throw new CRM_Core_Exception('Could not find contribution recur record');
}
// check if first contribution is completed, else complete first contribution
$first = TRUE;
Expand All @@ -344,7 +341,7 @@ public function main() {
if ($this->getFirstOrLastInSeriesStatus()) {
//send recurring Notification email for user
CRM_Contribute_BAO_ContributionPage::recurringNotify(
$ids['contribution'],
$contributionID,
$this->getFirstOrLastInSeriesStatus(),
$contributionRecur
);
Expand Down Expand Up @@ -379,11 +376,11 @@ public function main() {
}
$this->single($input, [
'participant' => $ids['participant'] ?? NULL,
'contributionRecur' => $contributionRecurID,
'contributionRecur' => $this->getContributionRecurID(),
], $contribution);
}
catch (CRM_Core_Exception $e) {
Civi::log()->debug($e->getMessage());
Civi::log()->debug($e->getMessage() . ' input {input}', ['input' => $input]);
echo 'Invalid or missing data';
}
}
Expand Down Expand Up @@ -511,4 +508,16 @@ protected function getFirstOrLastInSeriesStatus(): ?string {
return NULL;
}

/**
* Get the recurring contribution ID.
*
* @return int|null
*
* @throws \CRM_Core_Exception
*/
protected function getContributionRecurID(): ?int {
$id = $this->retrieve('contributionRecurID', 'Integer', FALSE);
return $id ? (int) $id : NULL;
}

}