diff options
author | ivan <ivan> | 2007-10-14 01:51:07 +0000 |
---|---|---|
committer | ivan <ivan> | 2007-10-14 01:51:07 +0000 |
commit | 11d0e83387a26e2615ab6bd6c3d9be4c355d399b (patch) | |
tree | 0cd1c8e7f9159e900c763b88c11df1b3e344fa3b /fs_selfservice | |
parent | d6dbf288fd8ea42ebd5171d80817356248cf22ce (diff) |
adding php examples
Diffstat (limited to 'fs_selfservice')
-rw-r--r-- | fs_selfservice/php/freeside.class.php | 33 | ||||
-rw-r--r-- | fs_selfservice/php/freeside.login_example.php | 37 | ||||
-rw-r--r-- | fs_selfservice/php/freeside_signup_example.php | 49 |
3 files changed, 119 insertions, 0 deletions
diff --git a/fs_selfservice/php/freeside.class.php b/fs_selfservice/php/freeside.class.php new file mode 100644 index 000000000..21e89b47f --- /dev/null +++ b/fs_selfservice/php/freeside.class.php @@ -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 index 000000000..69174a40a --- /dev/null +++ b/fs_selfservice/php/freeside.login_example.php @@ -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 index 000000000..8b1dc193c --- /dev/null +++ b/fs_selfservice/php/freeside_signup_example.php @@ -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 + +} + +?> |