3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * This api exposes CiviCRM Contribution records.
31 * @package CiviCRM_APIv3
35 * Add or update a Contribution.
37 * @param array $params
40 * @throws API_Exception
44 function civicrm_api3_contribution_create(&$params) {
46 _civicrm_api3_custom_format_params($params, $values, 'Contribution');
47 $params = array_merge($params, $values);
48 // The BAO should not clean money - it should be done in the form layer & api wrapper
49 // (although arguably the api should expect pre-cleaned it seems to do some cleaning.)
50 if (empty($params['skipCleanMoney'])) {
51 foreach (['total_amount', 'net_amount', 'fee_amount'] as $field) {
52 if (isset($params[$field])) {
53 $params[$field] = CRM_Utils_Rule
::cleanMoney($params[$field]);
57 $params['skipCleanMoney'] = TRUE;
59 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus()) {
60 if (empty($params['id'])) {
61 $op = CRM_Core_Action
::ADD
;
64 if (empty($params['financial_type_id'])) {
65 $params['financial_type_id'] = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution', $params['id'], 'financial_type_id');
67 $op = CRM_Core_Action
::UPDATE
;
69 CRM_Financial_BAO_FinancialType
::getAvailableFinancialTypes($types, $op);
70 if (!in_array($params['financial_type_id'], array_keys($types))) {
71 return civicrm_api3_create_error('You do not have permission to create this contribution');
74 if (!empty($params['id']) && !empty($params['contribution_status_id'])) {
76 //throw error for invalid status change such as setting completed back to pending
77 //@todo this sort of validation belongs in the BAO not the API - if it is not an OK
78 // action it needs to be blocked there. If it is Ok through a form it needs to be OK through the api
79 CRM_Contribute_BAO_Contribution
::checkStatusValidation(NULL, $params, $error);
80 if (array_key_exists('contribution_status_id', $error)) {
81 throw new API_Exception($error['contribution_status_id']);
84 if (!empty($params['id']) && !empty($params['financial_type_id'])) {
86 CRM_Contribute_BAO_Contribution
::checkFinancialTypeChange($params['financial_type_id'], $params['id'], $error);
87 if (array_key_exists('financial_type_id', $error)) {
88 throw new API_Exception($error['financial_type_id']);
91 _civicrm_api3_contribution_create_legacy_support_45($params);
93 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params, 'Contribution');
97 * Adjust Metadata for Create action.
99 * The metadata is used for setting defaults, documentation & validation.
101 * @param array $params
102 * Array of parameters determined by getfields.
104 function _civicrm_api3_contribution_create_spec(&$params) {
105 $params['contact_id']['api.required'] = 1;
106 $params['total_amount']['api.required'] = 1;
107 $params['payment_instrument_id']['api.aliases'] = array('payment_instrument');
108 $params['receive_date']['api.default'] = 'now';
109 $params['payment_processor'] = array(
110 'name' => 'payment_processor',
111 'title' => 'Payment Processor ID',
112 'description' => 'ID of payment processor used for this contribution',
113 // field is called payment processor - not payment processor id but can only be one id so
114 // it seems likely someone will fix it up one day to be more consistent - lets alias it from the start
115 'api.aliases' => array('payment_processor_id'),
116 'type' => CRM_Utils_Type
::T_INT
,
118 $params['financial_type_id']['api.aliases'] = array('contribution_type_id', 'contribution_type');
119 $params['financial_type_id']['api.required'] = 1;
120 $params['note'] = array(
122 'uniqueName' => 'contribution_note',
125 'description' => 'Associated Note in the notes table',
127 $params['soft_credit_to'] = array(
128 'name' => 'soft_credit_to',
129 'title' => 'Soft Credit contact ID (legacy)',
130 'type' => CRM_Utils_Type
::T_INT
,
131 'description' => 'ID of Contact to be Soft credited to (deprecated - use contribution_soft api)',
132 'FKClassName' => 'CRM_Contact_DAO_Contact',
134 $params['honor_contact_id'] = array(
135 'name' => 'honor_contact_id',
136 'title' => 'Honoree contact ID (legacy)',
137 'type' => CRM_Utils_Type
::T_INT
,
138 'description' => 'ID of honoree contact (deprecated - use contribution_soft api)',
139 'FKClassName' => 'CRM_Contact_DAO_Contact',
141 $params['honor_type_id'] = array(
142 'name' => 'honor_type_id',
143 'title' => 'Honoree Type (legacy)',
144 'type' => CRM_Utils_Type
::T_INT
,
145 'description' => 'Type of honoree contact (deprecated - use contribution_soft api)',
146 'pseudoconstant' => TRUE,
148 // note this is a recommended option but not adding as a default to avoid
149 // creating unnecessary changes for the dev
150 $params['skipRecentView'] = array(
151 'name' => 'skipRecentView',
152 'title' => 'Skip adding to recent view',
153 'type' => CRM_Utils_Type
::T_BOOLEAN
,
154 'description' => 'Do not add to recent view (setting this improves performance)',
156 $params['skipLineItem'] = array(
157 'name' => 'skipLineItem',
158 'title' => 'Skip adding line items',
159 'type' => CRM_Utils_Type
::T_BOOLEAN
,
161 'description' => 'Do not add line items by default (if you wish to add your own)',
163 $params['batch_id'] = array(
165 'type' => CRM_Utils_Type
::T_INT
,
166 'description' => 'Batch which relevant transactions should be added to',
168 $params['refund_trxn_id'] = array(
169 'title' => 'Refund Transaction ID',
170 'type' => CRM_Utils_Type
::T_STRING
,
171 'description' => 'Transaction ID specific to the refund taking place',
173 $params['card_type_id'] = array(
174 'title' => 'Card Type ID',
175 'description' => 'Providing Credit Card Type ID',
176 'type' => CRM_Utils_Type
::T_INT
,
177 'pseudoconstant' => array(
178 'optionGroupName' => 'accept_creditcard',
184 * Support for schema changes made in 4.5.
186 * The main purpose of the API is to provide integrators a level of stability not provided by
187 * the core code or schema - this means we have to provide support for api calls (where possible)
188 * across schema changes.
190 * @param array $params
192 function _civicrm_api3_contribution_create_legacy_support_45(&$params) {
193 //legacy soft credit handling - recommended approach is chaining
194 if (!empty($params['soft_credit_to'])) {
195 $params['soft_credit'][] = array(
196 'contact_id' => $params['soft_credit_to'],
197 'amount' => $params['total_amount'],
198 'soft_credit_type_id' => CRM_Core_OptionGroup
::getDefaultValue("soft_credit_type"),
201 if (!empty($params['honor_contact_id'])) {
202 $params['soft_credit'][] = array(
203 'contact_id' => $params['honor_contact_id'],
204 'amount' => $params['total_amount'],
205 'soft_credit_type_id' => CRM_Utils_Array
::value('honor_type_id', $params, CRM_Core_PseudoConstant
::getKey('CRM_Contribute_BAO_ContributionSoft', 'soft_credit_type_id', 'in_honor_of')),
211 * Delete a Contribution.
213 * @param array $params
218 function civicrm_api3_contribution_delete($params) {
220 $contributionID = !empty($params['contribution_id']) ?
$params['contribution_id'] : $params['id'];
221 // First check contribution financial type
222 $financialType = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionID, 'financial_type_id');
223 // Now check permissioned lineitems & permissioned contribution
224 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus()
225 && !CRM_Core_Permission
::check('delete contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($financialType)) ||
226 !CRM_Financial_BAO_FinancialType
::checkPermissionedLineItems($contributionID, 'delete', FALSE)
228 return civicrm_api3_create_error('You do not have permission to delete this contribution');
230 if (CRM_Contribute_BAO_Contribution
::deleteContribution($contributionID)) {
231 return civicrm_api3_create_success(array($contributionID => 1));
234 return civicrm_api3_create_error('Could not delete contribution');
239 * Modify metadata for delete action.
241 * Legacy support for contribution_id.
243 * @param array $params
245 function _civicrm_api3_contribution_delete_spec(&$params) {
246 $params['id']['api.aliases'] = array('contribution_id');
250 * Retrieve a set of contributions.
252 * @param array $params
256 * Array of contributions, if error an array with an error id and error message
258 function civicrm_api3_contribution_get($params) {
260 $mode = CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
;
261 $additionalOptions = _civicrm_api3_contribution_get_support_nonunique_returns($params);
262 $returnProperties = CRM_Contribute_BAO_Query
::defaultReturnProperties($mode);
264 $contributions = _civicrm_api3_get_using_query_object('Contribution', $params, $additionalOptions, NULL, $mode, $returnProperties);
266 foreach ($contributions as $id => $contribution) {
267 $softContribution = CRM_Contribute_BAO_ContributionSoft
::getSoftContribution($id, TRUE);
268 $contributions[$id] = array_merge($contribution, $softContribution);
269 // format soft credit for backward compatibility
270 _civicrm_api3_format_soft_credit($contributions[$id]);
271 _civicrm_api3_contribution_add_supported_fields($contributions[$id]);
274 return civicrm_api3_create_success($contributions, $params, 'Contribution', 'get');
278 * Fix the return values to reflect cases where the schema has been changed.
280 * At the query object level using uniquenames dismbiguates between tables.
282 * However, adding uniquename can change inputs accepted by the api, so we need
283 * to ensure we are asking for the unique name return fields.
285 * @param array $params
288 * @throws \API_Exception
290 function _civicrm_api3_contribution_get_support_nonunique_returns($params) {
291 $additionalOptions = array();
292 $options = _civicrm_api3_get_options_from_params($params, TRUE);
293 foreach (array('check_number', 'address_id') as $changedVariable) {
294 if (isset($options['return']) && !empty($options['return'][$changedVariable])) {
295 $additionalOptions['return']['contribution_' . $changedVariable] = 1;
298 return $additionalOptions;
302 * Support for supported output variables.
304 * @param $contribution
306 function _civicrm_api3_contribution_add_supported_fields(&$contribution) {
307 // These are output fields that are supported in our test contract.
308 // Arguably we should also do the same with 'campaign_id' &
309 // 'source' - which are also fields being rendered with unique names.
310 // That seems more consistent with other api where we output the actual field names.
311 $outputAliases = array(
312 'contribution_check_number' => 'check_number',
313 'contribution_address_id' => 'address_id',
314 'payment_instrument_id' => 'instrument_id',
316 foreach ($outputAliases as $returnName => $copyTo) {
317 if (array_key_exists($returnName, $contribution)) {
318 $contribution[$copyTo] = $contribution[$returnName];
325 * Get number of contacts matching the supplied criteria.
327 * @param array $params
331 function civicrm_api3_contribution_getcount($params) {
332 $count = _civicrm_api3_get_using_query_object('Contribution', $params, array(), TRUE, CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
);
337 * This function is used to format the soft credit for backward compatibility.
339 * As of v4.4 we support multiple soft credit, so now contribution returns array with 'soft_credit' as key
340 * but we still return first soft credit as a part of contribution array
342 * @param $contribution
344 function _civicrm_api3_format_soft_credit(&$contribution) {
345 if (!empty($contribution['soft_credit'])) {
346 $contribution['soft_credit_to'] = $contribution['soft_credit'][1]['contact_id'];
347 $contribution['soft_credit_id'] = $contribution['soft_credit'][1]['soft_credit_id'];
352 * Adjust Metadata for Get action.
354 * The metadata is used for setting defaults, documentation & validation.
356 * @param array $params
357 * Array of parameters determined by getfields.
359 function _civicrm_api3_contribution_get_spec(&$params) {
360 $params['contribution_test'] = array(
362 'type' => CRM_Utils_Type
::T_BOOLEAN
,
363 'title' => 'Get Test Contributions?',
364 'api.aliases' => array('is_test'),
367 $params['financial_type_id']['api.aliases'] = array('contribution_type_id');
368 $params['payment_instrument_id']['api.aliases'] = array('contribution_payment_instrument', 'payment_instrument');
369 $params['contact_id'] = CRM_Utils_Array
::value('contribution_contact_id', $params);
370 $params['contact_id']['api.aliases'] = array('contribution_contact_id');
371 unset($params['contribution_contact_id']);
375 * Legacy handling for contribution parameters.
377 * Take the input parameter list as specified in the data model and
378 * convert it into the same format that we use in QF and BAO object.
380 * @param array $params
381 * property name/value pairs to insert in new contact.
382 * @param array $values
383 * The reformatted properties that we can use internally.
387 function _civicrm_api3_contribute_format_params($params, &$values) {
388 //legacy way of formatting from v2 api - v3 way is to define metadata & do it in the api layer
389 _civicrm_api3_filter_fields_for_bao('Contribution', $params, $values);
394 * Adjust Metadata for Transact action.
396 * The metadata is used for setting defaults, documentation & validation.
398 * @param array $params
399 * Array of parameters determined by getfields.
401 function _civicrm_api3_contribution_transact_spec(&$params) {
402 $fields = civicrm_api3('Contribution', 'getfields', array('action' => 'create'));
403 $params = array_merge($params, $fields['values']);
404 $params['receive_date']['api.default'] = 'now';
408 * Process a transaction and record it against the contact.
410 * @param array $params
414 * contribution of created or updated record (or a civicrm error)
416 function civicrm_api3_contribution_transact($params) {
417 // Set some params specific to payment processing
418 // @todo - fix this function - none of the results checked by civicrm_error would ever be an array with
420 // also trxn_id is not saved.
421 // but since there is no test it's not desirable to jump in & make the obvious changes.
422 $params['payment_processor_mode'] = empty($params['is_test']) ?
'live' : 'test';
423 $params['amount'] = $params['total_amount'];
424 if (!isset($params['net_amount'])) {
425 $params['net_amount'] = $params['amount'];
427 if (!isset($params['invoiceID']) && isset($params['invoice_id'])) {
428 $params['invoiceID'] = $params['invoice_id'];
431 // Some payment processors expect a unique invoice_id - generate one if not supplied
432 $params['invoice_id'] = CRM_Utils_Array
::value('invoice_id', $params, md5(uniqid(rand(), TRUE)));
434 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getPayment($params['payment_processor'], $params['payment_processor_mode']);
435 $paymentProcessor['object']->doPayment($params);
437 $params['payment_instrument_id'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_PaymentProcessorType', $paymentProcessor['payment_processor_type_id'], 'payment_type') == 1 ?
'Credit Card' : 'Debit Card';
438 return civicrm_api('Contribution', 'create', $params);
442 * Send a contribution confirmation (receipt or invoice).
444 * The appropriate online template will be used (the existence of related objects
445 * (e.g. memberships ) will affect this selection
447 * @param array $params
452 function civicrm_api3_contribution_sendconfirmation($params) {
453 $ids = $values = array();
454 $allowedParams = array(
455 'receipt_from_email',
461 'payment_processor_id',
463 $input = array_intersect_key($params, array_flip($allowedParams));
464 $input['is_email_receipt'] = TRUE;
465 CRM_Contribute_BAO_Contribution
::sendMail($input, $ids, $params['id'], $values);
469 * Adjust Metadata for sendconfirmation action.
471 * The metadata is used for setting defaults, documentation & validation.
473 * @param array $params
474 * Array of parameters determined by getfields.
476 function _civicrm_api3_contribution_sendconfirmation_spec(&$params) {
477 $params['id'] = array(
479 'title' => ts('Contribution ID'),
480 'type' => CRM_Utils_Type
::T_INT
,
482 $params['receipt_from_email'] = array(
483 'title' => ts('From Email address (string)'),
484 'type' => CRM_Utils_Type
::T_STRING
,
486 $params['receipt_from_name'] = array(
487 'title' => ts('From Name (string)'),
488 'type' => CRM_Utils_Type
::T_STRING
,
490 $params['cc_receipt'] = array(
491 'title' => ts('CC Email address (string)'),
492 'type' => CRM_Utils_Type
::T_STRING
,
494 $params['bcc_receipt'] = array(
495 'title' => ts('BCC Email address (string)'),
496 'type' => CRM_Utils_Type
::T_STRING
,
498 $params['receipt_text'] = array(
499 'title' => ts('Message (string)'),
500 'type' => CRM_Utils_Type
::T_STRING
,
502 $params['receipt_update'] = array(
503 'title' => ts('Update the Receipt Date'),
504 'type' => CRM_Utils_Type
::T_BOOLEAN
,
505 'api.default' => TRUE,
507 $params['payment_processor_id'] = array(
508 'title' => ts('Payment processor Id (avoids mis-guesses)'),
509 'type' => CRM_Utils_Type
::T_INT
,
514 * Complete an existing (pending) transaction.
516 * This will update related entities (participant, membership, pledge etc)
517 * and take any complete actions from the contribution page (e.g. send receipt).
519 * @todo - most of this should live in the BAO layer but as we want it to be an addition
520 * to 4.3 which is already stable we should add it to the api layer & re-factor into the BAO layer later
522 * @param array $params
527 * @throws \API_Exception
528 * @throws \CRM_Core_Exception
531 function civicrm_api3_contribution_completetransaction(&$params) {
532 $input = $ids = array();
533 if (isset($params['payment_processor_id'])) {
534 $input['payment_processor_id'] = $params['payment_processor_id'];
536 $contribution = new CRM_Contribute_BAO_Contribution();
537 $contribution->id
= $params['id'];
538 if (!$contribution->find(TRUE)) {
539 throw new API_Exception('A valid contribution ID is required', 'invalid_data');
542 if (!$contribution->loadRelatedObjects($input, $ids, TRUE)) {
543 throw new API_Exception('failed to load related objects');
545 elseif ($contribution->contribution_status_id
== CRM_Core_PseudoConstant
::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed')) {
546 throw new API_Exception(ts('Contribution already completed'), 'contribution_completed');
548 $input['trxn_id'] = !empty($params['trxn_id']) ?
$params['trxn_id'] : $contribution->trxn_id
;
549 if (!empty($params['fee_amount'])) {
550 $input['fee_amount'] = $params['fee_amount'];
552 return _ipn_process_transaction($params, $contribution, $input, $ids);
557 * Provide function metadata.
559 * @param array $params
561 function _civicrm_api3_contribution_completetransaction_spec(&$params) {
562 $params['id'] = array(
563 'title' => 'Contribution ID',
564 'type' => CRM_Utils_Type
::T_INT
,
565 'api.required' => TRUE,
567 $params['trxn_id'] = array(
568 'title' => 'Transaction ID',
569 'type' => CRM_Utils_Type
::T_STRING
,
571 $params['is_email_receipt'] = array(
572 'title' => 'Send email Receipt?',
573 'type' => CRM_Utils_Type
::T_BOOLEAN
,
575 $params['receipt_from_email'] = array(
576 'title' => 'Email to send receipt from.',
577 'description' => 'If not provided this will default to being based on domain mail or contribution page',
578 'type' => CRM_Utils_Type
::T_EMAIL
,
580 $params['receipt_from_name'] = array(
581 'title' => 'Name to send receipt from',
582 'description' => '. If not provided this will default to domain mail or contribution page',
583 'type' => CRM_Utils_Type
::T_STRING
,
585 $params['payment_processor_id'] = array(
586 'title' => 'Payment processor ID',
587 'description' => 'Providing this is strongly recommended, as not possible to calculate it accurately always',
588 'type' => CRM_Utils_Type
::T_INT
,
590 $params['fee_amount'] = array(
591 'title' => 'Fee charged on transaction',
592 'description' => 'If a fee has been charged then the amount',
593 'type' => CRM_Utils_Type
::T_FLOAT
,
595 $params['trxn_date'] = array(
596 'title' => 'Transaction Date',
597 'description' => 'Date this transaction occurred',
598 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
600 $params['card_type_id'] = array(
601 'title' => 'Card Type ID',
602 'description' => 'Providing Credit Card Type ID',
603 'type' => CRM_Utils_Type
::T_INT
,
604 'pseudoconstant' => array(
605 'optionGroupName' => 'accept_creditcard',
611 * Complete an existing (pending) transaction.
613 * This will update related entities (participant, membership, pledge etc)
614 * and take any complete actions from the contribution page (e.g. send receipt).
616 * @todo - most of this should live in the BAO layer but as we want it to be an addition
617 * to 4.3 which is already stable we should add it to the api layer & re-factor into the BAO layer later
619 * @param array $params
624 * @throws API_Exception
626 function civicrm_api3_contribution_repeattransaction(&$params) {
627 $input = $ids = array();
628 civicrm_api3_verify_one_mandatory($params, NULL, array('contribution_recur_id', 'original_contribution_id'));
629 if (empty($params['original_contribution_id'])) {
630 // CRM-19873 call with test mode.
631 $params['original_contribution_id'] = civicrm_api3('contribution', 'getvalue', array(
633 'contribution_status_id' => array('IN' => array('Completed')),
634 'contribution_recur_id' => $params['contribution_recur_id'],
635 'contribution_test' => CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionRecur', $params['contribution_recur_id'], 'is_test'),
636 'options' => array('limit' => 1, 'sort' => 'id DESC'),
639 $contribution = new CRM_Contribute_BAO_Contribution();
640 $contribution->id
= $params['original_contribution_id'];
641 if (!$contribution->find(TRUE)) {
642 throw new API_Exception(
643 'A valid original contribution ID is required', 'invalid_data');
645 $original_contribution = clone $contribution;
646 $input['payment_processor_id'] = civicrm_api3('contributionRecur', 'getvalue', array(
647 'return' => 'payment_processor_id',
648 'id' => $contribution->contribution_recur_id
,
651 if (!$contribution->loadRelatedObjects($input, $ids, TRUE)) {
652 throw new API_Exception('failed to load related objects');
655 unset($contribution->id
, $contribution->receive_date
, $contribution->invoice_id
);
656 $contribution->receive_date
= $params['receive_date'];
658 $passThroughParams = array(
664 'contribution_status_id',
666 $input = array_intersect_key($params, array_fill_keys($passThroughParams, NULL));
668 return _ipn_process_transaction($params, $contribution, $input, $ids, $original_contribution);
670 catch(Exception
$e) {
671 throw new API_Exception('failed to load related objects' . $e->getMessage() . "\n" . $e->getTraceAsString());
676 * Calls IPN complete transaction for completing or repeating a transaction.
678 * The IPN function is overloaded with two purposes - this is simply a wrapper for that
679 * when separating them in the api layer.
681 * @param array $params
682 * @param CRM_Contribute_BAO_Contribution $contribution
683 * @param array $input
687 * @param CRM_Contribute_BAO_Contribution $firstContribution
691 function _ipn_process_transaction(&$params, $contribution, $input, $ids, $firstContribution = NULL) {
692 $objects = $contribution->_relatedObjects
;
693 $objects['contribution'] = &$contribution;
695 if ($firstContribution) {
696 $objects['first_contribution'] = $firstContribution;
698 $input['component'] = $contribution->_component
;
699 $input['is_test'] = $contribution->is_test
;
700 $input['amount'] = empty($input['total_amount']) ?
$contribution->total_amount
: $input['total_amount'];
702 if (isset($params['is_email_receipt'])) {
703 $input['is_email_receipt'] = $params['is_email_receipt'];
705 if (!empty($params['trxn_date'])) {
706 $input['trxn_date'] = $params['trxn_date'];
708 if (!empty($params['receive_date'])) {
709 $input['receive_date'] = $params['receive_date'];
711 if (empty($contribution->contribution_page_id
)) {
712 static $domainFromName;
713 static $domainFromEmail;
714 if (empty($domainFromEmail) && (empty($params['receipt_from_name']) ||
empty($params['receipt_from_email']))) {
715 list($domainFromName, $domainFromEmail) = CRM_Core_BAO_Domain
::getNameAndEmail(TRUE);
717 $input['receipt_from_name'] = CRM_Utils_Array
::value('receipt_from_name', $params, $domainFromName);
718 $input['receipt_from_email'] = CRM_Utils_Array
::value('receipt_from_email', $params, $domainFromEmail);
720 $input['card_type_id'] = CRM_Utils_Array
::value('card_type_id', $params);
721 $input['pan_truncation'] = CRM_Utils_Array
::value('pan_truncation', $params);
722 $transaction = new CRM_Core_Transaction();
723 return CRM_Contribute_BAO_Contribution
::completeOrder($input, $ids, $objects, $transaction, !empty
724 ($contribution->contribution_recur_id
), $contribution);
728 * Provide function metadata.
730 * @param array $params
732 function _civicrm_api3_contribution_repeattransaction_spec(&$params) {
733 $params['original_contribution_id'] = array(
734 'title' => 'Original Contribution ID',
735 'description' => 'Contribution ID to copy (will be calculated from recurring contribution if not provided)',
736 'type' => CRM_Utils_Type
::T_INT
,
738 $params['contribution_recur_id'] = array(
739 'title' => 'Recurring contribution ID',
740 'type' => CRM_Utils_Type
::T_INT
,
742 $params['trxn_id'] = array(
743 'title' => 'Transaction ID',
744 'type' => CRM_Utils_Type
::T_STRING
,
746 $params['is_email_receipt'] = array(
747 'title' => 'Send email Receipt?',
748 'type' => CRM_Utils_Type
::T_BOOLEAN
,
750 $params['contribution_status_id'] = array(
751 'title' => 'Contribution Status ID',
752 'name' => 'contribution_status_id',
753 'type' => CRM_Utils_Type
::T_INT
,
754 'pseudoconstant' => array(
755 'optionGroupName' => 'contribution_status',
757 'api.required' => TRUE,
759 $params['receive_date'] = array(
760 'title' => 'Contribution Receive Date',
761 'name' => 'receive_date',
762 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
763 'api.default' => 'now',
765 $params['trxn_id'] = array(
766 'title' => 'Transaction ID',
768 'type' => CRM_Utils_Type
::T_STRING
,
770 $params['campaign_id'] = array(
771 'title' => 'Campaign ID',
772 'name' => 'campaign_id',
773 'type' => CRM_Utils_Type
::T_INT
,
774 'pseudoconstant' => array(
775 'table' => 'civicrm_campaign',
777 'labelColumn' => 'title',
780 $params['financial_type_id'] = array(
781 'title' => 'Financial ID (ignored if more than one line item)',
782 'name' => 'financial_type_id',
783 'type' => CRM_Utils_Type
::T_INT
,
784 'pseudoconstant' => array(
785 'table' => 'civicrm_financial_type',
787 'labelColumn' => 'name',
790 $params['payment_processor_id'] = array(
791 'description' => ts('Payment processor ID, will be loaded from contribution_recur if not provided'),
792 'title' => 'Payment processor ID',
793 'name' => 'payment_processor_id',
794 'type' => CRM_Utils_Type
::T_INT
,