mastercard-hosted-session
Version:
Wrapper around Mastercard hosted session, allowing you to treat it as a modern Promise-based Javascript API.
58 lines (48 loc) • 1.86 kB
JavaScript
;
require("core-js/modules/es.object.define-property");
require("core-js/modules/es.object.to-string");
require("core-js/modules/es.promise");
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "HostedSessionError", {
enumerable: true,
get: function get() {
return _hostedSession.HostedSessionError;
}
});
exports.default = void 0;
var _hostedSession = require("./hosted-session");
/**
* Resolves a configured and initialised Hosted Session wrapper. You can use
* this wrapper object to get reliably-ordered multiple calls to the
* sessionisation API.
* @param merchantId Your Mastercard-provided merchant ID
* @param config all PaymentSession config options *other* than callbacks
* @param [paymentSession] optional injection of the PaymentSession global
*
* @return Promise that will resolve to an initialised Hosted Session, or reject
* if the session cannot be initialised.
*/
var getHostedSession = function getHostedSession(_ref) {
var config = _ref.config,
paymentSession = _ref.paymentSession;
return configureSession(paymentSession || global.PaymentSession, config);
};
var sessionInstance;
/**
* Singleton accessor for Hosted Session. Initialises the session against a
* payment form, or returns the already initialised form wrapper.
* @param paymentSession PaymentSession instance from the mastercard API
* @param config all PaymentSession config options *other* than callbacks
* @returns {Promise<HostedSession>}
*/
var configureSession = function configureSession(paymentSession, config) {
if (sessionInstance) {
return Promise.resolve(sessionInstance);
}
sessionInstance = new _hostedSession.HostedSession(paymentSession, config);
return sessionInstance.initialize();
};
var _default = getHostedSession;
exports.default = _default;