Webhooks & Notifications

Webhook Integration & Signatures

This webhook documentation outlines how to integrate and handle payment notifications from MONIEFLEX across all supported bank rails (PalmPay Direct Rail). When a payment is successfully processed, a real-time signed webhook notification is sent to your registered URL. The payload contains transaction status, amount, sender, receiver, customer, and settlement figures.

Webhook Notification Format

The webhook delivers a JSON payload to your endpoint with the following exact structure:

json
{
  "notification_status": "payment_successful",
  "transaction_id": "tx_9042b31174da",
  "amount_paid": 100,
  "settlement_amount": 99.5,
  "settlement_fee": 0.5,
  "transaction_status": "success",
  "sender": {
    "name": "AGH ONLINE ACADEMY TUTORS LIMITED",
    "account_number": "****4290",
    "bank": "HYDROGEN"
  },
  "receiver": {
    "name": "ALBARKADATASUB-Abd(MONIEFLEX)",
    "account_number": "6679854996",
    "bank": "PalmPay"
  },
  "customer": {
    "name": "Abdulismail",
    "email": "albarkadatasub@gmail.com",
    "phone": null,
    "customer_id": "cus_guest"
  },
  "description": "Your payment has been successfully processed.",
  "timestamp": "2024-11-22T13:00:04.256092Z"
}

Webhook Data Breakdown

  • notification_status: The status of the notification, e.g., 'payment_successful'.
  • transaction_id: Unique identifier for the transaction.
  • amount_paid: The total amount paid by the customer.
  • settlement_amount: The actual amount settled to your balance after fee deduction.
  • settlement_fee: The fee deducted from the payment before settlement.
  • transaction_status: The status of the transaction (e.g. 'success').
  • sender: Name, masked account number, and bank of the payer.
  • receiver: Name, account number, and bank of the reserved account (e.g., 'PalmPay').
  • customer: Name, email, phone number, and customer identifier.
  • description: Human-readable message describing the payment status.
  • timestamp: ISO 8601 formatted UTC timestamp.

Verifying Webhook Signatures

To ensure that incoming webhooks are authentic and haven't been tampered with, calculate the expected HMAC-SHA256 signature using your secret key and compare it with the signature sent in the Paymentpoint-Signature or X-Signature header.

PHP Webhook Verification Example

php
<?php

// Your secret security key
$secretKey = getenv('MONIEFLEX_SECRET_KEY') ?: 'your-secret-key';

// Step 1: Read the raw POST data from the request body
$inputData = file_get_contents('php://input');

// Step 2: Get the signature from headers
$headers = getallheaders();
$signatureHeader = $headers['Paymentpoint-Signature'] ?? $headers['X-Signature'] ?? $_SERVER['HTTP_PAYMENTPOINT_SIGNATURE'] ?? $_SERVER['HTTP_X_SIGNATURE'] ?? '';

// Step 3: Calculate the expected signature using HMAC-SHA256
$calculatedSignature = hash_hmac('sha256', $inputData, $secretKey);

// Step 4: Verify if the calculated signature matches the header
if (!hash_equals($calculatedSignature, $signatureHeader)) {
    http_response_code(400);
    echo "Invalid signature.";
    exit;
}

// Step 5: Decode the JSON payload
$webhookData = json_decode($inputData, true);
if ($webhookData === null) {
    http_response_code(400);
    echo "Invalid JSON data received.";
    exit;
}

// Step 6: Extract relevant data from the decoded webhook
$transactionId = $webhookData['transaction_id'] ?? null;
$amountPaid = $webhookData['amount_paid'] ?? null;
$settlementAmount = $webhookData['settlement_amount'] ?? null;
$status = $webhookData['transaction_status'] ?? null;

if (!$transactionId || !$amountPaid || !$settlementAmount || !$status) {
    http_response_code(400);
    echo "Missing required data.";
    exit;
}

// Step 7: Process the transaction (credit user wallet, fulfill order, etc.)
// Respond with 200 OK
http_response_code(200);
echo "Webhook processed successfully.";
?>

Python (Django / Flask) Example

python
import hmac, hashlib, json, os
from flask import Flask, request, jsonify

app = Flask(__name__)
SECRET_KEY = os.environ.get('MONIEFLEX_SECRET_KEY', 'your-secret-key').encode('utf-8')

@app.route('/webhook', methods=['POST'])
def webhook():
    signature = request.headers.get('Paymentpoint-Signature') or request.headers.get('X-Signature')
    raw_payload = request.data
    
    expected = hmac.new(SECRET_KEY, raw_payload, hashlib.sha256).hexdigest()
    if not hmac.compare_digest(expected, signature or ''):
        return 'Invalid signature.', 400
        
    data = json.loads(raw_payload.decode('utf-8'))
    if data.get('notification_status') == 'payment_successful':
        amount_paid = data['amount_paid']
        receiver_acc = data['receiver']['account_number']
        # Credit customer wallet
        pass
        
    return 'Webhook processed successfully.', 200

Node.js (Express) Example

javascript
const express = require('express');
const crypto = require('crypto');
const app = express();

const SECRET_KEY = process.env.MONIEFLEX_SECRET_KEY || 'your-secret-key';

app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
  const signature = req.headers['paymentpoint-signature'] || req.headers['x-signature'];
  const rawBody = req.body;
  
  const calculated = crypto.createHmac('sha256', SECRET_KEY).update(rawBody).digest('hex');
  
  if (calculated !== signature) {
    return res.status(400).send('Invalid signature.');
  }
  
  const webhookData = JSON.parse(rawBody.toString());
  if (webhookData.notification_status === 'payment_successful') {
    const { transaction_id, amount_paid, settlement_amount } = webhookData;
    // Credit customer wallet
  }
  
  return res.status(200).send('Webhook processed successfully.');
});