+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015 |
+ | Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
if (empty($params['id'])) {
- $op = 'add';
+ $op = CRM_Core_Action::ADD;
}
else {
if (empty($params['financial_type_id'])) {
- $params['financial_type_id'] = civicrm_api3('Contribution', 'getvalue', array(
- 'id' => $params['id'],
- 'return' => 'financial_type_id',
- ));
+ $params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $params['id'], 'financial_type_id');
}
- $op = 'edit';
+ $op = CRM_Core_Action::UPDATE;
}
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types, $op);
if (!in_array($params['financial_type_id'], array_keys($types))) {
_civicrm_api3_contribution_create_legacy_support_45($params);
// Make sure tax calculation is handled via api.
+ // @todo this belongs in the BAO NOT the api.
$params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Contribution');
$params['soft_credit_to'] = array(
'name' => 'soft_credit_to',
'title' => 'Soft Credit contact ID (legacy)',
- 'type' => 1,
+ 'type' => CRM_Utils_Type::T_INT,
'description' => 'ID of Contact to be Soft credited to (deprecated - use contribution_soft api)',
'FKClassName' => 'CRM_Contact_DAO_Contact',
);
$params['honor_contact_id'] = array(
'name' => 'honor_contact_id',
'title' => 'Honoree contact ID (legacy)',
- 'type' => 1,
+ 'type' => CRM_Utils_Type::T_INT,
'description' => 'ID of honoree contact (deprecated - use contribution_soft api)',
'FKClassName' => 'CRM_Contact_DAO_Contact',
);
$params['honor_type_id'] = array(
'name' => 'honor_type_id',
'title' => 'Honoree Type (legacy)',
- 'type' => 1,
+ 'type' => CRM_Utils_Type::T_INT,
'description' => 'Type of honoree contact (deprecated - use contribution_soft api)',
'pseudoconstant' => TRUE,
);
);
$params['batch_id'] = array(
'title' => 'Batch',
- 'type' => 1,
+ 'type' => CRM_Utils_Type::T_INT,
'description' => 'Batch which relevant transactions should be added to',
);
+ $params['refund_trxn_id'] = array(
+ 'title' => 'Refund Transaction ID',
+ 'type' => CRM_Utils_Type::T_STRING,
+ 'description' => 'Transaction ID specific to the refund taking place',
+ );
}
/**
function civicrm_api3_contribution_get($params) {
$mode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE;
- list($dao, $query) = _civicrm_api3_get_query_object($params, $mode, 'Contribution');
-
- $contribution = array();
- while ($dao->fetch()) {
- //CRM-8662
- $contribution_details = $query->store($dao);
- $softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($dao->contribution_id, TRUE);
- $contribution[$dao->contribution_id] = array_merge($contribution_details, $softContribution);
+ $returnProperties = CRM_Contribute_BAO_Query::defaultReturnProperties($mode);
+
+ $contributions = _civicrm_api3_get_using_query_object('Contribution', $params, array(), NULL, $mode, $returnProperties);
+
+ foreach ($contributions as $id => $contribution) {
+ $softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($id, TRUE);
+ $contributions[$id] = array_merge($contribution, $softContribution);
// format soft credit for backward compatibility
- _civicrm_api3_format_soft_credit($contribution[$dao->contribution_id]);
+ _civicrm_api3_format_soft_credit($contributions[$id]);
}
- return civicrm_api3_create_success($contribution, $params, 'Contribution', 'get', $dao);
+ return civicrm_api3_create_success($contributions, $params, 'Contribution', 'get');
+}
+
+/**
+ * Get number of contacts matching the supplied criteria.
+ *
+ * @param array $params
+ *
+ * @return int
+ */
+function civicrm_api3_contribution_getcount($params) {
+ $count = _civicrm_api3_get_using_query_object('Contribution', $params, array(), TRUE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE);
+ return (int) $count;
}
/**
* @throws Exception
*/
function civicrm_api3_contribution_sendconfirmation($params) {
- $contribution = new CRM_Contribute_BAO_Contribution();
- $contribution->id = $params['id'];
- if (!$contribution->find(TRUE)) {
- throw new Exception('Contribution does not exist');
+ $input = $ids = $values = array();
+ $passThroughParams = array(
+ 'receipt_from_email',
+ 'receipt_from_name',
+ 'receipt_update',
+ 'cc_receipt',
+ 'bcc_receipt',
+ 'receipt_text',
+ 'payment_processor_id',
+ );
+ foreach ($passThroughParams as $key) {
+ if (isset($params[$key])) {
+ $input[$key] = $params[$key];
+ }
}
- $input = $ids = $cvalues = array('receipt_from_email' => $params['receipt_from_email']);
- $contribution->loadRelatedObjects($input, $ids, TRUE);
- $contribution->composeMessageArray($input, $ids, $cvalues, FALSE, FALSE);
+ CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $params['id'], $values);
}
/**
function _civicrm_api3_contribution_sendconfirmation_spec(&$params) {
$params['id'] = array(
'api.required' => 1,
- 'title' => 'Contribution ID',
+ 'title' => ts('Contribution ID'),
'type' => CRM_Utils_Type::T_INT,
);
$params['receipt_from_email'] = array(
- 'api.required' => 1,
- 'title' => 'From Email address (string) required until someone provides a patch :-)',
+ 'title' => ts('From Email address (string)'),
'type' => CRM_Utils_Type::T_STRING,
);
$params['receipt_from_name'] = array(
- 'title' => 'From Name (string)',
+ 'title' => ts('From Name (string)'),
'type' => CRM_Utils_Type::T_STRING,
);
$params['cc_receipt'] = array(
- 'title' => 'CC Email address (string)',
+ 'title' => ts('CC Email address (string)'),
'type' => CRM_Utils_Type::T_STRING,
);
$params['bcc_receipt'] = array(
- 'title' => 'BCC Email address (string)',
+ 'title' => ts('BCC Email address (string)'),
'type' => CRM_Utils_Type::T_STRING,
);
$params['receipt_text'] = array(
- 'title' => 'Message (string)',
+ 'title' => ts('Message (string)'),
'type' => CRM_Utils_Type::T_STRING,
);
+ $params['receipt_update'] = array(
+ 'title' => ts('Update the Receipt Date'),
+ 'type' => CRM_Utils_Type::T_BOOLEAN,
+ 'api.default' => TRUE,
+ );
+ $params['payment_processor_id'] = array(
+ 'title' => ts('Payment processor Id (avoids mis-guesses)'),
+ 'type' => CRM_Utils_Type::T_INT,
+ );
}
/**
* @param array $params
* Input parameters.
*
- * @throws API_Exception
- * Api result array.
+ * @return array
+ * API result array
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
+ * @throws \Exception
*/
function civicrm_api3_contribution_completetransaction(&$params) {
if (!empty($params['fee_amount'])) {
$input['fee_amount'] = $params['fee_amount'];
}
- $params = _ipn_process_transaction($params, $contribution, $input, $ids);
+ return _ipn_process_transaction($params, $contribution, $input, $ids);
}
*/
function civicrm_api3_contribution_repeattransaction(&$params) {
$input = $ids = array();
+ civicrm_api3_verify_one_mandatory($params, NULL, array('contribution_recur_id', 'original_contribution_id'));
+ if (empty($params['original_contribution_id'])) {
+ $params['original_contribution_id'] = civicrm_api3('contribution', 'getvalue', array(
+ 'return' => 'id',
+ 'contribution_recur_id' => $params['contribution_recur_id'],
+ 'options' => array('limit' => 1, 'sort' => 'id DESC'),
+ ));
+ }
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $params['original_contribution_id'];
if (!$contribution->find(TRUE)) {
}
unset($contribution->id, $contribution->receive_date, $contribution->invoice_id);
- $contribution->contribution_status_id = $params['contribution_status_id'];
$contribution->receive_date = $params['receive_date'];
- $passThroughParams = array('trxn_id', 'total_amount', 'campaign_id', 'fee_amount');
+ $passThroughParams = array(
+ 'trxn_id',
+ 'total_amount',
+ 'campaign_id',
+ 'fee_amount',
+ 'financial_type_id',
+ 'contribution_status_id',
+ );
$input = array_intersect_key($params, array_fill_keys($passThroughParams, NULL));
- $params = _ipn_process_transaction($params, $contribution, $input, $ids, $original_contribution);
+ return _ipn_process_transaction($params, $contribution, $input, $ids, $original_contribution);
}
catch(Exception $e) {
throw new API_Exception('failed to load related objects' . $e->getMessage() . "\n" . $e->getTraceAsString());
$input['receipt_from_email'] = CRM_Utils_Array::value('receipt_from_email', $params, $domainFromEmail);
}
$transaction = new CRM_Core_Transaction();
- CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects, $transaction, !empty($contribution->contribution_recur_id), $contribution,
+ return CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects, $transaction, !empty
+ ($contribution->contribution_recur_id), $contribution,
FALSE, FALSE);
- return $params;
}
/**
function _civicrm_api3_contribution_repeattransaction_spec(&$params) {
$params['original_contribution_id'] = array(
'title' => 'Original Contribution ID',
+ 'description' => 'Contribution ID to copy (will be calculated from recurring contribution if not provided)',
+ 'type' => CRM_Utils_Type::T_INT,
+ );
+ $params['contribution_recur_id'] = array(
+ 'title' => 'Recurring contribution ID',
'type' => CRM_Utils_Type::T_INT,
- 'api.required' => TRUE,
);
$params['trxn_id'] = array(
'title' => 'Transaction ID',
'name' => 'trxn_id',
'type' => CRM_Utils_Type::T_STRING,
);
+ $params['campaign_id'] = array(
+ 'title' => 'Campaign ID',
+ 'name' => 'campaign_id',
+ 'type' => CRM_Utils_Type::T_INT,
+ 'pseudoconstant' => array(
+ 'table' => 'civicrm_campaign',
+ 'keyColumn' => 'id',
+ 'labelColumn' => 'title',
+ ),
+ );
+ $params['financial_type_id'] = array(
+ 'title' => 'Financial ID (ignored if more than one line item)',
+ 'name' => 'financial_type_id',
+ 'type' => CRM_Utils_Type::T_INT,
+ 'pseudoconstant' => array(
+ 'table' => 'civicrm_financial_type',
+ 'keyColumn' => 'id',
+ 'labelColumn' => 'name',
+ ),
+ );
$params['payment_processor_id'] = array(
'description' => ts('Payment processor ID, will be loaded from contribution_recur if not provided'),
'title' => 'Payment processor ID',