pakasir-js
v1.1.0
Published
The fastest Pakasir SDK. 4KB. Zero dependencies.
Maintainers
Readme
pakasir-js
The fastest Pakasir SDK. 4KB. Zero dependencies.
Ultra-lean TypeScript payment library for Pakasir API. Works on Node 18+, Bun, and Deno.
Installation
npm i pakasir-jsQuick Start
Initialize
import { Pakasir } from 'pakasir-js';
const pakasir = new Pakasir({
project: 'myshop',
apiKey: 'sk_live_xxxxx'
});Create Payment URL (Instant)
const paymentUrl = pakasir.createPaymentUrl({
amount: 50000,
order_id: 'ORD123',
redirect_url: 'https://myshop.com/success'
});
// Redirect user: window.location.href = paymentUrlCreate Transaction (QRIS)
const result = await pakasir.createTransaction('qris', {
amount: 50000,
order_id: 'ORD456',
customer_email: '[email protected]',
customer_phone: '08123456789'
});
console.log(result.data?.payment_url);Check Transaction Status
const txn = await pakasir.getTransaction({ order_id: 'ORD456' });
console.log(txn.data?.status); // 'pending' | 'success' | 'failed'Poll Transaction Status (Alternative to Webhooks)
// Poll every 2 seconds, up to 30 attempts (1 minute timeout)
const result = await pakasir.pollTransaction(
{ order_id: 'ORD456' },
{ interval: 2000, maxAttempts: 30 }
);
console.log(result.data?.status); // Returns when status changes or timeoutAPI Reference
| Method | Params | Returns |
| ----------------------------------- | ------------------------------------------------------------ | ------------------------------ |
| createPaymentUrl(params) | amount, order_id, redirect_url?, qris_only? | string (URL) |
| createTransaction(method, params) | method: 'qris' \| 'bni_va' \| ..., amount, order_id, ... | Promise<TransactionResponse> |
| getTransaction(params) | order_id | Promise<TransactionResponse> |
| pollTransaction(params, options) | order_id, interval?, maxAttempts? | Promise<TransactionResponse> |
| cancelTransaction(params) | order_id | Promise<TransactionResponse> |
| simulatePayment(params) | order_id | Promise<TransactionResponse> |
| validateWebhook(payload) | webhook payload object | boolean |
Payment Methods
import { PaymentMethod } from 'pakasir-js';
PaymentMethod.QRIS;
PaymentMethod.BNI_VA;
PaymentMethod.BRI_VA;
PaymentMethod.CIMB_VA;
PaymentMethod.PERMATA_VA;
PaymentMethod.MAYBANK_VA;
PaymentMethod.PAYPAL;
// ... and 4 moreWebhook Handling
app.post('/webhook', (req, res) => {
const payload = req.body;
if (!pakasir.validateWebhook(payload)) {
return res.status(401).json({ error: 'Invalid signature' });
}
// Process payment based on payload.status
if (payload.status === 'success') {
// Update order status in database
}
res.json({ ok: true });
});Error Handling
import { PakasirError, HttpError } from 'pakasir-js';
try {
await pakasir.getTransaction({ order_id: 'ORD999' });
} catch (err) {
if (err instanceof HttpError) {
console.error(`HTTP ${err.status}: ${err.body}`);
} else if (err instanceof PakasirError) {
console.error(err.message);
}
}Sandbox Mode
Automatically detected from API key prefix:
// Sandbox mode (auto-detected)
const pakasir = new Pakasir({
project: 'myshop',
apiKey: 'sk_test_xxxxx' // Triggers sandbox
});
// Or explicit
const pakasir = new Pakasir({
project: 'myshop',
apiKey: 'sk_live_xxxxx',
sandbox: true // Force sandbox
});Performance
- Bundle Size: ~4KB minified + gzipped
- Zero Dependencies: No external packages
- Tree-Shakeable: Import only what you need
- Payment URL: <1ms (no network call)
- API Calls: Minimal overhead
License
ISC
