{"id":21878068,"url":"https://github.com/midtrans/midtrans-nodejs-client","last_synced_at":"2025-05-15T12:04:32.464Z","repository":{"id":33231682,"uuid":"155836922","full_name":"Midtrans/midtrans-nodejs-client","owner":"Midtrans","description":"Official Midtrans Payment API Client for Node JS | https://midtrans.com","archived":false,"fork":false,"pushed_at":"2024-11-07T09:05:16.000Z","size":479,"stargazers_count":197,"open_issues_count":13,"forks_count":65,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-05-15T01:46:39.799Z","etag":null,"topics":["api-client","javascript","midtrans","node-js","nodejs","npm-package","payment","payment-gateway"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Midtrans.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-02T08:33:49.000Z","updated_at":"2025-05-13T14:15:11.000Z","dependencies_parsed_at":"2024-11-28T10:17:16.853Z","dependency_job_id":null,"html_url":"https://github.com/Midtrans/midtrans-nodejs-client","commit_stats":{"total_commits":132,"total_committers":9,"mean_commits":"14.666666666666666","dds":"0.48484848484848486","last_synced_commit":"2cb4967f9fda9396934beadb6d2a0368baa53e0c"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Midtrans%2Fmidtrans-nodejs-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Midtrans%2Fmidtrans-nodejs-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Midtrans%2Fmidtrans-nodejs-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Midtrans%2Fmidtrans-nodejs-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Midtrans","download_url":"https://codeload.github.com/Midtrans/midtrans-nodejs-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337612,"owners_count":22054253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","javascript","midtrans","node-js","nodejs","npm-package","payment","payment-gateway"],"created_at":"2024-11-28T08:11:35.676Z","updated_at":"2025-05-15T12:04:27.441Z","avatar_url":"https://github.com/Midtrans.png","language":"JavaScript","readme":"Midtrans Client - Node JS\n===============\n[![NPM](https://nodei.co/npm/midtrans-client.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/midtrans-client/)\n\n[![npm version](https://img.shields.io/npm/v/midtrans-client.svg?style=flat-square)](https://www.npmjs.org/package/midtrans-client)\n[![Build Status](https://travis-ci.org/rizdaprasetya/midtrans-nodejs-client.svg?branch=master)](https://travis-ci.org/rizdaprasetya/midtrans-nodejs-client)\n![NPM download/month](https://img.shields.io/npm/dm/midtrans-client.svg)\n![NPM download total](https://img.shields.io/npm/dt/midtrans-client.svg)\n\nMidtrans ❤️ Node JS! \n\nThis is the Official Node JS API client/library for Midtrans Payment API. Visit [https://midtrans.com](https://midtrans.com). More information about the product and see documentation at [http://docs.midtrans.com](https://docs.midtrans.com) for more technical details.\n\n## 1. Installation\n\n### 1.a Using NPM\n\n```\nnpm install --save midtrans-client\n```\n\n### 1.b Manual Installation\n\nIf you are not using NPM, you can clone or [download](https://github.com/midtrans/midtrans-nodejs-client/archive/master.zip) this repository.\nThen require from `index.js` file.\n\n```javascript\nlet midtransClient = require('./midtrans-client-nodejs/index.js');\n```\n\n## 2. Usage\n\n### 2.1 Choose Product/Method\n\nWe have [2 different products](https://docs.midtrans.com/en/welcome/index.html) of payment that you can use:\n- [Snap](#22A-snap) - Customizable payment popup will appear on **your web/app** (no redirection). [doc ref](https://snap-docs.midtrans.com/)\n- [Snap Redirect](#22B-snap-redirect) - Customer need to be redirected to payment url **hosted by midtrans**. [doc ref](https://snap-docs.midtrans.com/)\n- [Core API (VT-Direct)](#22C-core-api-vt-direct) - Basic backend implementation, you can customize the frontend embedded on **your web/app** as you like (no redirection). [doc ref](https://api-docs.midtrans.com/)\n\nChoose one that you think best for your unique needs.\n\n### 2.2 Client Initialization and Configuration\n\nGet your client key and server key from [Midtrans Dashboard](https://dashboard.midtrans.com)\n\nCreate API client object\n\n```javascript\nconst midtransClient = require('midtrans-client');\n// Create Core API instance\nlet coreApi = new midtransClient.CoreApi({\n        isProduction : false,\n        serverKey : 'YOUR_SERVER_KEY',\n        clientKey : 'YOUR_CLIENT_KEY'\n    });\n```\n\n\n```javascript\nconst midtransClient = require('midtrans-client');\n// Create Snap API instance\nlet snap = new midtransClient.Snap({\n        isProduction : false,\n        serverKey : 'YOUR_SERVER_KEY',\n        clientKey : 'YOUR_CLIENT_KEY'\n    });\n```\n\nYou can also re-set config using `Snap.apiConfig.set( ... )`\nexample:\n\n```javascript\nconst midtransClient = require('midtrans-client');\n\n// Create Snap API instance, empty config\nlet snap = new midtransClient.Snap();\nsnap.apiConfig.set({\n        isProduction : false,\n        serverKey : 'YOUR_SERVER_KEY',\n        clientKey : 'YOUR_CLIENT_KEY'\n    });\n\n// You don't have to re-set using all the options, \n// i.e. set serverKey only\nsnap.apiConfig.set({serverKey : 'YOUR_SERVER_KEY'});\n```\n\nYou can also set config directly from attribute\n```javascript\nconst midtransClient = require('midtrans-client');\n\n// Create Snap API instance, empty config\nlet snap = new midtransClient.Snap();\n\nsnap.apiConfig.isProduction = false;\nsnap.apiConfig.serverKey = 'YOUR_SERVER_KEY';\nsnap.apiConfig.clientKey = 'YOUR_CLIENT_KEY';\n```\n\n\n### 2.2.A Snap\nYou can see Snap example [here](examples/snap).\n\nAvailable methods for `Snap` class\n```javascript\n// return Snap API /transaction response as Promise of Object\ncreateTransaction(parameter)\n\n// return Snap API /transaction token as Promise of String\ncreateTransactionToken(parameter)\n\n// return Snap API /transaction redirect_url as Promise of String\ncreateTransactionRedirectUrl(parameter)\n```\n`parameter` is Object or String of JSON of [SNAP Parameter](https://snap-docs.midtrans.com/#json-objects)\n\n\n#### Get Snap Token\n\n```javascript\nconst midtransClient = require('midtrans-client');\n// Create Snap API instance\nlet snap = new midtransClient.Snap({\n        isProduction : false,\n        serverKey : 'YOUR_SERVER_KEY',\n        clientKey : 'YOUR_CLIENT_KEY'\n    });\n\nlet parameter = {\n    \"transaction_details\": {\n        \"order_id\": \"test-transaction-123\",\n        \"gross_amount\": 200000\n    }, \"credit_card\":{\n        \"secure\" : true\n    }\n};\n\n\nsnap.createTransaction(parameter)\n    .then((transaction)=\u003e{\n        // transaction token\n        let transactionToken = transaction.token;\n        console.log('transactionToken:',transactionToken);\n    })\n\n// alternative way to create transactionToken\n// snap.createTransactionToken(parameter)\n//     .then((transactionToken)=\u003e{\n//         console.log('transactionToken:',transactionToken);\n//     })\n```\n\n\n#### Initialize Snap JS when customer click pay button\n\nOn frontend / html:\nReplace `PUT_TRANSACTION_TOKEN_HERE` with `transactionToken` acquired above\n```html\n\u003chtml\u003e\n  \u003cbody\u003e\n    \u003cbutton id=\"pay-button\"\u003ePay!\u003c/button\u003e\n    \u003cpre\u003e\u003cdiv id=\"result-json\"\u003eJSON result will appear here after payment:\u003cbr\u003e\u003c/div\u003e\u003c/pre\u003e \n\n\u003c!-- TODO: Remove \".sandbox\" from script src URL for production environment. Also input your client key in \"data-client-key\" --\u003e\n    \u003cscript src=\"https://app.sandbox.midtrans.com/snap/snap.js\" data-client-key=\"\u003cSet your ClientKey here\u003e\"\u003e\u003c/script\u003e\n    \u003cscript type=\"text/javascript\"\u003e\n      document.getElementById('pay-button').onclick = function(){\n        // SnapToken acquired from previous step\n        snap.pay('PUT_TRANSACTION_TOKEN_HERE', {\n          // Optional\n          onSuccess: function(result){\n            /* You may add your own js here, this is just example */ document.getElementById('result-json').innerHTML += JSON.stringify(result, null, 2);\n          },\n          // Optional\n          onPending: function(result){\n            /* You may add your own js here, this is just example */ document.getElementById('result-json').innerHTML += JSON.stringify(result, null, 2);\n          },\n          // Optional\n          onError: function(result){\n            /* You may add your own js here, this is just example */ document.getElementById('result-json').innerHTML += JSON.stringify(result, null, 2);\n          }\n        });\n      };\n    \u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n#### Implement Notification Handler\n[Refer to this section](#23-handle-http-notification)\n\n### 2.2.B Snap Redirect\n\nAlso available as examples [here](examples/snap).\n\n#### Get Redirection URL of a Payment Page\n\n```javascript\nconst midtransClient = require('midtrans-client');\n// Create Snap API instance\nlet snap = new midtransClient.Snap({\n        isProduction : false,\n        serverKey : 'YOUR_SERVER_KEY',\n        clientKey : 'YOUR_CLIENT_KEY'\n    });\n\nlet parameter = {\n    \"transaction_details\": {\n        \"order_id\": \"test-transaction-123\",\n        \"gross_amount\": 200000\n    }, \"credit_card\":{\n        \"secure\" : true\n    }\n};\n\nsnap.createTransaction(parameter)\n    .then((transaction)=\u003e{\n        // transaction redirect_url\n        let redirectUrl = transaction.redirect_url;\n        console.log('redirectUrl:',redirectUrl);\n    })\n\n// alternative way to create redirectUrl\n// snap.createTransactionRedirectUrl(parameter)\n//     .then((redirectUrl)=\u003e{\n//         console.log('redirectUrl:',redirectUrl);\n//     })\n```\n#### Implement Notification Handler\n[Refer to this section](#23-handle-http-notification)\n\n### 2.2.C Core API (VT-Direct)\n\nYou can see some Core API examples [here](examples/coreApi).\n\nAvailable methods for `CoreApi` class\n```javascript\n/**\n * Do `/charge` API request to Core API\n * @param  {Object} parameter - object of Core API JSON body as parameter, will be converted to JSON (more params detail refer to: https://api-docs.midtrans.com)\n * @return {Promise} - Promise contains Object from JSON decoded response\n */\ncharge(parameter={})\n\n/**\n * Do `/capture` API request to Core API\n * @param  {Object} parameter - object of Core API JSON body as parameter, will be converted to JSON (more params detail refer to: https://api-docs.midtrans.com)\n * @return {Promise} - Promise contains Object from JSON decoded response\n */\ncapture(parameter={})\n\n/**\n * Do `/card/register` API request to Core API\n * @param  {Object} parameter - object of Core API JSON body as parameter, will be converted to JSON (more params detail refer to: https://api-docs.midtrans.com)\n * @return {Promise} - Promise contains Object from JSON decoded response\n */\ncardRegister(parameter={})\n\n/**\n * Do `/token` API request to Core API\n * @param  {Object} parameter - object of Core API JSON body as parameter, will be converted to JSON (more params detail refer to: https://api-docs.midtrans.com)\n * @return {Promise} - Promise contains Object from JSON decoded response\n */\ncardToken(parameter={})\n\n/**\n * Do `/point_inquiry/\u003ctokenId\u003e` API request to Core API\n * @param  {String} tokenId - tokenId of credit card (more params detail refer to: https://api-docs.midtrans.com)\n * @return {Promise} - Promise contains Object from JSON decoded response\n */\ncardPointInquiry(tokenId)\n```\n`parameter` is Object or String of JSON of [Core API Parameter](https://api-docs.midtrans.com/#json-objects)\n\n#### Credit Card Get Token\n\nGet token should be handled on  Frontend please refer to [API docs](https://api-docs.midtrans.com)\n\n#### Credit Card Charge\n\n```javascript\nconst midtransClient = require('midtrans-client');\n// Create Core API instance\nlet core = new midtransClient.CoreApi({\n        isProduction : false,\n        serverKey : 'YOUR_SERVER_KEY',\n        clientKey : 'YOUR_CLIENT_KEY'\n    });\n\nlet parameter = {\n    \"payment_type\": \"credit_card\",\n    \"transaction_details\": {\n        \"gross_amount\": 12145,\n        \"order_id\": \"test-transaction-54321\",\n    },\n    \"credit_card\":{\n        \"token_id\": 'CREDIT_CARD_TOKEN', // change with your card token\n        \"authentication\": true\n    }\n};\n\n// charge transaction\ncore.charge(parameter)\n    .then((chargeResponse)=\u003e{\n        console.log('chargeResponse:');\n        console.log(chargeResponse);\n    });\n```\n\n#### Credit Card 3DS Authentication\n\nThe credit card charge result may contains `redirect_url` for 3DS authentication. 3DS Authentication should be handled on Frontend please refer to [API docs](https://api-docs.midtrans.com/#card-features-3d-secure)\n\nFor full example on Credit Card 3DS transaction refer to:\n- [Express App examples](/examples/expressApp) that implement Snap \u0026 Core Api\n\n### 2.2.D Subscription API\n\nYou can see some Subscription API examples [here](examples/subscription), [Subscription API Docs](https://api-docs.midtrans.com/#subscription-api)\n\n#### Subscription API for Credit Card\n\nTo use subscription API for credit card, you should first obtain the 1-click saved token, [refer to this docs.](https://docs.midtrans.com/en/core-api/advanced-features?id=recurring-transaction-with-subscriptions-api)\n\nYou will receive `saved_token_id` as part of the response when the initial card payment is accepted (will also available in the HTTP notification's JSON), [refer to this docs.](https://docs.midtrans.com/en/core-api/advanced-features?id=sample-3ds-authenticate-json-response-for-the-first-transaction)\n\n```javascript\nconst midtransClient = require('midtrans-client');\n// Create Core API / Snap instance (both have shared `transactions` methods)\nlet core = new midtransClient.CoreAPi({\n        isProduction : false,\n        serverKey : 'YOUR_SERVER_KEY',\n        clientKey : 'YOUR_CLIENT_KEY'\n    });\n// prepare parameter \nlet parameter = {\n  \"name\": \"MONTHLY_2021\",\n  \"amount\": \"14000\",\n  \"currency\": \"IDR\",\n  \"payment_type\": \"credit_card\",\n  \"token\": \"521111gmWqMegyejqCQmmopnCFRs1117\",\n  \"schedule\": {\n    \"interval\": 1,\n    \"interval_unit\": \"month\",\n    \"max_interval\": 12,\n    \"start_time\": \"2021-11-25 07:25:01 +0700\"\n  },\n  \"metadata\": {\n    \"description\": \"Recurring payment for A\"\n  },\n  \"customer_details\": {\n    \"first_name\": \"John\",\n    \"last_name\": \"Doe\",\n    \"email\": \"johndoe@email.com\",\n    \"phone\": \"+62812345678\"\n  }\n};\n\ncore.createSubscription(parameter)\n        .then((response)=\u003e{\n          // do something to `response` object\n        });\n\n// get subscription by subscriptionId\ncore.getSubscription(subscriptionId)\n        .then((response)=\u003e{\n          // do something to `response` object\n        });\n\n// enable subscription by subscriptionId\ncore.enableSubscription(subscriptionId)\n        .then((response)=\u003e{\n          // do something to `response` object\n        });\n\n// update subscription by subscriptionId and updateSubscriptionParam\nlet updateSubscriptionParam = {\n  \"name\": \"MONTHLY_2021\",\n  \"amount\": \"300000\",\n  \"currency\": \"IDR\",\n  \"token\": savedTokenId,\n  \"schedule\": {\n    \"interval\": 1\n  }\n}\ncore.updateSubscription(subscriptionId, updateSubscriptionParam)\n        .then((response)=\u003e{\n          // do something to `response` object\n        });\n```\n#### Subscription API for Gopay\n\nTo use subscription API for gopay, you should first link your customer gopay account with gopay tokenization API, [refer to this section](#22e-tokenization-api)\n\nYou will receive gopay payment token using `getPaymentAccount` API call\n\nYou can see some Subscription API examples [here](examples/subscription)\n\n### 2.2.E Tokenization API\nYou can see some Tokenization API examples [here](examples/tokenization), [Tokenization API Docs](https://api-docs.midtrans.com/#gopay-tokenization)\n\n```javascript\nconst midtransClient = require('midtrans-client');\n// Create Core API / Snap instance (both have shared `transactions` methods)\nlet core = new midtransClient.CoreApi({\n        isProduction : false,\n        serverKey : 'YOUR_SERVER_KEY',\n        clientKey : 'YOUR_CLIENT_KEY'\n    });\n\n// prepare parameter \nlet parameter = {\n  \"payment_type\": \"gopay\",\n  \"gopay_partner\": {\n    \"phone_number\": \"81212345678\",\n    \"country_code\": \"62\",\n    \"redirect_url\": \"https://www.gojek.com\"\n  }\n};\n\n// link Payment Account\ncore.linkPaymentAccount(parameter)\n        .then((response)=\u003e{\n          // do something to `response` object\n        });\n\n// Get payment account by account id\ncore.getPaymentAccount(activeAccountId)\n        .then((response)=\u003e{\n          // do something to `response` object\n        });\n\n// unlink payment account by accountId\ncore.unlinkPaymentAccount(activeAccountId)\n        .then((response)=\u003e{\n          // do something to `response` object\n        });\n\n```\n\n### 2.3 Handle HTTP Notification\n\n\u003e **IMPORTANT NOTE**: To update transaction status on your backend/database, **DO NOT** solely rely on frontend callbacks! For security reason to make sure the status is authentically coming from Midtrans, only update transaction status based on HTTP Notification or API Get Status.\n\nCreate separated web endpoint (notification url) to receive HTTP POST notification callback/webhook. \nHTTP notification will be sent whenever transaction status is changed.\nExample also available [here](examples/transactionActions/notificationExample.js)\n\n```javascript\nconst midtransClient = require('midtrans-client');\n// Create Core API / Snap instance (both have shared `transactions` methods)\nlet apiClient = new midtransClient.Snap({\n        isProduction : false,\n        serverKey : 'YOUR_SERVER_KEY',\n        clientKey : 'YOUR_CLIENT_KEY'\n    });\n\napiClient.transaction.notification(notificationJson)\n    .then((statusResponse)=\u003e{\n        let orderId = statusResponse.order_id;\n        let transactionStatus = statusResponse.transaction_status;\n        let fraudStatus = statusResponse.fraud_status;\n\n        console.log(`Transaction notification received. Order ID: ${orderId}. Transaction status: ${transactionStatus}. Fraud status: ${fraudStatus}`);\n\n        // Sample transactionStatus handling logic\n\n        if (transactionStatus == 'capture'){\n            // capture only applies to card transaction, which you need to check for the fraudStatus\n            if (fraudStatus == 'challenge'){\n                // TODO set transaction status on your databaase to 'challenge'\n            } else if (fraudStatus == 'accept'){\n                // TODO set transaction status on your databaase to 'success'\n            }\n        } else if (transactionStatus == 'settlement'){\n            // TODO set transaction status on your databaase to 'success'\n        } else if (transactionStatus == 'deny'){\n            // TODO you can ignore 'deny', because most of the time it allows payment retries\n            // and later can become success\n        } else if (transactionStatus == 'cancel' ||\n          transactionStatus == 'expire'){\n            // TODO set transaction status on your databaase to 'failure'\n        } else if (transactionStatus == 'pending'){\n            // TODO set transaction status on your databaase to 'pending' / waiting payment\n        }\n    });\n```\n\n### 2.4 Transaction Action\nAlso available as examples [here](examples/transactionActions)\n#### Get Status\n```javascript\n// get status of transaction that already recorded on midtrans (already `charge`-ed) \napiClient.transaction.status('YOUR_ORDER_ID OR TRANSACTION_ID')\n    .then((response)=\u003e{\n        // do something to `response` object\n    });\n```\n#### Get Status B2B\n```javascript\n// get transaction status of VA b2b transaction\napiClient.transaction.statusb2b('YOUR_ORDER_ID OR TRANSACTION_ID')\n    .then((response)=\u003e{\n        // do something to `response` object\n    });\n```\n#### Approve Transaction\n```javascript\n// approve a credit card transaction with `challenge` fraud status\napiClient.transaction.approve('YOUR_ORDER_ID OR TRANSACTION_ID')\n    .then((response)=\u003e{\n        // do something to `response` object\n    });\n```\n#### Deny Transaction\n```javascript\n// deny a credit card transaction with `challenge` fraud status\napiClient.transaction.deny('YOUR_ORDER_ID OR TRANSACTION_ID')\n    .then((response)=\u003e{\n        // do something to `response` object\n    });\n```\n#### Cancel Transaction\n```javascript\napiClient.transaction.cancel('YOUR_ORDER_ID OR TRANSACTION_ID')\n    .then((response)=\u003e{\n        // do something to `response` object\n    });\n```\n#### Expire Transaction\n```javascript\napiClient.transaction.expire('YOUR_ORDER_ID OR TRANSACTION_ID')\n    .then((response)=\u003e{\n        // do something to `response` object\n    });\n```\n#### Refund Transaction\n```javascript\nlet parameter = {\n    \"refund_key\": \"order1-ref1\",\n    \"amount\": 5000,\n    \"reason\": \"Item out of stock\"\n}\napiClient.transaction.refund('YOUR_ORDER_ID OR TRANSACTION_ID',parameter)\n    .then((response)=\u003e{\n        // do something to `response` object\n    });\n```\n#### Refund Transaction with Direct Refund\n```javascript\nlet parameter = {\n    \"refund_key\": \"order1-ref1\",\n    \"amount\": 5000,\n    \"reason\": \"Item out of stock\"\n}\napiClient.transaction.refundDirect('YOUR_ORDER_ID OR TRANSACTION_ID',parameter)\n    .then((response)=\u003e{\n        // do something to `response` object\n    });\n```\n\n## 3. Handling Error / Exception\nWhen using function that result in Midtrans API call e.g: `core.charge(...)` or `snap.createTransaction(...)` \nthere's a chance it may throw error (`MidtransError` object), the error object will contains below properties that can be used as information to your error handling logic:\n```javascript\nsnap.createTransaction(parameter)\n      .then((res)=\u003e{\n      })\n      .catch((e)=\u003e{\n        e.message // basic error message string\n        e.httpStatusCode // HTTP status code e.g: 400, 401, etc.\n        e.ApiResponse // JSON of the API response \n        e.rawHttpClientData // raw Axios response object\n      })\n```\n\n## 4. Advanced Usage\n### Custom Http Client Config\nUnder the hood this API wrapper is using [Axios](https://github.com/axios/axios) as http client. You can override the default config. \n\nYou can set via the value of this `\u003capi-client-instance\u003e.httpClient.http_client.defaults` object, like [described in Axios guide](https://github.com/axios/axios#global-axios-defaults). e.g:\n```javascript\n// create instance of api client\nlet snap = new midtransClient.Snap({\n        isProduction : false,\n        serverKey : 'YOUR_SERVER_KEY',\n        clientKey : 'YOUR_CLIENT_KEY'\n    });\n\n// set Axios timeout config to 2500\nsnap.httpClient.http_client.defaults.timeout = 2500; \n\n// set custom HTTP header for every request from this instance\nsnap.httpClient.http_client.defaults.headers.common['My-Header'] = 'my-custom-value';\n```\n### Custom Http Client Interceptor\nAs Axios [also support interceptor](https://github.com/axios/axios#interceptors), you can also apply it here. e.g:\n```javascript\n// Add a request interceptor\nsnap.httpClient.http_client.interceptors.request.use(function (config) {\n    // Do something before request is sent\n    return config;\n  }, function (error) {\n    // Do something with request error\n    return Promise.reject(error);\n  });\n```\n\nIt can be used for example to customize/manipulate http request's body, header, etc. before it got sent to the destination API url.\n\n### Override Http Notification Url\nAs [described in API docs](https://snap-docs.midtrans.com/#override-notification-url), merchant can opt to change or add custom notification urls on every transaction. It can be achieved by adding additional HTTP headers into charge request.\n\nThis can be achived by:\n```javascript\n// create instance of api client\nlet snap = new midtransClient.Snap({\n        isProduction : false,\n        serverKey : 'YOUR_SERVER_KEY',\n        clientKey : 'YOUR_CLIENT_KEY'\n});\n\n// set custom HTTP header that will be used by Midtrans API to override notification url:\nsnap.httpClient.http_client.defaults.headers.common['X-Override-Notification'] = 'https://mysite.com/midtrans-notification-handler';\n```\n\nor append notification:\n```javascript\nsnap.httpClient.http_client.defaults.headers.common['X-Append-Notification'] = 'https://mysite.com/midtrans-notification-handler';\n```\n\n## 5. Iris Disbursement API\n\n[Iris](https://iris-docs.midtrans.com) is Midtrans’ cash management solution that allows you to disburse payments to any bank accounts in Indonesia securely and easily. Iris connects to the banks’ hosts to enable seamless transfer using integrated APIs.\n\nFor more details please visit: https://iris-docs.midtrans.com\n\n### 5.1 Client Initialization\n\nGet your API key from [Midtrans Iris Dashboard](https://app.midtrans.com/iris)\n\nCreate API client object. Note: the serverKey means your API key.\n\n```javascript\nconst midtransClient = require('midtrans-client');\n// Create Core API instance\nlet iris = new midtransClient.Iris({\n        isProduction : false,\n        serverKey : 'YOUR_API_KEY'\n    });\n```\n\nThen perform one of the available functions, using the payload described on [Iris docs](https://iris-docs.midtrans.com), e.g:\n```javascript\nlet iris = new midtransClient.Iris({\n        isProduction : false,\n        serverKey : 'YOUR_API_KEY'\n    });\n\niris.createBeneficiaries({\n  \"name\": \"Budi Susantoo\",\n  \"account\": \"0611101146\",\n  \"bank\": \"bca\",\n  \"alias_name\": \"budisusantoo\",\n  \"email\": \"budi.susantoo@example.com\"\n})\n  .then((res)=\u003e{\n    // do something based on the API response\n  })\n  .catch((err)=\u003e{\n    // do something based on the Error object \u0026 message\n  })\n```\n\n### 5.2 Available methods of Iris API\n\n```javascript\n\n  /**\n   * Do `/ping` API request to Iris API\n   * @return {Promise} - Promise contains String response\n   */\n  ping()\n  /**\n   * Do create `/beneficiaries` API request to Iris API\n   * @param  {Object} parameter - object of Iris API JSON body as parameter, will be converted to JSON (more params detail refer to: https://iris-docs.midtrans.com)\n   * @return {Promise} - Promise contains Object from JSON decoded response\n   */\n  createBeneficiaries(parameter={})\n  /**\n   * Do update `/beneficiaries/\u003calias_name\u003e` API request to Iris API\n   * @param  {String} parameter - alias_name of the beneficiaries that need to be updated\n   * @param  {Object} parameter - object of Iris API JSON body as parameter, will be converted to JSON (more params detail refer to: https://iris-docs.midtrans.com)\n   * @return {Promise} - Promise contains Object from JSON decoded response\n   */\n  updateBeneficiaries(aliasName,parameter={})\n  /**\n   * Do `/beneficiaries` API request to Iris API\n   * @return {Promise} - Promise contains Object from JSON decoded response\n   */\n  getBeneficiaries()\n  /**\n   * Do create `/payouts` API request to Iris API\n   * @param  {Object} parameter - object of Iris API JSON body as parameter, will be converted to JSON (more params detail refer to: https://iris-docs.midtrans.com)\n   * @return {Promise} - Promise contains Object from JSON decoded response\n   */\n  createPayouts(parameter={})\n  /**\n   * Do approve `/payouts/approve` API request to Iris API\n   * @param  {Object} parameter - object of Iris API JSON body as parameter, will be converted to JSON (more params detail refer to: https://iris-docs.midtrans.com)\n   * @return {Promise} - Promise contains Object from JSON decoded response\n   */\n  approvePayouts(parameter={})\n  /**\n   * Do reject `/payouts/reject` API request to Iris API\n   * @param  {Object} parameter - object of Iris API JSON body as parameter, will be converted to JSON (more params detail refer to: https://iris-docs.midtrans.com)\n   * @return {Promise} - Promise contains Object from JSON decoded response\n   */\n  rejectPayouts(parameter={})\n  /**\n   * Do `/payouts/\u003creference_no\u003e` API request to Iris API\n   * @param  {String} parameter - reference_no of the payout\n   * @return {Promise} - Promise contains Object from JSON decoded response\n   */\n  getPayoutDetails(referenceNo)\n  /**\n   * Do `/statements` API request to Iris API\n   * @return {Promise} - Promise contains Object from JSON decoded response\n   */\n  getTransactionHistory(parameter={})\n  /**\n   * Do `/channels` API request to Iris API\n   * @return {Promise} - Promise contains Object from JSON decoded response\n   */\n  getTopupChannels()\n  /**\n   * Do `/balance` API request to Iris API\n   * @return {Promise} - Promise contains Object from JSON decoded response\n   */\n  getBalance()\n  /**\n   * Do `/bank_accounts` API request to Iris API\n   * @return {Promise} - Promise contains Object from JSON decoded response\n   */\n  getFacilitatorBankAccounts()\n  /**\n   * Do `/bank_accounts/\u003cbank_account_id\u003e/balance` API request to Iris API\n   * @param  {String} parameter - bank_account_id of the bank account\n   * @return {Promise} - Promise contains Object from JSON decoded response\n   */\n  getFacilitatorBalance(bankAccountId)\n  /**\n   * Do `/beneficiary_banks` API request to Iris API\n   * @return {Promise} - Promise contains Object from JSON decoded response\n   */\n  getBeneficiaryBanks()\n  /**\n   * Do `/account_validation` API request to Iris API\n   * @param  {Object} parameter - object of Iris API JSON body as parameter, will be converted to GET Query param (more params detail refer to: https://iris-docs.midtrans.com)\n   * @return {Promise} - Promise contains Object from JSON decoded response\n   */\n  validateBankAccount(parameter={})\n```\nYou can also refer to [Iris test cases](/test/iris.test.js) for sample usage for now. Dedicated sample usage might be written later in the future.\n\n## 6. Snap-BI (*NEW FEATURE starting v1.4.2)\nStandar Nasional Open API Pembayaran, or in short SNAP, is a national payment open API standard published by Bank Indonesia. To learn more you can read this [docs](https://docs.midtrans.com/reference/core-api-snap-open-api-overview)\n\n### 6.1 General Settings\n\n```javascript\nconst midtransClient = require('midtrans-client'); // use this if installed via NPM\n\n//These config value are based on the header stated here https://docs.midtrans.com/reference/getting-started-1\n// Set to Development/Sandbox Environment (default). Set to true for Production Environment (accept real transaction).\nmidtransClient.SnapBiConfig.isProduction = true\n// Set your client id. Merchant’s client ID that will be given by Midtrans, will be used as X-CLIENT-KEY on request’s header in B2B Access Token API.\nmidtransClient.SnapBiConfig.snapBiClientId = \"your client id\"\n// Set your private key here, make sure to add \\n on the private key, you can refer to the examples\nmidtransClient.SnapBiConfig.snapBiPrivateKey = \"your private key\";\n// Set your client secret. Merchant’s secret key that will be given by Midtrans, will be used for symmetric signature generation for Transactional API’s header.\nmidtransClient.SnapBiConfig.snapBiClientSecret = \"your client secret\";\n// Set your partner id. Merchant’s partner ID that will be given by Midtrans, will be used as X-PARTNER-ID on Transactional API’s header.\nmidtransClient.SnapBiConfig.snapBiPartnerId = \"your partner id\";\n// Set the channel id here.\nmidtransClient.SnapBiConfig.snapBiChannelId = \"your channel id\";\n// Enable logging to see details of the request/response make sure to disable this on production, the default is disabled.\nmidtransClient.SnapBiConfig.enableLogging = true;\n```\n\n### 6.2 Create Payment\n\n#### 6.2.1 Direct Debit (Gopay, Dana, Shopeepay)\nRefer to this [docs](https://docs.midtrans.com/reference/direct-debit-api-gopay) for more detailed information about creating payment using direct debit.\n\n```javascript\nconst midtransClient = require('midtrans-client'); // use this if installed via NPM\n\nconst externalId = randomUUID();\nlet directDebiRequestBody = {\n  \"partnerReferenceNo\": externalId,\n  \"chargeToken\": \"\",\n  \"merchantId\": merchantId,\n  \"urlParam\": {\n    \"url\": \"https://midtrans-test.com/api/notification\",\n    \"type\": \"PAY_RETURN\",\n    \"isDeeplink\": \"N\"\n  },\n  \"validUpTo\": \"2030-07-20T20:34:15.452305Z\",\n  \"payOptionDetails\": [\n    {\n      \"payMethod\": \"GOPAY\",\n      \"payOption\": \"GOPAY_WALLET\",\n      \"transAmount\": {\n        \"value\": \"1500\",\n        \"currency\": \"IDR\"\n      }\n    }\n  ],\n  \"additionalInfo\": {\n    \"customerDetails\": {\n      \"firstName\": \"Merchant\",\n      \"lastName\": \"Operation\",\n      \"email\": \"merchant-ops@midtrans.com\",\n      \"phone\": \"+6281932358123\",\n      \"billingAddress\": {\n        \"firstName\": \"Merchant\",\n        \"lastName\": \"Operation\",\n        \"phone\": \"+6281932358123\",\n        \"address\": \"Pasaraya Blok M\",\n        \"city\": \"Jakarta\",\n        \"postalCode\": \"12160\",\n        \"countryCode\": \"IDN\"\n      },\n      \"shippingAddress\": {\n        \"firstName\": \"Merchant\",\n        \"lastName\": \"Operation\",\n        \"phone\": \"+6281932358123\",\n        \"address\": \"Pasaraya Blok M\",\n        \"city\": \"Jakarta\",\n        \"postalCode\": \"12160\",\n        \"countryCode\": \"IDN\"\n      }\n    },\n    \"items\": [\n      {\n        \"id\": \"8143fc4f-ec05-4c55-92fb-620c212f401e\",\n        \"price\": {\n          \"value\": \"1500.00\",\n          \"currency\": \"IDR\"\n        },\n        \"quantity\": 1,\n        \"name\": \"test item name\",\n        \"brand\": \"test item brand\",\n        \"category\": \"test item category\",\n        \"merchantName\": \"Merchant Operation\"\n      }\n    ]\n  }\n}\n/**\n *  Basic example\n * to change the payment method, you can change the value of the request body on the `payOptionDetails`\n * the `currency` value that we support for now is only `IDR`\n */\nmidtransClient.SnapBi.directDebit()\n        .withBody(directDebiRequestBody)\n        .createPayment(externalId)\n        .then(r =\u003e\n                console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n        )\n\n```\n#### 6.2.2 VA (Bank Transfer)\nRefer to this [docs](https://docs.midtrans.com/reference/virtual-account-api-bank-transfer) for more detailed information about VA/Bank Transfer.\n```javascript\nconst midtransClient = require('midtrans-client'); // use this if installed via NPM\n\nconst externalId = randomUUID();\nlet vaRequestBody = {\n  \"partnerServiceId\": \"    1234\",\n  \"customerNo\": \"0000000000\",\n  \"virtualAccountNo\": \"    12340000000000\",\n  \"virtualAccountName\": \"Merchant Operation\",\n  \"virtualAccountEmail\": \"merchant-ops@midtrans.com\",\n  \"virtualAccountPhone\": \"6281932358123\",\n  \"trxId\": externalId,\n  \"totalAmount\": {\n    \"value\": \"1500.00\",\n    \"currency\": \"IDR\"\n  },\n  \"expiredDate\": \"2030-07-20T20:50:04Z\",\n  \"additionalInfo\": {\n    \"merchantId\": merchantId,\n    \"bank\": \"bca\",\n    \"flags\": {\n      \"shouldRandomizeVaNumber\": true\n    },\n    \"customerDetails\": {\n      \"firstName\": \"Merchant\",\n      \"lastName\": \"Operation\",\n      \"email\": \"merchant-ops@midtrans.com\",\n      \"phone\": \"+6281932358123\",\n      \"billingAddress\": {\n        \"firstName\": \"Merchant\",\n        \"lastName\": \"Operation\",\n        \"phone\": \"+6281932358123\",\n        \"address\": \"Pasaraya Blok M\",\n        \"city\": \"Jakarta\",\n        \"postalCode\": \"12160\",\n        \"countryCode\": \"IDN\"\n      },\n      \"shippingAddress\": {\n        \"firstName\": \"Merchant\",\n        \"lastName\": \"Operation\",\n        \"phone\": \"+6281932358123\",\n        \"address\": \"Pasaraya Blok M\",\n        \"city\": \"Jakarta\",\n        \"postalCode\": \"12160\",\n        \"countryCode\": \"IDN\"\n      }\n    },\n    \"items\": [\n      {\n        \"id\": \"8143fc4f-ec05-4c55-92fb-620c212f401e\",\n        \"price\": {\n          \"value\": \"1500.00\",\n          \"currency\": \"IDR\"\n        },\n        \"quantity\": 1,\n        \"name\": \"test item name\",\n        \"brand\": \"test item brand\",\n        \"category\": \"test item category\",\n        \"merchantName\": \"Merchant Operation\"\n      }\n    ]\n  }\n}\n\n\n/**\n * basic implementation to create payment using va\n */\nmidtransClient.SnapBi.va()\n        .withBody(vaRequestBody)\n        .createPayment(externalId)\n        .then(r =\u003e\n                console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n        )\n```\n#### 6.2.3 Qris\nRefer to this [docs](https://docs.midtrans.com/reference/mpm-api-qris) for more detailed information about Qris.\n```javascript\nconst midtransClient = require('midtrans-client'); // use this if installed via NPM\n\nconst externalId = randomUUID();\n\nlet additionalHeader = {\n  \"X-device-id\": \"your device id\",\n  \"debug-id\": \"your debug id\"\n}\n\nlet qrisRequestBody = {\n  \"partnerReferenceNo\": externalId,\n  \"merchantId\": merchantId,\n  \"amount\": {\n    \"value\": \"1500.00\",\n    \"currency\": \"IDR\"\n  },\n  \"validityPeriod\": \"2030-07-03T12:08:56-07:00\",\n  \"additionalInfo\": {\n    \"acquirer\": \"gopay\",\n    \"customerDetails\": {\n      \"firstName\": \"Merchant\",\n      \"lastName\": \"Operation\",\n      \"email\": \"merchant-ops@midtrans.com\",\n      \"phone\": \"+6281932358123\"\n    },\n    \"items\": [\n      {\n        \"id\": \"8143fc4f-ec05-4c55-92fb-620c212f401e\",\n        \"price\": {\n          \"value\": \"1500.00\",\n          \"currency\": \"IDR\"\n        },\n        \"quantity\": 1,\n        \"name\": \"test item name\",\n        \"brand\": \"test item brand\",\n        \"category\": \"test item category\",\n        \"merchantName\": \"Merchant Operation\"\n      }\n    ],\n    \"countryCode\": \"ID\",\n    \"locale\": \"id_ID\"\n  }\n}\n\n/**\n * basic implementation to create payment using Qris\n */\nmidtransClient.SnapBi.qris()\n        .withBody(qrisRequestBody)\n        .createPayment(externalId)\n        .then(r =\u003e\n                console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n        )\n```\n\n### 6.4 Get Transaction Status\nRefer to this [docs](https://docs.midtrans.com/reference/get-transaction-status-api) for more detailed information about getting the transaction status.\n```javascript\nconst midtransClient = require('midtrans-client'); // use this if installed via NPM\n\nlet directDebitStatusBodyByExternalId = {\n  \"originalExternalId\": \"67fd4d9e-5fe6-477c-ab99-026a9ab88c34\",\n  \"serviceCode\": \"54\"\n}\nlet directDebitStatusBodyByReferenceNo = {\n  \"originalReferenceNo\": \"A120240930071006pW0gbFMTguID\",\n  \"serviceCode\": \"54\"\n}\n\nlet vaStatusBody = {\n  \"partnerServiceId\": \"    1234\",\n  \"customerNo\": \"356899\",\n  \"virtualAccountNo\": \"    1234356899\",\n  \"inquiryRequestId\": \"5a5597d1-615d-4df0-875d-aa429b2b1b68\",\n  \"additionalInfo\": {\n    \"merchantId\": merchantId\n  }\n}\n\nlet qrisStatusBody = {\n  \"originalReferenceNo\": \"A120240930074508BIDP4QaNnJID\",\n  \"originalPartnerReferenceNo\": \"b7d2bc2e-9d5b-4cec-a39f-4244c11e1b98\",\n  \"merchantId\": merchantId,\n  \"serviceCode\": \"47\"\n}\n\n/**\n * Example code for Direct Debit getStatus using externalId\n */\nmidtransClient.SnapBi.directDebit()\n        .withBody(directDebitStatusBodyByExternalId)\n        .getStatus(externalId)\n        .then(r =\u003e\n                console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n        )\n\n/**\n * Example code for Direct Debit getStatus using referenceNo\n */\nmidtransClient.SnapBi.directDebit()\n        .withBody(directDebitStatusBodyByReferenceNo)\n        .getStatus(externalId)\n        .then(r =\u003e\n                console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n        )\n    \n/**\n * Example code for VA (Bank Transfer) getStatus\n */\nmidtransClient.SnapBi.va()\n        .withBody(vaStatusBody)\n        .getStatus(externalId)\n        .then(r =\u003e\n                console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n        )\n/**\n * \n * Example code for Qris getStatus\n */\nmidtransClient.SnapBi.qris()\n        .withBody(qrisStatusBody)\n        .getStatus(externalId)\n        .then(r =\u003e\n                console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n        )\n\n```\n\n### 6.5 Cancel Transaction\nRefer to this [docs](https://docs.midtrans.com/reference/cancel-api) for more detailed information about cancelling the payment.\n\n```javascript\nconst midtransClient = require('midtrans-client'); // use this if installed via NPM\n\nconst externalId = randomUUID();\n\nlet directDebitCancelByReferenceNoBody = {\n  \"originalReferenceNo\" : \"A120240930075800vyWwxohb5WID\"\n}\n\nlet directDebitCancelByExternalIdBody = {\n  \"originalExternalId\" : \"8a074fc8-4eac-4b06-959a-95aeb91c7920\"\n}\n\nlet vaCancelBody = {\n  \"partnerServiceId\": \"    1234\",\n  \"customerNo\": \"564902\",\n  \"virtualAccountNo\": \"    1234564902\",\n  \"trxId\": \"18f2bd6d-e1be-43e2-89e4-8f9088251f60\",\n  \"additionalInfo\": {\n    \"merchantId\": merchantId\n  }\n}\n\nlet qrisCancelBody = {\n  \"originalReferenceNo\": \"A120240930075936LUOBMHxvPOID\",\n  \"merchantId\": merchantId,\n  \"reason\": \"cancel reason\"\n}\n/**\n * Basic implementation to cancel transaction using referenceNo\n */\nmidtransClient.SnapBi.directDebit()\n        .withBody(directDebitCancelByReferenceNoBody)\n        .cancel(externalId)\n        .then(r =\u003e\n                console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n        )\n\n/**\n * Basic implementation to cancel transaction using externalId\n */\nmidtransClient.SnapBi.directDebit()\n        .withBody(directDebitCancelByExternalIdBody)\n        .cancel(externalId)\n        .then(r =\u003e\n                console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n        )\n\n/**\n * Basic implementation of VA (Bank Transfer) to cancel transaction\n */\nmidtransClient.SnapBi.va()\n        .withBody(vaCancelBody)\n        .cancel(externalId)\n        .then(r =\u003e\n                console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n        )\n\n/**\n * Basic implementation of Qris to cancel transaction\n */\nmidtransClient.SnapBi.qris()\n        .withBody(qrisCancelBody)\n        .cancel(externalId)\n        .then(r =\u003e\n                console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n        )\n\n```\n\n### 6.6 Refund Transaction\nRefer to this [docs](https://docs.midtrans.com/reference/refund-api) for more detailed information about refunding the payment.\n\n```javascript\nconst midtransClient = require('midtrans-client'); // use this if installed via NPM\n\n let directDebitRefundBody = {\n  \"originalReferenceNo\": \"A1202409300808041pswnOt7wMID\",\n  \"reason\" : \"refund reason\"\n}\n\nlet qrisRefundBody = {\n  \"merchantId\": merchantId,\n  \"originalPartnerReferenceNo\": \"488fd30e-64d7-4236-9e7a-82d55d9efad3\",\n  \"originalReferenceNo\": \"A1202409300907114b5RZRNSRuID\",\n  \"partnerRefundNo\": \"is-refund-12345\",\n  \"reason\": \"refund reason\",\n  \"refundAmount\": {\n    \"value\": \"100.00\",\n    \"currency\": \"IDR\"\n  },\n  \"additionalInfo\": {\n    \"foo\": \"bar\"\n  }\n}\n/**\n * Example code for refund using Direct Debit\n */\nmidtransClient.SnapBi.directDebit()\n        .withBody(directDebitRefundBody)\n        .refund(externalId)\n        .then(r =\u003e\n                console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n        )\n\n/**\n * Example code for refund using Qris\n */\nmidtransClient.SnapBi.qris()\n        .withBody(qrisRefundBody)\n        .refund(externalId)\n        .then(r =\u003e\n                console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n        )\n```\n\n### 6.7 Adding additional header / override the header\n\nYou can add or override the header value, by utilizing the `withAccessTokenHeader` or `withTransactionHeader` method chain.\nRefer to this [docs](https://docs.midtrans.com/reference/core-api-snap-open-api-overview) to see the header value required by Snap-Bi , and see the default header on each payment method\n\n```javascript\nconst midtransClient = require('midtrans-client'); // use this if installed via NPM\n\nlet additionalHeader = {\n  \"X-device-id\": \"your device id\",\n  \"debug-id\": \"your debug id\"\n}\n /**\n * Example code for Direct Debit payment using additional header\n */\n midtransClient.SnapBi.directDebit()\n         .withBody(directDebiRequestBody)\n         .withAccessTokenHeader(additionalHeader)\n         .withTransactionHeader(additionalHeader)\n         .createPayment(externalId)\n         .then(r =\u003e\n                 console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n         )\n/**\n * Example code for using additional header on creating payment using VA\n */\nmidtransClient.SnapBi.va()\n        .withBody(vaRequestBody)\n        .withAccessTokenHeader(additionalHeader)\n        .withTransactionHeader(additionalHeader)\n        .createPayment(externalId)\n        .then(r =\u003e\n                console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n        )\n```\n\n### 6.8 Reusing Access Token\n\nIf you've saved your previous access token and wanted to re-use it, you can do it by utilizing the `.withAccessToken()`.\n\n```javascript\nconst midtransClient = require('midtrans-client'); // use this if installed via NPM\n/**\n * Example reusing your existing accessToken by using .withAccessToken()\n */\nmidtransClient.SnapBi.directDebit()\n        .withBody(directDebiRequestBody)\n        .withAccessToken(\"your access token\")\n        .createPayment(externalId)\n        .then(r =\u003e\n                console.log(\"Snap Bi result: \" + JSON.stringify(r, null, 2))\n        )\n\n```\n\n### 6.9 Payment Notification\nTo implement Snap-Bi Payment Notification you can refer to this [docs](https://docs.midtrans.com/reference/payment-notification-api)\nTo verify the webhook notification that you receive you can use this method below\n```javascript\n const midtransClient = require('midtrans-client'); // use this if installed via NPM\n\n// The request body/ payload sent by the webhook\n// Sample notification body, replace with actual data you receive from Midtrans\nlet notificationPayload = \"{\\\"originalPartnerReferenceNo\\\":\\\"GP24043015193402809\\\",\\\"originalReferenceNo\\\":\\\"A120240430081940S9vu8gSjaRID\\\",\\\"merchantId\\\":\\\"G099333790\\\",\\\"amount\\\":{\\\"value\\\":\\\"102800.00\\\",\\\"currency\\\":\\\"IDR\\\"},\\\"latestTransactionStatus\\\":\\\"00\\\",\\\"transactionStatusDesc\\\":\\\"SUCCESS\\\",\\\"additionalInfo\\\":{\\\"refundHistory\\\":[]}}\";\n\n// To get the signature value, you need to retrieve it from the webhook header called X-Signature\nlet signature = \"CgjmAyC9OZ3pB2JhBRDihL939kS86LjP1VLD1R7LgI4JkvYvskUQrPXgjhrZqU2SFkfPmLtSbcEUw21pg2nItQ0KoX582Y6Tqg4Mn45BQbxo4LTPzkZwclD4WI+aCYePQtUrXpJSTM8D32lSJQQndlloJfzoD6Rh24lNb+zjUpc+YEi4vMM6MBmS26PpCm/7FZ7/OgsVh9rlSNUsuQ/1QFpldA0F8bBNWSW4trwv9bE1NFDzliHrRAnQXrT/J3chOg5qqH0+s3E6v/W21hIrBYZVDTppyJPtTOoCWeuT1Tk9XI2HhSDiSuI3pevzLL8FLEWY/G4M5zkjm/9056LTDw==\";\n\n// To get the timeStamp value, you need to retrieve it from the webhook header called X-Timestamp\nlet timeStamp = \"2024-10-07T15:45:22+07:00\";\n\n// The url path is based on the webhook url of the payment method for example for direct debit is `/v1.0/debit/notify`\nlet notificationUrlPath = \"/v1.0/debit/notify\";\n/**\n * Example verifying the webhook notification\n */\nlet isVerified = midtransClient.SnapBi.notification()\n        .withNotificationPayload(notificationPayload)\n        .withSignature(signature)\n        .withTimeStamp(timeStamp)\n        .withNotificationUrlPath(notificationUrlPath)\n        .isWebhookNotificationVerified()\n```\n## Examples\nExamples are available on [/examples](/examples) folder.\nThere are:\n- [Core Api examples](/examples/coreApi)\n- [Snap examples](/examples/snap)\n- [Express App examples](/examples/expressApp) that implement Snap, Core Api \u0026 SnapBi\n- [Snap Bi examples](/examples/expressApp/SnapBi)\n\n\u003c!-- @TODO: document ## 5. IRIS --\u003e\n\n## Notes\n\n#### Not Designed for Frontend Usage\nThis library/package is mainly **NOT FOR FRONTEND** (Browser's javascript) usage, but for backend (Node JS server) usage:\n- This is mainly for backend usage, to do **secure server-to-server/backend-to-backend API call**.\n- You may/will encounter **CORS issue if you are using** this to do API request **from frontend**.\n- Your API **ServerKey may also be exposed to public** if you are using this **on frontend**.\n- If what you need is to display Snap payment page on your frontend, please [follow this official documentation](https://docs.midtrans.com/en/snap/integration-guide?id=_2-displaying-snap-payment-page-on-frontend)\n    - If you are using [ReactJS follow this recommendation](https://docs.midtrans.com/docs/technical-faq#my-developer-uses-react-js-frontend-framework-and-is-unable-to-use-midtransminjssnapjs-what-should-i-do).\n\n## Get help\n\n* [Midtrans Docs](https://docs.midtrans.com)\n* [Midtrans Dashboard ](https://dashboard.midtrans.com/)\n* [SNAP documentation](http://snap-docs.midtrans.com)\n* [Core API documentation](http://api-docs.midtrans.com)\n* Can't find answer you looking for? email to [support@midtrans.com](mailto:support@midtrans.com)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidtrans%2Fmidtrans-nodejs-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmidtrans%2Fmidtrans-nodejs-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidtrans%2Fmidtrans-nodejs-client/lists"}