@paydock/client-sdk 1.79.2-beta → 1.80.13-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/README.md +167 -25
  2. package/bundles/widget.umd.js +1103 -676
  3. package/bundles/widget.umd.min.js +1 -1
  4. package/lib/canvas-3ds/services/gpayments-service.d.ts +2 -3
  5. package/lib/canvas-3ds/services/gpayments-service.js +26 -13
  6. package/lib/canvas-3ds/services/gpayments-service.js.map +1 -1
  7. package/lib/canvas-3ds/services/standalone3ds-service.d.ts +1 -1
  8. package/lib/checkout-button/{afterpay-checkout-button.d.ts → afterpay/afterpay-checkout-button.d.ts} +2 -2
  9. package/lib/checkout-button/{afterpay-checkout-button.js → afterpay/afterpay-checkout-button.js} +4 -4
  10. package/lib/checkout-button/afterpay/afterpay-checkout-button.js.map +1 -0
  11. package/lib/checkout-button/{afterpay.runner.d.ts → afterpay/afterpay.runner.d.ts} +4 -5
  12. package/lib/checkout-button/{afterpay.runner.js → afterpay/afterpay.runner.js} +11 -10
  13. package/lib/checkout-button/afterpay/afterpay.runner.js.map +1 -0
  14. package/lib/checkout-button/checkout-button.d.ts +41 -50
  15. package/lib/checkout-button/checkout-button.interface.d.ts +48 -0
  16. package/lib/checkout-button/checkout-button.interface.js +45 -0
  17. package/lib/checkout-button/checkout-button.interface.js.map +1 -0
  18. package/lib/checkout-button/checkout-button.js +126 -127
  19. package/lib/checkout-button/checkout-button.js.map +1 -1
  20. package/lib/checkout-button/checkout-contextual-handler.d.ts +22 -0
  21. package/lib/checkout-button/checkout-contextual-handler.js +75 -0
  22. package/lib/checkout-button/checkout-contextual-handler.js.map +1 -0
  23. package/lib/checkout-button/index.d.ts +4 -4
  24. package/lib/checkout-button/index.js +4 -4
  25. package/lib/checkout-button/index.js.map +1 -1
  26. package/lib/checkout-button/{paypal-checkout-button.d.ts → paypal/paypal-checkout-button.d.ts} +1 -1
  27. package/lib/checkout-button/{paypal-checkout-button.js → paypal/paypal-checkout-button.js} +3 -3
  28. package/lib/checkout-button/paypal/paypal-checkout-button.js.map +1 -0
  29. package/lib/checkout-button/{paypal.runner.d.ts → paypal/paypal.runner.d.ts} +2 -3
  30. package/lib/checkout-button/paypal/paypal.runner.js +14 -0
  31. package/lib/checkout-button/paypal/paypal.runner.js.map +1 -0
  32. package/lib/checkout-button/runner/base.runner.d.ts +17 -0
  33. package/lib/checkout-button/runner/base.runner.js +13 -0
  34. package/lib/checkout-button/runner/base.runner.js.map +1 -0
  35. package/lib/checkout-button/runner/contextual.runner.d.ts +37 -0
  36. package/lib/checkout-button/runner/contextual.runner.js +40 -0
  37. package/lib/checkout-button/runner/contextual.runner.js.map +1 -0
  38. package/lib/checkout-button/runner/index.d.ts +8 -0
  39. package/lib/checkout-button/runner/index.js +11 -0
  40. package/lib/checkout-button/runner/index.js.map +1 -0
  41. package/lib/checkout-button/runner/popup.runner.d.ts +34 -0
  42. package/lib/checkout-button/{popup.runner.js → runner/popup.runner.js} +6 -7
  43. package/lib/checkout-button/runner/popup.runner.js.map +1 -0
  44. package/lib/checkout-button/runner/redirect.runner.d.ts +16 -0
  45. package/lib/checkout-button/runner/redirect.runner.js +15 -0
  46. package/lib/checkout-button/runner/redirect.runner.js.map +1 -0
  47. package/lib/checkout-button/{zipmoney-checkout-button.d.ts → zipmoney/zipmoney-checkout-button.d.ts} +20 -3
  48. package/lib/checkout-button/zipmoney/zipmoney-checkout-button.js +62 -0
  49. package/lib/checkout-button/zipmoney/zipmoney-checkout-button.js.map +1 -0
  50. package/lib/checkout-button/zipmoney/zipmoney-contextual.runner.d.ts +38 -0
  51. package/lib/checkout-button/zipmoney/zipmoney-contextual.runner.js +78 -0
  52. package/lib/checkout-button/zipmoney/zipmoney-contextual.runner.js.map +1 -0
  53. package/lib/checkout-button/zipmoney/zipmoney-redirect.runner.d.ts +25 -0
  54. package/lib/checkout-button/zipmoney/zipmoney-redirect.runner.js +41 -0
  55. package/lib/checkout-button/zipmoney/zipmoney-redirect.runner.js.map +1 -0
  56. package/lib/checkout-button/zipmoney/zipmoney.config.d.ts +3 -0
  57. package/lib/checkout-button/zipmoney/zipmoney.config.js +4 -0
  58. package/lib/checkout-button/zipmoney/zipmoney.config.js.map +1 -0
  59. package/lib/checkout-button/zipmoney/zipmoney.runner.d.ts +9 -0
  60. package/lib/checkout-button/zipmoney/zipmoney.runner.js +23 -0
  61. package/lib/checkout-button/zipmoney/zipmoney.runner.js.map +1 -0
  62. package/lib/checkout-button/zipmoney/zipmoney.types.d.ts +11 -0
  63. package/lib/checkout-button/zipmoney/zipmoney.types.js +1 -0
  64. package/lib/checkout-button/zipmoney/zipmoney.types.js.map +1 -0
  65. package/lib/components/dispatcher.js +2 -2
  66. package/lib/components/dispatcher.js.map +1 -1
  67. package/lib/components/param.d.ts +9 -2
  68. package/lib/components/param.js +3 -0
  69. package/lib/components/param.js.map +1 -1
  70. package/lib/components/popup.js +1 -1
  71. package/lib/components/popup.js.map +1 -1
  72. package/lib/components/storage-dispatcher.d.ts +20 -0
  73. package/lib/components/storage-dispatcher.js +49 -0
  74. package/lib/components/storage-dispatcher.js.map +1 -0
  75. package/lib/external-checkout/builder.d.ts +2 -2
  76. package/lib/external-checkout/builder.js +3 -3
  77. package/lib/external-checkout/builder.js.map +1 -1
  78. package/lib/external-checkout/checker.d.ts +1 -1
  79. package/lib/external-checkout/checker.js +2 -2
  80. package/lib/external-checkout/checker.js.map +1 -1
  81. package/lib/helper/event-emitter.d.ts +1 -1
  82. package/lib/helper/event-emitter.js.map +1 -1
  83. package/lib/wallet-buttons/afterpay.wallet-service.d.ts +28 -0
  84. package/lib/wallet-buttons/afterpay.wallet-service.js +137 -0
  85. package/lib/wallet-buttons/afterpay.wallet-service.js.map +1 -0
  86. package/lib/wallet-buttons/interfaces.d.ts +16 -1
  87. package/lib/wallet-buttons/wallet-buttons.d.ts +8 -5
  88. package/lib/wallet-buttons/wallet-buttons.js +12 -5
  89. package/lib/wallet-buttons/wallet-buttons.js.map +1 -1
  90. package/package.json +3 -2
  91. package/slate.md +31 -1
  92. package/vendors/zipmoney.d.ts +11 -4
  93. package/lib/checkout-button/afterpay-checkout-button.js.map +0 -1
  94. package/lib/checkout-button/afterpay.runner.js.map +0 -1
  95. package/lib/checkout-button/paypal-checkout-button.js.map +0 -1
  96. package/lib/checkout-button/paypal.runner.js +0 -13
  97. package/lib/checkout-button/paypal.runner.js.map +0 -1
  98. package/lib/checkout-button/popup.runner.d.ts +0 -19
  99. package/lib/checkout-button/popup.runner.js.map +0 -1
  100. package/lib/checkout-button/runner.d.ts +0 -43
  101. package/lib/checkout-button/runner.js +0 -44
  102. package/lib/checkout-button/runner.js.map +0 -1
  103. package/lib/checkout-button/zipmoney-checkout-button.js +0 -36
  104. package/lib/checkout-button/zipmoney-checkout-button.js.map +0 -1
  105. package/lib/checkout-button/zipmoney.runner.d.ts +0 -25
  106. package/lib/checkout-button/zipmoney.runner.js +0 -94
  107. package/lib/checkout-button/zipmoney.runner.js.map +0 -1
  108. package/lib/gateway/index.d.ts +0 -6
  109. package/lib/gateway/index.js +0 -7
  110. package/lib/gateway/index.js.map +0 -1
  111. package/lib/gateway/info.d.ts +0 -17
  112. package/lib/gateway/info.js +0 -27
  113. package/lib/gateway/info.js.map +0 -1
  114. package/lib/widget/external-checkout.d.ts +0 -0
  115. package/lib/widget/external-checkout.js +0 -1
  116. package/lib/widget/external-checkout.js.map +0 -1
  117. package/lib/widget/payment-source-token.d.ts +0 -0
  118. package/lib/widget/payment-source-token.js +0 -1
  119. package/lib/widget/payment-source-token.js.map +0 -1
@@ -532,6 +532,7 @@
532
532
  WALLET_GATEWAY["FLYPAY"] = "Flypay";
533
533
  WALLET_GATEWAY["PAYPAL"] = "Paypal";
534
534
  WALLET_GATEWAY["MASTERCARD"] = "MasterCard";
535
+ WALLET_GATEWAY["AFTERPAY"] = "Afterpay";
535
536
  })(WALLET_GATEWAY || (WALLET_GATEWAY = {}));
536
537
  var WALLET_TYPE;
537
538
  (function (WALLET_TYPE) {
@@ -539,6 +540,7 @@
539
540
  WALLET_TYPE["APPLE"] = "apple";
540
541
  WALLET_TYPE["FLYPAY"] = "flypay";
541
542
  WALLET_TYPE["PAYPAL"] = "paypal";
543
+ WALLET_TYPE["AFTERPAY"] = "afterpay";
542
544
  })(WALLET_TYPE || (WALLET_TYPE = {}));
543
545
 
544
546
  /**
@@ -2390,6 +2392,51 @@
2390
2392
  return HtmlWidget;
2391
2393
  }(HtmlMultiWidget);
2392
2394
 
2395
+ /**
2396
+ * @type {object}
2397
+ * @param {string} CLICK=click
2398
+ * @param {string} POPUP_REDIRECT=popup_redirect
2399
+ * @param {string} ERROR=error
2400
+ * @param {string} ACCEPTED=accepted
2401
+ * @param {string} FINISH=finish
2402
+ * @param {string} CLOSE=close
2403
+ */
2404
+ var CHECKOUT_BUTTON_EVENT = {
2405
+ CLICK: 'click',
2406
+ POPUP_REDIRECT: 'popupRedirect',
2407
+ REDIRECT: 'redirect',
2408
+ ERROR: 'error',
2409
+ REFERRED: 'referred',
2410
+ DECLINED: 'declined',
2411
+ CANCELLED: 'cancelled',
2412
+ ACCEPTED: 'accepted',
2413
+ FINISH: 'finish',
2414
+ CLOSE: 'close'
2415
+ };
2416
+ /**
2417
+ * @type {object}
2418
+ * @param {string} CONTEXTUAL=contextual
2419
+ * @param {string} REDIRECT=redirect
2420
+ */
2421
+ var CHECKOUT_MODE;
2422
+ (function (CHECKOUT_MODE) {
2423
+ CHECKOUT_MODE["CONTEXTUAL"] = "contextual";
2424
+ CHECKOUT_MODE["REDIRECT"] = "redirect";
2425
+ })(CHECKOUT_MODE || (CHECKOUT_MODE = {}));
2426
+ /**
2427
+ * @type {object}
2428
+ * @param {string} ZIPMONEY=Zipmoney
2429
+ * @param {string} PAYPAL=PaypalClassic
2430
+ * @param {string} AFTERPAY=Afterpay
2431
+ */
2432
+ var GATEWAY_TYPE;
2433
+ (function (GATEWAY_TYPE) {
2434
+ GATEWAY_TYPE["ZIPMONEY"] = "Zipmoney";
2435
+ GATEWAY_TYPE["PAYPAL"] = "PaypalClassic";
2436
+ GATEWAY_TYPE["AFTERPAY"] = "Afterpay";
2437
+ })(GATEWAY_TYPE || (GATEWAY_TYPE = {}));
2438
+ var CHECKOUT_BTN_LOG_PREFIX = '[Paydock:CheckoutButton]';
2439
+
2393
2440
  var HttpCore = function () {
2394
2441
  function HttpCore() {
2395
2442
  classCallCheck(this, HttpCore);
@@ -2473,37 +2520,37 @@
2473
2520
  }
2474
2521
 
2475
2522
  createClass(Builder, [{
2476
- key: "getLink",
2523
+ key: 'getLink',
2477
2524
  value: function getLink() {
2478
2525
  return EXTERNAL_CHECKOUT_LINK;
2479
2526
  }
2480
2527
  }, {
2481
- key: "setDescriptions",
2528
+ key: 'setDescriptions',
2482
2529
  value: function setDescriptions(text) {
2483
2530
  this.body.description = text;
2484
2531
  }
2485
2532
  }, {
2486
- key: "setMeta",
2533
+ key: 'setMeta',
2487
2534
  value: function setMeta(meta) {
2488
2535
  for (var key in meta) {
2489
2536
  if (!meta.hasOwnProperty(key)) continue;
2490
- if (SUPPORTED_CHECKOUT_META_COLLECTION.indexOf(key) !== -1) this.body.meta[key] = meta[key];else console.warn("ExternalCheckout::setMeta: unsupported meta key " + key);
2537
+ if (SUPPORTED_CHECKOUT_META_COLLECTION.indexOf(key) !== -1) this.body.meta[key] = meta[key];else console.warn('ExternalCheckout::setMeta: unsupported meta key ' + key);
2491
2538
  }
2492
2539
  }
2493
2540
  }, {
2494
- key: "getConfigs",
2541
+ key: 'getConfigs',
2495
2542
  value: function getConfigs() {
2496
2543
  return this.body;
2497
2544
  }
2498
2545
  }, {
2499
- key: "send",
2546
+ key: 'send',
2500
2547
  value: function send(publicKey, cb) {
2501
2548
  var errorCb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (err, code) {};
2502
2549
 
2503
2550
  this.create(publicKey, this.getConfigs(), function (data, status) {
2504
2551
  cb(data);
2505
2552
  }, function (err, status) {
2506
- if (typeof err.message === "undefined") errorCb(status + ": unknown error", 'unknown_error');else errorCb(err.message, err.code);
2553
+ if (typeof err.message === 'undefined') errorCb(status + ': unknown error', 'unknown_error');else errorCb(err.message, err.code);
2507
2554
  });
2508
2555
  }
2509
2556
  }]);
@@ -2536,7 +2583,7 @@
2536
2583
  this.get(accessToken, function (data, status) {
2537
2584
  cb(data);
2538
2585
  }, function (err, status) {
2539
- if (typeof err.message === "undefined") errorCb(status + ': unknown error');else errorCb(err.message);
2586
+ if (typeof err.message === 'undefined') errorCb(status + ': unknown error');else errorCb(err.message);
2540
2587
  });
2541
2588
  }
2542
2589
  }]);
@@ -2836,143 +2883,394 @@
2836
2883
  return Background;
2837
2884
  }();
2838
2885
 
2839
- var TYPE = {
2840
- EXTERNAL_CHECKOUT_TOKEN: 'external_checkout_token',
2841
- CHECKOUT_TOKEN: 'checkout_token',
2842
- BANK_ACCOUNT: 'bank_account',
2843
- CARD: 'card'
2844
- };
2845
- var LINK$1 = '/v1/payment_sources/tokens';
2846
- var Builder$1 = function (_HttpCore) {
2847
- inherits(Builder, _HttpCore);
2848
-
2849
- function Builder(gatewayID, body) {
2850
- var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : TYPE.CARD;
2851
- classCallCheck(this, Builder);
2886
+ var BaseRunner = function () {
2887
+ function BaseRunner() {
2888
+ classCallCheck(this, BaseRunner);
2852
2889
 
2853
- var _this = possibleConstructorReturn(this, (Builder.__proto__ || Object.getPrototypeOf(Builder)).call(this));
2890
+ this.widgetEnv = new Env(WIDGET_URL);
2891
+ }
2854
2892
 
2855
- _this.body = {
2856
- gateway_id: gatewayID,
2857
- type: type
2858
- };
2859
- switch (type) {
2860
- case TYPE.CARD:
2861
- case TYPE.BANK_ACCOUNT:
2862
- delete body.gateway_id;
2863
- delete body.type;
2864
- delete body.checkout_token;
2865
- _this.body = _extends(_this.body, body);
2866
- break;
2867
- case TYPE.CHECKOUT_TOKEN:
2868
- case TYPE.EXTERNAL_CHECKOUT_TOKEN:
2869
- _this.body.checkout_token = body;
2870
- break;
2871
- default:
2872
- throw new Error('Unsupported type of PaymentSourceToken');
2893
+ createClass(BaseRunner, [{
2894
+ key: 'error',
2895
+ value: function error(_error, code, callback) {
2896
+ callback(true);
2873
2897
  }
2874
- return _this;
2898
+ }, {
2899
+ key: 'setEnv',
2900
+ value: function setEnv(env, alias) {
2901
+ this.widgetEnv.setEnv(env, alias);
2902
+ }
2903
+ }]);
2904
+ return BaseRunner;
2905
+ }();
2906
+
2907
+ var RUNNER_EVENT;
2908
+ (function (RUNNER_EVENT) {
2909
+ RUNNER_EVENT["SUCCESS"] = "success";
2910
+ RUNNER_EVENT["DECLINED"] = "declined";
2911
+ RUNNER_EVENT["CLOSE"] = "close";
2912
+ RUNNER_EVENT["REFERRED"] = "referred";
2913
+ RUNNER_EVENT["ERROR"] = "error";
2914
+ })(RUNNER_EVENT || (RUNNER_EVENT = {}));
2915
+ function ContextualRunner() {
2916
+ var Runner = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : BaseRunner;
2917
+
2918
+ return function (_Runner) {
2919
+ inherits(_class, _Runner);
2920
+
2921
+ function _class() {
2922
+ var _ref;
2923
+
2924
+ classCallCheck(this, _class);
2925
+
2926
+ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
2927
+ args[_key] = arguments[_key];
2928
+ }
2929
+
2930
+ var _this = possibleConstructorReturn(this, (_ref = _class.__proto__ || Object.getPrototypeOf(_class)).call.apply(_ref, [this].concat(args)));
2931
+
2932
+ _this.background = new Background();
2933
+ _this.background.onTrigger(TRIGGER$1.FOCUS, function () {
2934
+ return _this.continue();
2935
+ });
2936
+ _this.background.onTrigger(TRIGGER$1.CLOSE, function () {
2937
+ return _this.stop();
2938
+ });
2939
+ return _this;
2940
+ }
2941
+
2942
+ createClass(_class, [{
2943
+ key: 'continue',
2944
+ value: function _continue() {}
2945
+ }, {
2946
+ key: 'stop',
2947
+ value: function stop() {}
2948
+ }, {
2949
+ key: 'error',
2950
+ value: function error(_error, code, callback) {
2951
+ callback(true);
2952
+ }
2953
+ }, {
2954
+ key: 'setSuspendedRedirectUri',
2955
+ value: function setSuspendedRedirectUri(uri) {
2956
+ this.suspendedRedirectUri = uri;
2957
+ }
2958
+ }, {
2959
+ key: 'setBackgroundTitle',
2960
+ value: function setBackgroundTitle(text) {
2961
+ this.background.setBackdropTitle(text);
2962
+ }
2963
+ }, {
2964
+ key: 'setBackgroundDescription',
2965
+ value: function setBackgroundDescription(text) {
2966
+ this.background.setBackdropDescription(text);
2967
+ }
2968
+ }, {
2969
+ key: 'turnOffBackdrop',
2970
+ value: function turnOffBackdrop() {
2971
+ this.background.turnOffControl();
2972
+ this.background.turnOffLoader();
2973
+ }
2974
+ }]);
2975
+ return _class;
2976
+ }(Runner);
2977
+ }
2978
+
2979
+ var DISPATCHER_LINK = '/dispatcher';
2980
+ var DISPATCHER_ELEMENT_ID = 'paydock-dispatcher';
2981
+ var Dispatcher = function () {
2982
+ function Dispatcher(messageSource) {
2983
+ classCallCheck(this, Dispatcher);
2984
+
2985
+ this.messageSource = messageSource;
2986
+ this.env = new Env(WIDGET_URL);
2875
2987
  }
2876
2988
 
2877
- createClass(Builder, [{
2878
- key: 'getLink',
2879
- value: function getLink() {
2880
- return LINK$1;
2989
+ createClass(Dispatcher, [{
2990
+ key: 'restartDispatcher',
2991
+ value: function restartDispatcher() {
2992
+ var dispatcher = document.getElementById(DISPATCHER_ELEMENT_ID);
2993
+ if (dispatcher && dispatcher.parentNode) dispatcher.parentNode.removeChild(dispatcher);
2994
+ var iFrame = document.createElement('iframe');
2995
+ iFrame.setAttribute('src', this.env.getConf().url + DISPATCHER_LINK);
2996
+ iFrame.id = DISPATCHER_ELEMENT_ID;
2997
+ iFrame.style.display = 'none';
2998
+ document.body.appendChild(iFrame);
2881
2999
  }
2882
3000
  }, {
2883
- key: 'send',
2884
- value: function send(accessToken, cb) {
2885
- var errorCb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (err) {};
3001
+ key: 'on',
3002
+ value: function on(name, cb) {
3003
+ var _this = this;
2886
3004
 
2887
- this.create(accessToken, this.getConfigs(), function (data, status) {
2888
- return cb(data);
2889
- }, function (err, status) {
2890
- if (typeof err.message === "undefined") errorCb('unknown error');else errorCb(err.message);
3005
+ Event.subscribe('message', window, function (event) {
3006
+ var data = null;
3007
+ try {
3008
+ data = JSON.parse(event.data);
3009
+ } catch (e) {}
3010
+ if (!data || data.message_source !== _this.messageSource || data.event !== name) return;
3011
+ cb(data);
2891
3012
  });
2892
3013
  }
2893
3014
  }, {
2894
- key: 'getConfigs',
2895
- value: function getConfigs() {
2896
- return this.body;
3015
+ key: 'setEnv',
3016
+ value: function setEnv(env, alias) {
3017
+ this.env.setEnv(env, alias);
3018
+ this.restartDispatcher();
2897
3019
  }
2898
3020
  }]);
2899
- return Builder;
2900
- }(HttpCore);
2901
-
2902
- var EVENT$1 = {
2903
- SUCCESS: 'success',
2904
- DECLINED: 'declined',
2905
- CLOSE: 'close',
2906
- REFERRED: 'referred',
2907
- ERROR: 'error'
2908
- };
2909
-
2910
- var Runner = function () {
2911
- function Runner() {
2912
- var _this = this;
3021
+ return Dispatcher;
3022
+ }();
2913
3023
 
2914
- classCallCheck(this, Runner);
3024
+ var EVENT_CLOSE = 'close';
3025
+ var ERROR_STYLES = "<style>\n .error-wrapper {\n color: #ff0000;\n display: flex;\n justify-content: center;\n align-items: center;\n height: 100%;\n }\n </style>";
3026
+ var ERROR_TEMPLATE = "<div class=\"error-wrapper\"><div>{{error}}</div></div>";
3027
+ var Popup = function () {
3028
+ function Popup() {
3029
+ classCallCheck(this, Popup);
2915
3030
 
2916
- this.customRedirectUti = null;
2917
- this.background = new Background();
2918
- this.background.onTrigger(TRIGGER$1.FOCUS, function () {
2919
- return _this.continue();
2920
- });
2921
- this.background.onTrigger(TRIGGER$1.CLOSE, function () {
2922
- return _this.stop();
2923
- });
2924
- this.widgetEnv = new Env(WIDGET_URL);
3031
+ this.configs = {
3032
+ width: 500,
3033
+ height: 500,
3034
+ scrollbars: true,
3035
+ resizable: true,
3036
+ top: 0,
3037
+ left: 0
3038
+ };
3039
+ this.eventEmitter = new EventEmitter();
2925
3040
  }
2926
3041
 
2927
- createClass(Runner, [{
2928
- key: 'continue',
2929
- value: function _continue() {}
3042
+ createClass(Popup, [{
3043
+ key: "isExist",
3044
+ value: function isExist() {
3045
+ return !!(this.getElement() && !this.getElement().closed);
3046
+ }
2930
3047
  }, {
2931
- key: 'next',
2932
- value: function next(checkoutData, params) {}
3048
+ key: "getElement",
3049
+ value: function getElement() {
3050
+ return this.window;
3051
+ }
2933
3052
  }, {
2934
- key: 'stop',
2935
- value: function stop() {}
3053
+ key: "init",
3054
+ value: function init() {
3055
+ var _this = this;
3056
+
3057
+ if (!Browser.isSupportPopUp()) return this.window = window;
3058
+ var configs = this.getConfigs();
3059
+ this.window = window.open('about:blank', '_blank', "noopener=false,width=" + configs.width + ",height=" + configs.height + ",top=" + configs.top + ",left=" + configs.left + ",scrollbars=" + (configs.scrollbars ? 'yes' : 'no') + ",resizable=" + (configs.resizable ? 'yes' : 'no'));
3060
+ this.showLoader();
3061
+ var timer = setInterval(function () {
3062
+ if (!_this.isExist()) {
3063
+ clearInterval(timer);
3064
+ _this.eventEmitter.emit(EVENT_CLOSE, {});
3065
+ }
3066
+ }, 200);
3067
+ }
2936
3068
  }, {
2937
- key: 'error',
2938
- value: function error(_error, code, callback) {
2939
- callback(true);
3069
+ key: "redirect",
3070
+ value: function redirect(url) {
3071
+ if (!this.isExist()) return;
3072
+ this.window.location.href = url;
2940
3073
  }
2941
3074
  }, {
2942
- key: 'setCustomRedirectUri',
2943
- value: function setCustomRedirectUri(uri) {
2944
- this.customRedirectUti = uri;
3075
+ key: "close",
3076
+ value: function close() {
3077
+ if (!this.isExist() || !this.getElement().close) return;
3078
+ this.getElement().close();
3079
+ this.window = null;
2945
3080
  }
2946
3081
  }, {
2947
- key: 'setEnv',
2948
- value: function setEnv(env, alias) {
2949
- this.widgetEnv.setEnv(env, alias);
3082
+ key: "focus",
3083
+ value: function focus() {
3084
+ if (!this.isExist() || !this.getElement().focus) return;
3085
+ this.getElement().focus();
3086
+ }
3087
+ }, {
3088
+ key: "setConfigs",
3089
+ value: function setConfigs(configs) {
3090
+ this.configs = _extends(this.configs, configs);
2950
3091
  }
2951
3092
  }, {
2952
- key: 'setBackgroundTitle',
2953
- value: function setBackgroundTitle(text) {
2954
- this.background.setBackdropTitle(text);
3093
+ key: "getNetConfigs",
3094
+ value: function getNetConfigs() {
3095
+ return _extends({}, this.configs);
2955
3096
  }
2956
3097
  }, {
2957
- key: 'setBackgroundDescription',
2958
- value: function setBackgroundDescription(text) {
2959
- this.background.setBackdropDescription(text);
3098
+ key: "getConfigs",
3099
+ value: function getConfigs() {
3100
+ var configs = this.getNetConfigs();
3101
+ configs.left = window.screenX + (window.screen.width / 2 - configs.width / 2);
3102
+ configs.top = window.screenY + (window.screen.height / 2 - configs.height / 2);
3103
+ return configs;
2960
3104
  }
2961
3105
  }, {
2962
- key: 'turnOffBackdrop',
2963
- value: function turnOffBackdrop() {
2964
- this.background.turnOffControl();
2965
- this.background.turnOffLoader();
3106
+ key: "onClose",
3107
+ value: function onClose(cb) {
3108
+ this.eventEmitter.subscribe(EVENT_CLOSE, cb);
3109
+ }
3110
+ }, {
3111
+ key: "initError",
3112
+ value: function initError(error) {
3113
+ this.getElement().document.write(".");
3114
+ var body = this.getElement().document.body || this.getElement().document.getElementsByTagName('body')[0];
3115
+ body.innerHTML = ERROR_STYLES + ERROR_TEMPLATE.replace('{{error}}', error);
3116
+ }
3117
+ }, {
3118
+ key: "showLoader",
3119
+ value: function showLoader() {
3120
+ this.getElement().document.write(".");
3121
+ var body = this.getElement().document.body || this.getElement().document.getElementsByTagName('body')[0];
3122
+ body.innerHTML = STYLE$1 + TEMPLATE;
3123
+ if (this.env !== ENV.STAGING || this.env !== ENV.STAGING_1 || this.env !== ENV.STAGING_2 || this.env !== ENV.STAGING_3 || this.env !== ENV.STAGING_4 || this.env !== ENV.STAGING_5 || this.env !== ENV.STAGING_6 || this.env !== ENV.STAGING_7 || this.env !== ENV.STAGING_8 || this.env !== ENV.STAGING_9 || this.env !== ENV.STAGING_10 || this.env !== ENV.STAGING_11 || this.env !== ENV.STAGING_12 || this.env !== ENV.STAGING_13 || this.env !== ENV.STAGING_14 || this.env !== ENV.STAGING_15) return;
3124
+ var clickCount = 0;
3125
+ Event.subscribe('click', body, function () {
3126
+ clickCount++;
3127
+ if (clickCount !== 5) return;
3128
+ body.innerHTML = EXTRA_STYLE + EXTRA_TEMPLATE;
3129
+ });
3130
+ }
3131
+ }, {
3132
+ key: "setEnv",
3133
+ value: function setEnv(env) {
3134
+ this.env = env;
2966
3135
  }
2967
3136
  }]);
2968
- return Runner;
3137
+ return Popup;
2969
3138
  }();
2970
3139
 
2971
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2972
-
2973
- function commonjsRequire () {
2974
- throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
2975
- }
3140
+ var PopupRunner = function (_ContextualRunner) {
3141
+ inherits(PopupRunner, _ContextualRunner);
3142
+
3143
+ function PopupRunner(publicKey) {
3144
+ classCallCheck(this, PopupRunner);
3145
+
3146
+ var _this = possibleConstructorReturn(this, (PopupRunner.__proto__ || Object.getPrototypeOf(PopupRunner)).call(this));
3147
+
3148
+ _this.publicKey = publicKey;
3149
+ _this.checkout = null;
3150
+ _this.dispatcher = new Dispatcher('checkout.paydock');
3151
+ setTimeout(function () {
3152
+ return _this.dispatcher.restartDispatcher();
3153
+ }, 200);
3154
+ _this.popup = new Popup();
3155
+ return _this;
3156
+ }
3157
+
3158
+ createClass(PopupRunner, [{
3159
+ key: 'run',
3160
+ value: function run() {
3161
+ if (this.isRunning()) return;
3162
+ this.popup.init();
3163
+ this.background.initControl();
3164
+ }
3165
+ }, {
3166
+ key: 'isRunning',
3167
+ value: function isRunning() {
3168
+ return this.popup.isExist();
3169
+ }
3170
+ }, {
3171
+ key: 'next',
3172
+ value: function next(checkoutData) {
3173
+ this.checkout = checkoutData;
3174
+ if (!Browser.isSupportPopUp()) window.localStorage.setItem('paydock_checkout_token', JSON.stringify(this.checkout));
3175
+ this.popup.redirect(this.checkout.link);
3176
+ }
3177
+ }, {
3178
+ key: 'continue',
3179
+ value: function _continue() {
3180
+ this.popup.focus();
3181
+ }
3182
+ }, {
3183
+ key: 'stop',
3184
+ value: function stop() {
3185
+ this.popup.close();
3186
+ }
3187
+ }, {
3188
+ key: 'onStop',
3189
+ value: function onStop(cb) {
3190
+ var _this2 = this;
3191
+
3192
+ this.popup.onClose(function () {
3193
+ _this2.background.clear();
3194
+ _this2.checkout = null;
3195
+ cb();
3196
+ });
3197
+ }
3198
+ }, {
3199
+ key: 'onCheckout',
3200
+ value: function onCheckout(event, cb) {
3201
+ var _this3 = this;
3202
+
3203
+ this.dispatcher.on(event, function (data) {
3204
+ if (_this3.checkout && _this3.checkout.reference_id === data.reference_id) {
3205
+ _this3.background.clear();
3206
+ cb(_this3.checkout);
3207
+ } else if (!Browser.isSupportPopUp()) {
3208
+ var item = window.localStorage.getItem('paydock_checkout_token');
3209
+ if (!item) return;
3210
+ var checkout = JSON.parse(item);
3211
+ if (checkout && checkout.reference_id === data.reference_id) {
3212
+ window.localStorage.removeItem('paydock_checkout_token');
3213
+ _this3.checkout = checkout;
3214
+ _this3.background.clear();
3215
+ cb(_this3.checkout);
3216
+ }
3217
+ }
3218
+ });
3219
+ }
3220
+ }, {
3221
+ key: 'setEnv',
3222
+ value: function setEnv(env, alias) {
3223
+ get(PopupRunner.prototype.__proto__ || Object.getPrototypeOf(PopupRunner.prototype), 'setEnv', this).call(this, env, alias);
3224
+ this.dispatcher.setEnv(env, alias);
3225
+ this.popup.setEnv(env);
3226
+ }
3227
+ }]);
3228
+ return PopupRunner;
3229
+ }(ContextualRunner());
3230
+
3231
+ function RedirectRunner() {
3232
+ var Runner = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : BaseRunner;
3233
+
3234
+ return function (_Runner) {
3235
+ inherits(_class, _Runner);
3236
+
3237
+ function _class() {
3238
+ classCallCheck(this, _class);
3239
+ return possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).apply(this, arguments));
3240
+ }
3241
+
3242
+ createClass(_class, [{
3243
+ key: 'setRedirectUrl',
3244
+ value: function setRedirectUrl(url) {
3245
+ this.merchantRedirectUrl = url;
3246
+ }
3247
+ }, {
3248
+ key: 'getRedirectUrl',
3249
+ value: function getRedirectUrl() {
3250
+ return this.merchantRedirectUrl;
3251
+ }
3252
+ }, {
3253
+ key: 'error',
3254
+ value: function error(_error, code, callback) {
3255
+ callback(false);
3256
+ }
3257
+ }]);
3258
+ return _class;
3259
+ }(Runner);
3260
+ }
3261
+
3262
+ function isContextualRunner(runner) {
3263
+ return 'run' in runner;
3264
+ }
3265
+ function isRedirectRunner(runner) {
3266
+ return 'setRedirectUrl' in runner;
3267
+ }
3268
+
3269
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
3270
+
3271
+ function commonjsRequire () {
3272
+ throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
3273
+ }
2976
3274
 
2977
3275
  function unwrapExports (x) {
2978
3276
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -4007,49 +4305,77 @@
4007
4305
 
4008
4306
  unwrapExports(zipmoney);
4009
4307
 
4010
- var ECHO_LINK = '/v1/echo';
4011
- var REDIRECT_URL_SUSPENDED = '/checkout/zipmoney';
4012
- var ZipmoneyRunner = function (_Runner) {
4013
- inherits(ZipmoneyRunner, _Runner);
4308
+ var ECHO_URI = '/v1/echo';
4309
+ var LOG_PREFIX = '[CheckoutButton:Zipmoney]';
4310
+ var ZipmoneyRunner = function (_BaseRunner) {
4311
+ inherits(ZipmoneyRunner, _BaseRunner);
4014
4312
 
4015
- function ZipmoneyRunner(publicKey) {
4313
+ function ZipmoneyRunner() {
4016
4314
  classCallCheck(this, ZipmoneyRunner);
4017
4315
 
4018
4316
  var _this = possibleConstructorReturn(this, (ZipmoneyRunner.__proto__ || Object.getPrototypeOf(ZipmoneyRunner)).call(this));
4019
4317
 
4020
- _this.publicKey = publicKey;
4021
- _this.checkout = null;
4318
+ _this.apiEnv = new Env(API_URL);
4319
+ return _this;
4320
+ }
4321
+
4322
+ createClass(ZipmoneyRunner, [{
4323
+ key: 'setEnv',
4324
+ value: function setEnv(env, alias) {
4325
+ get(ZipmoneyRunner.prototype.__proto__ || Object.getPrototypeOf(ZipmoneyRunner.prototype), 'setEnv', this).call(this, env, alias);
4326
+ this.apiEnv.setEnv(env, alias);
4327
+ }
4328
+ }, {
4329
+ key: 'getCheckoutUri',
4330
+ value: function getCheckoutUri(redirectUri) {
4331
+ return this.apiEnv.getConf().url + ECHO_URI + '?' + Url.serialize({
4332
+ json_body: JSON.stringify({
4333
+ redirect_uri: redirectUri
4334
+ })
4335
+ });
4336
+ }
4337
+ }]);
4338
+ return ZipmoneyRunner;
4339
+ }(BaseRunner);
4340
+
4341
+ var ZIPMONEY_PROXY_REDIRECT_URL = '/checkout/zipmoney/response';
4342
+ var ZIPMONEY_DEFAULT_SUSPENDED_URL = '/checkout/zipmoney/suspended';
4343
+ var ZIPMONEY_MESSAGE_SOURCE = 'zipmoney.checkout.paydock';
4344
+
4345
+ var ZipmoneyContextualRunner = function (_ContextualRunner) {
4346
+ inherits(ZipmoneyContextualRunner, _ContextualRunner);
4347
+
4348
+ function ZipmoneyContextualRunner() {
4349
+ classCallCheck(this, ZipmoneyContextualRunner);
4350
+
4351
+ var _this = possibleConstructorReturn(this, (ZipmoneyContextualRunner.__proto__ || Object.getPrototypeOf(ZipmoneyContextualRunner)).call(this));
4352
+
4022
4353
  _this.runs = false;
4023
4354
  _this.eventEmitter = new EventEmitter();
4024
- _this.echoEnv = new Env(API_URL);
4025
4355
  return _this;
4026
4356
  }
4027
4357
 
4028
- createClass(ZipmoneyRunner, [{
4029
- key: "run",
4358
+ createClass(ZipmoneyContextualRunner, [{
4359
+ key: 'run',
4030
4360
  value: function run() {
4031
4361
  this.runs = true;
4032
4362
  this.background.initLoader();
4033
4363
  }
4034
4364
  }, {
4035
- key: "isRunning",
4365
+ key: 'isRunning',
4036
4366
  value: function isRunning() {
4037
4367
  return this.runs;
4038
4368
  }
4039
4369
  }, {
4040
- key: "next",
4370
+ key: 'next',
4041
4371
  value: function next(checkoutData) {
4042
4372
  var _this2 = this;
4043
4373
 
4044
4374
  this.background.clear();
4045
4375
  this.checkout = checkoutData;
4046
- var checkoutLink = String(ECHO_LINK);
4047
- checkoutLink = Url.extendSearchParams(checkoutLink, AccessToken.validateJWT(this.publicKey) ? 'access_token' : 'public_key', this.publicKey);
4048
- checkoutLink = Url.extendSearchParams(checkoutLink, 'json_body', encodeURIComponent(JSON.stringify({
4049
- redirect_uri: this.checkout.link
4050
- })));
4376
+ var checkoutUri = this.getCheckoutUri(this.checkout.link);
4051
4377
  Zip.Checkout.init({
4052
- checkoutUri: this.echoEnv.getConf().url + checkoutLink,
4378
+ checkoutUri: checkoutUri,
4053
4379
  onComplete: function onComplete(args) {
4054
4380
  return _this2.eventHandler(args);
4055
4381
  },
@@ -4059,26 +4385,36 @@
4059
4385
  });
4060
4386
  }
4061
4387
  }, {
4062
- key: "stop",
4388
+ key: 'getSuccessRedirectUri',
4389
+ value: function getSuccessRedirectUri() {
4390
+ return this.suspendedRedirectUri ? this.suspendedRedirectUri : this.widgetEnv.getConf().url + String(ZIPMONEY_DEFAULT_SUSPENDED_URL);
4391
+ }
4392
+ }, {
4393
+ key: 'getErrorRedirectUri',
4394
+ value: function getErrorRedirectUri() {
4395
+ return this.getSuccessRedirectUri();
4396
+ }
4397
+ }, {
4398
+ key: 'stop',
4063
4399
  value: function stop() {
4064
- get(ZipmoneyRunner.prototype.__proto__ || Object.getPrototypeOf(ZipmoneyRunner.prototype), "stop", this).call(this);
4400
+ get(ZipmoneyContextualRunner.prototype.__proto__ || Object.getPrototypeOf(ZipmoneyContextualRunner.prototype), 'stop', this).call(this);
4065
4401
  this.runs = false;
4066
4402
  var element = document.querySelector('.zipmoney-overlay');
4067
4403
  if (element) element.remove();
4068
- this.eventEmitter.emit(EVENT$1.CLOSE, {});
4404
+ this.eventEmitter.emit(RUNNER_EVENT.CLOSE);
4069
4405
  }
4070
4406
  }, {
4071
- key: "onStop",
4407
+ key: 'onStop',
4072
4408
  value: function onStop(cb) {
4073
4409
  var _this3 = this;
4074
4410
 
4075
- this.eventEmitter.subscribe(EVENT$1.CLOSE, function () {
4411
+ this.eventEmitter.subscribe(RUNNER_EVENT.CLOSE, function () {
4076
4412
  _this3.background.clear();
4077
4413
  cb();
4078
4414
  });
4079
4415
  }
4080
4416
  }, {
4081
- key: "onCheckout",
4417
+ key: 'onCheckout',
4082
4418
  value: function onCheckout(event, cb) {
4083
4419
  var _this4 = this;
4084
4420
 
@@ -4087,451 +4423,386 @@
4087
4423
  });
4088
4424
  }
4089
4425
  }, {
4090
- key: "eventHandler",
4426
+ key: 'eventHandler',
4091
4427
  value: function eventHandler(args) {
4092
4428
  this.runs = false;
4093
4429
  switch (args.state) {
4094
- case 'approved':
4095
- this.eventEmitter.emit(EVENT$1.CLOSE, {});
4096
- this.eventEmitter.emit(EVENT$1.SUCCESS, {});
4430
+ case "approved" /* APPROVED */:
4431
+ this.eventEmitter.emit(RUNNER_EVENT.CLOSE);
4432
+ this.eventEmitter.emit(RUNNER_EVENT.SUCCESS);
4097
4433
  break;
4098
- case 'declined':
4099
- this.eventEmitter.emit(EVENT$1.CLOSE, {});
4100
- this.eventEmitter.emit(EVENT$1.DECLINED, {});
4434
+ case "declined" /* DECLINED */:
4435
+ this.eventEmitter.emit(RUNNER_EVENT.CLOSE);
4436
+ this.eventEmitter.emit(RUNNER_EVENT.DECLINED);
4101
4437
  break;
4102
- case 'cancelled':
4103
- this.eventEmitter.emit(EVENT$1.CLOSE, {});
4438
+ case "cancelled" /* CANCELLED */:
4439
+ this.eventEmitter.emit(RUNNER_EVENT.CLOSE);
4104
4440
  break;
4105
- case 'referred':
4106
- this.eventEmitter.emit(EVENT$1.CLOSE, {});
4107
- this.eventEmitter.emit(EVENT$1.REFERRED, {});
4441
+ case "referred" /* REFERRED */:
4442
+ this.eventEmitter.emit(RUNNER_EVENT.CLOSE);
4443
+ this.eventEmitter.emit(RUNNER_EVENT.REFERRED);
4108
4444
  break;
4109
4445
  default:
4110
- console.warn('Unknown gateway status');
4446
+ console.warn(LOG_PREFIX + ' Unknown gateway status.');
4111
4447
  break;
4112
4448
  }
4113
4449
  }
4114
- }, {
4115
- key: "getSuccessRedirectUri",
4116
- value: function getSuccessRedirectUri() {
4117
- return this.customRedirectUti ? this.customRedirectUti : this.widgetEnv.getConf().url + String(REDIRECT_URL_SUSPENDED);
4118
- }
4119
- }, {
4120
- key: "getErrorRedirectUri",
4121
- value: function getErrorRedirectUri() {
4122
- return this.getSuccessRedirectUri();
4123
- }
4124
- }, {
4125
- key: "setEnv",
4126
- value: function setEnv(env, alias) {
4127
- get(ZipmoneyRunner.prototype.__proto__ || Object.getPrototypeOf(ZipmoneyRunner.prototype), "setEnv", this).call(this, env, alias);
4128
- this.echoEnv.setEnv(env, alias);
4129
- }
4130
4450
  }]);
4131
- return ZipmoneyRunner;
4132
- }(Runner);
4133
-
4134
- var EXTERNAL_CHECKOUT_LINK$1 = '/v1/gateways/:gateway_id';
4135
- var Info = function (_HttpCore) {
4136
- inherits(Info, _HttpCore);
4137
-
4138
- function Info(gatewayID) {
4139
- classCallCheck(this, Info);
4140
-
4141
- var _this = possibleConstructorReturn(this, (Info.__proto__ || Object.getPrototypeOf(Info)).call(this));
4142
-
4143
- _this.gatewayID = gatewayID;
4144
- return _this;
4145
- }
4146
-
4147
- createClass(Info, [{
4148
- key: 'getLink',
4149
- value: function getLink() {
4150
- return String(EXTERNAL_CHECKOUT_LINK$1).replace(':gateway_id', this.gatewayID);
4151
- }
4152
- }, {
4153
- key: 'sendRequest',
4154
- value: function sendRequest(publicKey, cb) {
4155
- var errorCb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (err) {};
4156
-
4157
- this.get(publicKey, function (data, status) {
4158
- cb(data);
4159
- }, function (err, status) {
4160
- if (typeof err.message === "undefined") errorCb(status + ': unknown error');else errorCb(err.message);
4161
- });
4162
- }
4163
- }], [{
4164
- key: 'sendRequest',
4165
- value: function sendRequest(gatewayID, publicKey, env, cb) {
4166
- var errorCb = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : function (err) {};
4167
-
4168
- var info = new this(gatewayID);
4169
- info.setEnv(env);
4170
- info.sendRequest(publicKey, cb, errorCb);
4171
- }
4172
- }]);
4173
- return Info;
4174
- }(HttpCore);
4175
-
4176
- var GATEWAY_TYPE = {
4177
- ZIPMONEY: 'Zipmoney',
4178
- PAYPAL: 'PaypalClassic',
4179
- AFTERPAY: 'Afterpay'
4180
- };
4181
-
4182
- var DISPATCHER_LINK = '/dispatcher';
4183
- var DISPATCHER_ELEMENT_ID = 'paydock-dispatcher';
4184
- var Dispatcher = function () {
4185
- function Dispatcher(messageSource) {
4186
- classCallCheck(this, Dispatcher);
4451
+ return ZipmoneyContextualRunner;
4452
+ }(ContextualRunner(ZipmoneyRunner));
4453
+
4454
+ var STORAGE_DISPATCHER_URI = '/storage-dispatcher';
4455
+ var STORAGE_DISPATCHER_ID = 'pd-storage-dispatcher';
4456
+ var LOG_PREFIX$1 = '[Paydock:StorageDispatcher]';
4457
+ var StorageDataIntent;
4458
+ (function (StorageDataIntent) {
4459
+ StorageDataIntent["WIDGET_SESSION"] = "widget-session";
4460
+ })(StorageDataIntent || (StorageDataIntent = {}));
4461
+ var StorageDispatcher = function () {
4462
+ function StorageDispatcher(messageSource) {
4463
+ classCallCheck(this, StorageDispatcher);
4187
4464
 
4188
4465
  this.messageSource = messageSource;
4466
+ this.defaultPayload = {
4467
+ destination: 'widget.paydock'
4468
+ };
4189
4469
  this.env = new Env(WIDGET_URL);
4470
+ this.defaultPayload.source = messageSource;
4190
4471
  }
4191
4472
 
4192
- createClass(Dispatcher, [{
4193
- key: 'restartDispatcher',
4194
- value: function restartDispatcher() {
4195
- var dispatcher = document.getElementById(DISPATCHER_ELEMENT_ID);
4196
- if (dispatcher) dispatcher.parentNode.removeChild(dispatcher);
4473
+ createClass(StorageDispatcher, [{
4474
+ key: 'create',
4475
+ value: function create() {
4476
+ if (this.dispatcherFrame) this.destroy();
4197
4477
  var iFrame = document.createElement('iframe');
4198
- iFrame.setAttribute('src', this.env.getConf().url + DISPATCHER_LINK);
4199
- iFrame.id = DISPATCHER_ELEMENT_ID;
4478
+ iFrame.setAttribute('src', this.env.getConf().url + STORAGE_DISPATCHER_URI);
4479
+ iFrame.setAttribute('id', STORAGE_DISPATCHER_ID);
4200
4480
  iFrame.style.display = 'none';
4201
4481
  document.body.appendChild(iFrame);
4482
+ console.info(LOG_PREFIX$1 + ' initialized.');
4483
+ return iFrame;
4202
4484
  }
4203
4485
  }, {
4204
- key: 'on',
4205
- value: function on(name, cb) {
4206
- var _this = this;
4207
-
4208
- Event.subscribe('message', window, function (event) {
4209
- var data = null;
4210
- try {
4211
- data = JSON.parse(event.data);
4212
- } catch (e) {}
4213
- if (!data || data.message_source !== _this.messageSource || data.event !== name) return;
4214
- cb(data);
4215
- });
4486
+ key: 'destroy',
4487
+ value: function destroy() {
4488
+ if (this.dispatcherFrame && this.dispatcherFrame.parentNode) {
4489
+ this.dispatcherFrame.parentNode.removeChild(this.dispatcherFrame);
4490
+ this.dispatcherFrame = undefined;
4491
+ }
4492
+ }
4493
+ }, {
4494
+ key: 'push',
4495
+ value: function push(payload) {
4496
+ var _a;
4497
+ if (!this.dispatcherFrame) {
4498
+ console.error(LOG_PREFIX$1 + ' dispatcher is not initialized.');
4499
+ return;
4500
+ }
4501
+ var body = _extends(_extends({}, this.defaultPayload), payload);
4502
+ (_a = this.dispatcherFrame.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(body, this.env.getConf().url);
4216
4503
  }
4217
4504
  }, {
4218
4505
  key: 'setEnv',
4219
4506
  value: function setEnv(env, alias) {
4220
4507
  this.env.setEnv(env, alias);
4221
- this.restartDispatcher();
4508
+ this.dispatcherFrame = this.create();
4222
4509
  }
4223
4510
  }]);
4224
- return Dispatcher;
4511
+ return StorageDispatcher;
4225
4512
  }();
4226
4513
 
4227
- var EVENT_CLOSE = 'close';
4228
- var ERROR_STYLES = "<style>\n .error-wrapper {\n color: #ff0000;\n display: flex;\n justify-content: center;\n align-items: center;\n height: 100%;\n }\n </style>";
4229
- var ERROR_TEMPLATE = "<div class=\"error-wrapper\"><div>{{error}}</div></div>";
4230
- var Popup = function () {
4231
- function Popup() {
4232
- classCallCheck(this, Popup);
4514
+ var ZipmoneyRedirectRunner = function (_RedirectRunner) {
4515
+ inherits(ZipmoneyRedirectRunner, _RedirectRunner);
4233
4516
 
4234
- this.configs = {
4235
- width: 500,
4236
- height: 500,
4237
- scrollbars: true,
4238
- resizable: true,
4239
- top: 0,
4240
- left: 0
4241
- };
4242
- this.eventEmitter = new EventEmitter();
4517
+ function ZipmoneyRedirectRunner() {
4518
+ classCallCheck(this, ZipmoneyRedirectRunner);
4519
+
4520
+ var _this = possibleConstructorReturn(this, (ZipmoneyRedirectRunner.__proto__ || Object.getPrototypeOf(ZipmoneyRedirectRunner)).call(this));
4521
+
4522
+ _this.storageDispatcher = new StorageDispatcher(ZIPMONEY_MESSAGE_SOURCE);
4523
+ return _this;
4243
4524
  }
4244
4525
 
4245
- createClass(Popup, [{
4246
- key: "isExist",
4247
- value: function isExist() {
4248
- return !!(this.getElement() && !this.getElement().closed);
4526
+ createClass(ZipmoneyRedirectRunner, [{
4527
+ key: 'getProxyRedirectUrl',
4528
+ value: function getProxyRedirectUrl() {
4529
+ return this.widgetEnv.getConf().url + ZIPMONEY_PROXY_REDIRECT_URL;
4249
4530
  }
4250
4531
  }, {
4251
- key: "getElement",
4252
- value: function getElement() {
4253
- return this.window;
4532
+ key: 'next',
4533
+ value: function next(checkout, params) {
4534
+ var widgetSessionData = {
4535
+ merchant_redirect_url: this.getRedirectUrl(),
4536
+ checkout_token: checkout.token,
4537
+ public_key: params.public_key,
4538
+ gateway_id: params.gateway_id
4539
+ };
4540
+ this.storageDispatcher.push({ intent: StorageDataIntent.WIDGET_SESSION, data: widgetSessionData });
4541
+ var checkoutUri = this.getCheckoutUri(checkout.link);
4542
+ Zip.Checkout.init({
4543
+ checkoutUri: checkoutUri,
4544
+ redirect: true
4545
+ });
4254
4546
  }
4255
- }, {
4256
- key: "init",
4257
- value: function init() {
4258
- var _this = this;
4547
+ // for backward compatibility
4259
4548
 
4260
- if (!Browser.isSupportPopUp()) return this.window = window;
4261
- var configs = this.getConfigs();
4262
- this.window = window.open('about:blank', '_blank', "width=" + configs.width + ",height=" + configs.height + ",top=" + configs.top + ",left=" + configs.left + ",scrollbars=" + (configs.scrollbars ? 'yes' : 'no') + ",resizable=" + (configs.resizable ? 'yes' : 'no'));
4263
- this.showLoader();
4264
- var timer = setInterval(function () {
4265
- if (!_this.isExist()) {
4266
- clearInterval(timer);
4267
- _this.eventEmitter.emit(EVENT_CLOSE, {});
4268
- }
4269
- }, 200);
4270
- }
4271
- }, {
4272
- key: "redirect",
4273
- value: function redirect(url) {
4274
- if (!this.isExist()) return;
4275
- this.window.location.href = url;
4276
- }
4277
4549
  }, {
4278
- key: "close",
4279
- value: function close() {
4280
- if (!this.isExist() || !this.getElement().close) return;
4281
- this.getElement().close();
4282
- this.window = null;
4283
- }
4284
- }, {
4285
- key: "focus",
4286
- value: function focus() {
4287
- if (!this.isExist() || !this.getElement().focus) return;
4288
- this.getElement().focus();
4289
- }
4290
- }, {
4291
- key: "setConfigs",
4292
- value: function setConfigs(configs) {
4293
- this.configs = _extends(this.configs, configs);
4294
- }
4295
- }, {
4296
- key: "getNetConfigs",
4297
- value: function getNetConfigs() {
4298
- return _extends({}, this.configs);
4299
- }
4300
- }, {
4301
- key: "getConfigs",
4302
- value: function getConfigs() {
4303
- var configs = this.getNetConfigs();
4304
- configs.left = window.screenX + (window.screen.width / 2 - configs.width / 2);
4305
- configs.top = window.screenY + (window.screen.height / 2 - configs.height / 2);
4306
- return configs;
4550
+ key: 'getSuccessRedirectUri',
4551
+ value: function getSuccessRedirectUri() {
4552
+ return this.getProxyRedirectUrl();
4307
4553
  }
4554
+ // for backward compatibility
4555
+
4308
4556
  }, {
4309
- key: "onClose",
4310
- value: function onClose(cb) {
4311
- this.eventEmitter.subscribe(EVENT_CLOSE, cb);
4557
+ key: 'getErrorRedirectUri',
4558
+ value: function getErrorRedirectUri() {
4559
+ return this.getProxyRedirectUrl();
4312
4560
  }
4313
4561
  }, {
4314
- key: "initError",
4315
- value: function initError(error) {
4316
- this.getElement().document.write(".");
4317
- var body = this.getElement().document.body || this.getElement().document.getElementsByTagName('body')[0];
4318
- body.innerHTML = ERROR_STYLES + ERROR_TEMPLATE.replace('{{error}}', error);
4562
+ key: 'setEnv',
4563
+ value: function setEnv(env, alias) {
4564
+ get(ZipmoneyRedirectRunner.prototype.__proto__ || Object.getPrototypeOf(ZipmoneyRedirectRunner.prototype), 'setEnv', this).call(this, env, alias);
4565
+ this.storageDispatcher.setEnv(env, alias);
4319
4566
  }
4320
- }, {
4321
- key: "showLoader",
4322
- value: function showLoader() {
4323
- this.getElement().document.write(".");
4324
- var body = this.getElement().document.body || this.getElement().document.getElementsByTagName('body')[0];
4325
- body.innerHTML = STYLE$1 + TEMPLATE;
4326
- if (this.env !== ENV.STAGING || this.env !== ENV.STAGING_1 || this.env !== ENV.STAGING_2 || this.env !== ENV.STAGING_3 || this.env !== ENV.STAGING_4 || this.env !== ENV.STAGING_5 || this.env !== ENV.STAGING_6 || this.env !== ENV.STAGING_7 || this.env !== ENV.STAGING_8 || this.env !== ENV.STAGING_9 || this.env !== ENV.STAGING_10 || this.env !== ENV.STAGING_11 || this.env !== ENV.STAGING_12 || this.env !== ENV.STAGING_13 || this.env !== ENV.STAGING_14 || this.env !== ENV.STAGING_15) return;
4327
- var clickCount = 0;
4328
- Event.subscribe('click', body, function () {
4329
- clickCount++;
4330
- if (clickCount !== 5) return;
4331
- body.innerHTML = EXTRA_STYLE + EXTRA_TEMPLATE;
4332
- });
4567
+ }]);
4568
+ return ZipmoneyRedirectRunner;
4569
+ }(RedirectRunner(ZipmoneyRunner));
4570
+
4571
+ var REDIRECT_URI_SUCCESS = '/checkout/success';
4572
+ var REDIRECT_URI_ERROR = '/checkout/error';
4573
+ var PaypalRunner = function (_PopupRunner) {
4574
+ inherits(PaypalRunner, _PopupRunner);
4575
+
4576
+ function PaypalRunner() {
4577
+ classCallCheck(this, PaypalRunner);
4578
+ return possibleConstructorReturn(this, (PaypalRunner.__proto__ || Object.getPrototypeOf(PaypalRunner)).apply(this, arguments));
4579
+ }
4580
+
4581
+ createClass(PaypalRunner, [{
4582
+ key: 'getSuccessRedirectUri',
4583
+ value: function getSuccessRedirectUri() {
4584
+ return this.widgetEnv.getConf().url + Url.extendSearchParams(REDIRECT_URI_SUCCESS, 'merchant', encodeURIComponent(window.location.href));
4333
4585
  }
4334
4586
  }, {
4335
- key: "setEnv",
4336
- value: function setEnv(env) {
4337
- this.env = env;
4587
+ key: 'getErrorRedirectUri',
4588
+ value: function getErrorRedirectUri() {
4589
+ return this.widgetEnv.getConf().url + Url.extendSearchParams(REDIRECT_URI_ERROR, 'merchant', encodeURIComponent(window.location.href));
4338
4590
  }
4339
4591
  }]);
4340
- return Popup;
4341
- }();
4342
-
4343
- var PopupRunner = function (_Runner) {
4344
- inherits(PopupRunner, _Runner);
4592
+ return PaypalRunner;
4593
+ }(PopupRunner);
4345
4594
 
4346
- function PopupRunner(publicKey) {
4347
- classCallCheck(this, PopupRunner);
4595
+ var REDIRECT_URI_SUCCESS$1 = '/checkout/afterpay/merchant/{{merchant}}/success';
4596
+ var REDIRECT_URI_ERROR$1 = '/checkout/afterpay/merchant/{{merchant}}/error';
4597
+ var CHECKOUT_URL = '/checkout/afterpay/init';
4348
4598
 
4349
- var _this = possibleConstructorReturn(this, (PopupRunner.__proto__ || Object.getPrototypeOf(PopupRunner)).call(this));
4599
+ var AfterpayRunner = function (_PopupRunner) {
4600
+ inherits(AfterpayRunner, _PopupRunner);
4350
4601
 
4351
- _this.publicKey = publicKey;
4352
- _this.checkout = null;
4353
- _this.dispatcher = new Dispatcher('checkout.paydock');
4354
- setTimeout(function () {
4355
- return _this.dispatcher.restartDispatcher();
4356
- }, 200);
4357
- _this.popup = new Popup();
4358
- return _this;
4602
+ function AfterpayRunner() {
4603
+ classCallCheck(this, AfterpayRunner);
4604
+ return possibleConstructorReturn(this, (AfterpayRunner.__proto__ || Object.getPrototypeOf(AfterpayRunner)).apply(this, arguments));
4359
4605
  }
4360
4606
 
4361
- createClass(PopupRunner, [{
4362
- key: "run",
4363
- value: function run() {
4364
- if (this.isRunning()) return;
4365
- this.popup.init();
4366
- this.background.initControl();
4607
+ createClass(AfterpayRunner, [{
4608
+ key: 'getSuccessRedirectUri',
4609
+ value: function getSuccessRedirectUri() {
4610
+ return this.widgetEnv.getConf().url + REDIRECT_URI_SUCCESS$1.replace('{{merchant}}', encodeURIComponent(window.btoa(window.location.href)));
4367
4611
  }
4368
4612
  }, {
4369
- key: "isRunning",
4370
- value: function isRunning() {
4371
- return this.popup.isExist();
4613
+ key: 'getErrorRedirectUri',
4614
+ value: function getErrorRedirectUri() {
4615
+ return this.widgetEnv.getConf().url + REDIRECT_URI_ERROR$1.replace('{{merchant}}', encodeURIComponent(window.btoa(window.location.href)));
4372
4616
  }
4373
4617
  }, {
4374
- key: "next",
4375
- value: function next(checkoutData) {
4618
+ key: 'next',
4619
+ value: function next(checkoutData, params) {
4376
4620
  this.checkout = checkoutData;
4377
4621
  if (!Browser.isSupportPopUp()) window.localStorage.setItem('paydock_checkout_token', JSON.stringify(this.checkout));
4378
- this.popup.redirect(this.checkout.link);
4379
- }
4380
- }, {
4381
- key: "continue",
4382
- value: function _continue() {
4383
- this.popup.focus();
4622
+ this.popup.redirect(this.getRedirectUrl(this.checkout, params));
4384
4623
  }
4385
4624
  }, {
4386
- key: "stop",
4387
- value: function stop() {
4388
- this.popup.close();
4625
+ key: 'error',
4626
+ value: function error(_error, code, callback) {
4627
+ if (!code || code && code !== 'invalid_amount') return callback(true);
4628
+ this.popup.initError(_error);
4629
+ return callback(false);
4389
4630
  }
4390
4631
  }, {
4391
- key: "onStop",
4392
- value: function onStop(cb) {
4393
- var _this2 = this;
4394
-
4395
- this.popup.onClose(function () {
4396
- _this2.background.clear();
4397
- _this2.checkout = null;
4398
- cb();
4632
+ key: 'run',
4633
+ value: function run() {
4634
+ if (this.isRunning()) return;
4635
+ this.popup.setConfigs({
4636
+ width: 420,
4637
+ height: 715
4399
4638
  });
4639
+ this.popup.init();
4640
+ this.background.initControl();
4400
4641
  }
4401
4642
  }, {
4402
- key: "onCheckout",
4403
- value: function onCheckout(event, cb) {
4404
- var _this3 = this;
4405
-
4406
- this.dispatcher.on(event, function (data) {
4407
- if (_this3.checkout && _this3.checkout.reference_id === data.reference_id) {
4408
- _this3.background.clear();
4409
- cb(_this3.checkout);
4410
- } else if (!Browser.isSupportPopUp()) {
4411
- var item = window.localStorage.getItem('paydock_checkout_token');
4412
- if (!item) return;
4413
- var checkout = JSON.parse(item);
4414
- if (checkout && checkout.reference_id === data.reference_id) {
4415
- window.localStorage.removeItem('paydock_checkout_token');
4416
- _this3.checkout = checkout;
4417
- _this3.background.clear();
4418
- cb(_this3.checkout);
4419
- }
4420
- }
4421
- });
4422
- }
4423
- }, {
4424
- key: "setEnv",
4425
- value: function setEnv(env, alias) {
4426
- get(PopupRunner.prototype.__proto__ || Object.getPrototypeOf(PopupRunner.prototype), "setEnv", this).call(this, env, alias);
4427
- this.dispatcher.setEnv(env, alias);
4428
- this.popup.setEnv(env);
4643
+ key: 'getRedirectUrl',
4644
+ value: function getRedirectUrl(checkout, params) {
4645
+ return this.widgetEnv.getConf().url + CHECKOUT_URL + '?' + Url.serialize(_extends(_extends({}, params), { token: checkout.reference_id, env: checkout.mode === 'live' ? 'live' : 'test' }));
4429
4646
  }
4430
4647
  }]);
4431
- return PopupRunner;
4432
- }(Runner);
4648
+ return AfterpayRunner;
4649
+ }(PopupRunner);
4433
4650
 
4434
- var REDIRECT_URI_SUCCESS = '/checkout/success';
4435
- var REDIRECT_URI_ERROR = '/checkout/error';
4436
- var PaypalRunner = function (_PopupRunner) {
4437
- inherits(PaypalRunner, _PopupRunner);
4651
+ var TYPE = {
4652
+ EXTERNAL_CHECKOUT_TOKEN: 'external_checkout_token',
4653
+ CHECKOUT_TOKEN: 'checkout_token',
4654
+ BANK_ACCOUNT: 'bank_account',
4655
+ CARD: 'card'
4656
+ };
4657
+ var LINK$1 = '/v1/payment_sources/tokens';
4658
+ var Builder$1 = function (_HttpCore) {
4659
+ inherits(Builder, _HttpCore);
4438
4660
 
4439
- function PaypalRunner() {
4440
- classCallCheck(this, PaypalRunner);
4441
- return possibleConstructorReturn(this, (PaypalRunner.__proto__ || Object.getPrototypeOf(PaypalRunner)).apply(this, arguments));
4661
+ function Builder(gatewayID, body) {
4662
+ var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : TYPE.CARD;
4663
+ classCallCheck(this, Builder);
4664
+
4665
+ var _this = possibleConstructorReturn(this, (Builder.__proto__ || Object.getPrototypeOf(Builder)).call(this));
4666
+
4667
+ _this.body = {
4668
+ gateway_id: gatewayID,
4669
+ type: type
4670
+ };
4671
+ switch (type) {
4672
+ case TYPE.CARD:
4673
+ case TYPE.BANK_ACCOUNT:
4674
+ delete body.gateway_id;
4675
+ delete body.type;
4676
+ delete body.checkout_token;
4677
+ _this.body = _extends(_this.body, body);
4678
+ break;
4679
+ case TYPE.CHECKOUT_TOKEN:
4680
+ case TYPE.EXTERNAL_CHECKOUT_TOKEN:
4681
+ _this.body.checkout_token = body;
4682
+ break;
4683
+ default:
4684
+ throw new Error('Unsupported type of PaymentSourceToken');
4685
+ }
4686
+ return _this;
4442
4687
  }
4443
4688
 
4444
- createClass(PaypalRunner, [{
4445
- key: "getSuccessRedirectUri",
4446
- value: function getSuccessRedirectUri() {
4447
- return this.widgetEnv.getConf().url + Url.extendSearchParams(REDIRECT_URI_SUCCESS, 'merchant', encodeURIComponent(window.location.href));
4689
+ createClass(Builder, [{
4690
+ key: 'getLink',
4691
+ value: function getLink() {
4692
+ return LINK$1;
4693
+ }
4694
+ }, {
4695
+ key: 'send',
4696
+ value: function send(accessToken, cb) {
4697
+ var errorCb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (err) {};
4698
+
4699
+ this.create(accessToken, this.getConfigs(), function (data, status) {
4700
+ return cb(data);
4701
+ }, function (err, status) {
4702
+ if (typeof err.message === "undefined") errorCb('unknown error');else errorCb(err.message);
4703
+ });
4448
4704
  }
4449
4705
  }, {
4450
- key: "getErrorRedirectUri",
4451
- value: function getErrorRedirectUri() {
4452
- return this.widgetEnv.getConf().url + Url.extendSearchParams(REDIRECT_URI_ERROR, 'merchant', encodeURIComponent(window.location.href));
4706
+ key: 'getConfigs',
4707
+ value: function getConfigs() {
4708
+ return this.body;
4453
4709
  }
4454
4710
  }]);
4455
- return PaypalRunner;
4456
- }(PopupRunner);
4711
+ return Builder;
4712
+ }(HttpCore);
4457
4713
 
4458
- var REDIRECT_URI_SUCCESS$1 = '/checkout/afterpay/merchant/{{merchant}}/success';
4459
- var REDIRECT_URI_ERROR$1 = '/checkout/afterpay/merchant/{{merchant}}/error';
4460
- var CHECKOUT_URL = '/checkout/afterpay/init';
4714
+ var CheckoutContextualHandler = function () {
4715
+ function CheckoutContextualHandler(background, runner, eventEmitter, params) {
4716
+ var _this = this;
4461
4717
 
4462
- var AfterpayRunner = function (_PopupRunner) {
4463
- inherits(AfterpayRunner, _PopupRunner);
4718
+ classCallCheck(this, CheckoutContextualHandler);
4464
4719
 
4465
- function AfterpayRunner() {
4466
- classCallCheck(this, AfterpayRunner);
4467
- return possibleConstructorReturn(this, (AfterpayRunner.__proto__ || Object.getPrototypeOf(AfterpayRunner)).apply(this, arguments));
4720
+ this.background = background;
4721
+ this.runner = runner;
4722
+ this.eventEmitter = eventEmitter;
4723
+ this.params = params;
4724
+ this.runner.onStop(function () {
4725
+ _this.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.CLOSE);
4726
+ });
4468
4727
  }
4469
4728
 
4470
- createClass(AfterpayRunner, [{
4471
- key: "getSuccessRedirectUri",
4472
- value: function getSuccessRedirectUri() {
4473
- return this.widgetEnv.getConf().url + REDIRECT_URI_SUCCESS$1.replace('{{merchant}}', encodeURIComponent(window.btoa(window.location.href)));
4474
- }
4475
- }, {
4476
- key: "getErrorRedirectUri",
4477
- value: function getErrorRedirectUri() {
4478
- return this.widgetEnv.getConf().url + REDIRECT_URI_ERROR$1.replace('{{merchant}}', encodeURIComponent(window.btoa(window.location.href)));
4479
- }
4480
- }, {
4481
- key: "next",
4482
- value: function next(checkoutData, params) {
4483
- this.checkout = checkoutData;
4484
- if (!Browser.isSupportPopUp()) window.localStorage.setItem('paydock_checkout_token', JSON.stringify(this.checkout));
4485
- this.popup.redirect(this.getRedirectUrl(params));
4729
+ createClass(CheckoutContextualHandler, [{
4730
+ key: 'init',
4731
+ value: function init(env) {
4732
+ var _this2 = this;
4733
+
4734
+ this.setEnv(env);
4735
+ this.runner.onCheckout(RUNNER_EVENT.SUCCESS, function (checkout) {
4736
+ _this2.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.ACCEPTED, {});
4737
+ _this2.background.initLoader();
4738
+ _this2.runner.stop();
4739
+ _this2.checkToken(checkout.token, function () {
4740
+ _this2.createOneTimeToken(checkout.token);
4741
+ });
4742
+ });
4743
+ this.runner.onCheckout(RUNNER_EVENT.ERROR, function () {
4744
+ _this2.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.ERROR);
4745
+ console.error(CHECKOUT_BTN_LOG_PREFIX + ' Error from checkout server.');
4746
+ _this2.runner.stop();
4747
+ });
4748
+ this.runner.onCheckout(RUNNER_EVENT.REFERRED, function () {
4749
+ _this2.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.REFERRED);
4750
+ _this2.runner.stop();
4751
+ });
4752
+ this.runner.onCheckout(RUNNER_EVENT.DECLINED, function () {
4753
+ _this2.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.DECLINED);
4754
+ _this2.runner.stop();
4755
+ });
4756
+ this.eventEmitter.subscribe(CHECKOUT_BUTTON_EVENT.ERROR, function () {
4757
+ _this2.runner.stop();
4758
+ });
4759
+ this.eventEmitter.subscribe(CHECKOUT_BUTTON_EVENT.FINISH, function (data) {
4760
+ _this2.background.clear();
4761
+ });
4486
4762
  }
4487
4763
  }, {
4488
- key: "error",
4489
- value: function error(_error, code, callback) {
4490
- if (!code || code && code !== 'invalid_amount') return callback(true);
4491
- this.popup.initError(_error);
4492
- return callback(false);
4764
+ key: 'setEnv',
4765
+ value: function setEnv(env) {
4766
+ this.env = env;
4493
4767
  }
4494
4768
  }, {
4495
- key: "run",
4496
- value: function run() {
4497
- if (this.isRunning()) return;
4498
- this.popup.setConfigs({
4499
- width: 420,
4500
- height: 715
4769
+ key: 'checkToken',
4770
+ value: function checkToken(token, cb) {
4771
+ var _this3 = this;
4772
+
4773
+ var checker = new Checker(token);
4774
+ checker.setEnv(this.env);
4775
+ checker.send(this.params.accessToken, function (details) {
4776
+ _this3.details = details;
4777
+ cb();
4778
+ }, function () {
4779
+ _this3.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.ERROR, {});
4780
+ console.error(CHECKOUT_BTN_LOG_PREFIX + ' Error during creating payment source token.');
4501
4781
  });
4502
- this.popup.init();
4503
- this.background.initControl();
4504
4782
  }
4505
4783
  }, {
4506
- key: "getRedirectUrl",
4507
- value: function getRedirectUrl(params) {
4508
- return this.widgetEnv.getConf().url + CHECKOUT_URL + '?' + Url.serialize(_extends(_extends({}, params), { token: this.checkout.reference_id, env: this.checkout.mode === 'live' ? 'live' : 'test' }));
4784
+ key: 'createOneTimeToken',
4785
+ value: function createOneTimeToken(token) {
4786
+ var _this4 = this;
4787
+
4788
+ var paymentSourceToken = new Builder$1(this.params.gatewayId, token, TYPE.CHECKOUT_TOKEN);
4789
+ paymentSourceToken.setEnv(this.env);
4790
+ paymentSourceToken.send(this.params.accessToken, function (token) {
4791
+ _this4.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.FINISH, {
4792
+ payment_source_token: token,
4793
+ checkout_email: _this4.details.checkout_email,
4794
+ checkout_holder: _this4.details.checkout_holder,
4795
+ gateway_type: _this4.details.gateway_type
4796
+ });
4797
+ }, function () {
4798
+ _this4.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.ERROR, {});
4799
+ console.error(CHECKOUT_BTN_LOG_PREFIX + ' Error during creating payment source token.');
4800
+ });
4509
4801
  }
4510
4802
  }]);
4511
- return AfterpayRunner;
4512
- }(PopupRunner);
4803
+ return CheckoutContextualHandler;
4804
+ }();
4513
4805
 
4514
- /**
4515
- *
4516
- * @type {object}
4517
- * @param {string} CLICK=click
4518
- * @param {string} POPUP_REDIRECT=popup_redirect
4519
- * @param {string} ERROR=error
4520
- * @param {string} ACCEPTED=accepted
4521
- * @param {string} FINISH=finish
4522
- * @param {string} CLOSE=close
4523
- */
4524
- var CHECKOUT_BUTTON_EVENT = {
4525
- CLICK: 'click',
4526
- POPUP_REDIRECT: 'popupRedirect',
4527
- ERROR: 'error',
4528
- REFERRED: 'referred',
4529
- DECLINED: 'declined',
4530
- CANCELLED: 'cancelled',
4531
- ACCEPTED: 'accepted',
4532
- FINISH: 'finish',
4533
- CLOSE: 'close'
4534
- };
4535
4806
  /**
4536
4807
  * Class CheckoutButton transform usual button into checkout
4537
4808
  *
@@ -4542,138 +4813,75 @@
4542
4813
  * @param {string} [gatewayId=default] - PayDock's gatewayId. By default or if put 'default', it will use the selected default gateway
4543
4814
  * @param {string} [type=PaypalClassic] - Type of gateway (PaypalClassic, Zipmoney)
4544
4815
  * @example
4545
- * var widget = new CheckoutButton('#button', 'aceessToken','gatewayId');
4816
+ * var widget = new CheckoutButton('#button', 'accessToken','gatewayId');
4546
4817
  **/
4547
4818
  var CheckoutButton = function () {
4548
- function CheckoutButton(selector, aceessToken) {
4549
- var _this = this;
4550
-
4819
+ function CheckoutButton(selector, accessToken) {
4551
4820
  var gatewayId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'default';
4552
4821
  var gatewayType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : GATEWAY_TYPE.PAYPAL;
4822
+ var mode = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : CHECKOUT_MODE.CONTEXTUAL;
4553
4823
  classCallCheck(this, CheckoutButton);
4554
4824
 
4555
- this.aceessToken = aceessToken;
4825
+ this.accessToken = accessToken;
4556
4826
  this.gatewayId = gatewayId;
4557
4827
  this.gatewayType = gatewayType;
4558
- this.details = null;
4828
+ this.mode = mode;
4829
+ this.window = window;
4559
4830
  this.meta = {};
4560
4831
  this.env = DEFAULT_ENV;
4561
4832
  this.eventEmitter = new EventEmitter();
4562
4833
  this.container = new Container(selector);
4563
- this.background = new Background();
4564
- switch (gatewayType) {
4565
- case GATEWAY_TYPE.PAYPAL:
4566
- this.runner = new PaypalRunner(aceessToken);
4567
- break;
4568
- case GATEWAY_TYPE.AFTERPAY:
4569
- this.runner = new AfterpayRunner(aceessToken);
4570
- break;
4571
- case GATEWAY_TYPE.ZIPMONEY:
4572
- this.runner = new ZipmoneyRunner(aceessToken);
4573
- break;
4574
- }
4575
- this.initCheckout();
4576
- this.initCheckoutHandlers();
4577
- this.runner.onStop(function () {
4578
- _this.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.CLOSE, {});
4579
- });
4834
+ this.initCheckout(this.container);
4835
+ this.chooseRunner(gatewayType, mode);
4580
4836
  }
4581
4837
 
4582
4838
  createClass(CheckoutButton, [{
4583
- key: "buildAdditionalParams",
4839
+ key: 'chooseRunner',
4840
+ value: function chooseRunner(gatewayType, mode) {
4841
+ var Runner = this.getRunnerByMode(gatewayType, mode);
4842
+ this.runner = new Runner(this.accessToken);
4843
+ if (isContextualRunner(this.runner)) {
4844
+ this.background = new Background();
4845
+ this.checkoutHandler = new CheckoutContextualHandler(this.background, this.runner, this.eventEmitter, { accessToken: this.accessToken, gatewayId: this.gatewayId });
4846
+ this.checkoutHandler.init(this.env);
4847
+ } else {
4848
+ this.background = undefined;
4849
+ this.checkoutHandler = undefined;
4850
+ }
4851
+ }
4852
+ }, {
4853
+ key: 'buildAdditionalParams',
4584
4854
  value: function buildAdditionalParams() {
4585
4855
  return {};
4586
4856
  }
4587
4857
  }, {
4588
- key: "initCheckout",
4589
- value: function initCheckout() {
4590
- var _this2 = this;
4858
+ key: 'initCheckout',
4859
+ value: function initCheckout(container) {
4860
+ var _this = this;
4591
4861
 
4592
- this.container.on('click', function (event) {
4593
- if (_this2.runner.isRunning()) return;
4594
- _this2.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.CLICK, {});
4595
- _this2.runner.run();
4596
- var externalCheckout = new Builder(_this2.gatewayId, _this2.runner.getSuccessRedirectUri(), _this2.runner.getErrorRedirectUri());
4597
- externalCheckout.setMeta(_this2.meta);
4598
- externalCheckout.setEnv(_this2.env);
4599
- externalCheckout.send(_this2.aceessToken, function (checkout) {
4600
- _this2.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.POPUP_REDIRECT, {});
4601
- _this2.runner.next(checkout, _this2.buildAdditionalParams());
4862
+ container.on('click', function (event) {
4863
+ if (isContextualRunner(_this.runner)) {
4864
+ if (_this.runner.isRunning()) return;else _this.runner.run();
4865
+ } else if (isRedirectRunner(_this.runner)) {
4866
+ if (!_this.runner.getRedirectUrl()) throw Error(CHECKOUT_BTN_LOG_PREFIX + ' The merchant redirect URL should is required in the \'' + _this.mode + '\' mode.');
4867
+ }
4868
+ _this.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.CLICK);
4869
+ var externalCheckout = new Builder(_this.gatewayId, _this.runner.getSuccessRedirectUri(), _this.runner.getErrorRedirectUri());
4870
+ externalCheckout.setMeta(_this.meta);
4871
+ externalCheckout.setEnv(_this.env);
4872
+ externalCheckout.send(_this.accessToken, function (checkout) {
4873
+ var buttonEvent = isContextualRunner(_this.runner) ? CHECKOUT_BUTTON_EVENT.POPUP_REDIRECT : CHECKOUT_BUTTON_EVENT.REDIRECT;
4874
+ _this.eventEmitter.emit(buttonEvent);
4875
+ _this.runner.next(checkout, _this.buildAdditionalParams());
4602
4876
  }, function (error, code) {
4603
- _this2.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.ERROR, {});
4604
- _this2.runner.error(error, code, function (close) {
4605
- if (close) _this2.close();
4877
+ console.error(CHECKOUT_BTN_LOG_PREFIX + ' ' + error);
4878
+ _this.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.ERROR, { error: error, code: code });
4879
+ _this.runner.error(error, code, function (close) {
4880
+ if (close) _this.close();
4606
4881
  });
4607
4882
  });
4608
4883
  });
4609
4884
  }
4610
- }, {
4611
- key: "initCheckoutHandlers",
4612
- value: function initCheckoutHandlers() {
4613
- var _this3 = this;
4614
-
4615
- this.runner.onCheckout(EVENT$1.SUCCESS, function (checkout) {
4616
- _this3.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.ACCEPTED, {});
4617
- _this3.background.initLoader();
4618
- _this3.close();
4619
- _this3.checkToken(checkout.token, function () {
4620
- _this3.createOneTimeToken(checkout.token);
4621
- });
4622
- });
4623
- this.runner.onCheckout(EVENT$1.ERROR, function () {
4624
- _this3.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.ERROR, {});
4625
- console.error('Error from checkout server');
4626
- _this3.close();
4627
- });
4628
- this.runner.onCheckout(EVENT$1.REFERRED, function () {
4629
- _this3.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.REFERRED, {});
4630
- _this3.close();
4631
- });
4632
- this.runner.onCheckout(EVENT$1.DECLINED, function () {
4633
- _this3.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.DECLINED, {});
4634
- _this3.close();
4635
- });
4636
- this.eventEmitter.subscribe(CHECKOUT_BUTTON_EVENT.ERROR, function () {
4637
- _this3.background.clear();
4638
- });
4639
- this.eventEmitter.subscribe(CHECKOUT_BUTTON_EVENT.FINISH, function () {
4640
- _this3.background.clear();
4641
- });
4642
- }
4643
- }, {
4644
- key: "checkToken",
4645
- value: function checkToken(token, cb) {
4646
- var _this4 = this;
4647
-
4648
- var checker = new Checker(token);
4649
- checker.setEnv(this.env);
4650
- checker.send(this.aceessToken, function (details) {
4651
- _this4.details = details;
4652
- cb();
4653
- }, function () {
4654
- _this4.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.ERROR, {});
4655
- console.error('Error during creating payment source token');
4656
- });
4657
- }
4658
- }, {
4659
- key: "createOneTimeToken",
4660
- value: function createOneTimeToken(token) {
4661
- var _this5 = this;
4662
-
4663
- var paymentSourceToken = new Builder$1(this.gatewayId, token, TYPE.CHECKOUT_TOKEN);
4664
- paymentSourceToken.setEnv(this.env);
4665
- paymentSourceToken.send(this.aceessToken, function (token) {
4666
- _this5.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.FINISH, {
4667
- payment_source_token: token,
4668
- checkout_email: _this5.details.checkout_email,
4669
- checkout_holder: _this5.details.checkout_holder,
4670
- gateway_type: _this5.details.gateway_type
4671
- });
4672
- }, function () {
4673
- _this5.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.ERROR, {});
4674
- console.error('Error during creating payment source token');
4675
- });
4676
- }
4677
4885
  /**
4678
4886
  * This callback will be called for each event in payment source widget
4679
4887
  *
@@ -4692,18 +4900,20 @@
4692
4900
  */
4693
4901
 
4694
4902
  }, {
4695
- key: "on",
4903
+ key: 'on',
4696
4904
  value: function on(name, handler) {
4697
4905
  this.eventEmitter.subscribe(name, handler);
4698
4906
  }
4699
4907
  /**
4700
- * Close popup window forcibly
4908
+ * Close popup window forcibly.
4909
+ * Only for 'contextual' mode.
4910
+ *
4701
4911
  */
4702
4912
 
4703
4913
  }, {
4704
- key: "close",
4914
+ key: 'close',
4705
4915
  value: function close() {
4706
- this.runner.stop();
4916
+ if (this.assertMethodSupport(this.runner, CHECKOUT_MODE.CONTEXTUAL)) this.runner.stop();
4707
4917
  }
4708
4918
  /**
4709
4919
  * After finish event of checkout button, data (dataType) will be insert to input (selector)
@@ -4713,7 +4923,7 @@
4713
4923
  */
4714
4924
 
4715
4925
  }, {
4716
- key: "onFinishInsert",
4926
+ key: 'onFinishInsert',
4717
4927
  value: function onFinishInsert(selector, dataType) {
4718
4928
  this.on(CHECKOUT_BUTTON_EVENT.FINISH, function (event) {
4719
4929
  Event.insertToInput(selector, dataType, event);
@@ -4733,12 +4943,13 @@
4733
4943
  */
4734
4944
 
4735
4945
  }, {
4736
- key: "setMeta",
4946
+ key: 'setMeta',
4737
4947
  value: function setMeta(meta) {
4738
4948
  this.meta = _extends(this.meta, meta);
4739
4949
  }
4740
4950
  /**
4741
- * Method for setting backdrop description
4951
+ * Method for setting backdrop description.
4952
+ * Only for 'contextual' mode.
4742
4953
  *
4743
4954
  * @example
4744
4955
  * button.setBackdropDescription('Custom description');
@@ -4747,12 +4958,13 @@
4747
4958
  */
4748
4959
 
4749
4960
  }, {
4750
- key: "setBackdropDescription",
4961
+ key: 'setBackdropDescription',
4751
4962
  value: function setBackdropDescription(text) {
4752
- this.runner.setBackgroundDescription(text);
4963
+ if (this.assertMethodSupport(this.runner, CHECKOUT_MODE.CONTEXTUAL)) this.runner.setBackgroundDescription(text);
4753
4964
  }
4754
4965
  /**
4755
- * Method for setting backdrop title
4966
+ * Method for setting backdrop title.
4967
+ * Only for 'contextual' mode.
4756
4968
  *
4757
4969
  * @example
4758
4970
  * button.setBackdropTitle('Custom title');
@@ -4761,24 +4973,43 @@
4761
4973
  */
4762
4974
 
4763
4975
  }, {
4764
- key: "setBackdropTitle",
4976
+ key: 'setBackdropTitle',
4765
4977
  value: function setBackdropTitle(text) {
4766
- this.runner.setBackgroundTitle(text);
4978
+ if (this.assertMethodSupport(this.runner, CHECKOUT_MODE.CONTEXTUAL)) this.runner.setBackgroundTitle(text);
4767
4979
  }
4768
4980
  /**
4769
- * Method for setting suspended redirect uri. Redirect after referred checkout
4770
- *
4981
+ * Method for setting suspended redirect uri. Redirect after referred checkout.
4982
+ * Only for 'contextual' mode.
4771
4983
  *
4772
4984
  * @param {uri} string - uri for redirect (by default)
4773
4985
  */
4774
4986
 
4775
4987
  }, {
4776
- key: "setSuspendedRedirectUri",
4988
+ key: 'setSuspendedRedirectUri',
4777
4989
  value: function setSuspendedRedirectUri(uri) {
4778
- this.runner.setCustomRedirectUri(uri);
4990
+ if (this.assertMethodSupport(this.runner, CHECKOUT_MODE.CONTEXTUAL)) this.runner.setSuspendedRedirectUri(uri);
4991
+ }
4992
+ /**
4993
+ * Method for setting the merchant redirect URL.
4994
+ * Merchant's customers redirect after successfull checkout.
4995
+ * Only for 'redirect' mode.
4996
+ *
4997
+ * @param {url} string - redirect url
4998
+ */
4999
+
5000
+ }, {
5001
+ key: 'setRedirectUrl',
5002
+ value: function setRedirectUrl(url) {
5003
+ if (this.assertMethodSupport(this.runner, CHECKOUT_MODE.REDIRECT)) this.runner.setRedirectUrl(url);
5004
+ }
5005
+ }, {
5006
+ key: 'getSuccessRedirectUri',
5007
+ value: function getSuccessRedirectUri() {
5008
+ return this.runner.getSuccessRedirectUri();
4779
5009
  }
4780
5010
  /**
4781
5011
  * Method for disable backdrop on the page.
5012
+ * Only for 'contextual' mode.
4782
5013
  *
4783
5014
  * @example
4784
5015
  * button.turnOffBackdrop();
@@ -4786,32 +5017,65 @@
4786
5017
  */
4787
5018
 
4788
5019
  }, {
4789
- key: "turnOffBackdrop",
5020
+ key: 'turnOffBackdrop',
4790
5021
  value: function turnOffBackdrop() {
4791
5022
  this.turnOffControlBackdrop();
4792
5023
  this.turnOffLoaderBackdrop();
4793
5024
  }
4794
5025
  }, {
4795
- key: "turnOffControlBackdrop",
5026
+ key: 'turnOffControlBackdrop',
4796
5027
  value: function turnOffControlBackdrop() {
4797
- this.runner.turnOffBackdrop();
5028
+ if (this.assertMethodSupport(this.runner, CHECKOUT_MODE.CONTEXTUAL)) this.runner.turnOffBackdrop();
4798
5029
  }
4799
5030
  }, {
4800
- key: "turnOffLoaderBackdrop",
5031
+ key: 'turnOffLoaderBackdrop',
4801
5032
  value: function turnOffLoaderBackdrop() {
4802
- this.background.turnOffLoader();
5033
+ var _a;
5034
+ (_a = this.background) === null || _a === void 0 ? void 0 : _a.turnOffLoader();
4803
5035
  }
4804
5036
  }, {
4805
- key: "setEnv",
5037
+ key: 'setEnv',
4806
5038
  value: function setEnv(env, alias) {
5039
+ var _a;
4807
5040
  this.env = env;
5041
+ this.alias = alias;
5042
+ (_a = this.checkoutHandler) === null || _a === void 0 ? void 0 : _a.setEnv(env);
4808
5043
  this.runner.setEnv(env, alias);
4809
5044
  }
4810
5045
  }, {
4811
- key: "getEnv",
5046
+ key: 'getEnv',
4812
5047
  value: function getEnv() {
4813
5048
  return this.env;
4814
5049
  }
5050
+ }, {
5051
+ key: 'getRunnerByMode',
5052
+ value: function getRunnerByMode(gatewayType, mode) {
5053
+ if (gatewayType === GATEWAY_TYPE.PAYPAL) {
5054
+ if (mode === CHECKOUT_MODE.REDIRECT) throw Error(CHECKOUT_BTN_LOG_PREFIX + ' Gateway \'' + gatewayType + '\' do not support \'' + mode + '\' mode');
5055
+ return PaypalRunner;
5056
+ } else if (gatewayType === GATEWAY_TYPE.AFTERPAY) {
5057
+ if (mode === CHECKOUT_MODE.REDIRECT) throw Error(CHECKOUT_BTN_LOG_PREFIX + ' Gateway \'' + gatewayType + '\' do not support \'' + mode + '\' mode');
5058
+ return AfterpayRunner;
5059
+ } else if (gatewayType === GATEWAY_TYPE.ZIPMONEY) {
5060
+ return mode === CHECKOUT_MODE.CONTEXTUAL ? ZipmoneyContextualRunner : ZipmoneyRedirectRunner;
5061
+ } else {
5062
+ throw Error(CHECKOUT_BTN_LOG_PREFIX + ' Unsupported gateway.');
5063
+ }
5064
+ }
5065
+ }, {
5066
+ key: 'assertMethodSupport',
5067
+ value: function assertMethodSupport(runner, mode) {
5068
+ var warnMessage = CHECKOUT_BTN_LOG_PREFIX + ' The method is not supported in the \'' + mode + '\' mode.';
5069
+ switch (mode) {
5070
+ case CHECKOUT_MODE.CONTEXTUAL:
5071
+ if (isContextualRunner(runner)) return true;else console.warn(warnMessage);
5072
+ break;
5073
+ case CHECKOUT_MODE.REDIRECT:
5074
+ if (isRedirectRunner(runner)) return true;else console.warn(warnMessage);
5075
+ break;
5076
+ }
5077
+ return false;
5078
+ }
4815
5079
  }]);
4816
5080
  return CheckoutButton;
4817
5081
  }();
@@ -4826,6 +5090,7 @@
4826
5090
  * @param {string} selector - Selector of html element.
4827
5091
  * @param {string} publicKey - PayDock users public key
4828
5092
  * @param {string} [gatewayId=default] - PayDock's gatewayId. By default or if put 'default', it will use the selected default gateway
5093
+ * @param {string} [gatewayId=default] - Checkout mode, it could be set to 'contextual' or 'redirect'. By default it 'contextual'
4829
5094
  * @example
4830
5095
  * var widget = new ZipmoneyCheckoutButton('#button', 'publicKey','gatewayId');
4831
5096
  **/
@@ -4834,12 +5099,14 @@
4834
5099
 
4835
5100
  function ZipmoneyCheckoutButton(selector, publicKey) {
4836
5101
  var gatewayId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'default';
5102
+ var mode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : CHECKOUT_MODE.CONTEXTUAL;
4837
5103
  classCallCheck(this, ZipmoneyCheckoutButton);
4838
5104
 
4839
- var _this = possibleConstructorReturn(this, (ZipmoneyCheckoutButton.__proto__ || Object.getPrototypeOf(ZipmoneyCheckoutButton)).call(this, selector, publicKey, gatewayId, GATEWAY_TYPE.ZIPMONEY));
5105
+ var _this = possibleConstructorReturn(this, (ZipmoneyCheckoutButton.__proto__ || Object.getPrototypeOf(ZipmoneyCheckoutButton)).call(this, selector, publicKey, gatewayId, GATEWAY_TYPE.ZIPMONEY, mode));
4840
5106
 
4841
5107
  _this.publicKey = publicKey;
4842
5108
  _this.gatewayId = gatewayId;
5109
+ _this.mode = mode;
4843
5110
  return _this;
4844
5111
  }
4845
5112
  /**
@@ -4849,14 +5116,42 @@
4849
5116
  * This can be provided, even if using in-context checkout (sdk). By default, the standard styled page will be used.
4850
5117
  * If using in-context (sdk) we will not automatically redirect to this URI.
4851
5118
  *
4852
- * @param {uri} string - uri for redirect (by default)
5119
+ * @param {uri} string - uri for suspended redirect (by default)
4853
5120
  */
4854
5121
 
4855
5122
 
4856
5123
  createClass(ZipmoneyCheckoutButton, [{
4857
- key: "setSuspendedRedirectUri",
5124
+ key: 'setSuspendedRedirectUri',
4858
5125
  value: function setSuspendedRedirectUri(uri) {
4859
- get(ZipmoneyCheckoutButton.prototype.__proto__ || Object.getPrototypeOf(ZipmoneyCheckoutButton.prototype), "setSuspendedRedirectUri", this).call(this, uri);
5126
+ get(ZipmoneyCheckoutButton.prototype.__proto__ || Object.getPrototypeOf(ZipmoneyCheckoutButton.prototype), 'setSuspendedRedirectUri', this).call(this, uri);
5127
+ }
5128
+ /**
5129
+ * Method for setting the merchant redirect URL.
5130
+ * The merchant's customers would be redirected to the specified URL
5131
+ * at the end of ZipMoney checkout flow.
5132
+ *
5133
+ * Once the redirect URL would be set, the checkout flow would be immediately switched
5134
+ * from 'contextual' mode to the 'redirect' mode.
5135
+ * The merchant's customer would be automatically redirected to this URL after the checkout is complete.
5136
+ *
5137
+ * @param {url} string - URL for redirect
5138
+ */
5139
+
5140
+ }, {
5141
+ key: 'setRedirectUrl',
5142
+ value: function setRedirectUrl(url) {
5143
+ if (isContextualRunner(this.runner)) {
5144
+ get(ZipmoneyCheckoutButton.prototype.__proto__ || Object.getPrototypeOf(ZipmoneyCheckoutButton.prototype), 'chooseRunner', this).call(this, GATEWAY_TYPE.ZIPMONEY, CHECKOUT_MODE.REDIRECT);
5145
+ get(ZipmoneyCheckoutButton.prototype.__proto__ || Object.getPrototypeOf(ZipmoneyCheckoutButton.prototype), 'setEnv', this).call(this, this.env, this.alias);
5146
+ }
5147
+ get(ZipmoneyCheckoutButton.prototype.__proto__ || Object.getPrototypeOf(ZipmoneyCheckoutButton.prototype), 'setRedirectUrl', this).call(this, url);
5148
+ }
5149
+ }, {
5150
+ key: 'buildAdditionalParams',
5151
+ value: function buildAdditionalParams() {
5152
+ var defaultParams = get(ZipmoneyCheckoutButton.prototype.__proto__ || Object.getPrototypeOf(ZipmoneyCheckoutButton.prototype), 'buildAdditionalParams', this).call(this);
5153
+ var params = _extends(_extends({}, defaultParams), { public_key: this.publicKey, gateway_id: this.gatewayId });
5154
+ return params;
4860
5155
  }
4861
5156
  }]);
4862
5157
  return ZipmoneyCheckoutButton;
@@ -4902,7 +5197,7 @@
4902
5197
 
4903
5198
 
4904
5199
  createClass(AfterpayCheckoutButton, [{
4905
- key: "showEnhancedTrackingProtectionPopup",
5200
+ key: 'showEnhancedTrackingProtectionPopup',
4906
5201
  value: function showEnhancedTrackingProtectionPopup(doShow) {
4907
5202
  var _Browser$getBrowserIn = Browser.getBrowserInfo(),
4908
5203
  name = _Browser$getBrowserIn.name,
@@ -4911,9 +5206,9 @@
4911
5206
  if (doShow && name === 'Firefox' && +version >= 100) this.showETP = true;
4912
5207
  }
4913
5208
  }, {
4914
- key: "buildAdditionalParams",
5209
+ key: 'buildAdditionalParams',
4915
5210
  value: function buildAdditionalParams() {
4916
- var params = get(AfterpayCheckoutButton.prototype.__proto__ || Object.getPrototypeOf(AfterpayCheckoutButton.prototype), "buildAdditionalParams", this).call(this);
5211
+ var params = get(AfterpayCheckoutButton.prototype.__proto__ || Object.getPrototypeOf(AfterpayCheckoutButton.prototype), 'buildAdditionalParams', this).call(this);
4917
5212
  if (this.showETP) {
4918
5213
  params.show_etp = true;
4919
5214
  }
@@ -6531,6 +6826,124 @@
6531
6826
  return ApiInternal;
6532
6827
  }(ApiBase);
6533
6828
 
6829
+ var AfterPayWalletService = function (_WalletService) {
6830
+ inherits(AfterPayWalletService, _WalletService);
6831
+
6832
+ function AfterPayWalletService(token, meta) {
6833
+ classCallCheck(this, AfterPayWalletService);
6834
+ return possibleConstructorReturn(this, (AfterPayWalletService.__proto__ || Object.getPrototypeOf(AfterPayWalletService)).call(this, token, meta));
6835
+ }
6836
+
6837
+ createClass(AfterPayWalletService, [{
6838
+ key: 'load',
6839
+ value: function load(container) {
6840
+ this.mount(container);
6841
+ }
6842
+ }, {
6843
+ key: 'mount',
6844
+ value: function mount(container) {
6845
+ var _this2 = this;
6846
+
6847
+ var _a, _b, _c, _d;
6848
+ var customStyles = {};
6849
+ if (((_a = this.meta) === null || _a === void 0 ? void 0 : _a.style) && _typeof((_b = this.meta) === null || _b === void 0 ? void 0 : _b.style) === 'object') customStyles = JSON.parse(JSON.stringify(((_c = this.meta) === null || _c === void 0 ? void 0 : _c.style['afterpay']) || ((_d = this.meta) === null || _d === void 0 ? void 0 : _d.style)));
6850
+ var afterpayButton = this.getButton(customStyles);
6851
+ afterpayButton.onclick = function () {
6852
+ return _this2.onAfterPayButtonClicked();
6853
+ };
6854
+ var buttonWalletStyle = this.getButtonStyle(customStyles);
6855
+ container.getElement().appendChild(afterpayButton);
6856
+ container.getElement().appendChild(buttonWalletStyle);
6857
+ }
6858
+ }, {
6859
+ key: 'onAfterPayButtonClicked',
6860
+ value: function onAfterPayButtonClicked() {
6861
+ var _this3 = this;
6862
+
6863
+ return new Promise(function () {
6864
+ var _a, _b;
6865
+ var afterpayJS = document.createElement('script');
6866
+ var countryCode = (_a = _this3.meta) === null || _a === void 0 ? void 0 : _a.country;
6867
+ afterpayJS.type = 'text/javascript';
6868
+ afterpayJS.src = ((_b = _this3.meta) === null || _b === void 0 ? void 0 : _b.gateway_mode) === 'live' ? 'https://portal.afterpay.com/afterpay.js' : 'https://portal.sandbox.afterpay.com/afterpay.js';
6869
+ afterpayJS.async = true;
6870
+ afterpayJS.defer = true;
6871
+ afterpayJS.onload = function () {
6872
+ window.AfterPay.initialize({ countryCode: countryCode });
6873
+ _this3.getCheckoutSession().then(function (response) {
6874
+ window.AfterPay.redirect({
6875
+ token: response.ref_token
6876
+ });
6877
+ }).catch(function (err) {
6878
+ window.AfterPay.close();
6879
+ _this3.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, {
6880
+ err: err
6881
+ });
6882
+ });
6883
+ };
6884
+ document.head.appendChild(afterpayJS);
6885
+ });
6886
+ }
6887
+ }, {
6888
+ key: 'getCheckoutSession',
6889
+ value: function getCheckoutSession() {
6890
+ var _this4 = this;
6891
+
6892
+ return new Promise(function (resolve, reject) {
6893
+ return _this4.eventEmitter.emit(WALLET_EVENT.CALLBACK, {
6894
+ data: {
6895
+ request_type: 'CREATE_SESSION',
6896
+ wallet_type: WALLET_TYPE.AFTERPAY
6897
+ },
6898
+ onSuccess: function onSuccess(res) {
6899
+ resolve(res);
6900
+ },
6901
+ onError: function onError(message) {
6902
+ reject(message);
6903
+ }
6904
+ });
6905
+ });
6906
+ }
6907
+ }, {
6908
+ key: 'getButton',
6909
+ value: function getButton(customStyles) {
6910
+ var afterpayButton = document.createElement('button');
6911
+ afterpayButton.classList.add("afterpay-checkout-btn");
6912
+ afterpayButton.setAttribute('type', 'button');
6913
+ afterpayButton.innerHTML = '\n <div class="afterpay-checkout-btn__wrapper">\n <svg viewBox="0 0 390 94"\n height="' + this.getHeight(customStyles) + '"\n xmlns="http://www.w3.org/2000/svg">\n <g fill="currentColor">\n <path\n d="M388.6 21.4l-34.8 71.8h-14.4l13-26.8-20.5-45h14.8l13.2 30.1 14.3-30.1zM41 46.9c0-8.6-6.2-14.6-13.9-14.6s-13.9 6.1-13.9 14.6c0 8.4 6.2 14.6 13.9 14.6 7.6 0 13.9-6.1 13.9-14.6m.1 25.5v-6.6c-3.8 4.6-9.4 7.4-16.1 7.4C11 73.2.4 62 .4 46.9c0-15 11-26.4 24.9-26.4 6.5 0 12 2.9 15.8 7.3v-6.4h12.5v51H41.1zM114.6 61.1c-4.4 0-5.6-1.6-5.6-5.9V32.5h8.1V21.4H109V8.9H96.1v12.4H79.5v-5.1c0-4.3 1.6-5.9 6.1-5.9h2.8V.4h-6.2C71.6.4 66.6 3.9 66.6 14.5v6.8h-7.1v11.1h7.1v39.9h12.9V32.5h16.6v25c0 10.4 4 14.9 14.4 14.9h6.6V61.1h-2.5zM160.7 42.3c-.9-6.6-6.3-10.6-12.6-10.6s-11.5 3.9-12.9 10.6h25.5zm-25.6 7.9c.9 7.5 6.3 11.8 13.2 11.8 5.4 0 9.6-2.6 12-6.6h13.2c-3.1 10.8-12.7 17.7-25.5 17.7-15.4 0-26.2-10.8-26.2-26.2 0-15.4 11.4-26.5 26.5-26.5 15.2 0 26.2 11.2 26.2 26.5 0 1.1-.1 2.2-.3 3.3h-39.1zM256.2 46.9c0-8.3-6.2-14.6-13.9-14.6s-13.9 6.1-13.9 14.6c0 8.4 6.2 14.6 13.9 14.6 7.6 0 13.9-6.4 13.9-14.6m-40.4 46.3V21.4h12.5V28c3.8-4.7 9.4-7.5 16.1-7.5 13.8 0 24.6 11.3 24.6 26.3s-11 26.4-24.9 26.4c-6.4 0-11.7-2.6-15.4-6.8v26.8h-12.9zM314.2 46.9c0-8.6-6.2-14.6-13.9-14.6-7.6 0-13.9 6.1-13.9 14.6 0 8.4 6.2 14.6 13.9 14.6s13.9-6.1 13.9-14.6m.1 25.5v-6.6c-3.8 4.6-9.4 7.4-16.1 7.4-14 0-24.6-11.2-24.6-26.3 0-15 11-26.4 24.9-26.4 6.5 0 12 2.9 15.8 7.3v-6.4h12.5v51h-12.5zM193.2 26.4s3.2-5.9 11-5.9c3.3 0 5.5 1.2 5.5 1.2v13s-4.7-2.9-9.1-2.3c-4.3.6-7.1 4.6-7.1 9.9v30.2h-13v-51H193v4.9h.2z" />\n </g>\n </svg>\n <svg viewBox="0 0 107 96"\n height="' + this.getHeight(customStyles) + '"\n xmlns="http://www.w3.org/2000/svg">\n <path\n d="M99 19.5L84.2 11l-15-8.6c-10-5.7-22.4 1.5-22.4 13v1.9c0 1.1.6 2 1.5 2.6l7 4c1.9 1.1 4.4-.3 4.4-2.5v-4.6c0-2.3 2.5-3.7 4.4-2.6l13.8 7.9L91.6 30c2 1.1 2 4 0 5.1L77.9 43l-13.8 7.9c-2 1.1-4.4-.3-4.4-2.6V46c0-11.5-12.4-18.7-22.4-13l-15 8.6-14.8 8.5c-10 5.7-10 20.2 0 26l14.8 8.5 15 8.6c10 5.7 22.4-1.5 22.4-13v-1.9c0-1.1-.6-2-1.5-2.6l-7-4c-1.9-1.1-4.4.3-4.4 2.5v4.6c0 2.3-2.5 3.7-4.4 2.6l-13.8-7.9-13.7-7.9c-2-1.1-2-4 0-5.1l13.7-7.9 13.8-7.9c2-1.1 4.4.3 4.4 2.6v2.3c0 11.5 12.4 18.7 22.4 13l15-8.6L99 45.5c10.1-5.8 10.1-20.2 0-26"\n fill="currentColor" />\n </svg>\n </div>\n ';
6914
+ return afterpayButton;
6915
+ }
6916
+ }, {
6917
+ key: 'getButtonStyle',
6918
+ value: function getButtonStyle(customStyles) {
6919
+ var styleSheet = document.createElement('style');
6920
+ var buttonColor = this.generateButtonColor(customStyles.button_type);
6921
+ styleSheet.innerText = '\n .afterpay-checkout-btn {\n outline: none;\n border: none;\n border-radius: ' + this.getHeight(customStyles) + ';\n padding: 0;\n margin: 0;\n transition: all 300ms;\n cursor: pointer;\n }\n\n .afterpay-checkout-btn:active {\n opacity: 0.7;\n }\n\n .afterpay-checkout-btn__wrapper {\n display: flex;\n align-items: center;\n padding: 10px 20px;\n color: ' + buttonColor.color + ';\n background-color: ' + buttonColor.background + ';\n border-radius: ' + this.getHeight(customStyles) + ';\n }\n ';
6922
+ return styleSheet;
6923
+ }
6924
+ }, {
6925
+ key: 'generateButtonColor',
6926
+ value: function generateButtonColor(button_type) {
6927
+ switch (button_type) {
6928
+ case 'black':
6929
+ return { color: '#B2FCE3', background: '#000' };
6930
+ case 'mint':
6931
+ return { color: '#000', background: '#B2FCE3' };
6932
+ default:
6933
+ return { color: '#fff', background: '#000' };
6934
+ }
6935
+ }
6936
+ }, {
6937
+ key: 'getHeight',
6938
+ value: function getHeight(customStyles) {
6939
+ if (!customStyles.height) return '40px';
6940
+ if (Number.isNaN(Number(customStyles.height))) return customStyles.height;
6941
+ return customStyles.height + 'px';
6942
+ }
6943
+ }]);
6944
+ return AfterPayWalletService;
6945
+ }(WalletService);
6946
+
6534
6947
  /**
6535
6948
  * List of available event's name in the wallet button lifecycle
6536
6949
  * @const EVENT
@@ -6541,7 +6954,7 @@
6541
6954
  * @param {string} PAYMENT_SUCCESSFUL=paymentSuccessful
6542
6955
  * @param {string} PAYMENT_ERROR=paymentError
6543
6956
  */
6544
- var EVENT$2 = {
6957
+ var EVENT$1 = {
6545
6958
  UNAVAILABLE: "unavailable",
6546
6959
  UPDATE: "update",
6547
6960
  PAYMENT_SUCCESSFUL: "paymentSuccessful",
@@ -6553,19 +6966,22 @@
6553
6966
  * @interface IWalletMeta
6554
6967
  *
6555
6968
  * @type {object}
6556
- * @param {string} [amount_label] Label shown next to the total amount to be paid. Required for [Stripe, ApplePay, GooglePay]. N/A for [FlyPay, PayPal].
6557
- * @param {string} [country] Country of the user. 2 letter ISO code format. Required for [Stripe, ApplePay, GooglePay]. N/A for [FlyPay, PayPal].
6969
+ * @param {string} [amount_label] Label shown next to the total amount to be paid. Required for [Stripe, ApplePay, GooglePay]. N/A for [FlyPay, PayPal, Afterpay].
6970
+ * @param {string} [country] Country of the user. 2 letter ISO code format. Required for [Stripe, ApplePay, GooglePay, Afterpay]. N/A for [FlyPay, PayPal].
6558
6971
  * @param {string} [pay_later] Used to enable Pay Later feature in PayPal Smart Checkout WalletButton integration when available. Optional for [PayPal]. N/A for other wallets.
6559
6972
  * @param {boolean} [show_billing_address] Used to hide/show the billing address on ApplePay and GooglePay popups. Default value is false. Optional for [ApplePay, GooglePay]. N/A for other wallets.
6560
6973
  * @param {boolean} [request_payer_name] Used mainly for fraud purposes - recommended set to true. Optional for [Stripe]. N/A for other wallets.
6561
6974
  * @param {boolean} [request_payer_email] Used mainly for fraud purposes - recommended set to true. Optional for [Stripe]. N/A for other wallets.
6562
6975
  * @param {boolean} [request_payer_phone] Used mainly for fraud purposes - recommended set to true. Optional for [Stripe]. N/A for other wallets.
6563
- * @param {boolean} [request_shipping] Used to request or not shipping address in the Wallet checkout, being able to handle amount changes via the `update` event. Optional for [FlyPay, PayPal, ApplePay, GooglePay]. N/A for [Stripe].
6976
+ * @param {boolean} [request_shipping] Used to request or not shipping address in the Wallet checkout, being able to handle amount changes via the `update` event. Optional for [FlyPay, PayPal, ApplePay, GooglePay]. N/A for [Stripe, Afterpay].
6564
6977
  * @param {IApplePayShippingOption[] | IPayPalShippingOption[]} [shipping_options] Used to provide available shipping options.(To use shipping_options the request_shipping flag should be true). Optional for [ApplePay]. N/A for the other wallets.
6565
6978
  * @param {string} [merchant_name] Merchant Name used for GooglePay integration via MPGS. Required for [GooglePay]. N/A for other wallets.
6566
6979
  * @param {object} [raw_data_initialization] Used to provide values to initialize wallet with raw data. Optional for [ApplePay]. N/A for the other wallets.
6567
- * @param {object} [style] Used to style PayPal buttons, check possible values at https://developer.paypal.com/docs/business/checkout/reference/style-guide. Also used at ApplePay to select button type. Optional for [PayPal, ApplePay]. N/A for [Stripe, FlyPay].
6568
- * @param {object} [style.button_type] Used to select ApplePay button type (e.g: 'buy','donate', etc), check possible values at https://developer.apple.com/documentation/apple_pay_on_the_web/displaying_apple_pay_buttons_using_css. Optional for [ApplePay]. N/A for other wallets.
6980
+ * @param {object} [style] Used to style PayPal buttons, check possible values at https://developer.paypal.com/docs/business/checkout/reference/style-guide. Also used at ApplePay, GooglePay and Afterpay to select button type.
6981
+ * Optional for [PayPal, ApplePay, GooglePay, Afterpay]. N/A for [Stripe, FlyPay].
6982
+ * @param {object} [style.button_type] Used to select ApplePay button type (e.g: 'buy','donate', etc), check possible values at https://developer.apple.com/documentation/apple_pay_on_the_web/displaying_apple_pay_buttons_using_css.
6983
+ * Also select button type for GooglePay (check GooglePayStyles) and Afterpay (check AfterpayStyles). Optional for [ApplePay, GooglePay, Afterpay]. N/A for other wallets.
6984
+ * @param {object} [style.height] Used to select Afterpay button height. Optional for [Afterpay]. N/A for other wallets.
6569
6985
  * @param {array} [wallets] By default if this is not sent or empty, we will try to show either Apple Pay or Google Pay buttons. This can be limited sending the following array in this field: ['apple','google]. Optional for [Stripe, ApplePay, GooglePay]. N/A for other wallets.
6570
6986
  */
6571
6987
  /**
@@ -6635,6 +7051,9 @@
6635
7051
  case WALLET_GATEWAY.MASTERCARD:
6636
7052
  this.service = new MastercardWalletService('', _extends(_extends({}, meta), { credentials: tokenMeta.gateway.credentials, amount: tokenMeta.charge.amount, currency: tokenMeta.charge.currency, gateway_mode: tokenMeta.gateway.mode }));
6637
7053
  break;
7054
+ case WALLET_GATEWAY.AFTERPAY:
7055
+ this.service = new AfterPayWalletService(chargeToken, _extends(_extends({}, meta), { id: tokenMeta.charge.id, gateway_mode: tokenMeta.gateway.mode, amount: tokenMeta.charge.amount, currency: tokenMeta.charge.currency, reference: tokenMeta.charge.reference }));
7056
+ break;
6638
7057
  }
6639
7058
  }
6640
7059
  /**
@@ -6661,7 +7080,7 @@
6661
7080
  this.setupServiceCallbacks();
6662
7081
  this.service.load(this.container);
6663
7082
  } catch (err) {
6664
- this.eventEmitter.emit(EVENT$2.UNAVAILABLE, null);
7083
+ this.eventEmitter.emit(EVENT$1.UNAVAILABLE, null);
6665
7084
  throw err;
6666
7085
  }
6667
7086
  }
@@ -6781,7 +7200,7 @@
6781
7200
  value: function on(eventName, cb) {
6782
7201
  var _this = this;
6783
7202
 
6784
- if (eventName === EVENT$2.UPDATE) this.hasUpdateHandler = true;
7203
+ if (eventName === EVENT$1.UPDATE) this.hasUpdateHandler = true;
6785
7204
  if (typeof cb === 'function') return this.eventEmitter.subscribe(eventName, cb);
6786
7205
  return new Promise(function (resolve) {
6787
7206
  return _this.eventEmitter.subscribe(eventName, function (res) {
@@ -6813,9 +7232,9 @@
6813
7232
  value: function onUnavailable(handler) {
6814
7233
  var _this2 = this;
6815
7234
 
6816
- if (typeof handler === 'function') return this.eventEmitter.subscribe(EVENT$2.UNAVAILABLE, handler);
7235
+ if (typeof handler === 'function') return this.eventEmitter.subscribe(EVENT$1.UNAVAILABLE, handler);
6817
7236
  return new Promise(function (resolve) {
6818
- return _this2.eventEmitter.subscribe(EVENT$2.UNAVAILABLE, function () {
7237
+ return _this2.eventEmitter.subscribe(EVENT$1.UNAVAILABLE, function () {
6819
7238
  return resolve();
6820
7239
  });
6821
7240
  });
@@ -6842,9 +7261,9 @@
6842
7261
  var _this3 = this;
6843
7262
 
6844
7263
  this.hasUpdateHandler = true;
6845
- if (typeof handler === 'function') return this.eventEmitter.subscribe(EVENT$2.UPDATE, handler);
7264
+ if (typeof handler === 'function') return this.eventEmitter.subscribe(EVENT$1.UPDATE, handler);
6846
7265
  return new Promise(function (resolve) {
6847
- return _this3.eventEmitter.subscribe(EVENT$2.UPDATE, function (data) {
7266
+ return _this3.eventEmitter.subscribe(EVENT$1.UPDATE, function (data) {
6848
7267
  return resolve(data);
6849
7268
  });
6850
7269
  });
@@ -6869,9 +7288,9 @@
6869
7288
  value: function onPaymentSuccessful(handler) {
6870
7289
  var _this4 = this;
6871
7290
 
6872
- if (typeof handler === 'function') return this.eventEmitter.subscribe(EVENT$2.PAYMENT_SUCCESSFUL, handler);
7291
+ if (typeof handler === 'function') return this.eventEmitter.subscribe(EVENT$1.PAYMENT_SUCCESSFUL, handler);
6873
7292
  return new Promise(function (resolve) {
6874
- return _this4.eventEmitter.subscribe(EVENT$2.PAYMENT_SUCCESSFUL, function (data) {
7293
+ return _this4.eventEmitter.subscribe(EVENT$1.PAYMENT_SUCCESSFUL, function (data) {
6875
7294
  return resolve(data);
6876
7295
  });
6877
7296
  });
@@ -6896,9 +7315,9 @@
6896
7315
  value: function onPaymentInReview(handler) {
6897
7316
  var _this5 = this;
6898
7317
 
6899
- if (typeof handler === 'function') return this.eventEmitter.subscribe(EVENT$2.PAYMENT_IN_REVIEW, handler);
7318
+ if (typeof handler === 'function') return this.eventEmitter.subscribe(EVENT$1.PAYMENT_IN_REVIEW, handler);
6900
7319
  return new Promise(function (resolve) {
6901
- return _this5.eventEmitter.subscribe(EVENT$2.PAYMENT_IN_REVIEW, function (data) {
7320
+ return _this5.eventEmitter.subscribe(EVENT$1.PAYMENT_IN_REVIEW, function (data) {
6902
7321
  return resolve(data);
6903
7322
  });
6904
7323
  });
@@ -6923,9 +7342,9 @@
6923
7342
  value: function onPaymentError(handler) {
6924
7343
  var _this6 = this;
6925
7344
 
6926
- if (typeof handler === 'function') return this.eventEmitter.subscribe(EVENT$2.PAYMENT_ERROR, handler);
7345
+ if (typeof handler === 'function') return this.eventEmitter.subscribe(EVENT$1.PAYMENT_ERROR, handler);
6927
7346
  return new Promise(function (resolve) {
6928
- return _this6.eventEmitter.subscribe(EVENT$2.PAYMENT_ERROR, function (err) {
7347
+ return _this6.eventEmitter.subscribe(EVENT$1.PAYMENT_ERROR, function (err) {
6929
7348
  return resolve(err);
6930
7349
  });
6931
7350
  });
@@ -6947,7 +7366,7 @@
6947
7366
  var _this7 = this;
6948
7367
 
6949
7368
  this.service.on(WALLET_EVENT.UNAVAILABLE, function (eventData) {
6950
- return _this7.eventEmitter.emit(EVENT$2.UNAVAILABLE, { event: EVENT$2.UNAVAILABLE, data: eventData });
7369
+ return _this7.eventEmitter.emit(EVENT$1.UNAVAILABLE, { event: EVENT$1.UNAVAILABLE, data: eventData });
6951
7370
  });
6952
7371
  }
6953
7372
  }, {
@@ -6956,7 +7375,7 @@
6956
7375
  var _this8 = this;
6957
7376
 
6958
7377
  this.service.on(WALLET_EVENT.UPDATE, function (eventData) {
6959
- return _this8.hasUpdateHandler ? _this8.eventEmitter.emit(EVENT$2.UPDATE, { event: EVENT$2.UPDATE, data: eventData }) : _this8.update({ success: true });
7378
+ return _this8.hasUpdateHandler ? _this8.eventEmitter.emit(EVENT$1.UPDATE, { event: EVENT$1.UPDATE, data: eventData }) : _this8.update({ success: true });
6960
7379
  });
6961
7380
  }
6962
7381
  }, {
@@ -6988,7 +7407,7 @@
6988
7407
 
6989
7408
  _this10.api.charge().walletCapture(data).then(function (captureResult) {
6990
7409
  if (typeof onSuccess === 'function') onSuccess();
6991
- var event = captureResult.status === 'inreview' ? EVENT$2.PAYMENT_IN_REVIEW : EVENT$2.PAYMENT_SUCCESSFUL;
7410
+ var event = captureResult.status === 'inreview' ? EVENT$1.PAYMENT_IN_REVIEW : EVENT$1.PAYMENT_SUCCESSFUL;
6992
7411
  _this10.eventEmitter.emit(event, {
6993
7412
  event: event,
6994
7413
  data: _extends(_extends({}, captureResult), data.customer && {
@@ -6999,7 +7418,7 @@
6999
7418
  });
7000
7419
  }, function (err) {
7001
7420
  if (typeof onError === 'function') onError(err);
7002
- _this10.eventEmitter.emit(EVENT$2.PAYMENT_ERROR, { event: EVENT$2.PAYMENT_ERROR, data: err });
7421
+ _this10.eventEmitter.emit(EVENT$1.PAYMENT_ERROR, { event: EVENT$1.PAYMENT_ERROR, data: err });
7003
7422
  });
7004
7423
  });
7005
7424
  }
@@ -7009,7 +7428,7 @@
7009
7428
  var _this11 = this;
7010
7429
 
7011
7430
  this.service.on(WALLET_EVENT.PAYMENT_SUCCESS, function (eventData) {
7012
- return _this11.eventEmitter.emit(EVENT$2.PAYMENT_SUCCESSFUL, { event: EVENT$2.PAYMENT_SUCCESSFUL, data: eventData });
7431
+ return _this11.eventEmitter.emit(EVENT$1.PAYMENT_SUCCESSFUL, { event: EVENT$1.PAYMENT_SUCCESSFUL, data: eventData });
7013
7432
  });
7014
7433
  }
7015
7434
  }, {
@@ -7018,7 +7437,7 @@
7018
7437
  var _this12 = this;
7019
7438
 
7020
7439
  this.service.on(WALLET_EVENT.PAYMENT_IN_REVIEW, function (eventData) {
7021
- return _this12.eventEmitter.emit(EVENT$2.PAYMENT_IN_REVIEW, { event: EVENT$2.PAYMENT_IN_REVIEW, data: eventData });
7440
+ return _this12.eventEmitter.emit(EVENT$1.PAYMENT_IN_REVIEW, { event: EVENT$1.PAYMENT_IN_REVIEW, data: eventData });
7022
7441
  });
7023
7442
  }
7024
7443
  }, {
@@ -7027,7 +7446,7 @@
7027
7446
  var _this13 = this;
7028
7447
 
7029
7448
  this.service.on(WALLET_EVENT.PAYMENT_ERROR, function (eventData) {
7030
- return _this13.eventEmitter.emit(EVENT$2.PAYMENT_ERROR, { event: EVENT$2.PAYMENT_ERROR, data: eventData });
7449
+ return _this13.eventEmitter.emit(EVENT$1.PAYMENT_ERROR, { event: EVENT$1.PAYMENT_ERROR, data: eventData });
7031
7450
  });
7032
7451
  }
7033
7452
  }]);
@@ -7446,18 +7865,24 @@
7446
7865
  value: function initializeIFrames(initializationUrl, secondaryUrl, title) {
7447
7866
  var hideAuthorization = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
7448
7867
 
7868
+ var container = this.container.getElement();
7869
+ if (!container) return;
7449
7870
  var divAuthorization = document.createElement("div");
7450
7871
  divAuthorization.setAttribute("id", "paydock_authorization_iframe");
7451
- this.container.getElement().appendChild(divAuthorization);
7872
+ container.appendChild(divAuthorization);
7452
7873
  this.browserAndChallengeContainer = new Container("#paydock_authorization_iframe");
7453
7874
  this.iFrameAuthorization = new IFrame(this.browserAndChallengeContainer);
7454
7875
  this.iFrameAuthorization.load(initializationUrl, { title: title });
7455
- var divSecondaryURL = document.createElement("div");
7456
- divSecondaryURL.setAttribute("id", "paydock_secondary_iframe");
7457
- this.container.getElement().appendChild(divSecondaryURL);
7458
- this.monitoringContainer = new Container("#paydock_secondary_iframe");
7459
- this.iFrameSecondaryUrl = new IFrame(this.monitoringContainer);
7460
- this.iFrameSecondaryUrl.load(secondaryUrl, { title: title });
7876
+ if (secondaryUrl) {
7877
+ var divSecondaryURL = document.createElement("div");
7878
+ divSecondaryURL.setAttribute("id", "paydock_secondary_iframe");
7879
+ container.appendChild(divSecondaryURL);
7880
+ this.monitoringContainer = new Container("#paydock_secondary_iframe");
7881
+ this.iFrameSecondaryUrl = new IFrame(this.monitoringContainer);
7882
+ this.iFrameSecondaryUrl.load(secondaryUrl, { title: title });
7883
+ } else {
7884
+ this.iFrameSecondaryUrl = undefined;
7885
+ }
7461
7886
  this.hideIframes(hideAuthorization);
7462
7887
  }
7463
7888
  }, {
@@ -7465,10 +7890,11 @@
7465
7890
  value: function hideIframes() {
7466
7891
  var hideAuthorization = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
7467
7892
 
7893
+ var _a;
7468
7894
  for (var prop in hiddenStyle) {
7469
7895
  if (!hiddenStyle.hasOwnProperty(prop)) continue;
7470
7896
  if (hideAuthorization) this.iFrameAuthorization.setStyle(prop, hiddenStyle[prop]);
7471
- this.iFrameSecondaryUrl.setStyle(prop, hiddenStyle[prop]);
7897
+ (_a = this.iFrameSecondaryUrl) === null || _a === void 0 ? void 0 : _a.setStyle(prop, hiddenStyle[prop]);
7472
7898
  }
7473
7899
  }
7474
7900
  }, {
@@ -7520,8 +7946,9 @@
7520
7946
  if (this.resultRead) return;
7521
7947
  this.resultRead = true;
7522
7948
  this.api.charge().standalone3dsHandle().then(function (result) {
7949
+ var _a;
7523
7950
  _this2.iFrameAuthorization.remove();
7524
- _this2.iFrameSecondaryUrl.remove();
7951
+ (_a = _this2.iFrameSecondaryUrl) === null || _a === void 0 ? void 0 : _a.remove();
7525
7952
  if (result.status === PROCESS_STANDALONE_3DS_STATUS.SUCCESS) _this2.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_SUCCESS, _this2.parseResultData(result, charge3dsId));else _this2.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_ERROR, _this2.parseResultData(result, charge3dsId));
7526
7953
  }, function (err) {
7527
7954
  _this2.eventEmitter.emit(GPAYMENTS_EVENT.ERROR, _this2.parseError(err, charge3dsId));
@@ -7564,18 +7991,19 @@
7564
7991
 
7565
7992
  var charge_3ds_id = _ref4.charge_3ds_id;
7566
7993
 
7994
+ var _a;
7567
7995
  this.iFrameAuthorization.remove();
7568
- this.iFrameSecondaryUrl.remove();
7996
+ (_a = this.iFrameSecondaryUrl) === null || _a === void 0 ? void 0 : _a.remove();
7569
7997
  this.api.charge().standalone3dsProcess({ charge_3ds_id: charge_3ds_id }).then(function (authenticationResult) {
7570
7998
  var _a, _b;
7571
7999
  if (authenticationResult.status === "success" /* SUCCESS */) _this4.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_SUCCESS, _this4.parseHandleResponse(authenticationResult, charge_3ds_id));else if (authenticationResult.status === "pending" /* PENDING */) {
7572
8000
  if ((_a = authenticationResult === null || authenticationResult === void 0 ? void 0 : authenticationResult.result) === null || _a === void 0 ? void 0 : _a.challenge) {
7573
8001
  _this4.eventEmitter.emit(GPAYMENTS_EVENT.CHALLENGE, _this4.parseHandleResponse(authenticationResult, charge_3ds_id));
7574
- _this4.initializeIFrames(authenticationResult.result.challenge_url, 'authenticationResult.result.secondary_url', 'Authentication Challenge', false);
7575
- _this4.doPolling(authenticationResult.result.secondary_url, charge_3ds_id);
8002
+ _this4.initializeIFrames(authenticationResult.result.challenge_url, undefined, 'Authentication Challenge', false);
8003
+ if (authenticationResult.result.secondary_url) _this4.doPolling(authenticationResult.result.secondary_url, charge_3ds_id);
7576
8004
  } else if ((_b = authenticationResult === null || authenticationResult === void 0 ? void 0 : authenticationResult.result) === null || _b === void 0 ? void 0 : _b.decoupled_challenge) {
7577
8005
  _this4.eventEmitter.emit(GPAYMENTS_EVENT.DECOUPLED, _this4.parseHandleResponse(authenticationResult, charge_3ds_id));
7578
- _this4.doPolling(authenticationResult.result.secondary_url, charge_3ds_id);
8006
+ if (authenticationResult.result.secondary_url) _this4.doPolling(authenticationResult.result.secondary_url, charge_3ds_id);
7579
8007
  }
7580
8008
  } else return _this4.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_ERROR, _this4.parseHandleResponse(authenticationResult, charge_3ds_id));
7581
8009
  }, function (err) {
@@ -8086,7 +8514,7 @@
8086
8514
  * @param {string} CHECKOUT_COMPLETED=checkoutCompleted
8087
8515
  * @param {string} CHECKOUT_ERROR=checkoutError
8088
8516
  */
8089
- var EVENT$3;
8517
+ var EVENT$2;
8090
8518
  (function (EVENT) {
8091
8519
  EVENT["CHECKOUT_BUTTON_LOADED"] = "checkoutButtonLoaded";
8092
8520
  EVENT["CHECKOUT_BUTTON_CLICKED"] = "checkoutButtonClicked";
@@ -8094,7 +8522,7 @@
8094
8522
  EVENT["CHECKOUT_READY"] = "checkoutReady";
8095
8523
  EVENT["CHECKOUT_COMPLETED"] = "checkoutCompleted";
8096
8524
  EVENT["CHECKOUT_ERROR"] = "checkoutError";
8097
- })(EVENT$3 || (EVENT$3 = {}));
8525
+ })(EVENT$2 || (EVENT$2 = {}));
8098
8526
  var STYLE$2 = {
8099
8527
  BUTTON_TEXT_COLOR: 'button_text_color',
8100
8528
  PRIMARY_COLOR: 'primary_color',
@@ -8161,20 +8589,20 @@
8161
8589
  var _this = this;
8162
8590
 
8163
8591
  var widgetId = this.link.getParams().widget_id;
8164
- this.iFrameEvent.on(EVENT$3.CHECKOUT_READY, widgetId, function (_ref) {
8592
+ this.iFrameEvent.on(EVENT$2.CHECKOUT_READY, widgetId, function (_ref) {
8165
8593
  var data = _ref.data;
8166
8594
 
8167
- _this.eventEmitter.emit(EVENT$3.CHECKOUT_READY, data);
8595
+ _this.eventEmitter.emit(EVENT$2.CHECKOUT_READY, data);
8168
8596
  });
8169
- this.iFrameEvent.on(EVENT$3.CHECKOUT_COMPLETED, widgetId, function (_ref2) {
8597
+ this.iFrameEvent.on(EVENT$2.CHECKOUT_COMPLETED, widgetId, function (_ref2) {
8170
8598
  var data = _ref2.data;
8171
8599
 
8172
- _this.eventEmitter.emit(EVENT$3.CHECKOUT_COMPLETED, data);
8600
+ _this.eventEmitter.emit(EVENT$2.CHECKOUT_COMPLETED, data);
8173
8601
  });
8174
- this.iFrameEvent.on(EVENT$3.CHECKOUT_ERROR, widgetId, function (_ref3) {
8602
+ this.iFrameEvent.on(EVENT$2.CHECKOUT_ERROR, widgetId, function (_ref3) {
8175
8603
  var data = _ref3.data;
8176
8604
 
8177
- _this.eventEmitter.emit(EVENT$3.CHECKOUT_ERROR, data);
8605
+ _this.eventEmitter.emit(EVENT$2.CHECKOUT_ERROR, data);
8178
8606
  });
8179
8607
  if (this.autoResize) this.useAutoResize(true);
8180
8608
  }
@@ -8202,10 +8630,10 @@
8202
8630
  clickToPayAllCards.setAttribute('style', VisaSRCStyles.clickToPayAllCardsStyle);
8203
8631
  clickToPayAllCards.src = this.link.getBaseUrl() + ('' + GenerateCardSchemesLogo((_a = this.meta.customizations) === null || _a === void 0 ? void 0 : _a.card_schemes, true));
8204
8632
  checkoutButton.onclick = function () {
8205
- _this2.eventEmitter.emit(EVENT$3.CHECKOUT_BUTTON_CLICKED, {});
8633
+ _this2.eventEmitter.emit(EVENT$2.CHECKOUT_BUTTON_CLICKED, {});
8206
8634
  _this2.iFrame.load(_this2.link.getUrl(), { title: 'Visa SRC checkout' });
8207
8635
  _this2.iFrame.getElement().onload = function () {
8208
- return _this2.eventEmitter.emit(EVENT$3.IFRAME_LOADED, {});
8636
+ return _this2.eventEmitter.emit(EVENT$2.IFRAME_LOADED, {});
8209
8637
  };
8210
8638
  };
8211
8639
  container.appendChild(checkoutButton);
@@ -8213,7 +8641,7 @@
8213
8641
  footerContainer.appendChild(footerText);
8214
8642
  footerContainer.appendChild(clickToPayAllCards);
8215
8643
  this.buttonContainer.getElement().appendChild(container);
8216
- this.eventEmitter.emit(EVENT$3.CHECKOUT_BUTTON_LOADED, {});
8644
+ this.eventEmitter.emit(EVENT$2.CHECKOUT_BUTTON_LOADED, {});
8217
8645
  }
8218
8646
  }, {
8219
8647
  key: 'getEnv',
@@ -8532,7 +8960,6 @@
8532
8960
  exports.Api = Api;
8533
8961
  exports.CHECKOUT_BUTTON_EVENT = CHECKOUT_BUTTON_EVENT;
8534
8962
  exports.Canvas3ds = Canvas3ds;
8535
- exports.CheckoutButton = CheckoutButton;
8536
8963
  exports.Configuration = Configuration;
8537
8964
  exports.ELEMENT = ELEMENT;
8538
8965
  exports.EVENT = EVENT;