PHP code example of bawes / myfatoorah-php

1. Go to this page and download the library: Download bawes/myfatoorah-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bawes / myfatoorah-php example snippets



use bawes/myfatoorah/MyFatoorah;

$my = MyFatoorah::test();


use bawes/myfatoorah/MyFatoorah;

$merchantCode = "[Your merchant code here]";
$username = "[Your merchant username here]";
$password = "[Your merchant password here]";
$my = MyFatoorah::live($merchantCode, $username, $password);


use bawes/myfatoorah/MyFatoorah;

$merchantCode = "[Your merchant code here]";
$username = "[Your merchant username here]";
$password = "[Your merchant password here]";
$my = MyFatoorah::live($merchantCode, $username, $password);

$my->setPaymentMode(MyFatoorah::GATEWAY_ALL)
->setReturnUrl("https://google.com")
->setErrorReturnUrl("https://google.com")
->setCustomer("Khalid", "[email protected]", "97738271")
->setReferenceId() //Pass unique order number or leave empty to use time()
->addProduct("iPhone", 5.350, 3)
->addProduct("Samsung", 12.000, 1)
->getPaymentLinkAndReference();

$paymentUrl = $my['paymentUrl'];
$myfatoorahRefId = $my['paymentRef']; //good idea to store this for later status checks

// Redirect to payment url
header("Location: $paymentUrl");
die();



use bawes/myfatoorah/MyFatoorah;

// Example Ref ID
$myfatoorahRefId = $_GET['id'];

// Order status on Test environment
$orderStatus = MyFatoorah::test()
    ->getOrderStatus($myfatoorahRefId);

// Order status on Live environment
$merchantCode = "[Your merchant code here]";
$username = "[Your merchant username here]";
$password = "[Your merchant password here]";
$orderStatus = MyFatoorah::live($merchantCode, $username, $password)
    ->getOrderStatus($myfatoorahRefId);


$orderStatus = [
    'responseCode' => '0', //MyFatoorah::REQUEST_SUCCESSFUL
    'responseMessage' => 'SUCCESS',
    'result' => 'CAPTURED',

    // Successful payment fields
    'payMode' => 'KNET',
    'orderId' => '1085183',
    'payTransactionId' => '673386261283050',
    'grossAmountPaid' => '32.500',
    'netAmountToBeDeposited' => '32.300',

    // User defined fields
    'udf1' => '',
    'udf2' => '',
    'udf3' => '',
    'udf4' => '',
    'udf5' => ''
]


$orderStatus = [
    'responseCode' => '2009',
    'responseMessage' => 'Transaction Failed Messages',
    'result' => 'Payment Server detected an error',

    // User defined fields
    'udf1' => '',
    'udf2' => '',
    'udf3' => '',
    'udf4' => '',
    'udf5' => ''
]


use bawes/myfatoorah/MyFatoorah;

$my = MyFatoorah::live($merchantCode, $username, $password);
$my->setPaymentMode(MyFatoorah::GATEWAY_ALL)
bash
$ composer 
json
"bawes/myfatoorah-php": "^1.0"