tbusainvoicegen/api/v3/Invoicegen/Generate.php
2019-06-28 16:54:40 -04:00

43 lines
1.4 KiB
PHP

<?php
use CRM_Tbusainvoicegen_ExtensionUtil as E;
/**
* Invoicegen.Generate API specification (optional)
* This is used for documentation and validation.
*
* @param array $spec description of fields supported by this API call
* @return void
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
*/
function _civicrm_api3_invoicegen_Generate_spec(&$spec) {
$spec['magicword']['api.required'] = 1;
}
/**
* Invoicegen.Generate API
*
* @param array $params
* @return array API result descriptor
* @see civicrm_api3_create_success
* @see civicrm_api3_create_error
* @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);
}
}