OneShopNotificationListener.php

From Developer's API

(Difference between revisions)
 
Line 3: Line 3:
 
     include('../Library/OneShopAPI.php');
 
     include('../Library/OneShopAPI.php');
  
     #TODO: Add your Merchant Id as first parameter and Merchant Key as second parameter   
+
     # TODO: Add your Merchant ID as the First Parameter, and your Merchant Key as Second Parameter.
 
     $API = new OneShopAPI("","","https://www.mcssl.com");
 
     $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)
 
     {
 
     {
        #TODO: Verify syntax to get the node name of the domdocument
 
 
         $notificationType = $requestBodyXML->documentElement->nodeName;   
 
         $notificationType = $requestBodyXML->documentElement->nodeName;   
 
         $tokenNode = $requestBodyXML->getElementsByTagName('Token')->item(0)->nodeValue;   
 
         $tokenNode = $requestBodyXML->getElementsByTagName('Token')->item(0)->nodeValue;   
Line 24: 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 32: 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 apiResultXML                         
+
                 # TODO: Do something useful with the XML                       
 
             }
 
             }
 
             else
 
             else
 
             {
 
             {
                #TODO: Alert or log that the API returned a success of false
+
# TODO: Do something with the error returned by the API
 
             }
 
             }
 
         }
 
         }
 
         else
 
         else
 
         {
 
         {
             #TODO: Do something with the xmlErr to either notify or log that the XML could not be parsed             
+
             # 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 xmlErr to either notify or log that the XML could not be parsed
+
         # 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	
    }            
?>