*
* @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);
}