Skip to content

Instantly share code, notes, and snippets.

@benedict-w
Created January 23, 2013 11:58
Show Gist options
  • Save benedict-w/4604789 to your computer and use it in GitHub Desktop.
Save benedict-w/4604789 to your computer and use it in GitHub Desktop.
Neteven examples taken from Web Services Technical Guide v1.8_EN 21
<?php
/**
* May 2012 Web Services Technical Guide v1.8_EN 21
*
* Note: information must be encoded with utf8_encode function
*
* Library used: PHP5 SOAP library
* http://php.net/soap
*/
define('NETEVEN_URL', 'http://ws.neteven.com/NWS');
define('NETEVEN_NS', 'urn:NWS:examples');
/**
* Neteven account credentials
*/
define('NETEVEN_LOGIN', 'my_login');
define('NETEVEN_PASSWORD', 'my_password');
/**
* SOAP client creation
* -----------------------
* The second parameter is optional
*
* In this case, it allows to activate the visualisation of the last sent/received order received
* through the following operations :
*
* echo "<pre>Request:\n" . htmlspecialchars($client->__getLastRequest()) . "</pre>\n";
* echo "<pre>Response:\n" . htmlspecialchars($client->__getLastResponse()) . "</pre>\n";
*
* http://php.net/manual/en/function.soap-soapclient-construct.php
*/
$client = new SoapClient(NETEVEN_URL, array('trace' => 1));
/**
* Authentification
* ----------------
* 'createAuthentication' function encodes the login and password,
* for Neteven application,
* the result is placed in the SOAP client headers
*/
function createAuthentication($login, $password)
{
$seed = "*";
$stamp = date(DATE_ATOM);
$signature = base64_encode(md5(implode("/", array($login, $stamp, $seed, $password)), true));
return array(
'Method' => ' * ',
'Login' => $login,
'Seed' => $seed,
'Stamp' => $stamp,
'Signature' => $signature
);
}
$auth = createAuthentication(NETEVEN_LOGIN, NETEVEN_PASSWORD);
$client->__setSoapHeaders(new SoapHeader(NETEVEN_NS, "AuthenticationHeader", $auth));
/**
* Different methods call examples
* ------------------------------------------
* The sent/received parameters have to follow
* the structures defined in the service web WSDL
* (visible at the address http://ws.neteven.com/)
*
* These structures can be visualised
* by using the following command :
*
* var_dump($client->__getTypes());
*
* http://php.net/manual/en/function.soap-soapclient-gettypes.php
*/
/**
* Echo() (test method)
* ----------------------
* Sends back the character string that has been
* sent
*/
$params = array("EchoInput" => "Hello");
try {
$response = $client->Echo($params);
$message = $response->EchoOutput;
} catch (Exception $e) {
$message = null;
}
echo "<h2>Echo()</h2><pre>";
if (!is_null($message)) {
echo $message . "\n";
}
echo "</pre>";
/**
* TestConnection() (test method)
* --------------------------------
* Authentification test
*/
try {
$response = $client->TestConnection();
$message = $response->TestConnectionResult;
} catch (Exception $e) {
$message = null;
}
echo "<h2>TestConnection()</h2><pre>";
if (!is_null($message)) {
echo $message . "\n";
if ($message == 'Rejected') {
echo "Please check your login and password !";
}
}
echo "</pre>";
/**
* GetItems()
* --------------------------------
* Receiving products from the Inventory
*
* In the following example, the title of each product is displayed
*/
try {
$getItemsResponse = $client->GetItems();
$items = $getItemsResponse->items->InventoryItem;
} catch (Exception $e) {
$items = null;
}
// Example : the title of each product is displayed
echo "<h2>GetItems()</h2><pre>";
if (!is_null($items)) {
if (!is_array($items)) {
$items = array($items);
}
foreach ($items as $item) {
echo $item->Title . "\n";
}
}
echo "</pre>";
/**
* GetOrders()
* --------------------------------
* Receiving orders
*
* GetOrders() accepts the optional parameters :
* 'DateSaleFrom'
* 'DateSaleTo'
* 'DatePaymentFrom'
* 'DatePaymentTo'
*
* Here, the SKU of each sale
* since January 2007 is displayed
*/
$params = array("DateSaleFrom" => date(DATE_ATOM, mktime(0, 0, 0, 1, 1, 2007)));
try {
$getOrdersResponse = $client->GetOrders($params);
$orders = $getOrdersResponse->GetOrdersResult->MarketPlaceOrder;
} catch (Exception $e) {
$orders = null;
}
// Example : SKU of each sale since January 2007 is displayed
echo "<h2>GetOrders()</h2><pre>";
if (!is_null($orders)) {
if (!is_array($orders)) {
$orders = array($orders);
}
foreach ($orders as $order) {
echo $order->SKU . "\n";
}
}
echo "</pre>";
/**
* PostItems()
* --------------------------------
* Adding products to the inventory
*
* Hereunder, 2 products are added
* (only the mandatory fields are filled)
* the operation status is displayed for each product
*
* Important remark :
* When adding a large inventory file,
* for performance reason, please send your products by batch of 100
*/
$item1 = array(
"Title" => 'Test',
"SKU" => '0123ABCD',
"PartNumber" => 'EFGH4567',
"Quantity" => 10,
"PriceFixed" => 10,
"Description" => "<p><b>Test description</b></p>",
"ArrayOfSpecificFields" => array(
array("Name" => "couleur", "Value" => "Blue"),
array("Name" => "type_1", "Value" => "Shirt")
)
);
$item2 = array(
"Title" => 'Test2',
"SKU" => '0123ABCD2',
"PartNumber" => 'EFGH45672',
"Quantity" => 10,
"PriceFixed" => 10,
"Description" => "<p><b>Test2 description</b></p>",
"ArrayOfSpecificFields" => array(
array("Name" => "couleur", "Value" => "Blue"),
array("Name" => "type_1", "Value" => "Shirt")
)
);
$params = array("items" => array($item1, $item2));
try {
$response = $client->PostItems($params);
$itemsStatus = $response->PostItemsResult->InventoryItemStatusResponse;
} catch (Exception $e) {
$itemsStatus = null;
}
echo "<h2>PostItems()</h2><pre>";
if (!is_null($itemsStatus)) {
if (!is_array($itemsStatus)) {
$itemsStatus = array($itemsStatus);
}
foreach ($itemsStatus as $itemStatus) {
echo $itemStatus->StatusResponse . "\n";
}
}
echo "</pre>";
/**
* PostOrders()
* --------------------------------
* Update orders in your account
*
* in the following example, an order is updated
* (the madatory fields are 'ID' and 'CustomerId')
* the operation status is displayed
*/
$order = array(
"OrderID" => 123456,
"CustomerId" => 456789,
"TrackingNumber" => "89IJKL00"
);
$params = array("orders" => array($order));
try {
$response = $client->PostOrders($params);
$ordersStatus = $response->PostOrdersResult->MarketPlaceOrderStatusResponse;
} catch (Exception $e) {
$ordersStatus = null;
}
echo "<h2>PostOrders()</h2><pre>";
if (!is_null($ordersStatus)) {
if (!is_array($ordersStatus)) {
$ordersStatus = array($ordersStatus);
}
foreach ($ordersStatus as $orderStatus) {
echo $orderStatus->StatusResponse . "\n";
}
}
;
echo "</pre>";
/* DEBUG */
echo "<hr />";
echo "<pre>Last request:\n" . htmlspecialchars($client->__getLastRequest()) . "</pre>\n";
echo "<pre>Last response:\n" . htmlspecialchars($client->__getLastResponse()) . "</pre>\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment