5 $freeside = new FreesideAPI();
7 $result = $freeside->order_package( array(
8 'secret' => 'sharingiscaring', #config setting api_shared_secret
14 'start_date' => '12/1/2017',
15 'invoice_details' => [ 'detail', 'even more detail' ],
16 'address1' => '5432 API Lane',
22 'recur_fee' => '19000',
27 #pre-php 5.4 compatible version?
28 function flatten($hash) {
29 if ( !is_array($hash) ) return $hash;
32 array_walk($hash, function($value, $key, &$to) {
33 array_push($to, $key, $value);
36 if ( PHP_VERSION_ID >= 50400 ) {
39 foreach ($hash as $key => $value) {
51 //Change this to match the location of your backoffice XML-RPC interface
52 #var $URL = 'https://localhost/selfservice/xmlrpc.cgi';
53 var $URL = 'http://localhost:8008/';
55 function FreesideAPI() {
59 public function __call($name, $arguments) {
61 error_log("[FreesideAPI] $name called, sending to ". $this->URL);
63 $request = xmlrpc_encode_request("FS.API.$name", flatten($arguments[0]));
64 $context = stream_context_create( array( 'http' => array(
66 'header' => "Content-Type: text/xml",
69 $file = file_get_contents($this->URL, false, $context);
70 $response = xmlrpc_decode($file);
71 if (isset($response) && is_array($response) && xmlrpc_is_fault($response)) {
72 trigger_error("[FreesideAPI] XML-RPC communication error: $response[faultString] ($response[faultCode])");
74 //error_log("[FreesideAPI] $response");