Merge pull request #13365 from mattwire/caseformatcustomdata
[civicrm-core.git] / api / v3 / PaymentProcessor.php
index 658b51aae3fce929fc8da9b8e898108800941b98..5cd0195f0949ca012c5efcfaec49ad5a92996639 100644 (file)
@@ -93,7 +93,6 @@ function civicrm_api3_payment_processor_get($params) {
   return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
 }
 
-
 /**
  * Set default getlist parameters.
  *
@@ -123,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);
 }
 
@@ -145,7 +155,7 @@ function _civicrm_api3_payment_processor_pay_spec(&$params) {
   ];
   $params['amount'] = [
     'api.required' => TRUE,
-    'title' => ts('Amount to refund'),
+    'title' => ts('Amount to pay'),
     'type' => CRM_Utils_Type::T_MONEY,
   ];
 }