Transaction finished Webhook
1. Overview
The system will send you transaction information via Webhook after each transaction is completed. Each request header will contain a signature that verifies the integrity of the data to ensure it has not been tampered with. After receiving the message, {"ok": true}
needs to be returned to indicate success. If unsuccessful, the system will retry up to 5 times.
2. request information
- Request URL: The Webhook URL you provided
- Request method: POST
- Request header:
- Signature:
3. Request body
{
"id": "123456789",
"amount": 100,
"currency": "eth",
"to_address": "0x400539782Cb9aF1dE233c38E0efDC23DFEc6C60E"
"status": "completed",
"payment":{
"amount": 10,
"currency": "USD",
"payment_method": "VISA",
"status": "paid"
},
"transactionHash":"0x5cce9289bfe0782aa271b3f753b00f077e6cf24a27ea0123510dcf9fa056b625"
}
4. Signature verification
The request body will be signed using your key. You can use this signature to verify data integrity. The verification algorithm is:
$computedSignature = hash_hmac('sha256', $request->getContent(), $YOUR_SECRET_KEY);
5. Response
- Successful response:
{"ok": true}
- Failure response:
(You can return appropriate error message)
6. Retry mechanism
If the system does not receive a successful response, it will try up to 5 times.
7. Sample code
Node.js
const express = require('express');
const bodyParser = require('body-parser');
const crypto = require('crypto');
const app = express();
app.use(bodyParser.json());
const YOUR_SECRET_KEY = 'your_secret_key'; // The key used to sign
app.post('/your-webhook-endpoint', (req, res) => {
const signature = req.get('Signature');
const body = req.rawBody; //Use rawBody to get the original request body
// Verify signature
const computedSignature = crypto.createHmac('sha256', YOUR_SECRET_KEY).update(body).digest('hex');
if (signature === computedSignature) {
// Signature verification successful
res.json({ ok: true });
} else {
// Signature verification failed
res.status(401).json({ error: 'Invalid signature' });
}
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
The above is a simple API documentation example, you can adjust it appropriately according to your actual needs.
Modified at 2024-09-15 03:55:57