To create a webhook receiver for the FuturaPay payment gateway, you need to follow these steps. This will involve setting up a PHP script that can handle the incoming webhook request from FuturaPay, verify its authenticity, and process the data.


 

Setting Up Webhook Receiver for FuturaPay Payment Gateway

Follow these steps to create and configure a webhook receiver for FuturaPay. The webhook will notify your application about payment events, allowing you to process payments automatically.

 

Step 1: Set Up the Webhook Endpoint

Create a PHP file named webhook.php that will act as the webhook endpoint. This script will receive and process incoming webhook requests from FuturaPay.

Sample Code for webhook.php:

<?php
// webhook.php

// Step 3.1: Get the incoming POST data
$payload = file_get_contents('php://input');
$data = json_decode($payload, true);

// Step 3.2: Verify if the data is valid
if (!$data) {
    http_response_code(400); // Bad request
    echo "Invalid payload";
    exit;
}

// Step 3.3: Verify the webhook signature (optional but recommended)
$secret = 'your_webhook_secret'; // Set your webhook secret key here
$receivedSignature = $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? '';

$calculatedSignature = hash_hmac('sha256', $payload, $secret);

if ($receivedSignature !== $calculatedSignature) {
    http_response_code(403); // Forbidden
    echo "Invalid signature";
    exit;
}

// Step 3.4: Process the payment data
$transactionId = $data['transaction_id'] ?? '';
$status = $data['status'] ?? '';
$amount = $data['amount'] ?? 0;
$currency = $data['currency'] ?? '';

// Example: Update the database or take other actions based on the status
if ($status === 'completed') {
    // Update the order status to 'paid' in the database
    // Perform any other actions required for a successful payment
    echo "Payment successful for transaction ID: $transactionId";
} else {
    // Handle other statuses, e.g., 'failed', 'pending'
    echo "Payment status: $status for transaction ID: $transactionId";
}

// Step 3.5: Send a 200 OK response to acknowledge the webhook
http_response_code(200);
echo "Webhook received successfully";

 

Step 2: Configure the Webhook URL in FuturaPay

  1. Add the Webhook URL to FuturaPay Settings:
    • Log in to the FuturaPay merchant dashboard.
    • Go to the Settings section.
    • Navigate to Configurations.
    • Add the webhook URL, pointing to the location of the webhook.php file on your server. For example:
https://yourdomain.com/webhook.php

This configuration ensures that FuturaPay sends payment notifications to the specified endpoint.

 

Step 3: Testing the Webhook

  1. Simulate a Webhook Request: Use tools like Postman to simulate a POST request to the webhook URL, with a payload similar to what FuturaPay would send.
  2. Verify the Response: Check if the script processes the simulated request correctly and responds with a 200 OK status.

 

Step 4: Deploy to Production

  1. Upload the webhook.php file to your production server.
  2. Update the Webhook URL in the FuturaPay dashboard to the production URL.

 

Optional: Logging Webhook Data

For debugging purposes, you may want to log incoming webhook data. Here’s how you can do it:

// Log incoming webhook data to a file
file_put_contents('webhook_log.txt', date('Y-m-d H:i:s') . " - " . $payload . PHP_EOL, FILE_APPEND);

This updated guide provides a complete step-by-step process, from setting up the webhook endpoint to configuring it in FuturaPay, ensuring seamless integration and processing of payment events.