UNPKG

ts-midtrans-client

Version:

This library is an UNOFFICIAL TypeScript version of the Midtrans Client - Node.js.

139 lines (138 loc) 7.84 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); const apiConfig_1 = require("./apiConfig"); const httpClient_1 = require("./httpClient"); const transaction_1 = require("./transaction"); /** * CoreApi object able to do API request to Midtrans Core API */ class CoreApi { /** * Initiate with options * @param {Object} options - should have these props: * isProduction, serverKey, clientKey */ constructor(options) { this.apiConfig = new apiConfig_1.ApiConfig(options); this.httpClient = new httpClient_1.HttpClient(this); this.transaction = new transaction_1.Transaction(this); } /** * Do `/v2/charge` API request to Core API * @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) * @return {Promise} - Promise contains Object from JSON decoded response */ charge(parameter = {}) { const apiUrl = `${this.apiConfig.getCoreApiBaseUrl()}/v2/charge`; return this.httpClient.request('post', this.apiConfig.get().serverKey, apiUrl, parameter); } /** * Do `/v2/capture` API request to Core API * @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) * @return {Promise} - Promise contains Object from JSON decoded response */ capture(parameter = {}) { const apiUrl = `${this.apiConfig.getCoreApiBaseUrl()}/v2/capture`; return this.httpClient.request('post', this.apiConfig.get().serverKey, apiUrl, parameter); } /** * Do `/v2/card/register` API request to Core API * @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) * @return {Promise} - Promise contains Object from JSON decoded response */ cardRegister(parameter = {}) { const apiUrl = `${this.apiConfig.getCoreApiBaseUrl()}/v2/card/register`; return this.httpClient.request('get', this.apiConfig.get().serverKey, apiUrl, parameter); } /** * Do `/v2/token` API request to Core API * @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) * @return {Promise} - Promise contains Object from JSON decoded response */ cardToken(parameter = {}) { const apiUrl = `${this.apiConfig.getCoreApiBaseUrl()}/v2/token`; return this.httpClient.request('get', this.apiConfig.get().serverKey, apiUrl, parameter); } /** * Do `/v2/point_inquiry/<tokenId>` API request to Core API * @param {String} tokenId - tokenId of credit card (more params detail refer to: https://api-docs.midtrans.com) * @return {Promise} - Promise contains Object from JSON decoded response */ cardPointInquiry(tokenId) { const apiUrl = `${this.apiConfig.getCoreApiBaseUrl()}/v2/point_inquiry/${tokenId}`; return this.httpClient.request('get', this.apiConfig.get().serverKey, apiUrl, undefined); } /** * Create `/v2/pay/account` API request to Core API * @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/#create-pay-account) * @return {Promise} - Promise contains Object from JSON decoded response */ linkPaymentAccount(parameter = {}) { const apiUrl = `${this.apiConfig.getCoreApiBaseUrl()}/v2/pay/account`; return this.httpClient.request('post', this.apiConfig.get().serverKey, apiUrl, parameter); } /** * Do `/v2/pay/account/<accountId>` API request to Core API * @param {String} accountId - accountId for specific payment channel (more params detail refer to: https://api-docs.midtrans.com/#get-pay-account) * @return {Promise} - Promise contains Object from JSON decoded response */ getPaymentAccount(accountId) { const apiUrl = `${this.apiConfig.getCoreApiBaseUrl()}/v2/pay/account/${accountId}`; return this.httpClient.request('get', this.apiConfig.get().serverKey, apiUrl, undefined); } /** * Unbind `/v2/pay/account/<accountId>/unbind` API request to Core API * @param {String} accountId - accountId for specific payment channel (more params detail refer to: https://api-docs.midtrans.com/#unbind-pay-account) * @return {Promise} - Promise contains Object from JSON decoded response */ unlinkPaymentAccount(accountId) { const apiUrl = `${this.apiConfig.getCoreApiBaseUrl()}/v2/pay/account/${accountId}/unbind`; return this.httpClient.request('post', this.apiConfig.get().serverKey, apiUrl, undefined); } /** * Create `/v1/subscription` API request to Core API * @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/#create-subscription) * @return {Promise} - Promise contains Object from JSON decoded response */ createSubscription(parameter = {}) { const apiUrl = `${this.apiConfig.getCoreApiBaseUrl()}/v1/subscriptions`; return this.httpClient.request('post', this.apiConfig.get().serverKey, apiUrl, parameter); } /** * Do `/v1/subscription/<subscriptionId>` API request to Core API * @param {String} subscriptionId - subscriptionId given by Midtrans (more params detail refer to: https://api-docs.midtrans.com/#get-subscription) * @return {Promise} - Promise contains Object from JSON decoded response */ getSubscription(subscriptionId) { const apiUrl = `${this.apiConfig.getCoreApiBaseUrl()}/v1/subscriptions/${subscriptionId}`; return this.httpClient.request('get', this.apiConfig.get().serverKey, apiUrl, undefined); } /** * Do `/v1/subscription/<subscriptionId>/disable` API request to Core API * @param {String} subscriptionId - subscriptionId given by Midtrans (more params detail refer to: https://api-docs.midtrans.com/#disable-subscription) * @return {Promise} - Promise contains Object from JSON decoded response */ disableSubscription(subscriptionId) { const apiUrl = `${this.apiConfig.getCoreApiBaseUrl()}/v1/subscriptions/${subscriptionId}/disable`; return this.httpClient.request('post', this.apiConfig.get().serverKey, apiUrl, undefined); } /** * Do `/v1/subscription/<subscriptionId>/enable` API request to Core API * @param {String} subscriptionId - subscriptionId given by Midtrans (more params detail refer to: https://api-docs.midtrans.com/#enable-subscription) * @return {Promise} - Promise contains Object from JSON decoded response */ enableSubscription(subscriptionId) { const apiUrl = `${this.apiConfig.getCoreApiBaseUrl()}/v1/subscriptions/${subscriptionId}/enable`; return this.httpClient.request('post', this.apiConfig.get().serverKey, apiUrl, undefined); } /** * Do update subscription `/v1/subscription/<subscriptionId>` API request to Core API * @param {String} subscriptionId - subscriptionId given by Midtrans (more params detail refer to: https://api-docs.midtrans.com/#update-subscription) * @return {Promise} - Promise contains Object from JSON decoded response */ updateSubscription(subscriptionId, parameter = {}) { const apiUrl = `${this.apiConfig.getCoreApiBaseUrl()}/v1/subscriptions/${subscriptionId}`; return this.httpClient.request('patch', this.apiConfig.get().serverKey, apiUrl, parameter); } } exports.default = CoreApi;