diff --git a/CRM/Core/Payment/AuthorizeNetIPN.php b/CRM/Core/Payment/AuthorizeNetIPN.php index f3e3032d81c7..6254699d1dbf 100644 --- a/CRM/Core/Payment/AuthorizeNetIPN.php +++ b/CRM/Core/Payment/AuthorizeNetIPN.php @@ -43,14 +43,6 @@ public function main() { //we only get invoice num as a key player from payment gateway response. //for ARB we get x_subscription_id and x_subscription_paynum $x_subscription_id = $this->getRecurProcessorID(); - $input = []; - - $input['component'] = 'contribute'; - - // load post vars in $input - $this->getInput($input); - $paymentProcessorID = $this->getPaymentProcessorID(); - // Check if the contribution exists // make sure contribution exists and is valid $contribution = new CRM_Contribute_BAO_Contribution(); @@ -59,23 +51,14 @@ public function main() { 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)]); } - $contributionRecur = new CRM_Contribute_BAO_ContributionRecur(); - $contributionRecur->id = $this->getContributionRecurID(); - if (!$contributionRecur->find(TRUE)) { - throw new CRM_Core_Exception("Could not find contribution recur record: " . $this->getContributionRecurID() . " in IPN request: " . print_r($input, TRUE)); - } - // do a subscription check - if ($contributionRecur->processor_id != $this->getRecurProcessorID()) { - throw new CRM_Core_Exception('Unrecognized subscription.'); - } + $contributionRecur = $this->getContributionRecur(); // check if first contribution is completed, else complete first contribution $first = TRUE; if ($contribution->contribution_status_id == 1) { $first = FALSE; } - $input['payment_processor_id'] = $paymentProcessorID; - $isFirstOrLastRecurringPayment = $this->recur($input, $contributionRecur, $first); + $isFirstOrLastRecurringPayment = $this->recur($contributionRecur, $first); if ($isFirstOrLastRecurringPayment) { //send recurring Notification email for user @@ -100,8 +83,10 @@ public function main() { * @return bool * @throws \CRM_Core_Exception */ - public function recur($input, $recur, $first) { - + public function recur($recur, $first) { + $paymentProcessorID = $this->getPaymentProcessorID(); + $input = $this->getInput(); + $input['payment_processor_id'] = $paymentProcessorID; $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $now = date('YmdHis'); @@ -149,11 +134,12 @@ public function recur($input, $recur, $first) { /** * Get the input from passed in fields. * - * @param array $input - * * @throws \CRM_Core_Exception */ - public function getInput(&$input) { + public function getInput(): array { + $input = []; + // This component is probably obsolete & will go once we stop calling completeOrder directly. + $input['component'] = 'contribute'; $input['amount'] = $this->retrieve('x_amount', 'String'); $input['subscription_id'] = $this->getRecurProcessorID(); $input['response_reason_code'] = $this->retrieve('x_response_reason_code', 'String', FALSE); @@ -186,6 +172,7 @@ public function getInput(&$input) { foreach ($params as $civiName => $resName) { $input[$civiName] = $this->retrieve($resName, 'String', FALSE); } + return $input; } /** @@ -354,4 +341,23 @@ protected function getContributionRecurID(): int { return (int) $contributionRecur->id; } + /** + * @param array $input + * + * @return \CRM_Contribute_BAO_ContributionRecur + * @throws \CRM_Core_Exception + */ + private function getContributionRecur(): CRM_Contribute_BAO_ContributionRecur { + $contributionRecur = new CRM_Contribute_BAO_ContributionRecur(); + $contributionRecur->id = $this->getContributionRecurID(); + if (!$contributionRecur->find(TRUE)) { + throw new CRM_Core_Exception("Could not find contribution recur record: " . $this->getContributionRecurID() . " in IPN request: " . print_r($this->getInput(), TRUE)); + } + // do a subscription check + if ($contributionRecur->processor_id != $this->getRecurProcessorID()) { + throw new CRM_Core_Exception('Unrecognized subscription.'); + } + return $contributionRecur; + } + }