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
Refresh Token API
if your token is expired and you want to login again, so you have to use Refresh Token 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
You will need to incorporate the token you obtained during the login process into the body of the refresh token POST API.
Sample API Calls
An example call of Refresh Token API is given below.
function login(transaction_data) {
// Use fetch to send request data to FawryPay refreshToken API.
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
const response = await fetch('https://atfawry.fawrystaging.com/user-api/auth/token/refresh', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body:'WF0IjoxNjE0NcwMyIsInVzdCI6IkJVU0lODI0n3MS0xMWMzLTQxZmM',
});
// Return and display the result of the charge.
return response.json();
}
$response =request('POST', 'https://atfawry.fawrystaging.com/user-api/auth/token/refresh', [
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json'
],
'body' => 'WF0IjoxNjE0NcwMyIsInVzdCI6IkJVU0lODI0n3MS0xMWMzLTQxZmM',
]);
$response = json_decode($response->getBody()->getContents(), true);
$refreshData = $response['type']; // get response values
# importing the requests library
import requests
# importing Hash Library
import hashlib
# FawryPay login API Endpoint
URL = "https://atfawry.fawrystaging.com/user-api/auth/token/refresh"
# sending get request and saving the response as response object
login_request = requests.get(url = URL, params = 'WF0IjoxNjE0NcwMyIsInVzdCI6IkJVU0lODI0n3MS0xMWMzLTQxZmM')
# extracting data in json format
status_response = status_request.json()
function login() {
axios.get('https://atfawry.fawrystaging.com/user-api/auth/token/refresh',
'WF0IjoxNjE0NcwMyIsInVzdCI6IkJVU0lODI0n3MS0xMWMzLTQxZmM')
.then(response => {
// Get Response Contents
let refreshData = response.data.refreshData;
//
})
.catch(error => {
console.log(error.response.data)
})
}
$ curl https://atfawry.fawrystaging.com/user-api/auth/token/refresh\
-H "content-type: application/text" \
-X POST \
--data-raw WF0IjoxNjE0NcwMyIsInVzdCI6IkJVU0lODI0n3MS0xMWMzLTQxZmM
URL url = new URL ("https://atfawry.fawrystaging.com/user-api/auth/login");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
String jsonInputString = "{
returnURL,
}";
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/user-api/auth/login", new login_request
WF0IjoxNjE0NcwMyIsInVzdCI6IkJVU0lODI0n3MS0xMWMzLTQxZmM",
);
}
private static void PostJson(string uri, login_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.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("GET failed. Received HTTP {0}", httpWebResponse.StatusCode);
throw new ApplicationException(message);
}
}
}
public class login_request
{
public string refreshToken { 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 refresh token in the request body:
03fcb66ca88542b28a19a7993af0279961357816
Response Parameters
FawryPay Sample Response
Whenever you call FawryPay Refresh Token API, you may expect a response in the form of JSON object which contains all refresh token processing information.
Sample Refresh Token API Response
Response Parameters Description
Parameter | type | Description | example |
---|---|---|---|
token | String |
Used to allow the application to access the API. | MjxvQLYbauKzK0dNc5LSWKH5jVZhs0g6jMw7zpMjoCI |
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. |
500 | Internal server error. |
POSThttps://atfawry.fawrystaging.com/user-api/auth/login
Response
// API Response Data Should Appear here
// This is a sample successful Response
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOlsiZnAiLCJpbnYiXSwic3ViIjoiMDEyMzQ1Njc4OTkiLCJybG0iOiJCRSIsImZwYSI6IjQwMDAwMDAwNDcwMyIsInVzdCI6IkJVU0lORVNTX0VOVElUWSIsImJlaSI6OTIsImlzcyI6ImZhd3J5LmNvbSIsImV4cCI6MTYxNDQyNzYxNSwiaWF0IjoxNjE0NDI0MDE1LCJqdGkiOiI5Y2QwZGE3MS0xMWMzLTQxZmMtOTc2ZS1jODA5MWVjNmI3NmEifQ.MjxvQLYbauKzK0dNc5LSWKH5jVZhs0g6jMw7zpMjoCI",
}
Was this page helpful?
Thank you for helping improve FawryPay's documentation. If you need help or have any questions, please consider contacting support.