Update copyright date for 2020
[civicrm-core.git] / api / v3 / Contribution / Transact.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * @package CiviCRM_APIv3
30 */
31
32 /**
33 * Adjust Metadata for Transact action.
34 *
35 * The metadata is used for setting defaults, documentation & validation.
36 *
37 * @param array $params
38 * Array of parameters determined by getfields.
39 */
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';
44 }
45
46 /**
47 * Process a transaction and record it against the contact.
48 *
49 * @deprecated
50 *
51 * @param array $params
52 * Input parameters.
53 *
54 * @return array
55 * contribution of created or updated record (or a civicrm error)
56 */
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
61 // 'is_error' set
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'];
68 }
69 if (!isset($params['invoiceID']) && isset($params['invoice_id'])) {
70 $params['invoiceID'] = $params['invoice_id'];
71 }
72
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)));
75
76 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($params['payment_processor'], $params['payment_processor_mode']);
77 $paymentProcessor['object']->doPayment($params);
78
79 $params['payment_instrument_id'] = $paymentProcessor['object']->getPaymentInstrumentID();
80
81 return civicrm_api('Contribution', 'create', $params);
82 }