Skip to content

Commit

Permalink
[REF] Add getters for contribution id & contact id
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed May 14, 2021
1 parent 4f4bf3b commit 0b095e9
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions CRM/Core/Payment/PayPalIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ public function main() {
$component = $this->retrieve('module', 'String');
$input['component'] = $component;

$ids['contact'] = $this->retrieve('contactID', 'Integer', TRUE);
$contributionID = $ids['contribution'] = $this->retrieve('contributionID', 'Integer', TRUE);
$ids['contact'] = $this->getContactID();
$contributionID = $ids['contribution'] = $this->getContributionID();
$membershipID = $this->retrieve('membershipID', 'Integer', FALSE);

$this->getInput($input);
Expand Down Expand Up @@ -291,7 +291,7 @@ public function main() {
}
}
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $ids['contribution'];
$contribution->id = $this->getContributionID();
if (!$contribution->find(TRUE)) {
throw new CRM_Core_Exception('Failure: Could not find contribution record for ' . (int) $contribution->id, NULL, ['context' => "Could not find contribution record: {$contribution->id} in IPN request: " . print_r($input, TRUE)]);
}
Expand All @@ -301,7 +301,7 @@ public function main() {
$contact = new CRM_Contact_BAO_Contact();
$contact->id = $contribution->contact_id;
$contact->find(TRUE);
if ($contact->id != $ids['contact']) {
if ($contact->id != $this->getContactID()) {
// If the ids do not match then it is possible the contact id in the IPN has been merged into another contact which is why we use the contact_id from the contribution
CRM_Core_Error::debug_log_message("Contact ID in IPN {$ids['contact']} not found but contact_id found in contribution {$contribution->contact_id} used instead");
echo "WARNING: Could not find contact record: {$ids['contact']}<p>";
Expand Down Expand Up @@ -513,4 +513,26 @@ protected function getContributionRecurID(): ?int {
return $id ? (int) $id : NULL;
}

/**
* Get Contribution ID.
*
* @return int
*
* @throws \CRM_Core_Exception
*/
protected function getContributionID(): int {
return (int) $this->retrieve('contributionID', 'Integer', TRUE);
}

/**
* Get contact id from parameters.
*
* @return int
*
* @throws \CRM_Core_Exception
*/
protected function getContactID(): int {
return (int) $this->retrieve('contactID', 'Integer', TRUE);
}

}

0 comments on commit 0b095e9

Please sign in to comment.