From 8319cf114f26e04bb7586cd253af9d97b8cb3859 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 29 Jan 2015 17:11:14 +1300 Subject: [PATCH] infra updated incorrectly set public functions to private on payment classes 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 | 9 ++++++--- api/v3/Contribution.php | 18 +++++------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 187f1c67ea..899c837097 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -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); } diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index b23a0b3831..b5952d177d 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -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); } -- 2.25.1