keshopay-js
v0.1.4
Published
Lightweight JavaScript SDK for Keshopay checkout and payment key verification.
Maintainers
Readme
keshopay-js
Minimal JavaScript SDK to initiate a KeshoPay checkout with one call.
Install
npm i keshopay-js
# or
pnpm add keshopay-jsUsage
import initiateCheckout from 'keshopay-js';
const { success, checkoutUrl, paymentKey } = await initiateCheckout({
publicKey: 'pk_test_...',
privateKey: 'sk_test_...',
walletId: 'app_123',
amount: 1000,
reference: `ORDER-${Date.now()}`,
redirectUrl: 'https://yourapp.com/payment/success',
currency: 'KES',
phoneNumber: '254712345678',
identifier: 'iwowuywtw'
});
if (success) {
// Open or redirect the customer to checkoutUrl
}CommonJS (require)
const initiateCheckout = require('keshopay-js');
const { success, checkoutUrl, paymentKey } = await initiateCheckout({
publicKey: 'pk_test_...',
privateKey: 'sk_test_...',
walletId: 'app_123',
amount: 1000,
reference: `ORDER-${Date.now()}`,
redirectUrl: 'https://yourapp.com/payment/success',
currency: 'KES',
phoneNumber: '254712345678',
identifier: 'iwowuywtw'
});Notes
- The SDK internally generates the authorization key, initiates the payment, and returns the checkout URL.
- Return shape is always
{ success, checkoutUrl, paymentKey }. - In Node without global fetch, pass
fetchImpl(e.g., undici):
import initiateCheckout from 'keshopay-js';
import { fetch } from 'undici';
await initiateCheckout({
publicKey,
privateKey,
walletId,
amount: 1000,
reference: 'ORDER-1',
redirectUrl: 'https://...',
identifier: 'your_identifier',
fetchImpl: fetch
});