+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
*/
/**
- * Add or update a contribution.
+ * Add or update a Contribution.
*
* @param array $params
* Input parameters.
throw new API_Exception($error['contribution_status_id']);
}
}
-
+ if (!empty($params['id']) && !empty($params['financial_type_id'])) {
+ $error = array();
+ CRM_Contribute_BAO_Contribution::checkFinancialTypeChange($params['financial_type_id'], $params['id'], $error);
+ if (array_key_exists('financial_type_id', $error)) {
+ throw new API_Exception($error['financial_type_id']);
+ }
+ }
_civicrm_api3_contribution_create_legacy_support_45($params);
// Make sure tax calculation is handled via api.
// field is called payment processor - not payment processor id but can only be one id so
// it seems likely someone will fix it up one day to be more consistent - lets alias it from the start
'api.aliases' => array('payment_processor_id'),
+ 'type' => CRM_Utils_Type::T_INT,
);
$params['financial_type_id']['api.aliases'] = array('contribution_type_id', 'contribution_type');
$params['financial_type_id']['api.required'] = 1;
}
/**
- * Delete a contribution.
+ * Delete a Contribution.
*
* @param array $params
* Input parameters.
function civicrm_api3_contribution_get($params) {
$mode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE;
- $entity = 'contribution';
- list($dao, $query) = _civicrm_api3_get_query_object($params, $mode, $entity);
+ list($dao, $query) = _civicrm_api3_get_query_object($params, $mode, 'Contribution');
$contribution = array();
while ($dao->fetch()) {
// format soft credit for backward compatibility
_civicrm_api3_format_soft_credit($contribution[$dao->contribution_id]);
}
- return civicrm_api3_create_success($contribution, $params, 'contribution', 'get', $dao);
+ return civicrm_api3_create_success($contribution, $params, 'Contribution', 'get', $dao);
}
/**
* Array of parameters determined by getfields.
*/
function _civicrm_api3_contribution_get_spec(&$params) {
- $params['contribution_test']['api.default'] = 0;
- $params['contribution_test']['title'] = 'Get Test Contributions?';
+ $params['contribution_test'] = array(
+ 'api.default' => 0,
+ 'type' => CRM_Utils_Type::T_BOOLEAN,
+ 'title' => 'Get Test Contributions?',
+ );
$params['financial_type_id']['api.aliases'] = array('contribution_type_id');
+ $params['payment_instrument_id']['api.aliases'] = array('contribution_payment_instrument', 'payment_instrument');
$params['contact_id'] = $params['contribution_contact_id'];
$params['contact_id']['api.aliases'] = array('contribution_contact_id');
unset($params['contribution_contact_id']);
* Array of parameters determined by getfields.
*/
function _civicrm_api3_contribution_transact_spec(&$params) {
- $fields = civicrm_api3('contribution', 'getfields', array('action' => 'create'));
+ $fields = civicrm_api3('Contribution', 'getfields', array('action' => 'create'));
$params = array_merge($params, $fields['values']);
$params['receive_date']['api.default'] = 'now';
}
$transaction = $payment->doPayment($params);
$params['payment_instrument_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType', $paymentProcessor['payment_processor_type_id'], 'payment_type') == 1 ? 'Credit Card' : 'Debit Card';
- return civicrm_api('contribution', 'create', $params);
+ return civicrm_api('Contribution', 'create', $params);
}
/**
$params['id'] = array(
'api.required' => 1,
'title' => '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 :-)',
+ 'type' => CRM_Utils_Type::T_STRING,
);
$params['receipt_from_name'] = array(
'title' => 'From Name (string)',
+ 'type' => CRM_Utils_Type::T_STRING,
);
$params['cc_receipt'] = array(
'title' => 'CC Email address (string)',
+ 'type' => CRM_Utils_Type::T_STRING,
);
$params['bcc_receipt'] = array(
'title' => 'BCC Email address (string)',
+ 'type' => CRM_Utils_Type::T_STRING,
);
$params['receipt_text'] = array(
'title' => 'Message (string)',
+ 'type' => CRM_Utils_Type::T_STRING,
);
}
'title' => 'Send email Receipt?',
'type' => CRM_Utils_Type::T_BOOLEAN,
);
+ $params['receipt_from_email'] = array(
+ 'title' => 'Email to send receipt from.',
+ 'description' => 'If not provided this will default to being based on domain mail or contribution page',
+ 'type' => CRM_Utils_Type::T_EMAIL,
+ );
+ $params['receipt_from_name'] = array(
+ 'title' => 'Name to send receipt from',
+ 'description' => '. If not provided this will default to domain mail or contribution page',
+ 'type' => CRM_Utils_Type::T_STRING,
+ );
}
/**
unset($contribution->id, $contribution->receive_date, $contribution->invoice_id);
$contribution->contribution_status_id = $params['contribution_status_id'];
$contribution->receive_date = $params['receive_date'];
- // Have not set trxn_id to required but an e-notice if not provided seems appropriate.
- $input['trxn_id'] = $params['trxn_id'];
+
+ $passThroughParams = array('trxn_id', 'total_amount', 'campaign_id', 'fee_amount');
+ $input = array_intersect_key($params, array_fill_keys($passThroughParams, NULL));
$params = _ipn_process_transaction($params, $contribution, $input, $ids, $original_contribution);
}
}
$input['component'] = $contribution->_component;
$input['is_test'] = $contribution->is_test;
- $input['amount'] = $contribution->total_amount;
+ $input['amount'] = empty($input['total_amount']) ? $contribution->total_amount : $input['total_amount'];
+
if (isset($params['is_email_receipt'])) {
$input['is_email_receipt'] = $params['is_email_receipt'];
}
+ if (empty($contribution->contribution_page_id)) {
+ static $domainFromName;
+ static $domainFromEmail;
+ if (empty($domainFromEmail) && (empty($params['receipt_from_name']) || empty($params['receipt_from_email']))) {
+ list($domainFromName, $domainFromEmail) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
+ }
+ $input['receipt_from_name'] = CRM_Utils_Array::value('receipt_from_name', $params, $domainFromName);
+ $input['receipt_from_email'] = CRM_Utils_Array::value('receipt_from_email', $params, $domainFromEmail);
+ }
// @todo required for base ipn but problematic as api layer handles this
$transaction = new CRM_Core_Transaction();
$ipn = new CRM_Core_Payment_BaseIPN();