Developer

Read payment response

Follow

Response data comes encrypted as POST request to the Return URL registered in 2C2P PGW Dashboard.

Read Payment Response

Read POST message and decrypt response message
Transaction result will be posted to Merchant's Return URL
To setup Merchant's Return URL, Login to Merchant Dashboard, under Account / Options / Payment Result URL and SET 'Server-to-server 3DS API - Frontend return URL' & 'Server-to-server 3DS API - Backend return URL'.

URL Path Name Description
Server-to-server 3DS API - Frontend return URL User will be redirected to this URL when transaction completes to view transaction result page.
Server-to-server 3DS API - Backend return URL A duplicate record of transaction result will be sent to Merchant's backend URL for backend processing.
 
 

Read POST message

<?php 
	$response = $_REQUEST["paymentResponse"]; 

Decrypt response message

	include_once('pkcs7.php');
	$pkcs7 = new pkcs7();
	$response = $pkcs7->decrypt($response,"./keys/demo2.crt","./keys/demo2.pem","2c2p");   
	echo "Response:<br/><textarea style='width:100%;height:80px'>". $response."</textarea>"; 
?>

Complete Code

Copy & Paste below code to 'result.php' file, and put this file in your Web Server and register the URL in Merchant Dashboard as 'return URL'.

<?php 
	$response = $_REQUEST["paymentResponse"]; 
	
	include_once('pkcs7.php');
	$pkcs7 = new pkcs7();
	$response = $pkcs7->decrypt($response,"./keys/demo2.crt","./keys/demo2.pem","2c2p");   
	echo "Response:<br/><textarea style='width:100%;height:80px'>". $response."</textarea>"; 
?>

Copy & Paste below code to 'pkcs7.php' file, and put this file in your Web Server in the same folder as 'result.php'.

<?php 
Class pkcs7 { 
    function decrypt($text,$publickey,$privatekey,$password){
        $arr = str_split($text,64); $text = "";
        foreach($arr as $val) { $text .= $val."\n"; } 
        $text = "MIME-Version: 1.0
Content-Disposition: attachment; filename=\"smime.p7m\"
Content-Type: application/pkcs7-mime; smime-type=enveloped-data; name=\"smime.p7m\"
Content-Transfer-Encoding: base64

".$text;
        $text = rtrim($text,"\n");
        if(!file_exists( dirname(__FILE__)."/tmp/")) 
        { mkdir( dirname(__FILE__)."/tmp/"); } 
        $infilename = dirname(__FILE__)."/tmp/".time().".txt";
        $this->text_to_file($text,$infilename); 
        $outfilename = dirname(__FILE__)."/tmp/".time().".dec"; 
        $public = file_get_contents($publickey); 
        $private = array(file_get_contents($privatekey), $password); 
        if (openssl_pkcs7_decrypt($infilename, $outfilename, $public, $private)) {
            unlink($infilename);
            $content = file_get_contents($outfilename);
            unlink($outfilename);
            return $content;
        }
        else{
            unlink($outfilename);
            unlink($infilename);
            echo "DECRYPT FAIL";exit;
        }
    }
    
    private function text_to_file($text,$filename){
        if (!$handle = fopen($filename, 'w')) 
        { echo "Cannot open file ($filename)"; exit; }
        if (fwrite($handle, $text) === FALSE) 
        { echo "Cannot write to file ($filename)"; exit; }
    }
}
?>
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Please sign in to leave a comment.