$mercid = "<merchant_id>";
$username = "<username>";
$password = "<password>";
$client_id = "<client_id>";
$client_secret = "<client_secret>";
$privatekey = Checksum::encrypt($username . ":|:" . $password, $secret);
$data['buyer_phone'] = '99999999';
$data['card_uniquecode'] = 'card_token_example_123456';
$tokenUrl = "https://kraken.airpay.co.in/airpay/pay/v4/api/oauth2/";
$request['client_id'] = $client_id;
$request['client_secret'] = $client_secret;
$request['grant_type'] = 'client_credentials';
$request['merchant_id'] = $mercid;
$secretKey = md5($username . "~:~" . $password);
$encre = encrypt(json_encode($request), $secretKey);
'merchant_id' => $mercid,
'checksum' => checksumcal($request)
$access_token = sendPostData($tokenUrl, $req);
$decryptData = decrypt(json_decode($access_token, true), $secretKey);
$tokenResponse = json_decode($decryptData, true);
if ((isset($tokenResponse['success']) && !$tokenResponse['success']) || empty($access_token) || empty(trim($access_token))) {
echo $tokenResponse['msg'];
$accessToken = $tokenResponse['data']['access_token'];
$checksumReq = checksumcal($data);
$dataJson = json_encode($data);
'encdata' => aes256encrypt($dataJson, 'aes-256-cbc', $username, $password),
'merchant_id' => $mercid,
'privatekey' => $privatekey,
'checksum' => $checksumReq
$response = sendDataOverPost('https://kraken.airpay.co.in/airpay/pay/v4/api/deletecard?token=' . $accessToken, $request_data, 'POST');
$responseArr = json_decode($response, true);
$encdata = $responseArr['response'];
$iv = substr($encdata, 0, 16);
$encdata = substr($encdata, 16);
$decrypted_data = openssl_decrypt(base64_decode($encdata), 'aes-256-cbc', $secretKey, OPENSSL_RAW_DATA, $iv);
print_r($decrypted_data);
function sendDataOverPost($url, $fields, $method)
$User_Agent = 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31';
$request_headers = array();
$request_headers[] = 'User-Agent: ' . $User_Agent;
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
if (strtoupper($method) == 'POST') {
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_URL, $url . '?' . $fields);
curl_setopt($ch, CURLOPT_PORT, $port);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
$result = curl_exec($ch);
function aes256encrypt($data, $cipher = 'aes-256-cbc', $username, $password)
$key = md5($username . "~:~" . $password);
$iv = bin2hex(openssl_random_pseudo_bytes(8));
$encrypted = openssl_encrypt($data, $cipher, $key, OPENSSL_RAW_DATA, $iv);
$encryptedData = base64_encode($encrypted);
return $iv . $encryptedData;
function sendPostData($tokenUrl, $postData)
$ch = curl_init($tokenUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
$response = curl_exec($ch);
function checksumcal($postData)
foreach ($postData as $key => $value) {
return hash('SHA256', $data . date('Y-m-d'));
function encrypt($request, $secretKey)
$iv = bin2hex(openssl_random_pseudo_bytes(8));
$raw = openssl_encrypt($request, 'AES-256-CBC', $secretKey, OPENSSL_RAW_DATA, $iv);
$data = $iv . base64_encode($raw);
function decrypt($requestData, $secretKey)
$data = $requestData['response'];
$iv = substr($data, 0, 16);
$encryptedData = substr($data, 16);
$raw = openssl_decrypt(base64_decode($encryptedData), 'AES-256-CBC', $secretKey, OPENSSL_RAW_DATA, $iv);