[freeside-commits] freeside/fs_selfservice/php freeside.class.php, NONE, 1.1 freeside.login_example.php, NONE, 1.1 freeside_signup_example.php, NONE, 1.1
Ivan,,,
ivan at wavetail.420.am
Sat Oct 13 18:51:09 PDT 2007
Update of /home/cvs/cvsroot/freeside/fs_selfservice/php
In directory wavetail:/tmp/cvs-serv668
Added Files:
freeside.class.php freeside.login_example.php
freeside_signup_example.php
Log Message:
adding php examples
--- NEW FILE: freeside_signup_example.php ---
<?
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
}
?>
--- NEW FILE: freeside.login_example.php ---
<?
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
}
?>
--- NEW FILE: freeside.class.php ---
<?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;
}
}
}
?>
More information about the freeside-commits
mailing list