@flopay/react 0.3.13 → 0.3.15
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 +1 -1
- package/dist/index.cjs +133 -127
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +134 -128
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -206,7 +206,7 @@ import {
|
|
|
206
206
|
useStripe as useStripeRaw
|
|
207
207
|
} from "@stripe/react-stripe-js";
|
|
208
208
|
import { resolveButtonsLayoutTheme, getPostalCodeLabel, COUNTRY_OPTIONS } from "@flopay/shared";
|
|
209
|
-
import { forwardRef, useCallback, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
|
|
209
|
+
import { forwardRef, useCallback, useContext as useContext3, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
|
|
210
210
|
|
|
211
211
|
// src/hooks.ts
|
|
212
212
|
import { useContext as useContext2 } from "react";
|
|
@@ -307,15 +307,6 @@ function buildSyntheticSession(params, checkoutModeOverride) {
|
|
|
307
307
|
}))
|
|
308
308
|
};
|
|
309
309
|
}
|
|
310
|
-
function ensureInlineSessionReady(params) {
|
|
311
|
-
if (!params.account.email?.trim()) {
|
|
312
|
-
throw new FloPayError(
|
|
313
|
-
"Email is required before continuing with card checkout.",
|
|
314
|
-
"validation_error",
|
|
315
|
-
{ param: "createSession.account.email" }
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
310
|
function mergeAccountPatch(base, patch) {
|
|
320
311
|
if (!patch) return base;
|
|
321
312
|
return {
|
|
@@ -362,6 +353,14 @@ var FLOPAY_KEYFRAMES = `
|
|
|
362
353
|
function FloPayKeyframes() {
|
|
363
354
|
return /* @__PURE__ */ jsx4("style", { children: FLOPAY_KEYFRAMES });
|
|
364
355
|
}
|
|
356
|
+
function toCssSize(value) {
|
|
357
|
+
if (typeof value === "number") return `${value}px`;
|
|
358
|
+
return value;
|
|
359
|
+
}
|
|
360
|
+
function toCssWeight(value) {
|
|
361
|
+
if (typeof value === "number" || typeof value === "string") return value;
|
|
362
|
+
return void 0;
|
|
363
|
+
}
|
|
365
364
|
function ProcessingOverlay({ status, errorMessage }) {
|
|
366
365
|
return /* @__PURE__ */ jsx4("div", { style: {
|
|
367
366
|
position: "fixed",
|
|
@@ -769,6 +768,7 @@ function SplitCardFormInner({
|
|
|
769
768
|
}) {
|
|
770
769
|
const flopay = useFloPay();
|
|
771
770
|
const elements = useElements();
|
|
771
|
+
const checkout = useContext3(CheckoutContext);
|
|
772
772
|
const contextBillingUrl = useBillingApiUrl();
|
|
773
773
|
const [processing, setProcessing] = useState2(false);
|
|
774
774
|
const [error, setError] = useState2(null);
|
|
@@ -814,7 +814,8 @@ function SplitCardFormInner({
|
|
|
814
814
|
title: { ...base.title, ...buttonsStylesOverride.title }
|
|
815
815
|
};
|
|
816
816
|
}, [buttonsTheme, buttonsStylesOverride]);
|
|
817
|
-
const
|
|
817
|
+
const isInlineSessionPatchProcessing = checkout.inlineSessionPatchProcessing ?? false;
|
|
818
|
+
const isSubmitting = (externalProcessing ?? processing) || isInlineSessionPatchProcessing;
|
|
818
819
|
const isSelfContained = !onTokenizedBody;
|
|
819
820
|
const baseUrl = resolvedBillingApiUrl.replace(/\/+$/, "");
|
|
820
821
|
const resolvedAccount = useMemo2(() => mergeAccountPatch({
|
|
@@ -873,8 +874,11 @@ function SplitCardFormInner({
|
|
|
873
874
|
if (result === false) {
|
|
874
875
|
return false;
|
|
875
876
|
}
|
|
876
|
-
if (result
|
|
877
|
-
|
|
877
|
+
if (result && typeof result === "object") {
|
|
878
|
+
await checkout.applyInlineSessionPatch?.(result);
|
|
879
|
+
if (result.account) {
|
|
880
|
+
setAccountPatch((prev) => ({ ...prev ?? {}, ...result.account }));
|
|
881
|
+
}
|
|
878
882
|
}
|
|
879
883
|
return true;
|
|
880
884
|
} catch (err) {
|
|
@@ -886,7 +890,7 @@ function SplitCardFormInner({
|
|
|
886
890
|
onError?.(floPayErr);
|
|
887
891
|
return false;
|
|
888
892
|
}
|
|
889
|
-
}, [onBeforeButtonClick, sessionId, updateError, onError]);
|
|
893
|
+
}, [checkout.applyInlineSessionPatch, onBeforeButtonClick, sessionId, updateError, onError]);
|
|
890
894
|
const processPaymentInternal = useCallback(
|
|
891
895
|
async (tokenizedBody) => {
|
|
892
896
|
if (processingRef.current) return;
|
|
@@ -1163,23 +1167,58 @@ function SplitCardFormInner({
|
|
|
1163
1167
|
const cardInputBg = isButtons ? bStyles.cardInputBackground ?? "white" : "white";
|
|
1164
1168
|
const hideBackButtonLabel = isEmptySlotContent(cardBackButtonContent);
|
|
1165
1169
|
const hideTitle = isEmptySlotContent(cardTitleContent);
|
|
1166
|
-
const
|
|
1170
|
+
const nameInputOverrides = isButtons ? bStyles.nameInput : void 0;
|
|
1171
|
+
const resolvedInputFontSize = bStyles.cardInputFontSize ?? toCssSize(nameInputOverrides?.fontSize) ?? "16px";
|
|
1172
|
+
const resolvedInputFontFamily = typeof nameInputOverrides?.fontFamily === "string" ? nameInputOverrides.fontFamily : "Poppins, sans-serif";
|
|
1173
|
+
const resolvedInputFontWeight = toCssWeight(nameInputOverrides?.fontWeight) ?? 400;
|
|
1174
|
+
const resolvedInputColor = bStyles.cardInputColor ?? (typeof nameInputOverrides?.color === "string" ? nameInputOverrides.color : void 0) ?? "#262833";
|
|
1175
|
+
const resolvedPlaceholderColor = bStyles.cardInputPlaceholderColor ?? "#9ca3af";
|
|
1176
|
+
const sharedInputTypography = {
|
|
1177
|
+
fontSize: resolvedInputFontSize,
|
|
1178
|
+
fontFamily: resolvedInputFontFamily,
|
|
1179
|
+
fontWeight: resolvedInputFontWeight,
|
|
1180
|
+
color: resolvedInputColor,
|
|
1181
|
+
WebkitFontSmoothing: "antialiased",
|
|
1182
|
+
MozOsxFontSmoothing: "grayscale"
|
|
1183
|
+
};
|
|
1184
|
+
const sharedInputPlaceholderVars = {
|
|
1185
|
+
"--flopay-input-placeholder-color": resolvedPlaceholderColor,
|
|
1186
|
+
"--flopay-input-font-size": resolvedInputFontSize,
|
|
1187
|
+
"--flopay-input-font-family": resolvedInputFontFamily,
|
|
1188
|
+
"--flopay-input-font-weight": String(resolvedInputFontWeight)
|
|
1189
|
+
};
|
|
1190
|
+
const stripeElementStyle = {
|
|
1167
1191
|
style: {
|
|
1168
1192
|
base: {
|
|
1169
|
-
...
|
|
1170
|
-
|
|
1171
|
-
|
|
1193
|
+
...sharedInputTypography,
|
|
1194
|
+
fontSmoothing: "antialiased",
|
|
1195
|
+
"::placeholder": {
|
|
1196
|
+
color: resolvedPlaceholderColor,
|
|
1197
|
+
fontSize: resolvedInputFontSize,
|
|
1198
|
+
fontFamily: resolvedInputFontFamily,
|
|
1199
|
+
fontWeight: resolvedInputFontWeight
|
|
1200
|
+
}
|
|
1172
1201
|
},
|
|
1173
1202
|
invalid: { color: "#ef4444" }
|
|
1174
1203
|
}
|
|
1175
|
-
}
|
|
1204
|
+
};
|
|
1176
1205
|
const cardFormBlock = /* @__PURE__ */ jsxs2("div", { style: {
|
|
1177
1206
|
backgroundColor: cardBg,
|
|
1178
1207
|
borderRadius: "8px",
|
|
1179
1208
|
padding: isButtons ? "0" : "1rem",
|
|
1180
1209
|
...isButtons ? bStyles.cardFormContainer : {},
|
|
1181
|
-
...isButtons ? { padding: bStyles.cardFormContainer?.padding ?? "0" } : {}
|
|
1210
|
+
...isButtons ? { padding: bStyles.cardFormContainer?.padding ?? "0" } : {},
|
|
1211
|
+
...sharedInputPlaceholderVars
|
|
1182
1212
|
}, children: [
|
|
1213
|
+
/* @__PURE__ */ jsx4("style", { children: `
|
|
1214
|
+
.flopay-shared-input::placeholder {
|
|
1215
|
+
color: var(--flopay-input-placeholder-color);
|
|
1216
|
+
opacity: 1;
|
|
1217
|
+
font-size: var(--flopay-input-font-size);
|
|
1218
|
+
font-family: var(--flopay-input-font-family);
|
|
1219
|
+
font-weight: var(--flopay-input-font-weight);
|
|
1220
|
+
}
|
|
1221
|
+
` }),
|
|
1183
1222
|
isButtons && showCardForm && /* @__PURE__ */ jsxs2("div", { style: {
|
|
1184
1223
|
display: "flex",
|
|
1185
1224
|
alignItems: "center",
|
|
@@ -1268,6 +1307,7 @@ function SplitCardFormInner({
|
|
|
1268
1307
|
}, children: /* @__PURE__ */ jsx4(
|
|
1269
1308
|
"input",
|
|
1270
1309
|
{
|
|
1310
|
+
className: "flopay-shared-input",
|
|
1271
1311
|
placeholder: "Full Name on Card",
|
|
1272
1312
|
autoComplete: "cc-name",
|
|
1273
1313
|
value: fullName,
|
|
@@ -1279,9 +1319,7 @@ function SplitCardFormInner({
|
|
|
1279
1319
|
border: "none",
|
|
1280
1320
|
outline: "none",
|
|
1281
1321
|
background: "transparent",
|
|
1282
|
-
|
|
1283
|
-
fontFamily: "Poppins, sans-serif",
|
|
1284
|
-
color: bStyles.cardInputColor ?? "#262833",
|
|
1322
|
+
...sharedInputTypography,
|
|
1285
1323
|
...isButtons && bStyles.nameInput ? bStyles.nameInput : {}
|
|
1286
1324
|
}
|
|
1287
1325
|
}
|
|
@@ -1316,9 +1354,7 @@ function SplitCardFormInner({
|
|
|
1316
1354
|
border: "none",
|
|
1317
1355
|
outline: "none",
|
|
1318
1356
|
background: "transparent",
|
|
1319
|
-
|
|
1320
|
-
fontFamily: "Poppins, sans-serif",
|
|
1321
|
-
color: bStyles.cardInputColor ?? "#262833",
|
|
1357
|
+
...sharedInputTypography,
|
|
1322
1358
|
cursor: "pointer",
|
|
1323
1359
|
...isButtons && bStyles.nameInput ? bStyles.nameInput : {}
|
|
1324
1360
|
},
|
|
@@ -1339,6 +1375,7 @@ function SplitCardFormInner({
|
|
|
1339
1375
|
}, children: /* @__PURE__ */ jsx4(
|
|
1340
1376
|
"input",
|
|
1341
1377
|
{
|
|
1378
|
+
className: "flopay-shared-input",
|
|
1342
1379
|
placeholder: getPostalCodeLabel(selectedCountry),
|
|
1343
1380
|
autoComplete: "postal-code",
|
|
1344
1381
|
value: zipCode,
|
|
@@ -1355,9 +1392,7 @@ function SplitCardFormInner({
|
|
|
1355
1392
|
border: "none",
|
|
1356
1393
|
outline: "none",
|
|
1357
1394
|
background: "transparent",
|
|
1358
|
-
|
|
1359
|
-
fontFamily: "Poppins, sans-serif",
|
|
1360
|
-
color: bStyles.cardInputColor ?? "#262833",
|
|
1395
|
+
...sharedInputTypography,
|
|
1361
1396
|
...isButtons && bStyles.nameInput ? bStyles.nameInput : {}
|
|
1362
1397
|
}
|
|
1363
1398
|
}
|
|
@@ -1464,11 +1499,13 @@ function SplitCardFormInner({
|
|
|
1464
1499
|
{
|
|
1465
1500
|
type: "button",
|
|
1466
1501
|
onClick: async () => {
|
|
1502
|
+
if (isSubmitting) return;
|
|
1467
1503
|
const shouldContinue = await runBeforeCardButtonClick();
|
|
1468
1504
|
if (!shouldContinue) return;
|
|
1469
1505
|
onButtonClick?.("card");
|
|
1470
1506
|
expandToCard();
|
|
1471
1507
|
},
|
|
1508
|
+
disabled: isSubmitting,
|
|
1472
1509
|
style: {
|
|
1473
1510
|
width: "100%",
|
|
1474
1511
|
padding: "0.9rem 1rem",
|
|
@@ -1478,7 +1515,7 @@ function SplitCardFormInner({
|
|
|
1478
1515
|
borderRadius: "8px",
|
|
1479
1516
|
fontSize: bStyles.cardButtonFontSize ?? "0.95rem",
|
|
1480
1517
|
fontWeight: 600,
|
|
1481
|
-
cursor: "pointer",
|
|
1518
|
+
cursor: isSubmitting ? "not-allowed" : "pointer",
|
|
1482
1519
|
display: "flex",
|
|
1483
1520
|
alignItems: "center",
|
|
1484
1521
|
justifyContent: "center",
|
|
@@ -1486,6 +1523,7 @@ function SplitCardFormInner({
|
|
|
1486
1523
|
transition: "border-color 0.2s, box-shadow 0.2s, transform 0.1s",
|
|
1487
1524
|
boxShadow: "0 1px 2px rgba(0,0,0,0.04)",
|
|
1488
1525
|
position: "relative",
|
|
1526
|
+
opacity: isSubmitting ? 0.6 : 1,
|
|
1489
1527
|
...bStyles.cardButton
|
|
1490
1528
|
},
|
|
1491
1529
|
onMouseDown: (e) => {
|
|
@@ -1569,6 +1607,12 @@ function SplitCardFormInner({
|
|
|
1569
1607
|
|
|
1570
1608
|
// src/flopay-checkout.tsx
|
|
1571
1609
|
import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1610
|
+
function hasInlineSessionPatchData(patch) {
|
|
1611
|
+
if (!patch) return false;
|
|
1612
|
+
return Boolean(
|
|
1613
|
+
patch.account && Object.keys(patch.account).length > 0 || patch.couponCodes !== void 0 || patch.tagsData !== void 0 || patch.utmMetadata !== void 0
|
|
1614
|
+
);
|
|
1615
|
+
}
|
|
1572
1616
|
function FloPayCheckout({
|
|
1573
1617
|
sessionId: sessionIdProp,
|
|
1574
1618
|
createSession: createSessionParams,
|
|
@@ -1616,7 +1660,6 @@ function FloPayCheckout({
|
|
|
1616
1660
|
const [createSessionPatch, setCreateSessionPatch] = useState3(void 0);
|
|
1617
1661
|
const [createSessionPatchBaseHash, setCreateSessionPatchBaseHash] = useState3("");
|
|
1618
1662
|
const [cardBootstrapPending, setCardBootstrapPending] = useState3(false);
|
|
1619
|
-
const [deferredCardOpen, setDeferredCardOpen] = useState3(false);
|
|
1620
1663
|
const autoCheckoutAttempted = useRef3(false);
|
|
1621
1664
|
const onCompleteRef = useRef3(onComplete);
|
|
1622
1665
|
onCompleteRef.current = onComplete;
|
|
@@ -1751,9 +1794,6 @@ function FloPayCheckout({
|
|
|
1751
1794
|
);
|
|
1752
1795
|
const inflightRef = useRef3(/* @__PURE__ */ new Map());
|
|
1753
1796
|
const initializedHashRef = useRef3(null);
|
|
1754
|
-
const deferInlineSessionUntilCardClick = Boolean(
|
|
1755
|
-
effectiveCreateSession && !children && layout === "buttons" && onBeforeButtonClick && (effectiveCreateSession.checkoutMode ?? checkoutModeProp ?? "full") === "full"
|
|
1756
|
-
);
|
|
1757
1797
|
function hashCreateParams(params) {
|
|
1758
1798
|
const key = JSON.stringify({
|
|
1759
1799
|
c: params?.clientId,
|
|
@@ -1783,7 +1823,6 @@ function FloPayCheckout({
|
|
|
1783
1823
|
setResolvedSessionId(sessionIdProp ?? "");
|
|
1784
1824
|
}, [sessionIdProp]);
|
|
1785
1825
|
async function resolveInlineSession(params, cacheKey) {
|
|
1786
|
-
ensureInlineSessionReady(params);
|
|
1787
1826
|
const api = new PaymentAPI(resolvedBillingUrl);
|
|
1788
1827
|
let sid = typeof window !== "undefined" ? window.sessionStorage.getItem(cacheKey) : null;
|
|
1789
1828
|
let realResult = null;
|
|
@@ -1828,104 +1867,64 @@ function FloPayCheckout({
|
|
|
1828
1867
|
} finally {
|
|
1829
1868
|
inflightRef.current.delete(cacheKey);
|
|
1830
1869
|
}
|
|
1831
|
-
if (patch) {
|
|
1832
|
-
setCreateSessionPatchBaseHash(baseCreateSessionHash);
|
|
1833
|
-
setCreateSessionPatch((prev) => mergeInlineSessionPatches(prev, patch));
|
|
1834
|
-
}
|
|
1835
|
-
const { sid, result: realResult } = resolved;
|
|
1836
|
-
setUnified(realResult);
|
|
1837
|
-
if (realResult.data.session) {
|
|
1838
|
-
setSession(realResult.data.session);
|
|
1839
|
-
}
|
|
1840
|
-
if (sid) {
|
|
1841
|
-
setResolvedSessionId(sid);
|
|
1842
|
-
}
|
|
1843
|
-
let publishableKey;
|
|
1844
|
-
if (realResult.provider === "stripe") {
|
|
1845
|
-
publishableKey = realResult.data.stripe?.publishableKey;
|
|
1846
|
-
}
|
|
1847
|
-
if (!publishableKey) publishableKey = fallbackPublishableKey;
|
|
1848
|
-
if (!publishableKey) {
|
|
1849
|
-
throw new FloPayError3(
|
|
1850
|
-
"No publishable key found. Provide fallbackPublishableKey or ensure the session includes gatewayData.publishableKey.",
|
|
1851
|
-
"validation_error"
|
|
1852
|
-
);
|
|
1853
|
-
}
|
|
1854
|
-
const instance = await loadFloPay(publishableKey, {
|
|
1855
|
-
billingApiUrl: resolvedBillingUrl,
|
|
1856
|
-
locale
|
|
1857
|
-
});
|
|
1858
|
-
flopayRef.current = instance;
|
|
1859
|
-
setFloPay(instance);
|
|
1860
1870
|
initializedHashRef.current = cacheKey;
|
|
1861
|
-
|
|
1871
|
+
try {
|
|
1872
|
+
if (patch) {
|
|
1873
|
+
setCreateSessionPatchBaseHash(baseCreateSessionHash);
|
|
1874
|
+
setCreateSessionPatch((prev) => mergeInlineSessionPatches(prev, patch));
|
|
1875
|
+
}
|
|
1876
|
+
const { sid, result: realResult } = resolved;
|
|
1877
|
+
setUnified(realResult);
|
|
1878
|
+
if (realResult.data.session) {
|
|
1879
|
+
setSession(realResult.data.session);
|
|
1880
|
+
}
|
|
1881
|
+
if (sid) {
|
|
1882
|
+
setResolvedSessionId(sid);
|
|
1883
|
+
}
|
|
1884
|
+
let publishableKey;
|
|
1885
|
+
if (realResult.provider === "stripe") {
|
|
1886
|
+
publishableKey = realResult.data.stripe?.publishableKey;
|
|
1887
|
+
}
|
|
1888
|
+
if (!publishableKey) publishableKey = fallbackPublishableKey;
|
|
1889
|
+
if (!publishableKey) {
|
|
1890
|
+
throw new FloPayError3(
|
|
1891
|
+
"No publishable key found. Provide fallbackPublishableKey or ensure the session includes gatewayData.publishableKey.",
|
|
1892
|
+
"validation_error"
|
|
1893
|
+
);
|
|
1894
|
+
}
|
|
1895
|
+
const instance = await loadFloPay(publishableKey, {
|
|
1896
|
+
billingApiUrl: resolvedBillingUrl,
|
|
1897
|
+
locale
|
|
1898
|
+
});
|
|
1899
|
+
flopayRef.current = instance;
|
|
1900
|
+
setFloPay(instance);
|
|
1901
|
+
setIsLoading(false);
|
|
1902
|
+
} catch (err) {
|
|
1903
|
+
if (initializedHashRef.current === cacheKey) {
|
|
1904
|
+
initializedHashRef.current = null;
|
|
1905
|
+
}
|
|
1906
|
+
throw err;
|
|
1907
|
+
}
|
|
1862
1908
|
return resolved;
|
|
1863
1909
|
},
|
|
1864
1910
|
[fallbackPublishableKey, locale, resolvedBillingUrl]
|
|
1865
1911
|
);
|
|
1866
|
-
const
|
|
1867
|
-
if (cardBootstrapPending) return;
|
|
1868
|
-
setLoadError(null);
|
|
1912
|
+
const handleInlineSessionPatch = useCallback2(async (patch) => {
|
|
1913
|
+
if (!hasInlineSessionPatchData(patch) || cardBootstrapPending) return;
|
|
1869
1914
|
setCardBootstrapPending(true);
|
|
1870
1915
|
try {
|
|
1871
|
-
const beforeClickResult = await onBeforeButtonClick?.({
|
|
1872
|
-
method: "card",
|
|
1873
|
-
createSession: effectiveCreateSession
|
|
1874
|
-
});
|
|
1875
|
-
if (beforeClickResult === false) {
|
|
1876
|
-
setDeferredCardOpen(false);
|
|
1877
|
-
return;
|
|
1878
|
-
}
|
|
1879
|
-
const patch = beforeClickResult && typeof beforeClickResult === "object" ? beforeClickResult : void 0;
|
|
1880
|
-
const baseParams = createSessionParamsRef.current;
|
|
1881
|
-
if (!baseParams) {
|
|
1882
|
-
throw new FloPayError3(
|
|
1883
|
-
"createSession is required to bootstrap checkout.",
|
|
1884
|
-
"validation_error"
|
|
1885
|
-
);
|
|
1886
|
-
}
|
|
1887
|
-
ensureInlineSessionReady(mergeInlineSessionPatch(baseParams, patch));
|
|
1888
|
-
setDeferredCardOpen(true);
|
|
1889
|
-
onButtonClick?.("card");
|
|
1890
1916
|
await bootstrapInlineSession(patch);
|
|
1891
|
-
} catch (err) {
|
|
1892
|
-
setDeferredCardOpen(false);
|
|
1893
|
-
const floPayErr = err instanceof FloPayError3 ? err : new FloPayError3(
|
|
1894
|
-
err instanceof Error ? err.message : "Failed to start card checkout.",
|
|
1895
|
-
"api_error"
|
|
1896
|
-
);
|
|
1897
|
-
setLoadError(floPayErr);
|
|
1898
|
-
onErrorRef.current?.(floPayErr);
|
|
1899
1917
|
} finally {
|
|
1900
1918
|
setCardBootstrapPending(false);
|
|
1901
1919
|
}
|
|
1902
1920
|
}, [
|
|
1903
1921
|
bootstrapInlineSession,
|
|
1904
|
-
|
|
1905
|
-
cardBootstrapPending,
|
|
1906
|
-
effectiveCreateSession,
|
|
1907
|
-
onButtonClick,
|
|
1908
|
-
onBeforeButtonClick
|
|
1922
|
+
cardBootstrapPending
|
|
1909
1923
|
]);
|
|
1910
1924
|
useEffect4(() => {
|
|
1911
1925
|
let cancelled = false;
|
|
1912
1926
|
setLoadError(null);
|
|
1913
1927
|
if (createSessionHash) {
|
|
1914
|
-
if (deferInlineSessionUntilCardClick) {
|
|
1915
|
-
if (initializedHashRef.current !== createSessionHash) {
|
|
1916
|
-
setSession(null);
|
|
1917
|
-
setUnified(null);
|
|
1918
|
-
setFloPay(null);
|
|
1919
|
-
setResolvedSessionId("");
|
|
1920
|
-
setDeferredCardOpen(false);
|
|
1921
|
-
flopayRef.current = null;
|
|
1922
|
-
}
|
|
1923
|
-
setCurrentMode(createSessionParamsRef.current?.checkoutMode ?? checkoutModeProp ?? "full");
|
|
1924
|
-
setIsLoading(false);
|
|
1925
|
-
return () => {
|
|
1926
|
-
cancelled = true;
|
|
1927
|
-
};
|
|
1928
|
-
}
|
|
1929
1928
|
if (initializedHashRef.current === createSessionHash) return;
|
|
1930
1929
|
const params = createSessionParamsRef.current;
|
|
1931
1930
|
setSession(buildSyntheticSession(params, checkoutModeProp));
|
|
@@ -2021,7 +2020,7 @@ function FloPayCheckout({
|
|
|
2021
2020
|
return () => {
|
|
2022
2021
|
cancelled = true;
|
|
2023
2022
|
};
|
|
2024
|
-
}, [resolvedSessionId, createSessionHash, checkoutModeProp,
|
|
2023
|
+
}, [resolvedSessionId, createSessionHash, checkoutModeProp, bootstrapInlineSession]);
|
|
2025
2024
|
const handleConfirmCheckout = useCallback2(async () => {
|
|
2026
2025
|
if (confirmProcessing || !session) return;
|
|
2027
2026
|
setConfirmProcessing(true);
|
|
@@ -2064,17 +2063,29 @@ function FloPayCheckout({
|
|
|
2064
2063
|
}
|
|
2065
2064
|
return opts;
|
|
2066
2065
|
}, [unified, session, appearance, resolvedBillingUrl]);
|
|
2066
|
+
const shouldHandleInlineSessionPatch = Boolean(
|
|
2067
|
+
createSessionParams && !children && layout === "buttons" && onBeforeButtonClick && (effectiveCreateSession?.checkoutMode ?? checkoutModeProp ?? "full") === "full"
|
|
2068
|
+
);
|
|
2067
2069
|
const checkoutValue = useMemo3(
|
|
2068
2070
|
() => ({
|
|
2069
2071
|
session,
|
|
2070
2072
|
loading: isLoading,
|
|
2071
2073
|
error: loadError,
|
|
2072
|
-
checkoutMode: currentMode
|
|
2074
|
+
checkoutMode: currentMode,
|
|
2075
|
+
applyInlineSessionPatch: shouldHandleInlineSessionPatch ? handleInlineSessionPatch : void 0,
|
|
2076
|
+
inlineSessionPatchProcessing: cardBootstrapPending
|
|
2073
2077
|
}),
|
|
2074
|
-
[
|
|
2078
|
+
[
|
|
2079
|
+
session,
|
|
2080
|
+
isLoading,
|
|
2081
|
+
loadError,
|
|
2082
|
+
currentMode,
|
|
2083
|
+
shouldHandleInlineSessionPatch,
|
|
2084
|
+
handleInlineSessionPatch,
|
|
2085
|
+
cardBootstrapPending
|
|
2086
|
+
]
|
|
2075
2087
|
);
|
|
2076
2088
|
const shouldShowInterimButtons = Boolean(createSessionParams) && layout === "buttons" && (!flopay || !providerOptions);
|
|
2077
|
-
const shouldKeepDeferredInterimVisible = shouldShowInterimButtons && deferInlineSessionUntilCardClick;
|
|
2078
2089
|
if (isLoading) {
|
|
2079
2090
|
if (loadingNode) return /* @__PURE__ */ jsx5(Fragment3, { children: loadingNode });
|
|
2080
2091
|
if (layout === "buttons") {
|
|
@@ -2103,7 +2114,7 @@ function FloPayCheckout({
|
|
|
2103
2114
|
/* @__PURE__ */ jsx5("style", { children: `@keyframes spin { to { transform: rotate(360deg); } }` })
|
|
2104
2115
|
] });
|
|
2105
2116
|
}
|
|
2106
|
-
if (loadError
|
|
2117
|
+
if (loadError) {
|
|
2107
2118
|
if (errorNode) return /* @__PURE__ */ jsx5(Fragment3, { children: errorNode(loadError) });
|
|
2108
2119
|
return /* @__PURE__ */ jsx5(
|
|
2109
2120
|
"div",
|
|
@@ -2123,13 +2134,9 @@ function FloPayCheckout({
|
|
|
2123
2134
|
InterimButtonsView,
|
|
2124
2135
|
{
|
|
2125
2136
|
onButtonClick,
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
errorMessage: shouldKeepDeferredInterimVisible ? loadError?.message ?? null : null,
|
|
2130
|
-
showPayPal: deferInlineSessionUntilCardClick ? false : showPayPal,
|
|
2131
|
-
showApplePay: deferInlineSessionUntilCardClick ? false : showApplePay,
|
|
2132
|
-
showGooglePay: deferInlineSessionUntilCardClick ? false : showGooglePay,
|
|
2137
|
+
showPayPal,
|
|
2138
|
+
showApplePay,
|
|
2139
|
+
showGooglePay,
|
|
2133
2140
|
buttonsTheme,
|
|
2134
2141
|
buttonsStyles,
|
|
2135
2142
|
cardButtonContent,
|
|
@@ -2230,7 +2237,6 @@ function FloPayCheckout({
|
|
|
2230
2237
|
enableAVS,
|
|
2231
2238
|
avsLayout,
|
|
2232
2239
|
country: session?.customer?.country,
|
|
2233
|
-
initialCardOpen: deferredCardOpen,
|
|
2234
2240
|
submitLabel,
|
|
2235
2241
|
className
|
|
2236
2242
|
}
|