{"library":"midtrans-client","title":"Midtrans Payment API Client for Node.js","description":"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.","language":"javascript","status":"active","last_verified":"Sat Apr 25","install":{"commands":["npm install midtrans-client"],"cli":null},"imports":["const midtransClient = require('midtrans-client');","const midtransClient = require('midtrans-client');\nconst coreApi = new midtransClient.CoreApi({ /* config */ });","const midtransClient = require('midtrans-client');\nconst snap = new midtransClient.Snap({ /* config */ });"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const midtransClient = require('midtrans-client');\n\n// Initialize the Snap API client with environment variables for sensitive keys\nconst snap = new midtransClient.Snap({\n    isProduction: process.env.MIDTRANS_IS_PRODUCTION === 'true',\n    serverKey: process.env.MIDTRANS_SERVER_KEY ?? '',\n    clientKey: process.env.MIDTRANS_CLIENT_KEY ?? ''\n});\n\n// Define transaction parameters as per Midtrans Snap API documentation\nconst parameter = {\n    transaction_details: {\n        order_id: `ORDER-${Date.now()}`,\n        gross_amount: 10000 // Example: 10,000 IDR\n    },\n    credit_card: {\n        secure: true // Ensure 3D Secure is enabled\n    },\n    customer_details: {\n        first_name: 'Budi',\n        last_name: 'Pratama',\n        email: 'budi.pratama@example.com',\n        phone: '08123456789'\n    }\n};\n\n// Create the transaction and handle the response\nsnap.createTransaction(parameter)\n    .then((transaction) => {\n        // The transaction object contains token and redirect_url\n        let transactionToken = transaction.token;\n        console.log('Snap Transaction Token:', transactionToken);\n        let redirectUrl = transaction.redirect_url;\n        console.log('Snap Redirect URL:', redirectUrl);\n        \n        // In a real application, you would send this token or redirectUrl to your frontend\n        // to initiate the Snap payment popup or redirect the user.\n    })\n    .catch((e) => {\n        console.error('Error creating Snap transaction:', e.message);\n        // Handle error, e.g., log it or return an error response to the client\n    });\n","lang":"javascript","description":"This example demonstrates how to initialize the Midtrans Snap API client and create a new payment transaction, retrieving the transaction token and redirect URL.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}