Hoolah
2c2p support Hoolah Payment integrated via Secure Pay. The following section show guide and sample code how to do integration.
EnvironmentPlease refer Demo & Live Endpoint.
Â
Â
Set Account Credentials
<?php
//Merchant's account information
$merchantID = "702702000000000"; //Get MerchantID when opening account with 2C2P
$secretKey = "37EBE4BBBAC7DC1D1BA9976A9992ED39B34BFBDA5B5C884B3D22F0BB1FA2CF1F"; //Get SecretKey from 2C2P PGW Dashboard
Â
Set Transaction Information
Prepare required data.
//Transaction Information
$desc = "2 days 1 night hotel room";
$uniqueTransactionCode = time();
$currencyCode = "702";
$amt = "000000100000";
$panCountry = "SG";
$paymentChannel = "HOOLAH";
//Customer Information
$cardholderName = "Terrance";
$cardholderEmail = "[email protected]";
$mobilNo = "67172333";
$address1 = "32-01";
$address2 = "Raffles Place";
$address3 = "Center Park";
$postalCode = "048622";
$city = "Singapore";
$state = "Singapore";
$countryCode = "702";
Â
Set Payment Request Information
//Request Information
$version = "9.9";
Â
Construct Payment Request Message
Below show mandatory parameter of paymentRequest
. Refer to Payload & API Parameter for details.
Secure Pay APIRefer Payload Parameter Specification & API Parameter Specification
//Construct payment request message
$xml = "<PaymentRequest>
<merchantID>$merchantID</merchantID>
<uniqueTransactionCode>$uniqueTransactionCode</uniqueTransactionCode>
<desc>$desc</desc>
<amt>$amt</amt>
<currencyCode>$currencyCode</currencyCode>
<panCountry>$panCountry</panCountry>
<paymentChannel>$paymentChannel</paymentChannel>
<cardholderName>$cardholderName</cardholderName>
<cardholderEmail>$cardholderEmail</cardholderEmail>
<mobileNo>$mobilNo</mobileNo>
<addresses>
<billing>
<address1>$address1</address1>
<address2>$address2</address2>
<address3>$address3</address3>
<postalCode>$postalCode</postalCode>
<city>$city</city>
<state>$state</state>
<countryCode>$countryCode</countryCode>
</billing>
</addresses>
</PaymentRequest>";
$paymentPayload = base64_encode($xml); //Convert payload to base64
$signature = strtoupper(hash_hmac('sha256', $paymentPayload, $secretKey, false));
$payloadXML = "<PaymentRequest>
<version>$version</version>
<payload>$paymentPayload</payload>
<signature>$signature</signature>
</PaymentRequest>";
$payload = base64_encode($payloadXML); //encode with 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 and put this file in your Web Server.
<?php
//Merchant's account information
$merchantID = "702702000000000"; //Get MerchantID when opening account with 2C2P
$secretKey = "37EBE4BBBAC7DC1D1BA9976A9992ED39B34BFBDA5B5C884B3D22F0BB1FA2CF1F"; //Get SecretKey from 2C2P PGW Dashboard
//Transaction Information
$desc = "2 days 1 night hotel room";
$uniqueTransactionCode = time();
$currencyCode = "702";
$amt = "000000100000";
$panCountry = "SG";
$paymentChannel = "HOOLAH";
//Customer Information
$cardholderName = "Terrance";
$cardholderEmail = "[email protected]";
$mobilNo = "67172333";
$address1 = "32-01";
$address2 = "Raffles Place";
$address3 = "Center Park";
$postalCode = "048622";
$city = "Singapore";
$state = "Singapore";
$countryCode = "702";
//Request Information
$version = "9.9";
//Construct payment request message
$xml = "<PaymentRequest>
<merchantID>$merchantID</merchantID>
<uniqueTransactionCode>$uniqueTransactionCode</uniqueTransactionCode>
<desc>$desc</desc>
<amt>$amt</amt>
<currencyCode>$currencyCode</currencyCode>
<panCountry>$panCountry</panCountry>
<paymentChannel>$paymentChannel</paymentChannel>
<cardholderName>$cardholderName</cardholderName>
<cardholderEmail>$cardholderEmail</cardholderEmail>
<mobileNo>$mobilNo</mobileNo>
<addresses>
<billing>
<address1>$address1</address1>
<address2>$address2</address2>
<address3>$address3</address3>
<postalCode>$postalCode</postalCode>
<city>$city</city>
<state>$state</state>
<countryCode>$countryCode</countryCode>
</billing>
</addresses>
</PaymentRequest>";
$paymentPayload = base64_encode($xml); //Convert payload to base64
$signature = strtoupper(hash_hmac('sha256', $paymentPayload, $secretKey, false));
$payloadXML = "<PaymentRequest>
<version>$version</version>
<payload>$paymentPayload</payload>
<signature>$signature</signature>
</PaymentRequest>";
$payload = base64_encode($payloadXML); //encode with base64
?>
<!--Construct form to submit authorization request to 2c2p PGW-->
<!--Payment request data should be sent to 2c2p PGW with POST method inside parameter named 'paymentRequest'-->
<form action='https://demo2.2c2p.com/2C2PFrontEnd/SecurePayment/PaymentAuth.aspx' method='POST' name='paymentRequestForm'>
<!--display wait message to user when page is loading-->
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>
Â
When payment has completed, 2c2p will send payment response back to merchant end. Following code show that how to receive and process payment response.
Secure Pay APIRefer Payload Parameter Specification & API Parameter Specification
<?php
$response = $_REQUEST["paymentResponse"];
//Decode response with base64
$reponsePayLoadXML = base64_decode($response);
//Parse ResponseXML
$xmlObject =simplexml_load_string($reponsePayLoadXML) or die("Error: Cannot create object");
//Decode payload with base64 to get the Reponse
$payloadxml = base64_decode($xmlObject->payload);
//Get the signature from the ResponseXML
$signaturexml = $xmlObject->signature;
$secretKey = "37EBE4BBBAC7DC1D1BA9976A9992ED39B34BFBDA5B5C884B3D22F0BB1FA2CF1F"; //Get SecretKey from 2C2P PGW Dashboard
//Encode the payload
$base64EncodedPayloadResponse=base64_encode($payloadxml);
//Generate signature based on "payload"
$signatureHash = strtoupper(hash_hmac('sha256', $base64EncodedPayloadResponse ,$secretKey, false));
//Compare the response signature with payload signature with secretKey
if($signaturexml == $signatureHash){
echo "Response :<br/><textarea style='width:100%;height:80px'>". $payloadxml."</textarea>";
}
else{
//If Signature does not match
echo "Error :<br/><textarea style='width:100%;height:20px'>". "Wrong Signature"."</textarea>";
echo "<br/>";
}
?>
Updated about 1 month ago