Returning Payments Send From Account
With this service, a transfer request has been made but you can send a payment request for the returning payments due to the buyer account error. Returned payments are processed as a balance to a subaccount for your store. You can access the list of these reimbursed payments with the “Returning Payments - List API” service.
1-To send payment transfer from the account, send the information specified in the table to the URL related to POST: https://www.paytr.com/odeme/hesaptan-gonder
Required parameters for token creation
Field name / type |
Description |
Mandatory |
Limitations |
merchant_id(integer) |
Merchant No: Merchant number given to you by PayTR |
Yes |
- |
trans_id(string) |
Transfer ID: The unique transaction number you set for the transfer transaction. |
Yes |
Up to 64 characters, alpha numeric) |
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(integer) |
Merchant No: Merchant number given to you by PayTR |
Yes |
- |
trans_id(string) |
Transfer ID: The unique transaction number you set for the transfer transaction |
Yes |
Up to 64 characters, alpha numeric) |
trans_info(JSON) |
Transfer Information: Content in JSON format containing transfer amount, recipient name and IBAN values.(See sample code for how to define it) |
Yes |
- |
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(See sample code for calculation) |
Yes |
- |
2- Your request will be returned in JSON format.
a. If the request is valid, the status number returns the transaction number you sent in the success and trans_id field.
b. 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.
3- After receiving the success response, your request to send from the account will be successfully received by the PayTR system. The PayTR system will process your request in an average of 5 minutes, check the trans_info content you send, and make the transfers. If incorrect information is detected during the check, the relevant transaction is marked as unsuccessful. The resulting result is notified by
POST to the address you defined as PayTR Mağaza Paneli > Ayarlar > Platform Transfer Sonucu Bildirim URL in JSON format.
<?php
$merchant_id = 'XXXXXX';
$merchant_key = 'XXXXXXXXYYYYYYYY';
$merchant_salt = 'XXXXXXXXYYYYYYYY';
$trans_id="PHG".time();
$trans_info=array();
$trans_info[]=array("amount"=>"1283",
"receiver"=>"XYZ LTD ŞTİ",
"iban"=>"TRXXXXXXXXXXXXXXXXXXXXX");
$paytr_token=base64_encode(hash_hmac('sha256',$merchant_id.$trans_id.$merchant_salt, $merchant_key, true));
$post_vals=array('trans_info'=>json_encode($trans_info),
'trans_id'=>$trans_id,
'paytr_token'=>$paytr_token,
'merchant_id'=>$merchant_id
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.paytr.com/odeme/hesaptan-gonder");
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_raw=$result;
$result=json_decode($result,1);
if($result['status']=='success')
{
print_r($result_raw);
}
else
{
print_r($result_raw);
}
# Python 3.6+
import base64
import hmac
import hashlib
import json
import requests
import random
merchant_id = 'XXXXXX'
merchant_key = b'XXXXXXXXYYYYYYYY'
merchant_salt = 'XXXXXXXXYYYYYYYY'
trans_id = 'PHG' + random.randint(1, 9999999).__str__()
trans_info = [
{
'amount': '1283',
'receiver': 'XYZ LTD ŞTİ',
'iban': 'TRXXXXXXXXXXXXXXXXXXXXX'
}
]
hash_str = merchant_id + trans_id + merchant_salt
paytr_token = base64.b64encode(hmac.new(merchant_key, hash_str.encode(), hashlib.sha256).digest())
params = {
'trans_info': json.dumps(trans_info),
'trans_id': trans_id,
'merchant_id': merchant_id,
'paytr_token': paytr_token
}
result = requests.post('https://www.paytr.com/odeme/hesaptan-gonder', params)
res = json.loads(result.text)
if res['status'] == 'success':
print(res)
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;
namespace WebApplication1.Controllers
{
class PayTR
{
public string amount { get; set; }
public string receiver { get; set; }
public string iban { get; set; }
}
public class paytr_geri_donen_odemeler_hesaptan_gonder_ornekController : Controller
{
public ActionResult paytr_geri_donen_odemeler_hesaptan_gonder_ornek()
{
List<PayTR> TransferInfo = new List<PayTR>();
PayTR info = new PayTR();
info.amount = Convert.ToString(10 * 100); //amount 100 ile çarpılarak gönderilir.
info.receiver = "XYZ LTD ŞTİ";
info.iban = "TRXXXXXXXXXXXXXXXXXXXXX";
TransferInfo.Add(info);
string TransInfo = Newtonsoft.Json.JsonConvert.SerializeObject(TransferInfo);
string merchant_id = "AAAAAA";
string merchant_key = "XXXXXXXXXXXXXXXX";
string merchant_salt = "XXXXXXXXXXXXXXXX";
string TransId = "ZZZZZZZ";
string Birlestir = string.Concat(merchant_id, TransId, 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["trans_info"] = TransInfo;
data["trans_id"] = TransId;
data["paytr_token"] = paytr_token;
data["merchant_id"] = merchant_id;
using (WebClient client = new WebClient())
{
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
byte[] result = client.UploadValues("https://www.paytr.com/odeme/hesaptan-gonder", "POST", data);
string ResultAuthTicket = Encoding.UTF8.GetString(result);
dynamic json = JValue.Parse(ResultAuthTicket);
if (json.status == "success")
{
Response.Write(json);
}
else
{
Response.Write("Error. reason:" + 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);
});