diff options
author | Ivan Kohler <ivan@freeside.biz> | 2017-09-28 20:04:33 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2017-09-28 20:04:33 -0700 |
commit | 8202103585cb218da090f18a8f0ce71af4bada8e (patch) | |
tree | 2c916c5a083349a8fd6c97cdb50dc956a2793093 /bin | |
parent | 1bc76eeede2fcdea26a9e634409445626f53cdc9 (diff) |
new backoffice API to add a package, RT#77484
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/xmlrpc-order_package.php | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/bin/xmlrpc-order_package.php b/bin/xmlrpc-order_package.php new file mode 100755 index 000000000..fccf77a63 --- /dev/null +++ b/bin/xmlrpc-order_package.php @@ -0,0 +1,81 @@ +#!/usr/bin/php5 + +<?php + +$freeside = new FreesideAPI(); + +$result = $freeside->order_package( array( + 'secret' => 'sharingiscaring', #config setting api_shared_secret + 'custnum' => 619797, + 'pkgpart' => 2, + + #the rest is optional + 'quantity' => 5, + 'start_date' => '12/1/2017', + 'invoice_details' => [ 'detail', 'even more detail' ], + 'address1' => '5432 API Lane', + 'city' => 'API Town', + 'state' => 'AZ', + 'zip' => '54321', + 'country' => 'US', + 'setup_fee' => '23', + 'recur_fee' => '19000', +)); + +var_dump($result); + +#pre-php 5.4 compatible version? +function flatten($hash) { + if ( !is_array($hash) ) return $hash; + $flat = array(); + + array_walk($hash, function($value, $key, &$to) { + array_push($to, $key, $value); + }, $flat); + + if ( PHP_VERSION_ID >= 50400 ) { + + #php 5.4+ (deb 7+) + foreach ($hash as $key => $value) { + $flat[] = $key; + $flat[] = $value; + } + + } + + return($flat); +} + +class FreesideAPI { + + //Change this to match the location of your backoffice XML-RPC interface + #var $URL = 'https://localhost/selfservice/xmlrpc.cgi'; + var $URL = 'http://localhost:8008/'; + + function FreesideAPI() { + $this; + } + + public function __call($name, $arguments) { + + error_log("[FreesideAPI] $name called, sending to ". $this->URL); + + $request = xmlrpc_encode_request("FS.API.$name", flatten($arguments[0])); + $context = stream_context_create( array( 'http' => array( + 'method' => "POST", + 'header' => "Content-Type: text/xml", + 'content' => $request + ))); + $file = file_get_contents($this->URL, false, $context); + $response = xmlrpc_decode($file); + if (isset($response) && is_array($response) && xmlrpc_is_fault($response)) { + trigger_error("[FreesideAPI] XML-RPC communication error: $response[faultString] ($response[faultCode])"); + } else { + //error_log("[FreesideAPI] $response"); + return $response; + } + } + +} + +?> |