@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/README.md
CHANGED
|
@@ -178,7 +178,7 @@ Skip the backend API route — create the session directly in the component:
|
|
|
178
178
|
|
|
179
179
|
The component POSTs to the billing API, gets the full session back, and renders the form — zero backend code needed.
|
|
180
180
|
|
|
181
|
-
When you use `onBeforeButtonClick`, `createSession.account.email` can be filled in later for the card-button flow. PayPal and
|
|
181
|
+
When you use `onBeforeButtonClick`, `createSession.account.email` can still be filled in later for the card-button flow. PayPal and wallet buttons still bootstrap normally, but this hook does not run for them, so collect any data those methods require before the user uses them.
|
|
182
182
|
|
|
183
183
|
### Advanced: Manual Provider Setup
|
|
184
184
|
|
package/dist/index.cjs
CHANGED
|
@@ -351,15 +351,6 @@ function buildSyntheticSession(params, checkoutModeOverride) {
|
|
|
351
351
|
}))
|
|
352
352
|
};
|
|
353
353
|
}
|
|
354
|
-
function ensureInlineSessionReady(params) {
|
|
355
|
-
if (!params.account.email?.trim()) {
|
|
356
|
-
throw new import_shared3.FloPayError(
|
|
357
|
-
"Email is required before continuing with card checkout.",
|
|
358
|
-
"validation_error",
|
|
359
|
-
{ param: "createSession.account.email" }
|
|
360
|
-
);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
354
|
function mergeAccountPatch(base, patch) {
|
|
364
355
|
if (!patch) return base;
|
|
365
356
|
return {
|
|
@@ -406,6 +397,14 @@ var FLOPAY_KEYFRAMES = `
|
|
|
406
397
|
function FloPayKeyframes() {
|
|
407
398
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("style", { children: FLOPAY_KEYFRAMES });
|
|
408
399
|
}
|
|
400
|
+
function toCssSize(value) {
|
|
401
|
+
if (typeof value === "number") return `${value}px`;
|
|
402
|
+
return value;
|
|
403
|
+
}
|
|
404
|
+
function toCssWeight(value) {
|
|
405
|
+
if (typeof value === "number" || typeof value === "string") return value;
|
|
406
|
+
return void 0;
|
|
407
|
+
}
|
|
409
408
|
function ProcessingOverlay({ status, errorMessage }) {
|
|
410
409
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: {
|
|
411
410
|
position: "fixed",
|
|
@@ -813,6 +812,7 @@ function SplitCardFormInner({
|
|
|
813
812
|
}) {
|
|
814
813
|
const flopay = useFloPay();
|
|
815
814
|
const elements = useElements();
|
|
815
|
+
const checkout = (0, import_react6.useContext)(CheckoutContext);
|
|
816
816
|
const contextBillingUrl = useBillingApiUrl();
|
|
817
817
|
const [processing, setProcessing] = (0, import_react6.useState)(false);
|
|
818
818
|
const [error, setError] = (0, import_react6.useState)(null);
|
|
@@ -858,7 +858,8 @@ function SplitCardFormInner({
|
|
|
858
858
|
title: { ...base.title, ...buttonsStylesOverride.title }
|
|
859
859
|
};
|
|
860
860
|
}, [buttonsTheme, buttonsStylesOverride]);
|
|
861
|
-
const
|
|
861
|
+
const isInlineSessionPatchProcessing = checkout.inlineSessionPatchProcessing ?? false;
|
|
862
|
+
const isSubmitting = (externalProcessing ?? processing) || isInlineSessionPatchProcessing;
|
|
862
863
|
const isSelfContained = !onTokenizedBody;
|
|
863
864
|
const baseUrl = resolvedBillingApiUrl.replace(/\/+$/, "");
|
|
864
865
|
const resolvedAccount = (0, import_react6.useMemo)(() => mergeAccountPatch({
|
|
@@ -917,8 +918,11 @@ function SplitCardFormInner({
|
|
|
917
918
|
if (result === false) {
|
|
918
919
|
return false;
|
|
919
920
|
}
|
|
920
|
-
if (result
|
|
921
|
-
|
|
921
|
+
if (result && typeof result === "object") {
|
|
922
|
+
await checkout.applyInlineSessionPatch?.(result);
|
|
923
|
+
if (result.account) {
|
|
924
|
+
setAccountPatch((prev) => ({ ...prev ?? {}, ...result.account }));
|
|
925
|
+
}
|
|
922
926
|
}
|
|
923
927
|
return true;
|
|
924
928
|
} catch (err) {
|
|
@@ -930,7 +934,7 @@ function SplitCardFormInner({
|
|
|
930
934
|
onError?.(floPayErr);
|
|
931
935
|
return false;
|
|
932
936
|
}
|
|
933
|
-
}, [onBeforeButtonClick, sessionId, updateError, onError]);
|
|
937
|
+
}, [checkout.applyInlineSessionPatch, onBeforeButtonClick, sessionId, updateError, onError]);
|
|
934
938
|
const processPaymentInternal = (0, import_react6.useCallback)(
|
|
935
939
|
async (tokenizedBody) => {
|
|
936
940
|
if (processingRef.current) return;
|
|
@@ -1207,23 +1211,58 @@ function SplitCardFormInner({
|
|
|
1207
1211
|
const cardInputBg = isButtons ? bStyles.cardInputBackground ?? "white" : "white";
|
|
1208
1212
|
const hideBackButtonLabel = isEmptySlotContent(cardBackButtonContent);
|
|
1209
1213
|
const hideTitle = isEmptySlotContent(cardTitleContent);
|
|
1210
|
-
const
|
|
1214
|
+
const nameInputOverrides = isButtons ? bStyles.nameInput : void 0;
|
|
1215
|
+
const resolvedInputFontSize = bStyles.cardInputFontSize ?? toCssSize(nameInputOverrides?.fontSize) ?? "16px";
|
|
1216
|
+
const resolvedInputFontFamily = typeof nameInputOverrides?.fontFamily === "string" ? nameInputOverrides.fontFamily : "Poppins, sans-serif";
|
|
1217
|
+
const resolvedInputFontWeight = toCssWeight(nameInputOverrides?.fontWeight) ?? 400;
|
|
1218
|
+
const resolvedInputColor = bStyles.cardInputColor ?? (typeof nameInputOverrides?.color === "string" ? nameInputOverrides.color : void 0) ?? "#262833";
|
|
1219
|
+
const resolvedPlaceholderColor = bStyles.cardInputPlaceholderColor ?? "#9ca3af";
|
|
1220
|
+
const sharedInputTypography = {
|
|
1221
|
+
fontSize: resolvedInputFontSize,
|
|
1222
|
+
fontFamily: resolvedInputFontFamily,
|
|
1223
|
+
fontWeight: resolvedInputFontWeight,
|
|
1224
|
+
color: resolvedInputColor,
|
|
1225
|
+
WebkitFontSmoothing: "antialiased",
|
|
1226
|
+
MozOsxFontSmoothing: "grayscale"
|
|
1227
|
+
};
|
|
1228
|
+
const sharedInputPlaceholderVars = {
|
|
1229
|
+
"--flopay-input-placeholder-color": resolvedPlaceholderColor,
|
|
1230
|
+
"--flopay-input-font-size": resolvedInputFontSize,
|
|
1231
|
+
"--flopay-input-font-family": resolvedInputFontFamily,
|
|
1232
|
+
"--flopay-input-font-weight": String(resolvedInputFontWeight)
|
|
1233
|
+
};
|
|
1234
|
+
const stripeElementStyle = {
|
|
1211
1235
|
style: {
|
|
1212
1236
|
base: {
|
|
1213
|
-
...
|
|
1214
|
-
|
|
1215
|
-
|
|
1237
|
+
...sharedInputTypography,
|
|
1238
|
+
fontSmoothing: "antialiased",
|
|
1239
|
+
"::placeholder": {
|
|
1240
|
+
color: resolvedPlaceholderColor,
|
|
1241
|
+
fontSize: resolvedInputFontSize,
|
|
1242
|
+
fontFamily: resolvedInputFontFamily,
|
|
1243
|
+
fontWeight: resolvedInputFontWeight
|
|
1244
|
+
}
|
|
1216
1245
|
},
|
|
1217
1246
|
invalid: { color: "#ef4444" }
|
|
1218
1247
|
}
|
|
1219
|
-
}
|
|
1248
|
+
};
|
|
1220
1249
|
const cardFormBlock = /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: {
|
|
1221
1250
|
backgroundColor: cardBg,
|
|
1222
1251
|
borderRadius: "8px",
|
|
1223
1252
|
padding: isButtons ? "0" : "1rem",
|
|
1224
1253
|
...isButtons ? bStyles.cardFormContainer : {},
|
|
1225
|
-
...isButtons ? { padding: bStyles.cardFormContainer?.padding ?? "0" } : {}
|
|
1254
|
+
...isButtons ? { padding: bStyles.cardFormContainer?.padding ?? "0" } : {},
|
|
1255
|
+
...sharedInputPlaceholderVars
|
|
1226
1256
|
}, children: [
|
|
1257
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("style", { children: `
|
|
1258
|
+
.flopay-shared-input::placeholder {
|
|
1259
|
+
color: var(--flopay-input-placeholder-color);
|
|
1260
|
+
opacity: 1;
|
|
1261
|
+
font-size: var(--flopay-input-font-size);
|
|
1262
|
+
font-family: var(--flopay-input-font-family);
|
|
1263
|
+
font-weight: var(--flopay-input-font-weight);
|
|
1264
|
+
}
|
|
1265
|
+
` }),
|
|
1227
1266
|
isButtons && showCardForm && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: {
|
|
1228
1267
|
display: "flex",
|
|
1229
1268
|
alignItems: "center",
|
|
@@ -1312,6 +1351,7 @@ function SplitCardFormInner({
|
|
|
1312
1351
|
}, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1313
1352
|
"input",
|
|
1314
1353
|
{
|
|
1354
|
+
className: "flopay-shared-input",
|
|
1315
1355
|
placeholder: "Full Name on Card",
|
|
1316
1356
|
autoComplete: "cc-name",
|
|
1317
1357
|
value: fullName,
|
|
@@ -1323,9 +1363,7 @@ function SplitCardFormInner({
|
|
|
1323
1363
|
border: "none",
|
|
1324
1364
|
outline: "none",
|
|
1325
1365
|
background: "transparent",
|
|
1326
|
-
|
|
1327
|
-
fontFamily: "Poppins, sans-serif",
|
|
1328
|
-
color: bStyles.cardInputColor ?? "#262833",
|
|
1366
|
+
...sharedInputTypography,
|
|
1329
1367
|
...isButtons && bStyles.nameInput ? bStyles.nameInput : {}
|
|
1330
1368
|
}
|
|
1331
1369
|
}
|
|
@@ -1360,9 +1398,7 @@ function SplitCardFormInner({
|
|
|
1360
1398
|
border: "none",
|
|
1361
1399
|
outline: "none",
|
|
1362
1400
|
background: "transparent",
|
|
1363
|
-
|
|
1364
|
-
fontFamily: "Poppins, sans-serif",
|
|
1365
|
-
color: bStyles.cardInputColor ?? "#262833",
|
|
1401
|
+
...sharedInputTypography,
|
|
1366
1402
|
cursor: "pointer",
|
|
1367
1403
|
...isButtons && bStyles.nameInput ? bStyles.nameInput : {}
|
|
1368
1404
|
},
|
|
@@ -1383,6 +1419,7 @@ function SplitCardFormInner({
|
|
|
1383
1419
|
}, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1384
1420
|
"input",
|
|
1385
1421
|
{
|
|
1422
|
+
className: "flopay-shared-input",
|
|
1386
1423
|
placeholder: (0, import_shared4.getPostalCodeLabel)(selectedCountry),
|
|
1387
1424
|
autoComplete: "postal-code",
|
|
1388
1425
|
value: zipCode,
|
|
@@ -1399,9 +1436,7 @@ function SplitCardFormInner({
|
|
|
1399
1436
|
border: "none",
|
|
1400
1437
|
outline: "none",
|
|
1401
1438
|
background: "transparent",
|
|
1402
|
-
|
|
1403
|
-
fontFamily: "Poppins, sans-serif",
|
|
1404
|
-
color: bStyles.cardInputColor ?? "#262833",
|
|
1439
|
+
...sharedInputTypography,
|
|
1405
1440
|
...isButtons && bStyles.nameInput ? bStyles.nameInput : {}
|
|
1406
1441
|
}
|
|
1407
1442
|
}
|
|
@@ -1508,11 +1543,13 @@ function SplitCardFormInner({
|
|
|
1508
1543
|
{
|
|
1509
1544
|
type: "button",
|
|
1510
1545
|
onClick: async () => {
|
|
1546
|
+
if (isSubmitting) return;
|
|
1511
1547
|
const shouldContinue = await runBeforeCardButtonClick();
|
|
1512
1548
|
if (!shouldContinue) return;
|
|
1513
1549
|
onButtonClick?.("card");
|
|
1514
1550
|
expandToCard();
|
|
1515
1551
|
},
|
|
1552
|
+
disabled: isSubmitting,
|
|
1516
1553
|
style: {
|
|
1517
1554
|
width: "100%",
|
|
1518
1555
|
padding: "0.9rem 1rem",
|
|
@@ -1522,7 +1559,7 @@ function SplitCardFormInner({
|
|
|
1522
1559
|
borderRadius: "8px",
|
|
1523
1560
|
fontSize: bStyles.cardButtonFontSize ?? "0.95rem",
|
|
1524
1561
|
fontWeight: 600,
|
|
1525
|
-
cursor: "pointer",
|
|
1562
|
+
cursor: isSubmitting ? "not-allowed" : "pointer",
|
|
1526
1563
|
display: "flex",
|
|
1527
1564
|
alignItems: "center",
|
|
1528
1565
|
justifyContent: "center",
|
|
@@ -1530,6 +1567,7 @@ function SplitCardFormInner({
|
|
|
1530
1567
|
transition: "border-color 0.2s, box-shadow 0.2s, transform 0.1s",
|
|
1531
1568
|
boxShadow: "0 1px 2px rgba(0,0,0,0.04)",
|
|
1532
1569
|
position: "relative",
|
|
1570
|
+
opacity: isSubmitting ? 0.6 : 1,
|
|
1533
1571
|
...bStyles.cardButton
|
|
1534
1572
|
},
|
|
1535
1573
|
onMouseDown: (e) => {
|
|
@@ -1613,6 +1651,12 @@ function SplitCardFormInner({
|
|
|
1613
1651
|
|
|
1614
1652
|
// src/flopay-checkout.tsx
|
|
1615
1653
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1654
|
+
function hasInlineSessionPatchData(patch) {
|
|
1655
|
+
if (!patch) return false;
|
|
1656
|
+
return Boolean(
|
|
1657
|
+
patch.account && Object.keys(patch.account).length > 0 || patch.couponCodes !== void 0 || patch.tagsData !== void 0 || patch.utmMetadata !== void 0
|
|
1658
|
+
);
|
|
1659
|
+
}
|
|
1616
1660
|
function FloPayCheckout({
|
|
1617
1661
|
sessionId: sessionIdProp,
|
|
1618
1662
|
createSession: createSessionParams,
|
|
@@ -1660,7 +1704,6 @@ function FloPayCheckout({
|
|
|
1660
1704
|
const [createSessionPatch, setCreateSessionPatch] = (0, import_react7.useState)(void 0);
|
|
1661
1705
|
const [createSessionPatchBaseHash, setCreateSessionPatchBaseHash] = (0, import_react7.useState)("");
|
|
1662
1706
|
const [cardBootstrapPending, setCardBootstrapPending] = (0, import_react7.useState)(false);
|
|
1663
|
-
const [deferredCardOpen, setDeferredCardOpen] = (0, import_react7.useState)(false);
|
|
1664
1707
|
const autoCheckoutAttempted = (0, import_react7.useRef)(false);
|
|
1665
1708
|
const onCompleteRef = (0, import_react7.useRef)(onComplete);
|
|
1666
1709
|
onCompleteRef.current = onComplete;
|
|
@@ -1795,9 +1838,6 @@ function FloPayCheckout({
|
|
|
1795
1838
|
);
|
|
1796
1839
|
const inflightRef = (0, import_react7.useRef)(/* @__PURE__ */ new Map());
|
|
1797
1840
|
const initializedHashRef = (0, import_react7.useRef)(null);
|
|
1798
|
-
const deferInlineSessionUntilCardClick = Boolean(
|
|
1799
|
-
effectiveCreateSession && !children && layout === "buttons" && onBeforeButtonClick && (effectiveCreateSession.checkoutMode ?? checkoutModeProp ?? "full") === "full"
|
|
1800
|
-
);
|
|
1801
1841
|
function hashCreateParams(params) {
|
|
1802
1842
|
const key = JSON.stringify({
|
|
1803
1843
|
c: params?.clientId,
|
|
@@ -1827,7 +1867,6 @@ function FloPayCheckout({
|
|
|
1827
1867
|
setResolvedSessionId(sessionIdProp ?? "");
|
|
1828
1868
|
}, [sessionIdProp]);
|
|
1829
1869
|
async function resolveInlineSession(params, cacheKey) {
|
|
1830
|
-
ensureInlineSessionReady(params);
|
|
1831
1870
|
const api = new import_js.PaymentAPI(resolvedBillingUrl);
|
|
1832
1871
|
let sid = typeof window !== "undefined" ? window.sessionStorage.getItem(cacheKey) : null;
|
|
1833
1872
|
let realResult = null;
|
|
@@ -1872,104 +1911,64 @@ function FloPayCheckout({
|
|
|
1872
1911
|
} finally {
|
|
1873
1912
|
inflightRef.current.delete(cacheKey);
|
|
1874
1913
|
}
|
|
1875
|
-
if (patch) {
|
|
1876
|
-
setCreateSessionPatchBaseHash(baseCreateSessionHash);
|
|
1877
|
-
setCreateSessionPatch((prev) => mergeInlineSessionPatches(prev, patch));
|
|
1878
|
-
}
|
|
1879
|
-
const { sid, result: realResult } = resolved;
|
|
1880
|
-
setUnified(realResult);
|
|
1881
|
-
if (realResult.data.session) {
|
|
1882
|
-
setSession(realResult.data.session);
|
|
1883
|
-
}
|
|
1884
|
-
if (sid) {
|
|
1885
|
-
setResolvedSessionId(sid);
|
|
1886
|
-
}
|
|
1887
|
-
let publishableKey;
|
|
1888
|
-
if (realResult.provider === "stripe") {
|
|
1889
|
-
publishableKey = realResult.data.stripe?.publishableKey;
|
|
1890
|
-
}
|
|
1891
|
-
if (!publishableKey) publishableKey = fallbackPublishableKey;
|
|
1892
|
-
if (!publishableKey) {
|
|
1893
|
-
throw new import_shared6.FloPayError(
|
|
1894
|
-
"No publishable key found. Provide fallbackPublishableKey or ensure the session includes gatewayData.publishableKey.",
|
|
1895
|
-
"validation_error"
|
|
1896
|
-
);
|
|
1897
|
-
}
|
|
1898
|
-
const instance = await (0, import_js.loadFloPay)(publishableKey, {
|
|
1899
|
-
billingApiUrl: resolvedBillingUrl,
|
|
1900
|
-
locale
|
|
1901
|
-
});
|
|
1902
|
-
flopayRef.current = instance;
|
|
1903
|
-
setFloPay(instance);
|
|
1904
1914
|
initializedHashRef.current = cacheKey;
|
|
1905
|
-
|
|
1915
|
+
try {
|
|
1916
|
+
if (patch) {
|
|
1917
|
+
setCreateSessionPatchBaseHash(baseCreateSessionHash);
|
|
1918
|
+
setCreateSessionPatch((prev) => mergeInlineSessionPatches(prev, patch));
|
|
1919
|
+
}
|
|
1920
|
+
const { sid, result: realResult } = resolved;
|
|
1921
|
+
setUnified(realResult);
|
|
1922
|
+
if (realResult.data.session) {
|
|
1923
|
+
setSession(realResult.data.session);
|
|
1924
|
+
}
|
|
1925
|
+
if (sid) {
|
|
1926
|
+
setResolvedSessionId(sid);
|
|
1927
|
+
}
|
|
1928
|
+
let publishableKey;
|
|
1929
|
+
if (realResult.provider === "stripe") {
|
|
1930
|
+
publishableKey = realResult.data.stripe?.publishableKey;
|
|
1931
|
+
}
|
|
1932
|
+
if (!publishableKey) publishableKey = fallbackPublishableKey;
|
|
1933
|
+
if (!publishableKey) {
|
|
1934
|
+
throw new import_shared6.FloPayError(
|
|
1935
|
+
"No publishable key found. Provide fallbackPublishableKey or ensure the session includes gatewayData.publishableKey.",
|
|
1936
|
+
"validation_error"
|
|
1937
|
+
);
|
|
1938
|
+
}
|
|
1939
|
+
const instance = await (0, import_js.loadFloPay)(publishableKey, {
|
|
1940
|
+
billingApiUrl: resolvedBillingUrl,
|
|
1941
|
+
locale
|
|
1942
|
+
});
|
|
1943
|
+
flopayRef.current = instance;
|
|
1944
|
+
setFloPay(instance);
|
|
1945
|
+
setIsLoading(false);
|
|
1946
|
+
} catch (err) {
|
|
1947
|
+
if (initializedHashRef.current === cacheKey) {
|
|
1948
|
+
initializedHashRef.current = null;
|
|
1949
|
+
}
|
|
1950
|
+
throw err;
|
|
1951
|
+
}
|
|
1906
1952
|
return resolved;
|
|
1907
1953
|
},
|
|
1908
1954
|
[fallbackPublishableKey, locale, resolvedBillingUrl]
|
|
1909
1955
|
);
|
|
1910
|
-
const
|
|
1911
|
-
if (cardBootstrapPending) return;
|
|
1912
|
-
setLoadError(null);
|
|
1956
|
+
const handleInlineSessionPatch = (0, import_react7.useCallback)(async (patch) => {
|
|
1957
|
+
if (!hasInlineSessionPatchData(patch) || cardBootstrapPending) return;
|
|
1913
1958
|
setCardBootstrapPending(true);
|
|
1914
1959
|
try {
|
|
1915
|
-
const beforeClickResult = await onBeforeButtonClick?.({
|
|
1916
|
-
method: "card",
|
|
1917
|
-
createSession: effectiveCreateSession
|
|
1918
|
-
});
|
|
1919
|
-
if (beforeClickResult === false) {
|
|
1920
|
-
setDeferredCardOpen(false);
|
|
1921
|
-
return;
|
|
1922
|
-
}
|
|
1923
|
-
const patch = beforeClickResult && typeof beforeClickResult === "object" ? beforeClickResult : void 0;
|
|
1924
|
-
const baseParams = createSessionParamsRef.current;
|
|
1925
|
-
if (!baseParams) {
|
|
1926
|
-
throw new import_shared6.FloPayError(
|
|
1927
|
-
"createSession is required to bootstrap checkout.",
|
|
1928
|
-
"validation_error"
|
|
1929
|
-
);
|
|
1930
|
-
}
|
|
1931
|
-
ensureInlineSessionReady(mergeInlineSessionPatch(baseParams, patch));
|
|
1932
|
-
setDeferredCardOpen(true);
|
|
1933
|
-
onButtonClick?.("card");
|
|
1934
1960
|
await bootstrapInlineSession(patch);
|
|
1935
|
-
} catch (err) {
|
|
1936
|
-
setDeferredCardOpen(false);
|
|
1937
|
-
const floPayErr = err instanceof import_shared6.FloPayError ? err : new import_shared6.FloPayError(
|
|
1938
|
-
err instanceof Error ? err.message : "Failed to start card checkout.",
|
|
1939
|
-
"api_error"
|
|
1940
|
-
);
|
|
1941
|
-
setLoadError(floPayErr);
|
|
1942
|
-
onErrorRef.current?.(floPayErr);
|
|
1943
1961
|
} finally {
|
|
1944
1962
|
setCardBootstrapPending(false);
|
|
1945
1963
|
}
|
|
1946
1964
|
}, [
|
|
1947
1965
|
bootstrapInlineSession,
|
|
1948
|
-
|
|
1949
|
-
cardBootstrapPending,
|
|
1950
|
-
effectiveCreateSession,
|
|
1951
|
-
onButtonClick,
|
|
1952
|
-
onBeforeButtonClick
|
|
1966
|
+
cardBootstrapPending
|
|
1953
1967
|
]);
|
|
1954
1968
|
(0, import_react7.useEffect)(() => {
|
|
1955
1969
|
let cancelled = false;
|
|
1956
1970
|
setLoadError(null);
|
|
1957
1971
|
if (createSessionHash) {
|
|
1958
|
-
if (deferInlineSessionUntilCardClick) {
|
|
1959
|
-
if (initializedHashRef.current !== createSessionHash) {
|
|
1960
|
-
setSession(null);
|
|
1961
|
-
setUnified(null);
|
|
1962
|
-
setFloPay(null);
|
|
1963
|
-
setResolvedSessionId("");
|
|
1964
|
-
setDeferredCardOpen(false);
|
|
1965
|
-
flopayRef.current = null;
|
|
1966
|
-
}
|
|
1967
|
-
setCurrentMode(createSessionParamsRef.current?.checkoutMode ?? checkoutModeProp ?? "full");
|
|
1968
|
-
setIsLoading(false);
|
|
1969
|
-
return () => {
|
|
1970
|
-
cancelled = true;
|
|
1971
|
-
};
|
|
1972
|
-
}
|
|
1973
1972
|
if (initializedHashRef.current === createSessionHash) return;
|
|
1974
1973
|
const params = createSessionParamsRef.current;
|
|
1975
1974
|
setSession(buildSyntheticSession(params, checkoutModeProp));
|
|
@@ -2065,7 +2064,7 @@ function FloPayCheckout({
|
|
|
2065
2064
|
return () => {
|
|
2066
2065
|
cancelled = true;
|
|
2067
2066
|
};
|
|
2068
|
-
}, [resolvedSessionId, createSessionHash, checkoutModeProp,
|
|
2067
|
+
}, [resolvedSessionId, createSessionHash, checkoutModeProp, bootstrapInlineSession]);
|
|
2069
2068
|
const handleConfirmCheckout = (0, import_react7.useCallback)(async () => {
|
|
2070
2069
|
if (confirmProcessing || !session) return;
|
|
2071
2070
|
setConfirmProcessing(true);
|
|
@@ -2108,17 +2107,29 @@ function FloPayCheckout({
|
|
|
2108
2107
|
}
|
|
2109
2108
|
return opts;
|
|
2110
2109
|
}, [unified, session, appearance, resolvedBillingUrl]);
|
|
2110
|
+
const shouldHandleInlineSessionPatch = Boolean(
|
|
2111
|
+
createSessionParams && !children && layout === "buttons" && onBeforeButtonClick && (effectiveCreateSession?.checkoutMode ?? checkoutModeProp ?? "full") === "full"
|
|
2112
|
+
);
|
|
2111
2113
|
const checkoutValue = (0, import_react7.useMemo)(
|
|
2112
2114
|
() => ({
|
|
2113
2115
|
session,
|
|
2114
2116
|
loading: isLoading,
|
|
2115
2117
|
error: loadError,
|
|
2116
|
-
checkoutMode: currentMode
|
|
2118
|
+
checkoutMode: currentMode,
|
|
2119
|
+
applyInlineSessionPatch: shouldHandleInlineSessionPatch ? handleInlineSessionPatch : void 0,
|
|
2120
|
+
inlineSessionPatchProcessing: cardBootstrapPending
|
|
2117
2121
|
}),
|
|
2118
|
-
[
|
|
2122
|
+
[
|
|
2123
|
+
session,
|
|
2124
|
+
isLoading,
|
|
2125
|
+
loadError,
|
|
2126
|
+
currentMode,
|
|
2127
|
+
shouldHandleInlineSessionPatch,
|
|
2128
|
+
handleInlineSessionPatch,
|
|
2129
|
+
cardBootstrapPending
|
|
2130
|
+
]
|
|
2119
2131
|
);
|
|
2120
2132
|
const shouldShowInterimButtons = Boolean(createSessionParams) && layout === "buttons" && (!flopay || !providerOptions);
|
|
2121
|
-
const shouldKeepDeferredInterimVisible = shouldShowInterimButtons && deferInlineSessionUntilCardClick;
|
|
2122
2133
|
if (isLoading) {
|
|
2123
2134
|
if (loadingNode) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: loadingNode });
|
|
2124
2135
|
if (layout === "buttons") {
|
|
@@ -2147,7 +2158,7 @@ function FloPayCheckout({
|
|
|
2147
2158
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("style", { children: `@keyframes spin { to { transform: rotate(360deg); } }` })
|
|
2148
2159
|
] });
|
|
2149
2160
|
}
|
|
2150
|
-
if (loadError
|
|
2161
|
+
if (loadError) {
|
|
2151
2162
|
if (errorNode) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: errorNode(loadError) });
|
|
2152
2163
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2153
2164
|
"div",
|
|
@@ -2167,13 +2178,9 @@ function FloPayCheckout({
|
|
|
2167
2178
|
InterimButtonsView,
|
|
2168
2179
|
{
|
|
2169
2180
|
onButtonClick,
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
errorMessage: shouldKeepDeferredInterimVisible ? loadError?.message ?? null : null,
|
|
2174
|
-
showPayPal: deferInlineSessionUntilCardClick ? false : showPayPal,
|
|
2175
|
-
showApplePay: deferInlineSessionUntilCardClick ? false : showApplePay,
|
|
2176
|
-
showGooglePay: deferInlineSessionUntilCardClick ? false : showGooglePay,
|
|
2181
|
+
showPayPal,
|
|
2182
|
+
showApplePay,
|
|
2183
|
+
showGooglePay,
|
|
2177
2184
|
buttonsTheme,
|
|
2178
2185
|
buttonsStyles,
|
|
2179
2186
|
cardButtonContent,
|
|
@@ -2274,7 +2281,6 @@ function FloPayCheckout({
|
|
|
2274
2281
|
enableAVS,
|
|
2275
2282
|
avsLayout,
|
|
2276
2283
|
country: session?.customer?.country,
|
|
2277
|
-
initialCardOpen: deferredCardOpen,
|
|
2278
2284
|
submitLabel,
|
|
2279
2285
|
className
|
|
2280
2286
|
}
|