Store Creditcard Securely
Securely save your customers' creditcard information in My2C2P server. No more typing creditcard number and faster CheckOut!
Download full demo: PHP code / .Net code for 3DS Payment
Download full demo: PHP code / .Net code for non-3DS Payment
Construct Payment Form
Provide option to customer to select which card to use, and add 'data-encrypt' field into the form to capture CVV2 securely.
<form id="2c2p-payment-form" action="./payment_3d.php" method="POST">
Select the card you would like to make payment with:<br/>
<select name="cardid" id="cardid">
<option value="1" selected>411111-XXXXXX-1111</option>
<option value="2">555555-XXXXXX-4444</option>
</select><br/>
<input type="password" data-encrypt="cvv" maxlength="4" autocomplete="off" placeholder="CVV2/CVC2" ><br/>
<input type="submit" value="Submit">
</form>
Attribute | Description |
---|---|
data-encrypt="cvv" | To capture the credit card security code encrypted |
Import Api and Submit Form
Import 2C2P Secure Pay API and submit form with credit card information securely.
<script type="text/javascript" src="https://demo2.2c2p.com/2C2PFrontEnd/SecurePayment/api/my2c2p.1.6.9.min.js"></script>
<script type="text/javascript">
My2c2p.onSubmitForm("2c2p-payment-form", function(errCode,errDesc){
if(errCode!=0){
alert(errDesc);
}
});
</script>
Prepare payment request on backend code
Set payment request information.
//Request Information
$apiVersion = "9.3";
$encryptedCardInfo = $_POST['encryptedCardInfo']; //Retrieve encrypted credit card data
$cardid = $_POST['cardid']; //Get selected card id from UI
if($cardid == 1){
$storeCardUniqueID = '09071513062949492475'; //assign stored card token
}
else{
$storeCardUniqueID = '17031608495177120732';
}
//Construct signature string
$stringToHash = $apiVersion . $timeStamp . $merchantID . $uniqueTransactionCode . $desc . $amt . $currencyCode . $paymentChannel . $storeCardUniqueID . $panBank .
$country . $cardholderName . $cardholderEmail . $payCategoryID . $userDefined1 . $userDefined2 . $userDefined3 . $userDefined4 . $userDefined5 . $storeCard .
$ippTransaction . $installmentPeriod . $interestType . $recurring . $invoicePrefix . $recurringAmount . $allowAccumulate . $maxAccumulateAmt . $recurringInterval .
$recurringCount . $chargeNextDate . $promotion . $request3DS . $statementDescriptor . $agentCode . $channelCode . $paymentExpiry . $mobileNo . $tokenizeWithoutAuthorization . $encryptedCardInfo;
$hash = strtoupper(hash_hmac('sha1', $stringToHash ,$secretKey, false)); //Calculate Hash Value
Construct payment request message with additional attribute 'storeCardUniqueID'.
//Construct payment request message
$xml = "<PaymentRequest>
<version>$apiVersion</version>
<timeStamp>$timeStamp</timeStamp>
<merchantID>$merchantID</merchantID>
<uniqueTransactionCode>$uniqueTransactionCode</uniqueTransactionCode>
<desc>$desc</desc>
<amt>$amt</amt>
<currencyCode>$currencyCode</currencyCode>
<panCountry>$country</panCountry>
<cardholderName>$cardholderName</cardholderName>
<secureHash>$hash</secureHash>
<encCardData>$encryptedCardInfo</encCardData>
<storeCardUniqueID>$storeCardUniqueID</storeCardUniqueID>
</PaymentRequest>";
$payload = base64_encode($xml); //Convert payload to base64
Download full demo: PHP code / .Net code for 3DS Payment
Download full demo: PHP code / .Net code for non-3DS Payment