*/
function _civicrm_api3_contribute_format_params($params, &$values, $create = FALSE) {
//legacy way of formatting from v2 api - v3 way is to define metadata & do it in the api layer
- require_once 'api/v3/utils.php';
_civicrm_api3_filter_fields_for_bao('Contribution', $params, $values);
-
- foreach ($params as $key => $value) {
- // ignore empty values or empty arrays etc
- if (CRM_Utils_System::isNull($value)) {
- continue;
- }
- // note that this is legacy handling - these should be handled at the api layer
- switch ($key) {
- case 'financial_type' :// should be dealt with either api pseudoconstant in validate_integer fn
- $contributionTypeId = CRM_Utils_Array::key ( ucfirst ( $value ), CRM_Contribute_PseudoConstant::financialType() );
- if ($contributionTypeId) {
- if (CRM_Utils_Array::value('financial_type_id', $values) && $contributionTypeId != $values['financial_type_id']) {
- throw new Exception("Mismatched Financial Type and Financial Type Id");
- }
- $values ['financial_type_id'] = $contributionTypeId;
- }
- else {
- throw new Exception("Invalid Financial Type");
- }
- break;
-
- default:
- break;
- }
- }
-
return array();
}
$this->_checkFinancialRecords($contribution, 'offline');
$this->contributionGetnCheck($params, $contribution['id']);
}
- /*
- *
+ /**
+ * test create with valid payment instument
*/
function testCreateContributionWithPaymentInstrument() {
$params = $this->_params + array('payment_instrument' => 'EFT');
}
- /*
+ /**
* Function tests that additional financial records are created when online contribution is created
*/
function testCreateContributionOnline() {
$this->_checkFinancialRecords($contribution, 'online');
}
- /*
+ /**
+ * in the interests of removing financial type / contribution type checks from
+ * legacy format function lets test that the api is doing this for us
+ */
+ function testCreateInvalidFinancialType() {
+ $params = $this->_params;
+ $params['financial_type_id'] = 99999;
+ $result = $this->callAPIFailure($this->_entity, 'create', $params, "'99999' is not a valid option for field financial_type_id");
+ }
+
+ /**
* Function tests that additional financial records are created when online contribution with pay later option
* is created
*/