Convert payJunction to doPayment
authorMatthew Wire <mjw@mjwconsult.co.uk>
Mon, 17 May 2021 15:29:50 +0000 (16:29 +0100)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Mon, 17 May 2021 15:34:28 +0000 (16:34 +0100)
CRM/Core/Payment/PayJunction.php

index ce1b33442ce6fd0e5190906d9168cc7b96b51b2f..21e7ae1b90e343cdb8b5d1388a3ea17273a5b128 100644 (file)
@@ -41,14 +41,29 @@ class CRM_Core_Payment_PayJunction extends CRM_Core_Payment {
    * 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 @@ class CRM_Core_Payment_PayJunction extends CRM_Core_Payment {
     // 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;
   }