tf-checkout-react 2.0.0-beta.0 → 2.0.0-beta.1
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.d.mts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.esm.js +80 -27
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +80 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/auth/AuthModal.tsx +9 -2
- package/src/sections/BillingInfo.tsx +67 -20
- package/src/sections/Payment.tsx +20 -4
- package/src/sections/billing/TicketHoldersCard.tsx +5 -0
- package/src/sections/billing/fieldRules.ts +43 -0
package/dist/index.js
CHANGED
|
@@ -2643,22 +2643,29 @@ var getOrderReview = async (orderHash) => {
|
|
|
2643
2643
|
};
|
|
2644
2644
|
};
|
|
2645
2645
|
var mapProfileToBilling = (profile) => {
|
|
2646
|
-
var _a, _b, _c;
|
|
2646
|
+
var _a, _b, _c, _d;
|
|
2647
2647
|
const str = (v) => v == null || v === "" ? void 0 : String(v);
|
|
2648
2648
|
const idStr = (v) => {
|
|
2649
2649
|
const s = str(v);
|
|
2650
2650
|
return s === void 0 || s === "0" || s === "-1" ? void 0 : s;
|
|
2651
2651
|
};
|
|
2652
|
+
const dobParts = /^(\d{4})-(\d{2})-(\d{2})/.exec((_a = profile.dateOfBirth) != null ? _a : "");
|
|
2653
|
+
const dob = dobParts && Number(dobParts[1]) > 1900 ? {
|
|
2654
|
+
dobYear: Number(dobParts[1]),
|
|
2655
|
+
dobMonth: Number(dobParts[2]),
|
|
2656
|
+
dobDay: Number(dobParts[3])
|
|
2657
|
+
} : {};
|
|
2652
2658
|
return {
|
|
2653
|
-
firstName: (
|
|
2654
|
-
lastName: (
|
|
2655
|
-
email: (
|
|
2659
|
+
firstName: (_b = profile.firstName) != null ? _b : "",
|
|
2660
|
+
lastName: (_c = profile.lastName) != null ? _c : "",
|
|
2661
|
+
email: (_d = profile.email) != null ? _d : "",
|
|
2656
2662
|
phone: str(profile.phone),
|
|
2657
2663
|
streetAddress: str(profile.streetAddress),
|
|
2658
2664
|
city: str(profile.city),
|
|
2659
2665
|
zip: str(profile.zipCode),
|
|
2660
2666
|
countryId: idStr(profile.countryId),
|
|
2661
|
-
stateId: idStr(profile.stateId)
|
|
2667
|
+
stateId: idStr(profile.stateId),
|
|
2668
|
+
...dob
|
|
2662
2669
|
};
|
|
2663
2670
|
};
|
|
2664
2671
|
var completeFreeRegistration = async (orderHash) => {
|
|
@@ -3583,6 +3590,10 @@ var createEngine = (config) => {
|
|
|
3583
3590
|
reset: () => {
|
|
3584
3591
|
clearCartGuestToken();
|
|
3585
3592
|
store.reset();
|
|
3593
|
+
},
|
|
3594
|
+
expireCart: () => {
|
|
3595
|
+
clearCartGuestToken();
|
|
3596
|
+
store.expireCart();
|
|
3586
3597
|
}
|
|
3587
3598
|
};
|
|
3588
3599
|
};
|
|
@@ -4089,6 +4100,12 @@ var useCheckout = (config) => {
|
|
|
4089
4100
|
return () => clearInterval(t);
|
|
4090
4101
|
}, [snapshot.expiresAt]);
|
|
4091
4102
|
const secondsLeft = snapshot.expiresAt != null ? Math.max(0, Math.round((snapshot.expiresAt - now) / 1e3)) : void 0;
|
|
4103
|
+
(0, import_react3.useEffect)(() => {
|
|
4104
|
+
if (secondsLeft !== 0) return;
|
|
4105
|
+
if (snapshot.status === "placing" || snapshot.status === "succeeded") return;
|
|
4106
|
+
if (snapshot.status === "expired") return;
|
|
4107
|
+
engine.expireCart();
|
|
4108
|
+
}, [engine, secondsLeft, snapshot.status]);
|
|
4092
4109
|
const missingRequiredAddonNames = missingRequiredAddOns(
|
|
4093
4110
|
snapshot.requiredAddOns,
|
|
4094
4111
|
snapshot.addOns
|
|
@@ -6344,6 +6361,8 @@ var AuthModal = ({
|
|
|
6344
6361
|
const previouslyFocused = (0, import_react23.useRef)(null);
|
|
6345
6362
|
const submittingRef = (0, import_react23.useRef)(auth.isSubmitting);
|
|
6346
6363
|
submittingRef.current = auth.isSubmitting;
|
|
6364
|
+
const onCloseRef = (0, import_react23.useRef)(onClose);
|
|
6365
|
+
onCloseRef.current = onClose;
|
|
6347
6366
|
(0, import_react23.useEffect)(() => {
|
|
6348
6367
|
var _a, _b, _c;
|
|
6349
6368
|
if (!open) return;
|
|
@@ -6364,7 +6383,7 @@ var AuthModal = ({
|
|
|
6364
6383
|
initialFocus == null ? void 0 : initialFocus.focus();
|
|
6365
6384
|
const onKeyDown = (event) => {
|
|
6366
6385
|
var _a2;
|
|
6367
|
-
if (event.key === "Escape" && !submittingRef.current)
|
|
6386
|
+
if (event.key === "Escape" && !submittingRef.current) onCloseRef.current();
|
|
6368
6387
|
if (event.key !== "Tab") return;
|
|
6369
6388
|
const elements = focusable();
|
|
6370
6389
|
if (elements.length === 0) {
|
|
@@ -6389,7 +6408,7 @@ var AuthModal = ({
|
|
|
6389
6408
|
document.body.style.overflow = previousOverflow;
|
|
6390
6409
|
(_a2 = previouslyFocused.current) == null ? void 0 : _a2.focus();
|
|
6391
6410
|
};
|
|
6392
|
-
}, [
|
|
6411
|
+
}, [open]);
|
|
6393
6412
|
if (!open) return null;
|
|
6394
6413
|
const closeFromBackdrop = (event) => {
|
|
6395
6414
|
if (event.target === event.currentTarget && !auth.isSubmitting) onClose();
|
|
@@ -7544,6 +7563,19 @@ var BuyerField = ({
|
|
|
7544
7563
|
));
|
|
7545
7564
|
};
|
|
7546
7565
|
|
|
7566
|
+
// src/sections/billing/fieldRules.ts
|
|
7567
|
+
var isBlankPhone = (phone) => !phone || /^\+?\d{0,4}$/.test(phone.trim());
|
|
7568
|
+
var DOB_MIN = "1900-01-01";
|
|
7569
|
+
var todayISO = () => {
|
|
7570
|
+
const now = /* @__PURE__ */ new Date();
|
|
7571
|
+
return [
|
|
7572
|
+
now.getFullYear(),
|
|
7573
|
+
String(now.getMonth() + 1).padStart(2, "0"),
|
|
7574
|
+
String(now.getDate()).padStart(2, "0")
|
|
7575
|
+
].join("-");
|
|
7576
|
+
};
|
|
7577
|
+
var toDateInputValue = (year, month, day) => year && month && day ? `${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}` : void 0;
|
|
7578
|
+
|
|
7547
7579
|
// src/sections/billing/TicketHoldersCard.tsx
|
|
7548
7580
|
var import_react30 = __toESM(require("react"));
|
|
7549
7581
|
var import_react_international_phone2 = require("react-international-phone");
|
|
@@ -7626,6 +7658,8 @@ var TicketHoldersCard = ({
|
|
|
7626
7658
|
className: "tf-checkout-phone",
|
|
7627
7659
|
inputClassName: `tf-checkout-input tf-checkout-phone__input${fieldError(phoneKey) ? " tf-checkout-input--invalid" : ""}`,
|
|
7628
7660
|
defaultCountry: phoneCountry,
|
|
7661
|
+
disableDialCodeAndPrefix: true,
|
|
7662
|
+
showDisabledDialCodeAndPrefix: true,
|
|
7629
7663
|
disableDialCodePrefill: true,
|
|
7630
7664
|
value: holder.phone,
|
|
7631
7665
|
required: true,
|
|
@@ -7748,7 +7782,7 @@ var BillingInfo = ({
|
|
|
7748
7782
|
lastName: prev.lastName || profileBilling.lastName || "",
|
|
7749
7783
|
email: prev.email || profileBilling.email || "",
|
|
7750
7784
|
confirmEmail: prev.confirmEmail || (checkout.isLoggedIn ? profileBilling.email : "") || "",
|
|
7751
|
-
phone: prev.phone || profileBilling.phone,
|
|
7785
|
+
phone: (isBlankPhone(prev.phone) ? void 0 : prev.phone) || profileBilling.phone,
|
|
7752
7786
|
streetAddress: prev.streetAddress || profileBilling.streetAddress,
|
|
7753
7787
|
city: prev.city || profileBilling.city,
|
|
7754
7788
|
zip: prev.zip || profileBilling.zip,
|
|
@@ -7758,6 +7792,12 @@ var BillingInfo = ({
|
|
|
7758
7792
|
const keys = Object.keys(next);
|
|
7759
7793
|
return keys.every((k) => next[k] === prev[k]) ? prev : next;
|
|
7760
7794
|
});
|
|
7795
|
+
setDob((prev) => {
|
|
7796
|
+
var _a2;
|
|
7797
|
+
if (prev) return prev;
|
|
7798
|
+
const { dobYear: dobYear2, dobMonth: dobMonth2, dobDay: dobDay2 } = profileBilling;
|
|
7799
|
+
return (_a2 = toDateInputValue(dobYear2, dobMonth2, dobDay2)) != null ? _a2 : prev;
|
|
7800
|
+
});
|
|
7761
7801
|
}, [profile.data, checkout.isLoggedIn]);
|
|
7762
7802
|
(0, import_react31.useEffect)(() => {
|
|
7763
7803
|
setHolders(
|
|
@@ -7839,6 +7879,7 @@ var BillingInfo = ({
|
|
|
7839
7879
|
countryDefaultApplied.current = true;
|
|
7840
7880
|
setBilling((current2) => {
|
|
7841
7881
|
var _a3;
|
|
7882
|
+
if (current2.countryId) return current2;
|
|
7842
7883
|
return {
|
|
7843
7884
|
...current2,
|
|
7844
7885
|
countryId: String(preferred.id),
|
|
@@ -7879,24 +7920,30 @@ var BillingInfo = ({
|
|
|
7879
7920
|
}, [billing.stateId, billing.stateCode, states]);
|
|
7880
7921
|
const setB = (k) => (e) => setBilling((b) => ({ ...b, [k]: e.target.value }));
|
|
7881
7922
|
const patchHolder = (i, patch2) => setHolders((hs) => hs.map((h, j) => j === i ? { ...h, ...patch2 } : h));
|
|
7923
|
+
const dobMax = (0, import_react31.useMemo)(todayISO, []);
|
|
7882
7924
|
const [dobYear, dobMonth, dobDay] = dob ? dob.split("-").map(Number) : [];
|
|
7925
|
+
const buyerPhone = isBlankPhone(billing.phone) ? void 0 : billing.phone;
|
|
7883
7926
|
const committedBilling = {
|
|
7884
7927
|
...checkout.billing,
|
|
7885
7928
|
...billing,
|
|
7929
|
+
phone: buyerPhone,
|
|
7886
7930
|
stateRequired: gates.showAddress && Boolean(billing.countryId) && states.length > 0,
|
|
7887
7931
|
dataCapture,
|
|
7888
7932
|
dobDay,
|
|
7889
7933
|
dobMonth,
|
|
7890
7934
|
dobYear
|
|
7891
7935
|
};
|
|
7892
|
-
const committedHolders = holders.map((holder) =>
|
|
7893
|
-
|
|
7894
|
-
|
|
7895
|
-
|
|
7896
|
-
|
|
7897
|
-
|
|
7898
|
-
|
|
7899
|
-
|
|
7936
|
+
const committedHolders = holders.map((holder) => {
|
|
7937
|
+
const holderPhone = isBlankPhone(holder.phone) ? "" : holder.phone;
|
|
7938
|
+
return {
|
|
7939
|
+
firstName: holderNamesRequired ? holder.firstName : holder.firstName || billing.firstName,
|
|
7940
|
+
lastName: holderNamesRequired ? holder.lastName : holder.lastName || billing.lastName,
|
|
7941
|
+
email: showHolders && collectHolderContact ? holder.email : holder.email || billing.email,
|
|
7942
|
+
phone: showHolders && collectHolderContact ? holderPhone : holderPhone || buyerPhone || "",
|
|
7943
|
+
ticketTypeId: holder.ticketTypeId,
|
|
7944
|
+
ticketDataCapture: holder.ticketDataCapture
|
|
7945
|
+
};
|
|
7946
|
+
});
|
|
7900
7947
|
const missingDetails = missingCheckoutDetails(
|
|
7901
7948
|
{
|
|
7902
7949
|
billing: committedBilling,
|
|
@@ -8065,6 +8112,8 @@ var BillingInfo = ({
|
|
|
8065
8112
|
className: "tf-checkout-phone",
|
|
8066
8113
|
inputClassName: `tf-checkout-input tf-checkout-phone__input${fieldError("Valid phone number") ? " tf-checkout-input--invalid" : ""}`,
|
|
8067
8114
|
defaultCountry: phoneCountry,
|
|
8115
|
+
disableDialCodeAndPrefix: true,
|
|
8116
|
+
showDisabledDialCodeAndPrefix: true,
|
|
8068
8117
|
disableDialCodePrefill: true,
|
|
8069
8118
|
value: (_D = billing.phone) != null ? _D : "",
|
|
8070
8119
|
required: gates.phoneRequired,
|
|
@@ -8090,6 +8139,8 @@ var BillingInfo = ({
|
|
|
8090
8139
|
type: "date",
|
|
8091
8140
|
value: dob,
|
|
8092
8141
|
required: true,
|
|
8142
|
+
min: DOB_MIN,
|
|
8143
|
+
max: dobMax,
|
|
8093
8144
|
invalid: Boolean(dobError),
|
|
8094
8145
|
"aria-invalid": Boolean(dobError),
|
|
8095
8146
|
onChange: (e) => setDob(e.target.value)
|
|
@@ -8256,7 +8307,7 @@ var Payment = ({
|
|
|
8256
8307
|
showTestCardHint = false,
|
|
8257
8308
|
className
|
|
8258
8309
|
}) => {
|
|
8259
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
8310
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
8260
8311
|
const checkout = useCheckoutContext();
|
|
8261
8312
|
const validation = useCheckoutValidation();
|
|
8262
8313
|
const [error, setError] = (0, import_react33.useState)("");
|
|
@@ -8278,8 +8329,10 @@ var Payment = ({
|
|
|
8278
8329
|
const bd = checkout.breakdown;
|
|
8279
8330
|
const isFree = bd != null && Number(bd.total) === 0;
|
|
8280
8331
|
const isXendit = checkout.gateway === "xendit";
|
|
8332
|
+
const serverMethodTypes = (_a = checkout.stripeElementsConfig) == null ? void 0 : _a.paymentMethodTypes;
|
|
8333
|
+
const offersOxxo = Array.isArray(serverMethodTypes) && serverMethodTypes.includes("oxxo");
|
|
8281
8334
|
const options = (0, import_react33.useMemo)(() => {
|
|
8282
|
-
var _a2, _b2, _c2
|
|
8335
|
+
var _a2, _b2, _c2;
|
|
8283
8336
|
if (isFree || !methods) return [];
|
|
8284
8337
|
const out = [];
|
|
8285
8338
|
if (isXendit) {
|
|
@@ -8311,7 +8364,7 @@ var Payment = ({
|
|
|
8311
8364
|
value: "paymentPlan",
|
|
8312
8365
|
label: "Payment plan"
|
|
8313
8366
|
});
|
|
8314
|
-
if (
|
|
8367
|
+
if (offersOxxo)
|
|
8315
8368
|
out.push({ id: { kind: "oxxo" }, value: "oxxo", label: "OXXO (pay in cash)" });
|
|
8316
8369
|
}
|
|
8317
8370
|
if (methods.paypal)
|
|
@@ -8324,7 +8377,7 @@ var Payment = ({
|
|
|
8324
8377
|
checkout.gateway,
|
|
8325
8378
|
checkout.redirectPaymentMethods,
|
|
8326
8379
|
checkout.paymentPlan,
|
|
8327
|
-
|
|
8380
|
+
offersOxxo
|
|
8328
8381
|
]);
|
|
8329
8382
|
(0, import_react33.useEffect)(() => {
|
|
8330
8383
|
if (options.length && !options.some((o) => o.value === selected))
|
|
@@ -8334,14 +8387,14 @@ var Payment = ({
|
|
|
8334
8387
|
const selectedOption = options.find((o) => o.value === selected);
|
|
8335
8388
|
const isCardSelected = selected === cardValue;
|
|
8336
8389
|
const isPlanSelected = (selectedOption == null ? void 0 : selectedOption.id.kind) === "paymentPlan";
|
|
8337
|
-
const savedLast4 = (
|
|
8390
|
+
const savedLast4 = (_b = checkout.paymentPlan) == null ? void 0 : _b.savedCardLast4;
|
|
8338
8391
|
const reuseSavedCard = Boolean(savedLast4) && useSavedCard;
|
|
8339
8392
|
const usesCardDetails = !isFree && (isCardSelected || isPlanSelected && !reuseSavedCard);
|
|
8340
8393
|
const cardWidgetReportsItsOwnError = usesCardDetails && !isXendit;
|
|
8341
8394
|
const hasWallets = Boolean(
|
|
8342
|
-
((
|
|
8395
|
+
((_c = checkout.walletAvailability) == null ? void 0 : _c.applePay) || ((_d = checkout.walletAvailability) == null ? void 0 : _d.googlePay)
|
|
8343
8396
|
);
|
|
8344
|
-
const useWalletElement = !isXendit && !isPlanSelected && hasWallets && ((
|
|
8397
|
+
const useWalletElement = !isXendit && !isPlanSelected && hasWallets && ((_e = checkout.breakdown) == null ? void 0 : _e.currencyCode) !== "MXN" && Boolean((_f = checkout.stripeElementsConfig) == null ? void 0 : _f.mode);
|
|
8345
8398
|
const onlyOption = options.length === 1 ? options[0] : void 0;
|
|
8346
8399
|
const singleCard = (onlyOption == null ? void 0 : onlyOption.id.kind) === "card" || (onlyOption == null ? void 0 : onlyOption.id.kind) === "xenditCard";
|
|
8347
8400
|
const b = checkout.billing;
|
|
@@ -8358,7 +8411,7 @@ var Payment = ({
|
|
|
8358
8411
|
{ requireEmailConfirmation, collectTicketHolders, requireHolderContact }
|
|
8359
8412
|
);
|
|
8360
8413
|
const billingReady = missingDetails.length === 0;
|
|
8361
|
-
const conditions = [...(
|
|
8414
|
+
const conditions = [...(_g = checkout.conditions) != null ? _g : [], ...additionalConditions];
|
|
8362
8415
|
const requiredConditions = conditions.filter((c) => c.isRequired);
|
|
8363
8416
|
const conditionsOk = requiredConditions.every(
|
|
8364
8417
|
(c) => {
|
|
@@ -8367,10 +8420,10 @@ var Payment = ({
|
|
|
8367
8420
|
}
|
|
8368
8421
|
);
|
|
8369
8422
|
const extra = selectedOption == null ? void 0 : selectedOption.extra;
|
|
8370
|
-
const extrasOk = !extra || (extra === "cashtag" ? Boolean((
|
|
8423
|
+
const extrasOk = !extra || (extra === "cashtag" ? Boolean((_i = (_h = extras[selected]) == null ? void 0 : _h.cashtag) == null ? void 0 : _i.trim()) : Boolean((_k = (_j = extras[selected]) == null ? void 0 : _j.phoneNumber) == null ? void 0 : _k.trim()));
|
|
8371
8424
|
const privacyOk = !requirePrivacyPolicy || checkout.consent.ttfOptIn;
|
|
8372
|
-
const payLabel = isFree ? "Complete Registration" : isPlanSelected ? planConfirmLabel((
|
|
8373
|
-
const planTerms = paymentPlanTerms((
|
|
8425
|
+
const payLabel = isFree ? "Complete Registration" : isPlanSelected ? planConfirmLabel((_l = checkout.paymentPlan) == null ? void 0 : _l.configuration) : "Submit Payment";
|
|
8426
|
+
const planTerms = paymentPlanTerms((_m = checkout.paymentPlan) == null ? void 0 : _m.configuration);
|
|
8374
8427
|
const finalizing = checkout.status === "placing" || checkout.status === "succeeded";
|
|
8375
8428
|
const pay = () => {
|
|
8376
8429
|
setError("");
|