From e7dc92b8bdba392d635b7063c18cc22c1c454181 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 17 May 2021 16:26:42 +0100 Subject: [PATCH] Convert elavon to doPayment --- CRM/Core/Payment/Elavon.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/CRM/Core/Payment/Elavon.php b/CRM/Core/Payment/Elavon.php index 8990e85860..596d8898ca 100644 --- a/CRM/Core/Payment/Elavon.php +++ b/CRM/Core/Payment/Elavon.php @@ -84,13 +84,29 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment { /** * This function sends request and receives response from the processor. * - * @param array $params + * @param array|PropertyBag $params + * + * @param string $component * * @return array + * Result array (containing at least the key payment_status_id) * - * @throws \CRM_Core_Exception + * @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 (isset($params['is_recur']) && $params['is_recur'] == TRUE) { throw new CRM_Core_Exception(ts('Elavon - recurring payments not implemented')); } @@ -219,6 +235,8 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment { } $params['trxn_result_code'] = $processorResponse['ssl_approval_code'] . "-Cvv2:" . $processorResponse['ssl_cvv2_response'] . "-avs:" . $processorResponse['ssl_avs_response']; + $params['payment_status_id'] = array_search('Completed', $statuses); + $params['payment_status'] = 'Completed'; return $params; } -- 2.25.1