PHP Library

Current Version: 2.2

Installation Steps

Install the PHP library package via myfatoorah/library composer by running the below command:

composer require myfatoorah/library

👍

Library as a Zip File

If your web application does not support the composer package, be free to download the library as a zip file from here.

📘

Online Toolkit

For the best usage of the library, you can explore the PHP Toolkit. Moreover, You can download it and host it on your server to examine it.


Payment Operations

To handle a payment operation, create an object of the MyFatoorahPayment class. Then you can use one of the following functions.

The getInvoiceURL function

It gets the invoice or payment URL as well as the invoice id as it appliances for both SendPayment and ExecutePayment endpoints. Moreover, It implements the embedded payment.

<?php
$config = [
    'apiKey' => '',
    'vcCode' => 'KWT',
    'isTest' => false,
];

$paymentMethodId = 0; //to be redirect to MyFatoorah invoice page
//$paymentMethodId = 1; //to be redirect to Knet payment page if you are using test API token key
$postFields      = [
    'InvoiceValue' => '50',
    'CustomerName' => 'fname lname',
];

try {
  	$mfObj = new MyFatoorahPayment($config);
    $data  = $mfObj->getInvoiceURL($postFields, $paymentMethodId);

    $invoiceId   = $data->InvoiceId;
    $paymentLink = $data->InvoiceURL;

    echo "Click on <a href='$paymentLink' target='_blank'>$paymentLink</a> to pay with invoiceID $invoiceId.";
} catch (Exception $ex) {
    echo $ex->getMessage();
}

The initiatePayment function

It lists the available payment gateways and implements the InitiatePayment endpoint.

<?php

try {
    $mfObj = new MyFatoorahPayment($config);
    $paymentMethods = $mfObj->initiatePayment();

    print_r($paymentMethods);
} catch (Exception $ex) {
    echo $ex->getMessage();
}

The getPaymentStatus function

It gets the payment transaction status and implements the GetPaymentStatus endpoint.

<?php

$keyId   = '32090';
$KeyType = 'invoiceid';

try {
    $mfObj = new MyFatoorahPaymentStatus($config);
    $data  = $mfObj->getPaymentStatus($keyId, $KeyType);

    print_r($data);
} catch (Exception $ex) {
    echo $ex->getMessage();
}

Shipping Operations

To handle any shipping operation, create an object of the MyFatoorahShipping class. Then you can use one of the following functions:

The calculateShippingCharge function

It calculates the shipping charge and implements the CalculateShippingCharge endpoint.

<?php
$config = [
    'apiKey' => '',
    'vcCode' => 'KWT',
    'isTest' => false,
];

$invoiceItems[] = [
    'ProductName' => 'Product Name',
    "Description" => 'Description',
    'weight'      => 5,
    'Width'       => 10,
    'Height'      => 15,
    'Depth'       => 20,
    'Quantity'    => 1,
    'UnitPrice'   => 123,
];

$curlData = [
    'ShippingMethod' => 1,
    'Items'          => $invoiceItems,
    'CountryCode'    => 'EG',
    'CityName'       => 'Alexandria',
    'PostalCode'     => '12345',
];

try {
    $mfObj = new MyFatoorahShipping($config);
    $json  = $mfObj->calculateShippingCharge($curlData);

    print_r($json);
} catch (Exception $ex) {
    echo $ex->getMessage();
}

The getShippingCountries function

It gets MyFatoorah shipping countries and implements the GetCountries endpoint.

<?php

try {
    $mfObj = new MyFatoorahShipping($config);
    $data  = $mfObj->getShippingCountries();

    print_r($data);
} catch (Exception $ex) {
    echo $ex->getMessage();
}

The getShippingCities function

It gets MyFatoorah shipping cities and implements the GetCities endpoint.

<?php

$method      = 1;
$countryCode = 'EG';
$searchValue = 'Alex';

try {
    $mfObj = new MyFatoorahShipping($config);
    $data  = $mfObj->getShippingCities($method, $countryCode, $searchValue);

    print_r($data);
} catch (Exception $ex) {
    echo $ex->getMessage();
}

General Operations

Some functions handle some useful operations like:

The getCurrencyRate function

It gets the rate of a given currency according to the default currency of the MyFatoorah portal account.

<?php

try {
    $mfObj = new MyFatoorahList($config);
    $rate  = $mfObj->getCurrencyRate('EGP');

    echo($rate);
} catch (Exception $ex) {
    echo $ex->getMessage();
}

The static getPhone function

It gets the country code and the phone after applying the MyFatoorah restriction.

<?php

try {
    $phoneArr = MyFatoorah::getPhone('+2123456789');

    print_r($phoneArr);
} catch (Exception $ex) {
    echo $ex->getMessage();
}

The static getWeightRate function

It gets the rate to convert the given weight unit to MyFatoorah's default weight unit.

<?php

try {
    $weightRate = MyFatoorah::getWeightRate('lbs');

    echo($weightRate);
} catch (Exception $ex) {
    echo $ex->getMessage();
}

The static getDimensionRate function

It gets the rate to convert the given dimension unit to MyFatoorah's default dimension unit.

<?php

try {
    $dimensionRate = MyFatoorah::getDimensionRate('in');

    echo($dimensionRate);
} catch (Exception $ex) {
    echo $ex->getMessage();
}