Authorize and Capture Payments
Learn how to use FawryPay APIs to authorize a payment that you can capture later.
Throughout this page, you will learn how to use our set of comprehensive APIs to create payments authorization, capture authorized payment, and cancel payment authorization.
In a situation you might have a delayed shipment for which you do not want to collect funds right away, an authorization places a hold on the funds for you to capture later. After a successful authorization, FawryPay recommends that you capture the funds within the honor period.
How it works?
- Collect your client's payment details.
- Authorize the payment.
- Capture the authorized payment.
- Cancel payment authorization (optional).
1. Collect your client's payment details
Whenever your client is ready for checkout, you will need to present your own payment details form. This form should collect all payment details, i.e. preferred payment method , card details, and client's personal information. After collecting the required information, pass them to your server so your application can decide on the right Payment API to proceed with. For example, if the user choose to pay with his card, then, Pay with Card API is the right one to go with.
A sampleJSON Object that can be passed from your payment form to your server is provided below.
2. Authorize the payment
Payment authorization can be done either for card or card token payments. Depending on the payment method selected by your client, you may either proceed with with payment authorization using card information or you may use a pre-saved card token to issue the payment. A detailed description of each method associated API is given below.
This API can be used to authorize client payment using his card information. This authorization request shall place a hold on the client's card with the charged amount until you capture the payment later. 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
HTTP POST Parameters
Detailed description of the parameters that you need to incorporate into your POST request are given in the table below.
Parameter | type | required | Description | |
---|---|---|---|---|
merchantCode | String |
required | The merchant code provided by FawryPay team during the account setup. | |
merchantRefNum | Integer |
required | The unique reference number for the charge request in merchant system. | |
customerProfileId | Integer |
optional | The unique customer profile ID in merchant system. This can be the user ID. | |
paymentMethod | String |
required | Payment Method: PAYATFAWRY, CASHONDELIVERY, CARD, MWALLET. | |
cardNumber | Integer |
required | Card Number. | |
cardExpiryYear | Integer |
required | Card Expiry Year in two digits format: 21, 22. | |
cardExpiryMonth | Integer |
required | Card Expiry Month in two digits format: 05, 12. | |
cvv | Integer |
required | Card cvv code. | |
customerName | String |
optional | The customer name in merchant system. | |
customerMobile | String |
required | The customer mobile in merchant system: 01xxxxxxx. | |
customerEmail | String |
required | The customer e-mail in merchant system: test@email.com. | |
amount | Decimal |
required | The charge amount: must be in the form of xx.xx. | |
description | String |
required | Item description. | |
language | String |
required | Language: "ar-eg" - "en-gb". This key will control the language of the notification message to the customer | |
chargeItems
|
||||
itemId | String |
required | The id for the charge item | |
description | String |
required | Description of charge item. | |
price | Decimal |
required | Price per unit charge item. | |
quantity | Decimal |
required | Quantity of the charge items. | |
authCaptureModePayment | Boolean |
required | Set to "true" to enable authentication capture option. | |
signature | String |
required | The SHA-256 digested for the following concatenated string "merchantCode + merchantRefNum + customerProfileId + paymentMethod + amount (in two decimal format 10.00) + cardNumber + cardExpiryYear + cardExpiryMonth + cvv + secureKey" |
An example call of card payment with an amount of 580.55EGP is given below.
function FawryPayAuthCard(transaction_data) {
const PaymentData = {
merchantCode: transaction_data.merchantCode,
customerName: transaction_data.customerName,
customerMobile : transaction_data.customerMobile,
customerEmail : transaction_data.customerEmail,
customerProfileId : transaction_data.customerProfileId,
cardNumber : transaction_data.cardNumber,
cardExpiryYear : transaction_data.cardExpiryYear,
cardExpiryMonth : transaction_data.cardExpiryMonth,
cvv : transaction_data.cvv,
merchantRefNum : transaction_data.merchantRefNum,
amount : transaction_data.amount,
currencyCode : transaction_data.currencyCode,
language: transaction_data.language, // "en-gb" or "ar-eg"
chargeItems : [
{
itemId : transaction_data.chargeItems.itemId,
description : transaction_data.chargeItems.description,
price : transaction_data.chargeItems.price,
quantity : transaction_data.chargeItems.quantity
}
],
enable3DS : true,
authCaptureModePayment : true,
signature : transaction_data.signature ,
paymentMethod : 'CARD' ,
description : 'transaction description'
};
// Use fetch to send the Payment Data to FawryPay.
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
const response = await fetch('https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(PaymentData),
});
// Return and display the result of the charge.
return response.json();
}
$merchantCode = '1tSa6uxz2nTwlaAmt38enA==';
$merchantRefNum = '2312465464';
$merchant_cust_prof_id = '777777';
$payment_method = 'CARD';
$amount = '580.55';
$cardNumber = '4242424242424242',
$cardExpiryYear = '25';
$cardExpiryMonth = '05';
$cvv = 123;
$merchant_sec_key = '259af31fc2f74453b3a55739b21ae9ef'; // For the sake of demonstration
$signature = hash('sha256' , $merchantCode . $merchantRefNum . $merchant_cust_prof_id . $payment_method .
$amount . $cardNumber . $cardExpiryYear . $cardExpiryMonth . $cvv .$merchant_sec_key);
$httpClient = new \GuzzleHttp\Client(); // guzzle 6.3
$response = $httpClient->request('POST', 'https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge', [
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json'
],
'body' => json_encode( [
'merchantCode' => $merchantCode,
'merchantRefNum' => $merchantRefNum,
'customerMobile' => '01234567891',
'customerEmail' => 'example@gmail.com',
'customerProfileId'=> '777777',
'cardNumber' => '4242424242424242',
'cardExpiryYear' => '25',
'cardExpiryMonth' => '05',
'cvv' => '123',
'amount' => '580.55',
'currencyCode' => 'EGP',
'language' => 'en-gb',
'chargeItems' => [
'itemId' => '897fa8e81be26df25db592e81c31c',
'description' => 'Item Description',
'price' => '580.55',
'quantity' => '1'
],
'authCaptureModePayment' => true,
'signature' => $signature,
'paymentMethod' => 'CARD',
'description' => 'example description'
] , true)
]);
$response = json_decode($response->getBody()->getContents(), true);
$paymentStatus = $response['type']; // get response values
# importing the requests library
import requests
# importing Hash Library
import hashlib
# FawryPayAPI Endpoint
URL = "https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge"
# Payment Data
merchantCode = '1tSa6uxz2nTwlaAmt38enA=='
merchantRefNum = '2312465464'
merchant_cust_prof_id = '777777'
paymentMethod = 'CARD'
amount = '580.55'
cardNumber = '4242424242424242'
cardExpiryYear = '21'
cardExpiryMonth = '05'
cvv = 123
merchant_sec_key = '259af31fc2f74453b3a55739b21ae9ef' // For the sake of demonstration
signature = hashlib.sha256(merchantCode + merchantRefNum + merchant_cust_prof_id + payment_method +
amount + cardNumber + cardExpiryYear + cardExpiryMonth + cvv + merchant_sec_key).hexdigest()
# defining a params dict for the parameters to be sent to the API
PaymentData = {
'merchantCode' : merchantCode,
'merchantRefNum' : merchantRefNum,
'customerName' : 'Ahmed Ali',
'customerMobile' : '01234567891',
'customerEmail' : 'example@gmail.com',
'customerProfileId' : '777777',
'cardNumber' : '4242424242424242',
'cardExpiryYear' : '21',
'cardExpiryMonth' : '05',
'cvv' : '123',
'amount' : '580.55',
'currencyCode' : 'EGP',
'language' : 'en-gb',
'chargeItems' : {
'itemId' : '897fa8e81be26df25db592e81c31c',
'description' : 'Item Description',
'price' : '580.55',
'quantity' : '1'
},
'authCaptureModePayment' : true,
'signature' : signature,
'paymentMethod' : 'CARD',
'description': 'example description'
}
# sending post request and saving the response as response object
status_request = requests.post(url = URL, params = json.dumps(PaymentData))
# extracting data in json format
status_response = status_request.json()
// you Need to install sha256 and axios and import both inside js or by script tag
// sha256 from https://cdnjs.cloudflare.com/ajax/libs/js-sha256/0.9.0/sha256.min.js
//axios from https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js
import { sha256 } from 'js-sha256';
import axios from 'axios';
function FawryPayAuthCard() {
let merchantCode = "1tSa6uxz2nTwlaAmt38enA==";
let merchantRefNum = "2312465464";
let merchant_cust_prof_id = "777777";
let payment_method = "CARD";
let amount = "580.55";
let cardNumber = "4242424242424242";
let cardExpiryYear = "21";
let cardExpiryMonth = "05";
let cvv = 123;
let merchant_sec_key = "259af31fc2f74453b3a55739b21ae9ef";
let signature_body = merchantCode.concat(merchantCode , merchantRefNum , merchant_cust_prof_id , payment_method ,
amount , cardNumber , cardExpiryYear , cardExpiryMonth , cvv , merchant_sec_key);
let sha256 = new jsSHA('SHA-256', 'TEXT');
sha256.update(signature_body);
let hash_signature = sha256.getHash("HEX");
axios.post('https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge', {
'merchantCode' : merchantCode,
'merchantRefNum' : merchantRefNum,
'customerName' : 'Ahmed Ali',
'customerMobile' : '01234567891',
'customerEmail' : 'example@gmail.com',
'customerProfileId' : '777777',
'cardNumber' : '4242424242424242',
'cardExpiryYear' : '21',
'cardExpiryMonth' : '05',
'cvv' : '123',
'amount' : '580.55',
'currencyCode' : 'EGP',
'language' : 'en-gb',
'chargeItems' : {
'itemId' : '897fa8e81be26df25db592e81c31c',
'description' : 'Item Description',
'price' : '580.55',
'quantity' : '1'
},
'authCaptureModePayment' : true,
'signature' : hash_signature,
'paymentMethod' : 'CARD',
'description': 'example description'
})
.then(response => {
// Get Response Contents
let type = response.data.type;
let paymentStatus = response.data.paymentStatus;
//
})
.catch(error => {
console.log(error.response.data)
})
}
$ curl https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge \
-H "content-type: application/json" \
-X POST \
-d "{
"merchantCode" : "1tSa6uxz2nTwlaAmt38enA==",
"merchantRefNum" : "2312465464",
"customerProfileId" : "777777",
"customerName" : "customer name",
"customerMobile" : "01234567891",
"customerEmail" : "example@gmail.com",
"cardNumber" : "4242424242424242",
"cardExpiryYear" : "25",
"cardExpiryMonth" : "05",
"cvv" : 123,
"amount" : 580.55,
"currencyCode" : "EGP",
"language" : "en-gb",
"chargeItems" : {
"itemId" : "897fa8e81be26df25db592e81c31c",
"description" : "Item Description",
"price" : 580.55,
"quantity" : 1
},
"enable3DS" : "true",
"authCaptureModePayment" : true,
"signature" : "3f527d0209f4fa5e370caf46f66597c6a7c04580c827ca1f29927ec0d9215131",
"paymentMethod" : "CARD",
"description": "example description"
}"
URL url = new URL ("https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge");
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 = "{
"merchantCode" : "1tSa6uxz2nTwlaAmt38enA==",
"merchantRefNum" : "2312465464",
"customerName" : "Ahmed Ali",
"customerMobile" : "01234567891",
"customerEmail" : "example@gmail.com",
"customerProfileId" : "777777",
"cardNumber" : "4242424242424242",
"cardExpiryYear" : "21",
"cardExpiryMonth" : "05",
"cvv" : 123,
"amount" : 580.55,
"currencyCode" : "EGP",
"language" : "en-gb",
"chargeItems" : {
"itemId" : "897fa8e81be26df25db592e81c31c",
"description" : "Item Description",
"price" : 580.55,
"quantity" : 1
},
"enable3DS" : true,
"authCaptureModePayment" : true,
"signature" : "3f527d0209f4fa5e370caf46f66597c6a7c04580c827ca1f29927ec0d9215131",
"paymentMethod" : "CARD",
"description": "example description"
}";
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/ECommerceWeb/Fawry/payments/charge", new fawrypay_request
{
merchantCode = "1tSa6uxz2nTwlaAmt38enA==",
merchantRefNum = "2312465464",
customerProfileId = "777777",
customerName = "customer name",
customerMobile = "01234567891",
customerEmail = "example@gmail.com",
cardNumber = "4242424242424242",
cardExpiryYear = "21",
cardExpiryMonth = "05",
cvv = 123,
amount = 580.55,
currencyCode = "EGP",
language = "en-gb",
chargeItems = {
itemId = "897fa8e81be26df25db592e81c31c",
description = "Item Description",
price = 580.55,
quantity = 1
},
authCaptureModePayment = "true",
signature = "3f527d0209f4fa5e370caf46f66597c6a7c04580c827ca1f29927ec0d9215131",
payment_method = CARD,
description = "example description"
});
}
private static void PostJson(string uri, fawrypay_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 fawrypay_request
{
public string merchantCode { get; set; }
public string merchantRefNum { get; set; }
public string signature { get; set; }
public string merchantCode { get; set; }
public string merchantRefNum { get; set; }
public string customerName { get; set; }
public string customerMobile { get; set; }
public string customerEmail { get; set; }
public string customerProfileId { get; set; }
public string cardNumber { get; set; }
public string cardExpiryYear { get; set; }
public string cardExpiryMonth { get; set; }
public string cvv { get; set; }
public string amount { get; set; }
public string currencyCode { get; set; }
public string language { get; set; }
public ChargeItems chargeItems;
public string authCaptureModePayment { get; set; }
public string signature { get; set; }
public string payment_method { get; set; }
public string description { get; set; }
}
public class ChargeItems
{
public string itemId { get; set; }
public string description { get; set; }
public string price { get; set; }
public string quantity { get; set; }
}
}
Sample Request Data
{
"merchantCode": "1tSa6uxz2nTwlaAmt38enA==",
"merchantRefNum": "2312465464",
"customerProfileId": "777777",
"customerName": "example",
"customerMobile": "01234567891",
"customerEmail": "example@gmail.com",
"cardNumber": "4242424242424242",
"cardExpiryYear": "25",
"cardExpiryMonth": "05",
"cvv": "123",
"amount": 580.55,
"currencyCode": "EGP",
"language" : "en-gb",
"chargeItems": [
{
"itemId": "897fa8e81be26df25db592e81c31c",
"description": "Item Descriptoin",
"price": 580.55,
"quantity": "1"
}
],
"enable3DS" : true,
"authCaptureModePayment" : true,
"signature": "2ca4c078ab0d4c50ba90e31b3b0339d4d4ae5b32f97092dd9e9c07888c7eef36",
"paymentMethod": "CARD",
"description": "Example Description"
}
FawryPay Sample Response
Whenever you call FawryPay authroize payment API, you may expect a response in the form of JSON object which contains all necessary payment processing information.
Sample Authorize Payment API Response
Response Parameters Description
Arguments | type | Description | example |
---|---|---|---|
type | String |
Type of response. | ChargeResponse |
referenceNumber | String |
FawryPay issued transaction reference number. | 963455678 |
merchantRefNumber | String |
Merchant issued transaction reference number. This is the same as the reference number you have set in your charge request. | 9990d0642040 |
orderAmount | Decimal |
Order amount in two decimal places format. | 20.00 |
paymentAmount | Decimal |
The paid amount in two decimal places format. | 20.00 |
fawryFees | Decimal |
The payment processing fees. | 1.00 |
paymentMethod | String |
Payment Method Selected by your client. | 'CashOnDelivery', 'PayAtFawry', 'MWALLET', 'CARD' or 'VALU' |
orderStatus | String |
Order Status. | PAID |
paymentTime | Integer |
Timestamp to record when the payment has been processed. | 1607879720568 |
customerMobile | String |
Customer Mobile Number. | 01234567891 |
customerMail | String |
Customer E-mail address. | example@email.com |
customerProfileId | String |
Customer Profile ID in the merchant's system. | 1212 |
signature | String |
Response Signature generated as the SHA-256 of the following concatenated string (referenceNumber (if exist) + merchantRefNum + paymentAmount (in two decimal places format 10.00) + orderAmount (in two decimal places format 10.00) + orderStatus + paymentMethod + fawryFees (if exist) (in two decimal places format 10.00)) + shippingFees (if exist) (in two decimal places format 10.00)) + authNumber (if exists) + customerMail (if exist) + customerMobile (if exist) + secureKey) | 2df2943c6704176809ba6d559e2906b3d4df14916d6 |
statusCode | String |
Response status code. | 200 |
statusDescription | String |
Response status description. | Operation done successfully |
POSThttps://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge
Response
// API Response Data Should Appear here
// This is a sample successful Response
{
"type": "ChargeResponse",
"nextAction": {
"type": "THREE_D_SECURE",
"redirectUrl": "https://atfawry.fawrystaging.com/atfawry/plugin/3ds/7103292588"
},
"statusCode": 200,
"statusDescription": "Operation done successfully",
"basketPayment": false
}
3DS Charge Request using Card Token POST
This API can be used to authorize client payment using his pre-saved card token information. This authorization request shall place a hold on the client's card with the charged amount until you capture the payment later. 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 | |
---|---|---|---|---|
merchantCode | String |
required | The merchant code provided by FawryPay team during the account setup. | |
merchantRefNum | Integer |
required | The unique reference number for the charge request in merchant system. | |
customerProfileId | Integer |
optional | The unique customer profile ID in merchant system. This can be the user ID. | |
paymentMethod | String |
required | Payment Method: PAYATFAWRY, CASHONDELIVERY, CARD, MWALLET. | |
cardToken | String |
required | Card Token. | |
cvv | Integer |
required | Card cvv code. | |
customerName | String |
optional | The customer name in merchant system. | |
customerMobile | String |
required | The customer mobile in merchant system: 01xxxxxxx | |
customerEmail | String |
required | The customer e-mail in merchant system: test@email.com | |
amount | Decimal |
required | The charge amount: must in the form of xx.xx | |
description | String |
required | Item description. | |
language | String |
required | Language: "ar-eg" - "en-gb". This key will control the language of the notification message to the customer | |
chargeItems
|
||||
itemId | String |
required | The id for the charge item | |
description | String |
required | Description of charge item. | |
price | Decimal |
required | Price per unit charge item. | |
quantity | Decimal |
required | Quantity of the charge items. | |
authCaptureModePayment | Boolean |
required | Set to "true" to enable authentication capture option. | |
signature | String |
required | The SHA-256 digested for the following concatenated string "merchantCode + merchantRefNum + customerProfileId + paymentMethod + amount (in two decimal format 10.00) + cardToken + cvv + secureKey" |
An example call of authorization of card token payment with an amount of 580.55EGP is given below.
function FawryPayAuthCardToken(transaction_data) {
const PaymentData = {
merchantCode: transaction_data.merchantCode,
customerName: transaction_data.customerName,
customerMobile : transaction_data.customerMobile,
customerEmail : transaction_data.customerEmail,
customerProfileId : transaction_data.customerProfileId,
cardToken : transaction_data.cardToken,
cvv : transaction_data.cvv,
merchantRefNumber : transaction_data.merchantRefNumber,
amount : transaction_data.amount,
currencyCode : transaction_data.currencyCode,
language: transaction_data.language, // "en-gb" or "ar-eg"
chargeItems : [
{
itemId : transaction_data.chargeItems.itemId,
description : transaction_data.chargeItems.description,
price : transaction_data.chargeItems.price,
quantity : transaction_data.chargeItems.quantity
}
],
authCaptureModePayment : true,
signature : transaction_data.signature ,
paymentMethod : 'CARD' ,
description : 'transaction description'
};
// Use fetch to send the Payment Data to FawryPay.
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
const response = await fetch('https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(PaymentData),
});
// Return and display the result of the charge.
return response.json();
}
$merchantCode = '1tSa6uxz2nTwlaAmt38enA==';
$merchantRefNumber = '2312465464';
$merchant_cust_prof_id = '777777';
$payment_method = 'CARD';
$amount = '580.55';
$card_token = 'ac0a1909256e8bb5a35a6311c5e824c223d13ae877c5bb0419350b01c619d59d';
$cvv = 123;
$merchant_sec_key = '259af31fc2f74453b3a55739b21ae9ef'; // For the sake of demonstration
$signature = hash('sha256' , $merchantCode . $merchantRefNumber . $merchant_cust_prof_id . $payment_method . $amount . $card_token . $cvv . $merchant_sec_key);
$httpClient = new \GuzzleHttp\Client(); // guzzle 6.3
$response = $httpClient->request('POST', 'https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge', [
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json'
],
'body' => json_encode( [
'merchantCode' => $merchantCode,
'merchantRefNumber' => $merchantRefNumber,
'customerName' => 'Ahmed Ali',
'customerMobile' => '01234567891',
'customerEmail' => 'example@gmail.com',
'customerProfileId'=> '777777',
'cardToken' => $card_token,
'cvv' => '123',
'amount' => '580.55',
'currencyCode' => 'EGP',
'language' => 'en-gb',
'chargeItems' => [
'itemId' => '897fa8e81be26df25db592e81c31c',
'description' => 'Item Description',
'price' => '580.55',
'quantity' => '1'
],
'authCaptureModePayment' => true,
'signature' => $signature,
'paymentMethod' => 'CARD',
'description' => 'example description'
] , true)
]);
$response = json_decode($response->getBody()->getContents(), true);
$paymentStatus = $response['type']; // get response values
# importing the requests library
import requests
# importing Hash Library
import hashlib
# FawryPay API Endpoint
URL = "https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge"
# Payment Data
merchantCode = '1tSa6uxz2nTwlaAmt38enA=='
merchantRefNumber = '2312465464'
merchant_cust_prof_id = '777777'
payment_method = 'CARD'
amount = '580.55'
cvv = 123
card_token = 'ac0a1909256e8bb5a35a6311c5e824c223d13ae877c5bb0419350b01c619d59d'
merchant_sec_key = '259af31fc2f74453b3a55739b21ae9ef' // For the sake of demonstration
signature = hashlib.sha256(merchantCode + merchantRefNumber + merchant_cust_prof_id + payment_method + amount + card_token + cvv + merchant_sec_key).hexdigest()
# defining a params dict for the parameters to be sent to the API
PaymentData = {
'merchantCode' : merchantCode,
'merchantRefNumber' : merchantRefNumber,
'customerName' : 'Ahmed Ali',
'customerMobile' : '01234567891',
'customerEmail' : 'example@gmail.com',
'customerProfileId' : '777777',
'cardToken' : card_token,
'cvv' : '123',
'amount' : '580.55',
'currencyCode' : 'EGP',
'language' : 'en-gb',
'chargeItems' : {
'itemId' : '897fa8e81be26df25db592e81c31c',
'description' : 'Item Description',
'price' : '580.55',
'quantity' : '1'
},
'authCaptureModePayment' : true,
'signature' : signature,
'paymentMethod' : 'CARD',
'description': 'example description'
}
# sending post request and saving the response as response object
status_request = requests.post(url = URL, params = json.dumps(PaymentData))
# extracting data in json format
status_response = status_request.json()
// you Need to install sha256 and axios and import both inside js or by script tag
// sha256 from https://cdnjs.cloudflare.com/ajax/libs/js-sha256/0.9.0/sha256.min.js
//axios from https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js
import { sha256 } from 'js-sha256';
import axios from 'axios';
function FawryPayAuthCardToken() {
let merchantCode = "1tSa6uxz2nTwlaAmt38enA==";
let merchantRefNumber = "2312465464";
let merchant_cust_prof_id = "777777";
let payment_method = "CARD";
let amount = "580.55";
let card_token = 'ac0a1909256e8bb5a35a6311c5e824c223d13ae877c5bb0419350b01c619d59d';
let cvv = 123;
let merchant_sec_key = "259af31fc2f74453b3a55739b21ae9ef";
let signature_body = merchantCode.concat(merchantCode , merchantRefNumber , merchant_cust_prof_id , payment_method , amount , card_token, cvv, merchant_sec_key);
let sha256 = new jsSHA('SHA-256', 'TEXT');
sha256.update(signature_body);
let hash_signature = sha256.getHash("HEX");
axios.post('https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge', {
'merchantCode' : merchantCode,
'merchantRefNumber' : merchantRefNumber,
'customerName' : 'Ahmed Ali',
'customerMobile' : '01234567891',
'customerEmail' : 'example@gmail.com',
'customerProfileId' : '777777',
'cardToken' : card_token,
'cvv' : '123',
'amount' : '580.55',
'currencyCode' : 'EGP',
'language' : 'en-gb',
'chargeItems' : {
'itemId' : '897fa8e81be26df25db592e81c31c',
'description' : 'Item Description',
'price' : '580.55',
'quantity' : '1'
},
'authCaptureModePayment' : true,
'signature' : hash_signature,
'paymentMethod' : 'CARD',
'description': 'example description'
})
.then(response => {
// Get Response Contents
let type = response.data.type;
let paymentStatus = response.data.paymentStatus;
//
})
.catch(error => {
console.log(error.response.data)
})
}
$ curl https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge \
-H "content-type: application/json" \
-X POST \
-d "{
"merchantCode" : "1tSa6uxz2nTwlaAmt38enA==",
"merchantRefNumber" : "2312465464",
"customerName" : "Ahmed Ali",
"customerMobile" : "01234567891",
"customerEmail" : "example@gmail.com",
"customerProfileId" : "777777",
"cardToken" : "ac0a1909256e8bb5a35a6311c5e824c223d13ae877c5bb0419350b01c619d59d",
"cvv" : 123,
"amount" : 580.55,
"currencyCode" : "EGP",
"language" : "en-gb",
"chargeItems" : {
"itemId" : "897fa8e81be26df25db592e81c31c",
"description" : "Item Description",
"price" : 580.55,
"quantity" : 1
},
"authCaptureModePayment" : true,
"signature" : "3f527d0209f4fa5e370caf46f66597c6a7c04580c827ca1f29927ec0d9215131",
"paymentMethod" : "CARD",
"description": "example description"
}"
URL url = new URL ("https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge");
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 = "{
"merchantCode" : "1tSa6uxz2nTwlaAmt38enA==",
"merchantRefNumber" : "2312465464",
"customerName" : "Ahmed Ali",
"customerMobile" : "01234567891",
"customerEmail" : "example@gmail.com",
"customerProfileId" : "777777",
"cardToken" : "4f2f5dc87684fd67cb54c5dfbe30daec7e35e14265168db2a800c6553ef1aae1",
"cvv" : 123,
"amount" : 580.55,
"currencyCode" : "EGP",
"language" : "en-gb",
"chargeItems" : {
"itemId" : "897fa8e81be26df25db592e81c31c",
"description" : "Item Description",
"price" : 580.55,
"quantity" : 1
},
"authCaptureModePayment" : true,
"signature" : "3f527d0209f4fa5e370caf46f66597c6a7c04580c827ca1f29927ec0d9215131",
"paymentMethod" : "CARD",
"description": "example description"
}";
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/ECommerceWeb/Fawry/payments/charge", new fawrypay_request
{
merchantCode = "1tSa6uxz2nTwlaAmt38enA==",
merchantRefNumber = "2312465464",
customerName = "Ahmed Ali",
customerMobile = "01234567891",
customerEmail = "example@gmail.com",
customerProfileId = "777777",
cardToken = "4f2f5dc87684fd67cb54c5dfbe30daec7e35e14265168db2a800c6553ef1aae1",
cvv = "123",
amount = "580.55",
currencyCode = "EGP",
language = "en-gb",
chargeItems = {
itemId = "897fa8e81be26df25db592e81c31c",
description = "Item Description",
price = 580.55,
quantity = 1
},
authCaptureModePayment = "true",
signature = "3f527d0209f4fa5e370caf46f66597c6a7c04580c827ca1f29927ec0d9215131",
paymentMethod = "CARD",
description = "example description"
});
}
private static void PostJson(string uri, fawrypay_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 fawrypay_request
{
public string merchantCode { get; set; }
public string merchantRefNumber { get; set; }
public string signature { get; set; }
public string merchantCode { get; set; }
public string merchantRefNumber { get; set; }
public string customerName { get; set; }
public string customerMobile { get; set; }
public string customerEmail { get; set; }
public string customerProfileId { get; set; }
public string cardToken { get; set; }
public string cvv { get; set; }
public string amount { get; set; }
public string currencyCode { get; set; }
public string language { get; set; }
public ChargeItems chargeItems;
public string authCaptureModePayment { get; set; }
public string signature { get; set; }
public string payment_method { get; set; }
public string description { get; set; }
}
public class ChargeItems
{
public string itemId { get; set; }
public string description { get; set; }
public string price { get; set; }
public string quantity { get; set; }
}
}
Sample Request Data
{
"merchantCode": "1tSa6uxz2nTwlaAmt38enA==",
"customerName": "example name",
"customerMobile": "01234567891",
"customerEmail": "example@gmail.com",
"customerProfileId": "777777",
"cardToken": "ac0a1909256e8bb5a35a6311c5e824c223d13ae877c5bb0419350b01c619d59d",
"cvv": "123",
"merchantRefNum": "2312465464",
"amount": "580.55",
"currencyCode": "EGP",
"language" : "en-gb",
"chargeItems": [
{
"itemId": "897fa8e81be26df25db592e81c31c",
"description": "Item Descriptoin",
"price": "580.55",
"quantity": "1"
}
],
"authCaptureModePayment" : true,
"signature": "2ca4c078ab0d4c50ba90e31b3b0339d4d4ae5b32f97092dd9e9c07888c7eef36",
"paymentMethod": "CARD",
"description": "Example Description"
}
FawryPay Sample Response
Whenever you call FawryPay authorize payment API, you should expect a response in the form of JSON object which contains all necessary payment processing information.
Sample Authorize payment API Response
Response Parameters Description
Arguments | type | Description | example |
---|---|---|---|
type | String |
Type of response. | ChargeResponse |
referenceNumber | String |
FawryPay issued transaction reference number. | 963455678 |
merchantRefNumber | String |
Merchant issued transaction reference number. This is the same as the reference number you have set in your charge request. | 9990d0642040 |
orderAmount | Decimal |
Order amount in two decimal places format. | 20.00 |
paymentAmount | Decimal |
The paid amount in two decimal places format. | 20.00 |
fawryFees | Decimal |
The payment processing fees. | 1.00 |
paymentMethod | String |
Payment Method Selected by your client. | 'CashOnDelivery', 'PayAtFawry', 'MWALLET', 'CARD' or 'VALU' |
orderStatus | String |
Order Status. | PAID |
paymentTime | Integer |
Timestamp to record when the payment has been processed. | 1607879720568 |
customerMobile | String |
Customer Mobile Number. | 01234567891 |
customerMail | String |
Customer E-mail address. | example@email.com |
customerProfileId | String |
Customer Profile ID in the merchant's system. | 1212 |
signature | String |
Response Signature generated as the SHA-256 of the following concatenated string (referenceNumber (if exist) + merchantRefNum + paymentAmount (in two decimal places format 10.00) + orderAmount (in two decimal places format 10.00) + orderStatus + paymentMethod + fawryFees (if exist) (in two decimal places format 10.00)) + shippingFees (if exist) (in two decimal places format 10.00)) + authNumber (if exists) + customerMail (if exist) + customerMobile (if exist) + secureKey) | 2df2943c6704176809ba6d559e2906b3d4df14916d6 |
statusCode | String |
Response status code. | 200 |
statusDescription | String |
Response status description. | Operation done successfully |
POSThttps://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge
Response
// API Response Data Should Appear here
// This is a sample successful Response
{
"type": "ChargeResponse",
"referenceNumber": "963455678",
"merchantRefNumber": "9990d0642040",
"orderAmount": 20.00,
"paymentAmount": 20.00,
"fawryFees": 1.00,
"paymentMethod": "CARD",
"orderStatus": "PAID",
"paymentTime": 1607879720568,
"customerMobile": "01234567891",
"customerMail": "example@gmail.com",
"customerProfileId": "1212",
"signature": "b0ef178e2f06b215b18cfc7d82fb5d1f7b95dfcc91e33f8a6ce1e1251fdd04ec",
"statusCode": 200,
"statusDescription": "Operation done successfully"
}
3. Capture the authorized payment
Capture Authorized Payment POST
This API can be used to capture a payment for which you have created a payment authorization. To capture an authorized payment, include the authorization ID (merchantRefNum) you received with your payment authorization request. 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
HTTP POST Parameters
Detailed description of the parameters that you need to incorporate into your POST request are given in the table below.
Parameter | type | required | Description |
---|---|---|---|
merchantCode | String |
required | The merchant code provided by FawryPay team during the account setup. |
merchantRefNum | Integer |
required | The unique reference number for the charge request in merchant system. You should have received this number at the time of payment authorization. |
captureAmount | Double |
optional | in case you need to capture a partial amount of the order total amount in case you didn`t add the captureAmount parameter, we will capture the full amount. |
requestSignature | String |
required | The SHA-256 digested for the following concatenated string "merchantRefNum + captureAmount (if exist in two decimal format 10.00, otherwise "") + merchantCode + secureKey" |
An example call of card payment with an amount of 580.55EGP is given below.
function FawryPayCapture(transaction_data) {
const PaymentData = {
merchantCode: transaction_data.merchantCode,
merchantRefNum : transaction_data.merchantRefNum,
requestSignature : transaction_data.signature ,
};
// Use fetch to send the Payment Data to FawryPay.
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
const response = await fetch('https://atfawry.fawrystaging.com/ECommerceWeb/api/payment/capture', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(PaymentData),
});
// Return and display the result of the charge.
return response.json();
}
$merchantCode = '1tSa6uxz2nTwlaAmt38enA==';
$merchantRefNum = '2312465464';
$merchant_sec_key = '259af31fc2f74453b3a55739b21ae9ef'; // For the sake of demonstration
$signature = hash('sha256' , $merchantRefNum . $merchantCode . $merchant_sec_key);
$httpClient = new \GuzzleHttp\Client(); // guzzle 6.3
$response = $httpClient->request('POST', 'https://atfawry.fawrystaging.com/ECommerceWeb/api/payment/capture', [
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json'
],
'body' => json_encode( [
'merchantCode' => $merchantCode,
'merchantRefNum' => $merchantRefNum,
'requestSignature' => $signature,
] , true)
]);
$response = json_decode($response->getBody()->getContents(), true);
$paymentStatus = $response['type']; // get response values
# importing the requests library
import requests
# importing Hash Library
import hashlib
# FawryPayAPI Endpoint
URL = "https://atfawry.fawrystaging.com/ECommerceWeb/api/payment/capture"
# Payment Data
merchantCode = '1tSa6uxz2nTwlaAmt38enA=='
merchantRefNum = '2312465464'
merchant_sec_key = '259af31fc2f74453b3a55739b21ae9ef' // For the sake of demonstration
signature = hashlib.sha256(merchantRefNum + merchantCode + merchant_sec_key).hexdigest()
# defining a params dict for the parameters to be sent to the API
PaymentData = {
'merchantCode' : merchantCode,
'merchantRefNum' : merchantRefNum,
'requestSignature' : signature,
}
# sending post request and saving the response as response object
status_request = requests.post(url = URL, params = json.dumps(PaymentData))
# extracting data in json format
status_response = status_request.json()
// you Need to install sha256 and axios and import both inside js or by script tag
// sha256 from https://cdnjs.cloudflare.com/ajax/libs/js-sha256/0.9.0/sha256.min.js
//axios from https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js
import { sha256 } from 'js-sha256';
import axios from 'axios';
function FawryPayCapture() {
let merchantCode = "1tSa6uxz2nTwlaAmt38enA==";
let merchantRefNum = "2312465464";
let merchant_sec_key = "259af31fc2f74453b3a55739b21ae9ef";
let signature_body = merchantCode.concat( merchantRefNum, merchantCode , merchant_sec_key);
let sha256 = new jsSHA('SHA-256', 'TEXT');
sha256.update(signature_body);
let hash_signature = sha256.getHash("HEX");
axios.post('https://atfawry.fawrystaging.com/ECommerceWeb/api/payment/capture', {
'merchantCode' : merchantCode,
'merchantRefNum' : merchantRefNum,
'requestSignature' : hash_signature,
})
.then(response => {
// Get Response Contents
let type = response.data.type;
let paymentStatus = response.data.paymentStatus;
//
})
.catch(error => {
console.log(error.response.data)
})
}
$ curl https://atfawry.fawrystaging.com/ECommerceWeb/api/payment/capture \
-H "content-type: application/json" \
-X POST \
-d "{
"merchantCode" : "1tSa6uxz2nTwlaAmt38enA==",
"merchantRefNum" : "2312465464",
"requestSignature" : "3f527d0209f4fa5e370caf46f66597c6a7c04580c827ca1f29927ec0d9215131",
}"
URL url = new URL ("https://atfawry.fawrystaging.com/ECommerceWeb/api/payment/capture");
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 = "{
"merchantCode" : "1tSa6uxz2nTwlaAmt38enA==",
"merchantRefNum" : "2312465464",
"requestSignature" : "3f527d0209f4fa5e370caf46f66597c6a7c04580c827ca1f29927ec0d9215131",
}";
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/ECommerceWeb/api/payment/capture", new fawrypay_request
{
merchantCode = "1tSa6uxz2nTwlaAmt38enA==",
merchantRefNum = "2312465464",
requestSignature = "3f527d0209f4fa5e370caf46f66597c6a7c04580c827ca1f29927ec0d9215131"
});
}
private static void PostJson(string uri, fawrypay_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 fawrypay_request
{
public string merchantCode { get; set; }
public string merchantRefNum { get; set; }
public string requestSignature { get; set; }
}
}
Sample Request Data
{
"merchantCode": "1tSa6uxz2nTwlaAmt38enA==",
"merchantRefNum": "2312465464", // Use the same merchantRefNum received at payment auth time
"requestSignature": "2ca4c078ab0d4c50ba90e31b3b0339d4d4ae5b32f97092dd9e9c07888c7eef36"
}
FawryPay Sample Response
Whenever you call FawryPay capture authorized payment API, you may expect a response in the form of JSON object which contains all necessary payment processing information.
Sample Capture Authorized Payment API Response
Response Parameters Description
POSThttps://atfawry.fawrystaging.com/ECommerceWeb/api/payment/capture
Response
// API Response Data Should Appear here
// This is a sample successful Response
{
"type": "PaymentCaptureChargeResponse",
"fawryRefNumber": "100163201",
"merchantCode": "1tSa6uxz2nTwlaAmt38enA=="
"merchantRefNum": "2312465464",
"orderStatus" : "PAID",
"signature" : "809c20749f7daf13ac688e779510d2f19b857c27bd6ae4aab103df44c2c5f056",
"statusCode": 200,
"statusDescription": "Operation done successfully"
}
4. Cancel payment authorization
Cancel Payment AuthorizationPOST
This API can be used to cancel a payment authorization. To cancel an authorized payment, include the authorization ID (merchantRefNum) you received with your payment authorization request. 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
HTTP POST Parameters
Detailed description of the parameters that you need to incorporate into your POST request are given in the table below.
Parameter | type | required | Description |
---|---|---|---|
merchantCode | String |
required | The merchant code provided by FawryPay team during the account setup. |
merchantRefNum | Integer |
required | The unique reference number for the charge request in merchant system. |
requestSignature | String |
required | The SHA-256 digested for the following concatenated string "merchantRefNum + merchantCode + secureKey" |
An example call of card payment with an amount of 580.55EGP is given below.
function FawryPayCancelAuth(transaction_data) {
const PaymentData = {
merchantCode: transaction_data.merchantCode,
merchantRefNum : transaction_data.merchantRefNum,
requestSignature : transaction_data.signature ,
};
// Use fetch to send the Payment Data to FawryPay.
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
const response = await fetch('https://atfawry.fawrystaging.com/ECommerceWeb/api/payment/cancel', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(PaymentData),
});
// Return and display the result of the charge.
return response.json();
}
$merchantCode = '1tSa6uxz2nTwlaAmt38enA==';
$merchantRefNum = '23124654641';
$merchant_sec_key = '259af31fc2f74453b3a55739b21ae9ef'; // For the sake of demonstration
$signature = hash('sha256' , $merchantRefNum . $merchantCode . $merchant_sec_key);
$httpClient = new \GuzzleHttp\Client(); // guzzle 6.3
$response = $httpClient->request('POST', 'https://atfawry.fawrystaging.com/ECommerceWeb/api/payment/cancel', [
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json'
],
'body' => json_encode( [
'merchantCode' => $merchantCode,
'merchantRefNum' => $merchantRefNum,
'requestSignature' => $signature,
] , true)
]);
$response = json_decode($response->getBody()->getContents(), true);
$paymentStatus = $response['type']; // get response values
# importing the requests library
import requests
# importing Hash Library
import hashlib
# FawryPayAPI Endpoint
URL = "https://atfawry.fawrystaging.com/ECommerceWeb/api/payment/cancel"
# Payment Data
merchantCode = '1tSa6uxz2nTwlaAmt38enA=='
merchantRefNum = '23124654641'
merchant_sec_key = '259af31fc2f74453b3a55739b21ae9ef' // For the sake of demonstration
signature = hashlib.sha256(merchantRefNum + merchantCode + merchant_sec_key).hexdigest()
# defining a params dict for the parameters to be sent to the API
PaymentData = {
'merchantCode' : merchantCode,
'merchantRefNum' : merchantRefNum,
'requestSignature' : signature,
}
# sending post request and saving the response as response object
status_request = requests.post(url = URL, params = json.dumps(PaymentData))
# extracting data in json format
status_response = status_request.json()
function FawryPayCancelAuth() {
let merchantCode = "1tSa6uxz2nTwlaAmt38enA==";
let merchantRefNum = "23124654641";
let merchant_sec_key = "259af31fc2f74453b3a55739b21ae9ef";
let signature_body = merchantCode.concat(merchantRefNum, merchantCode , merchant_sec_key);
let sha256 = new jsSHA('SHA-256', 'TEXT');
sha256.update(signature_body);
let hash_signature = sha256.getHash("HEX");
axios.post('https://atfawry.fawrystaging.com/ECommerceWeb/api/payment/cancel', {
'merchantCode' : merchantCode,
'merchantRefNum' : merchantRefNum,
'requestSignature' : hash_signature,
})
.then(response => {
// Get Response Contents
let type = response.data.type;
let paymentStatus = response.data.paymentStatus;
//
})
.catch(error => {
console.log(error.response.data)
})
}
$ curl https://atfawry.fawrystaging.com/ECommerceWeb/api/payment/cancel \
-H "content-type: application/json" \
-X POST \
-d "{
"merchantCode" : "1tSa6uxz2nTwlaAmt38enA==",
"merchantRefNum" : "23124654641",
"requestSignature" : "3f527d0209f4fa5e370caf46f66597c6a7c04580c827ca1f29927ec0d9215131",
}"
URL url = new URL ("https://atfawry.fawrystaging.com/ECommerceWeb/api/payment/cancel");
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 = "{
"merchantCode" : "1tSa6uxz2nTwlaAmt38enA==",
"merchantRefNum" : "23124654641",
"requestSignature" : "3f527d0209f4fa5e370caf46f66597c6a7c04580c827ca1f29927ec0d9215131",
}";
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/ECommerceWeb/api/payment/cancel", new fawrypay_request
{
merchantCode = "1tSa6uxz2nTwlaAmt38enA==",
merchantRefNum = "23124654641",
requestSignature = "3f527d0209f4fa5e370caf46f66597c6a7c04580c827ca1f29927ec0d9215131"
});
}
private static void PostJson(string uri, fawrypay_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 fawrypay_request
{
public string merchantCode { get; set; }
public string merchantRefNum { get; set; }
public string requestSignature { get; set; }
}
}
Sample Request Data
{
"merchantCode": "1tSa6uxz2nTwlaAmt38enA==",
"merchantRefNum": "2312465464",
"requestSignature": "2ca4c078ab0d4c50ba90e31b3b0339d4d4ae5b32f97092dd9e9c07888c7eef36"
}
FawryPay Sample Response
Whenever you call FawryPay cancel authorized payment API, you may expect a response in the form of JSON object which contains all necessary payment processing information.
Sample Cancel Payment Authorization API Response
Response Parameters Description
POSThttps://atfawry.fawrystaging.com/ECommerceWeb/api/payment/cancel
Response
// API Response Data Should Appear here
// This is a sample successful Response
{
"type": "PaymentCaptureChargeResponse",
"fawryRefNumber": "100163201",
"merchantCode": "1tSa6uxz2nTwlaAmt38enA=="
"merchantRefNum": "2312465464",
"orderStatus" : "CANCELLED",
"signature" : "809c20749f7daf13ac688e779510d2f19b857c27bd6ae4aab103df44c2c5f056",
"statusCode": 200,
"statusDescription": "Operation done successfully"
}
5. Present Payment Result
After the client completes the payment and no further actions are
required on the front end or client app, use the stausCode
to inform
the client about the payment status.
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. |
9901 | merchant code is blank or invalid. |
9938 | Order not found. |
9946 | Blank or invalid signature. |
9935 | Refunded amount greater than paid amount. |
9954 | Order is not paid |
Next steps
Extend your Integration
Was this page helpful?
Thank you for helping improve FawryPay's documentation. If you need help or have any questions, please consider contacting support.