CRM-17718 update repeattransaction to permit the financial_type_id to be passed in
[civicrm-core.git] / api / v3 / Contribution.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 * This api exposes CiviCRM Contribution records.
30 *
31 * @package CiviCRM_APIv3
32 */
33
34 /**
35 * Add or update a Contribution.
36 *
37 * @param array $params
38 * Input parameters.
39 *
40 * @throws API_Exception
41 * @return array
42 * Api result array
43 */
44 function civicrm_api3_contribution_create(&$params) {
45 $values = array();
46 _civicrm_api3_custom_format_params($params, $values, 'Contribution');
47 $params = array_merge($params, $values);
48
49 if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
50 if (empty($params['id'])) {
51 $op = 'add';
52 }
53 else {
54 if (empty($params['financial_type_id'])) {
55 $params['financial_type_id'] = civicrm_api3('Contribution', 'getvalue', array(
56 'id' => $params['id'],
57 'return' => 'financial_type_id',
58 ));
59 }
60 $op = 'edit';
61 }
62 CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types, $op);
63 if (!in_array($params['financial_type_id'], array_keys($types))) {
64 return civicrm_api3_create_error('You do not have permission to create this contribution');
65 }
66 }
67 if (!empty($params['id']) && !empty($params['contribution_status_id'])) {
68 $error = array();
69 //throw error for invalid status change such as setting completed back to pending
70 //@todo this sort of validation belongs in the BAO not the API - if it is not an OK
71 // action it needs to be blocked there. If it is Ok through a form it needs to be OK through the api
72 CRM_Contribute_BAO_Contribution::checkStatusValidation(NULL, $params, $error);
73 if (array_key_exists('contribution_status_id', $error)) {
74 throw new API_Exception($error['contribution_status_id']);
75 }
76 }
77 if (!empty($params['id']) && !empty($params['financial_type_id'])) {
78 $error = array();
79 CRM_Contribute_BAO_Contribution::checkFinancialTypeChange($params['financial_type_id'], $params['id'], $error);
80 if (array_key_exists('financial_type_id', $error)) {
81 throw new API_Exception($error['financial_type_id']);
82 }
83 }
84 _civicrm_api3_contribution_create_legacy_support_45($params);
85
86 // Make sure tax calculation is handled via api.
87 $params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params);
88
89 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Contribution');
90 }
91
92 /**
93 * Adjust Metadata for Create action.
94 *
95 * The metadata is used for setting defaults, documentation & validation.
96 *
97 * @param array $params
98 * Array of parameters determined by getfields.
99 */
100 function _civicrm_api3_contribution_create_spec(&$params) {
101 $params['contact_id']['api.required'] = 1;
102 $params['total_amount']['api.required'] = 1;
103 $params['payment_instrument_id']['api.aliases'] = array('payment_instrument');
104 $params['receive_date']['api.default'] = 'now';
105 $params['payment_processor'] = array(
106 'name' => 'payment_processor',
107 'title' => 'Payment Processor ID',
108 'description' => 'ID of payment processor used for this contribution',
109 // field is called payment processor - not payment processor id but can only be one id so
110 // it seems likely someone will fix it up one day to be more consistent - lets alias it from the start
111 'api.aliases' => array('payment_processor_id'),
112 'type' => CRM_Utils_Type::T_INT,
113 );
114 $params['financial_type_id']['api.aliases'] = array('contribution_type_id', 'contribution_type');
115 $params['financial_type_id']['api.required'] = 1;
116 $params['note'] = array(
117 'name' => 'note',
118 'uniqueName' => 'contribution_note',
119 'title' => 'note',
120 'type' => 2,
121 'description' => 'Associated Note in the notes table',
122 );
123 $params['soft_credit_to'] = array(
124 'name' => 'soft_credit_to',
125 'title' => 'Soft Credit contact ID (legacy)',
126 'type' => 1,
127 'description' => 'ID of Contact to be Soft credited to (deprecated - use contribution_soft api)',
128 'FKClassName' => 'CRM_Contact_DAO_Contact',
129 );
130 $params['honor_contact_id'] = array(
131 'name' => 'honor_contact_id',
132 'title' => 'Honoree contact ID (legacy)',
133 'type' => 1,
134 'description' => 'ID of honoree contact (deprecated - use contribution_soft api)',
135 'FKClassName' => 'CRM_Contact_DAO_Contact',
136 );
137 $params['honor_type_id'] = array(
138 'name' => 'honor_type_id',
139 'title' => 'Honoree Type (legacy)',
140 'type' => 1,
141 'description' => 'Type of honoree contact (deprecated - use contribution_soft api)',
142 'pseudoconstant' => TRUE,
143 );
144 // note this is a recommended option but not adding as a default to avoid
145 // creating unnecessary changes for the dev
146 $params['skipRecentView'] = array(
147 'name' => 'skipRecentView',
148 'title' => 'Skip adding to recent view',
149 'type' => CRM_Utils_Type::T_BOOLEAN,
150 'description' => 'Do not add to recent view (setting this improves performance)',
151 );
152 $params['skipLineItem'] = array(
153 'name' => 'skipLineItem',
154 'title' => 'Skip adding line items',
155 'type' => CRM_Utils_Type::T_BOOLEAN,
156 'api.default' => 0,
157 'description' => 'Do not add line items by default (if you wish to add your own)',
158 );
159 $params['batch_id'] = array(
160 'title' => 'Batch',
161 'type' => 1,
162 'description' => 'Batch which relevant transactions should be added to',
163 );
164 }
165
166 /**
167 * Support for schema changes made in 4.5.
168 *
169 * The main purpose of the API is to provide integrators a level of stability not provided by
170 * the core code or schema - this means we have to provide support for api calls (where possible)
171 * across schema changes.
172 *
173 * @param array $params
174 */
175 function _civicrm_api3_contribution_create_legacy_support_45(&$params) {
176 //legacy soft credit handling - recommended approach is chaining
177 if (!empty($params['soft_credit_to'])) {
178 $params['soft_credit'][] = array(
179 'contact_id' => $params['soft_credit_to'],
180 'amount' => $params['total_amount'],
181 'soft_credit_type_id' => CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"),
182 );
183 }
184 if (!empty($params['honor_contact_id'])) {
185 $params['soft_credit'][] = array(
186 'contact_id' => $params['honor_contact_id'],
187 'amount' => $params['total_amount'],
188 'soft_credit_type_id' => CRM_Utils_Array::value('honor_type_id', $params, CRM_Core_OptionGroup::getValue('soft_credit_type', 'in_honor_of', 'name')),
189 );
190 }
191 }
192
193 /**
194 * Delete a Contribution.
195 *
196 * @param array $params
197 * Input parameters.
198 *
199 * @return array
200 */
201 function civicrm_api3_contribution_delete($params) {
202
203 $contributionID = !empty($params['contribution_id']) ? $params['contribution_id'] : $params['id'];
204 // First check contribution financial type
205 $financialType = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionID, 'financial_type_id');
206 // Now check permissioned lineitems & permissioned contribution
207 if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
208 && !CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($financialType)) ||
209 !CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($contributionID, 'delete', FALSE)
210 ) {
211 return civicrm_api3_create_error('You do not have permission to delete this contribution');
212 }
213 if (CRM_Contribute_BAO_Contribution::deleteContribution($contributionID)) {
214 return civicrm_api3_create_success(array($contributionID => 1));
215 }
216 else {
217 return civicrm_api3_create_error('Could not delete contribution');
218 }
219 }
220
221 /**
222 * Modify metadata for delete action.
223 *
224 * Legacy support for contribution_id.
225 *
226 * @param array $params
227 */
228 function _civicrm_api3_contribution_delete_spec(&$params) {
229 $params['id']['api.aliases'] = array('contribution_id');
230 }
231
232 /**
233 * Retrieve a set of contributions.
234 *
235 * @param array $params
236 * Input parameters.
237 *
238 * @return array
239 * Array of contributions, if error an array with an error id and error message
240 */
241 function civicrm_api3_contribution_get($params) {
242
243 $mode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE;
244 $returnProperties = CRM_Contribute_BAO_Query::defaultReturnProperties($mode);
245
246 $contributions = _civicrm_api3_get_using_query_object('Contribution', $params, array(), NULL, $mode, $returnProperties);
247
248 foreach ($contributions as $id => $contribution) {
249 $softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($id, TRUE);
250 $contributions[$id] = array_merge($contribution, $softContribution);
251 // format soft credit for backward compatibility
252 _civicrm_api3_format_soft_credit($contributions[$id]);
253 }
254 return civicrm_api3_create_success($contributions, $params, 'Contribution', 'get');
255 }
256
257 /**
258 * Get number of contacts matching the supplied criteria.
259 *
260 * @param array $params
261 *
262 * @return int
263 */
264 function civicrm_api3_contribution_getcount($params) {
265 $count = _civicrm_api3_get_using_query_object('Contribution', $params, array(), TRUE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE);
266 return (int) $count;
267 }
268
269 /**
270 * This function is used to format the soft credit for backward compatibility.
271 *
272 * As of v4.4 we support multiple soft credit, so now contribution returns array with 'soft_credit' as key
273 * but we still return first soft credit as a part of contribution array
274 *
275 * @param $contribution
276 */
277 function _civicrm_api3_format_soft_credit(&$contribution) {
278 if (!empty($contribution['soft_credit'])) {
279 $contribution['soft_credit_to'] = $contribution['soft_credit'][1]['contact_id'];
280 $contribution['soft_credit_id'] = $contribution['soft_credit'][1]['soft_credit_id'];
281 }
282 }
283
284 /**
285 * Adjust Metadata for Get action.
286 *
287 * The metadata is used for setting defaults, documentation & validation.
288 *
289 * @param array $params
290 * Array of parameters determined by getfields.
291 */
292 function _civicrm_api3_contribution_get_spec(&$params) {
293 $params['contribution_test'] = array(
294 'api.default' => 0,
295 'type' => CRM_Utils_Type::T_BOOLEAN,
296 'title' => 'Get Test Contributions?',
297 'api.aliases' => array('is_test'),
298 );
299
300 $params['financial_type_id']['api.aliases'] = array('contribution_type_id');
301 $params['payment_instrument_id']['api.aliases'] = array('contribution_payment_instrument', 'payment_instrument');
302 $params['contact_id'] = $params['contribution_contact_id'];
303 $params['contact_id']['api.aliases'] = array('contribution_contact_id');
304 unset($params['contribution_contact_id']);
305 }
306
307 /**
308 * Legacy handling for contribution parameters.
309 *
310 * Take the input parameter list as specified in the data model and
311 * convert it into the same format that we use in QF and BAO object.
312 *
313 * @param array $params
314 * property name/value pairs to insert in new contact.
315 * @param array $values
316 * The reformatted properties that we can use internally.
317 *
318 * @return array
319 */
320 function _civicrm_api3_contribute_format_params($params, &$values) {
321 //legacy way of formatting from v2 api - v3 way is to define metadata & do it in the api layer
322 _civicrm_api3_filter_fields_for_bao('Contribution', $params, $values);
323 return array();
324 }
325
326 /**
327 * Adjust Metadata for Transact action.
328 *
329 * The metadata is used for setting defaults, documentation & validation.
330 *
331 * @param array $params
332 * Array of parameters determined by getfields.
333 */
334 function _civicrm_api3_contribution_transact_spec(&$params) {
335 $fields = civicrm_api3('Contribution', 'getfields', array('action' => 'create'));
336 $params = array_merge($params, $fields['values']);
337 $params['receive_date']['api.default'] = 'now';
338 }
339
340 /**
341 * Process a transaction and record it against the contact.
342 *
343 * @param array $params
344 * Input parameters.
345 *
346 * @return array
347 * contribution of created or updated record (or a civicrm error)
348 */
349 function civicrm_api3_contribution_transact($params) {
350 // Set some params specific to payment processing
351 // @todo - fix this function - none of the results checked by civicrm_error would ever be an array with
352 // 'is_error' set
353 // also trxn_id is not saved.
354 // but since there is no test it's not desirable to jump in & make the obvious changes.
355 $params['payment_processor_mode'] = empty($params['is_test']) ? 'live' : 'test';
356 $params['amount'] = $params['total_amount'];
357 if (!isset($params['net_amount'])) {
358 $params['net_amount'] = $params['amount'];
359 }
360 if (!isset($params['invoiceID']) && isset($params['invoice_id'])) {
361 $params['invoiceID'] = $params['invoice_id'];
362 }
363
364 // Some payment processors expect a unique invoice_id - generate one if not supplied
365 $params['invoice_id'] = CRM_Utils_Array::value('invoice_id', $params, md5(uniqid(rand(), TRUE)));
366
367 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($params['payment_processor'], $params['payment_processor_mode']);
368 $paymentProcessor['object']->doPayment($params);
369
370 $params['payment_instrument_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType', $paymentProcessor['payment_processor_type_id'], 'payment_type') == 1 ? 'Credit Card' : 'Debit Card';
371 return civicrm_api('Contribution', 'create', $params);
372 }
373
374 /**
375 * Send a contribution confirmation (receipt or invoice).
376 *
377 * The appropriate online template will be used (the existence of related objects
378 * (e.g. memberships ) will affect this selection
379 *
380 * @param array $params
381 * Input parameters.
382 *
383 * @throws Exception
384 */
385 function civicrm_api3_contribution_sendconfirmation($params) {
386 $contribution = new CRM_Contribute_BAO_Contribution();
387 $contribution->id = $params['id'];
388 if (!$contribution->find(TRUE)) {
389 throw new Exception('Contribution does not exist');
390 }
391 $input = $ids = $cvalues = array('receipt_from_email' => $params['receipt_from_email']);
392 $contribution->loadRelatedObjects($input, $ids, TRUE);
393 $contribution->composeMessageArray($input, $ids, $cvalues, FALSE, FALSE);
394 }
395
396 /**
397 * Adjust Metadata for sendconfirmation action.
398 *
399 * The metadata is used for setting defaults, documentation & validation.
400 *
401 * @param array $params
402 * Array of parameters determined by getfields.
403 */
404 function _civicrm_api3_contribution_sendconfirmation_spec(&$params) {
405 $params['id'] = array(
406 'api.required' => 1,
407 'title' => 'Contribution ID',
408 'type' => CRM_Utils_Type::T_INT,
409 );
410 $params['receipt_from_email'] = array(
411 'api.required' => 1,
412 'title' => 'From Email address (string) required until someone provides a patch :-)',
413 'type' => CRM_Utils_Type::T_STRING,
414 );
415 $params['receipt_from_name'] = array(
416 'title' => 'From Name (string)',
417 'type' => CRM_Utils_Type::T_STRING,
418 );
419 $params['cc_receipt'] = array(
420 'title' => 'CC Email address (string)',
421 'type' => CRM_Utils_Type::T_STRING,
422 );
423 $params['bcc_receipt'] = array(
424 'title' => 'BCC Email address (string)',
425 'type' => CRM_Utils_Type::T_STRING,
426 );
427 $params['receipt_text'] = array(
428 'title' => 'Message (string)',
429 'type' => CRM_Utils_Type::T_STRING,
430 );
431 }
432
433 /**
434 * Complete an existing (pending) transaction.
435 *
436 * This will update related entities (participant, membership, pledge etc)
437 * and take any complete actions from the contribution page (e.g. send receipt).
438 *
439 * @todo - most of this should live in the BAO layer but as we want it to be an addition
440 * to 4.3 which is already stable we should add it to the api layer & re-factor into the BAO layer later
441 *
442 * @param array $params
443 * Input parameters.
444 *
445 * @throws API_Exception
446 * Api result array.
447 */
448 function civicrm_api3_contribution_completetransaction(&$params) {
449
450 $input = $ids = array();
451 if (isset($params['payment_processor_id'])) {
452 $input['payment_processor_id'] = $params['payment_processor_id'];
453 }
454 $contribution = new CRM_Contribute_BAO_Contribution();
455 $contribution->id = $params['id'];
456 $contribution->find(TRUE);
457 if (!$contribution->id == $params['id']) {
458 throw new API_Exception('A valid contribution ID is required', 'invalid_data');
459 }
460
461 if (!$contribution->loadRelatedObjects($input, $ids, TRUE)) {
462 throw new API_Exception('failed to load related objects');
463 }
464 elseif ($contribution->contribution_status_id == CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name')) {
465 throw new API_Exception(ts('Contribution already completed'), 'contribution_completed');
466 }
467 $input['trxn_id'] = !empty($params['trxn_id']) ? $params['trxn_id'] : $contribution->trxn_id;
468 if (!empty($params['fee_amount'])) {
469 $input['fee_amount'] = $params['fee_amount'];
470 }
471 $params = _ipn_process_transaction($params, $contribution, $input, $ids);
472
473 }
474
475 /**
476 * Provide function metadata.
477 *
478 * @param array $params
479 */
480 function _civicrm_api3_contribution_completetransaction_spec(&$params) {
481 $params['id'] = array(
482 'title' => 'Contribution ID',
483 'type' => CRM_Utils_Type::T_INT,
484 'api.required' => TRUE,
485 );
486 $params['trxn_id'] = array(
487 'title' => 'Transaction ID',
488 'type' => CRM_Utils_Type::T_STRING,
489 );
490 $params['is_email_receipt'] = array(
491 'title' => 'Send email Receipt?',
492 'type' => CRM_Utils_Type::T_BOOLEAN,
493 );
494 $params['receipt_from_email'] = array(
495 'title' => 'Email to send receipt from.',
496 'description' => 'If not provided this will default to being based on domain mail or contribution page',
497 'type' => CRM_Utils_Type::T_EMAIL,
498 );
499 $params['receipt_from_name'] = array(
500 'title' => 'Name to send receipt from',
501 'description' => '. If not provided this will default to domain mail or contribution page',
502 'type' => CRM_Utils_Type::T_STRING,
503 );
504 $params['payment_processor_id'] = array(
505 'title' => 'Payment processor ID',
506 'description' => 'Providing this is strongly recommended, as not possible to calculate it accurately always',
507 'type' => CRM_Utils_Type::T_INT,
508 );
509 $params['fee_amount'] = array(
510 'title' => 'Fee charged on transaction',
511 'description' => 'If a fee has been charged then the amount',
512 'type' => CRM_Utils_Type::T_FLOAT,
513 );
514 $params['trxn_date'] = array(
515 'title' => 'Transaction Date',
516 'description' => 'Date this transaction occurred',
517 'type' => CRM_Utils_Type::T_DATE,
518 );
519 }
520
521 /**
522 * Complete an existing (pending) transaction.
523 *
524 * This will update related entities (participant, membership, pledge etc)
525 * and take any complete actions from the contribution page (e.g. send receipt).
526 *
527 * @todo - most of this should live in the BAO layer but as we want it to be an addition
528 * to 4.3 which is already stable we should add it to the api layer & re-factor into the BAO layer later
529 *
530 * @param array $params
531 * Input parameters.
532 *
533 * @throws API_Exception
534 * Api result array.
535 */
536 function civicrm_api3_contribution_repeattransaction(&$params) {
537 $input = $ids = array();
538 civicrm_api3_verify_one_mandatory($params, NULL, array('contribution_recur_id', 'original_contribution_id'));
539 if (empty($params['original_contribution_id'])) {
540 $params['original_contribution_id'] = civicrm_api3('contribution', 'getvalue', array(
541 'return' => 'id',
542 'contribution_recur_id' => $params['contribution_recur_id'],
543 'options' => array('limit' => 1, 'sort' => 'id DESC'),
544 ));
545 }
546 $contribution = new CRM_Contribute_BAO_Contribution();
547 $contribution->id = $params['original_contribution_id'];
548 if (!$contribution->find(TRUE)) {
549 throw new API_Exception(
550 'A valid original contribution ID is required', 'invalid_data');
551 }
552 $original_contribution = clone $contribution;
553 try {
554 if (!$contribution->loadRelatedObjects($input, $ids, TRUE)) {
555 throw new API_Exception('failed to load related objects');
556 }
557
558 unset($contribution->id, $contribution->receive_date, $contribution->invoice_id);
559 $contribution->contribution_status_id = $params['contribution_status_id'];
560 $contribution->receive_date = $params['receive_date'];
561
562 $passThroughParams = array('trxn_id', 'total_amount', 'campaign_id', 'fee_amount', 'financial_type_id');
563 $input = array_intersect_key($params, array_fill_keys($passThroughParams, NULL));
564
565 $params = _ipn_process_transaction($params, $contribution, $input, $ids, $original_contribution);
566 }
567 catch(Exception $e) {
568 throw new API_Exception('failed to load related objects' . $e->getMessage() . "\n" . $e->getTraceAsString());
569 }
570 }
571
572 /**
573 * Calls IPN complete transaction for completing or repeating a transaction.
574 *
575 * The IPN function is overloaded with two purposes - this is simply a wrapper for that
576 * when separating them in the api layer.
577 *
578 * @param array $params
579 * @param CRM_Contribute_BAO_Contribution $contribution
580 * @param array $input
581 *
582 * @param array $ids
583 *
584 * @param CRM_Contribute_BAO_Contribution $firstContribution
585 *
586 * @return mixed
587 */
588 function _ipn_process_transaction(&$params, $contribution, $input, $ids, $firstContribution = NULL) {
589 $objects = $contribution->_relatedObjects;
590 $objects['contribution'] = &$contribution;
591
592 if ($firstContribution) {
593 $objects['first_contribution'] = $firstContribution;
594 }
595 $input['component'] = $contribution->_component;
596 $input['is_test'] = $contribution->is_test;
597 $input['amount'] = empty($input['total_amount']) ? $contribution->total_amount : $input['total_amount'];
598
599 if (isset($params['is_email_receipt'])) {
600 $input['is_email_receipt'] = $params['is_email_receipt'];
601 }
602 if (!empty($params['trxn_date'])) {
603 $input['trxn_date'] = $params['trxn_date'];
604 }
605 if (empty($contribution->contribution_page_id)) {
606 static $domainFromName;
607 static $domainFromEmail;
608 if (empty($domainFromEmail) && (empty($params['receipt_from_name']) || empty($params['receipt_from_email']))) {
609 list($domainFromName, $domainFromEmail) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
610 }
611 $input['receipt_from_name'] = CRM_Utils_Array::value('receipt_from_name', $params, $domainFromName);
612 $input['receipt_from_email'] = CRM_Utils_Array::value('receipt_from_email', $params, $domainFromEmail);
613 }
614 $transaction = new CRM_Core_Transaction();
615 CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects, $transaction, !empty($contribution->contribution_recur_id), $contribution,
616 FALSE, FALSE);
617 return $params;
618 }
619
620 /**
621 * Provide function metadata.
622 *
623 * @param array $params
624 */
625 function _civicrm_api3_contribution_repeattransaction_spec(&$params) {
626 $params['original_contribution_id'] = array(
627 'title' => 'Original Contribution ID',
628 'description' => 'Contribution ID to copy (will be calculated from recurring contribution if not provided)',
629 'type' => CRM_Utils_Type::T_INT,
630 );
631 $params['contribution_recur_id'] = array(
632 'title' => 'Recurring contribution ID',
633 'type' => CRM_Utils_Type::T_INT,
634 );
635 $params['trxn_id'] = array(
636 'title' => 'Transaction ID',
637 'type' => CRM_Utils_Type::T_STRING,
638 );
639 $params['is_email_receipt'] = array(
640 'title' => 'Send email Receipt?',
641 'type' => CRM_Utils_Type::T_BOOLEAN,
642 );
643 $params['contribution_status_id'] = array(
644 'title' => 'Contribution Status ID',
645 'name' => 'contribution_status_id',
646 'type' => CRM_Utils_Type::T_INT,
647 'pseudoconstant' => array(
648 'optionGroupName' => 'contribution_status',
649 ),
650 'api.required' => TRUE,
651 );
652 $params['receive_date'] = array(
653 'title' => 'Contribution Receive Date',
654 'name' => 'receive_date',
655 'type' => CRM_Utils_Type::T_DATE,
656 'api.default' => 'now',
657 );
658 $params['trxn_id'] = array(
659 'title' => 'Transaction ID',
660 'name' => 'trxn_id',
661 'type' => CRM_Utils_Type::T_STRING,
662 );
663 $params['campaign_id'] = array(
664 'title' => 'Campaign ID',
665 'name' => 'campaign_id',
666 'type' => CRM_Utils_Type::T_INT,
667 'pseudoconstant' => array(
668 'table' => 'civicrm_campaign',
669 'keyColumn' => 'id',
670 'labelColumn' => 'title',
671 ),
672 );
673 $params['financial_type_id'] = array(
674 'title' => 'Financial ID (ignored if more than one line item)',
675 'name' => 'financial_type_id',
676 'type' => CRM_Utils_Type::T_INT,
677 'pseudoconstant' => array(
678 'table' => 'civicrm_financial_type',
679 'keyColumn' => 'id',
680 'labelColumn' => 'name',
681 ),
682 );
683 $params['payment_processor_id'] = array(
684 'description' => ts('Payment processor ID, will be loaded from contribution_recur if not provided'),
685 'title' => 'Payment processor ID',
686 'name' => 'payment_processor_id',
687 'type' => CRM_Utils_Type::T_INT,
688 );
689 }