UNPKG

braintree-web

Version:

A suite of tools for integrating Braintree in the browser

55 lines (38 loc) 1.22 kB
"use strict"; var BraintreeError = require("../../../braintree-error"); var errors = require("../../shared/errors"); function noop() {} function PopupBridge(options) { this._closed = null; this._options = options; } PopupBridge.prototype.initialize = function (callback) { var self = this; window.popupBridge.onComplete = function (err, payload) { var popupDismissed = !payload && !err; self._closed = true; if (err || popupDismissed) { // User clicked "Done" button of browser view callback(new BraintreeError(errors.FRAME_SERVICE_FRAME_CLOSED)); return; } // User completed popup flow (includes success and cancel cases) callback(null, payload); }; }; PopupBridge.prototype.open = function (options) { var url; options = options || {}; url = options.openFrameUrl || this._options.openFrameUrl; this._closed = false; window.popupBridge.open(url); }; PopupBridge.prototype.focus = noop; PopupBridge.prototype.close = noop; PopupBridge.prototype.isClosed = function () { return Boolean(this._closed); }; PopupBridge.prototype.redirect = function (redirectUrl) { this.open({ openFrameUrl: redirectUrl }); }; module.exports = PopupBridge;