@bagibagi/partner-integration
v0.1.1
Published
TypeScript SDK for BagiBagi Partner QRIS integration
Maintainers
Readme
@bagibagi/partner-integration
TypeScript SDK for BagiBagi Partner QRIS integration.
Features
- Create QRIS transaction
- Verify callback token
Installation
npm install @bagibagi/partner-integrationInformation
- You must have a BagiBagi account to use this SDK.
- To get your
merchantCodeandapiKey, request access via our Discord server: Join BagiBagi Discord
Quick Start (SDK Only)
import { BagiBagiClient } from "@bagibagi/partner-integration";
const client = new BagiBagiClient({
merchantCode: process.env.BAGIBAGI_MERCHANT_CODE!,
apiKey: process.env.BAGIBAGI_API_KEY!,
baseUrl: "https://bagibagi.co",
timeoutMs: 10000,
});
const result = await client.createQrisTransaction({
name: "test",
message: "testt",
amount: 100000,
email: "[email protected]",
webhookUrl: "https://partner.example.com/webhooks/bagibagi",
});
console.log(result);Express Example (Optional)
Full runnable example app: examples/express/README.md
import express from "express";
import {
BagiBagiClient,
createQrisRoute,
callbackVerifierMiddleware,
} from "@bagibagi/partner-integration/express";
const app = express();
app.use(express.json());
const client = new BagiBagiClient({
merchantCode: process.env.BAGIBAGI_MERCHANT_CODE!,
apiKey: process.env.BAGIBAGI_API_KEY!,
});
app.post("/payments/qris", createQrisRoute(client));
app.post("/webhooks/bagibagi", callbackVerifierMiddleware(client), (req, res) => {
res.status(200).json({ success: true });
});
app.listen(3000);Configuration
| Field | Required | Default | Description |
| -------------- | -------- | --------------------- | ------------------------------- |
| merchantCode | Yes | - | Merchant code from BagiBagi |
| apiKey | Yes | - | Secret key from BagiBagi |
| baseUrl | No | https://bagibagi.co | Base URL for API |
| timeoutMs | No | 10000 | Request timeout in milliseconds |
API
createQrisTransaction(input)
Input:
namemessageamountemailwebhookUrl
Returns:
qrisCodedonationIdamountemailexpiredAt
verifyCallbackToken(payload)
Validate callback token using:
MD5(merchantCode + apiKey + donationId + amount)
Returns:
trueif validfalseif invalid
Callback Payload Example
{
"OrderId": "bagibagi-0aedc19e-b75d-4b11-8d2d-d34b8b905795",
"Status": true,
"Token": "86bb978f6b6f067c5e99fd8d7c0a7259",
"DonationId": "0aedc19e-b75d-4b11-8d2d-d34b8b905795",
"Amount": 100000,
"CallbackAt": "2025-12-11T21:59:39.836634+07:00"
}Error Handling
Expected error classes:
ValidationErrorApiErrorNetworkErrorAuthError
Example:
import {
ValidationError,
ApiError,
NetworkError,
AuthError,
} from "@bagibagi/partner-integration";
try {
await client.createQrisTransaction(input);
} catch (err) {
if (err instanceof ValidationError) {
// Invalid input
} else if (err instanceof ApiError) {
// Non-2xx provider response
} else if (err instanceof NetworkError) {
// Timeout or network issue
} else if (err instanceof AuthError) {
// Callback token/auth issue
}
}Security Best Practices
- Store
apiKeyin env vars or secret manager - Do not log secrets or full tokens
- Always verify callback token before processing business logic
- Use server-side environments only
Development
npm run build
npm test
npm run lintLicense
MIT
