@flopay/react 0.3.19 → 0.4.0
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 +6 -2
- package/dist/index.cjs +115 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -2
- package/dist/index.d.ts +16 -2
- package/dist/index.mjs +113 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -299,9 +299,13 @@ The `SplitCardForm` layout:
|
|
|
299
299
|
|
|
300
300
|
### PayPal Handling
|
|
301
301
|
|
|
302
|
-
PayPal requires its own Stripe Elements instance because it cannot share an Elements group that uses `paymentMethodCreation: 'manual'`.
|
|
302
|
+
PayPal requires its own Stripe Elements instance because it cannot share an Elements group that uses `paymentMethodCreation: 'manual'`. In addition, the billing API may return a dedicated Stripe account for PayPal via `gatewayData.paypalPublishableKey` — when set, every PayPal Stripe operation uses that key. When the field is `null` or missing, PayPal is disabled (the button is not rendered); there is no fallback to the primary `publishableKey`.
|
|
303
303
|
|
|
304
|
-
|
|
304
|
+
The SDK handles this in two ways:
|
|
305
|
+
|
|
306
|
+
- **`SplitCardForm`**: Automatically manages two Elements instances internally. Card/wallet fields use the primary Stripe account with `paymentMethodCreation: 'manual'`. PayPal renders inside a separate `<Elements>` wrapper backed by the dedicated PayPal FloPay instance (exposed via the `usePayPalFloPay()` hook).
|
|
307
|
+
|
|
308
|
+
- **`FloPayProvider`** (manual composition): accepts an optional `paypalFlopay` prop. Load a second `FloPay` instance with the PayPal publishable key yourself, then pass it in alongside the primary instance. `usePayPalFloPay()` exposes it to descendants.
|
|
305
309
|
|
|
306
310
|
- **`PayPalButton`** (standalone): Must be rendered inside its own `FloPayProvider`:
|
|
307
311
|
|
package/dist/index.cjs
CHANGED
|
@@ -43,7 +43,8 @@ __export(index_exports, {
|
|
|
43
43
|
SplitCardForm: () => SplitCardForm,
|
|
44
44
|
useCheckout: () => useCheckout,
|
|
45
45
|
useElements: () => useElements,
|
|
46
|
-
useFloPay: () => useFloPay
|
|
46
|
+
useFloPay: () => useFloPay,
|
|
47
|
+
usePayPalFloPay: () => usePayPalFloPay
|
|
47
48
|
});
|
|
48
49
|
module.exports = __toCommonJS(index_exports);
|
|
49
50
|
|
|
@@ -55,6 +56,7 @@ var import_shared = require("@flopay/shared");
|
|
|
55
56
|
var import_react = require("react");
|
|
56
57
|
var FloPayContext = (0, import_react.createContext)({
|
|
57
58
|
flopay: null,
|
|
59
|
+
paypalFlopay: null,
|
|
58
60
|
elements: null,
|
|
59
61
|
billingApiUrl: ""
|
|
60
62
|
});
|
|
@@ -68,12 +70,16 @@ var CheckoutContext = (0, import_react.createContext)({
|
|
|
68
70
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
69
71
|
function FloPayProvider({
|
|
70
72
|
flopay: floPayProp,
|
|
73
|
+
paypalFlopay: paypalFloPayProp,
|
|
71
74
|
options,
|
|
72
75
|
children
|
|
73
76
|
}) {
|
|
74
77
|
const [flopay, setFloPay] = (0, import_react2.useState)(
|
|
75
78
|
floPayProp instanceof Promise ? null : floPayProp
|
|
76
79
|
);
|
|
80
|
+
const [paypalFlopay, setPaypalFloPay] = (0, import_react2.useState)(
|
|
81
|
+
paypalFloPayProp instanceof Promise || !paypalFloPayProp ? null : paypalFloPayProp
|
|
82
|
+
);
|
|
77
83
|
const [elements, setElements] = (0, import_react2.useState)(null);
|
|
78
84
|
(0, import_react2.useEffect)(() => {
|
|
79
85
|
let cancelled = false;
|
|
@@ -90,6 +96,25 @@ function FloPayProvider({
|
|
|
90
96
|
cancelled = true;
|
|
91
97
|
};
|
|
92
98
|
}, [floPayProp]);
|
|
99
|
+
(0, import_react2.useEffect)(() => {
|
|
100
|
+
let cancelled = false;
|
|
101
|
+
if (!paypalFloPayProp) {
|
|
102
|
+
setPaypalFloPay(null);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (paypalFloPayProp instanceof Promise) {
|
|
106
|
+
paypalFloPayProp.then((instance) => {
|
|
107
|
+
if (!cancelled) {
|
|
108
|
+
setPaypalFloPay(instance);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
} else {
|
|
112
|
+
setPaypalFloPay(paypalFloPayProp);
|
|
113
|
+
}
|
|
114
|
+
return () => {
|
|
115
|
+
cancelled = true;
|
|
116
|
+
};
|
|
117
|
+
}, [paypalFloPayProp]);
|
|
93
118
|
(0, import_react2.useEffect)(() => {
|
|
94
119
|
if (!flopay) {
|
|
95
120
|
setElements(null);
|
|
@@ -109,8 +134,8 @@ function FloPayProvider({
|
|
|
109
134
|
}, [flopay, options?.appearance, options?.clientSecret, options?.amount, options?.currency]);
|
|
110
135
|
const resolvedBillingApiUrl = (0, import_shared.resolveBillingApiUrl)(options?.billingApiUrl);
|
|
111
136
|
const value = (0, import_react2.useMemo)(
|
|
112
|
-
() => ({ flopay, elements, billingApiUrl: resolvedBillingApiUrl }),
|
|
113
|
-
[flopay, elements, resolvedBillingApiUrl]
|
|
137
|
+
() => ({ flopay, paypalFlopay, elements, billingApiUrl: resolvedBillingApiUrl }),
|
|
138
|
+
[flopay, paypalFlopay, elements, resolvedBillingApiUrl]
|
|
114
139
|
);
|
|
115
140
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FloPayContext.Provider, { value, children });
|
|
116
141
|
}
|
|
@@ -259,6 +284,10 @@ function useFloPay() {
|
|
|
259
284
|
const ctx = (0, import_react5.useContext)(FloPayContext);
|
|
260
285
|
return ctx.flopay;
|
|
261
286
|
}
|
|
287
|
+
function usePayPalFloPay() {
|
|
288
|
+
const ctx = (0, import_react5.useContext)(FloPayContext);
|
|
289
|
+
return ctx.paypalFlopay ?? null;
|
|
290
|
+
}
|
|
262
291
|
function useElements() {
|
|
263
292
|
const ctx = (0, import_react5.useContext)(FloPayContext);
|
|
264
293
|
return ctx.elements;
|
|
@@ -645,7 +674,7 @@ function PayPalButtonInner({
|
|
|
645
674
|
event.reject();
|
|
646
675
|
return;
|
|
647
676
|
}
|
|
648
|
-
const beforeClick = runBeforeButtonClick ? await runBeforeButtonClick("paypal"
|
|
677
|
+
const beforeClick = runBeforeButtonClick ? await runBeforeButtonClick("paypal") : { proceed: true };
|
|
649
678
|
if (!beforeClick.proceed) {
|
|
650
679
|
beforeClickRef.current = null;
|
|
651
680
|
event.reject();
|
|
@@ -653,7 +682,7 @@ function PayPalButtonInner({
|
|
|
653
682
|
}
|
|
654
683
|
beforeClickRef.current = {
|
|
655
684
|
accountPatch: beforeClick.accountPatch,
|
|
656
|
-
|
|
685
|
+
sessionId: beforeClick.sessionId
|
|
657
686
|
};
|
|
658
687
|
event.resolve();
|
|
659
688
|
}, [isProcessing, runBeforeButtonClick, submitting]);
|
|
@@ -669,15 +698,10 @@ function PayPalButtonInner({
|
|
|
669
698
|
}
|
|
670
699
|
prepared = {
|
|
671
700
|
accountPatch: beforeClick.accountPatch,
|
|
672
|
-
|
|
701
|
+
sessionId: beforeClick.sessionId
|
|
673
702
|
};
|
|
674
703
|
}
|
|
675
|
-
const
|
|
676
|
-
if (patchResult.error) {
|
|
677
|
-
event.paymentFailed({ reason: "fail", message: patchResult.error.message });
|
|
678
|
-
return;
|
|
679
|
-
}
|
|
680
|
-
const effectiveSessionId = patchResult.sessionId ?? sessionId;
|
|
704
|
+
const effectiveSessionId = prepared?.sessionId ?? sessionId;
|
|
681
705
|
const effectiveEmail = prepared?.accountPatch?.email ?? email;
|
|
682
706
|
onButtonClick?.("paypal");
|
|
683
707
|
try {
|
|
@@ -801,16 +825,11 @@ function WalletButtonInner({
|
|
|
801
825
|
}
|
|
802
826
|
prepared = {
|
|
803
827
|
accountPatch: beforeClick.accountPatch,
|
|
804
|
-
|
|
828
|
+
sessionId: beforeClick.sessionId
|
|
805
829
|
};
|
|
806
830
|
}
|
|
807
|
-
const patchResult = prepared?.pendingInlinePatch ? await prepared.pendingInlinePatch : { error: null, sessionId };
|
|
808
|
-
if (patchResult.error) {
|
|
809
|
-
event.paymentFailed({ reason: "fail", message: patchResult.error.message });
|
|
810
|
-
return;
|
|
811
|
-
}
|
|
812
831
|
const method = walletType === "apple_pay" ? "apple_pay" : "google_pay";
|
|
813
|
-
const effectiveSessionId =
|
|
832
|
+
const effectiveSessionId = prepared?.sessionId ?? sessionId;
|
|
814
833
|
const effectiveEmail = prepared?.accountPatch?.email ?? email;
|
|
815
834
|
onButtonClick?.(walletType === "apple_pay" ? "apple_pay" : "google_pay");
|
|
816
835
|
try {
|
|
@@ -879,7 +898,7 @@ function WalletButtonInner({
|
|
|
879
898
|
onLoadError: () => setLoadState("unavailable"),
|
|
880
899
|
onClick: async (event) => {
|
|
881
900
|
lastWalletMethodRef.current = event.expressPaymentType === "apple_pay" ? "apple_pay" : "google_pay";
|
|
882
|
-
const beforeClick = runBeforeButtonClick ? await runBeforeButtonClick(lastWalletMethodRef.current
|
|
901
|
+
const beforeClick = runBeforeButtonClick ? await runBeforeButtonClick(lastWalletMethodRef.current) : { proceed: true };
|
|
883
902
|
if (!beforeClick.proceed) {
|
|
884
903
|
beforeClickRef.current = null;
|
|
885
904
|
event.reject();
|
|
@@ -887,7 +906,7 @@ function WalletButtonInner({
|
|
|
887
906
|
}
|
|
888
907
|
beforeClickRef.current = {
|
|
889
908
|
accountPatch: beforeClick.accountPatch,
|
|
890
|
-
|
|
909
|
+
sessionId: beforeClick.sessionId
|
|
891
910
|
};
|
|
892
911
|
event.resolve();
|
|
893
912
|
},
|
|
@@ -957,6 +976,7 @@ function SplitCardFormInner({
|
|
|
957
976
|
innerRef
|
|
958
977
|
}) {
|
|
959
978
|
const flopay = useFloPay();
|
|
979
|
+
const paypalFlopay = usePayPalFloPay();
|
|
960
980
|
const elements = useElements();
|
|
961
981
|
const checkout = (0, import_react6.useContext)(CheckoutContext);
|
|
962
982
|
const contextBillingUrl = useBillingApiUrl();
|
|
@@ -1020,6 +1040,10 @@ function SplitCardFormInner({
|
|
|
1020
1040
|
if (!flopay) return null;
|
|
1021
1041
|
return flopay.getRawProvider();
|
|
1022
1042
|
}, [flopay]);
|
|
1043
|
+
const paypalStripeInstance = (0, import_react6.useMemo)(() => {
|
|
1044
|
+
if (!paypalFlopay) return null;
|
|
1045
|
+
return paypalFlopay.getRawProvider();
|
|
1046
|
+
}, [paypalFlopay]);
|
|
1023
1047
|
const amountInCents = totalAmount || 100;
|
|
1024
1048
|
const walletOptions = (0, import_react6.useMemo)(() => ({
|
|
1025
1049
|
mode: "payment",
|
|
@@ -1072,7 +1096,7 @@ function SplitCardFormInner({
|
|
|
1072
1096
|
},
|
|
1073
1097
|
[checkout.applyInlineSessionPatch, onError, sessionId, updateError]
|
|
1074
1098
|
);
|
|
1075
|
-
const runBeforeButtonClick = (0, import_react6.useCallback)(async (method
|
|
1099
|
+
const runBeforeButtonClick = (0, import_react6.useCallback)(async (method) => {
|
|
1076
1100
|
if (!onBeforeButtonClick) return { proceed: true };
|
|
1077
1101
|
try {
|
|
1078
1102
|
const result = await onBeforeButtonClick({
|
|
@@ -1087,15 +1111,7 @@ function SplitCardFormInner({
|
|
|
1087
1111
|
if (result.account) {
|
|
1088
1112
|
setAccountPatch((prev) => ({ ...prev ?? {}, ...result.account }));
|
|
1089
1113
|
}
|
|
1090
|
-
const
|
|
1091
|
-
if (options?.deferInlineSessionPatch) {
|
|
1092
|
-
return {
|
|
1093
|
-
proceed: true,
|
|
1094
|
-
accountPatch: result.account,
|
|
1095
|
-
pendingInlinePatch
|
|
1096
|
-
};
|
|
1097
|
-
}
|
|
1098
|
-
const patchResult = await pendingInlinePatch;
|
|
1114
|
+
const patchResult = await applyInlineSessionPatch(result, method);
|
|
1099
1115
|
if (patchResult.error) {
|
|
1100
1116
|
return {
|
|
1101
1117
|
proceed: false,
|
|
@@ -1197,9 +1213,9 @@ function SplitCardFormInner({
|
|
|
1197
1213
|
return;
|
|
1198
1214
|
}
|
|
1199
1215
|
try {
|
|
1200
|
-
const
|
|
1201
|
-
if (!
|
|
1202
|
-
updateError("
|
|
1216
|
+
const paypalStripe = paypalFlopay?.getRawProvider();
|
|
1217
|
+
if (!paypalStripe) {
|
|
1218
|
+
updateError("PayPal is not available.");
|
|
1203
1219
|
return;
|
|
1204
1220
|
}
|
|
1205
1221
|
const confirmParams = {
|
|
@@ -1208,7 +1224,7 @@ function SplitCardFormInner({
|
|
|
1208
1224
|
if (savedPmId) {
|
|
1209
1225
|
confirmParams["payment_method"] = savedPmId;
|
|
1210
1226
|
}
|
|
1211
|
-
const { error: confirmError } = await
|
|
1227
|
+
const { error: confirmError } = await paypalStripe.confirmPayment({
|
|
1212
1228
|
clientSecret: secret,
|
|
1213
1229
|
confirmParams,
|
|
1214
1230
|
redirect: "if_required"
|
|
@@ -1245,7 +1261,7 @@ function SplitCardFormInner({
|
|
|
1245
1261
|
processingRef.current = false;
|
|
1246
1262
|
}
|
|
1247
1263
|
},
|
|
1248
|
-
[baseUrl, sessionId, resolvedAccount, fullName, chv, flopay, onComplete, onError, updateError, emitDecline]
|
|
1264
|
+
[baseUrl, sessionId, resolvedAccount, fullName, chv, flopay, paypalFlopay, onComplete, onError, updateError, emitDecline]
|
|
1249
1265
|
);
|
|
1250
1266
|
const dispatchTokenizedBody = (0, import_react6.useCallback)(
|
|
1251
1267
|
(tokenizedBody, overrides) => {
|
|
@@ -1695,7 +1711,7 @@ function SplitCardFormInner({
|
|
|
1695
1711
|
...!isButtonsView && !buttonsAnim ? { visibility: "hidden", position: "absolute", pointerEvents: "none", width: "100%" } : {},
|
|
1696
1712
|
...buttonsAnim ? { animation: buttonsAnim, pointerEvents: "none" } : {}
|
|
1697
1713
|
}, children: [
|
|
1698
|
-
showPayPal &&
|
|
1714
|
+
showPayPal && paypalStripeInstance && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_stripe_js.Elements, { stripe: paypalStripeInstance, options: paypalOptions, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1699
1715
|
PayPalButtonInner,
|
|
1700
1716
|
{
|
|
1701
1717
|
sessionId,
|
|
@@ -1708,7 +1724,7 @@ function SplitCardFormInner({
|
|
|
1708
1724
|
onDecline,
|
|
1709
1725
|
runBeforeButtonClick
|
|
1710
1726
|
}
|
|
1711
|
-
) })
|
|
1727
|
+
) }),
|
|
1712
1728
|
showWallets && stripeInstance ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_stripe_js.Elements, { stripe: stripeInstance, options: walletOptions, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1713
1729
|
WalletButtonInner,
|
|
1714
1730
|
{
|
|
@@ -1807,7 +1823,7 @@ function SplitCardFormInner({
|
|
|
1807
1823
|
onDecline
|
|
1808
1824
|
}
|
|
1809
1825
|
) }),
|
|
1810
|
-
showPayPal &&
|
|
1826
|
+
showPayPal && paypalStripeInstance && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_stripe_js.Elements, { stripe: paypalStripeInstance, options: paypalOptions, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1811
1827
|
PayPalButtonInner,
|
|
1812
1828
|
{
|
|
1813
1829
|
sessionId,
|
|
@@ -1819,7 +1835,7 @@ function SplitCardFormInner({
|
|
|
1819
1835
|
onDecline
|
|
1820
1836
|
}
|
|
1821
1837
|
) }),
|
|
1822
|
-
(showWallets && stripeInstance || showPayPal &&
|
|
1838
|
+
(showWallets && stripeInstance || showPayPal && paypalStripeInstance) && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: {
|
|
1823
1839
|
display: "flex",
|
|
1824
1840
|
alignItems: "center",
|
|
1825
1841
|
gap: "0.75rem",
|
|
@@ -1884,6 +1900,8 @@ function FloPayCheckout({
|
|
|
1884
1900
|
const [unified, setUnified] = (0, import_react7.useState)(null);
|
|
1885
1901
|
const [flopay, setFloPay] = (0, import_react7.useState)(null);
|
|
1886
1902
|
const flopayRef = (0, import_react7.useRef)(null);
|
|
1903
|
+
const [paypalFlopay, setPaypalFloPay] = (0, import_react7.useState)(null);
|
|
1904
|
+
const paypalFlopayRef = (0, import_react7.useRef)(null);
|
|
1887
1905
|
const [session, setSession] = (0, import_react7.useState)(null);
|
|
1888
1906
|
const [resolvedSessionId, setResolvedSessionId] = (0, import_react7.useState)(sessionIdProp ?? "");
|
|
1889
1907
|
const [isLoading, setIsLoading] = (0, import_react7.useState)(true);
|
|
@@ -2001,13 +2019,18 @@ function FloPayCheckout({
|
|
|
2001
2019
|
return false;
|
|
2002
2020
|
}
|
|
2003
2021
|
if (redirectResult.type === "paypal_redirect_required") {
|
|
2022
|
+
const paypalStripe = paypalFlopayRef.current?.getRawProvider();
|
|
2023
|
+
if (!paypalStripe) {
|
|
2024
|
+
setModeError("PayPal is not available.");
|
|
2025
|
+
return false;
|
|
2026
|
+
}
|
|
2004
2027
|
const confirmParams = {
|
|
2005
2028
|
return_url: window.location.href
|
|
2006
2029
|
};
|
|
2007
2030
|
if (redirectResult.paymentMethodId) {
|
|
2008
2031
|
confirmParams["payment_method"] = redirectResult.paymentMethodId;
|
|
2009
2032
|
}
|
|
2010
|
-
const { error } = await
|
|
2033
|
+
const { error } = await paypalStripe.confirmPayment({
|
|
2011
2034
|
clientSecret: redirectResult.threeDSecureToken,
|
|
2012
2035
|
confirmParams,
|
|
2013
2036
|
redirect: "if_required"
|
|
@@ -2116,8 +2139,10 @@ function FloPayCheckout({
|
|
|
2116
2139
|
setResolvedSessionId(sid);
|
|
2117
2140
|
}
|
|
2118
2141
|
let publishableKey;
|
|
2142
|
+
let paypalPublishableKey;
|
|
2119
2143
|
if (realResult.provider === "stripe") {
|
|
2120
2144
|
publishableKey = realResult.data.stripe?.publishableKey;
|
|
2145
|
+
paypalPublishableKey = realResult.data.stripe?.paypalPublishableKey;
|
|
2121
2146
|
}
|
|
2122
2147
|
if (!publishableKey) publishableKey = fallbackPublishableKey;
|
|
2123
2148
|
if (!publishableKey) {
|
|
@@ -2126,12 +2151,30 @@ function FloPayCheckout({
|
|
|
2126
2151
|
"validation_error"
|
|
2127
2152
|
);
|
|
2128
2153
|
}
|
|
2129
|
-
const
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2154
|
+
const needsSeparatePaypal = Boolean(paypalPublishableKey) && paypalPublishableKey !== publishableKey;
|
|
2155
|
+
const [instance, paypalInstanceOrError] = await Promise.all([
|
|
2156
|
+
(0, import_js.loadFloPay)(publishableKey, {
|
|
2157
|
+
billingApiUrl: resolvedBillingUrl,
|
|
2158
|
+
locale
|
|
2159
|
+
}),
|
|
2160
|
+
needsSeparatePaypal ? (0, import_js.loadFloPay)(paypalPublishableKey, {
|
|
2161
|
+
billingApiUrl: resolvedBillingUrl,
|
|
2162
|
+
locale
|
|
2163
|
+
}).catch((err) => {
|
|
2164
|
+
console.warn("[FloPay] Failed to load PayPal Stripe instance:", err);
|
|
2165
|
+
return null;
|
|
2166
|
+
}) : Promise.resolve(null)
|
|
2167
|
+
]);
|
|
2133
2168
|
flopayRef.current = instance;
|
|
2134
2169
|
setFloPay(instance);
|
|
2170
|
+
if (paypalPublishableKey) {
|
|
2171
|
+
const paypalInstance = needsSeparatePaypal ? paypalInstanceOrError : instance;
|
|
2172
|
+
paypalFlopayRef.current = paypalInstance;
|
|
2173
|
+
setPaypalFloPay(paypalInstance);
|
|
2174
|
+
} else {
|
|
2175
|
+
paypalFlopayRef.current = null;
|
|
2176
|
+
setPaypalFloPay(null);
|
|
2177
|
+
}
|
|
2135
2178
|
setIsLoading(false);
|
|
2136
2179
|
} catch (err) {
|
|
2137
2180
|
if (initializedHashRef.current === cacheKey) {
|
|
@@ -2244,8 +2287,10 @@ function FloPayCheckout({
|
|
|
2244
2287
|
}
|
|
2245
2288
|
async function initStripe(result) {
|
|
2246
2289
|
let publishableKey;
|
|
2290
|
+
let paypalPublishableKey;
|
|
2247
2291
|
if (result.provider === "stripe") {
|
|
2248
2292
|
publishableKey = result.data.stripe?.publishableKey;
|
|
2293
|
+
paypalPublishableKey = result.data.stripe?.paypalPublishableKey;
|
|
2249
2294
|
}
|
|
2250
2295
|
if (!publishableKey) publishableKey = fallbackPublishableKey;
|
|
2251
2296
|
if (!publishableKey) {
|
|
@@ -2254,12 +2299,30 @@ function FloPayCheckout({
|
|
|
2254
2299
|
"validation_error"
|
|
2255
2300
|
);
|
|
2256
2301
|
}
|
|
2257
|
-
const
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2302
|
+
const needsSeparatePaypal = Boolean(paypalPublishableKey) && paypalPublishableKey !== publishableKey;
|
|
2303
|
+
const [instance, paypalInstanceOrError] = await Promise.all([
|
|
2304
|
+
(0, import_js.loadFloPay)(publishableKey, {
|
|
2305
|
+
billingApiUrl: resolvedBillingUrl,
|
|
2306
|
+
locale
|
|
2307
|
+
}),
|
|
2308
|
+
needsSeparatePaypal ? (0, import_js.loadFloPay)(paypalPublishableKey, {
|
|
2309
|
+
billingApiUrl: resolvedBillingUrl,
|
|
2310
|
+
locale
|
|
2311
|
+
}).catch((err) => {
|
|
2312
|
+
console.warn("[FloPay] Failed to load PayPal Stripe instance:", err);
|
|
2313
|
+
return null;
|
|
2314
|
+
}) : Promise.resolve(null)
|
|
2315
|
+
]);
|
|
2261
2316
|
flopayRef.current = instance;
|
|
2262
2317
|
setFloPay(instance);
|
|
2318
|
+
if (paypalPublishableKey) {
|
|
2319
|
+
const paypalInstance = needsSeparatePaypal ? paypalInstanceOrError : instance;
|
|
2320
|
+
paypalFlopayRef.current = paypalInstance;
|
|
2321
|
+
setPaypalFloPay(paypalInstance);
|
|
2322
|
+
} else {
|
|
2323
|
+
paypalFlopayRef.current = null;
|
|
2324
|
+
setPaypalFloPay(null);
|
|
2325
|
+
}
|
|
2263
2326
|
}
|
|
2264
2327
|
init();
|
|
2265
2328
|
return () => {
|
|
@@ -2394,7 +2457,7 @@ function FloPayCheckout({
|
|
|
2394
2457
|
}
|
|
2395
2458
|
if (!flopay || !providerOptions) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, {});
|
|
2396
2459
|
if (currentMode === "confirm") {
|
|
2397
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CheckoutContext.Provider, { value: checkoutValue, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FloPayProvider, { flopay, options: providerOptions, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className, children: [
|
|
2460
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CheckoutContext.Provider, { value: checkoutValue, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FloPayProvider, { flopay, paypalFlopay, options: providerOptions, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className, children: [
|
|
2398
2461
|
modeError && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2399
2462
|
"div",
|
|
2400
2463
|
{
|
|
@@ -3226,6 +3289,7 @@ function PayPalButton({
|
|
|
3226
3289
|
SplitCardForm,
|
|
3227
3290
|
useCheckout,
|
|
3228
3291
|
useElements,
|
|
3229
|
-
useFloPay
|
|
3292
|
+
useFloPay,
|
|
3293
|
+
usePayPalFloPay
|
|
3230
3294
|
});
|
|
3231
3295
|
//# sourceMappingURL=index.cjs.map
|