Pay By Link (E-Invoice) - Using our APIS
if you already have your own dashboard and you want to generate e-invoices for your clients , you can login to fawry and generat e-invoices using our APIS
Refund Invoice API
to refund paid invoice you can use Refund API.
In case you are still in development phase, you will need to call our API using POST at the following staging endpoint API point URL
Meanwhile, whenever you are ready for production, you should use the following production API endpoint URL instead
Detailed description of the parameters that you need to incorporate into your POST request are given in the table below.
Parameter | type | Required | Description |
---|---|---|---|
amount | double |
required | Total amount of the invoice. |
reason | String |
required | Reason of refund. |
orderReferenceNumber | String |
required | The reference number of the order to be refunded. |
Sample API Calls
An example call of refund API for an amount of 362.50EGP is given below.
function refund(transaction_data) {
const refundData = {
amount: transaction_data.amount,
reason: transaction_data.reason,
orderReferenceNumber: transaction_data.orderReferenceNumber,
};
// Use fetch to send request data to FawryPay Refund API.
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
const response = await fetch('https://atfawry.fawrystaging.com/invoice-api/invoices/{invoice_num}/refund', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + transaction_data.token, // The token you obtained from the login API
},
body: JSON.stringify(refundData),
});
// Return and display the result of the charge.
return response.json();
}
$amount = '150';
$reason = 'The reason of refund';
$orderReferenceNumber = '145556';
$response =request('POST', 'https://atfawry.fawrystaging.com/invoice-api/invoices/{invoice_num}/refund', [
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Bearer ' + $token, // The token you obtained from the login API
],
'body' => json_encode( [
'amount' => $amount,
'reason' => $reason,
] , true)
]);
$response = json_decode($response->getBody()->getContents(), true);
$refundData = $response['type']; // post response values
# importing the requests library
import requests
# importing Hash Library
import hashlib
# FawryPay refund invoice API Endpoint
URL = "https://atfawry.fawrystaging.com/invoice-api/invoices/{invoice_num}/refund"
# refund Data
amount = '150'
reason = 'The reason of refund'
orderReferenceNumber = '145556'
# defining a params dict for the parameters to be sent to the API
refundData = {
'amount' : amount,
'reason' : reason,
'orderReferenceNumber' : orderReferenceNumber,
}
# sending post request and saving the response as response object
refund_request = requests.post(url = URL, params = json.dumps(refundtData),
headers={'Content-Type':'application/json',
'Authorization': 'Bearer {}'.AccessToken}//The token you obtained from the login API
)
# extracting data in json format
status_response = status_request.json()
function refund() {
let amount = "150";
let reason = "The reason of refund";
let orderReferenceNumber = "145556";
axios.post('https://atfawry.fawrystaging.com/invoice-api/invoices/{invoice_num}/refund', {
'amount' : amount,
'reason' : reason,
'orderReferenceNumber' : orderReferenceNumber,
},
headers: {
'Authorization': `Bearer AccessToken` //The token you obtained from the login API
}
)
.then(response => {
// post Response Contents
let refundData = response.data.refundData;
//
})
.catch(error => {
console.log(error.response.data)
})
}
$ curl https://atfawry.fawrystaging.com/invoice-api/invoices/{invoice_num}/refund\
-H "content-type: application/json , Authorization: Bearer ACCESS_TOKEN" \
-X POST \
-d "{
"amount": "150",
"reason": "The reason of refund",
"orderReferenceNumber" : "145556"
}"
URL url = new URL ("https://atfawry.fawrystaging.com/invoice-api/invoices/{invoice_num}/refund");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestproperty("Authorization","Bearer " + AccessToken); //The token you obtained from the login API
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
String jsonInputString = "{
"amount": "150",
"reason": "The reason of refund",
"orderReferenceNumber" : "145556"
}";
try(OutputStream os = con.getOutputStream()) {
byte[] input = jsonInputString.getBytes("utf-8");
os.write(input, 0, input.length);
}
try(BufferedReader br = new BufferedReader(
new InputStreamReader(con.getInputStream(), "utf-8"))) {
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println(response.toString());
}
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Newtonsoft.Json;
namespace FawryPayRequest
{
public class Program
{
static void Main(string[] args)
{
PostJson("https://atfawry.fawrystaging.com/invoice-api/invoices/{invoice_num}/refund", new refund_request
{
amount = "150",
reason = "The reason of refund",
orderReferenceNumber = "145556",
});
}
private static void PostJson(string uri, refund_request postParameters)
{
string postData = JsonConvert.SerializeObject(postParameters);
byte[] bytes = Encoding.UTF8.GetBytes(postData);
var httpWebRequest = (HttpWebRequest) WebRequest.Create(uri);
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = bytes.Length;
httpWebRequest.Headers.Add("Authorization", "Bearer " + AccessToken);//The token you obtained from the login API
httpWebRequest.ContentType = "text/json";
using (Stream requestStream = httpWebRequest.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Count());
}
var httpWebResponse = (HttpWebResponse) httpWebRequest.GetResponse();
if (httpWebResponse.StatusCode != HttpStatusCode.OK)
{
string message = String.Format("POST failed. Received HTTP {0}", httpWebResponse.StatusCode);
throw new ApplicationException(message);
}
}
}
public class refund_request
{
public string amount { get; set; }
public string reason { get; set; }
public string orderReferenceNumber { get; set; }
}
}
Request Parameters
Regardless of the choice of your preferred language, any of the code snippets above should produce an POST request containing the following JSON object in the request header:
{
"amount": "150",
"reason": "The reason of refund",
"orderReferenceNumber" : "145556"
}
Error Handling
After submitting an API call to FawryPay, you receive a response back to inform you that your request was received and processed. A sample error response can be found below.
Depending on the HTTP status code of the response, you should build some logic to handle any errors that a request or the system may return. A list of possible potential error codes that you may receive can found below. For a full list of all possible error codes can be found in the Error Codes section.
Error Code | Description |
---|---|
200 | Operation done successfully. |
400 | Bad Request. |
POSThttps://atfawry.fawrystaging.com/invoice-api/invoices/{invoice_num}/refund
// please run login API and put your token in the token field below
Response
// API Response Data Should Appear here
// This is a sample successful Response
{
}
Was this page helpful?
Thank you for helping improve FawryPay's documentation. If you need help or have any questions, please consider contacting support.