OneShopNotificationListener.php
From Developer's API
(Difference between revisions)
(One intermediate revision by one user not shown) | |||
Line 2: | Line 2: | ||
<?php | <?php | ||
include('../Library/OneShopAPI.php'); | include('../Library/OneShopAPI.php'); | ||
− | + | ||
− | $API = new OneShopAPI(" | + | # TODO: Add your Merchant ID as the First Parameter, and your Merchant Key as Second Parameter. |
+ | $API = new OneShopAPI("","","https://www.mcssl.com"); | ||
$requestBodyXML = new DOMDocument(); | $requestBodyXML = new DOMDocument(); | ||
− | #Load the request body into XML and check that the result has been parsed into XML | + | # Load the request body into XML and check that the result has been parsed into XML |
− | + | ||
if ($requestBodyXML->loadXML($HTTP_RAW_POST_DATA) == true) | if ($requestBodyXML->loadXML($HTTP_RAW_POST_DATA) == true) | ||
{ | { | ||
− | |||
$notificationType = $requestBodyXML->documentElement->nodeName; | $notificationType = $requestBodyXML->documentElement->nodeName; | ||
$tokenNode = $requestBodyXML->getElementsByTagName('Token')->item(0)->nodeValue; | $tokenNode = $requestBodyXML->getElementsByTagName('Token')->item(0)->nodeValue; | ||
Line 23: | Line 22: | ||
default: | default: | ||
− | #May have other types of notifications in the future | + | # May have other types of notifications in the future |
break; | break; | ||
} | } | ||
Line 31: | Line 30: | ||
if ($apiResultXML->loadXML($apiResult)==true) | if ($apiResultXML->loadXML($apiResult)==true) | ||
{ | { | ||
− | #Check if the API returned an error | + | # Check if the API returned an error |
$apiSuccess = $apiResultXML->getElementsByTagName('Response')->item(0)->getAttribute('success'); | $apiSuccess = $apiResultXML->getElementsByTagName('Response')->item(0)->getAttribute('success'); | ||
if ($apiSuccess == 'true') | if ($apiSuccess == 'true') | ||
{ | { | ||
− | #TODO: Do something with the | + | # TODO: Do something useful with the XML |
} | } | ||
else | else | ||
{ | { | ||
− | + | # TODO: Do something with the error returned by the API | |
} | } | ||
} | } | ||
else | else | ||
{ | { | ||
− | #TODO: Do something with the | + | # TODO: Do something with the xml error to either notify or log that the XML could not be parsed |
} | } | ||
} | } | ||
else | else | ||
{ | { | ||
− | #TODO: Do something with the | + | # TODO: Do something with the xml error to either notify or log that the XML could not be parsed |
} | } | ||
?> | ?> | ||
</pre> | </pre> |
Latest revision as of 14:12, 29 May 2008
<?php include('../Library/OneShopAPI.php'); # TODO: Add your Merchant ID as the First Parameter, and your Merchant Key as Second Parameter. $API = new OneShopAPI("","","https://www.mcssl.com"); $requestBodyXML = new DOMDocument(); # Load the request body into XML and check that the result has been parsed into XML if ($requestBodyXML->loadXML($HTTP_RAW_POST_DATA) == true) { $notificationType = $requestBodyXML->documentElement->nodeName; $tokenNode = $requestBodyXML->getElementsByTagName('Token')->item(0)->nodeValue; switch ($notificationType) { case "NewOrder": $apiResult = $API->GetOrderById($tokenNode); break; default: # May have other types of notifications in the future break; } $apiResultXML = new DOMDocument(); if ($apiResultXML->loadXML($apiResult)==true) { # Check if the API returned an error $apiSuccess = $apiResultXML->getElementsByTagName('Response')->item(0)->getAttribute('success'); if ($apiSuccess == 'true') { # TODO: Do something useful with the XML } else { # TODO: Do something with the error returned by the API } } else { # TODO: Do something with the xml error to either notify or log that the XML could not be parsed } } else { # TODO: Do something with the xml error to either notify or log that the XML could not be parsed } ?>