From e02cd7819469f2be8146d6108e0734b36ca66086 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 15 Jul 2021 11:47:43 +1200 Subject: [PATCH] [REF] Use getter rather than passing variable txnType is a required parameter for recurring & unused for single. This switches to retrieving it as needed rather than passing it around. It removes one check for whether it is set because the abort will exit if not --- CRM/Core/Payment/PayPalIPN.php | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/CRM/Core/Payment/PayPalIPN.php b/CRM/Core/Payment/PayPalIPN.php index 29d7587527..a345d0c3c7 100644 --- a/CRM/Core/Payment/PayPalIPN.php +++ b/CRM/Core/Payment/PayPalIPN.php @@ -70,13 +70,7 @@ class CRM_Core_Payment_PayPalIPN extends CRM_Core_Payment_BaseIPN { * @throws \CiviCRM_API3_Exception */ public function recur($input, $recur, $contribution, $first) { - if (!isset($input['txnType'])) { - Civi::log()->debug('PayPalIPN: Could not find txn_type in input request'); - echo "Failure: Invalid parameters

"; - return; - } - - if ($input['txnType'] === 'subscr_payment' && + if ($this->getTrxnType() === 'subscr_payment' && $input['paymentStatus'] !== 'Completed' ) { Civi::log()->debug('PayPalIPN: Ignore all IPN payments that are not completed'); @@ -94,9 +88,8 @@ class CRM_Core_Payment_PayPalIPN extends CRM_Core_Payment_BaseIPN { $now = date('YmdHis'); // set transaction type - $txnType = $this->getTrxnType(); $contributionStatuses = array_flip(CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id', 'validate')); - switch ($txnType) { + switch ($this->getTrxnType()) { case 'subscr_signup': $recur->create_date = $now; // sometimes subscr_signup response come after the subscr_payment and set to pending mode. @@ -151,7 +144,7 @@ class CRM_Core_Payment_PayPalIPN extends CRM_Core_Payment_BaseIPN { $recur->save(); - if ($txnType !== 'subscr_payment') { + if ($this->getTrxnType() !== 'subscr_payment') { return; } @@ -336,7 +329,6 @@ class CRM_Core_Payment_PayPalIPN extends CRM_Core_Payment_BaseIPN { */ public function getInput(&$input) { $billingID = CRM_Core_BAO_LocationType::getBilling(); - $input['txnType'] = $this->retrieve('txn_type', 'String', FALSE); $input['paymentStatus'] = $this->retrieve('payment_status', 'String', FALSE); $input['invoice'] = $this->retrieve('invoice', 'String', TRUE); $input['amount'] = $this->retrieve('mc_gross', 'Money', FALSE); @@ -428,8 +420,7 @@ class CRM_Core_Payment_PayPalIPN extends CRM_Core_Payment_BaseIPN { * @throws \CRM_Core_Exception */ protected function getTrxnType() { - $txnType = $this->retrieve('txn_type', 'String'); - return $txnType; + return $this->retrieve('txn_type', 'String'); } /** -- 2.25.1