From bda4a802228bcb7ec40ce76d28cf6dbb0cffbbb8 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 17 May 2021 16:29:50 +0100 Subject: [PATCH] Convert payJunction to doPayment --- CRM/Core/Payment/PayJunction.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/CRM/Core/Payment/PayJunction.php b/CRM/Core/Payment/PayJunction.php index ce1b33442ce6..21e7ae1b90e3 100644 --- a/CRM/Core/Payment/PayJunction.php +++ b/CRM/Core/Payment/PayJunction.php @@ -41,14 +41,29 @@ public function __construct($mode, &$paymentProcessor) { * This function sends request and receives response from * PayJunction payment process * - * @param array $params - * Assoc array of input parameters for this transaction. + * @param array|PropertyBag $params + * + * @param string $component * * @return array - * the result in an nice formatted array (or an error object) + * 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; + } + $logon = $this->_paymentProcessor['user_name']; $password = $this->_paymentProcessor['password']; $url_site = $this->_paymentProcessor['url_site']; @@ -151,6 +166,8 @@ public function doDirectPayment(&$params) { // Success $params['trxn_result_code'] = $pjpgResponse['dc_response_code']; $params['trxn_id'] = $pjpgResponse['dc_transaction_id']; + $params['payment_status_id'] = array_search('Completed', $statuses); + $params['payment_status'] = 'Completed'; return $params; }