The `midtrans-client` package is the official Node.js API client for integrating with the Midtrans Payment Gateway. It provides a structured interface for interacting with Midtrans' two primary payment products: Snap, which offers a customizable payment popup directly on the merchant's website, and Core API (VT-Direct), which facilitates backend-driven payment flows with full frontend customization. The library is currently at version 1.4.3, with recent updates addressing dependency vulnerabilities and introducing new features such as Snap Bi functionalities (Direct Debit, QRIS, VA) and webhook notification verification. Its release cadence indicates active maintenance, with focus on reliability and feature expansion. As the official client, it provides a well-supported and up-to-date integration path, adhering to Midtrans' specific API requirements and product offerings.
npm install midtrans-clientVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to initialize the Midtrans Snap API client and create a new payment transaction, retrieving the transaction token and redirect URL.
Upgrade to `midtrans-client@1.4.2` or a newer version immediately to resolve the 'SnapBiApiRequestor' import problem and ensure the correct operation of Snap Bi features.
Adhere to `const midtransClient = require('midtrans-client');` for maximal compatibility. If ESM is required, ensure your project's `package.json` specifies `"type": "module"` and/or use a bundler (like Webpack, Rollup) or transpiler (like Babel, TypeScript).Always cross-reference your API keys with the chosen environment in your Midtrans Dashboard. Set `isProduction: true` for live transactions and `false` for testing/sandbox environments, matching your provided keys.
Regularly update the `midtrans-client` package to its latest stable version to incorporate security patches and benefit from updated dependencies.
Upgrade your `midtrans-client` package to version `1.4.2` or higher. This particular issue was fixed in that release.
Verify that your `serverKey` and `clientKey` are correct and correspond to the `isProduction` setting in your client initialization. Ensure you are not mixing sandbox and production keys/environments.
Ensure the package is installed by running `npm install midtrans-client`. If you're manually including the library, verify the `require()` path is correct, e.g., `require('./path/to/midtrans-client-nodejs/index.js')`.Refactor your import to use CommonJS `require()` and access `Snap` as a property: `const midtransClient = require('midtrans-client'); let snap = new midtransClient.Snap(...);`No dependency data recorded yet.