PHP Code Example to receive payment notification on your webhook page

<?php

// Set the content type to application/json
header('Content-Type: application/json');

// Retrieve the Authorization header
$headers = getallheaders();
$authHeader = $headers['Authorization'] ?? '';

// Define your expected Bearer token
$expectedToken = "jHGSFjgfwugfkweugfwjfwjfgwjegfuwefw"; // Replace with your actual Api Key

// Validate the Bearer token
if (strpos($authHeader, 'Bearer ') === 0) {
  $token = substr($authHeader, 7); // Remove 'Bearer ' prefix
  if ($token !== $expectedToken) {
    echo 'Unauthorized: Invalid token.';
    exit;
  }
} else {
    echo 'Unauthorized: Invalid token.';
  exit;
}

// Get the raw POST data
$input = file_get_contents("php://input");

// Check if the input is empty
if (empty($input)) {
    echo 'No input received.';
  exit;
}

// Decode the JSON string into a PHP associative array
$data = json_decode($input, true);

// Check status and message
if ($data['status'] === 'success' && $data['message'] === 'Data received successfully.') {

  // Retrieve all relevant fields
  $transactionId = $data['transactionId'] ?? null;
  $transactionAmount = $data['transactionAmount'] ?? null;
  $transactionFee = $data['transactionFee'] ?? null;
  $settledAmount = $data['settledamount'] ?? null;
  $date = $data['date'] ?? null;
  $senderAccountNumber = $data['senderaccountnumber'] ?? null;
  $senderAccountName = $data['senderaccountname'] ?? null;
  $senderBank = $data['senderbank'] ?? null;
  $receiver = $data['receiver'] ?? null;
  $receiveraccountnumber = $data['receiveraccountnumber'] ?? null;

  // Do what you want with the data
}

?>