Note
Ensure that you include the webhook URL in the 'webhook_url' parameter when making a request to the Create Charge API.
Code Example
<?php
// Define your API key
$apiKey = '982d381360a69d419689740d9f2e26ce36fb7a50';
// Get the API key from the request headers
$headerApi = isset($_SERVER['HTTP_RT_UDDOKTAPAY_API_KEY']) ? $_SERVER['HTTP_RT_UDDOKTAPAY_API_KEY'] : null;
// Get the request body
$rawData = file_get_contents('php://input');
// Verify the API key
if ($headerApi !== $apiKey) {
http_response_code(401); // Unauthorized
die("Unauthorized Action");
}
// Parse the JSON data
$data = json_decode($rawData, true);
// Check if JSON data was successfully parsed
if ($data === null) {
http_response_code(400); // Bad Request
die("Invalid JSON data");
}
// Handle the webhook data
echo "Webhook Data Received:\n";
print_r($data);
// You can now process the data as needed
const express = require('express');
const app = express();
const port = 3000; // You can choose any available port
// Define your API key
const apiKey = '982d381360a69d419689740d9f2e26ce36fb7a50';
// Middleware to parse JSON
app.use(express.json());
// Webhook endpoint
app.post('/webhook', (req, res) => {
// Get the API key from the request headers
const headerApi = req.headers['rt-uddoktapay-api-key'];
// Verify the API key
if (headerApi !== apiKey) {
res.status(401).send('Unauthorized Action');
return;
}
// Webhook data
const webhookData = req.body;
// Handle the webhook data
console.log('Webhook Data Received:');
console.log(webhookData);
// You can now process the data as needed
res.status(200).send('Webhook received successfully');
});
app.listen(port, () => {
console.log(`Webhook server is running on port ${port}`);
});
from flask import Flask, request, abort, jsonify
app = Flask(__name__)
# Define your API key
api_key = '982d381360a69d419689740d9f2e26ce36fb7a50'
# Webhook endpoint
@app.route('/webhook', methods=['POST'])
def webhook():
# Get the API key from the request headers
header_api = request.headers.get('RT-UDDOKTAPAY-API-KEY')
# Verify the API key
if header_api is None or header_api != api_key:
abort(401) # Unauthorized
# Get and parse the JSON data
try:
webhook_data = request.get_json()
except ValueError:
abort(400) # Bad Request
# Handle the webhook data
print('Webhook Data Received:')
print(webhook_data)
# You can now process the data as needed
return 'Webhook received successfully', 200
if __name__ == '__main__':
app.run(debug=True)
Sample Payloads
{
"full_name": "John Doe",
"email": "[email protected]",
"amount": "100.00",
"fee": "0.00",
"charged_amount": "100.00",
"invoice_id": "Erm9wzjM0FBwjSYT0QVb",
"metadata": {
"user_id": "10",
"order_id": "50"
},
"payment_method": "bkash",
"sender_number": "01311111111",
"transaction_id": "TESTTRANS1",
"date": "2023-01-07 14:00:50",
"status": "COMPLETED"
}