Skip to Content
APIWebhooks

Webhooks

Afriex sends webhook notifications for key events. The SDK provides a verifier to validate webhook signatures.

Setup

Initialize the SDK with your webhook public key:

const afriex = new AfriexSDK({ apiKey: 'your-api-key', webhookPublicKey: 'your-afriex-public-key' });

Verify Webhook Signature

app.post('/webhook', (req, res) => { const signature = req.headers['x-webhook-signature']; const payload = req.body; // Raw string body try { const event = afriex.webhooks.verifyAndParse(payload, signature); // Handle the event switch (event.event) { case 'customer.created': console.log('Customer created:', event.data); break; case 'TRANSACTION.CREATED': console.log('Transaction created:', event.data); break; case 'PAYMENT_METHOD.CREATED': console.log('Payment method created:', event.data); break; } res.status(200).send('OK'); } catch (error) { console.error('Invalid signature'); res.status(400).send('Invalid signature'); } });

Event Types

Customer Events

EventDescription
customer.createdCustomer was created
customer.updatedCustomer was updated
customer.deletedCustomer was deleted

Payload:

{ event: 'customer.created', data: { customerId: string, name: string, email: string, phone: string, countryCode: string } }

Transaction Events

EventDescription
TRANSACTION.CREATEDTransaction was created
TRANSACTION.UPDATEDTransaction status changed

Payload:

{ event: 'TRANSACTION.UPDATED', data: { transactionId: string, customerId: string, destinationId: string, status: 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED' | ..., type: string, sourceAmount: string, sourceCurrency: string, destinationAmount: string, destinationCurrency: string, meta: { narration?, invoice?, idempotencyKey?, merchantId? }, createdAt: string, updatedAt: string } }

Payment Method Events

EventDescription
PAYMENT_METHOD.CREATEDPayment method was created
PAYMENT_METHOD.UPDATEDPayment method was updated
PAYMENT_METHOD.DELETEDPayment method was deleted

Payload:

{ event: 'PAYMENT_METHOD.CREATED', data: { paymentMethodId: string, channel: string, customerId: string, accountName: string, accountNumber: string, countryCode: string, institution: { institutionId?, institutionName?, institutionCode? }, recipient: { recipientName?, recipientEmail?, recipientPhone? } } }

Signature Verification Only

If you only want to verify the signature without parsing:

const isValid = afriex.webhooks.verify(payload, signature); if (isValid) { const event = JSON.parse(payload); // Handle event }
Last updated on