ts-midtrans-client
Version:
This library is an UNOFFICIAL TypeScript version of the Midtrans Client - Node.js.
98 lines (97 loc) • 3.84 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiConfig = void 0;
const _ = __importStar(require("lodash"));
/**
* Config Object that is used to store isProduction, serverKey, clientKey,
* and also API base URLs.
*/
class ApiConfig {
constructor(options = { isProduction: false, serverKey: '', clientKey: '' }) {
var _a;
this.isProduction = (_a = options.isProduction) !== null && _a !== void 0 ? _a : false;
this.serverKey = options.serverKey;
this.clientKey = options.clientKey;
this.set(options);
}
/**
* Return config stored
* @return {Object} object contains isProduction, serverKey, clientKey
*/
get() {
return {
isProduction: this.isProduction,
serverKey: this.serverKey,
clientKey: this.clientKey,
};
}
/**
* Set config stored
* @param {Object} options - object contains isProduction, serverKey, clientKey
*/
set(options) {
const parsedOptions = _.pick(options, ['isProduction', 'serverKey', 'clientKey']);
const mergedConfig = _.merge({}, { isProduction: this.isProduction, serverKey: this.serverKey, clientKey: this.clientKey }, parsedOptions);
this.isProduction = mergedConfig.isProduction;
this.serverKey = mergedConfig.serverKey;
this.clientKey = mergedConfig.clientKey;
}
/**
* @return {String} core api base url
*/
getCoreApiBaseUrl() {
return this.isProduction ? ApiConfig.CORE_PRODUCTION_BASE_URL : ApiConfig.CORE_SANDBOX_BASE_URL;
}
/**
* @return {String} snap api base url
*/
getSnapApiBaseUrl() {
return this.isProduction ? ApiConfig.SNAP_PRODUCTION_BASE_URL : ApiConfig.SNAP_SANDBOX_BASE_URL;
}
/**
* @return {String} Iris api base url
*/
getIrisApiBaseUrl() {
return this.isProduction ? ApiConfig.IRIS_PRODUCTION_BASE_URL : ApiConfig.IRIS_SANDBOX_BASE_URL;
}
}
exports.ApiConfig = ApiConfig;
ApiConfig.CORE_SANDBOX_BASE_URL = 'https://api.sandbox.midtrans.com';
ApiConfig.CORE_PRODUCTION_BASE_URL = 'https://api.midtrans.com';
ApiConfig.SNAP_SANDBOX_BASE_URL = 'https://app.sandbox.midtrans.com/snap/v1';
ApiConfig.SNAP_PRODUCTION_BASE_URL = 'https://app.midtrans.com/snap/v1';
ApiConfig.IRIS_SANDBOX_BASE_URL = 'https://app.sandbox.midtrans.com/iris/api/v1';
ApiConfig.IRIS_PRODUCTION_BASE_URL = 'https://app.midtrans.com/iris/api/v1';