PHP code example of fahipay / gateway

1. Go to this page and download the library: Download fahipay/gateway 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/ */

    

fahipay / gateway example snippets


$merchantId     = 'your_merchant_id';
$secretKey      = 'your_secret_key';
$returnUrl      = 'https://example.com/success';
$returnErrorUrl = 'https://example.com/error';
$cancelUrl      = 'https://example.com/cancel';

$apiClient      = new FahiPay\Gateway($merchantId, $secretKey, $returnUrl, $returnErrorUrl, $cancelUrl);
$response       = $apiClient->createTransaction('TXN001', 10.03); // Unique transaction id, Amount in MVR (2dp)
print_r($response);
/*
{
  "type": "success",
  "link": "https://fahipay.mv/pay/L2XXXXXXXXXXXXXXXXXX"
}
*/


$transactionId = 'TXN001'; // Replace with the actual transaction ID
$queryResponse = $apiClient->getTransaction($transactionId);

print_r($queryResponse);
/*
{
  "type": "success",
  "data": {
    "time": "2023-08-15 21:29:05",
    "method": "gateway",
    "mref": "TXN001",
    "amount": 10.03,
    "fee": 0.0,
    "link": "https://fahipay.mv/pay/L2XXXXXXXXXXXXXXXXXX",
    "extras": null,
    "status": "pending",
    "ApprovalCode": null
  }
}
*/

$success          = $_GET['Success'];
$transactionId    = $_GET['ShoppingCartID'];
$approvalCode     = $_GET['ApprovalCode'];
$signature        = $_GET['Signature'];
$isValidSignature = $apiClient->validateSignature($success,$transactionId,$approvalCode,$signature);

print_r($isValidSignature); //returns true or false