Set account credentials
<?php
//Merchant's account information
$merchant_id = "JT01"; //Get MerchantID when opening account with 2C2P
$secret_key = "7jYcp4FxFdf0"; //Get SecretKey from 2C2P PGW Dashboard
Set transaction information
//Transaction information
$payment_description = '2 days 1 night hotel room';
$order_id = time();
$currency = "702";
$amount = '000000102500';
Enable Recurring Payment Plan
//Payment Options
$payment_option = "C"; //Customer Payment Options
$request_3ds = "N"; //For test purpose, disable 3DS
//IPP Options
$recurring = "Y"; //Recurring flag
$order_prefix = "JT01".(new DateTime('tomorrow'))->format('dmY').(time()%1000); //Recurring invoice no prefix. for demo purpose we set it to date and time.
$recurring_amount = "000000000100"; //Recurring charge amount
$allow_accumulate = "N"; //Allow accumulate amount flag
$max_accumulate_amount = "000000000200"; //Maximum accumulate amount allowed
$recurring_interval = "1"; //Recurring interval by no of day
$recurring_count = "10"; //Number of recurring charges
$charge_next_date = (new DateTime('tomorrow'))->format('dmY'); //The first day to start recurring charges.
$charge_on_date = ""; //To set a specific date for recurring charges to trigger instead of using day interval.
Set payment request information
//Request information
$version = "7.2";
$payment_url = "https://demo2.2c2p.com/2C2PFrontEnd/RedirectV3/payment";
$result_url_1 = "http://localhost/devPortal/V3_UI_PHP_JT01_devPortal/result.php";
//Construct signature string
$params = $version.$merchant_id.$payment_description.$order_id.$invoice_no.$currency.$amount.$customer_email.$pay_category_id.$promotion.$user_defined_1.$user_defined_2.$user_defined_3.$user_defined_4.$user_defined_5.$result_url_1.$result_url_2.$enable_store_card.$stored_card_unique_id.$request_3ds.$recurring.$order_prefix.$recurring_amount.$allow_accumulate.$max_accumulate_amount.$recurring_interval.$recurring_count.$charge_next_date.$charge_on_date.$payment_option.$ipp_interest_type.$payment_expiry.$default_lang.$statement_descriptor;
$hash_value = hash_hmac('sha1',$params, $secret_key,false); //Compute hash value
Construct payment request form
echo 'Payment information:';
echo '<html>
<body>
<form id="myform" method="post" action="'.$payment_url.'">
<input type="hidden" name="version" value="'.$version.'"/>
<input type="hidden" name="merchant_id" value="'.$merchant_id.'"/>
<input type="hidden" name="currency" value="'.$currency.'"/>
<input type="hidden" name="result_url_1" value="'.$result_url_1.'"/>
<input type="hidden" name="payment_option" value="'.$payment_option.'"/>
<input type="hidden" name="request_3ds" value="'.$request_3ds.'"/>
<input type="hidden" name="recurring" value="'.$recurring.'"/>
<input type="hidden" name="order_prefix" value="'.$order_prefix.'"/>
<input type="hidden" name="recurring_amount" value="'.$recurring_amount.'"/>
<input type="hidden" name="allow_accumulate" value="'.$allow_accumulate.'"/>
<input type="hidden" name="max_accumulate_amount" value="'.$max_accumulate_amount.'"/>
<input type="hidden" name="recurring_interval" value="'.$recurring_interval.'"/>
<input type="hidden" name="recurring_count" value="'.$recurring_count.'"/>
<input type="hidden" name="charge_next_date" value="'.$charge_next_date.'"/>
<input type="hidden" name="charge_on_date" value="'.$charge_on_date.'"/>
<input type="hidden" name="hash_value" value="'.$hash_value.'"/>
PRODUCT INFO : <input type="text" name="payment_description" value="'.$payment_description.'" readonly/><br/>
ORDER NO : <input type="text" name="order_id" value="'.$order_id.'" readonly/><br/>
AMOUNT: <input type="text" name="amount" value="'.$amount.'" readonly/><br/>
<input type="submit" name="submit" value="Confirm" />
</form>
Submit payment request form
<script type="text/javascript">
document.forms.myform.submit();
</script>
</body>
</html>';
?>
Complete Code
Copy & Paste below code to your working file, and put this file in your Web Server.
<?php
//Merchant's account information
$merchant_id = "JT01"; //Get MerchantID when opening account with 2C2P
$secret_key = "7jYcp4FxFdf0"; //Get SecretKey from 2C2P PGW Dashboard
//Transaction information
$payment_description = '2 days 1 night hotel room';
$order_id = time();
$currency = "702";
$amount = '000000102500';
//Payment Options
$payment_option = "C"; //Customer Payment Options
$request_3ds = "N"; //For test purpose, disable 3DS
//IPP Options
$recurring = "Y"; //Recurring flag
$order_prefix = "JT01".(new DateTime('tomorrow'))->format('dmY').(time()%1000); //Recurring invoice no prefix. for demo purpose we set it to date and time.
$recurring_amount = "000000000100"; //Recurring charge amount
$allow_accumulate = "N"; //Allow accumulate amount flag
$max_accumulate_amount = "000000000200"; //Maximum accumulate amount allowed
$recurring_interval = "1"; //Recurring interval by no of day
$recurring_count = "10"; //Number of recurring charges
$charge_next_date = (new DateTime('tomorrow'))->format('dmY'); //The first day to start recurring charges.
$charge_on_date = ""; //To set a specific date for recurring charges to trigger instead of using day interval.
//Request information
$version = "7.2";
$payment_url = "https://demo2.2c2p.com/2C2PFrontEnd/RedirectV3/payment";
$result_url_1 = "http://localhost/devPortal/V3_UI_PHP_JT01_devPortal/result.php";
//Construct signature string
$params = $version.$merchant_id.$payment_description.$order_id.$invoice_no.$currency.$amount.$customer_email.$pay_category_id.$promotion.$user_defined_1.$user_defined_2.$user_defined_3.$user_defined_4.$user_defined_5.$result_url_1.$result_url_2.$enable_store_card.$stored_card_unique_id.$request_3ds.$recurring.$order_prefix.$recurring_amount.$allow_accumulate.$max_accumulate_amount.$recurring_interval.$recurring_count.$charge_next_date.$charge_on_date.$payment_option.$ipp_interest_type.$payment_expiry.$default_lang.$statement_descriptor;
$hash_value = hash_hmac('sha1',$params, $secret_key,false); //Compute hash value
echo 'Payment information:';
echo '<html>
<body>
<form id="myform" method="post" action="'.$payment_url.'">
<input type="hidden" name="version" value="'.$version.'"/>
<input type="hidden" name="merchant_id" value="'.$merchant_id.'"/>
<input type="hidden" name="currency" value="'.$currency.'"/>
<input type="hidden" name="result_url_1" value="'.$result_url_1.'"/>
<input type="hidden" name="payment_option" value="'.$payment_option.'"/>
<input type="hidden" name="request_3ds" value="'.$request_3ds.'"/>
<input type="hidden" name="recurring" value="'.$recurring.'"/>
<input type="hidden" name="order_prefix" value="'.$order_prefix.'"/>
<input type="hidden" name="recurring_amount" value="'.$recurring_amount.'"/>
<input type="hidden" name="allow_accumulate" value="'.$allow_accumulate.'"/>
<input type="hidden" name="max_accumulate_amount" value="'.$max_accumulate_amount.'"/>
<input type="hidden" name="recurring_interval" value="'.$recurring_interval.'"/>
<input type="hidden" name="recurring_count" value="'.$recurring_count.'"/>
<input type="hidden" name="charge_next_date" value="'.$charge_next_date.'"/>
<input type="hidden" name="charge_on_date" value="'.$charge_on_date.'"/>
<input type="hidden" name="hash_value" value="'.$hash_value.'"/>
PRODUCT INFO : <input type="text" name="payment_description" value="'.$payment_description.'" readonly/><br/>
ORDER NO : <input type="text" name="order_id" value="'.$order_id.'" readonly/><br/>
AMOUNT: <input type="text" name="amount" value="'.$amount.'" readonly/><br/>
<input type="submit" name="submit" value="Confirm" />
</form>
<script type="text/javascript">
document.forms.myform.submit();
</script>
</body>
</html>';
?>
Comments
Please sign in to leave a comment.