---
title: Delete Card
description: Delete a saved tokenized card for a buyer.
---

## Delete Saved Card

Remove a saved card from the token vault using the buyer's phone number and the card's tokenized identifier.

## POST

```http
https://kraken.airpay.co.in/airpay/pay/v4/api/deletecard
```

## Request Body

| Parameter         | Required | Type / Size         | Description                                        | Example              |
| ----------------- | -------- | ------------------- | -------------------------------------------------- | -------------------- |
| `buyer_phone`     | Yes      | Numeric (8-15)      | Buyer phone number associated with the saved card. | `99999999`           |
| `card_uniquecode` | Yes      | Alphanumeric (3-64) | Unique tokenized identifier of the card to delete. | `abc123def456ghi789` |

## Success 200

```json
{
  "status_code": "200",
  "response_code": "00",
  "status": "success",
  "message": "Card deleted successfully",
  "data": []
}
```

## Response Fields

| Field           | Type   | Description                                         |
| --------------- | ------ | --------------------------------------------------- |
| `status_code`   | String | Status code returned by the API.                    |
| `response_code` | String | Internal response code indicating success or error. |
| `status`        | String | Response status, usually `success` or `failure`.    |
| `message`       | String | Message describing the result.                      |
| `data`          | Array  | Empty array for successful deletion.                |

## PHP

```php
<?php

$mercid = "<merchant_id>";
$username = "<username>";
$password = "<password>";
$secret = "<secret>";
$client_id = "<client_id>";
$client_secret = "<client_secret>";

$privatekey = Checksum::encrypt($username . ":|:" . $password, $secret);
$request = array();

$data = [];
$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);
$req = [
    'merchant_id' => $mercid,
    'encdata' => $encre,
    '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'];
    exit;
}

$accessToken = $tokenResponse['data']['access_token'];

$checksumReq = checksumcal($data);
$dataJson = json_encode($data);
$request_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)
{
    $timeout = 60;
    $port = 443;
    $ch = curl_init();

    $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);
    } else {
        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);
    curl_close($ch);
    return $result;
}

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);
    curl_close($ch);
    return $response;
}

function checksumcal($postData)
{
    ksort($postData);
    $data = '';
    foreach ($postData as $key => $value) {
        $data .= $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);
    return $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);
    return $raw;
}
?>
```