Merge pull request #8119 from eileenmcnaughton/CRM-18303
[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 $input = $ids = $values = array();
390 $passThroughParams = array(
391 'receipt_from_email',
392 'receipt_from_name',
393 'receipt_update',
394 'cc_receipt',
395 'bcc_receipt',
396 'receipt_text',
397 'payment_processor_id',
398 );
399 foreach ($passThroughParams as $key) {
400 if (isset($params[$key])) {
401 $input[$key] = $params[$key];
402 }
403 }
404 CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $params['id'], $values);
405 }
406
407 /**
408 * Adjust Metadata for sendconfirmation action.
409 *
410 * The metadata is used for setting defaults, documentation & validation.
411 *
412 * @param array $params
413 * Array of parameters determined by getfields.
414 */
415 function _civicrm_api3_contribution_sendconfirmation_spec(&$params) {
416 $params['id'] = array(
417 'api.required' => 1,
418 'title' => ts('Contribution ID'),
419 'type' => CRM_Utils_Type::T_INT,
420 );
421 $params['receipt_from_email'] = array(
422 'title' => ts('From Email address (string)'),
423 'type' => CRM_Utils_Type::T_STRING,
424 );
425 $params['receipt_from_name'] = array(
426 'title' => ts('From Name (string)'),
427 'type' => CRM_Utils_Type::T_STRING,
428 );
429 $params['cc_receipt'] = array(
430 'title' => ts('CC Email address (string)'),
431 'type' => CRM_Utils_Type::T_STRING,
432 );
433 $params['bcc_receipt'] = array(
434 'title' => ts('BCC Email address (string)'),
435 'type' => CRM_Utils_Type::T_STRING,
436 );
437 $params['receipt_text'] = array(
438 'title' => ts('Message (string)'),
439 'type' => CRM_Utils_Type::T_STRING,
440 );
441 $params['receipt_update'] = array(
442 'title' => ts('Update the Receipt Date'),
443 'type' => CRM_Utils_Type::T_BOOLEAN,
444 'api.default' => TRUE,
445 );
446 $params['payment_processor_id'] = array(
447 'title' => ts('Payment processor Id (avoids mis-guesses)'),
448 'type' => CRM_Utils_Type::T_INT,
449 );
450 }
451
452 /**
453 * Complete an existing (pending) transaction.
454 *
455 * This will update related entities (participant, membership, pledge etc)
456 * and take any complete actions from the contribution page (e.g. send receipt).
457 *
458 * @todo - most of this should live in the BAO layer but as we want it to be an addition
459 * to 4.3 which is already stable we should add it to the api layer & re-factor into the BAO layer later
460 *
461 * @param array $params
462 * Input parameters.
463 *
464 * @return array
465 * API result array
466 * @throws \API_Exception
467 * @throws \CRM_Core_Exception
468 * @throws \Exception
469 */
470 function civicrm_api3_contribution_completetransaction(&$params) {
471
472 $input = $ids = array();
473 if (isset($params['payment_processor_id'])) {
474 $input['payment_processor_id'] = $params['payment_processor_id'];
475 }
476 $contribution = new CRM_Contribute_BAO_Contribution();
477 $contribution->id = $params['id'];
478 $contribution->find(TRUE);
479 if (!$contribution->id == $params['id']) {
480 throw new API_Exception('A valid contribution ID is required', 'invalid_data');
481 }
482
483 if (!$contribution->loadRelatedObjects($input, $ids, TRUE)) {
484 throw new API_Exception('failed to load related objects');
485 }
486 elseif ($contribution->contribution_status_id == CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name')) {
487 throw new API_Exception(ts('Contribution already completed'), 'contribution_completed');
488 }
489 $input['trxn_id'] = !empty($params['trxn_id']) ? $params['trxn_id'] : $contribution->trxn_id;
490 if (!empty($params['fee_amount'])) {
491 $input['fee_amount'] = $params['fee_amount'];
492 }
493 return _ipn_process_transaction($params, $contribution, $input, $ids);
494
495 }
496
497 /**
498 * Provide function metadata.
499 *
500 * @param array $params
501 */
502 function _civicrm_api3_contribution_completetransaction_spec(&$params) {
503 $params['id'] = array(
504 'title' => 'Contribution ID',
505 'type' => CRM_Utils_Type::T_INT,
506 'api.required' => TRUE,
507 );
508 $params['trxn_id'] = array(
509 'title' => 'Transaction ID',
510 'type' => CRM_Utils_Type::T_STRING,
511 );
512 $params['is_email_receipt'] = array(
513 'title' => 'Send email Receipt?',
514 'type' => CRM_Utils_Type::T_BOOLEAN,
515 );
516 $params['receipt_from_email'] = array(
517 'title' => 'Email to send receipt from.',
518 'description' => 'If not provided this will default to being based on domain mail or contribution page',
519 'type' => CRM_Utils_Type::T_EMAIL,
520 );
521 $params['receipt_from_name'] = array(
522 'title' => 'Name to send receipt from',
523 'description' => '. If not provided this will default to domain mail or contribution page',
524 'type' => CRM_Utils_Type::T_STRING,
525 );
526 $params['payment_processor_id'] = array(
527 'title' => 'Payment processor ID',
528 'description' => 'Providing this is strongly recommended, as not possible to calculate it accurately always',
529 'type' => CRM_Utils_Type::T_INT,
530 );
531 $params['fee_amount'] = array(
532 'title' => 'Fee charged on transaction',
533 'description' => 'If a fee has been charged then the amount',
534 'type' => CRM_Utils_Type::T_FLOAT,
535 );
536 $params['trxn_date'] = array(
537 'title' => 'Transaction Date',
538 'description' => 'Date this transaction occurred',
539 'type' => CRM_Utils_Type::T_DATE,
540 );
541 }
542
543 /**
544 * Complete an existing (pending) transaction.
545 *
546 * This will update related entities (participant, membership, pledge etc)
547 * and take any complete actions from the contribution page (e.g. send receipt).
548 *
549 * @todo - most of this should live in the BAO layer but as we want it to be an addition
550 * to 4.3 which is already stable we should add it to the api layer & re-factor into the BAO layer later
551 *
552 * @param array $params
553 * Input parameters.
554 *
555 * @throws API_Exception
556 * Api result array.
557 */
558 function civicrm_api3_contribution_repeattransaction(&$params) {
559 $input = $ids = array();
560 civicrm_api3_verify_one_mandatory($params, NULL, array('contribution_recur_id', 'original_contribution_id'));
561 if (empty($params['original_contribution_id'])) {
562 $params['original_contribution_id'] = civicrm_api3('contribution', 'getvalue', array(
563 'return' => 'id',
564 'contribution_recur_id' => $params['contribution_recur_id'],
565 'options' => array('limit' => 1, 'sort' => 'id DESC'),
566 ));
567 }
568 $contribution = new CRM_Contribute_BAO_Contribution();
569 $contribution->id = $params['original_contribution_id'];
570 if (!$contribution->find(TRUE)) {
571 throw new API_Exception(
572 'A valid original contribution ID is required', 'invalid_data');
573 }
574 $original_contribution = clone $contribution;
575 try {
576 if (!$contribution->loadRelatedObjects($input, $ids, TRUE)) {
577 throw new API_Exception('failed to load related objects');
578 }
579
580 unset($contribution->id, $contribution->receive_date, $contribution->invoice_id);
581 $contribution->receive_date = $params['receive_date'];
582
583 $passThroughParams = array(
584 'trxn_id',
585 'total_amount',
586 'campaign_id',
587 'fee_amount',
588 'financial_type_id',
589 'contribution_status_id',
590 );
591 $input = array_intersect_key($params, array_fill_keys($passThroughParams, NULL));
592
593 return _ipn_process_transaction($params, $contribution, $input, $ids, $original_contribution);
594 }
595 catch(Exception $e) {
596 throw new API_Exception('failed to load related objects' . $e->getMessage() . "\n" . $e->getTraceAsString());
597 }
598 }
599
600 /**
601 * Calls IPN complete transaction for completing or repeating a transaction.
602 *
603 * The IPN function is overloaded with two purposes - this is simply a wrapper for that
604 * when separating them in the api layer.
605 *
606 * @param array $params
607 * @param CRM_Contribute_BAO_Contribution $contribution
608 * @param array $input
609 *
610 * @param array $ids
611 *
612 * @param CRM_Contribute_BAO_Contribution $firstContribution
613 *
614 * @return mixed
615 */
616 function _ipn_process_transaction(&$params, $contribution, $input, $ids, $firstContribution = NULL) {
617 $objects = $contribution->_relatedObjects;
618 $objects['contribution'] = &$contribution;
619
620 if ($firstContribution) {
621 $objects['first_contribution'] = $firstContribution;
622 }
623 $input['component'] = $contribution->_component;
624 $input['is_test'] = $contribution->is_test;
625 $input['amount'] = empty($input['total_amount']) ? $contribution->total_amount : $input['total_amount'];
626
627 if (isset($params['is_email_receipt'])) {
628 $input['is_email_receipt'] = $params['is_email_receipt'];
629 }
630 if (!empty($params['trxn_date'])) {
631 $input['trxn_date'] = $params['trxn_date'];
632 }
633 if (empty($contribution->contribution_page_id)) {
634 static $domainFromName;
635 static $domainFromEmail;
636 if (empty($domainFromEmail) && (empty($params['receipt_from_name']) || empty($params['receipt_from_email']))) {
637 list($domainFromName, $domainFromEmail) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
638 }
639 $input['receipt_from_name'] = CRM_Utils_Array::value('receipt_from_name', $params, $domainFromName);
640 $input['receipt_from_email'] = CRM_Utils_Array::value('receipt_from_email', $params, $domainFromEmail);
641 }
642 $transaction = new CRM_Core_Transaction();
643 return CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects, $transaction, !empty
644 ($contribution->contribution_recur_id), $contribution,
645 FALSE, FALSE);
646 }
647
648 /**
649 * Provide function metadata.
650 *
651 * @param array $params
652 */
653 function _civicrm_api3_contribution_repeattransaction_spec(&$params) {
654 $params['original_contribution_id'] = array(
655 'title' => 'Original Contribution ID',
656 'description' => 'Contribution ID to copy (will be calculated from recurring contribution if not provided)',
657 'type' => CRM_Utils_Type::T_INT,
658 );
659 $params['contribution_recur_id'] = array(
660 'title' => 'Recurring contribution ID',
661 'type' => CRM_Utils_Type::T_INT,
662 );
663 $params['trxn_id'] = array(
664 'title' => 'Transaction ID',
665 'type' => CRM_Utils_Type::T_STRING,
666 );
667 $params['is_email_receipt'] = array(
668 'title' => 'Send email Receipt?',
669 'type' => CRM_Utils_Type::T_BOOLEAN,
670 );
671 $params['contribution_status_id'] = array(
672 'title' => 'Contribution Status ID',
673 'name' => 'contribution_status_id',
674 'type' => CRM_Utils_Type::T_INT,
675 'pseudoconstant' => array(
676 'optionGroupName' => 'contribution_status',
677 ),
678 'api.required' => TRUE,
679 );
680 $params['receive_date'] = array(
681 'title' => 'Contribution Receive Date',
682 'name' => 'receive_date',
683 'type' => CRM_Utils_Type::T_DATE,
684 'api.default' => 'now',
685 );
686 $params['trxn_id'] = array(
687 'title' => 'Transaction ID',
688 'name' => 'trxn_id',
689 'type' => CRM_Utils_Type::T_STRING,
690 );
691 $params['campaign_id'] = array(
692 'title' => 'Campaign ID',
693 'name' => 'campaign_id',
694 'type' => CRM_Utils_Type::T_INT,
695 'pseudoconstant' => array(
696 'table' => 'civicrm_campaign',
697 'keyColumn' => 'id',
698 'labelColumn' => 'title',
699 ),
700 );
701 $params['financial_type_id'] = array(
702 'title' => 'Financial ID (ignored if more than one line item)',
703 'name' => 'financial_type_id',
704 'type' => CRM_Utils_Type::T_INT,
705 'pseudoconstant' => array(
706 'table' => 'civicrm_financial_type',
707 'keyColumn' => 'id',
708 'labelColumn' => 'name',
709 ),
710 );
711 $params['payment_processor_id'] = array(
712 'description' => ts('Payment processor ID, will be loaded from contribution_recur if not provided'),
713 'title' => 'Payment processor ID',
714 'name' => 'payment_processor_id',
715 'type' => CRM_Utils_Type::T_INT,
716 );
717 }