Refund a payment
This operation helps to return the entire amount of a transaction or part of it AFTER being captured. This operation can only be performed after the purchase has been authorized and payment has been captured.
The request
Use the details below to set up your request.
Endpoints
Live
POST https://paymentservices.payfort.com/FortAPI/paymentApi
Sandbox
POST https://sbpaymentservices.payfort.com/FortAPI/paymentApi
Request example
Check out the request parameters by visiting this link
Sample Request
Here are the sample request you are required to send authorizing a purchase.
error_reporting(E_ALL);
ini_set('display_errors', '1');
$url = 'https://sbpaymentservices.payfort.com/FortAPI/paymentApi';
$arrData = array(
'command' => 'REFUND',
'access_code' => 'zx0IPmPy5jp1vAz8Kpg7',
'merchant_identifier' => 'CycHZxVj',
'merchant_reference' => ' XYZ9239-yu898',
'amount' => '10000',
'currency' => 'AED',
'language' => 'en',
'signature' => '7cad05f0212ed933c9a5d5dffa31661acf2c827a',
'fort_id' => '149295435400084008',
'order_description' => 'iPhone 6-S',
);
$ch = curl_init( $url );
# Setup request to send json via POST.
$data = json_encode($arrData);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Print response.
echo "<pre>$result</pre>";
import urllib
import urllib2
import json
url = 'https://sbpaymentservices.payfort.com/FortAPI/paymentApi';
arrData = {
'command':'REFUND',
'access_code':'zx0IPmPy5jp1vAz8Kpg7',
'merchant_identifier':'CycHZxVj',
'merchant_reference':' XYZ9239-yu898',
'amount':'10000',
'currency':'AED',
'language':'en',
'signature':'7cad05f0212ed933c9a5d5dffa31661acf2c827a',
'fort_id':'149295435400084008',
'order_description':'iPhone 6-S',
};
values = json.dumps(arrData)
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
page = response.read()
print page + '\n\n'
require 'json'
require 'net/http'
require 'net/https'
require 'uri'
require 'openssl'
arrData = {
'command' => 'REFUND',
'access_code' => 'zx0IPmPy5jp1vAz8Kpg7',
'merchant_identifier' => 'CycHZxVj',
'merchant_reference' => ' XYZ9239-yu898',
'amount' => '10000',
'currency' => 'AED',
'language' => 'en',
'signature' => '7cad05f0212ed933c9a5d5dffa31661acf2c827a',
'fort_id' => '149295435400084008',
'order_description' => 'iPhone 6-S',
};
arrData = arrData.to_json
uri = URI.parse("https://sbpaymentservices.payfort.com/FortAPI/paymentApi")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new("/v1.1/auth")
request.add_field('Content-Type', 'application/json')
request.body = arrData
response = http.request(request)
String jsonRequestString = "{\"command\" : \"REFUND\" , \"access_code\" : \"zx0IPmPy5jp1vAz8Kpg7\", \"merchant_identifier\" : \"CycHZxVj\", "
+ "\"merchant_reference\" : \"XYZ9239-yu898\", \"amount\" : \"10000\", \"currency\" : \"AED\","
+ "\"language\" : \"en\", \"signature\" : \"7cad05f0212ed933c9a5d5dffa31661acf2c827a\", "
+ "\"fort_id\" : \"149295435400084008\", \"order_description\" : \"iPhone 6-S\"}";
// Define and Initialize HttpClient
HttpClient httpClient = HttpClientBuilder.create().build();
// Intialize HttpPOST with FORT Payment services URL
HttpPost request = new HttpPost("https://sbpaymentservices.payfort.com/FortAPI/paymentApi");
// Setup Http POST entity with JSON String
StringEntity params = new StringEntity(jsonRequestString);
// Setup request type as JSON
request.addHeader("content-type", "application/json");
request.setEntity(params);
// Post request to FORT
HttpResponse response = httpClient.execute(request);
// Read response using StringBuilder
StringBuilder sb = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()), 65728);
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
// Print response
System.out.println(sb.toString());
curl -H "Content-Type: application/json" -d
'{"command":"REFUND",
"access_code":"zx0IPmPy5jp1vAz8Kpg7",
"merchant_identifier":"CycHZxVj",
"merchant_reference":"XYZ9239-yu898",
"amount":"10000",
"currency":"AED",
"language":"en",
"signature":"7cad05f0212ed933c9a5d5dffa31661acf2c827a",
"fort_id":"149295435400084008",
"order_description":"iPhone6-S"}'
https://sbpaymentservices.payfort.com/FortAPI/paymentApi
The response
If you receive status code 20064
with status code 04
it means your request for refund has been accepted by the PayFort Server. The response sent by the server will be in the format of JSON.
Response examples
json
{"command":"REFUND",
"access_code":"zx0IPmPy5jp1vAz8Kpg7",
"merchant_identifier":"CycHZxVj",
"merchant_reference":"XYZ9239-yu898",
"amount":"10000",
"currency":"AED",
"language":"en",
"signature":"7cad05f0212ed933c9a5d5dffa31661acf2c827a",
"fort_id":"149295435400084008",
"order_description":"iPhone 6-S",
"response_message":"Success",
"response_code":"20064",
status":"04"
}
You can check out various transaction codes by visiting this link
Go to Full API
Check out our full API by visiting this link
Need further help?
Thanks for using PayFort.com. If you need any help or support, then message our support team at support@payfort.com.