api updated; can successfully calculate price now

This commit is contained in:
2019-06-28 17:30:27 -04:00
parent 84a8314761
commit f33b02dc20
2 changed files with 46 additions and 26 deletions

View File

@ -10,7 +10,8 @@ use CRM_Tbusainvoicegen_ExtensionUtil as E;
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
*/
function _civicrm_api3_invoicegen_Generate_spec(&$spec) {
$spec['magicword']['api.required'] = 1;
$spec['contact_id']['api.required'] = 0;
$spec['billing_period']['api.required'] = 0;
}
/**
@ -23,20 +24,6 @@ function _civicrm_api3_invoicegen_Generate_spec(&$spec) {
* @throws API_Exception
*/
function civicrm_api3_invoicegen_Generate($params) {
if (array_key_exists('magicword', $params) && $params['magicword'] == 'sesame') {
$returnValues = array(
// OK, return several data rows
12 => array('id' => 12, 'name' => 'Twelve'),
34 => array('id' => 34, 'name' => 'Thirty four'),
56 => array('id' => 56, 'name' => 'Fifty six'),
);
// ALTERNATIVE: $returnValues = array(); // OK, success
// ALTERNATIVE: $returnValues = array("Some value"); // OK, return a single value
// Spec: civicrm_api3_create_success($values = 1, $params = array(), $entity = NULL, $action = NULL)
return civicrm_api3_create_success($returnValues, $params, 'NewEntity', 'NewAction');
}
else {
throw new API_Exception(/*errorMessage*/ 'Everyone knows that the magicword is "sesame"', /*errorCode*/ 1234);
}
$returnValues = CRM_Tbusainvoicegen_Timebank::generate($params['contact_id'], $params['billing_period']);
return civicrm_api3_create_success($returnValues, $params, 'Invoicegen', 'generate');
}