API Reference

Introduction:

In this step of the integration process, you will need to utilize the "ExecutePayment" endpoint, which is a POST request. This endpoint allows you to create a Fawaterak transaction on the selected gateway.

Sample Code:
Here's a sample code snippet that demonstrates how to initiate the payment request:

import axios from 'axios';

// Configuration values
const API_URL = 'https://staging.fawaterk.com/api/v2/invoiceInitPay';
const API_TOKEN = 'd83a5d07aaeb8442dcbe259e6dae80a3f2e21a3a581e1a5acd';
const PAYMENT_id = 4, // 2=Visa-MasterCard 3=Fawry 4=Meeza

const requestData = {
  payment_method_id: PAYMENT_id
  cartTotal: '100',
  currency: 'EGP',
  customer: {
    first_name: 'test',
    last_name: 'test',
    email: '[email protected]',
    phone: '01000000000',
    address: 'test address',
  },
  redirectionUrls: {
    successUrl: 'https://dev.fawaterk.com/success',  //you should change this to the Url you want to redirect
    failUrl: 'https://dev.fawaterk.com/fail',
    pendingUrl: 'https://dev.fawaterk.com/pending',
  },
  cartItems: [
    {
      name: 'test',
      price: '100',
      quantity: '1',
    },
  ],
};

const config = {
  method: 'post',
  url: API_URL,
  headers: {
    Authorization: `Bearer ${API_TOKEN}`,
    'Content-Type': 'application/json',
  },
  data: requestData,
};

axios(config)
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error);
  });

import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody

fun main() {
    val apiUrl = "https://staging.fawaterk.com/api/v2/invoiceInitPay"
    val apiToken = "d83a5d07aaeb8442dcbe259e6dae80a3f2e21a3a581e1a5acd"
    val paymentId = 4

    val requestData = "{\"payment_method_id\":$paymentId,\"cartTotal\":\"100\",\"currency\":\"EGP\",\"customer\":{\"first_name\":\"test\",\"last_name\":\"test\",\"email\":\"[email protected]\",\"phone\":\"01000000000\",\"address\":\"test address\"},\"redirectionUrls\":{\"successUrl\":\"https://dev.fawaterk.com/success\",\"failUrl\":\"https://dev.fawaterk.com/fail\",\"pendingUrl\":\"https://dev.fawaterk.com/pending\"},\"cartItems\":[{\"name\":\"test\",\"price\":\"100\",\"quantity\":\"1\"}]}"

    val client = OkHttpClient()

    val requestBody = requestData.toRequestBody("application/json".toMediaType())

    val request = Request.Builder()
        .url(apiUrl)
        .addHeader("Authorization", "Bearer $apiToken")
        .addHeader("Content-Type", "application/json")
        .post(requestBody)
        .build()

    client.newCall(request).execute().use { response ->
        if (response.isSuccessful) {
            val responseData = response.body?.string()
            println(responseData)
        } else {
            println("Request failed: ${response.code}")
        }
    }
}

import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import java.io.IOException;

public class Main {
    public static void main(String[] args) {
        String apiUrl = "https://staging.fawaterk.com/api/v2/invoiceInitPay";
        String apiToken = "d83a5d07aaeb8442dcbe259e6dae80a3f2e21a3a581e1a5acd";
        int paymentId = 4;

        String requestData = "{\"payment_method_id\":" + paymentId + ",\"cartTotal\":\"100\",\"currency\":\"EGP\",\"customer\":{\"first_name\":\"test\",\"last_name\":\"test\",\"email\":\"[email protected]\",\"phone\":\"01000000000\",\"address\":\"test address\"},\"redirectionUrls\":{\"successUrl\":\"https://dev.fawaterk.com/success\",\"failUrl\":\"https://dev.fawaterk.com/fail\",\"pendingUrl\":\"https://dev.fawaterk.com/pending\"},\"cartItems\":[{\"name\":\"test\",\"price\":\"100\",\"quantity\":\"1\"}]}";

        OkHttpClient client = new OkHttpClient();

        RequestBody requestBody = RequestBody.create(requestData, MediaType.get("application/json"));

        Request request = new Request.Builder()
                .url(apiUrl)
                .addHeader("Authorization", "Bearer " + apiToken)
                .addHeader("Content-Type", "application/json")
                .post(requestBody)
                .build();

        try {
            Response response = client.newCall(request).execute();
            if (response.isSuccessful()) {
                String responseData = response.body().string();
                System.out.println(responseData);
            } else {
                System.out.println("Request failed: " + response.code());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

import Foundation

let apiUrl = "https://staging.fawaterk.com/api/v2/invoiceInitPay"
let apiToken = "d83a5d07aaeb8442dcbe259e6dae80a3f2e21a3a581e1a5acd"
let paymentId = 4

let requestData = "{\"payment_method_id\":\(paymentId),\"cartTotal\":\"100\",\"currency\":\"EGP\",\"customer\":{\"first_name\":\"test\",\"last_name\":\"test\",\"email\":\"[email protected]\",\"phone\":\"01000000000\",\"address\":\"test address\"},\"redirectionUrls\":{\"successUrl\":\"https://dev.fawaterk.com/success\",\"failUrl\":\"https://dev.fawaterk.com/fail\",\"pendingUrl\":\"https://dev.fawaterk.com/pending\"},\"cartItems\":[{\"name\":\"test\",\"price\":\"100\",\"quantity\":\"1\"}]}"

if let url = URL(string: apiUrl) {
    var request = URLRequest(url: url)
    request.httpMethod = "POST"
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    request.setValue("Bearer \(apiToken)", forHTTPHeaderField: "Authorization")
    request.httpBody = requestData.data(using: .utf8)

    let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
        if let error = error {
            print("Error: \(error)")
            return
        }

        if let data = data {
            let responseData = String(data: data, encoding: .utf8)
            print(responseData ?? "")
        }
    }

    task.resume()
}

import 'dart:convert';
import 'package:http/http.dart' as http;

void sendPaymentRequest() async {
  final apiUrl = 'https://staging.fawaterk.com/api/v2/invoiceInitPay';
  final apiToken = 'd83a5d07aaeb8442dcbe259e6dae80a3f2e21a3a581e1a5acd';
  final paymentId = 4; // 2=Visa-MasterCard, 3=Fawry, 4=Meeza

  final requestData = {
    'payment_method_id': paymentId,
    'cartTotal': '100',
    'currency': 'EGP',
    'customer': {
      'first_name': 'test',
      'last_name': 'test',
      'email': '[email protected]',
      'phone': '01000000000',
      'address': 'test address',
    },
    'redirectionUrls': {
      'successUrl': 'https://dev.fawaterk.com/success',
      'failUrl': 'https://dev.fawaterk.com/fail',
      'pendingUrl': 'https://dev.fawaterk.com/pending',
    },
    'cartItems': [
      {
        'name': 'test',
        'price': '100',
        'quantity': '1',
      },
    ],
  };

  final headers = {
    'Authorization': 'Bearer $apiToken',
    'Content-Type': 'application/json',
  };

  try {
    final response = await http.post(
      Uri.parse(apiUrl),
      headers: headers,
      body: json.encode(requestData),
    );

    final responseData = json.decode(response.body);
    print(json.encode(responseData));
  } catch (error) {
    print(error);
  }
}

void main() {
  sendPaymentRequest();
}


Initiate Payment Response:

Upon initiating the payment request, you will receive different responses based on the selected payment method. Here are the sample responses for three different payment methods:

Fawry Response:

If Fawry is the selected payment method, the response will contain the following information:

{
    "status": "success",
    "data": {
        "invoice_id": 1000425,
        "invoice_key": "QqgdnAB7Ad2kmIq",
        "payment_data": {
            "fawryCode": "981335305",
            "expireDate": "2021-07-06 15:53:41"
        }
    }
}

Mastercard/Visa Response:

For Mastercard/Visa as the selected payment method, the response will provide the redirection URL:

{
    "status": "success",
    "data": {
        "invoice_id": 1000428,
        "invoice_key": "hyU2vcy3USvT5Tg",
        "payment_data": {
            "redirectTo": "https://staging.fawaterk.com/link/I0PAH"
        }
    }
}

Meeza Response:

If Meeza is the selected payment method, the response will include the following details:

{  
    "status": "success",  
    "data": {  
        "invoice_id": 1000427,  
        "invoice_key": "2vX8jSkmqbwJ4Ls",  
        "payment_data": {  
            "meezaReference": 4266311  
        }  
    }  
}

Feel free to reach out if you have any further questions or need assistance with the integration process.