3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 (!empty($params['check_permissions']) && 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 throw new API_Exception('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'] = ['payment_instrument'];
108 $params['receive_date']['api.default'] = 'now';
109 $params['receive_date']['api.required'] = TRUE;
110 $params['payment_processor'] = [
111 'name' => 'payment_processor',
112 'title' => 'Payment Processor ID',
113 'description' => 'ID of payment processor used for this contribution',
114 // field is called payment processor - not payment processor id but can only be one id so
115 // it seems likely someone will fix it up one day to be more consistent - lets alias it from the start
116 'api.aliases' => ['payment_processor_id'],
117 'type' => CRM_Utils_Type
::T_INT
,
119 $params['financial_type_id']['api.aliases'] = ['contribution_type_id', 'contribution_type'];
120 $params['financial_type_id']['api.required'] = 1;
123 'uniqueName' => 'contribution_note',
126 'description' => 'Associated Note in the notes table',
128 $params['soft_credit_to'] = [
129 'name' => 'soft_credit_to',
130 'title' => 'Soft Credit contact ID (legacy)',
131 'type' => CRM_Utils_Type
::T_INT
,
132 'description' => 'ID of Contact to be Soft credited to (deprecated - use contribution_soft api)',
133 'FKClassName' => 'CRM_Contact_DAO_Contact',
135 $params['honor_contact_id'] = [
136 'name' => 'honor_contact_id',
137 'title' => 'Honoree contact ID (legacy)',
138 'type' => CRM_Utils_Type
::T_INT
,
139 'description' => 'ID of honoree contact (deprecated - use contribution_soft api)',
140 'FKClassName' => 'CRM_Contact_DAO_Contact',
142 $params['honor_type_id'] = [
143 'name' => 'honor_type_id',
144 'title' => 'Honoree Type (legacy)',
145 'type' => CRM_Utils_Type
::T_INT
,
146 'description' => 'Type of honoree contact (deprecated - use contribution_soft api)',
147 'pseudoconstant' => TRUE,
149 // note this is a recommended option but not adding as a default to avoid
150 // creating unnecessary changes for the dev
151 $params['skipRecentView'] = [
152 'name' => 'skipRecentView',
153 'title' => 'Skip adding to recent view',
154 'type' => CRM_Utils_Type
::T_BOOLEAN
,
155 'description' => 'Do not add to recent view (setting this improves performance)',
157 $params['skipLineItem'] = [
158 'name' => 'skipLineItem',
159 'title' => 'Skip adding line items',
160 'type' => CRM_Utils_Type
::T_BOOLEAN
,
162 'description' => 'Do not add line items by default (if you wish to add your own)',
164 $params['batch_id'] = [
166 'type' => CRM_Utils_Type
::T_INT
,
167 'description' => 'Batch which relevant transactions should be added to',
169 $params['refund_trxn_id'] = [
170 'title' => 'Refund Transaction ID',
171 'type' => CRM_Utils_Type
::T_STRING
,
172 'description' => 'Transaction ID specific to the refund taking place',
174 $params['card_type_id'] = [
175 'title' => 'Card Type ID',
176 'description' => 'Providing Credit Card Type ID',
177 'type' => CRM_Utils_Type
::T_INT
,
178 'pseudoconstant' => [
179 'optionGroupName' => 'accept_creditcard',
185 * Support for schema changes made in 4.5.
187 * The main purpose of the API is to provide integrators a level of stability not provided by
188 * the core code or schema - this means we have to provide support for api calls (where possible)
189 * across schema changes.
191 * @param array $params
193 function _civicrm_api3_contribution_create_legacy_support_45(&$params) {
194 //legacy soft credit handling - recommended approach is chaining
195 if (!empty($params['soft_credit_to'])) {
196 $params['soft_credit'][] = [
197 'contact_id' => $params['soft_credit_to'],
198 'amount' => $params['total_amount'],
199 'soft_credit_type_id' => CRM_Core_OptionGroup
::getDefaultValue("soft_credit_type"),
202 if (!empty($params['honor_contact_id'])) {
203 $params['soft_credit'][] = [
204 'contact_id' => $params['honor_contact_id'],
205 'amount' => $params['total_amount'],
206 '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')),
212 * Delete a Contribution.
214 * @param array $params
218 * @throws \API_Exception
220 function civicrm_api3_contribution_delete($params) {
222 $contributionID = !empty($params['contribution_id']) ?
$params['contribution_id'] : $params['id'];
223 // First check contribution financial type
224 $financialType = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionID, 'financial_type_id');
225 // Now check permissioned lineitems & permissioned contribution
226 if (!empty($params['check_permissions']) && CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus() &&
228 !CRM_Core_Permission
::check('delete contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($financialType))
229 ||
!CRM_Financial_BAO_FinancialType
::checkPermissionedLineItems($contributionID, 'delete', FALSE)
232 throw new API_Exception('You do not have permission to delete this contribution');
234 if (CRM_Contribute_BAO_Contribution
::deleteContribution($contributionID)) {
235 return civicrm_api3_create_success([$contributionID => 1]);
238 throw new API_Exception('Could not delete contribution');
243 * Modify metadata for delete action.
245 * Legacy support for contribution_id.
247 * @param array $params
249 function _civicrm_api3_contribution_delete_spec(&$params) {
250 $params['id']['api.aliases'] = ['contribution_id'];
254 * Retrieve a set of contributions.
256 * @param array $params
260 * Array of contributions, if error an array with an error id and error message
262 function civicrm_api3_contribution_get($params) {
264 $mode = CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
;
265 $additionalOptions = _civicrm_api3_contribution_get_support_nonunique_returns($params);
266 $returnProperties = CRM_Contribute_BAO_Query
::defaultReturnProperties($mode);
268 // Get the contributions based on parameters passed in
269 $contributions = _civicrm_api3_get_using_query_object('Contribution', $params, $additionalOptions, NULL, $mode, $returnProperties);
270 if (!empty($contributions)) {
271 $softContributions = CRM_Contribute_BAO_ContributionSoft
::getSoftCreditContributionFields(array_keys($contributions), TRUE);
272 foreach ($contributions as $id => $contribution) {
273 $contributions[$id] = isset($softContributions[$id]) ?
array_merge($contribution, $softContributions[$id]) : $contribution;
274 // format soft credit for backward compatibility
275 _civicrm_api3_format_soft_credit($contributions[$id]);
276 _civicrm_api3_contribution_add_supported_fields($contributions[$id]);
279 return civicrm_api3_create_success($contributions, $params, 'Contribution', 'get');
283 * Fix the return values to reflect cases where the schema has been changed.
285 * At the query object level using uniquenames dismbiguates between tables.
287 * However, adding uniquename can change inputs accepted by the api, so we need
288 * to ensure we are asking for the unique name return fields.
290 * @param array $params
293 * @throws \API_Exception
295 function _civicrm_api3_contribution_get_support_nonunique_returns($params) {
296 $additionalOptions = [];
297 $options = _civicrm_api3_get_options_from_params($params, TRUE);
298 foreach (['check_number', 'address_id', 'cancel_date'] as $changedVariable) {
299 if (isset($options['return']) && !empty($options['return'][$changedVariable])) {
300 $additionalOptions['return']['contribution_' . $changedVariable] = 1;
303 return $additionalOptions;
307 * Support for supported output variables.
309 * @param $contribution
311 function _civicrm_api3_contribution_add_supported_fields(&$contribution) {
312 // These are output fields that are supported in our test contract.
313 // Arguably we should also do the same with 'campaign_id' &
314 // 'source' - which are also fields being rendered with unique names.
315 // That seems more consistent with other api where we output the actual field names.
317 'contribution_check_number' => 'check_number',
318 'contribution_address_id' => 'address_id',
319 'payment_instrument_id' => 'instrument_id',
320 'contribution_cancel_date' => 'cancel_date',
322 foreach ($outputAliases as $returnName => $copyTo) {
323 if (array_key_exists($returnName, $contribution)) {
324 $contribution[$copyTo] = $contribution[$returnName];
331 * Get number of contacts matching the supplied criteria.
333 * @param array $params
337 function civicrm_api3_contribution_getcount($params) {
338 $count = _civicrm_api3_get_using_query_object('Contribution', $params, [], TRUE, CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
);
343 * This function is used to format the soft credit for backward compatibility.
345 * As of v4.4 we support multiple soft credit, so now contribution returns array with 'soft_credit' as key
346 * but we still return first soft credit as a part of contribution array
348 * @param $contribution
350 function _civicrm_api3_format_soft_credit(&$contribution) {
351 if (!empty($contribution['soft_credit'])) {
352 $contribution['soft_credit_to'] = $contribution['soft_credit'][1]['contact_id'];
353 $contribution['soft_credit_id'] = $contribution['soft_credit'][1]['soft_credit_id'];
358 * Adjust Metadata for Get action.
360 * The metadata is used for setting defaults, documentation & validation.
362 * @param array $params
363 * Array of parameters determined by getfields.
365 function _civicrm_api3_contribution_get_spec(&$params) {
366 $params['contribution_test'] = [
368 'type' => CRM_Utils_Type
::T_BOOLEAN
,
369 'title' => 'Get Test Contributions?',
370 'api.aliases' => ['is_test'],
373 $params['financial_type_id']['api.aliases'] = ['contribution_type_id'];
374 $params['payment_instrument_id']['api.aliases'] = ['contribution_payment_instrument', 'payment_instrument'];
375 $params['contact_id'] = CRM_Utils_Array
::value('contribution_contact_id', $params);
376 $params['contact_id']['api.aliases'] = ['contribution_contact_id'];
377 unset($params['contribution_contact_id']);
381 * Legacy handling for contribution parameters.
383 * Take the input parameter list as specified in the data model and
384 * convert it into the same format that we use in QF and BAO object.
386 * @param array $params
387 * property name/value pairs to insert in new contact.
388 * @param array $values
389 * The reformatted properties that we can use internally.
393 function _civicrm_api3_contribute_format_params($params, &$values) {
394 //legacy way of formatting from v2 api - v3 way is to define metadata & do it in the api layer
395 _civicrm_api3_filter_fields_for_bao('Contribution', $params, $values);
400 * Adjust Metadata for Transact action.
402 * The metadata is used for setting defaults, documentation & validation.
404 * @param array $params
405 * Array of parameters determined by getfields.
407 function _civicrm_api3_contribution_transact_spec(&$params) {
408 $fields = civicrm_api3('Contribution', 'getfields', ['action' => 'create']);
409 $params = array_merge($params, $fields['values']);
410 $params['receive_date']['api.default'] = 'now';
414 * Process a transaction and record it against the contact.
416 * @param array $params
420 * contribution of created or updated record (or a civicrm error)
422 function civicrm_api3_contribution_transact($params) {
423 // Set some params specific to payment processing
424 // @todo - fix this function - none of the results checked by civicrm_error would ever be an array with
426 // also trxn_id is not saved.
427 // but since there is no test it's not desirable to jump in & make the obvious changes.
428 $params['payment_processor_mode'] = empty($params['is_test']) ?
'live' : 'test';
429 $params['amount'] = $params['total_amount'];
430 if (!isset($params['net_amount'])) {
431 $params['net_amount'] = $params['amount'];
433 if (!isset($params['invoiceID']) && isset($params['invoice_id'])) {
434 $params['invoiceID'] = $params['invoice_id'];
437 // Some payment processors expect a unique invoice_id - generate one if not supplied
438 $params['invoice_id'] = CRM_Utils_Array
::value('invoice_id', $params, md5(uniqid(rand(), TRUE)));
440 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getPayment($params['payment_processor'], $params['payment_processor_mode']);
441 $paymentProcessor['object']->doPayment($params);
443 $params['payment_instrument_id'] = $paymentProcessor['object']->getPaymentInstrumentID();
445 return civicrm_api('Contribution', 'create', $params);
449 * Send a contribution confirmation (receipt or invoice).
451 * The appropriate online template will be used (the existence of related objects
452 * (e.g. memberships ) will affect this selection
454 * @param array $params
459 function civicrm_api3_contribution_sendconfirmation($params) {
462 'receipt_from_email',
468 'payment_processor_id',
470 $input = array_intersect_key($params, array_flip($allowedParams));
471 $input['is_email_receipt'] = TRUE;
472 CRM_Contribute_BAO_Contribution
::sendMail($input, $ids, $params['id'], $values);
476 * Adjust Metadata for sendconfirmation action.
478 * The metadata is used for setting defaults, documentation & validation.
480 * @param array $params
481 * Array of parameters determined by getfields.
483 function _civicrm_api3_contribution_sendconfirmation_spec(&$params) {
486 'title' => ts('Contribution ID'),
487 'type' => CRM_Utils_Type
::T_INT
,
489 $params['receipt_from_email'] = [
490 'title' => ts('From Email address (string)'),
491 'type' => CRM_Utils_Type
::T_STRING
,
493 $params['receipt_from_name'] = [
494 'title' => ts('From Name (string)'),
495 'type' => CRM_Utils_Type
::T_STRING
,
497 $params['cc_receipt'] = [
498 'title' => ts('CC Email address (string)'),
499 'type' => CRM_Utils_Type
::T_STRING
,
501 $params['bcc_receipt'] = [
502 'title' => ts('BCC Email address (string)'),
503 'type' => CRM_Utils_Type
::T_STRING
,
505 $params['receipt_text'] = [
506 'title' => ts('Message (string)'),
507 'type' => CRM_Utils_Type
::T_STRING
,
509 $params['receipt_update'] = [
510 'title' => ts('Update the Receipt Date'),
511 'type' => CRM_Utils_Type
::T_BOOLEAN
,
512 'api.default' => TRUE,
514 $params['payment_processor_id'] = [
515 'title' => ts('Payment processor Id (avoids mis-guesses)'),
516 'type' => CRM_Utils_Type
::T_INT
,
521 * Complete an existing (pending) transaction.
523 * This will update related entities (participant, membership, pledge etc)
524 * and take any complete actions from the contribution page (e.g. send receipt).
526 * @todo - most of this should live in the BAO layer but as we want it to be an addition
527 * to 4.3 which is already stable we should add it to the api layer & re-factor into the BAO layer later
529 * @param array $params
534 * @throws \API_Exception
535 * @throws \CRM_Core_Exception
538 function civicrm_api3_contribution_completetransaction($params) {
540 if (isset($params['payment_processor_id'])) {
541 $input['payment_processor_id'] = $params['payment_processor_id'];
543 $contribution = new CRM_Contribute_BAO_Contribution();
544 $contribution->id
= $params['id'];
545 if (!$contribution->find(TRUE)) {
546 throw new API_Exception('A valid contribution ID is required', 'invalid_data');
549 if (!$contribution->loadRelatedObjects($input, $ids, TRUE)) {
550 throw new API_Exception('failed to load related objects');
552 elseif ($contribution->contribution_status_id
== CRM_Core_PseudoConstant
::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed')) {
553 throw new API_Exception(ts('Contribution already completed'), 'contribution_completed');
555 $input['trxn_id'] = !empty($params['trxn_id']) ?
$params['trxn_id'] : $contribution->trxn_id
;
556 if (!empty($params['fee_amount'])) {
557 $input['fee_amount'] = $params['fee_amount'];
559 return _ipn_process_transaction($params, $contribution, $input, $ids);
564 * Provide function metadata.
566 * @param array $params
568 function _civicrm_api3_contribution_completetransaction_spec(&$params) {
570 'title' => 'Contribution ID',
571 'type' => CRM_Utils_Type
::T_INT
,
572 'api.required' => TRUE,
574 $params['trxn_id'] = [
575 'title' => 'Transaction ID',
576 'type' => CRM_Utils_Type
::T_STRING
,
578 $params['is_email_receipt'] = [
579 'title' => 'Send email Receipt?',
580 'type' => CRM_Utils_Type
::T_BOOLEAN
,
582 $params['receipt_from_email'] = [
583 'title' => 'Email to send receipt from.',
584 'description' => 'If not provided this will default to being based on domain mail or contribution page',
585 'type' => CRM_Utils_Type
::T_EMAIL
,
587 $params['receipt_from_name'] = [
588 'title' => 'Name to send receipt from',
589 'description' => '. If not provided this will default to domain mail or contribution page',
590 'type' => CRM_Utils_Type
::T_STRING
,
592 $params['payment_processor_id'] = [
593 'title' => 'Payment processor ID',
594 'description' => 'Providing this is strongly recommended, as not possible to calculate it accurately always',
595 'type' => CRM_Utils_Type
::T_INT
,
597 $params['fee_amount'] = [
598 'title' => 'Fee charged on transaction',
599 'description' => 'If a fee has been charged then the amount',
600 'type' => CRM_Utils_Type
::T_FLOAT
,
602 $params['trxn_date'] = [
603 'title' => 'Transaction Date',
604 'description' => 'Date this transaction occurred',
605 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
607 $params['card_type_id'] = [
608 'title' => 'Card Type ID',
609 'description' => 'Providing Credit Card Type ID',
610 'type' => CRM_Utils_Type
::T_INT
,
611 'pseudoconstant' => [
612 'optionGroupName' => 'accept_creditcard',
615 // At some point we will deprecate this api in favour of calling payment create which will in turn call this
616 // api if appropriate to transition related entities and send receipts - ie. financial responsibility should
617 // not exist in completetransaction. For now we just need to allow payment.create to force a bypass on the
618 // things it does itself.
619 $params['is_post_payment_create'] = [
620 'title' => 'Is this being called from payment create?',
621 'type' => CRM_Utils_Type
::T_BOOLEAN
,
622 'description' => 'The \'correct\' flow is to call payment.create for the financial side & for that to call completecontribution for the entity & receipt management. However, we need to still support completetransaction directly for legacy reasons',
627 * Complete an existing (pending) transaction.
629 * This will update related entities (participant, membership, pledge etc)
630 * and take any complete actions from the contribution page (e.g. send receipt).
632 * @todo - most of this should live in the BAO layer but as we want it to be an addition
633 * to 4.3 which is already stable we should add it to the api layer & re-factor into the BAO layer later
635 * @param array $params
640 * @throws API_Exception
642 function civicrm_api3_contribution_repeattransaction($params) {
644 civicrm_api3_verify_one_mandatory($params, NULL, ['contribution_recur_id', 'original_contribution_id']);
645 if (empty($params['original_contribution_id'])) {
646 // CRM-19873 call with test mode.
647 $params['original_contribution_id'] = civicrm_api3('contribution', 'getvalue', [
649 'contribution_status_id' => ['IN' => ['Completed']],
650 'contribution_recur_id' => $params['contribution_recur_id'],
651 'contribution_test' => CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionRecur', $params['contribution_recur_id'], 'is_test'),
652 'options' => ['limit' => 1, 'sort' => 'id DESC'],
655 $contribution = new CRM_Contribute_BAO_Contribution();
656 $contribution->id
= $params['original_contribution_id'];
657 if (!$contribution->find(TRUE)) {
658 throw new API_Exception(
659 'A valid original contribution ID is required', 'invalid_data');
661 $original_contribution = clone $contribution;
662 $input['payment_processor_id'] = civicrm_api3('contributionRecur', 'getvalue', [
663 'return' => 'payment_processor_id',
664 'id' => $contribution->contribution_recur_id
,
667 if (!$contribution->loadRelatedObjects($input, $ids, TRUE)) {
668 throw new API_Exception('failed to load related objects');
671 unset($contribution->id
, $contribution->receive_date
, $contribution->invoice_id
);
672 $contribution->receive_date
= $params['receive_date'];
674 $passThroughParams = [
680 'contribution_status_id',
683 $input = array_intersect_key($params, array_fill_keys($passThroughParams, NULL));
685 return _ipn_process_transaction($params, $contribution, $input, $ids, $original_contribution);
687 catch (Exception
$e) {
688 throw new API_Exception('failed to load related objects' . $e->getMessage() . "\n" . $e->getTraceAsString());
693 * Calls IPN complete transaction for completing or repeating a transaction.
695 * The IPN function is overloaded with two purposes - this is simply a wrapper for that
696 * when separating them in the api layer.
698 * @param array $params
699 * @param CRM_Contribute_BAO_Contribution $contribution
700 * @param array $input
704 * @param CRM_Contribute_BAO_Contribution $firstContribution
708 function _ipn_process_transaction(&$params, $contribution, $input, $ids, $firstContribution = NULL) {
709 $objects = $contribution->_relatedObjects
;
710 $objects['contribution'] = &$contribution;
712 if ($firstContribution) {
713 $objects['first_contribution'] = $firstContribution;
715 $input['component'] = $contribution->_component
;
716 $input['is_test'] = $contribution->is_test
;
717 $input['amount'] = empty($input['total_amount']) ?
$contribution->total_amount
: $input['total_amount'];
719 if (isset($params['is_email_receipt'])) {
720 $input['is_email_receipt'] = $params['is_email_receipt'];
722 if (!empty($params['trxn_date'])) {
723 $input['trxn_date'] = $params['trxn_date'];
725 if (!empty($params['receive_date'])) {
726 $input['receive_date'] = $params['receive_date'];
728 if (empty($contribution->contribution_page_id
)) {
729 static $domainFromName;
730 static $domainFromEmail;
731 if (empty($domainFromEmail) && (empty($params['receipt_from_name']) ||
empty($params['receipt_from_email']))) {
732 list($domainFromName, $domainFromEmail) = CRM_Core_BAO_Domain
::getNameAndEmail(TRUE);
734 $input['receipt_from_name'] = CRM_Utils_Array
::value('receipt_from_name', $params, $domainFromName);
735 $input['receipt_from_email'] = CRM_Utils_Array
::value('receipt_from_email', $params, $domainFromEmail);
737 $input['card_type_id'] = CRM_Utils_Array
::value('card_type_id', $params);
738 $input['pan_truncation'] = CRM_Utils_Array
::value('pan_truncation', $params);
739 $transaction = new CRM_Core_Transaction();
740 return CRM_Contribute_BAO_Contribution
::completeOrder($input, $ids, $objects, $transaction,
741 !empty($contribution->contribution_recur_id
), $contribution, CRM_Utils_Array
::value('is_post_payment_create', $params));
745 * Provide function metadata.
747 * @param array $params
749 function _civicrm_api3_contribution_repeattransaction_spec(&$params) {
750 $params['original_contribution_id'] = [
751 'title' => 'Original Contribution ID',
752 'description' => 'Contribution ID to copy (will be calculated from recurring contribution if not provided)',
753 'type' => CRM_Utils_Type
::T_INT
,
755 $params['contribution_recur_id'] = [
756 'title' => 'Recurring contribution ID',
757 'type' => CRM_Utils_Type
::T_INT
,
759 $params['trxn_id'] = [
760 'title' => 'Transaction ID',
761 'type' => CRM_Utils_Type
::T_STRING
,
763 $params['is_email_receipt'] = [
764 'title' => 'Send email Receipt?',
765 'type' => CRM_Utils_Type
::T_BOOLEAN
,
767 $params['contribution_status_id'] = [
768 'title' => 'Contribution Status ID',
769 'name' => 'contribution_status_id',
770 'type' => CRM_Utils_Type
::T_INT
,
771 'pseudoconstant' => [
772 'optionGroupName' => 'contribution_status',
774 'api.required' => TRUE,
776 $params['receive_date'] = [
777 'title' => 'Contribution Receive Date',
778 'name' => 'receive_date',
779 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
780 'api.default' => 'now',
782 $params['trxn_id'] = [
783 'title' => 'Transaction ID',
785 'type' => CRM_Utils_Type
::T_STRING
,
787 $params['campaign_id'] = [
788 'title' => 'Campaign ID',
789 'name' => 'campaign_id',
790 'type' => CRM_Utils_Type
::T_INT
,
791 'pseudoconstant' => [
792 'table' => 'civicrm_campaign',
794 'labelColumn' => 'title',
797 $params['financial_type_id'] = [
798 'title' => 'Financial ID (ignored if more than one line item)',
799 'name' => 'financial_type_id',
800 'type' => CRM_Utils_Type
::T_INT
,
801 'pseudoconstant' => [
802 'table' => 'civicrm_financial_type',
804 'labelColumn' => 'name',
807 $params['payment_processor_id'] = [
808 'description' => ts('Payment processor ID, will be loaded from contribution_recur if not provided'),
809 'title' => 'Payment processor ID',
810 'name' => 'payment_processor_id',
811 'type' => CRM_Utils_Type
::T_INT
,