Quick Start
Get up and running with BessaPay payment API in minutes.
1. Authentication
Request your API key
1curl -X POST https://api.bessapay.com/v1/developers/register \
2 -H "Content-Type: application/json" \
3 -d '{
4 "name": "Your App Name",
5 "email": "developer@example.com",
6 "webhook_url": "https://your-app.com/webhooks/bessapay"
7 }'2. Create a transaction
Node.js example
1const fetch = require('node-fetch');
2
3async function createTransaction() {
4 const response = await fetch('https://api.bessapay.com/v1/transactions', {
5 method: 'POST',
6 headers: {
7 'Content-Type': 'application/json',
8 'X-API-Key': 'your_api_key_here'
9 },
10 body: JSON.stringify({
11 amount: 1000,
12 currency: 'KES',
13 reference: 'order-123',
14 customer: {
15 name: 'John Doe',
16 email: 'john@example.com',
17 phone: '+254712345678'
18 },
19 callback_url: 'https://your-app.com/callbacks/bessapay'
20 })
21 });
22
23 const data = await response.json();
24 console.log(data);
25}
26
27createTransaction();3. Handle webhooks
Express.js webhook handler
1const express = require('express');
2const app = express();
3app.use(express.json());
4
5// BessaPay webhook handler
6app.post('/webhooks/bessapay', (req, res) => {
7 const event = req.body;
8
9 // Verify webhook signature
10 const signature = req.headers['x-bessapay-signature'];
11 if (!verifySignature(event, signature, 'your_webhook_secret')) {
12 return res.status(400).send('Invalid signature');
13 }
14
15 // Handle different event types
16 switch(event.event) {
17 case 'payment.success':
18 // Payment was successful
19 console.log('Payment successful:', event.transactionId);
20 // Update your database, fulfill the order, etc.
21 break;
22 case 'payment.failed':
23 // Payment failed
24 console.log('Payment failed:', event.transactionId);
25 break;
26 // Handle other event types
27 }
28
29 res.status(200).send('Webhook received');
30});
31
32app.listen(3000, () => {
33 console.log('Server listening on port 3000');
34});