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