This error is really frustrating and annoying. It only happens on the live server but works fine on the local server. I have drupal 7 site with civicrm installed. One of the key I am passing on the $params array is
$params['contribution_page_id'] = 3
. The data type that this paramer expects is an integer and I have tried casting it as an integer but does not work.
I am trying to create a contribution record but it throws the error while
$contribution = civicrm_api3('Contribution', 'create', $params);
Here it throws the error and I don't know why.
The full error goes like this
CiviCRM_API3_Exception: '3' is not a valid option for field contribution_page_id in civicrm_api3() (line 45 of /home/mysite/public_html/v2/sites/all/modules/civicrm/api/api.php).
So here is my full code
$params['contact_id'] = $attendee;
$params['event_id'] = $event_id;
$params['register_date'] = date('YmdHis');
$params['register_date_time'] =date('h:i A');
$params['role_id'] =1;
$params['status_id'] = 1;
$params['status_id'] = 1;
$params['fee_level'] = '';
$params['is_pay_later'] = 1;
$params['fee_amount'] = calculate_total();
$params['fee_currency'] = 'GBP';
$bao = new CRM_Event_BAO_Participant();
$participnt = $bao->create($params);
//add Contribution
$non_deductible_amount = round(calculate_total(),2);
$total_amount = round(calculate_total(),2);
$tax_amount = round(calculate_total_vat(),2);
if($non_deductible_amount == 0) {
$non_deductible_amount = 0;
}
if($total_amount == 0) {
$total_amount = 0;
}
if($tax_amount == 0) {
$tax_amount = 0;
}
$bao = new CRM_Contribute_BAO_Contribution();
$params = array();
$params['contact_id'] = $attendee;
$params['financial_type_id'] = 4;
$params['contribution_page_id'] = 3;
$params['currency'] = $params['currencyID'] = 'GBP'; /**/
$params['non_deductible_amount'] = $non_deductible_amount; /**/
$params['total_amount'] = $total_amount; /**/
$params['Source'] = 'Event Registration';
//$params['is_pay_later'] = 1;
$params['tax_amount'] = $tax_amount;
$params['contribution_status_id'] = 'Pending';
$params['skipLineItem'] =1;
//$contribution = $bao->create($params);
$params['invoice_id'] = md5(uniqid(rand(), TRUE));
$params['payment_processor'] = 1;
$params['is_test'] = 0;
$params['description'] = 'Event Registration payment';
$params['qfKey'] = md5(uniqid(rand(), TRUE));
$params['email'] = 'sanjok@hotmail.com';
//This is where it fails.
$contribution = civicrm_api3('Contribution', 'create', $params);
That is where if fails and spits out the error.