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