OneShopNotificationListener.php

From Developer's API

(Difference between revisions)
(New page: <pre> <?php include('../Library/OneShopAPI.php'); $API = new OneShopAPI("80086","dfd9e90384e842d18c4ef74ed08a4673","http://localhost"); $requestBodyXML = new DOMDocum...)
 
Line 3: Line 3:
 
     include('../Library/OneShopAPI.php');
 
     include('../Library/OneShopAPI.php');
 
      
 
      
     $API = new OneShopAPI("80086","dfd9e90384e842d18c4ef74ed08a4673","http://localhost");
+
     $API = new OneShopAPI("118303","0","https://www.mcssl.com");
 
      
 
      
 
     $requestBodyXML = new DOMDocument();
 
     $requestBodyXML = new DOMDocument();

Revision as of 20:00, 26 May 2008

<?php
    include('../Library/OneShopAPI.php');
    
    $API = new OneShopAPI("118303","0","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	
    }            
?>