OneShopNotificationListener.php

From Developer's API

Revision as of 20:36, 28 May 2008 by Chrisn (Talk | contribs)
<?php
    include('../Library/OneShopAPI.php');

    #TODO: Add your Merchant Id as first parameter and 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)
    {
        #TODO: Verify syntax to get the node name of the domdocument
        $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 with the apiResultXML                          
            }
            else
            {
                #TODO: Alert or log that the API returned a success of false 
            }
        }
        else
        {
            #TODO: Do something with the xmlErr to either notify or log that the XML could not be parsed            
        }
    }
    else
    {
        #TODO: Do something with the xmlErr to either notify or log that the XML could not be parsed	
    }            
?>