node-wipay
Version:
This is a node wrapper for the WiPay Caribbean V1 API.
131 lines • 4.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var config_1 = require("../config");
var WiPayTransactions = require('wipay-transaction');
/**
* Authorisation Class
* @param {WiPayAuthConfig} config
* @return {WiPayAuth}
*/
var WiPayAuth = /** @class */ (function () {
/**
* Authorisation Constructor
* This function is private to allow for Singleton design.
* @param {WiPayAuthConfig} config
*/
function WiPayAuth(config, payments) {
var _this = this;
/**
* Verify Hashsum
* This function verifies that the hashsum returned from the Gateway Request was valid.
* @param {WiPayGateWayResponse} response The response from the WiPay Gateway request.
*/
this.verify = function (response) {
return WiPayTransactions(response).verifyHash(_this.Config.ApiKey);
};
WiPayAuth._Payments = payments;
WiPayAuth._config = config;
WiPayAuth._endpoint = config.LiveMode !== false ? config_1.API.Live : config_1.API.Sandbox;
if (WiPayAuth._Payments)
WiPayAuth._gateway = config.LiveMode !== false ? config_1.Gateway.Live : config_1.Gateway.Sandbox;
else
WiPayAuth._gateway = config.LiveMode !== false ? config_1.Gateway2.Live : config_1.Gateway2.Sandbox;
WiPayAuth._LiveMode = config.LiveMode !== false ? true : false;
}
Object.defineProperty(WiPayAuth.prototype, "LiveMode", {
/**
* Live Mode
* This function returns whether or not the authorisation module will use
* the live or sandbox API endpoint.
* @return {boolean}
*/
get: function () {
return WiPayAuth._LiveMode;
},
/**
* Live Mode
* This function will set the LiveMode, for the authorisation module to use
* the live or sandbox API endpoint.
* @param {boolean} isLive
*/
set: function (isLive) {
WiPayAuth._LiveMode = isLive;
WiPayAuth._endpoint = isLive ? config_1.API.Live : config_1.API.Sandbox;
if (this.Payments)
WiPayAuth._gateway = isLive ? config_1.Gateway.Live : config_1.Gateway.Sandbox;
else
WiPayAuth._gateway = isLive ? config_1.Gateway2.Live : config_1.Gateway2.Sandbox;
},
enumerable: false,
configurable: true
});
Object.defineProperty(WiPayAuth.prototype, "Config", {
/**
* Config
* This function returns the configuration of this authorisation module.
* @return {WiPayAuthConfig}
*/
get: function () {
return WiPayAuth._config;
},
enumerable: false,
configurable: true
});
Object.defineProperty(WiPayAuth.prototype, "Endpoint", {
/**
* Endpoint
* This function returns the API endpoint currently used by the
* authorisation module.
* @return {string}
*/
get: function () {
return WiPayAuth._endpoint;
},
enumerable: false,
configurable: true
});
Object.defineProperty(WiPayAuth.prototype, "Gateway", {
/**
* Gateway
* This function returns the API Credit Card Gateway Endpoint currently
* used by the authorisation module.
*/
get: function () {
return WiPayAuth._gateway;
},
enumerable: false,
configurable: true
});
Object.defineProperty(WiPayAuth.prototype, "Payments", {
get: function () {
return WiPayAuth._Payments;
},
set: function (usePayments) {
WiPayAuth._Payments = usePayments;
if (this.Payments)
WiPayAuth._gateway = this.LiveMode ? config_1.Gateway.Live : config_1.Gateway.Sandbox;
else
WiPayAuth._gateway = this.LiveMode ? config_1.Gateway2.Live : config_1.Gateway2.Sandbox;
},
enumerable: false,
configurable: true
});
/**
* Get Authorisation Instance
* @param {WiPayAuthConfig} config
* @return {WiPayAuth}
*/
WiPayAuth.getInstance = function (config, payments) {
if (config === void 0) { config = null; }
if (payments === void 0) { payments = false; }
if (WiPayAuth._instance) {
return WiPayAuth._instance;
}
if (config === null || config === undefined)
throw new Error("Cannot instantiate the authorisation with a null configuration.");
return WiPayAuth._instance = new WiPayAuth(config, payments);
};
return WiPayAuth;
}());
exports.default = WiPayAuth;
//# sourceMappingURL=index.js.map