infra updated incorrectly set public functions to private on payment classes
authorEileen McNaughton <eileen@fuzion.co.nz>
Thu, 29 Jan 2015 04:11:14 +0000 (17:11 +1300)
committerEileen McNaughton <eileen@fuzion.co.nz>
Thu, 29 Jan 2015 04:11:14 +0000 (17:11 +1300)
this doesn't fix that - it just adapts one instance to not call doDirectPayment & to instead call doPayment
doPayment is now preferred (decision from there rests in payment system) but since doPayment
throws exceptions not changing an masse - however, the api is 'exception-native'

CRM/Core/Payment.php
api/v3/Contribution.php

index 187f1c67eaf28d8d026647935b93c35f77f16a3d..899c83709779711c0088ddc99441aa1f32c95de3 100644 (file)
@@ -398,8 +398,11 @@ abstract class CRM_Core_Payment {
   }
 
   /**
-   * This function collects all the information from a web/api form and invokes
-   * the relevant payment processor specific functions to perform the transaction
+   * Calling this from outside the payment subsystem is deprecated - use doPayment.
+   *
+   * Does a server to server payment transaction.
+   *
+   * Note that doPayment will throw an exception so the code may need to be modified
    *
    * @param array $params
    *   Assoc array of input parameters for this transaction.
@@ -422,7 +425,7 @@ abstract class CRM_Core_Payment {
    *   (modified)
    * @throws CRM_Core_Exception
    */
-  public function doPayment(&$params, $component) {
+  public function doPayment(&$params, $component = 'contribute') {
     if ($this->_paymentProcessor['billing_mode'] == 4) {
       $result = $this->doTransferCheckout($params, $component);
     }
index b23a0b383135192e47362b1da482e256c3be666f..b5952d177d2e99bb64160f795d7948b7d867058b 100644 (file)
@@ -292,6 +292,10 @@ function _civicrm_api3_contribution_transact_spec(&$params) {
  */
 function civicrm_api3_contribution_transact($params) {
   // Set some params specific to payment processing
+  // @todo - fix this function - none of the results checked by civicrm_error would ever be an array with
+  // 'is_error' set
+  // also trxn_id is not saved.
+  // but since there is no test it's not desirable to jump in & make the obvious changes.
   $params['payment_processor_mode'] = empty($params['is_test']) ? 'live' : 'test';
   $params['amount'] = $params['total_amount'];
   if (!isset($params['net_amount'])) {
@@ -314,20 +318,8 @@ function civicrm_api3_contribution_transact($params) {
     return $payment;
   }
 
-  $transaction = $payment->doDirectPayment($params);
-  if (civicrm_error($transaction)) {
-    return $transaction;
-  }
+  $transaction = $payment->doPayment($params);
 
-  // but actually, $payment->doDirectPayment() doesn't return a
-  // CRM_Core_Error by itself
-  if (is_object($transaction) && get_class($transaction) == 'CRM_Core_Error') {
-    $errs = $transaction->getErrors();
-    if (!empty($errs)) {
-      $last_error = array_shift($errs);
-      return CRM_Core_Error::createApiError($last_error['message']);
-    }
-  }
   $params['payment_instrument_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType', $paymentProcessor['payment_processor_type_id'], 'payment_type') == 1 ? 'Credit Card' : 'Debit Card';
   return civicrm_api('contribution', 'create', $params);
 }