3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * @package CiviCRM_APIv3
33 * Adjust Metadata for Transact action.
35 * The metadata is used for setting defaults, documentation & validation.
37 * @param array $params
38 * Array of parameters determined by getfields.
40 function _civicrm_api3_contribution_transact_spec(&$params) {
41 $fields = civicrm_api3('Contribution', 'getfields', ['action' => 'create']);
42 $params = array_merge($params, $fields['values']);
43 $params['receive_date']['api.default'] = 'now';
47 * Process a transaction and record it against the contact.
51 * @param array $params
55 * contribution of created or updated record (or a civicrm error)
57 function civicrm_api3_contribution_transact($params) {
58 CRM_Core_Error
::deprecatedFunctionWarning('The contibution.transact api is unsupported & known to have issues. Please see the section at the bottom of https://docs.civicrm.org/dev/en/latest/financial/OrderAPI/ for getting off it');
59 // Set some params specific to payment processing
60 // @todo - fix this function - none of the results checked by civicrm_error would ever be an array with
62 // also trxn_id is not saved.
63 // but since there is no test it's not desirable to jump in & make the obvious changes.
64 $params['payment_processor_mode'] = empty($params['is_test']) ?
'live' : 'test';
65 $params['amount'] = $params['total_amount'];
66 if (!isset($params['net_amount'])) {
67 $params['net_amount'] = $params['amount'];
69 if (!isset($params['invoiceID']) && isset($params['invoice_id'])) {
70 $params['invoiceID'] = $params['invoice_id'];
73 // Some payment processors expect a unique invoice_id - generate one if not supplied
74 $params['invoice_id'] = CRM_Utils_Array
::value('invoice_id', $params, md5(uniqid(rand(), TRUE)));
76 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getPayment($params['payment_processor'], $params['payment_processor_mode']);
77 $paymentProcessor['object']->doPayment($params);
79 $params['payment_instrument_id'] = $paymentProcessor['object']->getPaymentInstrumentID();
81 return civicrm_api('Contribution', 'create', $params);