fersaku
v1.0.0
Published
Official Fersaku QRIS Payment Gateway SDK for Node.js
Maintainers
Readme
Fersaku Node.js SDK
Official Node.js SDK untuk Fersaku QRIS Payment Gateway.
Instalasi
npm install fersakuAtau copy file index.js langsung ke project Anda.
Quick Start
const Fersaku = require('fersaku');
const fersaku = new Fersaku('sk_live_your_secret_key');
// Buat pembayaran
const payment = await fersaku.createPayment({
amount: 50000,
customer_name: 'John Doe',
customer_email: '[email protected]',
description: 'Pembelian Produk A',
external_id: 'order-123',
expired_minutes: 30,
});
console.log(payment.checkout_url); // Redirect customer ke sini
console.log(payment.qr_string); // Atau tampilkan QR langsungAPI Methods
createPayment(params)
Buat pembayaran QRIS baru.
const payment = await fersaku.createPayment({
amount: 100000, // Wajib, min 1000
customer_name: 'Budi', // Opsional
customer_email: '[email protected]', // Opsional
description: 'Order #123', // Opsional
external_id: 'my-order-123', // Opsional, ID dari sistem Anda
expired_minutes: 30, // Opsional, default 30
});getPayment(id)
Ambil detail pembayaran.
const detail = await fersaku.getPayment('payment_id_here');listPayments(params)
List pembayaran dengan filter.
const list = await fersaku.listPayments({ status: 'paid', limit: 10 });cancelPayment(id)
Batalkan pembayaran pending.
await fersaku.cancelPayment('payment_id_here');checkStatus(id)
Cek status terbaru.
const result = await fersaku.checkStatus('payment_id_here');simulate(paymentId, action) (Sandbox only)
Simulasi pembayaran di sandbox.
const sandbox = new Fersaku('sk_test_your_sandbox_key');
await sandbox.simulate('payment_id', 'pay'); // pay, expire, fail, cancelWebhook Verification
const Fersaku = require('fersaku');
// Express handler
app.post('/webhook', (req, res) => {
const signature = req.headers['x-webhook-signature'];
const isValid = Fersaku.verifyWebhook(req.body, signature, 'whsec_your_secret');
if (!isValid) {
return res.status(401).send('Invalid signature');
}
const { event, payment_id, status, amount } = req.body;
if (event === 'payment.paid') {
// Proses pembayaran berhasil
}
res.status(200).send('OK');
});Sandbox vs Production
// Production
const live = new Fersaku('sk_live_xxx');
// Sandbox (testing)
const sandbox = new Fersaku('sk_test_xxx');Error Handling
try {
const payment = await fersaku.createPayment({ amount: 500 });
} catch (error) {
console.log(error.message); // "Amount must be at least Rp 1.000"
console.log(error.status); // 400
}Publish ke NPM
npm login
npm publishLicense
MIT
