Payments made seamless.
Reliable Mobile Money verification for your apps. Accept payments from MTN, Telecel, and AirtelTigo instantly with our robust SDK.
Installation
Install via your favorite package manager.
npm install lokipay-sdkAuthentication
Initialize the library with your Secret Key. You can find this in your Dashboard Settings. Never expose your secret key on the client-side.
import { LokiPay } from 'lokipay-sdk';
export const lokipay = new LokiPay({
secretKey: process.env.LOKIPAY_SECRET_KEY as string,
// Optional: Custom merchant config if not using defaults
merchant: {
mtnMerchantCode: '190638'
}
});Create Order
Initiate a transaction. This creates a pending order in the system which you can then ask the user to pay for.
Parameters
| Name | Type | Description |
|---|---|---|
| phone | string | The payer's mobile number (e.g., 0551234567) |
| amount | number | Amount in GHS. |
| description | string | Optional note for the order. |
const result = await lokipay.createOrder({
phone: "0551234567",
amount: 150.00,
description: "Electronics Store Order #12345"
});
console.log(result.order);
// {
// orderId: "ord_82910",
// vfmReference: "LP-82910",
// status: "pending",
// instructions: { ... }
// }Poll Payment Status
Use the builtin waitForPayment helper to automatically check status until completion.
// Check every 5 seconds for up to 10 minutes
const status = await lokipay.waitForPayment(result.order.orderId, {
intervalMs: 5000,
timeoutMs: 600000,
onStatusChange: (status) => {
console.log('Current status:', status.status);
}
});
if (status.status === 'confirmed') {
console.log("✅ Payment received!");
}React Component
The SDK exports a pre-built LokiPayCheckout component that handles the entire payment flow for you.
import { LokiPay } from 'lokipay-sdk';
import { LokiPayCheckout } from 'lokipay-sdk/react';
const lokipay = new LokiPay({
secretKey: 'sk_live_...'
});
export default function Payment() {
return (
<div className="flex justify-center p-12">
<LokiPayCheckout
client={lokipay}
amount={150.00}
description="Premium Plan"
onSuccess={(order) => {
console.log('Payment Verified:', order);
alert('Payment successful!');
}}
darkMode={false} // Toggle dark mode
color="#30D158" // Custom accent color
/>
</div>
);
}Component Props
| Prop | Type | Required | Description |
|---|---|---|---|
| client | LokiPay | Yes | Initialized SDK instance. |
| amount | number | Yes | Amount to pay in GHS. |
| description | string | No | Payment description. |
| onSuccess | function | No | Callback when payment is confirmed. |
| darkMode | boolean | No | Force dark mode style. |
| color | string | No | Primary accent color (hex). |
Webhooks
For production apps, we recommend listening to webhooks rather than holding a connection open. LokiPay sends a `POST` request to your URL when status changes.
!Security Note
Always verify the X-LokiPay-Signature header to ensure the request is genuinely from us.
{
"event": "payment.confirmed",
"data": {
"order_id": "ord_12345",
"status": "confirmed",
"amount": 150.00,
"transaction": {
"id": "trans_99182",
"sender": "John Doe",
"reference": "72819102"
}
}
}