$mercid = "<merchant_id>";
$username = "<username>";
$password = "<password>";
$client_id = "<client_id>";
$client_secret = "<client_secret>";
$privatekey = hash('SHA256', $secret . '@' . $username . ":|:" . $password);
$data['buyer_phone'] = '99999999';
$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 = aes256encrypt(json_encode($request), 'aes-256-cbc', $username, $password);
'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 = sendPostData('https://kraken.airpay.co.in/airpay/pay/v4/api/getcards?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, $options = OPENSSL_RAW_DATA, $iv);
print_r($decrypted_data);
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, $options = 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) {
$data = $data . date('Y-m-d');
$checksum = hash('SHA256', $data);
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);