@paystack/inline-js 2.26.0-dev.5 → 2.26.0-dev.6

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
@@ -592,22 +592,22 @@ var PaystackPop = (function () {
592
592
  logWarning("\"".concat(oldName, "\" has been deprecated, please use \"").concat(newName, "\". ").concat(extraMessage || ''));
593
593
  }
594
594
 
595
- var withTimeoutDeadline = function withTimeoutDeadline(work, deadlineInMilliseconds) {
595
+ var withTimeoutDelay = function withTimeoutDelay(work, delayInMilliseconds) {
596
596
  var onTimeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
597
597
  return null;
598
598
  };
599
- var timer;
600
- var deadline = new Promise(function (resolve) {
601
- timer = setTimeout(function () {
599
+ var timeout;
600
+ var delay = new Promise(function (resolve) {
601
+ timeout = setTimeout(function () {
602
602
  try {
603
603
  resolve(onTimeout());
604
604
  } catch (error) {
605
605
  resolve(null);
606
606
  }
607
- }, deadlineInMilliseconds);
607
+ }, delayInMilliseconds);
608
608
  });
609
- return Promise.race([work, deadline]).finally(function () {
610
- return clearTimeout(timer);
609
+ return Promise.race([work, delay]).finally(function () {
610
+ return clearTimeout(timeout);
611
611
  });
612
612
  };
613
613
 
@@ -687,6 +687,7 @@ var PaystackPop = (function () {
687
687
  })],
688
688
  transactionInfo: {
689
689
  totalPriceStatus: 'FINAL',
690
+ checkoutOption: 'COMPLETE_IMMEDIATE_PURCHASE',
690
691
  totalPrice: amountSubunitToBase(getChannelAmount(response, CHANNELS.GOOGLE_PAY)).toFixed(2),
691
692
  currencyCode: response.currency,
692
693
  countryCode: CURRENCY_COUNTRYCODE_MAPPING[response.currency] || COUNTRYCODE.NIGERIA
@@ -717,7 +718,6 @@ var PaystackPop = (function () {
717
718
  var canUseGooglePay = function canUseGooglePay(transaction) {
718
719
  var googlePayConfig = getGooglePayConfig(transaction);
719
720
  if (!googlePayConfig) {
720
- logWarning('Google Pay: no merchant configuration on this transaction. Add your merchant details in Dashboard > Developers > Google Pay.');
721
721
  return Promise.resolve(null);
722
722
  }
723
723
  var authMethods = getSupportedAuthMethods(googlePayConfig);
@@ -748,7 +748,7 @@ var PaystackPop = (function () {
748
748
  var loadSdk = hasGooglePaySDKLoaded() ? Promise.resolve(true) : loadScript(GOOGLE_PAY_SDK_SOURCE).then(function () {
749
749
  return hasGooglePaySDKLoaded();
750
750
  });
751
- return withTimeoutDeadline(loadSdk.catch(function () {
751
+ return withTimeoutDelay(loadSdk.catch(function () {
752
752
  return false;
753
753
  }).then(function (loaded) {
754
754
  if (!loaded) {
@@ -1026,12 +1026,6 @@ var PaystackPop = (function () {
1026
1026
  innerWrapper.id = 'paystack-payment-request-inner-wrapper';
1027
1027
  innerWrapper.style.display = 'none';
1028
1028
  container.appendChild(innerWrapper);
1029
- var revealWrapper = function revealWrapper(button) {
1030
- if (button) {
1031
- innerWrapper.style.display = '';
1032
- }
1033
- return button;
1034
- };
1035
1029
  var applePayOptions = {
1036
1030
  styles: parseApplePayCustomStyles(styles.applePay),
1037
1031
  theme: styles.theme,
@@ -1044,7 +1038,7 @@ var PaystackPop = (function () {
1044
1038
  return mountApplePayButton(innerWrapper, applePayOptions);
1045
1039
  }).catch(function () {
1046
1040
  return mountApplePayFallbackButton(innerWrapper, applePayOptions);
1047
- }).then(revealWrapper).catch(function () {
1041
+ }).catch(function () {
1048
1042
  return null;
1049
1043
  });
1050
1044
  } else if (channels.includes(CHANNELS.APPLE_PAY)) {
@@ -1059,7 +1053,7 @@ var PaystackPop = (function () {
1059
1053
  styles: styles,
1060
1054
  onClick: onClickGooglePayButton
1061
1055
  });
1062
- }).then(revealWrapper).catch(function () {
1056
+ }).catch(function () {
1063
1057
  return null;
1064
1058
  });
1065
1059
  return Promise.all([applePayButton, googlePayButton]).then(function (_ref6) {
@@ -1069,6 +1063,7 @@ var PaystackPop = (function () {
1069
1063
  if (!applePay && !googlePay) {
1070
1064
  return null;
1071
1065
  }
1066
+ innerWrapper.style.display = '';
1072
1067
  return {
1073
1068
  applePay: !!applePay,
1074
1069
  googlePay: !!googlePay
@@ -1981,10 +1976,10 @@ var PaystackPop = (function () {
1981
1976
  transaction: transaction,
1982
1977
  styles: styles,
1983
1978
  onClickApplePayButton: function onClickApplePayButton() {
1984
- return _this3.startApplePay();
1979
+ return _this3.startApplePay(transaction);
1985
1980
  },
1986
1981
  onClickGooglePayButton: function onClickGooglePayButton() {
1987
- return _this3.startGooglePay();
1982
+ return _this3.startGooglePay(transaction);
1988
1983
  }
1989
1984
  }).then(function (mountedElements) {
1990
1985
  if (onElementsMount) {
@@ -2022,10 +2017,14 @@ var PaystackPop = (function () {
2022
2017
  }
2023
2018
  }, {
2024
2019
  key: "startGooglePay",
2025
- value: function startGooglePay() {
2020
+ value: function startGooglePay(inlineTransaction) {
2026
2021
  var _this4 = this;
2027
2022
  var paymentMethod = 'google pay';
2028
- var transaction = this.activeTransaction();
2023
+ var transaction = inlineTransaction || this.activeTransaction();
2024
+ if (inlineTransaction && !inlineTransaction.isActive) {
2025
+ logWarning('Google Pay: this button belongs to a transaction that is no longer active.');
2026
+ return Promise.resolve();
2027
+ }
2029
2028
  if (transaction && transaction.response) {
2030
2029
  if (this.isCharging) {
2031
2030
  return Promise.resolve();
@@ -2119,8 +2118,12 @@ var PaystackPop = (function () {
2119
2118
  });
2120
2119
  } catch (error) {
2121
2120
  this.isCharging = false;
2121
+ logWarning('Google Pay: could not start the charge.');
2122
2122
  notifyMerchant(function () {
2123
- return transaction.onSetupError(error);
2123
+ return transaction.onSetupError({
2124
+ status: false,
2125
+ message: 'Could not complete the Google Pay payment'
2126
+ });
2124
2127
  });
2125
2128
  return Promise.resolve();
2126
2129
  }
@@ -2131,10 +2134,14 @@ var PaystackPop = (function () {
2131
2134
  }
2132
2135
  }, {
2133
2136
  key: "startApplePay",
2134
- value: function startApplePay() {
2137
+ value: function startApplePay(inlineTransaction) {
2135
2138
  var _this5 = this;
2136
2139
  var paymentMethod = 'apple pay';
2137
- var transaction = this.activeTransaction();
2140
+ var transaction = inlineTransaction || this.activeTransaction();
2141
+ if (inlineTransaction && !inlineTransaction.isActive) {
2142
+ logWarning('Apple Pay: this button belongs to a transaction that is no longer active.');
2143
+ return;
2144
+ }
2138
2145
  if (transaction && transaction.response) {
2139
2146
  if (this.isCharging) {
2140
2147
  return;
package/es/inline.js CHANGED
@@ -589,22 +589,22 @@ function printDeprecationNotice(oldName, newName, extraMessage) {
589
589
  logWarning("\"".concat(oldName, "\" has been deprecated, please use \"").concat(newName, "\". ").concat(extraMessage || ''));
590
590
  }
591
591
 
592
- var withTimeoutDeadline = function withTimeoutDeadline(work, deadlineInMilliseconds) {
592
+ var withTimeoutDelay = function withTimeoutDelay(work, delayInMilliseconds) {
593
593
  var onTimeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
594
594
  return null;
595
595
  };
596
- var timer;
597
- var deadline = new Promise(function (resolve) {
598
- timer = setTimeout(function () {
596
+ var timeout;
597
+ var delay = new Promise(function (resolve) {
598
+ timeout = setTimeout(function () {
599
599
  try {
600
600
  resolve(onTimeout());
601
601
  } catch (error) {
602
602
  resolve(null);
603
603
  }
604
- }, deadlineInMilliseconds);
604
+ }, delayInMilliseconds);
605
605
  });
606
- return Promise.race([work, deadline]).finally(function () {
607
- return clearTimeout(timer);
606
+ return Promise.race([work, delay]).finally(function () {
607
+ return clearTimeout(timeout);
608
608
  });
609
609
  };
610
610
 
@@ -684,6 +684,7 @@ var buildPaymentDataRequest = function buildPaymentDataRequest(transaction) {
684
684
  })],
685
685
  transactionInfo: {
686
686
  totalPriceStatus: 'FINAL',
687
+ checkoutOption: 'COMPLETE_IMMEDIATE_PURCHASE',
687
688
  totalPrice: amountSubunitToBase(getChannelAmount(response, CHANNELS.GOOGLE_PAY)).toFixed(2),
688
689
  currencyCode: response.currency,
689
690
  countryCode: CURRENCY_COUNTRYCODE_MAPPING[response.currency] || COUNTRYCODE.NIGERIA
@@ -714,7 +715,6 @@ var chargeGooglePay = function chargeGooglePay(_ref) {
714
715
  var canUseGooglePay = function canUseGooglePay(transaction) {
715
716
  var googlePayConfig = getGooglePayConfig(transaction);
716
717
  if (!googlePayConfig) {
717
- logWarning('Google Pay: no merchant configuration on this transaction. Add your merchant details in Dashboard > Developers > Google Pay.');
718
718
  return Promise.resolve(null);
719
719
  }
720
720
  var authMethods = getSupportedAuthMethods(googlePayConfig);
@@ -745,7 +745,7 @@ var loadGooglePay = function loadGooglePay(transaction) {
745
745
  var loadSdk = hasGooglePaySDKLoaded() ? Promise.resolve(true) : loadScript(GOOGLE_PAY_SDK_SOURCE).then(function () {
746
746
  return hasGooglePaySDKLoaded();
747
747
  });
748
- return withTimeoutDeadline(loadSdk.catch(function () {
748
+ return withTimeoutDelay(loadSdk.catch(function () {
749
749
  return false;
750
750
  }).then(function (loaded) {
751
751
  if (!loaded) {
@@ -1023,12 +1023,6 @@ function mountPaymentRequestButtons(container, _ref5) {
1023
1023
  innerWrapper.id = 'paystack-payment-request-inner-wrapper';
1024
1024
  innerWrapper.style.display = 'none';
1025
1025
  container.appendChild(innerWrapper);
1026
- var revealWrapper = function revealWrapper(button) {
1027
- if (button) {
1028
- innerWrapper.style.display = '';
1029
- }
1030
- return button;
1031
- };
1032
1026
  var applePayOptions = {
1033
1027
  styles: parseApplePayCustomStyles(styles.applePay),
1034
1028
  theme: styles.theme,
@@ -1041,7 +1035,7 @@ function mountPaymentRequestButtons(container, _ref5) {
1041
1035
  return mountApplePayButton(innerWrapper, applePayOptions);
1042
1036
  }).catch(function () {
1043
1037
  return mountApplePayFallbackButton(innerWrapper, applePayOptions);
1044
- }).then(revealWrapper).catch(function () {
1038
+ }).catch(function () {
1045
1039
  return null;
1046
1040
  });
1047
1041
  } else if (channels.includes(CHANNELS.APPLE_PAY)) {
@@ -1056,7 +1050,7 @@ function mountPaymentRequestButtons(container, _ref5) {
1056
1050
  styles: styles,
1057
1051
  onClick: onClickGooglePayButton
1058
1052
  });
1059
- }).then(revealWrapper).catch(function () {
1053
+ }).catch(function () {
1060
1054
  return null;
1061
1055
  });
1062
1056
  return Promise.all([applePayButton, googlePayButton]).then(function (_ref6) {
@@ -1066,6 +1060,7 @@ function mountPaymentRequestButtons(container, _ref5) {
1066
1060
  if (!applePay && !googlePay) {
1067
1061
  return null;
1068
1062
  }
1063
+ innerWrapper.style.display = '';
1069
1064
  return {
1070
1065
  applePay: !!applePay,
1071
1066
  googlePay: !!googlePay
@@ -1978,10 +1973,10 @@ var Inline = /*#__PURE__*/function () {
1978
1973
  transaction: transaction,
1979
1974
  styles: styles,
1980
1975
  onClickApplePayButton: function onClickApplePayButton() {
1981
- return _this3.startApplePay();
1976
+ return _this3.startApplePay(transaction);
1982
1977
  },
1983
1978
  onClickGooglePayButton: function onClickGooglePayButton() {
1984
- return _this3.startGooglePay();
1979
+ return _this3.startGooglePay(transaction);
1985
1980
  }
1986
1981
  }).then(function (mountedElements) {
1987
1982
  if (onElementsMount) {
@@ -2019,10 +2014,14 @@ var Inline = /*#__PURE__*/function () {
2019
2014
  }
2020
2015
  }, {
2021
2016
  key: "startGooglePay",
2022
- value: function startGooglePay() {
2017
+ value: function startGooglePay(inlineTransaction) {
2023
2018
  var _this4 = this;
2024
2019
  var paymentMethod = 'google pay';
2025
- var transaction = this.activeTransaction();
2020
+ var transaction = inlineTransaction || this.activeTransaction();
2021
+ if (inlineTransaction && !inlineTransaction.isActive) {
2022
+ logWarning('Google Pay: this button belongs to a transaction that is no longer active.');
2023
+ return Promise.resolve();
2024
+ }
2026
2025
  if (transaction && transaction.response) {
2027
2026
  if (this.isCharging) {
2028
2027
  return Promise.resolve();
@@ -2116,8 +2115,12 @@ var Inline = /*#__PURE__*/function () {
2116
2115
  });
2117
2116
  } catch (error) {
2118
2117
  this.isCharging = false;
2118
+ logWarning('Google Pay: could not start the charge.');
2119
2119
  notifyMerchant(function () {
2120
- return transaction.onSetupError(error);
2120
+ return transaction.onSetupError({
2121
+ status: false,
2122
+ message: 'Could not complete the Google Pay payment'
2123
+ });
2121
2124
  });
2122
2125
  return Promise.resolve();
2123
2126
  }
@@ -2128,10 +2131,14 @@ var Inline = /*#__PURE__*/function () {
2128
2131
  }
2129
2132
  }, {
2130
2133
  key: "startApplePay",
2131
- value: function startApplePay() {
2134
+ value: function startApplePay(inlineTransaction) {
2132
2135
  var _this5 = this;
2133
2136
  var paymentMethod = 'apple pay';
2134
- var transaction = this.activeTransaction();
2137
+ var transaction = inlineTransaction || this.activeTransaction();
2138
+ if (inlineTransaction && !inlineTransaction.isActive) {
2139
+ logWarning('Apple Pay: this button belongs to a transaction that is no longer active.');
2140
+ return;
2141
+ }
2135
2142
  if (transaction && transaction.response) {
2136
2143
  if (this.isCharging) {
2137
2144
  return;
package/lib/inline.js CHANGED
@@ -591,22 +591,22 @@ function printDeprecationNotice(oldName, newName, extraMessage) {
591
591
  logWarning("\"".concat(oldName, "\" has been deprecated, please use \"").concat(newName, "\". ").concat(extraMessage || ''));
592
592
  }
593
593
 
594
- var withTimeoutDeadline = function withTimeoutDeadline(work, deadlineInMilliseconds) {
594
+ var withTimeoutDelay = function withTimeoutDelay(work, delayInMilliseconds) {
595
595
  var onTimeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
596
596
  return null;
597
597
  };
598
- var timer;
599
- var deadline = new Promise(function (resolve) {
600
- timer = setTimeout(function () {
598
+ var timeout;
599
+ var delay = new Promise(function (resolve) {
600
+ timeout = setTimeout(function () {
601
601
  try {
602
602
  resolve(onTimeout());
603
603
  } catch (error) {
604
604
  resolve(null);
605
605
  }
606
- }, deadlineInMilliseconds);
606
+ }, delayInMilliseconds);
607
607
  });
608
- return Promise.race([work, deadline]).finally(function () {
609
- return clearTimeout(timer);
608
+ return Promise.race([work, delay]).finally(function () {
609
+ return clearTimeout(timeout);
610
610
  });
611
611
  };
612
612
 
@@ -686,6 +686,7 @@ var buildPaymentDataRequest = function buildPaymentDataRequest(transaction) {
686
686
  })],
687
687
  transactionInfo: {
688
688
  totalPriceStatus: 'FINAL',
689
+ checkoutOption: 'COMPLETE_IMMEDIATE_PURCHASE',
689
690
  totalPrice: amountSubunitToBase(getChannelAmount(response, CHANNELS.GOOGLE_PAY)).toFixed(2),
690
691
  currencyCode: response.currency,
691
692
  countryCode: CURRENCY_COUNTRYCODE_MAPPING[response.currency] || COUNTRYCODE.NIGERIA
@@ -716,7 +717,6 @@ var chargeGooglePay = function chargeGooglePay(_ref) {
716
717
  var canUseGooglePay = function canUseGooglePay(transaction) {
717
718
  var googlePayConfig = getGooglePayConfig(transaction);
718
719
  if (!googlePayConfig) {
719
- logWarning('Google Pay: no merchant configuration on this transaction. Add your merchant details in Dashboard > Developers > Google Pay.');
720
720
  return Promise.resolve(null);
721
721
  }
722
722
  var authMethods = getSupportedAuthMethods(googlePayConfig);
@@ -747,7 +747,7 @@ var loadGooglePay = function loadGooglePay(transaction) {
747
747
  var loadSdk = hasGooglePaySDKLoaded() ? Promise.resolve(true) : loadScript(GOOGLE_PAY_SDK_SOURCE).then(function () {
748
748
  return hasGooglePaySDKLoaded();
749
749
  });
750
- return withTimeoutDeadline(loadSdk.catch(function () {
750
+ return withTimeoutDelay(loadSdk.catch(function () {
751
751
  return false;
752
752
  }).then(function (loaded) {
753
753
  if (!loaded) {
@@ -1025,12 +1025,6 @@ function mountPaymentRequestButtons(container, _ref5) {
1025
1025
  innerWrapper.id = 'paystack-payment-request-inner-wrapper';
1026
1026
  innerWrapper.style.display = 'none';
1027
1027
  container.appendChild(innerWrapper);
1028
- var revealWrapper = function revealWrapper(button) {
1029
- if (button) {
1030
- innerWrapper.style.display = '';
1031
- }
1032
- return button;
1033
- };
1034
1028
  var applePayOptions = {
1035
1029
  styles: parseApplePayCustomStyles(styles.applePay),
1036
1030
  theme: styles.theme,
@@ -1043,7 +1037,7 @@ function mountPaymentRequestButtons(container, _ref5) {
1043
1037
  return mountApplePayButton(innerWrapper, applePayOptions);
1044
1038
  }).catch(function () {
1045
1039
  return mountApplePayFallbackButton(innerWrapper, applePayOptions);
1046
- }).then(revealWrapper).catch(function () {
1040
+ }).catch(function () {
1047
1041
  return null;
1048
1042
  });
1049
1043
  } else if (channels.includes(CHANNELS.APPLE_PAY)) {
@@ -1058,7 +1052,7 @@ function mountPaymentRequestButtons(container, _ref5) {
1058
1052
  styles: styles,
1059
1053
  onClick: onClickGooglePayButton
1060
1054
  });
1061
- }).then(revealWrapper).catch(function () {
1055
+ }).catch(function () {
1062
1056
  return null;
1063
1057
  });
1064
1058
  return Promise.all([applePayButton, googlePayButton]).then(function (_ref6) {
@@ -1068,6 +1062,7 @@ function mountPaymentRequestButtons(container, _ref5) {
1068
1062
  if (!applePay && !googlePay) {
1069
1063
  return null;
1070
1064
  }
1065
+ innerWrapper.style.display = '';
1071
1066
  return {
1072
1067
  applePay: !!applePay,
1073
1068
  googlePay: !!googlePay
@@ -1980,10 +1975,10 @@ var Inline = /*#__PURE__*/function () {
1980
1975
  transaction: transaction,
1981
1976
  styles: styles,
1982
1977
  onClickApplePayButton: function onClickApplePayButton() {
1983
- return _this3.startApplePay();
1978
+ return _this3.startApplePay(transaction);
1984
1979
  },
1985
1980
  onClickGooglePayButton: function onClickGooglePayButton() {
1986
- return _this3.startGooglePay();
1981
+ return _this3.startGooglePay(transaction);
1987
1982
  }
1988
1983
  }).then(function (mountedElements) {
1989
1984
  if (onElementsMount) {
@@ -2021,10 +2016,14 @@ var Inline = /*#__PURE__*/function () {
2021
2016
  }
2022
2017
  }, {
2023
2018
  key: "startGooglePay",
2024
- value: function startGooglePay() {
2019
+ value: function startGooglePay(inlineTransaction) {
2025
2020
  var _this4 = this;
2026
2021
  var paymentMethod = 'google pay';
2027
- var transaction = this.activeTransaction();
2022
+ var transaction = inlineTransaction || this.activeTransaction();
2023
+ if (inlineTransaction && !inlineTransaction.isActive) {
2024
+ logWarning('Google Pay: this button belongs to a transaction that is no longer active.');
2025
+ return Promise.resolve();
2026
+ }
2028
2027
  if (transaction && transaction.response) {
2029
2028
  if (this.isCharging) {
2030
2029
  return Promise.resolve();
@@ -2118,8 +2117,12 @@ var Inline = /*#__PURE__*/function () {
2118
2117
  });
2119
2118
  } catch (error) {
2120
2119
  this.isCharging = false;
2120
+ logWarning('Google Pay: could not start the charge.');
2121
2121
  notifyMerchant(function () {
2122
- return transaction.onSetupError(error);
2122
+ return transaction.onSetupError({
2123
+ status: false,
2124
+ message: 'Could not complete the Google Pay payment'
2125
+ });
2123
2126
  });
2124
2127
  return Promise.resolve();
2125
2128
  }
@@ -2130,10 +2133,14 @@ var Inline = /*#__PURE__*/function () {
2130
2133
  }
2131
2134
  }, {
2132
2135
  key: "startApplePay",
2133
- value: function startApplePay() {
2136
+ value: function startApplePay(inlineTransaction) {
2134
2137
  var _this5 = this;
2135
2138
  var paymentMethod = 'apple pay';
2136
- var transaction = this.activeTransaction();
2139
+ var transaction = inlineTransaction || this.activeTransaction();
2140
+ if (inlineTransaction && !inlineTransaction.isActive) {
2141
+ logWarning('Apple Pay: this button belongs to a transaction that is no longer active.');
2142
+ return;
2143
+ }
2137
2144
  if (transaction && transaction.response) {
2138
2145
  if (this.isCharging) {
2139
2146
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paystack/inline-js",
3
- "version": "2.26.0-dev.5",
3
+ "version": "2.26.0-dev.6",
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",