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] Remove excess handling around contact_id #19050

Merged
merged 1 commit into from
Nov 27, 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
22 changes: 4 additions & 18 deletions CRM/Core/Payment/AuthorizeNetIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function main() {
$input['component'] = 'contribute';

// load post vars in $input
$this->getInput($input, $ids);
$this->getInput($input);

// load post ids in $ids
$this->getIDs($ids, $input);
Expand All @@ -65,19 +65,8 @@ public function main() {
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)]);
}
$ids['contributionPage'] = $contribution->contribution_page_id;

// make sure contact exists and is valid
// use the contact id from the contribution record as the id in the IPN may not be valid anymore.
$contact = new CRM_Contact_BAO_Contact();
$contact->id = $contribution->contact_id;
$contact->find(TRUE);
if ($contact->id != $ids['contact']) {
// 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>";
$ids['contact'] = $contribution->contact_id;
}
$ids['contributionPage'] = $contribution->contribution_page_id;

$contributionRecur = new CRM_Contribute_BAO_ContributionRecur();
$contributionRecur->id = $ids['contributionRecur'];
Expand All @@ -95,7 +84,6 @@ public function main() {
//load new contribution object if required.
// create a contribution and then get it processed
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->contact_id = $ids['contact'];
$contribution->contribution_page_id = $ids['contributionPage'];
$contribution->contribution_recur_id = $ids['contributionRecur'];
$contribution->receive_date = $input['receive_date'];
Expand All @@ -110,7 +98,7 @@ public function main() {
if ($isFirstOrLastRecurringPayment) {
//send recurring Notification email for user
CRM_Contribute_BAO_ContributionPage::recurringNotify(TRUE,
$ids['contact'],
$contributionRecur->contact_id,
$ids['contributionPage'],
$contributionRecur,
(bool) $this->getMembershipID($contribution->id, $contributionRecur->id)
Expand Down Expand Up @@ -252,11 +240,9 @@ public function getInput(&$input) {
* @throws \CRM_Core_Exception
*/
public function getIDs(&$ids, $input) {
$ids['contact'] = (int) $this->retrieve('x_cust_id', 'Integer', FALSE, 0);
$ids['contribution'] = (int) $this->retrieve('x_invoice_num', 'Integer');
$contributionRecur = $this->getContributionRecurObject($input['subscription_id'], $ids['contact'], $ids['contribution']);
$contributionRecur = $this->getContributionRecurObject($input['subscription_id'], (int) $this->retrieve('x_cust_id', 'Integer', FALSE, 0), $ids['contribution']);
$ids['contributionRecur'] = (int) $contributionRecur->id;
$ids['contact'] = $contributionRecur->contact_id;
}

/**
Expand Down