Developer

Submit payment request (S2B)

Follow

Server to Browser (S2B) Integration support 3DS and Non-3DS transactions

Prepare Payment Request

Set account credentials

<?php 
	//Merchant's account information
	$merchantID = "JT01";		//Get MerchantID when opening account with 2C2P
	$secretKey = "7jYcp4FxFdf0";	//Get SecretKey from 2C2P PGW Dashboard

Set transaction information

	//Transaction Information
	$desc = "2 days 1 night hotel room";
	$uniqueTransactionCode = time();
	$currencyCode = "702";
	$amt  = "000000000010";
	$panCountry = "SG";

	//Customer Information
	$cardholderName = "John Doe";

Set encrypted card data

	//Encrypted card data
	$encCardData = $_POST['encryptedCardInfo'];

	//Retrieve card information for merchant use if needed
	$maskedCardNo = $_POST['maskedCardInfo'];
	$expMonth = $_POST['expMonthCardInfo'];
	$expYear = $_POST['expYearCardInfo'];

Merchant's backend code will receive credit card details encrypted.

"encryptedCardInfo" => "00acTPCs4oy2P52nolDsjc9FabG5/p6OqMzISvh8glP+qb5YgD7z7wCayBp9QW66CtAFENvqW/zZTgDBSKM8qz0W6sFx4TO6Uww58ar//VvDc5+OUz+JIAlQCPhewZN8IznxlyaBFvFLpvi+VugaUWo/Eow6kYalVuIj0MYg8OAccgU=U2FsdGVkX18jR/eUn9PmDT3MSuD3cmgWSovAztlaIPaE52l+fl3SJkU2+UhgJxZL"

Posted information to backend code

Variable name  Description 
 encryptedCardInfo  Encrypted card data to be sent to 2C2P PGW
 maskedCardInfo  Masked card number (first 6 and last 4 digit of the credit card)
 expMonthCardInfo  Card expiry month
 expYearCardInfo  Card expiry year

 

Set payment request information

	//Request Information 
	$version = "9.3";  
 
	//Construct signature string
	$stringToHash = $version.$merchantID.$uniqueTransactionCode.$desc.$amt.$currencyCode.$panCountry.$cardholderName.$encCardData;
	$hash = strtoupper(hash_hmac('sha1', $stringToHash ,$secretKey, false));	//Compute hash value

Construct payment request message

	//Construct payment request message
	$xml = "<PaymentRequest>
		<version>$version</version> 
		<merchantID>$merchantID</merchantID>
		<uniqueTransactionCode>$uniqueTransactionCode</uniqueTransactionCode>
		<desc>$desc</desc>
		<amt>$amt</amt>
		<currencyCode>$currencyCode</currencyCode>  
		<panCountry>$panCountry</panCountry> 
		<cardholderName>$cardholderName</cardholderName>
		<encCardData>$encCardData</encCardData>
		<secureHash>$hash</secureHash>
		</PaymentRequest>"; 
	$payload = base64_encode($xml);	//Convert payload to base64  
?>

Submit payment request form

<form action='https://demo2.2c2p.com/2C2PFrontEnd/SecurePayment/PaymentAuth.aspx' method='POST' name='paymentRequestForm'>
	Processing payment request, Do not close the browser, press back or refresh the page. 
	<?php echo "<input type='hidden' name='paymentRequest' value='".$payload."'>"; ?>
</form>
<script language="JavaScript">
	document.paymentRequestForm.submit();	//submit form to 2c2p PGW
</script>

Complete Code
Copy & Paste below code to 'payment_3d.php' file, and put this file in your Web Server.

<?php 
	//Merchant's account information
	$merchantID = "JT01";		//Get MerchantID when opening account with 2C2P
	$secretKey = "7jYcp4FxFdf0";	//Get SecretKey from 2C2P PGW Dashboard

	//Transaction Information
	$desc = "2 days 1 night hotel room";
	$uniqueTransactionCode = time();
	$currencyCode = "702";
	$amt  = "000000000010";
	$panCountry = "SG";

	//Customer Information
	$cardholderName = "John Doe";
 
	//Encrypted card data
	$encCardData = $_POST['encryptedCardInfo'];

	//Retrieve card information for merchant use if needed
	$maskedCardNo = $_POST['maskedCardInfo'];
	$expMonth = $_POST['expMonthCardInfo'];
	$expYear = $_POST['expYearCardInfo'];

	//Request Information 
	$version = "9.3";  
 
	//Construct signature string
	$stringToHash = $version.$merchantID.$uniqueTransactionCode.$desc.$amt.$currencyCode.$panCountry.$cardholderName.$encCardData;
	$hash = strtoupper(hash_hmac('sha1', $stringToHash ,$secretKey, false));	//Compute hash value
  
  	
	//Construct payment request message
	$xml = "<PaymentRequest>
		<version>$version</version> 
		<merchantID>$merchantID</merchantID>
		<uniqueTransactionCode>$uniqueTransactionCode</uniqueTransactionCode>
		<desc>$desc</desc>
		<amt>$amt</amt>
		<currencyCode>$currencyCode</currencyCode>  
		<panCountry>$panCountry</panCountry> 
		<cardholderName>$cardholderName</cardholderName>
		<encCardData>$encCardData</encCardData>
		<secureHash>$hash</secureHash>
		</PaymentRequest>"; 
	$payload = base64_encode($xml);	//Convert payload to base64  
?>

<form action='https://demo2.2c2p.com/2C2PFrontEnd/SecurePayment/PaymentAuth.aspx' method='POST' name='paymentRequestForm'>
	Processing payment request, Do not close the browser, press back or refresh the page. 
	<?php echo "<input type='hidden' name='paymentRequest' value='".$payload."'>"; ?>
</form>
<script language="JavaScript">
	document.paymentRequestForm.submit();	//submit form to 2c2p PGW
</script>
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.