3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * @package CiviCRM_APIv3
17 * Adjust Metadata for Transact action.
19 * The metadata is used for setting defaults, documentation & validation.
21 * @param array $params
22 * Array of parameters determined by getfields.
24 function _civicrm_api3_contribution_transact_spec(&$params) {
25 $fields = civicrm_api3('Contribution', 'getfields', ['action' => 'create']);
26 $params = array_merge($params, $fields['values']);
27 $params['receive_date']['api.default'] = 'now';
31 * Process a transaction and record it against the contact.
35 * @param array $params
39 * contribution of created or updated record (or a civicrm error)
41 function civicrm_api3_contribution_transact($params) {
42 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');
43 // Set some params specific to payment processing
44 // @todo - fix this function - none of the results checked by civicrm_error would ever be an array with
46 // also trxn_id is not saved.
47 // but since there is no test it's not desirable to jump in & make the obvious changes.
48 $params['payment_processor_mode'] = empty($params['is_test']) ?
'live' : 'test';
49 $params['amount'] = $params['total_amount'];
50 if (!isset($params['net_amount'])) {
51 $params['net_amount'] = $params['amount'];
53 if (!isset($params['invoiceID']) && isset($params['invoice_id'])) {
54 $params['invoiceID'] = $params['invoice_id'];
57 // Some payment processors expect a unique invoice_id - generate one if not supplied
58 $params['invoice_id'] = CRM_Utils_Array
::value('invoice_id', $params, md5(uniqid(rand(), TRUE)));
60 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getPayment($params['payment_processor'], $params['payment_processor_mode']);
61 $paymentProcessor['object']->doPayment($params);
63 $params['payment_instrument_id'] = $paymentProcessor['object']->getPaymentInstrumentID();
65 return civicrm_api('Contribution', 'create', $params);