UNPKG

@test-org122/merchant-iframe

Version:

Mediator iFrame package. This is used to sandbox the connector code away from the running hypernet core.

36 lines 2.09 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MerchantIframe = void 0; const PostmateApi_1 = __importDefault(require("@merchant-iframe/implementations/api/PostmateApi")); const data_1 = require("@merchant-iframe/implementations/data"); const utils_1 = require("@merchant-iframe/implementations/utils"); const MerchantService_1 = require("@merchant-iframe/implementations/business/MerchantService"); const utils_2 = require("@test-org122/utils"); class MerchantIframe { constructor() { // First step, get the mediator URL from the iframe params const urlParams = new URLSearchParams(window.location.search); const merchantUrl = urlParams.get("merchantUrl"); if (merchantUrl == null) { throw new Error("Must provide merchantURL parameter!"); } // Instantiate all the pieces this.contextProvider = new utils_1.ContextProvider(new URL(merchantUrl)); this.ajaxUtils = new utils_2.AxiosAjaxUtils(); this.merchantConnectorRepository = new data_1.MerchantConnectorRepository(this.ajaxUtils); this.merchantService = new MerchantService_1.MerchantService(this.merchantConnectorRepository, this.contextProvider); this.merchantIframeApi = new PostmateApi_1.default(this.merchantService, this.contextProvider); // Since this iframe is supposed to host a merchant connector, first things first, let's validate the merchant's connector this.merchantService.validateMerchantConnector().andThen(() => { // We're ready to answer questions about the connector, we can activate the API // Note, it would be better to have a waitForValidated() function down lower so that the API // can be activated immediately. return this.merchantIframeApi.activateModel(); }); } } exports.MerchantIframe = MerchantIframe; //# sourceMappingURL=MerchantIFrame.js.map