@sen-pay/webhooks
v0.1.0
Published
Webhook verification helpers for SenPay
Readme
@sen-pay/webhooks
Helpers de vérification de webhooks pour SenPay.
Installation
pnpm add @sen-pay/webhooksUsage
Vérification manuelle
import { verifyPayDunyaWebhook, extractPayDunyaHash } from "@sen-pay/webhooks";
const hash = extractPayDunyaHash(requestBody);
if (hash) {
const valid = await verifyPayDunyaWebhook(hash, masterKey);
// valid === true si le hash est correct
}Middleware Express
import { createPayDunyaWebhookHandler } from "@sen-pay/webhooks";
app.post(
"/webhook",
express.json(),
createPayDunyaWebhookHandler(
process.env.PAYDUNYA_MASTER_KEY!,
async (paymentData) => {
console.log("Paiement reçu:", paymentData);
// Mettre à jour votre base de données...
}
)
);API
| Fonction | Description |
|---|---|
| verifyPayDunyaWebhook(hash, masterKey) | Vérifie le hash SHA-512 |
| extractPayDunyaHash(body) | Extrait le hash du payload |
| createPayDunyaWebhookHandler(key, handler) | Middleware Express |
| sha512(input) | Utilitaire SHA-512 |
