From d4137beed307786c569dac73f357bbbef5937cbb Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 17 May 2021 16:20:31 +0100 Subject: [PATCH] Convert eway to doPayment --- ext/ewaysingle/CRM/Core/Payment/eWAY.php | 27 ++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/ext/ewaysingle/CRM/Core/Payment/eWAY.php b/ext/ewaysingle/CRM/Core/Payment/eWAY.php index a50389ffd3..7dc7d233b5 100644 --- a/ext/ewaysingle/CRM/Core/Payment/eWAY.php +++ b/ext/ewaysingle/CRM/Core/Payment/eWAY.php @@ -128,12 +128,29 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment { /** * Sends request and receive response from eWAY payment process. * - * @param array $params + * @param array|\Civi\Payment\PropertyBag $params * - * @return array|object - * @throws \Exception + * @param string $component + * + * @return array + * Result array (containing at least the key payment_status_id) + * + * @throws \Civi\Payment\Exception\PaymentProcessorException */ - public function doDirectPayment(&$params) { + public function doPayment(&$params, $component = 'contribute') { + $propertyBag = \Civi\Payment\PropertyBag::cast($params); + $this->_component = $component; + $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id', 'validate'); + + // If we have a $0 amount, skip call to processor and set payment_status to Completed. + // Conceivably a processor might override this - perhaps for setting up a token - but we don't + // have an example of that at the moment. + if ($propertyBag->getAmount() == 0) { + $result['payment_status_id'] = array_search('Completed', $statuses); + $result['payment_status'] = 'Completed'; + return $result; + } + if (CRM_Utils_Array::value('is_recur', $params) == TRUE) { throw new CRM_Core_Exception(ts('eWAY - recurring payments not implemented')); } @@ -319,6 +336,8 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment { } $params['trxn_result_code'] = $eWAYResponse->Status() . $beaglestatus; $params['trxn_id'] = $eWAYResponse->TransactionNumber(); + $params['payment_status_id'] = array_search('Completed', $statuses); + $params['payment_status'] = 'Completed'; return $params; } -- 2.25.1