Event Service Overview
Last updated
Was this helpful?
Was this helpful?
const express = require('express');
const { EventClient } = require('hyperswitch-prism');
const app = express();
const eventClient = new EventClient({
connector: 'stripe',
apiKey: 'YOUR_API_KEY'
});
app.post('/webhooks/payments', express.raw({ type: 'application/json' }), async (req, res) => {
try {
const event = await eventClient.handleEvent({
payload: req.body,
headers: req.headers,
webhookSecret: 'whsec_xxx'
});
if (event.type === 'payment.captured') {
await fulfillOrder(event.data.merchantTransactionId);
}
res.json({ received: true });
} catch (err) {
res.status(400).json({ error: err.message });
}
});