Merge pull request #15808 from civicrm/5.20
[civicrm-core.git] / api / v3 / PaymentProcessor.php
index 8373cc7ec7c8174995f81830715f85980aba15a9..ea54aca4e1c2f513653908a9aca44fdd0d4b8450 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019                                |
+ | Copyright CiviCRM LLC (c) 2004-2020                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -65,7 +65,13 @@ function _civicrm_api3_payment_processor_create_spec(&$params) {
   $params['domain_id']['api.default'] = CRM_Core_Config::domainID();
   $params['financial_account_id']['api.default'] = CRM_Financial_BAO_PaymentProcessor::getDefaultFinancialAccountID();
   $params['financial_account_id']['api.required'] = TRUE;
+  $params['financial_account_id']['type'] = CRM_Utils_Type::T_INT;
   $params['financial_account_id']['title'] = ts('Financial Account for Processor');
+  $params['financial_account_id']['pseudoconstant'] = [
+    'table' => 'civicrm_financial_account',
+    'keyColumn' => 'id',
+    'labelColumn' => 'name',
+  ];
 }
 
 /**
@@ -131,15 +137,6 @@ 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']]));
   try {
-    $processor->setContributionID($params['contribution_id']);
-    $processor->setInvoiceID($params['invoice_id'] ?? '');
-    if (!empty($params['contact_id'])) {
-      $processor->setContactID((int) $params['contact_id']);
-    }
-    if (!empty($params['contribution_recur_id'])) {
-      $processor->setContributionRecurID((int) $params['contribution_recur_id']);
-    }
-
     $result = $processor->doPayment($params);
   }
   catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
@@ -150,7 +147,7 @@ function civicrm_api3_payment_processor_pay($params) {
     }
     throw new API_Exception('Payment failed', $code, $errorData, $e);
   }
-  return civicrm_api3_create_success([$result], $params);
+  return civicrm_api3_create_success(array($result), $params);
 }
 
 /**