Sample Code

GetPaymentStatus

<?php

/* For simplicity check our PHP SDK library here https://myfatoorah.readme.io/php-library */

//PHP Notice:  To enable MyFatoorah auto-update, kindly give the write/read permissions to the library folder
//use zip file
include 'myfatoorah-library-2.2/MyfatoorahLoader.php';
include 'myfatoorah-library-2.2/MyfatoorahLibrary.php';

//use composer
//require 'vendor/autoload.php';
//use MyFatoorah\Library\API\Payment\MyFatoorahPaymentStatus;

/* --------------------------- Configurations ------------------------------- */
//Test
$mfConfig = [
    /**
     * API Token Key (string)
     * Accepted value:
     * Live Token: https://myfatoorah.readme.io/docs/live-token
     * Test Token: https://myfatoorah.readme.io/docs/test-token
     */
    'apiKey'      => '',
    /*
     * Vendor Country ISO Code (string)
     * Accepted value: KWT, SAU, ARE, QAT, BHR, OMN, JOD, or EGY. Check https://docs.myfatoorah.com/docs/iso-lookups
     */
    'vcCode' => 'KWT',
    /**
     * Test Mode (boolean)
     * Accepted value: true for the test mode or false for the live mode
     */
    'isTest'      => true,
];

/* --------------------------- GetPaymentStatus Endpoint -------------------- */

//Inquiry using InvoiceId
//InvoiceId should be returned in the send/execute payment endpoit response
$keyId   = '3110788';
$KeyType = 'InvoiceId';

//Inquiry using CustomerReference
//CustomerReference should be returned in the callback
$keyId   = 'test123';
$KeyType = 'CustomerReference';

//Inquiry using PaymentId
//PaymentId should be returned in the callback
$keyId   = '07073110788180275773';
$KeyType = 'PaymentId';

//------------- Call the Endpoint -------------------------
try {
    $mfObj = new MyFatoorahPaymentStatus($mfConfig);
    $data  = $mfObj->getPaymentStatus($keyId, $KeyType);

    //Display the result to your customer
    echo '<h3><u>Summary:</u></h3>';
    echo "Payment status is <b>$data->InvoiceStatus</b>";
    if ($data->InvoiceError) {
        echo "<br>Payment error is <b>$data->InvoiceError</b>";
    }

    echo '<h3><u>GetPaymentStatus Response Data:</u></h3><pre>';
    print_r($data);
    echo '</pre>';
} catch (Exception $ex) {
    echo $ex->getMessage();
    die;
}
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

namespace PaymentStatus
{
    class Program
    {
        // You can get test token from this page  https://myfatoorah.readme.io/docs/test-token
        static string token = "";
        static string baseURL = "https://apitest.myfatoorah.com";

        static async Task Main(string[] args)
        {
            string key = "641450";
            string keyType = "InvoiceId";//or it can be PaymentId
            var getPaymentStatusResponse = await GetPaymentStatus(key,keyType).ConfigureAwait(false);
            Console.WriteLine("Payment Status Response :");
            Console.WriteLine(getPaymentStatusResponse);
            Console.ReadLine();
        }

        public static async Task<string> GetPaymentStatus(string key,string keyType)
        {
            var GetPaymentStatusRequest = new
            {
                Key = key,
                KeyType = keyType
            };

            var GetPaymentStatusRequestJSON = JsonConvert.SerializeObject(GetPaymentStatusRequest);
            return await PerformRequest(GetPaymentStatusRequestJSON, "GetPaymentStatus").ConfigureAwait(false);

        }

        public static async Task<string> PerformRequest(string requestJSON, string endPoint)
        {
            string url = baseURL + $"/v2/{endPoint}";
            HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            var httpContent = new StringContent(requestJSON, System.Text.Encoding.UTF8, "application/json");
            var responseMessage = await client.PostAsync(url, httpContent).ConfigureAwait(false);
            string response = string.Empty;
            if (!responseMessage.IsSuccessStatusCode)
            {
                response = JsonConvert.SerializeObject(new
                {
                    IsSuccess = false,
                    Message = responseMessage.StatusCode.ToString()
                });
            }
            else
            {
                response = await responseMessage.Content.ReadAsStringAsync();
            }

            return response;
        }
    }
}
# Get Payment Status

# Import required libraries (make sure it is installed!)
import requests
import json
import sys


# Define Functions

def check_data(key, response_data):
    if key in response_data.keys() and response_data[key] is not None:
        return True
    else:
        return False


# Error Handle Function
def handle_response(response):
    if response.text == "":  # In case of empty response
        raise Exception("API key is not correct")

    response_data = response.json()
    response_keys = response_data.keys()

    if "IsSuccess" in response_keys and response_data["IsSuccess"] is True:
        return  # Successful
    elif check_data("ValidationErrors", response_data):
        error = []
        for i in range(len(response.json()["ValidationErrors"])):
            v_error = [response_data["ValidationErrors"][i].get(key) for key in ["Name", "Error"]]
            error.append(v_error)
    elif check_data("ErrorMessage", response_data):
        error = response_data["ErrorMessage"]
    elif check_data("Message", response_data):
        error = response_data["Message"]
    elif check_data("ErrorMessage", response_data["Data"]):
        error = response_data["Data"]["ErrorMessage"]
    else:
        error = "An Error has occurred. API response: " + response.text
    raise Exception(error)


# Call API Function
def call_api(api_url, api_key, request_data, request_type="POST"):
    request_data = json.dumps(request_data)
    headers = {"Content-Type": "application/json", "Authorization": "Bearer " + api_key}
    response = requests.request(request_type, api_url, data=request_data, headers=headers)
    handle_response(response)
    return response


# Get Payment Status endpoint Function
def get_payment_status(getpay_request):
    api_url = base_url + "/v2/getPaymentStatus"
    getpay_response = call_api(api_url, api_key, getpay_request).json()
    invoice_status = getpay_response["Data"]["InvoiceStatus"]
    if getpay_request["KeyType"] == "invoiceid":
        invoice_transactions = []
        for i in range(len(getpay_response["Data"]["InvoiceTransactions"])):
            x = [getpay_response["Data"]["InvoiceTransactions"][i].get(key) for key in ["PaymentGateway",
                                                                                        "TransactionStatus", "Error"]]
            invoice_transactions.append(x)
        print("Invoice Status: ", invoice_status, "\nInvoice Transactions", invoice_transactions)
        return invoice_status, invoice_transactions
    else:
        x = getpay_response["Data"]["InvoiceTransactions"]["PaymentId" == getpay_request["Key"]]
        transactions_status = [x.get(key) for key in ["PaymentGateway", "TransactionStatus", "Error"]]
        print("Invoice Status: ", invoice_status, "\nTransactions Status", transactions_status)
        return invoice_status, transactions_status


# Test Environment
base_url = "https://apitest.myfatoorah.com"
api_key = "MyTokenValue"  # Test token value to be placed here: https:#myfatoorah.readme.io/docs/test-token

# Live Environment
# base_url = "https:#api.myfatoorah.com"
# api_key = "mytokenvalue" #Live token value to be placed here: https:#myfatoorah.readme.io/docs/live-token


getpay_request = {
                 "Key": "962899",
                 "KeyType": "invoiceid"
                }

try:
    get_payment_status(getpay_request)
except:
    ex_type, ex_value, ex_traceback = sys.exc_info()
    print("Exception type : %s " % ex_type.__name__)
    print("Exception message : %s" % ex_value)



#{
#"Key": "100202124125652215",
#"KeyType": "PaymentId"
#}