From b5ab97644ba51d35d1858a71975cc75da6145a69 Mon Sep 17 00:00:00 2001 From: eileen Date: Sun, 11 Oct 2020 12:30:36 +1300 Subject: [PATCH] dev/financial#152 [REF] Extract getMembershipID Note that since NULL is valid we can just return the result of the query. Bypassing for component=event doesn't provide enough value to justify relying on a url param as opposed to just looking it up & feels very original-form-flow --- CRM/Core/Payment/AuthorizeNetIPN.php | 42 +++++++++++++++------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/CRM/Core/Payment/AuthorizeNetIPN.php b/CRM/Core/Payment/AuthorizeNetIPN.php index 1cadb8f931..1f36f4f3c4 100644 --- a/CRM/Core/Payment/AuthorizeNetIPN.php +++ b/CRM/Core/Payment/AuthorizeNetIPN.php @@ -290,7 +290,7 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN { */ public function getIDs(&$ids, &$input) { $ids['contact'] = $this->retrieve('x_cust_id', 'Integer', FALSE, 0); - $ids['contribution'] = $this->retrieve('x_invoice_num', 'Integer'); + $ids['contribution'] = (int) $this->retrieve('x_invoice_num', 'Integer'); // joining with contribution table for extra checks $sql = " @@ -302,7 +302,7 @@ INNER JOIN civicrm_contribution co ON co.contribution_recur_id = cr.id LIMIT 1"; $contRecur = CRM_Core_DAO::executeQuery($sql); $contRecur->fetch(); - $ids['contributionRecur'] = $contRecur->id; + $ids['contributionRecur'] = (int) $contRecur->id; if ($ids['contact'] != $contRecur->contact_id) { $message = ts("Recurring contribution appears to have been re-assigned from id %1 to %2, continuing with %2.", [1 => $ids['contact'], 2 => $contRecur->contact_id]); CRM_Core_Error::debug_log_message($message); @@ -314,24 +314,7 @@ INNER JOIN civicrm_contribution co ON co.contribution_recur_id = cr.id $log->error('payment_notification', ['message' => $message, 'ids' => $ids, 'input' => $input]); throw new CRM_Core_Exception($message); } - - if ($input['component'] == 'event') { - // FIXME: figure out fields for event - } - else { - // Get membershipId. Join with membership payment table for additional checks - $sql = " - SELECT m.id - FROM civicrm_membership m -INNER JOIN civicrm_membership_payment mp ON m.id = mp.membership_id AND mp.contribution_id = {$ids['contribution']} - WHERE m.contribution_recur_id = {$ids['contributionRecur']} - LIMIT 1"; - if ($membershipId = CRM_Core_DAO::singleValueQuery($sql)) { - $ids['membership'] = $membershipId; - } - - // FIXME: todo related_contact and onBehalfDupeAlert. Check paypalIPN. - } + $ids['membership'] = $this->getMembershipID($ids['contribution'], $ids['contributionRecur']); } /** @@ -359,4 +342,23 @@ INNER JOIN civicrm_membership_payment mp ON m.id = mp.membership_id AND mp.contr return $value; } + /** + * Get membership id, if any. + * + * @param int $contributionID + * @param int $contributionRecurID + * + * @return int|null + */ + protected function getMembershipID(int $contributionID, int $contributionRecurID): ?int { + // Get membershipId. Join with membership payment table for additional checks + $sql = " + SELECT m.id + FROM civicrm_membership m +INNER JOIN civicrm_membership_payment mp ON m.id = mp.membership_id AND mp.contribution_id = {$contributionID} + WHERE m.contribution_recur_id = {$contributionRecurID} + LIMIT 1"; + return CRM_Core_DAO::singleValueQuery($sql); + } + } -- 2.25.1