@paystack/inline-js 2.29.0-dev.1 → 2.29.0-dev.3

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.
package/dist/inline.js CHANGED
@@ -858,17 +858,9 @@ var PaystackPop = (function () {
858
858
  var merchantInfo = googlePayConfig.registered_merchant_info || {};
859
859
  return {
860
860
  merchantId: merchantInfo.merchantId,
861
- merchantName: merchantInfo.merchantName,
862
- merchantOrigin: merchantInfo.merchantOrigin
861
+ merchantName: merchantInfo.merchantName
863
862
  };
864
863
  };
865
- var warnOnOriginMismatch = function warnOnOriginMismatch(googlePayConfig) {
866
- var registeredOrigin = googlePayConfig.registered_merchant_info && googlePayConfig.registered_merchant_info.merchantOrigin;
867
- var hostname = window.location.hostname;
868
- if (registeredOrigin && registeredOrigin !== hostname) {
869
- logWarning("Google Pay: the registered merchantOrigin (\"".concat(registeredOrigin, "\") does not match this page (\"").concat(hostname, "\"). Google may reject the payment sheet. Update the domain in Dashboard > Developers > Google Pay."));
870
- }
871
- };
872
864
  var buildPaymentDataRequest = function buildPaymentDataRequest(transaction) {
873
865
  var googlePayConfig = getGooglePayConfig(transaction);
874
866
  var response = transaction.response;
@@ -916,7 +908,6 @@ var PaystackPop = (function () {
916
908
  if (!authMethods.length || !googlePayConfig.tokenization_specification || !hasGooglePaySDKLoaded()) {
917
909
  return Promise.resolve(null);
918
910
  }
919
- warnOnOriginMismatch(googlePayConfig);
920
911
  var readiness = Promise.resolve().then(function () {
921
912
  var client = getGooglePayClient(resolveGooglePayEnvironment(transaction.response));
922
913
  return client.isReadyToPay(_objectSpread2(_objectSpread2({}, buildBaseRequest(googlePayConfig)), {}, {
@@ -1978,6 +1969,11 @@ var PaystackPop = (function () {
1978
1969
  _excluded2 = ["container", "styles", "onElementsMount"],
1979
1970
  _excluded3 = ["data"];
1980
1971
  var inlineInstance;
1972
+ var CHECKOUT_ORIGIN = new URL(config.checkoutUrl).origin;
1973
+ var SITE_ORIGIN = new URL(config.siteUrl).origin;
1974
+ function postToCheckout(checkoutIframe, message) {
1975
+ checkoutIframe.contentWindow.postMessage(message, CHECKOUT_ORIGIN);
1976
+ }
1981
1977
  function findResumableTransaction(transactions, parameters) {
1982
1978
  if (!transactions.length) {
1983
1979
  return null;
@@ -1996,11 +1992,11 @@ var PaystackPop = (function () {
1996
1992
  if (!checkoutIframe || !urlParameters) {
1997
1993
  return;
1998
1994
  }
1999
- checkoutIframe.contentWindow.postMessage({
1995
+ postToCheckout(checkoutIframe, {
2000
1996
  type: 'inline:url',
2001
1997
  path: 'newTransaction',
2002
1998
  params: urlParameters
2003
- }, '*');
1999
+ });
2004
2000
  }
2005
2001
  var analyticsActions = {
2006
2002
  TRACK_PAYMENT_ERROR: 'trackPaymentError',
@@ -2020,6 +2016,7 @@ var PaystackPop = (function () {
2020
2016
  this.isLoaded = false;
2021
2017
  this.isCharging = false;
2022
2018
  this.isDeprecatedApi = params && params.isDeprecatedApi; // track deprecatedApi
2019
+ this.embedIframes = [];
2023
2020
  if (params && params.isEmbed) {
2024
2021
  this.isEmbed = true;
2025
2022
  } else if (params && params.isPaymentRequest) {
@@ -2038,12 +2035,13 @@ var PaystackPop = (function () {
2038
2035
  value: function registerListeners() {
2039
2036
  var _this = this;
2040
2037
  window.addEventListener('message', function (event) {
2041
- var isCheckoutIframe = "".concat(event.origin, "/") === config.checkoutUrl;
2042
- var isThisInline = _this.checkoutIframe && _this.checkoutIframe.contentWindow === event.source;
2043
- var isEmbed = _this.isEmbed;
2044
- if (isCheckoutIframe || isThisInline) {
2038
+ var isFromThisCheckout = event.origin === CHECKOUT_ORIGIN && _this.checkoutIframe && _this.checkoutIframe.contentWindow === event.source;
2039
+ var isFromThisEmbed = event.origin === SITE_ORIGIN && _this.embedIframes.some(function (iframe) {
2040
+ return iframe.contentWindow === event.source;
2041
+ });
2042
+ if (isFromThisCheckout) {
2045
2043
  _this.respondToEvent(event);
2046
- } else if (isEmbed) {
2044
+ } else if (isFromThisEmbed) {
2047
2045
  _this.respondToEmbedEvents(event);
2048
2046
  }
2049
2047
  });
@@ -2051,11 +2049,11 @@ var PaystackPop = (function () {
2051
2049
  }, {
2052
2050
  key: "sendAnalyticsEventToCheckout",
2053
2051
  value: function sendAnalyticsEventToCheckout(action, params) {
2054
- this.checkoutIframe.contentWindow.postMessage({
2052
+ postToCheckout(this.checkoutIframe, {
2055
2053
  type: 'analytics',
2056
2054
  action: action,
2057
2055
  params: params
2058
- }, '*');
2056
+ });
2059
2057
  }
2060
2058
  }, {
2061
2059
  key: "checkout",
@@ -2585,7 +2583,7 @@ var PaystackPop = (function () {
2585
2583
  checkoutIframe: checkoutIframe,
2586
2584
  backgroundIframe: backgroundIframe
2587
2585
  }).then(function () {
2588
- _this6.checkoutIframe.contentWindow.postMessage('render', '*');
2586
+ postToCheckout(_this6.checkoutIframe, 'render');
2589
2587
  });
2590
2588
  this.isOpen = true;
2591
2589
  }
@@ -2618,7 +2616,7 @@ var PaystackPop = (function () {
2618
2616
  checkoutIframe: checkoutIframe,
2619
2617
  backgroundIframe: backgroundIframe
2620
2618
  }).then(function () {
2621
- _this7.checkoutIframe.contentWindow.postMessage('close', '*');
2619
+ postToCheckout(_this7.checkoutIframe, 'close');
2622
2620
  });
2623
2621
  this.isOpen = false;
2624
2622
  }
@@ -2644,9 +2642,10 @@ var PaystackPop = (function () {
2644
2642
  if (isEmbed) {
2645
2643
  var inlineUrl = "".concat(config.siteUrl, "/assets/payment/production/inline.html?").concat(serialize(urlParameters));
2646
2644
  var iframe = mountEmbedCheckoutIframe(inlineInstance.id, inlineUrl);
2645
+ inlineInstance.embedIframes.push(iframe);
2647
2646
  appendIframeToContainer(parameters.container, iframe);
2648
2647
  iframe.onload = function onLoad() {
2649
- iframe.contentWindow.postMessage("PaystackOpen ".concat(inlineInstance.id), '*');
2648
+ iframe.contentWindow.postMessage("PaystackOpen ".concat(inlineInstance.id), SITE_ORIGIN);
2650
2649
  animateEmbedCheckoutIn(iframe);
2651
2650
  };
2652
2651
  } else {
package/es/inline.js CHANGED
@@ -855,17 +855,9 @@ var buildMerchantInfo = function buildMerchantInfo(googlePayConfig) {
855
855
  var merchantInfo = googlePayConfig.registered_merchant_info || {};
856
856
  return {
857
857
  merchantId: merchantInfo.merchantId,
858
- merchantName: merchantInfo.merchantName,
859
- merchantOrigin: merchantInfo.merchantOrigin
858
+ merchantName: merchantInfo.merchantName
860
859
  };
861
860
  };
862
- var warnOnOriginMismatch = function warnOnOriginMismatch(googlePayConfig) {
863
- var registeredOrigin = googlePayConfig.registered_merchant_info && googlePayConfig.registered_merchant_info.merchantOrigin;
864
- var hostname = window.location.hostname;
865
- if (registeredOrigin && registeredOrigin !== hostname) {
866
- logWarning("Google Pay: the registered merchantOrigin (\"".concat(registeredOrigin, "\") does not match this page (\"").concat(hostname, "\"). Google may reject the payment sheet. Update the domain in Dashboard > Developers > Google Pay."));
867
- }
868
- };
869
861
  var buildPaymentDataRequest = function buildPaymentDataRequest(transaction) {
870
862
  var googlePayConfig = getGooglePayConfig(transaction);
871
863
  var response = transaction.response;
@@ -913,7 +905,6 @@ var canUseGooglePay = function canUseGooglePay(transaction) {
913
905
  if (!authMethods.length || !googlePayConfig.tokenization_specification || !hasGooglePaySDKLoaded()) {
914
906
  return Promise.resolve(null);
915
907
  }
916
- warnOnOriginMismatch(googlePayConfig);
917
908
  var readiness = Promise.resolve().then(function () {
918
909
  var client = getGooglePayClient(resolveGooglePayEnvironment(transaction.response));
919
910
  return client.isReadyToPay(_objectSpread2(_objectSpread2({}, buildBaseRequest(googlePayConfig)), {}, {
@@ -1975,6 +1966,11 @@ var _excluded = ["preload", "inlineTransaction", "transactionData"],
1975
1966
  _excluded2 = ["container", "styles", "onElementsMount"],
1976
1967
  _excluded3 = ["data"];
1977
1968
  var inlineInstance;
1969
+ var CHECKOUT_ORIGIN = new URL(config.checkoutUrl).origin;
1970
+ var SITE_ORIGIN = new URL(config.siteUrl).origin;
1971
+ function postToCheckout(checkoutIframe, message) {
1972
+ checkoutIframe.contentWindow.postMessage(message, CHECKOUT_ORIGIN);
1973
+ }
1978
1974
  function findResumableTransaction(transactions, parameters) {
1979
1975
  if (!transactions.length) {
1980
1976
  return null;
@@ -1993,11 +1989,11 @@ function notifyIframeToUpdateURL(options) {
1993
1989
  if (!checkoutIframe || !urlParameters) {
1994
1990
  return;
1995
1991
  }
1996
- checkoutIframe.contentWindow.postMessage({
1992
+ postToCheckout(checkoutIframe, {
1997
1993
  type: 'inline:url',
1998
1994
  path: 'newTransaction',
1999
1995
  params: urlParameters
2000
- }, '*');
1996
+ });
2001
1997
  }
2002
1998
  var analyticsActions = {
2003
1999
  TRACK_PAYMENT_ERROR: 'trackPaymentError',
@@ -2017,6 +2013,7 @@ var Inline = /*#__PURE__*/function () {
2017
2013
  this.isLoaded = false;
2018
2014
  this.isCharging = false;
2019
2015
  this.isDeprecatedApi = params && params.isDeprecatedApi; // track deprecatedApi
2016
+ this.embedIframes = [];
2020
2017
  if (params && params.isEmbed) {
2021
2018
  this.isEmbed = true;
2022
2019
  } else if (params && params.isPaymentRequest) {
@@ -2035,12 +2032,13 @@ var Inline = /*#__PURE__*/function () {
2035
2032
  value: function registerListeners() {
2036
2033
  var _this = this;
2037
2034
  window.addEventListener('message', function (event) {
2038
- var isCheckoutIframe = "".concat(event.origin, "/") === config.checkoutUrl;
2039
- var isThisInline = _this.checkoutIframe && _this.checkoutIframe.contentWindow === event.source;
2040
- var isEmbed = _this.isEmbed;
2041
- if (isCheckoutIframe || isThisInline) {
2035
+ var isFromThisCheckout = event.origin === CHECKOUT_ORIGIN && _this.checkoutIframe && _this.checkoutIframe.contentWindow === event.source;
2036
+ var isFromThisEmbed = event.origin === SITE_ORIGIN && _this.embedIframes.some(function (iframe) {
2037
+ return iframe.contentWindow === event.source;
2038
+ });
2039
+ if (isFromThisCheckout) {
2042
2040
  _this.respondToEvent(event);
2043
- } else if (isEmbed) {
2041
+ } else if (isFromThisEmbed) {
2044
2042
  _this.respondToEmbedEvents(event);
2045
2043
  }
2046
2044
  });
@@ -2048,11 +2046,11 @@ var Inline = /*#__PURE__*/function () {
2048
2046
  }, {
2049
2047
  key: "sendAnalyticsEventToCheckout",
2050
2048
  value: function sendAnalyticsEventToCheckout(action, params) {
2051
- this.checkoutIframe.contentWindow.postMessage({
2049
+ postToCheckout(this.checkoutIframe, {
2052
2050
  type: 'analytics',
2053
2051
  action: action,
2054
2052
  params: params
2055
- }, '*');
2053
+ });
2056
2054
  }
2057
2055
  }, {
2058
2056
  key: "checkout",
@@ -2582,7 +2580,7 @@ var Inline = /*#__PURE__*/function () {
2582
2580
  checkoutIframe: checkoutIframe,
2583
2581
  backgroundIframe: backgroundIframe
2584
2582
  }).then(function () {
2585
- _this6.checkoutIframe.contentWindow.postMessage('render', '*');
2583
+ postToCheckout(_this6.checkoutIframe, 'render');
2586
2584
  });
2587
2585
  this.isOpen = true;
2588
2586
  }
@@ -2615,7 +2613,7 @@ var Inline = /*#__PURE__*/function () {
2615
2613
  checkoutIframe: checkoutIframe,
2616
2614
  backgroundIframe: backgroundIframe
2617
2615
  }).then(function () {
2618
- _this7.checkoutIframe.contentWindow.postMessage('close', '*');
2616
+ postToCheckout(_this7.checkoutIframe, 'close');
2619
2617
  });
2620
2618
  this.isOpen = false;
2621
2619
  }
@@ -2641,9 +2639,10 @@ var Inline = /*#__PURE__*/function () {
2641
2639
  if (isEmbed) {
2642
2640
  var inlineUrl = "".concat(config.siteUrl, "/assets/payment/production/inline.html?").concat(serialize(urlParameters));
2643
2641
  var iframe = mountEmbedCheckoutIframe(inlineInstance.id, inlineUrl);
2642
+ inlineInstance.embedIframes.push(iframe);
2644
2643
  appendIframeToContainer(parameters.container, iframe);
2645
2644
  iframe.onload = function onLoad() {
2646
- iframe.contentWindow.postMessage("PaystackOpen ".concat(inlineInstance.id), '*');
2645
+ iframe.contentWindow.postMessage("PaystackOpen ".concat(inlineInstance.id), SITE_ORIGIN);
2647
2646
  animateEmbedCheckoutIn(iframe);
2648
2647
  };
2649
2648
  } else {
package/lib/inline.js CHANGED
@@ -857,17 +857,9 @@ var buildMerchantInfo = function buildMerchantInfo(googlePayConfig) {
857
857
  var merchantInfo = googlePayConfig.registered_merchant_info || {};
858
858
  return {
859
859
  merchantId: merchantInfo.merchantId,
860
- merchantName: merchantInfo.merchantName,
861
- merchantOrigin: merchantInfo.merchantOrigin
860
+ merchantName: merchantInfo.merchantName
862
861
  };
863
862
  };
864
- var warnOnOriginMismatch = function warnOnOriginMismatch(googlePayConfig) {
865
- var registeredOrigin = googlePayConfig.registered_merchant_info && googlePayConfig.registered_merchant_info.merchantOrigin;
866
- var hostname = window.location.hostname;
867
- if (registeredOrigin && registeredOrigin !== hostname) {
868
- logWarning("Google Pay: the registered merchantOrigin (\"".concat(registeredOrigin, "\") does not match this page (\"").concat(hostname, "\"). Google may reject the payment sheet. Update the domain in Dashboard > Developers > Google Pay."));
869
- }
870
- };
871
863
  var buildPaymentDataRequest = function buildPaymentDataRequest(transaction) {
872
864
  var googlePayConfig = getGooglePayConfig(transaction);
873
865
  var response = transaction.response;
@@ -915,7 +907,6 @@ var canUseGooglePay = function canUseGooglePay(transaction) {
915
907
  if (!authMethods.length || !googlePayConfig.tokenization_specification || !hasGooglePaySDKLoaded()) {
916
908
  return Promise.resolve(null);
917
909
  }
918
- warnOnOriginMismatch(googlePayConfig);
919
910
  var readiness = Promise.resolve().then(function () {
920
911
  var client = getGooglePayClient(resolveGooglePayEnvironment(transaction.response));
921
912
  return client.isReadyToPay(_objectSpread2(_objectSpread2({}, buildBaseRequest(googlePayConfig)), {}, {
@@ -1977,6 +1968,11 @@ var _excluded = ["preload", "inlineTransaction", "transactionData"],
1977
1968
  _excluded2 = ["container", "styles", "onElementsMount"],
1978
1969
  _excluded3 = ["data"];
1979
1970
  var inlineInstance;
1971
+ var CHECKOUT_ORIGIN = new URL(config.checkoutUrl).origin;
1972
+ var SITE_ORIGIN = new URL(config.siteUrl).origin;
1973
+ function postToCheckout(checkoutIframe, message) {
1974
+ checkoutIframe.contentWindow.postMessage(message, CHECKOUT_ORIGIN);
1975
+ }
1980
1976
  function findResumableTransaction(transactions, parameters) {
1981
1977
  if (!transactions.length) {
1982
1978
  return null;
@@ -1995,11 +1991,11 @@ function notifyIframeToUpdateURL(options) {
1995
1991
  if (!checkoutIframe || !urlParameters) {
1996
1992
  return;
1997
1993
  }
1998
- checkoutIframe.contentWindow.postMessage({
1994
+ postToCheckout(checkoutIframe, {
1999
1995
  type: 'inline:url',
2000
1996
  path: 'newTransaction',
2001
1997
  params: urlParameters
2002
- }, '*');
1998
+ });
2003
1999
  }
2004
2000
  var analyticsActions = {
2005
2001
  TRACK_PAYMENT_ERROR: 'trackPaymentError',
@@ -2019,6 +2015,7 @@ var Inline = /*#__PURE__*/function () {
2019
2015
  this.isLoaded = false;
2020
2016
  this.isCharging = false;
2021
2017
  this.isDeprecatedApi = params && params.isDeprecatedApi; // track deprecatedApi
2018
+ this.embedIframes = [];
2022
2019
  if (params && params.isEmbed) {
2023
2020
  this.isEmbed = true;
2024
2021
  } else if (params && params.isPaymentRequest) {
@@ -2037,12 +2034,13 @@ var Inline = /*#__PURE__*/function () {
2037
2034
  value: function registerListeners() {
2038
2035
  var _this = this;
2039
2036
  window.addEventListener('message', function (event) {
2040
- var isCheckoutIframe = "".concat(event.origin, "/") === config.checkoutUrl;
2041
- var isThisInline = _this.checkoutIframe && _this.checkoutIframe.contentWindow === event.source;
2042
- var isEmbed = _this.isEmbed;
2043
- if (isCheckoutIframe || isThisInline) {
2037
+ var isFromThisCheckout = event.origin === CHECKOUT_ORIGIN && _this.checkoutIframe && _this.checkoutIframe.contentWindow === event.source;
2038
+ var isFromThisEmbed = event.origin === SITE_ORIGIN && _this.embedIframes.some(function (iframe) {
2039
+ return iframe.contentWindow === event.source;
2040
+ });
2041
+ if (isFromThisCheckout) {
2044
2042
  _this.respondToEvent(event);
2045
- } else if (isEmbed) {
2043
+ } else if (isFromThisEmbed) {
2046
2044
  _this.respondToEmbedEvents(event);
2047
2045
  }
2048
2046
  });
@@ -2050,11 +2048,11 @@ var Inline = /*#__PURE__*/function () {
2050
2048
  }, {
2051
2049
  key: "sendAnalyticsEventToCheckout",
2052
2050
  value: function sendAnalyticsEventToCheckout(action, params) {
2053
- this.checkoutIframe.contentWindow.postMessage({
2051
+ postToCheckout(this.checkoutIframe, {
2054
2052
  type: 'analytics',
2055
2053
  action: action,
2056
2054
  params: params
2057
- }, '*');
2055
+ });
2058
2056
  }
2059
2057
  }, {
2060
2058
  key: "checkout",
@@ -2584,7 +2582,7 @@ var Inline = /*#__PURE__*/function () {
2584
2582
  checkoutIframe: checkoutIframe,
2585
2583
  backgroundIframe: backgroundIframe
2586
2584
  }).then(function () {
2587
- _this6.checkoutIframe.contentWindow.postMessage('render', '*');
2585
+ postToCheckout(_this6.checkoutIframe, 'render');
2588
2586
  });
2589
2587
  this.isOpen = true;
2590
2588
  }
@@ -2617,7 +2615,7 @@ var Inline = /*#__PURE__*/function () {
2617
2615
  checkoutIframe: checkoutIframe,
2618
2616
  backgroundIframe: backgroundIframe
2619
2617
  }).then(function () {
2620
- _this7.checkoutIframe.contentWindow.postMessage('close', '*');
2618
+ postToCheckout(_this7.checkoutIframe, 'close');
2621
2619
  });
2622
2620
  this.isOpen = false;
2623
2621
  }
@@ -2643,9 +2641,10 @@ var Inline = /*#__PURE__*/function () {
2643
2641
  if (isEmbed) {
2644
2642
  var inlineUrl = "".concat(config.siteUrl, "/assets/payment/production/inline.html?").concat(serialize(urlParameters));
2645
2643
  var iframe = mountEmbedCheckoutIframe(inlineInstance.id, inlineUrl);
2644
+ inlineInstance.embedIframes.push(iframe);
2646
2645
  appendIframeToContainer(parameters.container, iframe);
2647
2646
  iframe.onload = function onLoad() {
2648
- iframe.contentWindow.postMessage("PaystackOpen ".concat(inlineInstance.id), '*');
2647
+ iframe.contentWindow.postMessage("PaystackOpen ".concat(inlineInstance.id), SITE_ORIGIN);
2649
2648
  animateEmbedCheckoutIn(iframe);
2650
2649
  };
2651
2650
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paystack/inline-js",
3
- "version": "2.29.0-dev.1",
3
+ "version": "2.29.0-dev.3",
4
4
  "description": "Client-side library to load the Paystack checkout form",
5
5
  "packageManager": "pnpm@10.33.4+sha512.1c67b3b359b2d408119ba1ed289f34b8fc3c6873412bec6fd264fbdc82489e510fcbecb9ce9d22dae7f3b76269d8441046014bdca53b9979cd7a561ad631b800",
6
6
  "main": "lib/inline.js",