@paystack/inline-js 2.26.0-dev.2 → 2.26.0-dev.4
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/README.md +13 -9
- package/dist/inline.js +70 -41
- package/es/inline.js +70 -41
- package/lib/inline.js +70 -41
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -418,14 +418,18 @@ All General and Custom configuration options that are accepted by [PaystackPop.n
|
|
|
418
418
|
|
|
419
419
|
`width` and `height` size the button. Every other key is passed straight through to Google's [`createButton`](https://developers.google.com/pay/api/web/reference/client#createButton), so anything it accepts works here, including overriding the defaults below.
|
|
420
420
|
|
|
421
|
-
| Option | Type
|
|
422
|
-
| -------------- |
|
|
423
|
-
| width | `String`
|
|
424
|
-
| height | `String`
|
|
425
|
-
|
|
|
426
|
-
|
|
|
427
|
-
| buttonColor | `String`
|
|
428
|
-
| buttonSizeMode | `String`
|
|
421
|
+
| Option | Type | Default |
|
|
422
|
+
| -------------- | ------------------ | -------------------- |
|
|
423
|
+
| width | `String` | `'auto'` |
|
|
424
|
+
| height | `String` | `'50px'` |
|
|
425
|
+
| borderRadius | `String`\|`Number` | `'3px'` |
|
|
426
|
+
| buttonType | `String` | `'pay'` |
|
|
427
|
+
| buttonColor | `String` | Follows `styles.theme` |
|
|
428
|
+
| buttonSizeMode | `String` | `'fill'` |
|
|
429
|
+
|
|
430
|
+
`borderRadius` takes the same shape it does on `styles.applePay`, so `'3px'` and
|
|
431
|
+
`3` both work. Google's own `buttonRadius` is still accepted, and takes a bare
|
|
432
|
+
number.
|
|
429
433
|
|
|
430
434
|
|
|
431
435
|
### Configuration Options for Callbacks
|
|
@@ -478,7 +482,7 @@ async function loadPaymentRequestButtons() {
|
|
|
478
482
|
},
|
|
479
483
|
googlePay: {
|
|
480
484
|
height: '50px',
|
|
481
|
-
|
|
485
|
+
borderRadius: '3px',
|
|
482
486
|
buttonType: 'pay'
|
|
483
487
|
}
|
|
484
488
|
},
|
package/dist/inline.js
CHANGED
|
@@ -329,13 +329,21 @@ var PaystackPop = (function () {
|
|
|
329
329
|
MERCHANT_ACCOUNT_ERROR: 'MERCHANT_ACCOUNT_ERROR'
|
|
330
330
|
};
|
|
331
331
|
var GOOGLE_PAY_TIMEOUT_MS = 10000;
|
|
332
|
+
var COUNTRYCODE = {
|
|
333
|
+
COTE_D_IVOIRE: 'CI',
|
|
334
|
+
GHANA: 'GH',
|
|
335
|
+
KENYA: 'KE',
|
|
336
|
+
NIGERIA: 'NG',
|
|
337
|
+
SOUTH_AFRICA: 'ZA',
|
|
338
|
+
EGYPT: 'EG'
|
|
339
|
+
};
|
|
332
340
|
var CURRENCY_COUNTRYCODE_MAPPING = {
|
|
333
|
-
|
|
334
|
-
GHS:
|
|
335
|
-
KES:
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
EGP:
|
|
341
|
+
XOF: COUNTRYCODE.COTE_D_IVOIRE,
|
|
342
|
+
GHS: COUNTRYCODE.GHANA,
|
|
343
|
+
KES: COUNTRYCODE.KENYA,
|
|
344
|
+
NGN: COUNTRYCODE.NIGERIA,
|
|
345
|
+
ZAR: COUNTRYCODE.SOUTH_AFRICA,
|
|
346
|
+
EGP: COUNTRYCODE.EGYPT
|
|
339
347
|
};
|
|
340
348
|
|
|
341
349
|
var loaderHTML = "\n <!DOCTYPE html>\n <html lang=\"en\">\n\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n <title>Paystack Popup Loader</title>\n <style>\n .app-loader {\n margin: 200px 0;\n text-align: center;\n color: white;\n }\n @keyframes app-loader__spinner {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n }\n @-webkit-keyframes app-loader__spinner {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n }\n .app-loader__spinner {\n position: relative;\n display: inline-block;\n }\n .app-loader__spinner div {\n left: 95px;\n top: 35px;\n position: absolute;\n -webkit-animation: app-loader__spinner linear 1s infinite;\n animation: app-loader__spinner linear 1s infinite;\n background: white;\n width: 10px;\n height: 30px;\n border-radius: 40%;\n -webkit-transform-origin: 5px 65px;\n transform-origin: 5px 65px;\n }\n .app-loader__spinner div:nth-child(1) {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg);\n -webkit-animation-delay: -0.916666666666667s;\n animation-delay: -0.916666666666667s;\n }\n .app-loader__spinner div:nth-child(2) {\n -webkit-transform: rotate(30deg);\n transform: rotate(30deg);\n -webkit-animation-delay: -0.833333333333333s;\n animation-delay: -0.833333333333333s;\n }\n .app-loader__spinner div:nth-child(3) {\n -webkit-transform: rotate(60deg);\n transform: rotate(60deg);\n -webkit-animation-delay: -0.75s;\n animation-delay: -0.75s;\n }\n .app-loader__spinner div:nth-child(4) {\n -webkit-transform: rotate(90deg);\n transform: rotate(90deg);\n -webkit-animation-delay: -0.666666666666667s;\n animation-delay: -0.666666666666667s;\n }\n .app-loader__spinner div:nth-child(5) {\n -webkit-transform: rotate(120deg);\n transform: rotate(120deg);\n -webkit-animation-delay: -0.583333333333333s;\n animation-delay: -0.583333333333333s;\n }\n .app-loader__spinner div:nth-child(6) {\n -webkit-transform: rotate(150deg);\n transform: rotate(150deg);\n -webkit-animation-delay: -0.5s;\n animation-delay: -0.5s;\n }\n .app-loader__spinner div:nth-child(7) {\n -webkit-transform: rotate(180deg);\n transform: rotate(180deg);\n -webkit-animation-delay: -0.416666666666667s;\n animation-delay: -0.416666666666667s;\n }\n .app-loader__spinner div:nth-child(8) {\n -webkit-transform: rotate(210deg);\n transform: rotate(210deg);\n -webkit-animation-delay: -0.333333333333333s;\n animation-delay: -0.333333333333333s;\n }\n .app-loader__spinner div:nth-child(9) {\n -webkit-transform: rotate(240deg);\n transform: rotate(240deg);\n -webkit-animation-delay: -0.25s;\n animation-delay: -0.25s;\n }\n .app-loader__spinner div:nth-child(10) {\n -webkit-transform: rotate(270deg);\n transform: rotate(270deg);\n -webkit-animation-delay: -0.166666666666667s;\n animation-delay: -0.166666666666667s;\n }\n .app-loader__spinner div:nth-child(11) {\n -webkit-transform: rotate(300deg);\n transform: rotate(300deg);\n -webkit-animation-delay: -0.083333333333333s;\n animation-delay: -0.083333333333333s;\n }\n .app-loader__spinner div:nth-child(12) {\n -webkit-transform: rotate(330deg);\n transform: rotate(330deg);\n -webkit-animation-delay: 0s;\n animation-delay: 0s;\n }\n .app-loader__spinner {\n width: 40px;\n height: 40px;\n -webkit-transform: translate(-20px, -20px) scale(0.2) translate(20px, 20px);\n transform: translate(-20px, -20px) scale(0.2) translate(20px, 20px);\n }\n </style>\n </head>\n\n <body>\n <div id=\"app-loader\" class=\"app-loader\">\n <div id=\"spinner\" class=\"app-loader__spinner\">\n <div></div><div></div><div></div><div></div><div></div><div></div><div>\n </div><div></div><div></div><div></div><div></div><div></div>\n </div>\n </div>\n </body>\n\n </html>\n";
|
|
@@ -432,6 +440,7 @@ var PaystackPop = (function () {
|
|
|
432
440
|
return new Promise(function (resolve, reject) {
|
|
433
441
|
if (!url) {
|
|
434
442
|
reject('No script url');
|
|
443
|
+
return;
|
|
435
444
|
}
|
|
436
445
|
var script = document.createElement('script');
|
|
437
446
|
script.src = url;
|
|
@@ -583,23 +592,22 @@ var PaystackPop = (function () {
|
|
|
583
592
|
logWarning("\"".concat(oldName, "\" has been deprecated, please use \"").concat(newName, "\". ").concat(extraMessage || ''));
|
|
584
593
|
}
|
|
585
594
|
|
|
586
|
-
var withTimeoutDeadline = function withTimeoutDeadline(
|
|
587
|
-
var
|
|
595
|
+
var withTimeoutDeadline = function withTimeoutDeadline(work, deadlineInMilliseconds) {
|
|
596
|
+
var onTimeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
|
|
597
|
+
return null;
|
|
598
|
+
};
|
|
599
|
+
var timer;
|
|
588
600
|
var deadline = new Promise(function (resolve) {
|
|
589
|
-
|
|
601
|
+
timer = setTimeout(function () {
|
|
590
602
|
try {
|
|
591
603
|
resolve(onTimeout());
|
|
592
|
-
} catch (
|
|
604
|
+
} catch (error) {
|
|
593
605
|
resolve(null);
|
|
594
606
|
}
|
|
595
|
-
},
|
|
607
|
+
}, deadlineInMilliseconds);
|
|
596
608
|
});
|
|
597
|
-
return Promise.race([
|
|
598
|
-
clearTimeout(
|
|
599
|
-
return value;
|
|
600
|
-
}, function (error) {
|
|
601
|
-
clearTimeout(timeoutId);
|
|
602
|
-
throw error;
|
|
609
|
+
return Promise.race([work, deadline]).finally(function () {
|
|
610
|
+
return clearTimeout(timer);
|
|
603
611
|
});
|
|
604
612
|
};
|
|
605
613
|
|
|
@@ -681,7 +689,7 @@ var PaystackPop = (function () {
|
|
|
681
689
|
totalPriceStatus: 'FINAL',
|
|
682
690
|
totalPrice: amountSubunitToBase(getChannelAmount(response, CHANNELS.GOOGLE_PAY)).toFixed(2),
|
|
683
691
|
currencyCode: response.currency,
|
|
684
|
-
countryCode: CURRENCY_COUNTRYCODE_MAPPING[response.currency] ||
|
|
692
|
+
countryCode: CURRENCY_COUNTRYCODE_MAPPING[response.currency] || COUNTRYCODE.NIGERIA
|
|
685
693
|
},
|
|
686
694
|
merchantInfo: buildMerchantInfo(googlePayConfig),
|
|
687
695
|
emailRequired: true
|
|
@@ -747,12 +755,10 @@ var PaystackPop = (function () {
|
|
|
747
755
|
return null;
|
|
748
756
|
}
|
|
749
757
|
return canUseGooglePay(transaction);
|
|
750
|
-
}),
|
|
751
|
-
return null;
|
|
752
|
-
}, GOOGLE_PAY_TIMEOUT_MS);
|
|
758
|
+
}), GOOGLE_PAY_TIMEOUT_MS);
|
|
753
759
|
};
|
|
754
760
|
|
|
755
|
-
var _excluded$2 = ["height", "width"];
|
|
761
|
+
var _excluded$2 = ["height", "width", "borderRadius", "buttonRadius"];
|
|
756
762
|
function createIframe(id) {
|
|
757
763
|
var iframe = document.createElement('iframe');
|
|
758
764
|
iframe.setAttribute('frameBorder', '0');
|
|
@@ -944,6 +950,10 @@ var PaystackPop = (function () {
|
|
|
944
950
|
button.style.display = isLoading ? 'none' : '';
|
|
945
951
|
loadingButton.style.display = isLoading ? 'flex' : 'none';
|
|
946
952
|
}
|
|
953
|
+
var resolveGooglePayButtonRadius = function resolveGooglePayButtonRadius(borderRadius, buttonRadius) {
|
|
954
|
+
var parsed = parseFloat(borderRadius !== undefined ? borderRadius : buttonRadius);
|
|
955
|
+
return parsed >= 0 ? parsed : GOOGLE_PAY_BUTTON_RADIUS;
|
|
956
|
+
};
|
|
947
957
|
function mountGooglePayButton(container, _ref3) {
|
|
948
958
|
var transaction = _ref3.transaction,
|
|
949
959
|
_ref3$styles = _ref3.styles,
|
|
@@ -952,15 +962,18 @@ var PaystackPop = (function () {
|
|
|
952
962
|
var _ref4 = styles.googlePay || {},
|
|
953
963
|
height = _ref4.height,
|
|
954
964
|
width = _ref4.width,
|
|
965
|
+
borderRadius = _ref4.borderRadius,
|
|
966
|
+
buttonRadius = _ref4.buttonRadius,
|
|
955
967
|
googlePayStyles = _objectWithoutProperties(_ref4, _excluded$2);
|
|
956
968
|
var googlePayConfig = getGooglePayConfig(transaction);
|
|
969
|
+
var radius = resolveGooglePayButtonRadius(borderRadius, buttonRadius);
|
|
957
970
|
appendCSS(container, generateGooglePayCSS({
|
|
958
971
|
height: height,
|
|
959
972
|
width: width
|
|
960
973
|
}));
|
|
961
974
|
var buttonColor = googlePayStyles.buttonColor || (styles.theme === PAYMENT_REQUEST_BUTTON_THEME.LIGHT ? 'white' : 'black');
|
|
962
975
|
appendCSS(container, generateGooglePayLoadingCSS({
|
|
963
|
-
borderRadius:
|
|
976
|
+
borderRadius: radius,
|
|
964
977
|
buttonColor: buttonColor
|
|
965
978
|
}));
|
|
966
979
|
var buttonContainer = document.createElement('div');
|
|
@@ -969,7 +982,7 @@ var PaystackPop = (function () {
|
|
|
969
982
|
var button = client.createButton(_objectSpread2(_objectSpread2({
|
|
970
983
|
buttonColor: buttonColor,
|
|
971
984
|
buttonType: 'pay',
|
|
972
|
-
buttonRadius:
|
|
985
|
+
buttonRadius: radius,
|
|
973
986
|
buttonSizeMode: 'fill'
|
|
974
987
|
}, googlePayStyles), {}, {
|
|
975
988
|
onClick: onClick,
|
|
@@ -2015,7 +2028,7 @@ var PaystackPop = (function () {
|
|
|
2015
2028
|
var transaction = this.activeTransaction();
|
|
2016
2029
|
if (transaction && transaction.response) {
|
|
2017
2030
|
if (this.isCharging) {
|
|
2018
|
-
return;
|
|
2031
|
+
return Promise.resolve();
|
|
2019
2032
|
}
|
|
2020
2033
|
this.isCharging = true;
|
|
2021
2034
|
try {
|
|
@@ -2029,7 +2042,14 @@ var PaystackPop = (function () {
|
|
|
2029
2042
|
paymentMethod: paymentMethod
|
|
2030
2043
|
}));
|
|
2031
2044
|
var client = getGooglePayClient(resolveGooglePayEnvironment(transaction.response));
|
|
2032
|
-
|
|
2045
|
+
var notifyMerchant = function notifyMerchant(notify) {
|
|
2046
|
+
try {
|
|
2047
|
+
notify();
|
|
2048
|
+
} catch (error) {
|
|
2049
|
+
logWarning("Google Pay: a merchant callback threw. ".concat(error && error.message || error));
|
|
2050
|
+
}
|
|
2051
|
+
};
|
|
2052
|
+
return client.loadPaymentData(buildPaymentDataRequest(transaction)).then(function (paymentData) {
|
|
2033
2053
|
toggleGooglePayLoadingState(_this4.paymentRequestContainer, true);
|
|
2034
2054
|
return chargeGooglePay({
|
|
2035
2055
|
transactionId: transaction.id,
|
|
@@ -2042,11 +2062,9 @@ var PaystackPop = (function () {
|
|
|
2042
2062
|
if (response.status === TRANSACTION_STATUS.SUCCESS) {
|
|
2043
2063
|
var data = response.data,
|
|
2044
2064
|
envelope = _objectWithoutProperties(response, _excluded3);
|
|
2045
|
-
|
|
2046
|
-
transaction.onSuccess(_objectSpread2(_objectSpread2({}, data), envelope));
|
|
2047
|
-
}
|
|
2048
|
-
logWarning("Google Pay: the onSuccess callback threw. ".concat(error && error.message || error));
|
|
2049
|
-
}
|
|
2065
|
+
notifyMerchant(function () {
|
|
2066
|
+
return transaction.onSuccess(_objectSpread2(_objectSpread2({}, data), envelope));
|
|
2067
|
+
});
|
|
2050
2068
|
_this4.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_COMPLETION, _objectSpread2(_objectSpread2({}, analyticsPayload), {}, {
|
|
2051
2069
|
timeSpent: transaction.getTimeSpent()
|
|
2052
2070
|
}));
|
|
@@ -2056,9 +2074,11 @@ var PaystackPop = (function () {
|
|
|
2056
2074
|
// `auth` means a step-up we cannot render here, so say so rather
|
|
2057
2075
|
// than leaving the customer holding a token with nowhere to go.
|
|
2058
2076
|
var message = response.status === TRANSACTION_STATUS.AUTH ? 'This card requires additional authentication, which is not supported here. Please use another payment method.' : response && response.message || 'Transaction attempt failed';
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2077
|
+
notifyMerchant(function () {
|
|
2078
|
+
return transaction.onSetupError(_objectSpread2(_objectSpread2({}, response), {}, {
|
|
2079
|
+
message: message
|
|
2080
|
+
}));
|
|
2081
|
+
});
|
|
2062
2082
|
_this4.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_ERROR, {
|
|
2063
2083
|
channel: CHANNELS.GOOGLE_PAY,
|
|
2064
2084
|
message: message
|
|
@@ -2067,7 +2087,9 @@ var PaystackPop = (function () {
|
|
|
2067
2087
|
toggleGooglePayLoadingState(_this4.paymentRequestContainer, false);
|
|
2068
2088
|
_this4.isCharging = false;
|
|
2069
2089
|
if (error && error.statusCode === GOOGLE_PAY_STATUS_CODE.CANCELED) {
|
|
2070
|
-
|
|
2090
|
+
notifyMerchant(function () {
|
|
2091
|
+
return transaction.onCancel();
|
|
2092
|
+
});
|
|
2071
2093
|
return;
|
|
2072
2094
|
}
|
|
2073
2095
|
var statusCode = error && error.statusCode;
|
|
@@ -2075,9 +2097,11 @@ var PaystackPop = (function () {
|
|
|
2075
2097
|
logWarning("Google Pay: ".concat(statusCode, ". Google rejected the merchant or the origin serving the button. Check that the merchant ID and domain saved in Dashboard > Developers > Google Pay match this page."));
|
|
2076
2098
|
}
|
|
2077
2099
|
var message = error && (error.statusMessage || error.message) || 'Could not complete the Google Pay payment';
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2100
|
+
notifyMerchant(function () {
|
|
2101
|
+
return transaction.onSetupError({
|
|
2102
|
+
status: false,
|
|
2103
|
+
message: message
|
|
2104
|
+
});
|
|
2081
2105
|
});
|
|
2082
2106
|
_this4.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_ERROR, {
|
|
2083
2107
|
channel: CHANNELS.GOOGLE_PAY,
|
|
@@ -2085,18 +2109,23 @@ var PaystackPop = (function () {
|
|
|
2085
2109
|
});
|
|
2086
2110
|
}).catch(function (error) {
|
|
2087
2111
|
_this4.isCharging = false;
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2112
|
+
logWarning("Google Pay: the charge handler failed. ".concat(error && error.message || error));
|
|
2113
|
+
notifyMerchant(function () {
|
|
2114
|
+
return transaction.onSetupError({
|
|
2115
|
+
status: false,
|
|
2116
|
+
message: 'Could not complete the Google Pay payment'
|
|
2117
|
+
});
|
|
2091
2118
|
});
|
|
2092
2119
|
});
|
|
2093
2120
|
} catch (error) {
|
|
2094
2121
|
this.isCharging = false;
|
|
2095
2122
|
transaction.onSetupError(error);
|
|
2123
|
+
return Promise.resolve();
|
|
2096
2124
|
}
|
|
2097
2125
|
} else {
|
|
2098
2126
|
handleError('Could not initiate google pay transaction');
|
|
2099
2127
|
}
|
|
2128
|
+
return Promise.resolve();
|
|
2100
2129
|
}
|
|
2101
2130
|
}, {
|
|
2102
2131
|
key: "startApplePay",
|
package/es/inline.js
CHANGED
|
@@ -326,13 +326,21 @@ var GOOGLE_PAY_STATUS_CODE = {
|
|
|
326
326
|
MERCHANT_ACCOUNT_ERROR: 'MERCHANT_ACCOUNT_ERROR'
|
|
327
327
|
};
|
|
328
328
|
var GOOGLE_PAY_TIMEOUT_MS = 10000;
|
|
329
|
+
var COUNTRYCODE = {
|
|
330
|
+
COTE_D_IVOIRE: 'CI',
|
|
331
|
+
GHANA: 'GH',
|
|
332
|
+
KENYA: 'KE',
|
|
333
|
+
NIGERIA: 'NG',
|
|
334
|
+
SOUTH_AFRICA: 'ZA',
|
|
335
|
+
EGYPT: 'EG'
|
|
336
|
+
};
|
|
329
337
|
var CURRENCY_COUNTRYCODE_MAPPING = {
|
|
330
|
-
|
|
331
|
-
GHS:
|
|
332
|
-
KES:
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
EGP:
|
|
338
|
+
XOF: COUNTRYCODE.COTE_D_IVOIRE,
|
|
339
|
+
GHS: COUNTRYCODE.GHANA,
|
|
340
|
+
KES: COUNTRYCODE.KENYA,
|
|
341
|
+
NGN: COUNTRYCODE.NIGERIA,
|
|
342
|
+
ZAR: COUNTRYCODE.SOUTH_AFRICA,
|
|
343
|
+
EGP: COUNTRYCODE.EGYPT
|
|
336
344
|
};
|
|
337
345
|
|
|
338
346
|
var loaderHTML = "\n <!DOCTYPE html>\n <html lang=\"en\">\n\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n <title>Paystack Popup Loader</title>\n <style>\n .app-loader {\n margin: 200px 0;\n text-align: center;\n color: white;\n }\n @keyframes app-loader__spinner {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n }\n @-webkit-keyframes app-loader__spinner {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n }\n .app-loader__spinner {\n position: relative;\n display: inline-block;\n }\n .app-loader__spinner div {\n left: 95px;\n top: 35px;\n position: absolute;\n -webkit-animation: app-loader__spinner linear 1s infinite;\n animation: app-loader__spinner linear 1s infinite;\n background: white;\n width: 10px;\n height: 30px;\n border-radius: 40%;\n -webkit-transform-origin: 5px 65px;\n transform-origin: 5px 65px;\n }\n .app-loader__spinner div:nth-child(1) {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg);\n -webkit-animation-delay: -0.916666666666667s;\n animation-delay: -0.916666666666667s;\n }\n .app-loader__spinner div:nth-child(2) {\n -webkit-transform: rotate(30deg);\n transform: rotate(30deg);\n -webkit-animation-delay: -0.833333333333333s;\n animation-delay: -0.833333333333333s;\n }\n .app-loader__spinner div:nth-child(3) {\n -webkit-transform: rotate(60deg);\n transform: rotate(60deg);\n -webkit-animation-delay: -0.75s;\n animation-delay: -0.75s;\n }\n .app-loader__spinner div:nth-child(4) {\n -webkit-transform: rotate(90deg);\n transform: rotate(90deg);\n -webkit-animation-delay: -0.666666666666667s;\n animation-delay: -0.666666666666667s;\n }\n .app-loader__spinner div:nth-child(5) {\n -webkit-transform: rotate(120deg);\n transform: rotate(120deg);\n -webkit-animation-delay: -0.583333333333333s;\n animation-delay: -0.583333333333333s;\n }\n .app-loader__spinner div:nth-child(6) {\n -webkit-transform: rotate(150deg);\n transform: rotate(150deg);\n -webkit-animation-delay: -0.5s;\n animation-delay: -0.5s;\n }\n .app-loader__spinner div:nth-child(7) {\n -webkit-transform: rotate(180deg);\n transform: rotate(180deg);\n -webkit-animation-delay: -0.416666666666667s;\n animation-delay: -0.416666666666667s;\n }\n .app-loader__spinner div:nth-child(8) {\n -webkit-transform: rotate(210deg);\n transform: rotate(210deg);\n -webkit-animation-delay: -0.333333333333333s;\n animation-delay: -0.333333333333333s;\n }\n .app-loader__spinner div:nth-child(9) {\n -webkit-transform: rotate(240deg);\n transform: rotate(240deg);\n -webkit-animation-delay: -0.25s;\n animation-delay: -0.25s;\n }\n .app-loader__spinner div:nth-child(10) {\n -webkit-transform: rotate(270deg);\n transform: rotate(270deg);\n -webkit-animation-delay: -0.166666666666667s;\n animation-delay: -0.166666666666667s;\n }\n .app-loader__spinner div:nth-child(11) {\n -webkit-transform: rotate(300deg);\n transform: rotate(300deg);\n -webkit-animation-delay: -0.083333333333333s;\n animation-delay: -0.083333333333333s;\n }\n .app-loader__spinner div:nth-child(12) {\n -webkit-transform: rotate(330deg);\n transform: rotate(330deg);\n -webkit-animation-delay: 0s;\n animation-delay: 0s;\n }\n .app-loader__spinner {\n width: 40px;\n height: 40px;\n -webkit-transform: translate(-20px, -20px) scale(0.2) translate(20px, 20px);\n transform: translate(-20px, -20px) scale(0.2) translate(20px, 20px);\n }\n </style>\n </head>\n\n <body>\n <div id=\"app-loader\" class=\"app-loader\">\n <div id=\"spinner\" class=\"app-loader__spinner\">\n <div></div><div></div><div></div><div></div><div></div><div></div><div>\n </div><div></div><div></div><div></div><div></div><div></div>\n </div>\n </div>\n </body>\n\n </html>\n";
|
|
@@ -429,6 +437,7 @@ var loadScript = function loadScript(url) {
|
|
|
429
437
|
return new Promise(function (resolve, reject) {
|
|
430
438
|
if (!url) {
|
|
431
439
|
reject('No script url');
|
|
440
|
+
return;
|
|
432
441
|
}
|
|
433
442
|
var script = document.createElement('script');
|
|
434
443
|
script.src = url;
|
|
@@ -580,23 +589,22 @@ function printDeprecationNotice(oldName, newName, extraMessage) {
|
|
|
580
589
|
logWarning("\"".concat(oldName, "\" has been deprecated, please use \"").concat(newName, "\". ").concat(extraMessage || ''));
|
|
581
590
|
}
|
|
582
591
|
|
|
583
|
-
var withTimeoutDeadline = function withTimeoutDeadline(
|
|
584
|
-
var
|
|
592
|
+
var withTimeoutDeadline = function withTimeoutDeadline(work, deadlineInMilliseconds) {
|
|
593
|
+
var onTimeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
|
|
594
|
+
return null;
|
|
595
|
+
};
|
|
596
|
+
var timer;
|
|
585
597
|
var deadline = new Promise(function (resolve) {
|
|
586
|
-
|
|
598
|
+
timer = setTimeout(function () {
|
|
587
599
|
try {
|
|
588
600
|
resolve(onTimeout());
|
|
589
|
-
} catch (
|
|
601
|
+
} catch (error) {
|
|
590
602
|
resolve(null);
|
|
591
603
|
}
|
|
592
|
-
},
|
|
604
|
+
}, deadlineInMilliseconds);
|
|
593
605
|
});
|
|
594
|
-
return Promise.race([
|
|
595
|
-
clearTimeout(
|
|
596
|
-
return value;
|
|
597
|
-
}, function (error) {
|
|
598
|
-
clearTimeout(timeoutId);
|
|
599
|
-
throw error;
|
|
606
|
+
return Promise.race([work, deadline]).finally(function () {
|
|
607
|
+
return clearTimeout(timer);
|
|
600
608
|
});
|
|
601
609
|
};
|
|
602
610
|
|
|
@@ -678,7 +686,7 @@ var buildPaymentDataRequest = function buildPaymentDataRequest(transaction) {
|
|
|
678
686
|
totalPriceStatus: 'FINAL',
|
|
679
687
|
totalPrice: amountSubunitToBase(getChannelAmount(response, CHANNELS.GOOGLE_PAY)).toFixed(2),
|
|
680
688
|
currencyCode: response.currency,
|
|
681
|
-
countryCode: CURRENCY_COUNTRYCODE_MAPPING[response.currency] ||
|
|
689
|
+
countryCode: CURRENCY_COUNTRYCODE_MAPPING[response.currency] || COUNTRYCODE.NIGERIA
|
|
682
690
|
},
|
|
683
691
|
merchantInfo: buildMerchantInfo(googlePayConfig),
|
|
684
692
|
emailRequired: true
|
|
@@ -744,12 +752,10 @@ var loadGooglePay = function loadGooglePay(transaction) {
|
|
|
744
752
|
return null;
|
|
745
753
|
}
|
|
746
754
|
return canUseGooglePay(transaction);
|
|
747
|
-
}),
|
|
748
|
-
return null;
|
|
749
|
-
}, GOOGLE_PAY_TIMEOUT_MS);
|
|
755
|
+
}), GOOGLE_PAY_TIMEOUT_MS);
|
|
750
756
|
};
|
|
751
757
|
|
|
752
|
-
var _excluded$2 = ["height", "width"];
|
|
758
|
+
var _excluded$2 = ["height", "width", "borderRadius", "buttonRadius"];
|
|
753
759
|
function createIframe(id) {
|
|
754
760
|
var iframe = document.createElement('iframe');
|
|
755
761
|
iframe.setAttribute('frameBorder', '0');
|
|
@@ -941,6 +947,10 @@ function toggleGooglePayLoadingState(container, isLoading) {
|
|
|
941
947
|
button.style.display = isLoading ? 'none' : '';
|
|
942
948
|
loadingButton.style.display = isLoading ? 'flex' : 'none';
|
|
943
949
|
}
|
|
950
|
+
var resolveGooglePayButtonRadius = function resolveGooglePayButtonRadius(borderRadius, buttonRadius) {
|
|
951
|
+
var parsed = parseFloat(borderRadius !== undefined ? borderRadius : buttonRadius);
|
|
952
|
+
return parsed >= 0 ? parsed : GOOGLE_PAY_BUTTON_RADIUS;
|
|
953
|
+
};
|
|
944
954
|
function mountGooglePayButton(container, _ref3) {
|
|
945
955
|
var transaction = _ref3.transaction,
|
|
946
956
|
_ref3$styles = _ref3.styles,
|
|
@@ -949,15 +959,18 @@ function mountGooglePayButton(container, _ref3) {
|
|
|
949
959
|
var _ref4 = styles.googlePay || {},
|
|
950
960
|
height = _ref4.height,
|
|
951
961
|
width = _ref4.width,
|
|
962
|
+
borderRadius = _ref4.borderRadius,
|
|
963
|
+
buttonRadius = _ref4.buttonRadius,
|
|
952
964
|
googlePayStyles = _objectWithoutProperties(_ref4, _excluded$2);
|
|
953
965
|
var googlePayConfig = getGooglePayConfig(transaction);
|
|
966
|
+
var radius = resolveGooglePayButtonRadius(borderRadius, buttonRadius);
|
|
954
967
|
appendCSS(container, generateGooglePayCSS({
|
|
955
968
|
height: height,
|
|
956
969
|
width: width
|
|
957
970
|
}));
|
|
958
971
|
var buttonColor = googlePayStyles.buttonColor || (styles.theme === PAYMENT_REQUEST_BUTTON_THEME.LIGHT ? 'white' : 'black');
|
|
959
972
|
appendCSS(container, generateGooglePayLoadingCSS({
|
|
960
|
-
borderRadius:
|
|
973
|
+
borderRadius: radius,
|
|
961
974
|
buttonColor: buttonColor
|
|
962
975
|
}));
|
|
963
976
|
var buttonContainer = document.createElement('div');
|
|
@@ -966,7 +979,7 @@ function mountGooglePayButton(container, _ref3) {
|
|
|
966
979
|
var button = client.createButton(_objectSpread2(_objectSpread2({
|
|
967
980
|
buttonColor: buttonColor,
|
|
968
981
|
buttonType: 'pay',
|
|
969
|
-
buttonRadius:
|
|
982
|
+
buttonRadius: radius,
|
|
970
983
|
buttonSizeMode: 'fill'
|
|
971
984
|
}, googlePayStyles), {}, {
|
|
972
985
|
onClick: onClick,
|
|
@@ -2012,7 +2025,7 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2012
2025
|
var transaction = this.activeTransaction();
|
|
2013
2026
|
if (transaction && transaction.response) {
|
|
2014
2027
|
if (this.isCharging) {
|
|
2015
|
-
return;
|
|
2028
|
+
return Promise.resolve();
|
|
2016
2029
|
}
|
|
2017
2030
|
this.isCharging = true;
|
|
2018
2031
|
try {
|
|
@@ -2026,7 +2039,14 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2026
2039
|
paymentMethod: paymentMethod
|
|
2027
2040
|
}));
|
|
2028
2041
|
var client = getGooglePayClient(resolveGooglePayEnvironment(transaction.response));
|
|
2029
|
-
|
|
2042
|
+
var notifyMerchant = function notifyMerchant(notify) {
|
|
2043
|
+
try {
|
|
2044
|
+
notify();
|
|
2045
|
+
} catch (error) {
|
|
2046
|
+
logWarning("Google Pay: a merchant callback threw. ".concat(error && error.message || error));
|
|
2047
|
+
}
|
|
2048
|
+
};
|
|
2049
|
+
return client.loadPaymentData(buildPaymentDataRequest(transaction)).then(function (paymentData) {
|
|
2030
2050
|
toggleGooglePayLoadingState(_this4.paymentRequestContainer, true);
|
|
2031
2051
|
return chargeGooglePay({
|
|
2032
2052
|
transactionId: transaction.id,
|
|
@@ -2039,11 +2059,9 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2039
2059
|
if (response.status === TRANSACTION_STATUS.SUCCESS) {
|
|
2040
2060
|
var data = response.data,
|
|
2041
2061
|
envelope = _objectWithoutProperties(response, _excluded3);
|
|
2042
|
-
|
|
2043
|
-
transaction.onSuccess(_objectSpread2(_objectSpread2({}, data), envelope));
|
|
2044
|
-
}
|
|
2045
|
-
logWarning("Google Pay: the onSuccess callback threw. ".concat(error && error.message || error));
|
|
2046
|
-
}
|
|
2062
|
+
notifyMerchant(function () {
|
|
2063
|
+
return transaction.onSuccess(_objectSpread2(_objectSpread2({}, data), envelope));
|
|
2064
|
+
});
|
|
2047
2065
|
_this4.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_COMPLETION, _objectSpread2(_objectSpread2({}, analyticsPayload), {}, {
|
|
2048
2066
|
timeSpent: transaction.getTimeSpent()
|
|
2049
2067
|
}));
|
|
@@ -2053,9 +2071,11 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2053
2071
|
// `auth` means a step-up we cannot render here, so say so rather
|
|
2054
2072
|
// than leaving the customer holding a token with nowhere to go.
|
|
2055
2073
|
var message = response.status === TRANSACTION_STATUS.AUTH ? 'This card requires additional authentication, which is not supported here. Please use another payment method.' : response && response.message || 'Transaction attempt failed';
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2074
|
+
notifyMerchant(function () {
|
|
2075
|
+
return transaction.onSetupError(_objectSpread2(_objectSpread2({}, response), {}, {
|
|
2076
|
+
message: message
|
|
2077
|
+
}));
|
|
2078
|
+
});
|
|
2059
2079
|
_this4.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_ERROR, {
|
|
2060
2080
|
channel: CHANNELS.GOOGLE_PAY,
|
|
2061
2081
|
message: message
|
|
@@ -2064,7 +2084,9 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2064
2084
|
toggleGooglePayLoadingState(_this4.paymentRequestContainer, false);
|
|
2065
2085
|
_this4.isCharging = false;
|
|
2066
2086
|
if (error && error.statusCode === GOOGLE_PAY_STATUS_CODE.CANCELED) {
|
|
2067
|
-
|
|
2087
|
+
notifyMerchant(function () {
|
|
2088
|
+
return transaction.onCancel();
|
|
2089
|
+
});
|
|
2068
2090
|
return;
|
|
2069
2091
|
}
|
|
2070
2092
|
var statusCode = error && error.statusCode;
|
|
@@ -2072,9 +2094,11 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2072
2094
|
logWarning("Google Pay: ".concat(statusCode, ". Google rejected the merchant or the origin serving the button. Check that the merchant ID and domain saved in Dashboard > Developers > Google Pay match this page."));
|
|
2073
2095
|
}
|
|
2074
2096
|
var message = error && (error.statusMessage || error.message) || 'Could not complete the Google Pay payment';
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2097
|
+
notifyMerchant(function () {
|
|
2098
|
+
return transaction.onSetupError({
|
|
2099
|
+
status: false,
|
|
2100
|
+
message: message
|
|
2101
|
+
});
|
|
2078
2102
|
});
|
|
2079
2103
|
_this4.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_ERROR, {
|
|
2080
2104
|
channel: CHANNELS.GOOGLE_PAY,
|
|
@@ -2082,18 +2106,23 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2082
2106
|
});
|
|
2083
2107
|
}).catch(function (error) {
|
|
2084
2108
|
_this4.isCharging = false;
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2109
|
+
logWarning("Google Pay: the charge handler failed. ".concat(error && error.message || error));
|
|
2110
|
+
notifyMerchant(function () {
|
|
2111
|
+
return transaction.onSetupError({
|
|
2112
|
+
status: false,
|
|
2113
|
+
message: 'Could not complete the Google Pay payment'
|
|
2114
|
+
});
|
|
2088
2115
|
});
|
|
2089
2116
|
});
|
|
2090
2117
|
} catch (error) {
|
|
2091
2118
|
this.isCharging = false;
|
|
2092
2119
|
transaction.onSetupError(error);
|
|
2120
|
+
return Promise.resolve();
|
|
2093
2121
|
}
|
|
2094
2122
|
} else {
|
|
2095
2123
|
handleError('Could not initiate google pay transaction');
|
|
2096
2124
|
}
|
|
2125
|
+
return Promise.resolve();
|
|
2097
2126
|
}
|
|
2098
2127
|
}, {
|
|
2099
2128
|
key: "startApplePay",
|
package/lib/inline.js
CHANGED
|
@@ -328,13 +328,21 @@ var GOOGLE_PAY_STATUS_CODE = {
|
|
|
328
328
|
MERCHANT_ACCOUNT_ERROR: 'MERCHANT_ACCOUNT_ERROR'
|
|
329
329
|
};
|
|
330
330
|
var GOOGLE_PAY_TIMEOUT_MS = 10000;
|
|
331
|
+
var COUNTRYCODE = {
|
|
332
|
+
COTE_D_IVOIRE: 'CI',
|
|
333
|
+
GHANA: 'GH',
|
|
334
|
+
KENYA: 'KE',
|
|
335
|
+
NIGERIA: 'NG',
|
|
336
|
+
SOUTH_AFRICA: 'ZA',
|
|
337
|
+
EGYPT: 'EG'
|
|
338
|
+
};
|
|
331
339
|
var CURRENCY_COUNTRYCODE_MAPPING = {
|
|
332
|
-
|
|
333
|
-
GHS:
|
|
334
|
-
KES:
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
EGP:
|
|
340
|
+
XOF: COUNTRYCODE.COTE_D_IVOIRE,
|
|
341
|
+
GHS: COUNTRYCODE.GHANA,
|
|
342
|
+
KES: COUNTRYCODE.KENYA,
|
|
343
|
+
NGN: COUNTRYCODE.NIGERIA,
|
|
344
|
+
ZAR: COUNTRYCODE.SOUTH_AFRICA,
|
|
345
|
+
EGP: COUNTRYCODE.EGYPT
|
|
338
346
|
};
|
|
339
347
|
|
|
340
348
|
var loaderHTML = "\n <!DOCTYPE html>\n <html lang=\"en\">\n\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n <title>Paystack Popup Loader</title>\n <style>\n .app-loader {\n margin: 200px 0;\n text-align: center;\n color: white;\n }\n @keyframes app-loader__spinner {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n }\n @-webkit-keyframes app-loader__spinner {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n }\n .app-loader__spinner {\n position: relative;\n display: inline-block;\n }\n .app-loader__spinner div {\n left: 95px;\n top: 35px;\n position: absolute;\n -webkit-animation: app-loader__spinner linear 1s infinite;\n animation: app-loader__spinner linear 1s infinite;\n background: white;\n width: 10px;\n height: 30px;\n border-radius: 40%;\n -webkit-transform-origin: 5px 65px;\n transform-origin: 5px 65px;\n }\n .app-loader__spinner div:nth-child(1) {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg);\n -webkit-animation-delay: -0.916666666666667s;\n animation-delay: -0.916666666666667s;\n }\n .app-loader__spinner div:nth-child(2) {\n -webkit-transform: rotate(30deg);\n transform: rotate(30deg);\n -webkit-animation-delay: -0.833333333333333s;\n animation-delay: -0.833333333333333s;\n }\n .app-loader__spinner div:nth-child(3) {\n -webkit-transform: rotate(60deg);\n transform: rotate(60deg);\n -webkit-animation-delay: -0.75s;\n animation-delay: -0.75s;\n }\n .app-loader__spinner div:nth-child(4) {\n -webkit-transform: rotate(90deg);\n transform: rotate(90deg);\n -webkit-animation-delay: -0.666666666666667s;\n animation-delay: -0.666666666666667s;\n }\n .app-loader__spinner div:nth-child(5) {\n -webkit-transform: rotate(120deg);\n transform: rotate(120deg);\n -webkit-animation-delay: -0.583333333333333s;\n animation-delay: -0.583333333333333s;\n }\n .app-loader__spinner div:nth-child(6) {\n -webkit-transform: rotate(150deg);\n transform: rotate(150deg);\n -webkit-animation-delay: -0.5s;\n animation-delay: -0.5s;\n }\n .app-loader__spinner div:nth-child(7) {\n -webkit-transform: rotate(180deg);\n transform: rotate(180deg);\n -webkit-animation-delay: -0.416666666666667s;\n animation-delay: -0.416666666666667s;\n }\n .app-loader__spinner div:nth-child(8) {\n -webkit-transform: rotate(210deg);\n transform: rotate(210deg);\n -webkit-animation-delay: -0.333333333333333s;\n animation-delay: -0.333333333333333s;\n }\n .app-loader__spinner div:nth-child(9) {\n -webkit-transform: rotate(240deg);\n transform: rotate(240deg);\n -webkit-animation-delay: -0.25s;\n animation-delay: -0.25s;\n }\n .app-loader__spinner div:nth-child(10) {\n -webkit-transform: rotate(270deg);\n transform: rotate(270deg);\n -webkit-animation-delay: -0.166666666666667s;\n animation-delay: -0.166666666666667s;\n }\n .app-loader__spinner div:nth-child(11) {\n -webkit-transform: rotate(300deg);\n transform: rotate(300deg);\n -webkit-animation-delay: -0.083333333333333s;\n animation-delay: -0.083333333333333s;\n }\n .app-loader__spinner div:nth-child(12) {\n -webkit-transform: rotate(330deg);\n transform: rotate(330deg);\n -webkit-animation-delay: 0s;\n animation-delay: 0s;\n }\n .app-loader__spinner {\n width: 40px;\n height: 40px;\n -webkit-transform: translate(-20px, -20px) scale(0.2) translate(20px, 20px);\n transform: translate(-20px, -20px) scale(0.2) translate(20px, 20px);\n }\n </style>\n </head>\n\n <body>\n <div id=\"app-loader\" class=\"app-loader\">\n <div id=\"spinner\" class=\"app-loader__spinner\">\n <div></div><div></div><div></div><div></div><div></div><div></div><div>\n </div><div></div><div></div><div></div><div></div><div></div>\n </div>\n </div>\n </body>\n\n </html>\n";
|
|
@@ -431,6 +439,7 @@ var loadScript = function loadScript(url) {
|
|
|
431
439
|
return new Promise(function (resolve, reject) {
|
|
432
440
|
if (!url) {
|
|
433
441
|
reject('No script url');
|
|
442
|
+
return;
|
|
434
443
|
}
|
|
435
444
|
var script = document.createElement('script');
|
|
436
445
|
script.src = url;
|
|
@@ -582,23 +591,22 @@ function printDeprecationNotice(oldName, newName, extraMessage) {
|
|
|
582
591
|
logWarning("\"".concat(oldName, "\" has been deprecated, please use \"").concat(newName, "\". ").concat(extraMessage || ''));
|
|
583
592
|
}
|
|
584
593
|
|
|
585
|
-
var withTimeoutDeadline = function withTimeoutDeadline(
|
|
586
|
-
var
|
|
594
|
+
var withTimeoutDeadline = function withTimeoutDeadline(work, deadlineInMilliseconds) {
|
|
595
|
+
var onTimeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
|
|
596
|
+
return null;
|
|
597
|
+
};
|
|
598
|
+
var timer;
|
|
587
599
|
var deadline = new Promise(function (resolve) {
|
|
588
|
-
|
|
600
|
+
timer = setTimeout(function () {
|
|
589
601
|
try {
|
|
590
602
|
resolve(onTimeout());
|
|
591
|
-
} catch (
|
|
603
|
+
} catch (error) {
|
|
592
604
|
resolve(null);
|
|
593
605
|
}
|
|
594
|
-
},
|
|
606
|
+
}, deadlineInMilliseconds);
|
|
595
607
|
});
|
|
596
|
-
return Promise.race([
|
|
597
|
-
clearTimeout(
|
|
598
|
-
return value;
|
|
599
|
-
}, function (error) {
|
|
600
|
-
clearTimeout(timeoutId);
|
|
601
|
-
throw error;
|
|
608
|
+
return Promise.race([work, deadline]).finally(function () {
|
|
609
|
+
return clearTimeout(timer);
|
|
602
610
|
});
|
|
603
611
|
};
|
|
604
612
|
|
|
@@ -680,7 +688,7 @@ var buildPaymentDataRequest = function buildPaymentDataRequest(transaction) {
|
|
|
680
688
|
totalPriceStatus: 'FINAL',
|
|
681
689
|
totalPrice: amountSubunitToBase(getChannelAmount(response, CHANNELS.GOOGLE_PAY)).toFixed(2),
|
|
682
690
|
currencyCode: response.currency,
|
|
683
|
-
countryCode: CURRENCY_COUNTRYCODE_MAPPING[response.currency] ||
|
|
691
|
+
countryCode: CURRENCY_COUNTRYCODE_MAPPING[response.currency] || COUNTRYCODE.NIGERIA
|
|
684
692
|
},
|
|
685
693
|
merchantInfo: buildMerchantInfo(googlePayConfig),
|
|
686
694
|
emailRequired: true
|
|
@@ -746,12 +754,10 @@ var loadGooglePay = function loadGooglePay(transaction) {
|
|
|
746
754
|
return null;
|
|
747
755
|
}
|
|
748
756
|
return canUseGooglePay(transaction);
|
|
749
|
-
}),
|
|
750
|
-
return null;
|
|
751
|
-
}, GOOGLE_PAY_TIMEOUT_MS);
|
|
757
|
+
}), GOOGLE_PAY_TIMEOUT_MS);
|
|
752
758
|
};
|
|
753
759
|
|
|
754
|
-
var _excluded$2 = ["height", "width"];
|
|
760
|
+
var _excluded$2 = ["height", "width", "borderRadius", "buttonRadius"];
|
|
755
761
|
function createIframe(id) {
|
|
756
762
|
var iframe = document.createElement('iframe');
|
|
757
763
|
iframe.setAttribute('frameBorder', '0');
|
|
@@ -943,6 +949,10 @@ function toggleGooglePayLoadingState(container, isLoading) {
|
|
|
943
949
|
button.style.display = isLoading ? 'none' : '';
|
|
944
950
|
loadingButton.style.display = isLoading ? 'flex' : 'none';
|
|
945
951
|
}
|
|
952
|
+
var resolveGooglePayButtonRadius = function resolveGooglePayButtonRadius(borderRadius, buttonRadius) {
|
|
953
|
+
var parsed = parseFloat(borderRadius !== undefined ? borderRadius : buttonRadius);
|
|
954
|
+
return parsed >= 0 ? parsed : GOOGLE_PAY_BUTTON_RADIUS;
|
|
955
|
+
};
|
|
946
956
|
function mountGooglePayButton(container, _ref3) {
|
|
947
957
|
var transaction = _ref3.transaction,
|
|
948
958
|
_ref3$styles = _ref3.styles,
|
|
@@ -951,15 +961,18 @@ function mountGooglePayButton(container, _ref3) {
|
|
|
951
961
|
var _ref4 = styles.googlePay || {},
|
|
952
962
|
height = _ref4.height,
|
|
953
963
|
width = _ref4.width,
|
|
964
|
+
borderRadius = _ref4.borderRadius,
|
|
965
|
+
buttonRadius = _ref4.buttonRadius,
|
|
954
966
|
googlePayStyles = _objectWithoutProperties(_ref4, _excluded$2);
|
|
955
967
|
var googlePayConfig = getGooglePayConfig(transaction);
|
|
968
|
+
var radius = resolveGooglePayButtonRadius(borderRadius, buttonRadius);
|
|
956
969
|
appendCSS(container, generateGooglePayCSS({
|
|
957
970
|
height: height,
|
|
958
971
|
width: width
|
|
959
972
|
}));
|
|
960
973
|
var buttonColor = googlePayStyles.buttonColor || (styles.theme === PAYMENT_REQUEST_BUTTON_THEME.LIGHT ? 'white' : 'black');
|
|
961
974
|
appendCSS(container, generateGooglePayLoadingCSS({
|
|
962
|
-
borderRadius:
|
|
975
|
+
borderRadius: radius,
|
|
963
976
|
buttonColor: buttonColor
|
|
964
977
|
}));
|
|
965
978
|
var buttonContainer = document.createElement('div');
|
|
@@ -968,7 +981,7 @@ function mountGooglePayButton(container, _ref3) {
|
|
|
968
981
|
var button = client.createButton(_objectSpread2(_objectSpread2({
|
|
969
982
|
buttonColor: buttonColor,
|
|
970
983
|
buttonType: 'pay',
|
|
971
|
-
buttonRadius:
|
|
984
|
+
buttonRadius: radius,
|
|
972
985
|
buttonSizeMode: 'fill'
|
|
973
986
|
}, googlePayStyles), {}, {
|
|
974
987
|
onClick: onClick,
|
|
@@ -2014,7 +2027,7 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2014
2027
|
var transaction = this.activeTransaction();
|
|
2015
2028
|
if (transaction && transaction.response) {
|
|
2016
2029
|
if (this.isCharging) {
|
|
2017
|
-
return;
|
|
2030
|
+
return Promise.resolve();
|
|
2018
2031
|
}
|
|
2019
2032
|
this.isCharging = true;
|
|
2020
2033
|
try {
|
|
@@ -2028,7 +2041,14 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2028
2041
|
paymentMethod: paymentMethod
|
|
2029
2042
|
}));
|
|
2030
2043
|
var client = getGooglePayClient(resolveGooglePayEnvironment(transaction.response));
|
|
2031
|
-
|
|
2044
|
+
var notifyMerchant = function notifyMerchant(notify) {
|
|
2045
|
+
try {
|
|
2046
|
+
notify();
|
|
2047
|
+
} catch (error) {
|
|
2048
|
+
logWarning("Google Pay: a merchant callback threw. ".concat(error && error.message || error));
|
|
2049
|
+
}
|
|
2050
|
+
};
|
|
2051
|
+
return client.loadPaymentData(buildPaymentDataRequest(transaction)).then(function (paymentData) {
|
|
2032
2052
|
toggleGooglePayLoadingState(_this4.paymentRequestContainer, true);
|
|
2033
2053
|
return chargeGooglePay({
|
|
2034
2054
|
transactionId: transaction.id,
|
|
@@ -2041,11 +2061,9 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2041
2061
|
if (response.status === TRANSACTION_STATUS.SUCCESS) {
|
|
2042
2062
|
var data = response.data,
|
|
2043
2063
|
envelope = _objectWithoutProperties(response, _excluded3);
|
|
2044
|
-
|
|
2045
|
-
transaction.onSuccess(_objectSpread2(_objectSpread2({}, data), envelope));
|
|
2046
|
-
}
|
|
2047
|
-
logWarning("Google Pay: the onSuccess callback threw. ".concat(error && error.message || error));
|
|
2048
|
-
}
|
|
2064
|
+
notifyMerchant(function () {
|
|
2065
|
+
return transaction.onSuccess(_objectSpread2(_objectSpread2({}, data), envelope));
|
|
2066
|
+
});
|
|
2049
2067
|
_this4.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_COMPLETION, _objectSpread2(_objectSpread2({}, analyticsPayload), {}, {
|
|
2050
2068
|
timeSpent: transaction.getTimeSpent()
|
|
2051
2069
|
}));
|
|
@@ -2055,9 +2073,11 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2055
2073
|
// `auth` means a step-up we cannot render here, so say so rather
|
|
2056
2074
|
// than leaving the customer holding a token with nowhere to go.
|
|
2057
2075
|
var message = response.status === TRANSACTION_STATUS.AUTH ? 'This card requires additional authentication, which is not supported here. Please use another payment method.' : response && response.message || 'Transaction attempt failed';
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2076
|
+
notifyMerchant(function () {
|
|
2077
|
+
return transaction.onSetupError(_objectSpread2(_objectSpread2({}, response), {}, {
|
|
2078
|
+
message: message
|
|
2079
|
+
}));
|
|
2080
|
+
});
|
|
2061
2081
|
_this4.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_ERROR, {
|
|
2062
2082
|
channel: CHANNELS.GOOGLE_PAY,
|
|
2063
2083
|
message: message
|
|
@@ -2066,7 +2086,9 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2066
2086
|
toggleGooglePayLoadingState(_this4.paymentRequestContainer, false);
|
|
2067
2087
|
_this4.isCharging = false;
|
|
2068
2088
|
if (error && error.statusCode === GOOGLE_PAY_STATUS_CODE.CANCELED) {
|
|
2069
|
-
|
|
2089
|
+
notifyMerchant(function () {
|
|
2090
|
+
return transaction.onCancel();
|
|
2091
|
+
});
|
|
2070
2092
|
return;
|
|
2071
2093
|
}
|
|
2072
2094
|
var statusCode = error && error.statusCode;
|
|
@@ -2074,9 +2096,11 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2074
2096
|
logWarning("Google Pay: ".concat(statusCode, ". Google rejected the merchant or the origin serving the button. Check that the merchant ID and domain saved in Dashboard > Developers > Google Pay match this page."));
|
|
2075
2097
|
}
|
|
2076
2098
|
var message = error && (error.statusMessage || error.message) || 'Could not complete the Google Pay payment';
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2099
|
+
notifyMerchant(function () {
|
|
2100
|
+
return transaction.onSetupError({
|
|
2101
|
+
status: false,
|
|
2102
|
+
message: message
|
|
2103
|
+
});
|
|
2080
2104
|
});
|
|
2081
2105
|
_this4.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_ERROR, {
|
|
2082
2106
|
channel: CHANNELS.GOOGLE_PAY,
|
|
@@ -2084,18 +2108,23 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2084
2108
|
});
|
|
2085
2109
|
}).catch(function (error) {
|
|
2086
2110
|
_this4.isCharging = false;
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2111
|
+
logWarning("Google Pay: the charge handler failed. ".concat(error && error.message || error));
|
|
2112
|
+
notifyMerchant(function () {
|
|
2113
|
+
return transaction.onSetupError({
|
|
2114
|
+
status: false,
|
|
2115
|
+
message: 'Could not complete the Google Pay payment'
|
|
2116
|
+
});
|
|
2090
2117
|
});
|
|
2091
2118
|
});
|
|
2092
2119
|
} catch (error) {
|
|
2093
2120
|
this.isCharging = false;
|
|
2094
2121
|
transaction.onSetupError(error);
|
|
2122
|
+
return Promise.resolve();
|
|
2095
2123
|
}
|
|
2096
2124
|
} else {
|
|
2097
2125
|
handleError('Could not initiate google pay transaction');
|
|
2098
2126
|
}
|
|
2127
|
+
return Promise.resolve();
|
|
2099
2128
|
}
|
|
2100
2129
|
}, {
|
|
2101
2130
|
key: "startApplePay",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paystack/inline-js",
|
|
3
|
-
"version": "2.26.0-dev.
|
|
3
|
+
"version": "2.26.0-dev.4",
|
|
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",
|