An unofficial Midtrans Payment API Client Library for Node.js.
npm install @xct007/midtrans-client
// CommonJS
const MidtransClient = require("@xct007/midtrans-client").default;
// ES Modules
import MidtransClient from "@xct007/midtrans-client";
const { Core, Snap, Iris } = new MidtransClient({
sandbox: true, // Set to false for production
clientKey: "YOUR_CLIENT_KEY",
serverKey: "YOUR_SERVER_KEY",
throwHttpErrors: true,
});
Core.charge({
payment_type: "bank_transfer",
transaction_details: {
order_id: "order-id-" + new Date().getTime(),
gross_amount: 10000,
},
bank_transfer: {
bank: "bca",
},
})
.then((response) => {
console.log("Charge Response:", response);
})
.catch((error) => {
console.error("Charge Error:", error);
});
Explore more Core API methods on examples/core.
Snap.create({
transaction_details: {
order_id: "order-id-" + new Date().getTime(),
gross_amount: 10000,
},
})
.then((response) => {
console.log("Snap Token:", response.token);
console.log("Redirect URL:", response.redirect_url);
})
.catch((error) => {
console.error("Snap Error:", error);
});
Explore more Snap API methods on examples/snap.
Iris.ping()
.then((response) => {
console.log("Ping Response:", response);
})
.catch((error) => {
console.error("Ping Error:", error);
});
Explore more Iris API methods on examples/iris.
For hands-on examples, please refer to the examples directory.
For detailed API documentation, please refer to the Midtrans API Documentation.
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
This project is licensed under the MIT License - see the LICENSE file for details.
- This library is unofficial and maintained by xct007.
- This library is inspired by the official Midtrans Node.js Client
- Special thanks to Midtrans team.