add option to limit automatic unsuspensions to a specific suspension reason type...
[freeside.git] / bin / xmlrpc-order_package.php
1 #!/usr/bin/php5
2
3 <?php
4
5 $freeside = new FreesideAPI();
6
7 $result = $freeside->order_package( array(
8   'secret'          => 'sharingiscaring', #config setting api_shared_secret
9   'custnum'         => 619797,
10   'pkgpart'         => 2,
11
12   #the rest is optional
13   'quantity'        => 5,
14   'start_date'      => '12/1/2017',
15   'invoice_details' => [ 'detail', 'even more detail' ],
16   'address1'        => '5432 API Lane',
17   'city'            => 'API Town',
18   'state'           => 'AZ',
19   'zip'             => '54321',
20   'country'         => 'US',
21   'setup_fee'       => '23',
22   'recur_fee'       => '19000',
23 ));
24
25 var_dump($result);
26
27 #pre-php 5.4 compatible version?
28 function flatten($hash) {
29   if ( !is_array($hash) ) return $hash;
30   $flat = array();
31
32   array_walk($hash, function($value, $key, &$to) { 
33     array_push($to, $key, $value);
34   }, $flat);
35
36   if ( PHP_VERSION_ID >= 50400 ) {
37
38     #php 5.4+ (deb 7+)
39     foreach ($hash as $key => $value) {
40       $flat[] = $key;
41       $flat[] = $value;
42     }
43
44   }
45
46   return($flat);
47 }
48
49 class FreesideAPI  {
50
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/';
54
55     function FreesideAPI() {
56       $this;
57     }
58
59     public function __call($name, $arguments) {
60
61         error_log("[FreesideAPI] $name called, sending to ". $this->URL);
62
63         $request = xmlrpc_encode_request("FS.API.$name", flatten($arguments[0]));
64         $context = stream_context_create( array( 'http' => array(
65             'method' => "POST",
66             'header' => "Content-Type: text/xml",
67             'content' => $request
68         )));
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])");
73         } else {
74             //error_log("[FreesideAPI] $response");
75             return $response;
76         }
77     }
78
79 }
80
81 ?>