findPayments

Searching for payments

Three files are required to search for payments:

  • a file for the functions "function.php".

  • a file for defining objects "v5.php".

  • findPayments file (operation):
    <?php
    include_once 'v5.php'; 	// File containing the definition of different objects 
    include_once 'function.php';// File containing all the useful functions (generation of the uuid, etc.)
    
    
    //Intialization of variables
    $shopId = "12345678";
    $key = "1234567891234567";	
    $mode = "TEST";
    $wsdl = "https://paiement.systempay.fr/vads-ws/v5?wsdl";
    
    //Example of Initialisation of a SOAP client with SNI management
    		/*
    		$client = new soapClient($wsdl,	
    		$options = array('trace'=>1, 'exceptions'=> 0, 			
    					'encoding' => 'UTF-8','soapaction' => '',
    					'uri' => 'http://v5.ws.vads.lyra.com/',	            
    					'cache_wsdl' => WSDL_CACHE_NONE, 
    					//Proxy parameters
    					'proxy_host' => 'my.proxy.host',
    					'proxy_port' => 3128,
    					'stream_context' => stream_context_create (array('ssl' => array(                               
    								'SNI_enabled' => true,
    								'SNI_server_name' => 'paiement.systempay.fr')))
    					));
    		*/	
    
    //Example of Initialization of a SOAP client without proxy		
    		$client = new soapClient($wsdl, $options = array(
    					'trace'=>1, 
    					'exceptions'=> 0, 			
    					'encoding' => 'UTF-8',
    					'soapaction' => '')
    				);
    
    //Generating a header
    			$requestId = gen_uuid ();
    			$timestamp = gmdate ( "Y-m-d\TH:i:s\Z" );			
    			$authToken = base64_encode(hash_hmac('sha256',$requestId.$timestamp, $key, true));			
    			setHeaders ($shopId, $requestId, $timestamp, $mode, $authToken, $key, $client);
    
    //Generating a body
    $queryRequest = new queryRequest;
    	$queryRequest->orderId ="myOrder";
    
    try {
    		
    		
    		
    		$findPaymentsRequest = new findPayments;
    
    			$findPaymentsRequest->queryRequest = $queryRequest; 
    		
    			$findPaymentsResponse = $client->findPayments($findPaymentsRequest);
    	} catch (SoapFault $fault) {
    
    //Managing exceptions		
    	trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
    				 }
    	
    		/* Displaying XML logs that must be replaced in a log file.	
    		 *
    		 * WARNING DO NOT REGISTER CARD NUMBERS IN YOUR LOGS
    		 */
    			echo "<hr> [Request Header] <br/>", htmlspecialchars($client->__getLastRequestHeaders()), "<br/>";
    			echo "<hr> [Request] <br/>", htmlspecialchars($client->__getLastRequest()), "<br/>";	
    			echo "<hr> [Response Header]<br/>", htmlspecialchars($client->__getLastResponseHeaders()), "<br/>";
    			echo "<hr> [Response]<br/>", htmlspecialchars($client->__getLastResponse()), "<br/>";
    			echo '<hr>';			
    			echo "<hr> [Response SOAP Headers]<br/>";
    
    //Response analysis
    	//Retrieving the SOAP Header of the response to store the headers in a table (here $responseHeader)	
    		$dom = new DOMDocument;
            $dom->loadXML($client->__getLastResponse(), LIBXML_NOWARNING);
            $path = new DOMXPath($dom);
            $headers = $path->query('//*[local-name()="Header"]/*');			
    		$responseHeader = array();				
    		foreach($headers as $headerItem) {			
    			$responseHeader[$headerItem->nodeName] = $headerItem->nodeValue;				
    		}	
    	
    //Computation of the authentication token of the response				
    		$authTokenResponse = base64_encode(hash_hmac('sha256',$responseHeader['timestamp'].$responseHeader['requestId'], $key, true));			
    		if ($authTokenResponse !== $responseHeader['authToken']){			
    			//Computation error or attempted fraud			
    				echo 'Internal error';
    		}
    		else{		
    			//Response analysis
    				if ($createPaymentResponse->createPaymentResult->commonResponse->responseCode != "0"){				
    				//process error				
    				}
    				else{
    				//Process successfully completed					
    					//Checking the presence of the transactionStatusLabel:
    			if (isset ($findPaymentsResponse->findPaymentsResult->commonResponse->transactionStatusLabel)){
    				//The card is not enrolled or 3DS deactivated
    									
    					// The payment is accepted	
    					switch ($findPaymentsResponse->findPaymentsResult->commonResponse->transactionStatusLabel) {
    					
    						case "AUTHORISED":
    							echo "payment accepted";
    									break;
    									case "WAITING_AUTHORISATION":
    							echo "payment accepted";
    									break;
    									case "AUTHORISED_TO_VALIDATE":
    							echo "payment accepted";
    									break;
    									case "WAITING_AUTHORISATION_TO_VALIDATE":
    							echo "payment accepted";
    									break;							
    								// The payment is declined							
    									default:
    							echo "payment declined";
    									break;									
    								}						
    					}
    					else{			
    					// if absent = the transaction has not been created, we are in the case of an enrolled card
    					// we move on to generating the  3DS redirection form
    						
    						//we retrieve the session id for maintaining the session during the analysis of the response from the ACS
    						$cookie = getJsessionId($client);
    						
    						// we store the session id in the MD field.