Skip to content

Instantly share code, notes, and snippets.

@tvlooy
Created May 31, 2012 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tvlooy/2845144 to your computer and use it in GitHub Desktop.
Save tvlooy/2845144 to your computer and use it in GitHub Desktop.
Rentplus SOAP proof of concept
<?php
class XmlSerializer {
private static $xmlns = 'www.rentplus.be/webservices/';
public static function toXml($obj) {
$class = get_class($obj);
$xml = '<?xml version="1.0" standalone="yes"?>' .
'<ds' . $class . ' xmlns="' . self::$xmlns . $class . '.xsd">' .
self::serialize($obj) .
'</ds' . $class . '>';
return $xml;
}
private static function serialize($obj) {
$xml = '';
$endClass = '';
if (is_object($obj)) {
$class = get_class($obj);
$xml = '<' . $class . '>';
$endClass = '</' . $class . '>';
}
foreach ($obj as $key => $val) {
if ($val instanceof DateTime) {
$val = $val->format('Y-m-d\TH:i:sP');
} else if (is_array($val)) {
$subXml = '';
foreach ($val as $subval) {
$subXml .= self::serialize($subval);
}
$val = $subXml;
}
$xml .= "<" . $key . ">" . $val . "</" . $key . ">";
}
return $xml . $endClass;
}
}
require_once('lib/nusoap.php');
$client = new nusoap_client('http://194.78.38.141/RentplusWebServices2/RentPlusServices.asmx?wsdl', 'wsdl');
// Get customer list is OK
$list = @$client->call('GetCustomerList', array());
print_r($list);
// Get customer info is OK
$list = @$client->call('GetCustomerInfo', array('customerKey' => '12292', 'Venture_Number' => '0587636193'));
$customer = $list['GetCustomerInfoResult']['diffgram']['dsCustomerInfo']['CustomerInfo'];
print_r($customer);
// GetOrderPrice is OK
class Order extends stdClass {}
class OrderLine extends stdClass {}
$orderLine = new OrderLine();
$orderLine->Article_Key = 'KKDI006';
$orderLine->Number = '2';
$order = new Order();
$order->Customer_Venture_Number = '0451740381';
$order->Date_Period_Out = new DateTime('2008-09-18T00:00:00+01:00');
$order->Date_Period_In = new DateTime('2008-09-22T00:00:00+01:00');
$order->Date_Availibility_Out = new DateTime('2008-09-18T00:00:00+01:00');
$order->Date_Availibility_In = new DateTime('2008-09-22T00:00:00+01:00');
$order->OrderLines[] = $orderLine;
//echo XmlSerializer::toXml($order);
$orderPrice = @$client->call('GetOrderPrice', array('param' => XmlSerializer::toXml($order)));
print_r($orderPrice);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment