Merge in 5.20
[civicrm-core.git] / api / v3 / Contribution / Transact.php
CommitLineData
bdf636a3
MWMC
1<?php
2/*
3 +--------------------------------------------------------------------+
a30c801b 4 | Copyright CiviCRM LLC. All rights reserved. |
bdf636a3 5 | |
a30c801b
TO
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 |
bdf636a3
MWMC
9 +--------------------------------------------------------------------+
10 */
11
12/**
13 * @package CiviCRM_APIv3
14 */
15
16/**
17 * Adjust Metadata for Transact action.
18 *
19 * The metadata is used for setting defaults, documentation & validation.
20 *
21 * @param array $params
22 * Array of parameters determined by getfields.
23 */
24function _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';
28}
29
30/**
31 * Process a transaction and record it against the contact.
32 *
647143dc 33 * @deprecated
34 *
bdf636a3
MWMC
35 * @param array $params
36 * Input parameters.
37 *
38 * @return array
39 * contribution of created or updated record (or a civicrm error)
40 */
41function civicrm_api3_contribution_transact($params) {
647143dc 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');
bdf636a3
MWMC
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
45 // 'is_error' set
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'];
52 }
53 if (!isset($params['invoiceID']) && isset($params['invoice_id'])) {
54 $params['invoiceID'] = $params['invoice_id'];
55 }
56
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)));
59
60 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($params['payment_processor'], $params['payment_processor_mode']);
61 $paymentProcessor['object']->doPayment($params);
62
63 $params['payment_instrument_id'] = $paymentProcessor['object']->getPaymentInstrumentID();
64
65 return civicrm_api('Contribution', 'create', $params);
66}