Delete Card
    
    	
DELETING THE USER CARD (CAPI DELETE)
1- To delete a card from a user's registered cards, make a request by sending the following parameters to https://www.paytr.com/odeme/capi/delete
Required parameters for token creation
| Field name / Type | 
Description | 
Mandatory | 
Limitations | 
| utoken | 
User Token: User specific token notified to you by PAYTR system in post-payment notification | 
Yes | 
- | 
| ctoken | 
Token information on your user's card from the CAPI LIST service | 
Yes | 
- | 
| merchant_salt | 
A value specific to your store, which you can access through the PayTR Merchant Panel > Information page. | 
Yes | 
- | 
| merchant_key | 
A value specific to your store, which you can access through the PayTR Merchant Panel > Information page. | 
Yes | 
- | 
Values to be sent in POST REQUEST content:
| Variable / Type | 
Compulsory | 
Explanation | 
| merchant_id (integer) | 
Yes | 
Store Number: Store number given to you by PAYTR | 
| utoken (string) | 
Yes | 
User Token: User specific token notified to you by PAYTR system in post-payment notification | 
| paytr_token (string) | 
Yes | 
PayTR Token: It is the value that you will create to make sure that the request comes from you and that the content has not changed (You should look at the sample codes regarding the calculation) | 
| ctoken (string) | 
Yes | 
Card Token: The token that identifies the user's registered card. | 
2- The values in the table below will return to JSON format. You can inform your user according to the response.
| Variable / Type | 
Explanation | 
Possible / Sample Values | 
| status (string) | 
Status: Indicates that the card deletion request made was successful or failed. | 
success or error | 
| err_msg (string) | 
Error Message: If the request is unsuccessful, the error reason is returned in err_msg | 
Example: No card or previously deleted | 
    
    
            
    <?php
    $merchant_id    = 'XXXXXX';
    $merchant_key   = 'YYYYYYYYYYYYYY';
    $merchant_salt  = 'ZZZZZZZZZZZZZZ';
    $utoken = "";
    $ctoken = "";
    $hash_str = $ctoken . $utoken . $merchant_salt;
    $paytr_token=base64_encode(hash_hmac('sha256', $hash_str, $merchant_key, true));
    $post_vals=array(
        'merchant_id'=>$merchant_id,
        'ctoken'=>$ctoken,
        'utoken'=>$utoken,
        'paytr_token'=>$paytr_token
    );
    $ch=curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://www.paytr.com/odeme/capi/delete");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1) ;
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vals);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    $result = @curl_exec($ch);
    if(curl_errno($ch))
        die("PAYTR CAPI Delete connection error. err:".curl_error($ch));
    curl_close($ch);
    $result=json_decode($result,1);
    if($result['status']=='success')
        echo "Kart silindi!";
    else
        die("PAYTR CAPI Delete failed. Error:".$result['err_msg']);
    ?>
 
            
    # Python 3.6+
import base64
import hmac
import hashlib
import requests
import json
merchant_id = 'XXXXXX'
merchant_key = b'YYYYYYYYYYYYYY'
merchant_salt = 'ZZZZZZZZZZZZZZ'
utoken = ''
ctoken = ''
hash_str = ctoken + utoken + merchant_salt
paytr_token = base64.b64encode(hmac.new(merchant_key, hash_str.encode(), hashlib.sha256).digest())
params = {
    'merchant_id': merchant_id,
    'ctoken': ctoken,
    'utoken': utoken,
    'paytr_token': paytr_token
}
result = requests.post('https://www.paytr.com/odeme/capi/delete', params)
res = json.loads(result.text)
print(res)
 
            
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Collections.Specialized;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Web.Script.Serialization;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Delete()
        {
            string merchant_id = "XXXXXX";
            string merchant_key = "XXXXXX";
            string merchant_salt = "XXXXXX";
            string utoken = "";
            string ctoken = "";
            string Birlestir = string.Concat(ctoken, utoken, merchant_salt);
            HMACSHA256 hmac = new HMACSHA256(Encoding.UTF8.GetBytes(merchant_key));
            byte[] b = hmac.ComputeHash(Encoding.UTF8.GetBytes(Birlestir));
            string paytr_token = Convert.ToBase64String(b);
            NameValueCollection data = new NameValueCollection();
            data["merchant_id"] = merchant_id;
            data["ctoken"] = ctoken;
            data["utoken"] = utoken;
            data["paytr_token"] = paytr_token;
            using (WebClient client = new WebClient())
            {
                client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                byte[] result = client.UploadValues("https://www.paytr.com/odeme/capi/delete", "POST", data);
                string ResultAuthTicket = Encoding.UTF8.GetString(result);
                dynamic json = JValue.Parse(ResultAuthTicket);
                if (json.status == "success")
                {
                    Response.Write("Kart başarıyla silindi!");
                }
                else
                {
                    Response.Write("PAYTR CAPI Delete failed. reason:" + json.err_msg + "");
                }
            }
            return View();
        }
    }
}
 
            
var request = require('request');
var crypto = require('crypto');
var express = require('express');
var app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
var merchant_id = 'XXXXXX';
var merchant_key = 'YYYYYYYYYYYYYY';
var merchant_salt = 'ZZZZZZZZZZZZZZ';
var utoken = '';
var ctoken = '';
var paytr_token = crypto.createHmac('sha256', merchant_key).update(ctoken + utoken + merchant_salt).digest('base64');
app.get("/", function (req, res) {
var options = {
    'method': 'POST',
    'url': 'https://www.paytr.com/odeme/capi/delete',
    'headers': {
        'Content-Type': 'application/x-www-form-urlencoded'
    },
    form: {
        'merchant_id': merchant_id,
        'ctoken': ctoken,
        'utoken': utoken,
        'paytr_token': paytr_token,
    }
};
request(options, function (error, response, body) {
    if (error) throw new Error(error);
    var res_data = JSON.parse(body);
    if (res_data.status == 'success') {
        res.send('Kart bilgisi basarili sekilde silindi.');
    } else {
        console.log(response.body);
        res.end(response.body);
    }
});
});
var port = 3200;
app.listen(port, function () {
    console.log("Server is running. Port:" + port);
});