From c28ad54a7194e30033ffed1ad727586546e80db3 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 15 Oct 2019 13:17:30 +1300 Subject: [PATCH] Add getters & setters for contributionID on CRM_Core_Payment. This will enable PaymentProcessor.pay to do ->setContributionID(['contribution_id']) and set a pattern for definining other standardised parameters. --- CRM/Core/Payment.php | 36 +++++++++++++++++++++++++++++++++ CRM/Core/Payment/PayPalImpl.php | 4 ++++ 2 files changed, 40 insertions(+) diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 69b97a342f..cb2e2f77cf 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -149,6 +149,41 @@ abstract class CRM_Core_Payment { */ protected $backOffice = FALSE; + /** + * Contribution that is being paid. + * + * @var int + */ + protected $contributionID; + + /** + * Passed in parameters. + * + * Using individual getters & setters is preferred but these will be used if + * they are not available. + * + * @var array + */ + protected $inputParams = []; + + /** + * Get the contribution ID. + * + * We prefer the one set by the setter but traditional forms just pass in 'contributionID'. + * + * @return int + */ + public function getContributionID(): int { + return $this->contributionID ?? $this->inputParams['contributionID']; + } + + /** + * @param int $contributionID + */ + public function setContributionID(int $contributionID) { + $this->contributionID = $contributionID; + } + /** * @return bool */ @@ -1244,6 +1279,7 @@ abstract class CRM_Core_Payment { * @throws \Civi\Payment\Exception\PaymentProcessorException */ public function doPayment(&$params, $component = 'contribute') { + $this->inputParams = $params; $this->_component = $component; $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id', 'validate'); diff --git a/CRM/Core/Payment/PayPalImpl.php b/CRM/Core/Payment/PayPalImpl.php index 905e369a61..8c556973ad 100644 --- a/CRM/Core/Payment/PayPalImpl.php +++ b/CRM/Core/Payment/PayPalImpl.php @@ -432,6 +432,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { "&m=" . "&c={$params['contactID']}" . "&r={$params['contributionRecurID']}" . + // @todo use $this->getContributionID(); "&b={$params['contributionID']}" . "&p={$params['contributionPageID']}"; @@ -569,6 +570,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $args['PROFILEREFERENCE'] = "" . "i=" . $params['invoiceID'] . "&m=" . $component . "&c=" . $params['contactID'] . "&r=" . $params['contributionRecurID'] . + // @todo use $this->getContributionID(); "&b=" . $params['contributionID'] . "&p=" . $params['contributionPageID']; } @@ -880,6 +882,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $notifyParameters = ['module' => $component]; $notifyParameterMap = [ 'contactID' => 'contactID', + // @todo use $this->getContributionID(); 'contributionID' => 'contributionID', 'eventID' => 'eventID', 'participantID' => 'participantID', @@ -903,6 +906,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $cancelUrlString = "$cancel=1&cancel=1&qfKey={$params['qfKey']}"; if (!empty($params['is_recur'])) { + // @todo use $this->getContributionID(); $cancelUrlString .= "&isRecur=1&recurId={$params['contributionRecurID']}&contribId={$params['contributionID']}"; } -- 2.25.1