From f15d3f218eb73db309bb182aa8580cd03c0480e4 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 9 Apr 2019 12:51:57 +1200 Subject: [PATCH] Include lower level data when throwing an exception on payment processor.pay --- api/v3/PaymentProcessor.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/api/v3/PaymentProcessor.php b/api/v3/PaymentProcessor.php index 51e401c75e..0c8b7c1316 100644 --- a/api/v3/PaymentProcessor.php +++ b/api/v3/PaymentProcessor.php @@ -122,12 +122,23 @@ function _civicrm_api3_payment_processor_getlist_defaults(&$request) { * * @return array * API result array. - * @throws CiviCRM_API3_Exception + * + * @throws \API_Exception */ function civicrm_api3_payment_processor_pay($params) { $processor = Civi\Payment\System::singleton()->getById($params['payment_processor_id']); $processor->setPaymentProcessor(civicrm_api3('PaymentProcessor', 'getsingle', ['id' => $params['payment_processor_id']])); - $result = $processor->doPayment($params); + try { + $result = $processor->doPayment($params); + } + catch (\Civi\Payment\Exception\PaymentProcessorException $e) { + $code = $e->getErrorCode(); + $errorData = $e->getErrorData(); + if (empty($code)) { + $code = 'EXTERNAL_FAILURE'; + } + throw new API_Exception('Payment failed', $code, $errorData, $e); + } return civicrm_api3_create_success(array($result), $params); } -- 2.25.1