Best Payment Gateway In India - Start Accepting Payments Online with SabPaisa's Online Payment Gateway. Enable Businesses to Collect Payment Online.
1. Create the Config page name as config.php
config.php
<?php
$spURL = null;
$spDomain = "https://securepay.sabpaisa.in/SabPaisa/sabPaisaInit";
$username = "YOUR-USER-NAME";
$password = "YOUR_PASSWORD";
$clientCode = "YOUR_CLIENT_CODE";
$authKey = "YOUR-KYE";
$authIV = "YOUR_ENCRIPT_KEY";
$URLsuccess = "example.com/success_fail.php";
$URLfailure = "example.com/success_fail.php";
?>
2. Authentication.php /* Copy this encrypt code */
<?php
class AesCipher {
private const OPENSSL_CIPHER_NAME = "aes-128-cbc";
private const CIPHER_KEY_LEN = 16;
private static function fixKey($key) {
if (strlen($key) < AesCipher::CIPHER_KEY_LEN) {
return str_pad("$key", AesCipher::CIPHER_KEY_LEN, "0");
}
if (strlen($key) > AesCipher::CIPHER_KEY_LEN) {
return substr($key, 0, AesCipher::CIPHER_KEY_LEN);
}
return $key;
}
static function encrypt($key, $iv, $data) {
echo 'Data value is :' .$data;
$encodedEncryptedData = base64_encode(openssl_encrypt($data, AesCipher::OPENSSL_CIPHER_NAME, AesCipher::fixKey($key), OPENSSL_RAW_DATA, $iv));
$encodedIV = base64_encode($iv);
$encryptedPayload = $encodedEncryptedData.":".$encodedIV;
echo '$encryptedPayload value is :' .$encryptedPayload;
return $encryptedPayload;
}
static function decrypt($key,$iv, $data) {
$parts = explode(':', $data); //Separate Encrypted data from iv.
$encrypted = $parts[0];
$iv = $parts[1];
$decryptedData = openssl_decrypt(base64_decode($encrypted), AesCipher::OPENSSL_CIPHER_NAME, AesCipher::fixKey($key), OPENSSL_RAW_DATA, base64_decode($iv));
return $decryptedData;
}
}
?>
3. order.php
<?php
session_start();
include 'Authentication.php';
include_once('config.php');
/* Get User Data From Database */
$aid='1002'; /* User ID */
$fname=trim('Dipankar');
$lname=trim('Biswas');
$applicant_ph=trim('973312121');
$applicant_details_blank="NR";
$cur_applicant_email='xxx@gmail.com';
$order_id='52456' /* Order ID */
$challan_type="ORDER";
$fees=100; /* INR */
$$challan_id=$_REQUEST['order_id'];
if($fees>0)
{
$rand_start=mt_rand(0,9);
$programID=$challan_id;
// $txnID Seperate by _ and $challan_id must be 2nd position
$txnId='Your Uni ID'.'_'.$challan_id.'_'.$challan_type;
$txnAmt = $fees;
$payerFirstName =$fname;
$payerLastName =$lname;
$payerContact = $applicant_ph;
$payerEmail = $cur_applicant_email;
$payerAddress = "NA";
$spURL ="?clientName=".$clientCode."&usern=".$username."&pass=".$password."&amt=".$txnAmt."&txnId=".$txnId."&firstName=".$payerFirstName."&lstName=".$payerLastName."&contactNo=".$payerContact."&Email=".$payerEmail."&Add=".$payerAddress."&ru=".$URLsuccess."&failureURL=".$URLfailure;
//echo $spURL;
$AesCipher = new AesCipher();
$spURL = $AesCipher->encrypt($authKey,$authIV,$spURL);
$spURL = str_replace("+", "%2B",$spURL);
$spURL="?query=".$spURL."&clientName=".$clientCode;
$spURL = $spDomain.$spURL;
header("location:".$spURL);
}
else
{
$error_msg="There was an error with your application. Please try again.";
}
?>
4. success_fail.php
<?php
session_start();
include 'Authentication.php';
include_once('config.php');
$query = $_REQUEST['query'];
$decText = null;
$AesCipher = new AesCipher();
$query = str_replace("%2B","+",$query);
$decText = $AesCipher -> decrypt($authKey, $authIV, $query);
//$userid = $_SESSION['userid'];
$arr=explode('&', $decText);
$ss=1;
$txnID=$arr[2];
$txnID=explode('=',$txnID);
$txnIDM=$txnID[1];
$txn_ID_my= $arr[6];
$txn_ID_my=explode('=',$txn_ID_my);
$txn_ID_myM=$txn_ID_my[1];
$txIDN=explode('_',$txn_ID_myM);
$txID=$txIDN[1];
$challan_type=$txIDN[2];
$status=$arr[18];
$status=explode('=',$status);
$statusM=$status[1];
if($statusM=="SUCCESS")
{
$app_or_adm=$sid;
$transaction_num='odr_'.$txnIDM;
$now=time();
if($transaction_num!=null)
{
/* Update Database by order id $txID */
$success_msg="Your payment has been successfully processed. ";
$error_msg="";
}
else
{
$error_msg="Cahllan Not Found.";
}
}else{
$error_msg="Sorry payment failed try again ";
}
?>
Get the latest news and updates by signing up to our daily newsletter.We won't sell your email or spam you !