JavaScript SDK - Payments#
M-Pesa (STK push) and Snippe (mobile money, hosted checkout).
Settings#
const { data: settings } = await db.payments.getSettings();
await db.payments.updateSettings({
mpesa_consumer_key: '...',
mpesa_consumer_secret: '...',
snippe_api_key: '...',
});
TypeScriptM-Pesa STK push#
const { data: push } = await db.payments.stkPush({
phone: '+255712345678',
amount: 5000,
description: 'Order #123',
});
TypeScriptThe customer authorizes on their phone; RafikiDB receives the callback and records the transaction.
Snippe#
// Direct mobile money payment
const { data: payment } = await db.payments.snippeInitiate({
amount: 5000,
phone: '+255712345678',
first_name: 'Asha',
last_name: 'Mwinyi',
email: 'asha@example.com',
order_id: 'ORD-123',
});
// Hosted checkout session
const { data: checkout } = await db.payments.snippeSession({
amount: 25000,
description: 'Checkout',
redirect_url: 'https://myapp.com/thanks',
customer_name: 'Asha Mwinyi',
customer_phone: '+255712345678',
expires_in: 3600,
});
TypeScriptStatus and transactions#
const { data: status } = await db.payments.snippeStatus(reference);
const { data: transactions } = await db.payments.listTransactions();
const { data: txn } = await db.payments.getTransaction(transactionId);
TypeScriptWebhooks#
Payment callbacks arrive at your configured endpoints; deliveries are HMAC-signed like webhooks.
Next: Errors.