Webhook Integration
To seamlessly receive notifications for confirmed transactions, integrate with our advanced webhook solution. Follow the steps below to set up webhook integration successfully:
Requirements:
Webhook Verification Key: Obtain your unique webhook verification key from here.
Pass Webhook URL at Checkout-Session Creation: During the creation of a checkout session, ensure that you include the webhook URL. Refer to the documentation here for details.
Code Examples:
You MUST make sure to verify the webhook key to avoid malicious requests.
The webhook view should return a 200 response code, our system will retry to call it for any other response code
- FastAPI
- Flask
- Django
- Gin
- Spring Boot
- sinatra
- Express
- PHP (Slim)
import os
from fastapi import FastAPI, Request
# Create the FastAPI app
app = FastAPI()
@app.post('/notrix-webhook')
async def notrix_webhook(request: Request):
# Get the webhook verification key from the header
webhook_key = request.headers['X-Notrix-Webhook-Key']
if webhook_key != os.environ['WEBHOOK_VERIFICATION_KEY']:
return {'message': 'invalid webhook key'}, 401
# Load order from body
order = await request.json()
# Start post-payment processing
# ...
return 200
from flask import Flask, request, abort
app = Flask(__name__)
@app.route('/notrix-webhook', methods=['POST'])
def notrix_webhook():
# Get the webhook verification key from the header
webhook_key = request.headers.get('X-Notrix-Webhook-Key')
if webhook_key != os.environ.get('WEBHOOK_VERIFICATION_KEY'):
return {'message': 'invalid webhook key'}, 401
# Load order from the request body
order = request.get_json()
# Start post-payment processing
# ...
return '', 200
if __name__ == '__main__':
app.run(port=5000)
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
import json
import os
@csrf_exempt
@require_POST
def notrix_webhook(request):
# Get the webhook verification key from the header
webhook_key = request.headers.get('X-Notrix-Webhook-Key')
if webhook_key != os.environ.get('WEBHOOK_VERIFICATION_KEY'):
return JsonResponse({'message': 'invalid webhook key'}, status=401)
# Load order from the request body
order = json.loads(request.body)
# Start post-payment processing
# ...
return JsonResponse({}, status=200)
package main
import (
"github.com/gin-gonic/gin"
"net/http"
"os"
)
func main() {
router := gin.Default()
router.POST("/notrix-webhook", notrixWebhookHandler)
router.Run(":8080")
}
func notrixWebhookHandler(c *gin.Context) {
// Get the webhook verification key from the header
webhookKey := c.GetHeader("X-Notrix-Webhook-Key")
if webhookKey != os.Getenv("WEBHOOK_VERIFICATION_KEY") {
c.JSON(http.StatusUnauthorized, gin.H{"message": "invalid webhook key"})
return
}
// Load order from the request body
var order map[string]interface{}
if err := c.ShouldBindJSON(&order); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"message": "invalid request body"})
return
}
// Start post-payment processing
// ...
c.Status(http.StatusOK)
}
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class NotrixWebhookApplication {
public static void main(String[] args) {
SpringApplication.run(NotrixWebhookApplication.class, args);
}
}
@RestController
class NotrixWebhookController {
@PostMapping("/notrix-webhook")
public ResponseEntity<Object> notrixWebhook(
@RequestHeader("X-Notrix-Webhook-Key") String webhookKey,
@RequestBody String orderJson) {
// Get the webhook verification key from the header
if (!webhookKey.equals(System.getenv("WEBHOOK_VERIFICATION_KEY"))) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("{\"message\": \"invalid webhook key\"}");
}
// Load order from the request body
// Note: You may need to use a JSON library to parse the orderJson string
// For example, using Jackson ObjectMapper
// Start post-payment processing
// ...
return ResponseEntity.status(HttpStatus.OK).build();
}
}
require 'sinatra'
require 'json'
set :port, 4567
post '/notrix-webhook' do
# Get the webhook verification key from the header
webhook_key = request.env['HTTP_X_NOTRIX_WEBHOOK_KEY']
if webhook_key != ENV['WEBHOOK_VERIFICATION_KEY']
return [401, { 'Content-Type' => 'application/json' }, { message: 'invalid webhook key' }.to_json]
end
# Load order from the request body
order = JSON.parse(request.body.read)
# Start post-payment processing
# ...
200
end
const express = require('express');
const app = express();
app.post('/notrix-webhook', (req, res) => {
// Get the webhook verification key from the header
const webhookKey = req.headers['x-notrix-webhook-key'];
if (webhookKey !== process.env.WEBHOOK_VERIFICATION_KEY) {
return res.status(401).send({ message: 'invalid webhook key' });
}
// Load order from body
const order = req.body;
// Start post-payment processing
// ...
res.sendStatus(200);
});
app.listen(3000, () => {
console.log('Webhook server listening on port 3000');
});
<?php
require 'vendor/autoload.php';
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
$app = AppFactory::create();
$app->addRoutingMiddleware();
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
$app->post('/notrix-webhook', function (Request $request, Response $response) {
// Get the webhook verification key from the header
$webhookKey = $request->getHeaderLine('X-Notrix-Webhook-Key');
if ($webhookKey !== getenv('WEBHOOK_VERIFICATION_KEY')) {
return $response->withJson(['message' => 'invalid webhook key'], 401);
}
// Load order from the request body
$order = json_decode($request->getBody(), true);
// Start post-payment processing
// ...
return $response->withStatus(200);
});
$app->run();
Webhook Payload:
Upon successful integration, the webhook payload will furnish comprehensive order details, including the unique checkout session UUID (checkout-session-uuid). Stay informed about confirmed transactions effortlessly with Notrix's webhook integration.
{
"created_at": "2024-04-15T17:54:49.657172327Z",
"uuid": "30190f78-ea2f-4a52-a5a0-b8a7e05ecdec",
"paidFrom": "<wallet address>",
"priceInCurrency": "147947596",
"priceInUSD": "1",
"checkoutSessionUuid": "610a362b-40fd-43e5-b695-e1ad057cdfbf",
"checkoutSession": {
"uuid": "610a362b-40fd-43e5-b695-e1ad057cdfbf",
"totalAmount": "1", // USD
"successURL": "http://demo.notrix.io/post-payment",
"cancelURL": "http://demo.notrix.io",
"clientReferenceID": null,
"active": false,
"showCompany": false,
"expires_at": "2024-04-16T17:51:41.559279Z",
"status": "paid",
"paymentRequestToken": "kp3vODJmftOb4H75EVktvLQkqxRf4S",
"webhookURL": "https://demo.notrix.io/post-payment/webhook",
"lineItems": null
},
"walletUuid": "b92a589b-ff34-4b65-a1e1-2d5f33dc2128",
"wallet": {
"uuid": "b92a589b-ff34-4b65-a1e1-2d5f33dc2128",
"address": "<wallet address>",
"grossIncome": "1363858107",
"commision": "0",
"active": true,
"currency_uuid": "6ac38c5d-6ab5-41f7-bc1e-ed6ada0bfc3a",
}
}