Returning Payments List
With this service, a transfer request has been made but you can access the list of returned payments due to the buyer account error. Returned payments are processed as a balance to a subaccount for your store. You can use the "Returning Payments - Send From Account" service to resend these returned payments.
1- To get the list of returned payments, send the information specified in the table to the URL related to
POST: https://www.paytr.com/odeme/geri-donen-transfer
Required parameters for token creation
Field name / type |
Description |
Mandatory |
Limitations |
merchant_id(integer) |
Merchant No: Merchant number given to you by PayTR |
Yes |
- |
start_date(string) |
Start date: Sample format: 2020-05-29 00:05:56 (YYYY-MM-DD hh:mm:ss) |
Yes |
- |
end_date |
End date: Sample format: 2020-05-29 23:59:10 (YYYY-MM-DD hh:mm:ss) |
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:
Field name / type |
Description |
Mandatory |
Limitations |
merchant_id (string) |
Merchant No: Merchant number given to you by PayTR |
Yes |
- |
start_date (integer) |
Start date: Sample format: 2020-05-29 00:05:56 (YYYY-MM-DD hh:mm:ss) |
Yes |
- |
end_date(integer) |
End date: Sample format: 2020-05-29 23:59:10 (YYYY-MM-DD hh:mm:ss) |
Yes |
- |
dummy (integer) |
Dummy is used to create data |
No |
1 or 0 (1 needs to be sent for Dummy data) |
paytr_token(string) |
PayTR Token: The value you create to make sure that the request comes from you and that the content has not changed |
Yes |
(See sample code for calculation |
2- Your request will be returned in JSON format.
a. If there is no bounce payment within the specified date range, the status value returns failed.
b. If there is any bounce payment within the specified date range, the status value success and
the information in the table below will be returned.
c. If you have an error in the query, the status value returns an error. In this case, you should
check the err_msg content for the error detail.
Other information returned in the status success status is detailed in the table below. Same values are returned without any difference in Sales and Returns transactions.
Description |
Field name / type |
Values |
Reference No: The distinguishing number of the transaction |
ref_no |
Example: 1000001 |
The date on which the returned payment was detected |
date_detected |
Example: 2020-06-08 |
The date the payment was returned |
date_reimbursed |
Example: 2020-06-08 |
Receiver name and surname transmitted in the transfer request |
transfer_name |
Example: TEST USER |
IBAN transmitted in the transfer request |
transfer_iban |
- |
Amount transmitted in the transfer request |
transfer_amount |
Example: 35.18 |
Currency transmitted in the transfer request |
transfer_currency |
Example: TL |
Date of transfer request |
transfer_date |
Example: 2020-06-08 |
<?php
$merchant_id = 'XXXXXX';
$merchant_key = 'XXXXXXXXYYYYYYYY';
$merchant_salt = 'XXXXXXXXYYYYYYYY';
$start_date = "2020-05-20 00:00:00";
$end_date = "2020-06-16 23:59:59";
$paytr_token = base64_encode(hash_hmac('sha256', $merchant_id . $start_date . $end_date . $merchant_salt, $merchant_key, true));
$post_vals = array('merchant_id' => $merchant_id,
'start_date' => $start_date,
'end_date' => $end_date,
'paytr_token' => $paytr_token
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.paytr.com/odeme/geri-donen-transfer");
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, 90);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 90);
$result = @curl_exec($ch);
if (curl_errno($ch)) {
echo curl_error($ch);
curl_close($ch);
exit;
}
curl_close($ch);
$result = json_decode($result, 1);
if ($result[status] == 'success')
{
print_r($result);
}
elseif ($result[status] == 'failed')
{
echo "ilgili tarih araliginda islem bulunamadi";
}
else
{
echo $result[err_no] . " - " . $result[err_msg];
}
# Python 3.6+
import base64
import hmac
import hashlib
import json
import requests
merchant_id = 'XXXXXX'
merchant_key = b'XXXXXXXXYYYYYYYY'
merchant_salt = 'XXXXXXXXYYYYYYYY'
start_date = '2020-05-20 00:00:00'
end_date = '2020-06-16 23:59:59'
hash_str = merchant_id + start_date + end_date + merchant_salt
paytr_token = base64.b64encode(hmac.new(merchant_key, hash_str.encode(), hashlib.sha256).digest())
params = {
'merchant_id': merchant_id,
'start_date': start_date,
'end_date': end_date,
'paytr_token': paytr_token
}
result = requests.post('https://www.paytr.com/odeme/geri-donen-transfer', params)
res = json.loads(result.text)
"""
res değeri içerisinde;
['ref_no'] - 1000001
['date_detected'] - 2020-06-10
['date_reimbursed'] - 2020-06-08
['transfer_name'] - ÖRNEK İSİM
['transfer_iban'] - TR100000000000000000000001
['transfer_amount'] - 35.18
['transfer_currency'] - TL
['transfer_date'] - 2020-06-08
bilgileri dönmektedir.
"""
if res['status'] == 'success':
print(res)
elif res['status'] == 'failed':
print('İlgili tarih araliginda islem bulunamadi')
else:
print(res['err_no'] + ' - ' + res['err_msg'])
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;
using System.Web.Routing;
namespace WebApplication1.Controllers
{
public class paytr_geri_donen_odemeler_listele_ornekController : Controller
{
public ActionResult paytr_geri_donen_odemeler_listele_ornek()
{
string merchant_id = "AAAAAA";
string merchant_key = "XXXXXXXXXXXXXXXX";
string merchant_salt = "XXXXXXXXXXXXXXXX";
string start_date = "2021-11-01 00:00:00";
string end_date = "2021-11-29 23:59:59";
string Birlestir = string.Concat(merchant_id,start_date,end_date,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["start_date"] = start_date;
data["end_date"] = end_date;
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/geri-donen-transfer", "POST", data);
string ResultAuthTicket = Encoding.UTF8.GetString(result);
dynamic json = JValue.Parse(ResultAuthTicket);
if (json.status == "success")
{
Response.Write(json);
}
else if (json.status == "failed")
{
Response.Write("İlgili tarih araliginda islem bulunamadi");
}
else
{
Response.Write(json.err_no + "-" + 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 = 'XXXXXXXXYYYYYYYY';
var merchant_salt = 'XXXXXXXXYYYYYYYY';
app.get("/list", function (req, res) {
var start_date = '2020-11-01 00:00:00';
var end_date = '2020-11-29 23:59:59';
var paytr_token = crypto.createHmac('sha256', merchant_key).update(merchant_id + start_date + end_date + merchant_salt).digest('base64');
var options = {
'method': 'POST',
'url': 'https://www.paytr.com/odeme/geri-donen-transfer',
'headers': {
'Content-Type': 'application/x-www-form-urlencoded'
},
form: {
'merchant_id': merchant_id,
'start_date': start_date,
'end_date': end_date,
'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(res_data);
} else {
console.log(response.body);
res.end(response.body);
}
});
});
app.get("/send", function (req, res) {
var trans_id = '';
var trans_info = [{
'amount': '1283',
'receiver': 'XYZ LTD ŞTİ',
'iban': 'TRXXXXXXXXXXXXXXXXXXXXX'
}];
var paytr_token = crypto.createHmac('sha256', merchant_key).update(merchant_id + trans_id + merchant_salt).digest('base64');
var options = {
'method': 'POST',
'url': 'https://www.paytr.com/odeme/hesaptan-gonder',
'headers': {
'Content-Type': 'application/x-www-form-urlencoded'
},
form: {
'trans_info': JSON.stringify(trans_info),
'trans_id': trans_id,
'paytr_token': paytr_token,
'merchant_id': merchant_id,
}
};
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 {
res.end(response.body);
}
});
});
app.post("/callback", function (req, res) {
var callback = req.body;
var paytr_token = crypto.createHmac('sha256', merchant_key).update(callback.merchant_id + callback.trans_id + merchant_salt).digest('base64');
if (paytr_token != callback.hash) {
throw new Error("PAYTR notification failed: bad hash");
}
var processed_result = JSON.parse(callback.processed_result);
for (const [key, value] of Object.entries(processed_result)) {
console.log(`${key}: ${value}`);
}
res.send("OK");
});
var port = 3200;
app.listen(port, function () {
console.log("Server is running. Port:" + port);
});