### Sample Request Query Parameters
Source: https://developer.fawrystaging.com/docs/card-tokens/manage-card-tokens
Example of the resulting URL query parameters for the GET request.
```html
https://www.fawrypay.com/ECommerceWeb/Fawry/cards/cardToken?merchantCode=1tSa6uxz2nRbgY+b+cZGyA==&customerProfileId=777777&signature=2ca4c078ab0d4c50ba90e31b3b0339d4d4ae5b32f97092dd9e9c07888c7eef36
```
--------------------------------
### PHP R2P Wallet Payment Example
Source: https://developer.fawrystaging.com/docs/server-apis/mobile-wallet-payment
A PHP example demonstrating how to construct and send R2P wallet payment data using the Guzzle HTTP client. Ensure Guzzle is installed.
```php
$merchantCode = '1tSa6uxz2nTwlaAmt38enA==';
$merchantRefNumber = '23124654641';
$merchant_cust_prof_id = '777777';
$payment_method = 'MWALLET';
$amount = '580.55';
$debitMobileWalletNo = 01009914491;
$merchant_sec_key = '259af31fc2f74453b3a55739b21ae9ef'; // For the sake of demonstration
$signature = hash('sha256' , $merchantCode . $merchantRefNumber . $merchant_cust_prof_id . $payment_method . $amount . $debitMobileWalletNo. $merchant_sec_key);
$httpClient = new \GuzzleHttp\Client(); // guzzle 6.3
$response = $httpClient->request('POST', 'https://atfawry.fawrystaging.com/ECommerceWeb/api/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',
'amount' => '580.55',
'currencyCode' => 'EGP',
'language' => 'en-gb',
'chargeItems' => [
'itemId' => '897fa8e81be26df25db592e81c31c',
'description' => 'Item Description',
'price' => '580.55',
'quantity' => '1'
],
'debitMobileWalletNo'=> $debitMobileWalletNo,
'signature' => $signature,
'paymentMethod' => 'MWALLET',
'description' => 'example description'
] , true)
]);
$response = json_decode($response->getBody()->getContents(), true);
$paymentStatus = $response['type']; // get response values
```
--------------------------------
### Bash Example
Source: https://developer.fawrystaging.com/docs/server-apis/auth-capture-payment-apis
Example of how to capture a payment using curl.
```bash
$ curl https://atfawry.fawrystaging.com/ECommerceWeb/api/payment/capture \
-H "content-type: application/json" \
-X POST \
-d "{
\"merchantCode\" : \"1tSa6uxz2nTwlaAmt38enA==\",
\"merchantRefNum\" : \"2312465464\",
\"requestSignature\" : \"3f527d0209f4fa5e370caf46f66597c6a7c04580c827ca1f29927ec0d9215131\",
}"
```
--------------------------------
### Java Example
Source: https://developer.fawrystaging.com/docs/server-apis/auth-capture-payment-apis
Example of how to capture a payment using Java.
```java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class FawryPayCapture {
public static void main(String[] args) {
try {
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 = "{\n" +
" \"merchantCode\" : \"1tSa6uxz2nTwlaAmt38enA==\",\n" +
" \"merchantRefNum\" : \"2312465464\",\n" +
" \"requestSignature\" : \"3f527d0209f4fa5e370caf46f66597c6a7c04580c827ca1f29927ec0d9215131\",\n" +
"}";
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());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
--------------------------------
### Login API Call Example in Python
Source: https://developer.fawrystaging.com/docs/pay-by-link-login-api
Python example for calling the Fawry Login API using the requests library. It shows how to define login data and send a GET request (note: example uses GET, API typically uses POST for login).
```Python
# importing the requests library
import requests
# importing Hash Library
import hashlib
# FawryPay login API Endpoint
URL = "https://atfawry.fawrystaging.com/user-api/auth/login"
# login Data
userIdentifier = '01234567899'
password = "****"
# defining a params dict for the parameters to be sent to the API
loginData = {
'userIdentifier' : userIdentifier,
'password' : password,
}
# sending get request and saving the response as response object
login_request = requests.get(url = URL, params = json.dumps(logintData))
```
--------------------------------
### C# Example
Source: https://developer.fawrystaging.com/docs/server-apis/auth-capture-payment-apis
Example of how to capture a payment using C#.
```csharp
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Newtonsoft.Json;
public class FawryPayRequest {
public class fawrypay_request {
public string merchantCode { get; set; }
public string merchantRefNum { get; set; }
public string requestSignature { get; set; }
}
public 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 = "application/json"; // Corrected ContentType
using (Stream requestStream = httpWebRequest.GetRequestStream()) {
requestStream.Write(bytes, 0, bytes.Length);
}
try {
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);
}
// Optionally read the response stream here
using (var reader = new StreamReader(httpWebResponse.GetResponseStream())) {
string responseText = reader.ReadToEnd();
Console.WriteLine(responseText);
}
} catch (WebException ex) {
Console.WriteLine(ex.Message);
if (ex.Response != null) {
using (var errorResponse = (HttpWebResponse)ex.Response) {
using (var reader = new StreamReader(errorResponse.GetResponseStream())) {
string errorText = reader.ReadToEnd();
Console.WriteLine(errorText);
}
}
}
}
}
}
```
--------------------------------
### Java HTTPURLConnection Setup
Source: https://developer.fawrystaging.com/docs/server-apis/auth-capture-payment-apis
This Java code snippet demonstrates the initial setup for making an HTTP POST request using HttpURLConnection. It sets the URL and the request method to POST.
```java
URL url = new URL ("https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
```
--------------------------------
### JavaScript Example (Node.js)
Source: https://developer.fawrystaging.com/docs/server-apis/auth-capture-payment-apis
Example of how to capture a payment using JavaScript with axios and js-sha256.
```javascript
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_hasher = sha256.create(); // Use create() for a new instance
sha256_hasher.update(signature_body);
let hash_signature = sha256_hasher.hex(); // Use hex() to get the hex string
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;
console.log('Payment Status:', paymentStatus);
})
.catch(error => {
console.log(error.response.data);
});
}
FawryPayCapture();
```
--------------------------------
### Refresh Token Implementation in Python
Source: https://developer.fawrystaging.com/docs/pay-by-link-refresh-token-api
Example of using the requests library to send a GET request to the refresh token endpoint.
```Python
# 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')
```
--------------------------------
### C#: HTTP Request for Invoice Details
Source: https://developer.fawrystaging.com/docs/pay-by-link-get-invoice-details
Implements an HTTP GET request in C# to retrieve invoice details. This example serializes request parameters and includes authorization headers.
```C#
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)
{
GetJson("https://atfawry.fawrystaging.com/invoice-api/invoices/{invoice_num}/details");
}
private static void GetJson(string uri, invoice_details_request GetParameters)
{
string GetData = JsonConvert.SerializeObject(GetParameters);
byte[] bytes = Encoding.UTF8.GetBytes(GetData);
var httpWebRequest = (HttpWebRequest) WebRequest.Create(uri);
httpWebRequest.Method = "Get";
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("Get failed. Received HTTP {0}", httpWebResponse.StatusCode);
throw new ApplicationException(message);
}
}
}
}
```
--------------------------------
### Get Installment Plans API Call in Python
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-bank-apis
This Python script uses the requests library to send a GET request to the Get Installment Plans API. The accountNumber is included as a JSON string in the parameters.
```Python
# importing the requests library
import requests
# Get Installment Plans API Endpoint
URL = "https://atfawry.fawrystaging.com/ECommerceWeb/api/merchant/installment-plans"
# defining a params dict for the parameters to be sent to the API
RequestData = {
'accountNumber' : '1tSa6uxz2nTwlaAmt38enA=='
}
# sending post request and saving the response as response object
status_request = requests.get(url = URL, params = json.dumps(RequestData))
```
--------------------------------
### Import FawryPay JavaScript Libraries
Source: https://developer.fawrystaging.com/docs/express-checkout/self-hosted-checkout
Select the appropriate library based on your environment. Use the staging library for development and the production library for live transactions.
```HTML
```
```HTML
```
--------------------------------
### Get Installment Plans API Call in PHP
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-bank-apis
This PHP code snippet uses Guzzle HTTP client to make a GET request to the Get Installment Plans API. It retrieves and decodes the JSON response.
```PHP
$accountNumber = '1tSa6uxz2nTwlaAmt38enA==';
$httpClient = new \GuzzleHttp\Client(); // guzzle 6.3
$response = $httpClient->request('GET', 'https://atfawry.fawrystaging.com/ECommerceWeb/api/merchant/installment-plans', [
'query' => [
'accountNumber' => $accountNumber
]
]);
$response = json_decode($response->getBody()->getContents(), true);
$installmentPlan = $response['installmentPlan']; // get response values
```
--------------------------------
### Get Installment Plans API Endpoint (Production)
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-bank-apis
Use this production endpoint for live transactions to retrieve installment plans. Include your accountNumber in the GET request.
```HTTP
https://www.atfawry.com/ECommerceWeb/api/merchant/installment-plans
```
--------------------------------
### Install and Activate Plugin
Source: https://developer.fawrystaging.com/docs/plugins/magento-plugin
Run these commands in the Magento root directory to register and refresh the plugin after extracting the files.
```bash
php bin/magento setup:upgrade
php bin/magento cache:flush
php bin/magento cache:clean
```
--------------------------------
### Get Installment Plans API Endpoint (Staging)
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-bank-apis
Use this staging endpoint to retrieve installment plans associated with your account. Include your accountNumber in the GET request.
```HTTP
https://atfawry.fawrystaging.com/ECommerceWeb/api/merchant/installment-plans
```
--------------------------------
### Sample GET Request URL for Installment Plans
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-bank-apis
This is the structure of the GET request URL used to fetch installment plans from the Fawry API, including the accountNumber parameter.
```HTTP
https://atfawry.fawrystaging.com/ECommerceWeb/api/merchant/installment-plans?accountNumber=1tSa6uxz2nTwlaAmt38enA==
```
--------------------------------
### Get Installment Plans using Bash
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-bank-apis
This Bash command uses curl to make a GET request to the Fawry API for installment plans. The accountNumber is passed as data.
```Bash
$ curl https://atfawry.fawrystaging.com/ECommerceWeb/api/merchant/installment-plans \
-X GET \
-d accountNumber = 1tSa6uxz2nTwlaAmt38enA==
```
--------------------------------
### Java: FawryPay Charge Request Setup
Source: https://developer.fawrystaging.com/docs/server-apis/mobile-wallet-payment
Sets up an HTTP connection to the FawryPay API for a POST request. Configures request properties and prepares the JSON input string.
```java
URL url = new URL ("https://atfawry.fawrystaging.com/ECommerceWeb/api/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" : "23124654641",
"customerName" : "Ahmed Ali",
"customerMobile" : "01234567891",
"customerEmail" : "example@gmail.com",
```
--------------------------------
### Get Installment Plans API Call in JavaScript
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-bank-apis
This JavaScript function uses the Fetch API to call the Get Installment Plans API. Ensure the correct staging or production URL is used.
```JavaScript
function FawryGetInstallmentPlans(transaction_data) {
const PaymentData = {
accountNumber: transaction_data.accountNumber
};
// Use fetch to send the Get Installment Plans API.
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
const response = await fetch('https://atfawry.fawrystaging.com/ECommerceWeb/api/merchant/installment-plans', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(PaymentData),
});
// Return and display the result of the charge.
return response.json();
}
```
--------------------------------
### Get Installment Plans using C#
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-bank-apis
This C# code snippet shows how to make a GET request to the Fawry API for installment plans using HttpWebRequest. It serializes the request object and handles the response.
```C#
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/merchant/installment-plans", new fawrypay_request
{
accountNumber = "1tSa6uxz2nTwlaAmt38enA=="
});
}
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 = "GET";
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 accountNumber { get; set; }
}
}
```
--------------------------------
### Initialize Java HTTP connection
Source: https://developer.fawrystaging.com/docs/card-tokens/create-use-token
Set up a basic HTTP connection for POST requests in Java.
```Java
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);
```
--------------------------------
### Get Installment Plans using Java
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-bank-apis
This Java code demonstrates how to make an HTTP GET request to the Fawry API to fetch installment plans. It sets request properties and handles the response using HttpURLConnection.
```Java
URL url = new URL ("https://atfawry.fawrystaging.com/ECommerceWeb/api/merchant/installment-plans");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
String jsonInputString = "{
"accountNumber": "1tSa6uxz2nTwlaAmt38enA=="
}";
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());
}
```
--------------------------------
### Get Installment Plans using JavaScript
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-bank-apis
Use this JavaScript snippet with Axios to retrieve installment plans. Ensure you have Axios installed. The merchant code is required.
```JavaScript
function FawryGetInstallmentPlans() {
let merchantCode = "1tSa6uxz2nTwlaAmt38enA==";
axios.get('https://atfawry.fawrystaging.com/ECommerceWeb/api/merchant/installment-plans', {
'accountNumber' : merchantCode
})
.then(response => {
// Get Response Contents
let accountType = response.data.accountType;
let installmentPlan = response.data.installmentPlan;
//
})
.catch(error => {
console.log(error.response.data)
})
}
```
--------------------------------
### Python R2P Wallet Payment Setup
Source: https://developer.fawrystaging.com/docs/server-apis/mobile-wallet-payment
Initial setup for making R2P wallet payments in Python, including importing necessary libraries and defining the API endpoint. This snippet is incomplete and requires further implementation for the actual request.
```python
# importing the requests library
import requests
# importing Hash Library
import hashlib
# FawryPay API Endpoint
URL = "https://atfawry.fawrystaging.com/ECommerceWeb/api/payments/charge"
```
--------------------------------
### Get Payment Status API Endpoint URL
Source: https://developer.fawrystaging.com/docs/express-checkout/payment-notifications/get-payment-status-v2
Example of the GET request URL structure including query parameters for merchant identification and signature.
```HTTP
https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/status/v2?merchantCode=is0N+YQzlE4=&merchantRefNumber=23124654641
&signature=a5701a2e1e865bf863f0c781829f709ea4d36bdaf7d70e9bafb9458b1
```
--------------------------------
### Login API Call Example in JavaScript (React)
Source: https://developer.fawrystaging.com/docs/pay-by-link-login-api
Example of how to call the Fawry Login API using JavaScript's fetch API. Requires userIdentifier and password. Handles JSON response.
```JavaScript
function login(transaction_data) {
const loginData = {
userIdentifier: transaction_data.userIdentifier,
password: transaction_data.password,
};
// Use fetch to send request data.
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
const response = await fetch('https://atfawry.fawrystaging.com/user-api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(loginData),
});
// Return and display the result of the charge.
return response.json();
}
```
--------------------------------
### GET /api/merchant/installment-plans
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-bank-apis
Retrieves a list of available installment plans for merchants.
```APIDOC
## GET /api/merchant/installment-plans
### Description
Retrieves a list of available installment plans for merchants.
### Method
GET
### Endpoint
`https://atfawry.fawrystaging.com/ECommerceWeb/api/merchant/installment-plans`
### Request Body
```json
{
"accountNumber": "is0N%2BYQzlE4%3D"
}
```
### Response
#### Success Response (200)
- **id** (integer) - The ID of the installment plan.
- **installmentPlan** (object) - Details of the installment plan.
- **id** (integer) - The ID of the installment plan.
- **nameAr** (string) - The name of the installment plan in Arabic.
- **nameEn** (string) - The name of the installment plan in English.
- **rate** (float) - The interest rate for the installment plan.
- **noOfMonths** (integer) - The number of months for the installment plan.
- **merchantProfileCode** (string) - The merchant profile code.
- **minAmount** (float) - The minimum amount for the installment plan.
- **maxAmount** (float) - The maximum amount for the installment plan.
- **startDate** (long) - The start date of the installment plan in milliseconds.
- **endDate** (long) - The end date of the installment plan in milliseconds.
- **online** (boolean) - Indicates if the plan is available online.
- **status** (object) - The status of the installment plan.
- **id** (integer) - The ID of the status.
- **code** (string) - The status code.
- **nameAr** (string) - The status name in Arabic.
- **nameEn** (string) - The status name in English.
- **accountType** (object) - Details of the account type.
- **id** (integer) - The ID of the account type.
- **nameEn** (string) - The account type name in English.
- **nameAr** (string) - The account type name in Arabic.
- **code** (string) - The account type code.
- **bank** (object) - Details of the bank.
- **id** (integer) - The ID of the bank.
- **nameEn** (string) - The bank name in English.
- **nameAr** (string) - The bank name in Arabic.
- **code** (string) - The bank code.
- **swfCode** (string) - The SWF code of the bank.
- **pans** (array) - List of PANs associated with the account type.
- **type** (string) - The type of installment plan.
- **applyTo** (string) - Specifies what the installment plan applies to.
- **products** (array) - List of products associated with the plan.
- **productsCodes** (array) - List of product codes.
- **variants** (array) - List of variants.
- **categories** (array) - List of categories.
- **requiredItemsValidation** (boolean) - Indicates if item validation is required.
#### Response Example
```json
{
"id": 1,
"installmentPlan": {
"id": 1,
"nameAr": "5 months",
"nameEn": "5 months",
"rate": 5.0,
"noOfMonths": 5,
"merchantProfileCode": "TEST525785",
"minAmount": 10.0,
"maxAmount": 1000.0,
"startDate": 1555891200000,
"endDate": 1598832000000,
"online": true,
"status": {
"id": 1,
"code": "ACTIVE",
"nameAr": "ACTIVE",
"nameEn": "ACTIVE"
},
"accountType": {
"id": 1,
"nameEn": "VC",
"nameAr": "VC",
"code": "VC",
"bank": {
"id": 1,
"nameEn": "VC",
"nameAr": "VC",
"code": "VC",
"swfCode": "VC"
},
"pans": [
"500555",
"500555",
"600555",
"700555",
"800555",
"512345"
]
},
"type": "INDIRECT"
},
"applyTo": "ANY_PRODUCT",
"products": [],
"productsCodes": [],
"variants": [],
"categories": [],
"requiredItemsValidation": false
}
```
```
--------------------------------
### GET /ECommerceWeb/api/merchant/installment-plans
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-bank-apis
Retrieves the list of installment plans available for a specific merchant account.
```APIDOC
## GET /ECommerceWeb/api/merchant/installment-plans
### Description
Retrieves the payment plans associated with your merchant account.
### Method
GET
### Endpoint
Staging: https://atfawry.fawrystaging.com/ECommerceWeb/api/merchant/installment-plans
Production: https://www.atfawry.com/ECommerceWeb/api/merchant/installment-plans
### Parameters
#### Query Parameters
- **accountNumber** (String) - Required - The merchant code provided by FawryPay team during the account setup.
### Request Example
GET /ECommerceWeb/api/merchant/installment-plans?accountNumber=1tSa6uxz2nTwlaAmt38enA==
### Response
#### Success Response (200)
- **installmentPlan** (Array) - The list of available installment plans.
```
--------------------------------
### PHP FawryPay MWALLET Payment Example
Source: https://developer.fawrystaging.com/docs/server-apis/mobile-wallet-payment
This PHP example demonstrates how to make a MWALLET payment request to FawryPay using Guzzle HTTP client. It includes signature generation and constructing the request body.
```php
$merchantCode = '1tSa6uxz2nTwlaAmt38enA==';
$merchantRefNum = '23124654641';
$merchant_cust_prof_id = '777777';
$payment_method = 'MWALLET';
$amount = '580.55';
$merchant_sec_key = '259af31fc2f74453b3a55739b21ef'; // For the sake of demonstration
$signature = hash('sha256' , $merchantCode . $merchantRefNum . $merchant_cust_prof_id . $payment_method .
$amount . $merchant_sec_key);
$httpClient = new \GuzzleHttp\Client(); // guzzle 6.3
$response = $httpClient->request('POST', 'https://atfawry.fawrystaging.com/ECommerceWeb/api/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',
'amount' => '580.55',
'currencyCode' => 'EGP',
'language' => 'en-gb',
'chargeItems' => [
'itemId' => '897fa8e81be26df25db592e81c31c',
'description' => 'Item Description',
'price' => '580.55',
'quantity' => '1'
],
'signature' => $signature,
'payment_method' => 'MWALLET',
'description' => 'example description'
] , true)
]);
$response = json_decode($response->getBody()->getContents(), true);
$paymentStatus = $response['type']; // get response values
```
--------------------------------
### Compile and Deploy Static Files
Source: https://developer.fawrystaging.com/docs/plugins/magento-plugin
Required steps when running Magento in production mode to ensure the module is correctly compiled and assets are deployed.
```bash
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
```
--------------------------------
### PHP Example for Payment Link Parameters
Source: https://developer.fawrystaging.com/docs/pay-by-link-add-payment-link-api
This PHP code snippet demonstrates how to define variables for payment link parameters. It includes examples for dates, customer data, discounts, and items.
```PHP
$sendingDate= "2021-02-27";
$expiryDate= "2021-02-28T13:19:17.000Z";
$note= "invoice description";
$releaseDate= "2021-02-27T13:16:50.668Z";
$alertMerchantUponExpiry= "false";
$requiredCustomerData= [
[ "id"=> 1,
"code"=> "NAME",
"nameAr"=> "اسم العميل",
"nameEn"=> "Customer name"],
[
"id"=> 3,
"code"=> "MOBILE_NUMBER",
"nameAr"=> "الهاتف",
"nameEn"=> "Mobile number"]
];
$discount= [
"value"=> 20,
"type"=> "FLAT"
];
$taxes= 0;
$amount= 150.75;
$items= [
"nameEn"=> "description 1",
"nameAr"=> "description 1",
```
--------------------------------
### Get FawryPay Payment Status in JavaScript
Source: https://developer.fawrystaging.com/docs/payment-notifications/get-payment-status-v2
Use this JavaScript function to check the payment status by generating a SHA256 signature and making an HTTP GET request. Ensure you have sha256 and axios libraries installed.
```javascript
import { sha256 } from 'js-sha256';
import axios from 'axios';
function FawryPayGetPaymentStatus() {
let merchantCode = "1tSa6uxz2nRbgY+b+cZGyA==";
let merchantRefNumber = "23124654641";
let merchant_sec_key = "259af31fc2f74453b3a55739b21ae9ef";
let signature_body = merchantCode.concat(merchantRefNumber,merchant_sec_key);
let sha256 = new jsSHA('SHA-256', 'TEXT');
sha256.update(signature_body);
let hash_signature = sha256.getHash("HEX");
axios.get('https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/status/v2', {
merchantCode: merchantCode,
merchantRefNumber: merchantRefNumber,
signature: hash_signature
})
.then(response => {
// Get Response Contents
let type = response.data.type;
let paymentStatus = response.data.paymentStatus;
//
})
.catch(error => {
console.log(error.response.data)
})
}
```
--------------------------------
### Initialize Python API Imports
Source: https://developer.fawrystaging.com/docs/server-apis/auth-capture-payment-apis
Imports necessary libraries for HTTP requests and hashing for the FawryPay API.
```python
# importing the requests library
import requests
# importing Hash Library
import hashlib
# FawryPayAPI Endpoint
URL = "https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge"
```
--------------------------------
### Python API Endpoint Configuration
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-bank-apis
Initial setup for importing required libraries and defining the FawryPay API endpoint.
```python
# importing the requests library
import requests
# importing Hash Library
import hashlib
# FawryPay Installment Charge using Card Token API Endpoint
URL = "https://atfawry.fawrystaging.com/ECommerceWeb/Fawry/payments/charge"
```
--------------------------------
### PHP Installment Charge Request
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-bank-apis
Example of generating a SHA-256 signature and executing a POST request using Guzzle HTTP client.
```php
$merchantCode = '1tSa6uxz2nTwlaAmt38enA==';
$merchantRefNumber = '23124654641';
$merchant_cust_prof_id = '777777';
$payment_method = 'CARD';
$amount = '580.55';
$card_token = 'ac0a1909256e8bb5a35a6311c5e824c223d13ae877c5bb0419350b01c619d59d';
$cvv = 123;
$returnUrl = "https://www.google.com/";
$installmentPlanId = 1952;
$merchant_sec_key = '259af31fc2f74453b3a55739b21ae9ef'; // For the sake of demonstration
$signature = hash('sha256' , $merchantCode . $merchantRefNumber . $merchant_cust_prof_id . $payment_method . $amount . $card_token . $cvv . $installmentPlanId . $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,
'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'
],
'enable3DS' => true,
'installmentPlanId' => $installmentPlanId,
'returnUrl' => $returnUrl,
'signature' => $signature,
'paymentMethod' => 'CARD',
'description' => 'example description'
] , true)
]);
$response = json_decode($response->getBody()->getContents(), true);
$paymentStatus = $response['type']; // get response values
```
--------------------------------
### PHP: Fawry Pay Card Token Payment Example
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-card-apis
This PHP example demonstrates how to make a card token payment using the Guzzle HTTP client. It includes generating the required signature.
```php
$merchantCode = '1tSa6uxz2nTwlaAmt38enA==';
$merchantRefNumber = '23124654641';
$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'
],
'signature' => $signature,
'paymentMethod' => 'CARD',
'description' => 'example description'
] , true)
]);
$response = json_decode($response->getBody()->getContents(), true);
$paymentStatus = $response['type']; // get response values
```
--------------------------------
### PHP: Construct Signature and Initiate Payment
Source: https://developer.fawrystaging.com/docs/server-apis/create-payment-3ds-apis
This PHP example demonstrates how to construct the signature and initiate a 3DS card token payment using Guzzle HTTP client. Ensure your secure key and other parameters are correctly set.
```php
$merchantCode = '1tSa6uxz2nTwlaAmt38enA==';
$merchantRefNumber = '23124654641';
$merchant_cust_prof_id = '777777';
$payment_method = 'CARD';
$amount = '580.55';
$card_token = 'ac0a1909256e8bb5a35a6311c5e824c223d13ae877c5bb0419350b01c619d59d';
$cvv = 123;
$returnUrl = "https://www.google.com/";
$merchant_sec_key = '259af31fc2f74453b3a55739b21ae9ef'; // For the sake of demonstration
$signature = hash('sha256' , $merchantCode . $merchantRefNumber . $merchant_cust_prof_id . $payment_method . $amount . $card_token . $cvv . $returnUrl . $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',
```
--------------------------------
### Sample Create Card Token API Responses
Source: https://developer.fawrystaging.com/docs/card-tokens/create-use-token
Example JSON responses for 3D Secure authentication and successful token creation.
```JSON
{
"type":"CardTokenResponse",
"nextAction":{
"type":"THREE_D_SECURE",
"redirectUrl":"https://atfawry.fawrystaging.com/atfawry/plugin/3ds/T-1004644"
},
"statusCode":200,
"statusDescription":"Operation done successfully",
"basketPayment":false
}
```
```JSON
{
"type":"CardTokenResponse",
"card": {
"token":"c44f3f20d92e5fb1239e515e7a3736a2a94117151896d3c314de931b5d0fc80a",
"creationDate": 1514744801948,
"lastFourDigits":"0001",
"firstSixDigits":"400555",
"brand":"Visa Card"
},
"statusCode":200,
"statusDescription":"Operation done successfully"
}
```