<?php
$merchant_id = 'AAAAAA';
$merchant_key = 'XXXXXXXXXXXXXXXX';
$merchant_salt = 'XXXXXXXXXXXXXXXX';
$id = "YYYXXX";
$debug_on = 1;
$paytr_token=base64_encode(hash_hmac('sha256', $id.$merchant_id.$merchant_salt, $merchant_key, true));
$post_vals=array(
'merchant_id' => $merchant_id,
'id' => $id,
'debug_on' => $debug_on,
'paytr_token' => $paytr_token
);
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.paytr.com/odeme/api/link/delete");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1) ;
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vals);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = @curl_exec($ch);
if(curl_errno($ch))
die("PAYTR LINK DELETE API request timeout. err:".curl_error($ch));
curl_close($ch);
$result=json_decode($result,1);
if($result['status']=='error')
die($result['err_msg']);
elseif($result['status']=='failed')
print_r($result);
else
print_r($result);
# Python 3.6+
import base64
import hmac
import hashlib
import requests
import json
import random
merchant_id = 'AAAAAA'
merchant_key = b'AAAAAA'
merchant_salt = 'XXXXXXXXXXXXXXXX'
id = 'YYYXXX'
debug_on=1
hash_str = id + merchant_id + merchant_salt
paytr_token = base64.b64encode(hmac.new(merchant_key, hash_str.encode(), hashlib.sha256).digest())
params = {
'merchant_id': merchant_id,
'id': id,
'debug_on': debug_on,
'paytr_token': paytr_token
}
result = requests.post('https://www.paytr.com/odeme/api/link/delete', params)
res = json.loads(result.text)
if res['status'] == 'error':
print('Error: ' + res['err_msg'])
elif res['status'] == 'failed':
print(result.text)
else:
print(result.text)
var crypto = require('crypto');
var express = require('express');
var app = express();
var request = require('request');
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
var merchant_id = 'AAAAAA';
var merchant_key = 'XXXXXXXXXXXXXXXX';
var merchant_salt = 'XXXXXXXXXXXXXXXX';
app.get("/create", function (req, res) {
var name = 'Örnek Ürün / Hizmet Adı';
var price = '1445';
var currency = 'TL';
var max_installment = '12';
var link_type = 'product';
var lang = 'tr';
var required = name + price + currency + max_installment + link_type + lang;
var email = '';
var min_count = '';
if (link_type == 'product') {
min_count = '1';
required += min_count;
} else {
(link_type == 'collection')
email = 'test@example.com';
required += email;
}
var max_count = '1';
var expiry_date = '2021-06-23 17:00:00';
var callback_link = '';
var callback_id = '';
var debug_on = '1';
var paytr_token = crypto.createHmac('sha256', merchant_key).update(required + merchant_salt).digest('base64');
var options = {
'method': 'POST',
'url': 'https://www.paytr.com/odeme/api/link/create',
'headers': {
'Content-Type': 'application/x-www-form-urlencoded'
},
form: {
'merchant_id': merchant_id,
'name': name,
'price': price,
'currency': currency,
'max_installment': max_installment,
'link_type': link_type,
'lang': lang,
'min_count': min_count,
'email': email,
'expiry_date': expiry_date,
'max_count': max_count,
'callback_link': callback_link,
'callback_id': callback_id,
'debug_on': debug_on,
'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(body);
} else {
res.end(body);
}
});
});
app.get("/delete", function (req, res) {
var id = 'XXXX';
var debug_on = '1';
var paytr_token = crypto.createHmac('sha256', merchant_key).update(id + merchant_id + merchant_salt).digest('base64');
var options = {
'method': 'POST',
'url': 'https://www.paytr.com/odeme/api/link/delete',
'headers': {
'Content-Type': 'application/x-www-form-urlencoded'
},
form: {
'merchant_id': merchant_id,
'id': id,
'debug_on': debug_on,
'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(response.body);
} else {
console.log(response.body);
res.end(response.body);
}
});
});
app.get("/sendsms", function (req, res) {
var id = 'XXXX';
var cell_phone = '05555555555';
var debug_on = '1';
var paytr_token = crypto.createHmac('sha256', merchant_key).update(id + merchant_id + cell_phone + merchant_salt).digest('base64');
var options = {
'method': 'POST',
'url': 'https://www.paytr.com/odeme/api/link/send-sms',
'headers': {
'Content-Type': 'application/x-www-form-urlencoded'
},
form: {
'merchant_id': merchant_id,
'id': id,
'cell_phone': cell_phone,
'debug_on': debug_on,
'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(response.body);
} else {
console.log(response.body);
res.end(response.body);
}
});
});
app.get("/sendmail", function (req, res) {
var id = 'XXXX';
var email = '';
var debug_on = '1';
var paytr_token = crypto.createHmac('sha256', merchant_key).update(id + merchant_id + email + merchant_salt).digest('base64');
var options = {
'method': 'POST',
'url': 'https://www.paytr.com/odeme/api/link/send-email',
'headers': {
'Content-Type': 'application/x-www-form-urlencoded'
},
form: {
'merchant_id': merchant_id,
'id': id,
'email': email,
'debug_on': debug_on,
'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(response.body);
} else {
console.log(response.body);
res.end(response.body);
}
});
});
app.post("/callback", function (req, res) {
var callback = req.body;
token = callback.id + callback.merchant_oid + merchant_salt + callback.status + callback.total_amount;
var paytr_token = crypto.createHmac('sha256', merchant_key).update(token).digest('base64');
if (paytr_token != callback.hash) {
throw new Error("PAYTR notification failed: bad hash");
}
if (callback.status == 'success') {
} else {
}
res.send('OK');
});
var port = 3200;
app.listen(port, function () {
console.log("Server is running. Port:" + port);
});