adding php examples
authorivan <ivan>
Sun, 14 Oct 2007 01:51:07 +0000 (01:51 +0000)
committerivan <ivan>
Sun, 14 Oct 2007 01:51:07 +0000 (01:51 +0000)
fs_selfservice/php/freeside.class.php [new file with mode: 0644]
fs_selfservice/php/freeside.login_example.php [new file with mode: 0644]
fs_selfservice/php/freeside_signup_example.php [new file with mode: 0644]

diff --git a/fs_selfservice/php/freeside.class.php b/fs_selfservice/php/freeside.class.php
new file mode 100644 (file)
index 0000000..21e89b4
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+class FreesideSelfService  {
+
+    //Change this to match the location of your selfservice xmlrpc.cgi or daemon
+    var $URL = 'https://www.example.com/selfservice/xmlrpc.cgi';
+
+    function FreesideSelfService() {
+      $this;
+    }
+
+    public function __call($name, $arguments) {
+
+        error_log("[FreesideSelfService] $name called, sending to ". $this->URL);
+
+        $request = xmlrpc_encode_request("FS.SelfService.XMLRPC.$name", $arguments);
+        $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 (xmlrpc_is_fault($response)) {
+            trigger_error("[FreesideSelfService] XML-RPC communication error: $response[faultString] ($response[faultCode])");
+        } else {
+            //error_log("[FreesideSelfService] $response");
+            return $response;
+        }
+    }
+
+}
+
+?>
diff --git a/fs_selfservice/php/freeside.login_example.php b/fs_selfservice/php/freeside.login_example.php
new file mode 100644 (file)
index 0000000..69174a4
--- /dev/null
@@ -0,0 +1,37 @@
+<?
+
+require('freeside.class.php');
+$freeside = new FreesideSelfService();
+
+$domain = 'example.com';
+
+$response = $freeside->login( array( 
+  'username' => strtolower($_POST['username']),
+  'domain'   => $domain,
+  'password' => strtolower($_POST['password']),
+) );
+
+error_log("[login] received response from freeside: $response");
+$error = $response['error'];
+
+if ( ! $error ) {
+
+    // sucessful login
+
+    $session_id = $response['session_id'];
+
+    error_log("[login] logged into freeside with session_id=$session_id");
+
+    // store session id in your session store, to be used for other calls
+
+} else {
+
+    // unsucessful login
+
+    error_log("[login] error logging into freeside: $error");
+
+    // display error message to user
+
+}
+
+?>
diff --git a/fs_selfservice/php/freeside_signup_example.php b/fs_selfservice/php/freeside_signup_example.php
new file mode 100644 (file)
index 0000000..8b1dc19
--- /dev/null
@@ -0,0 +1,49 @@
+<?
+
+require('freeside.class.php');
+$freeside = new FreesideSelfService();
+
+$response = $freeside->new_customer( array(
+  'agentnum'       => 1,
+
+  'first'          => $_POST['first'],
+  'last'           => $_POST['last'],
+  'address1'       => $_POST['address1'],
+  'address2'       => $_POST['address2'],
+  'city'           => $_POST['city'],
+  'state'          => $_POST['state'],
+  'zip'            => $_POST['zip'],
+  'country'        => 'US',
+  'daytime'        => $_POST['daytime'],
+  'fax'            => $_POST['fax'],
+
+  'payby'          => 'BILL',
+  'invoicing_list' => $_POST['email'],
+
+  'pkgpart'        => 2,
+  'username'       => strtolower($_POST['username']),
+  '_password'      => strtolower($_POST['password'])
+) );
+
+error_log("[new_customer] received response from freeside: $response");
+$error = $response['error'];
+
+if ( ! $error ) {
+
+    // sucessful signup
+
+    $custnum = $response['custnum'];
+
+    error_log("[new_customer] signup up with custnum $custnum");
+
+} else {
+
+    // unsucessful signup
+
+    error_log("[new_customer] signup error:: $error");
+
+    // display error message to user
+
+}
+
+?>