@flopay/react 0.5.13 → 0.5.16
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/index.cjs +45 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -9
- package/dist/index.d.ts +38 -9
- package/dist/index.mjs +74 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -43,6 +43,7 @@ __export(index_exports, {
|
|
|
43
43
|
PayPalButton: () => PayPalButton,
|
|
44
44
|
PaymentElement: () => PaymentElement,
|
|
45
45
|
SplitCardForm: () => SplitCardForm,
|
|
46
|
+
isInAppBrowser: () => isInAppBrowser,
|
|
46
47
|
useCheckout: () => useCheckout,
|
|
47
48
|
useElements: () => useElements,
|
|
48
49
|
useFloPay: () => useFloPay,
|
|
@@ -661,26 +662,53 @@ function wasSessionRecentlyCompleted(sessionId) {
|
|
|
661
662
|
|
|
662
663
|
// src/in-app-browser-notice.tsx
|
|
663
664
|
var import_react7 = require("react");
|
|
665
|
+
|
|
666
|
+
// src/in-app-browser.ts
|
|
667
|
+
function isInAppBrowser(userAgent) {
|
|
668
|
+
const ua = userAgent ?? (typeof navigator !== "undefined" ? navigator.userAgent : "");
|
|
669
|
+
if (!ua) return false;
|
|
670
|
+
if (/FBAN|FBAV|FB_IAB|FBIOS|Instagram|musical_ly|BytedanceWebview|TikTok/i.test(ua)) {
|
|
671
|
+
return true;
|
|
672
|
+
}
|
|
673
|
+
if (/Twitter|Snapchat|Pinterest|LinkedInApp|Line\/|MicroMessenger|GSA\//i.test(ua)) {
|
|
674
|
+
return true;
|
|
675
|
+
}
|
|
676
|
+
if (/Android.*;\s?wv\)/.test(ua)) return true;
|
|
677
|
+
if (/(iPhone|iPad|iPod).*AppleWebKit(?!.*Safari)/.test(ua)) return true;
|
|
678
|
+
return false;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// src/in-app-browser-notice.tsx
|
|
664
682
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
665
683
|
var DEFAULT_MESSAGE = "PayPal and some digital wallets aren't supported in this browser. Open this page in your device's browser to use them.";
|
|
666
684
|
function InAppBrowserNotice({
|
|
667
685
|
message,
|
|
668
|
-
openButtonLabel
|
|
669
|
-
copiedButtonLabel
|
|
686
|
+
openButtonLabel,
|
|
687
|
+
copiedButtonLabel,
|
|
670
688
|
containerStyle,
|
|
671
689
|
buttonStyle,
|
|
672
690
|
onOpenInBrowser
|
|
673
691
|
}) {
|
|
674
692
|
const [copied, setCopied] = (0, import_react7.useState)(false);
|
|
693
|
+
const [inAppBrowser, setInAppBrowser] = (0, import_react7.useState)(false);
|
|
694
|
+
(0, import_react7.useEffect)(() => {
|
|
695
|
+
setInAppBrowser(isInAppBrowser());
|
|
696
|
+
}, []);
|
|
697
|
+
const defaultOpenLabel = inAppBrowser ? "Copy link" : "Open in browser";
|
|
698
|
+
const defaultCopiedLabel = inAppBrowser ? "Link copied \u2014 open Safari/Chrome and paste" : "Link copied \u2014 paste in your browser";
|
|
699
|
+
const effectiveOpenLabel = openButtonLabel ?? defaultOpenLabel;
|
|
700
|
+
const effectiveCopiedLabel = copiedButtonLabel ?? defaultCopiedLabel;
|
|
675
701
|
const handleClick = (0, import_react7.useCallback)(async () => {
|
|
676
702
|
if (typeof window === "undefined") return;
|
|
677
703
|
const url = window.location.href;
|
|
678
704
|
let opened = false;
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
705
|
+
if (!inAppBrowser) {
|
|
706
|
+
try {
|
|
707
|
+
const win = window.open(url, "_blank");
|
|
708
|
+
opened = !!win;
|
|
709
|
+
} catch {
|
|
710
|
+
opened = false;
|
|
711
|
+
}
|
|
684
712
|
}
|
|
685
713
|
let didCopy = false;
|
|
686
714
|
if (!opened) {
|
|
@@ -695,13 +723,14 @@ function InAppBrowserNotice({
|
|
|
695
723
|
}
|
|
696
724
|
}
|
|
697
725
|
onOpenInBrowser?.({ opened, copied: didCopy });
|
|
698
|
-
}, [onOpenInBrowser]);
|
|
726
|
+
}, [inAppBrowser, onOpenInBrowser]);
|
|
699
727
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
700
728
|
"div",
|
|
701
729
|
{
|
|
702
730
|
role: "status",
|
|
703
731
|
"data-testid": "flopay-in-app-browser-notice",
|
|
704
732
|
style: {
|
|
733
|
+
marginTop: "0.75rem",
|
|
705
734
|
padding: "0.75rem 0.875rem",
|
|
706
735
|
background: "#FFFBEB",
|
|
707
736
|
border: "1px solid #FDE68A",
|
|
@@ -733,7 +762,7 @@ function InAppBrowserNotice({
|
|
|
733
762
|
cursor: "pointer",
|
|
734
763
|
...buttonStyle
|
|
735
764
|
},
|
|
736
|
-
children: copied ?
|
|
765
|
+
children: copied ? effectiveCopiedLabel : effectiveOpenLabel
|
|
737
766
|
}
|
|
738
767
|
)
|
|
739
768
|
]
|
|
@@ -1378,11 +1407,15 @@ function SplitCardFormInner({
|
|
|
1378
1407
|
const showWallets = showApplePay || showGooglePay;
|
|
1379
1408
|
const [paypalLoadState, setPaypalLoadState] = (0, import_react8.useState)("loading");
|
|
1380
1409
|
const [walletLoadState, setWalletLoadState] = (0, import_react8.useState)("loading");
|
|
1410
|
+
const [inAppBrowserDetected, setInAppBrowserDetected] = (0, import_react8.useState)(false);
|
|
1411
|
+
(0, import_react8.useEffect)(() => {
|
|
1412
|
+
setInAppBrowserDetected(isInAppBrowser());
|
|
1413
|
+
}, []);
|
|
1381
1414
|
const expectedPayPal = showPayPal && !!paypalStripeInstance;
|
|
1382
1415
|
const expectedWallets = showWallets && !!stripeInstance;
|
|
1383
|
-
const paypalLoadFailed = expectedPayPal && paypalLoadState === "load_error";
|
|
1416
|
+
const paypalLoadFailed = expectedPayPal && (paypalLoadState === "load_error" || paypalLoadState === "unavailable");
|
|
1384
1417
|
const walletsLoadFailed = expectedWallets && walletLoadState === "load_error";
|
|
1385
|
-
const showInAppBrowserNotice = (expectedPayPal || expectedWallets) && (
|
|
1418
|
+
const showInAppBrowserNotice = (expectedPayPal || expectedWallets) && (inAppBrowserDetected || paypalLoadFailed || walletsLoadFailed);
|
|
1386
1419
|
const handleNameChange = (0, import_react8.useCallback)((value) => {
|
|
1387
1420
|
setFullName(value);
|
|
1388
1421
|
onFullNameChange?.(value);
|
|
@@ -5444,6 +5477,7 @@ function FloPayAutomaticPaymentButton({
|
|
|
5444
5477
|
PayPalButton,
|
|
5445
5478
|
PaymentElement,
|
|
5446
5479
|
SplitCardForm,
|
|
5480
|
+
isInAppBrowser,
|
|
5447
5481
|
useCheckout,
|
|
5448
5482
|
useElements,
|
|
5449
5483
|
useFloPay,
|