@lockerverse/react 0.2.224-dev.1 → 0.2.225-dev.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/MIGRATIONS.md CHANGED
@@ -4,6 +4,33 @@ This file ships in both @lockerverse/sdk and @lockerverse/react. Use the copy in
4
4
  the target installed release. This is an agent-run procedure, not an install
5
5
  script. Installing a package does not edit host code or guarantee these steps ran.
6
6
 
7
+ ## Unreleased — business booking setup and payment verification
8
+
9
+ - **Affected:** optional SDK bookings, React booking state and booking payment.
10
+ - **Required for live bookings:** pass `customer: { name, email, phone }` to
11
+ `initialize`; use the server's service and account configuration. Existing
12
+ sandbox calls without customer details remain supported.
13
+ - **Recommended:** use `client.createSession(previousAccessToken?)` to start or
14
+ renew a public booking session. Keep the returned capability private and retain
15
+ it for saved-booking recovery. The method does not store or rotate host state.
16
+ - **Required for bank verification:** pass `attempt` and `onRecover` to
17
+ `LockerverseBookingPayment`. Render it while `paymentVisible` is true and use
18
+ `disabled={!canPay && !needsPaymentAction}`. This keeps Stripe mounted during
19
+ submission and lets a recovered payment continue its bank verification.
20
+ - **Required for payment review:** show the saved attempt's `serviceName`,
21
+ `amountCents` and `currency`, rather than the current service configuration.
22
+ The payment component prefers these saved values; legacy amount/currency props
23
+ remain accepted. Keep new payments disabled if the saved amount is missing.
24
+ - **Automatic:** the optional payment component uses the attempt's Stripe account
25
+ and recovers the same payment after a bank verification. Other entry points and
26
+ consumers have no change. Neither booking data entry imports Stripe.
27
+ - **Automatic recovery:** configuration failure no longer prevents recovery of a
28
+ saved attempt. Bank verification can continue for an existing payment even
29
+ while the owner's current setup prevents new payments.
30
+ - **Check:** a new business uses its own booking and payment account; customer
31
+ contact details reach the saved booking; a test card that needs authentication
32
+ completes or recovers without a second payment. Keep `clientSecret` private.
33
+
7
34
  ## 0.2.224-dev.1 — clearer booking payment messages
8
35
 
9
36
  - **Affected:** the optional React booking payment component.
@@ -3,9 +3,15 @@ import { LockerverseBookingAttempt } from "@lockerverse/sdk/bookings";
3
3
  //#region src/booking-payment.d.ts
4
4
  type LockerverseBookingPaymentProps = {
5
5
  publishableKey: string;
6
- amountCents: number;
7
- currency: "USD";
6
+ /** Legacy fallback. New hosts should use the saved attempt's amount. */
7
+ amountCents?: number;
8
+ currency?: "USD";
8
9
  onConfirm: (confirmationToken: string) => Promise<LockerverseBookingAttempt> | Promise<void>;
10
+ /** Pass the recovered attempt to continue a required bank verification. */
11
+ attempt?: LockerverseBookingAttempt;
12
+ /** Recover the same saved attempt after bank verification. */
13
+ onRecover?: () => Promise<LockerverseBookingAttempt | null>;
14
+ stripeAccountId?: string | null;
9
15
  disabled?: boolean;
10
16
  className?: string;
11
17
  buttonClassName?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"booking-payment.d.ts","names":[],"sources":["../src/booking-payment.tsx"],"mappings":";;;KAaY;EACV;EACA;EACA;EACA,YACE,8BACG,QAAQ,6BAA6B;EAC1C;EACA;EACA;EACA,cAAc;;;iBA0EA,0BACd,OAAO,iDAA8B,IAAA"}
1
+ {"version":3,"file":"booking-payment.d.ts","names":[],"sources":["../src/booking-payment.tsx"],"mappings":";;;KAcY;EACV;;EAEA;EACA;EACA,YACE,8BACG,QAAQ,6BAA6B;;EAE1C,UAAU;;EAEV,kBAAkB,QAAQ;EAC1B;EACA;EACA;EACA;EACA,cAAc;;;iBA2JA,0BACd,OAAO,iDAA8B,IAAA"}
@@ -1,2 +1,2 @@
1
- import{useEffect as e,useRef as t,useState as n}from"react";import{jsx as r,jsxs as i}from"react/jsx-runtime";import{Elements as a,PaymentElement as o,useElements as s,useStripe as c}from"@stripe/react-stripe-js";import{loadStripe as l}from"@stripe/stripe-js/pure/index.js";const u=/^pk_(?:test|live)_/;function d(e){let a=c(),l=s(),u=t(!1),d=t(!1),[f,p]=n(!1),[m,h]=n(!1),[g,_]=n(``);async function v(){if(!(!(a&&l&&m)||e.disabled||u.current||d.current)){u.current=!0,p(!0),_(``);try{if((await l.submit()).error){_(`Check your card details.`);return}let t=await a.createConfirmationToken({elements:l});if(t.error||!t.confirmationToken){_(`Card details could not be confirmed. No payment was submitted.`);return}d.current=!0,await e.onConfirm(t.confirmationToken.id)}catch{_(`We could not confirm the result. Check your booking status before trying to pay again.`)}finally{u.current=!1,p(!1)}}}return i(`div`,{className:e.className,children:[r(o,{onLoadError:()=>{h(!1),_(`Card entry could not load. Reload the page to check your booking before trying to pay again.`)},onReady:()=>h(!0),options:{wallets:{applePay:`never`,googlePay:`never`}}}),!(m||g)&&r(`p`,{role:`status`,children:`Loading secure card entry…`}),g&&r(`p`,{role:`alert`,children:g}),r(`button`,{className:e.buttonClassName,disabled:!m||f||d.current||e.disabled,onClick:v,type:`button`,children:f?`Checking payment…`:e.buttonLabel??`Pay and book`})]})}function f(t){let[i,o]=n(null),[s,c]=n(!1),f=`${t.publishableKey}:${t.amountCents}:${t.currency}`,[p]=n(f);if(f!==p)throw Error(`Remount booking payment when its confirmed payment configuration changes.`);if(!(u.test(t.publishableKey)&&Number.isSafeInteger(t.amountCents))||t.amountCents<=0||t.currency!==`USD`)throw TypeError(`A valid server-provided booking payment configuration is required.`);return e(()=>{let e=!0;return l(t.publishableKey).then(t=>{e&&(o(t),c(!t))}).catch(()=>{e&&c(!0)}),()=>{e=!1}},[t.publishableKey]),s?r(`p`,{role:`alert`,children:`Secure card entry could not load. Reload the page to check your booking before trying to pay again.`}):i?r(a,{options:{allowedPaymentMethodTypes:[`card`],amount:t.amountCents,currency:`usd`,mode:`payment`,setupFutureUsage:`off_session`},stripe:i,children:r(d,{...t})}):r(`p`,{role:`status`,children:`Loading secure card entry…`})}export{f as LockerverseBookingPayment};
1
+ import{useEffect as e,useRef as t,useState as n}from"react";import{jsx as r,jsxs as i}from"react/jsx-runtime";import{Elements as a,PaymentElement as o,useElements as s,useStripe as c}from"@stripe/react-stripe-js";import{loadStripe as l}from"@stripe/stripe-js/pure/index.js";const u=/^pk_(?:test|live)_/,d=/^acct_[A-Za-z0-9]+$/;function f(e){return e.attempt?.stripeAccountId===void 0?e.stripeAccountId??null:e.attempt.stripeAccountId}async function p(e,t,n){if(!(n.clientSecret&&t.onRecover)||(n.stripeAccountId??null)!==f(t))throw Error(`Recover this booking before continuing payment.`);try{if((await e.handleNextAction({clientSecret:n.clientSecret})).error)throw Error(`Payment verification could not be completed.`)}finally{await t.onRecover()}}function m(e){let a=c(),l=s(),u=t(!1),d=t(!1),[f,p]=n(!1),[m,h]=n(!1),[g,_]=n(``);async function v(){if(!(!(a&&l&&m)||e.attempt!==void 0&&e.attempt.status!==`review`||e.disabled||u.current||d.current)){u.current=!0,p(!0),_(``);try{if((await l.submit()).error){_(`Check your card details.`);return}let t=await a.createConfirmationToken({elements:l});if(t.error||!t.confirmationToken){_(`Card details could not be confirmed. No payment was submitted.`);return}d.current=!0,await e.onConfirm(t.confirmationToken.id)}catch{_(`We could not confirm the result. Check your booking status before trying to pay again.`)}finally{u.current=!1,p(!1)}}}return i(`div`,{className:e.className,children:[r(o,{onLoadError:()=>{h(!1),_(`Card entry could not load. Reload the page to check your booking before trying to pay again.`)},onReady:()=>h(!0),options:{wallets:{applePay:`never`,googlePay:`never`}}}),!(m||g)&&r(`p`,{role:`status`,children:`Loading secure card entry…`}),g&&r(`p`,{role:`alert`,children:g}),r(`button`,{className:e.buttonClassName,disabled:!m||f||d.current||e.disabled||e.attempt!==void 0&&e.attempt.status!==`review`,onClick:v,type:`button`,children:f?`Checking payment…`:e.buttonLabel??`Pay and book`})]})}function h({stripe:e,...a}){let o=t(!1),[s,c]=n(!1),[l,u]=n(``);async function d(){if(!(o.current||a.disabled||!a.attempt)){o.current=!0,c(!0),u(``);try{await p(e,a,a.attempt)}catch{u(`We could not complete payment verification. Check your booking status before trying again.`)}finally{o.current=!1,c(!1)}}}return i(`div`,{className:a.className,children:[r(`p`,{children:`Your bank needs you to approve this payment.`}),l&&r(`p`,{role:`alert`,children:l}),r(`button`,{className:a.buttonClassName,disabled:s||a.disabled||!a.onRecover,onClick:d,type:`button`,children:s?`Checking payment…`:`Continue payment`})]})}function g(t){let[i,o]=n(null),[s,c]=n(!1),p=f(t),g=t.attempt?.amountCents??t.amountCents??NaN,_=t.attempt?.currency??t.currency,v=`${t.publishableKey}:${p??``}:${g}:${_}`,[y]=n(v);if(v!==y)throw Error(`Remount booking payment when its confirmed payment configuration changes.`);if(!(u.test(t.publishableKey)&&Number.isSafeInteger(g))||g<=0||_!==`USD`||p!==null&&!d.test(p))throw TypeError(`A valid server-provided booking payment configuration is required.`);return e(()=>{let e=!0;return l(t.publishableKey,p?{stripeAccount:p}:void 0).then(t=>{e&&(o(t),c(!t))}).catch(()=>{e&&c(!0)}),()=>{e=!1}},[t.publishableKey,p]),s?r(`p`,{role:`alert`,children:`Secure card entry could not load. Reload the page to check your booking before trying to pay again.`}):i?t.attempt?.status===`payment_action_required`?r(h,{...t,stripe:i}):r(a,{options:{allowedPaymentMethodTypes:[`card`],amount:g,currency:`usd`,mode:`payment`,setupFutureUsage:`off_session`},stripe:i,children:r(m,{...t})}):r(`p`,{role:`status`,children:`Loading secure card entry…`})}export{g as LockerverseBookingPayment};
2
2
  //# sourceMappingURL=booking-payment.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"booking-payment.js","names":[],"sources":["../src/booking-payment.tsx"],"sourcesContent":["import type { LockerverseBookingAttempt } from \"@lockerverse/sdk/bookings\";\nimport {\n Elements,\n PaymentElement,\n useElements,\n useStripe,\n} from \"@stripe/react-stripe-js\";\nimport type { Stripe } from \"@stripe/stripe-js\";\nimport { loadStripe } from \"@stripe/stripe-js/pure\";\nimport { type ReactNode, useEffect, useRef, useState } from \"react\";\n\nconst publishableKeyPattern = /^pk_(?:test|live)_/;\n\nexport type LockerverseBookingPaymentProps = {\n publishableKey: string;\n amountCents: number;\n currency: \"USD\";\n onConfirm: (\n confirmationToken: string\n ) => Promise<LockerverseBookingAttempt> | Promise<void>;\n disabled?: boolean;\n className?: string;\n buttonClassName?: string;\n buttonLabel?: ReactNode;\n};\n\nfunction BookingCardForm(props: LockerverseBookingPaymentProps) {\n const stripe = useStripe();\n const elements = useElements();\n const submitting = useRef(false);\n const sentToBackend = useRef(false);\n const [busy, setBusy] = useState(false);\n const [ready, setReady] = useState(false);\n const [error, setError] = useState(\"\");\n async function submit() {\n if (\n !(stripe && elements && ready) ||\n props.disabled ||\n submitting.current ||\n sentToBackend.current\n ) {\n return;\n }\n submitting.current = true;\n setBusy(true);\n setError(\"\");\n try {\n const submitted = await elements.submit();\n if (submitted.error) {\n setError(\"Check your card details.\");\n return;\n }\n const result = await stripe.createConfirmationToken({ elements });\n if (result.error || !result.confirmationToken) {\n setError(\n \"Card details could not be confirmed. No payment was submitted.\"\n );\n return;\n }\n sentToBackend.current = true;\n await props.onConfirm(result.confirmationToken.id);\n } catch {\n setError(\n \"We could not confirm the result. Check your booking status before trying to pay again.\"\n );\n } finally {\n submitting.current = false;\n setBusy(false);\n }\n }\n return (\n <div className={props.className}>\n <PaymentElement\n onLoadError={() => {\n setReady(false);\n setError(\n \"Card entry could not load. Reload the page to check your booking before trying to pay again.\"\n );\n }}\n onReady={() => setReady(true)}\n options={{ wallets: { applePay: \"never\", googlePay: \"never\" } }}\n />\n {!(ready || error) && <p role=\"status\">Loading secure card entry…</p>}\n {error && <p role=\"alert\">{error}</p>}\n <button\n className={props.buttonClassName}\n disabled={!ready || busy || sentToBackend.current || props.disabled}\n onClick={submit}\n type=\"button\"\n >\n {busy ? \"Checking payment…\" : (props.buttonLabel ?? \"Pay and book\")}\n </button>\n </div>\n );\n}\n\n/** Import this entry only when the recovered attempt is ready for card entry. */\nexport function LockerverseBookingPayment(\n props: LockerverseBookingPaymentProps\n) {\n const [stripe, setStripe] = useState<Stripe | null>(null);\n const [failed, setFailed] = useState(false);\n const identity = `${props.publishableKey}:${props.amountCents}:${props.currency}`;\n const [initialIdentity] = useState(identity);\n if (identity !== initialIdentity) {\n throw new Error(\n \"Remount booking payment when its confirmed payment configuration changes.\"\n );\n }\n if (\n !(\n publishableKeyPattern.test(props.publishableKey) &&\n Number.isSafeInteger(props.amountCents)\n ) ||\n props.amountCents <= 0 ||\n props.currency !== \"USD\"\n ) {\n throw new TypeError(\n \"A valid server-provided booking payment configuration is required.\"\n );\n }\n useEffect(() => {\n let active = true;\n loadStripe(props.publishableKey)\n .then((result) => {\n if (active) {\n setStripe(result);\n setFailed(!result);\n }\n })\n .catch(() => {\n if (active) {\n setFailed(true);\n }\n });\n return () => {\n active = false;\n };\n }, [props.publishableKey]);\n if (failed) {\n return (\n <p role=\"alert\">\n Secure card entry could not load. Reload the page to check your booking\n before trying to pay again.\n </p>\n );\n }\n if (!stripe) {\n return <p role=\"status\">Loading secure card entry…</p>;\n }\n return (\n <Elements\n options={{\n allowedPaymentMethodTypes: [\"card\"],\n amount: props.amountCents,\n currency: \"usd\",\n mode: \"payment\",\n setupFutureUsage: \"off_session\",\n }}\n stripe={stripe}\n >\n <BookingCardForm {...props} />\n </Elements>\n );\n}\n"],"mappings":"kRAWA,MAAM,EAAwB,qBAe9B,SAAS,EAAgB,EAAuC,CAC9D,IAAM,EAAS,EAAU,EACnB,EAAW,EAAY,EACvB,EAAa,EAAO,EAAK,EACzB,EAAgB,EAAO,EAAK,EAC5B,CAAC,EAAM,GAAW,EAAS,EAAK,EAChC,CAAC,EAAO,GAAY,EAAS,EAAK,EAClC,CAAC,EAAO,GAAY,EAAS,EAAE,EACrC,eAAe,GAAS,CAEpB,OAAE,GAAU,GAAY,IACxB,EAAM,UACN,EAAW,SACX,EAAc,SAMhB,CAFA,EAAW,QAAU,GACrB,EAAQ,EAAI,EACZ,EAAS,EAAE,EACX,GAAI,CAEF,IAAI,MADoB,EAAS,OAAO,EAAA,CAC1B,MAAO,CACnB,EAAS,0BAA0B,EACnC,MACF,CACA,IAAM,EAAS,MAAM,EAAO,wBAAwB,CAAE,UAAS,CAAC,EAChE,GAAI,EAAO,OAAS,CAAC,EAAO,kBAAmB,CAC7C,EACE,gEACF,EACA,MACF,CACA,EAAc,QAAU,GACxB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MACU,CACX,EAAS,EACX,CACF,EAAG,CAAC,EAAM,cAAc,CAAC,EACrB,EAEA,EAAC,IAAD,CAAG,KAAK,QAAQ,SAAA,qGAGb,CAAA,EAGF,EAIH,EAAC,EAAD,CACE,QAAS,CACP,0BAA2B,CAAC,MAAM,EAClC,OAAQ,EAAM,YACd,SAAU,MACV,KAAM,UACN,iBAAkB,aACpB,EACQ,SAER,SAAA,EAAC,EAAD,CAAiB,GAAI,CAAQ,CAAA,CACrB,CAAA,EAdH,EAAC,IAAD,CAAG,KAAK,SAAS,SAAA,4BAA6B,CAAA,CAgBzD"}
1
+ {"version":3,"file":"booking-payment.js","names":[],"sources":["../src/booking-payment.tsx"],"sourcesContent":["import type { LockerverseBookingAttempt } from \"@lockerverse/sdk/bookings\";\nimport {\n Elements,\n PaymentElement,\n useElements,\n useStripe,\n} from \"@stripe/react-stripe-js\";\nimport type { Stripe } from \"@stripe/stripe-js\";\nimport { loadStripe } from \"@stripe/stripe-js/pure\";\nimport { type ReactNode, useEffect, useRef, useState } from \"react\";\n\nconst publishableKeyPattern = /^pk_(?:test|live)_/;\nconst accountIdPattern = /^acct_[A-Za-z0-9]+$/;\n\nexport type LockerverseBookingPaymentProps = {\n publishableKey: string;\n /** Legacy fallback. New hosts should use the saved attempt's amount. */\n amountCents?: number;\n currency?: \"USD\";\n onConfirm: (\n confirmationToken: string\n ) => Promise<LockerverseBookingAttempt> | Promise<void>;\n /** Pass the recovered attempt to continue a required bank verification. */\n attempt?: LockerverseBookingAttempt;\n /** Recover the same saved attempt after bank verification. */\n onRecover?: () => Promise<LockerverseBookingAttempt | null>;\n stripeAccountId?: string | null;\n disabled?: boolean;\n className?: string;\n buttonClassName?: string;\n buttonLabel?: ReactNode;\n};\n\nfunction accountForPayment(props: LockerverseBookingPaymentProps) {\n return props.attempt?.stripeAccountId === undefined\n ? (props.stripeAccountId ?? null)\n : props.attempt.stripeAccountId;\n}\n\nasync function completePaymentAction(\n stripe: Stripe,\n props: LockerverseBookingPaymentProps,\n attempt: LockerverseBookingAttempt\n) {\n if (\n !(attempt.clientSecret && props.onRecover) ||\n (attempt.stripeAccountId ?? null) !== accountForPayment(props)\n ) {\n throw new Error(\"Recover this booking before continuing payment.\");\n }\n try {\n const result = await stripe.handleNextAction({\n clientSecret: attempt.clientSecret,\n });\n if (result.error) {\n throw new Error(\"Payment verification could not be completed.\");\n }\n } finally {\n // A closed bank dialog or lost response must recover the saved payment.\n await props.onRecover();\n }\n}\n\nfunction BookingCardForm(props: LockerverseBookingPaymentProps) {\n const stripe = useStripe();\n const elements = useElements();\n const submitting = useRef<boolean>(false);\n const sentToBackend = useRef(false);\n const [busy, setBusy] = useState(false);\n const [ready, setReady] = useState(false);\n const [error, setError] = useState(\"\");\n async function submit() {\n if (\n !(stripe && elements && ready) ||\n (props.attempt !== undefined && props.attempt.status !== \"review\") ||\n props.disabled ||\n submitting.current ||\n sentToBackend.current\n ) {\n return;\n }\n submitting.current = true;\n setBusy(true);\n setError(\"\");\n try {\n const submitted = await elements.submit();\n if (submitted.error) {\n setError(\"Check your card details.\");\n return;\n }\n const result = await stripe.createConfirmationToken({ elements });\n if (result.error || !result.confirmationToken) {\n setError(\n \"Card details could not be confirmed. No payment was submitted.\"\n );\n return;\n }\n sentToBackend.current = true;\n // The recovered action state shows Continue payment. One mounted action\n // component owns the bank dialog and its in-flight guard.\n await props.onConfirm(result.confirmationToken.id);\n } catch {\n setError(\n \"We could not confirm the result. Check your booking status before trying to pay again.\"\n );\n } finally {\n submitting.current = false;\n setBusy(false);\n }\n }\n return (\n <div className={props.className}>\n <PaymentElement\n onLoadError={() => {\n setReady(false);\n setError(\n \"Card entry could not load. Reload the page to check your booking before trying to pay again.\"\n );\n }}\n onReady={() => setReady(true)}\n options={{ wallets: { applePay: \"never\", googlePay: \"never\" } }}\n />\n {!(ready || error) && <p role=\"status\">Loading secure card entry…</p>}\n {error && <p role=\"alert\">{error}</p>}\n <button\n className={props.buttonClassName}\n disabled={\n !ready ||\n busy ||\n sentToBackend.current ||\n props.disabled ||\n (props.attempt !== undefined && props.attempt.status !== \"review\")\n }\n onClick={submit}\n type=\"button\"\n >\n {busy ? \"Checking payment…\" : (props.buttonLabel ?? \"Pay and book\")}\n </button>\n </div>\n );\n}\n\nfunction BookingPaymentAction({\n stripe,\n ...props\n}: LockerverseBookingPaymentProps & { stripe: Stripe }) {\n const submitting = useRef<boolean>(false);\n const [busy, setBusy] = useState(false);\n const [error, setError] = useState(\"\");\n async function continuePayment() {\n // biome-ignore lint/suspicious/noUnnecessaryConditions: A second click can enter while bank verification awaits.\n if (submitting.current || props.disabled || !props.attempt) {\n return;\n }\n submitting.current = true;\n setBusy(true);\n setError(\"\");\n try {\n await completePaymentAction(stripe, props, props.attempt);\n } catch {\n setError(\n \"We could not complete payment verification. Check your booking status before trying again.\"\n );\n } finally {\n submitting.current = false;\n setBusy(false);\n }\n }\n return (\n <div className={props.className}>\n <p>Your bank needs you to approve this payment.</p>\n {error && <p role=\"alert\">{error}</p>}\n <button\n className={props.buttonClassName}\n disabled={busy || props.disabled || !props.onRecover}\n onClick={continuePayment}\n type=\"button\"\n >\n {busy ? \"Checking payment…\" : \"Continue payment\"}\n </button>\n </div>\n );\n}\n\n/** Import this entry only when the recovered attempt is ready for card entry. */\nexport function LockerverseBookingPayment(\n props: LockerverseBookingPaymentProps\n) {\n const [stripe, setStripe] = useState<Stripe | null>(null);\n const [failed, setFailed] = useState(false);\n const stripeAccountId = accountForPayment(props);\n const amountCents =\n props.attempt?.amountCents ?? props.amountCents ?? Number.NaN;\n const currency = props.attempt?.currency ?? props.currency;\n const identity = `${props.publishableKey}:${stripeAccountId ?? \"\"}:${amountCents}:${currency}`;\n const [initialIdentity] = useState(identity);\n if (identity !== initialIdentity) {\n throw new Error(\n \"Remount booking payment when its confirmed payment configuration changes.\"\n );\n }\n if (\n !(\n publishableKeyPattern.test(props.publishableKey) &&\n Number.isSafeInteger(amountCents)\n ) ||\n amountCents <= 0 ||\n currency !== \"USD\" ||\n (stripeAccountId !== null && !accountIdPattern.test(stripeAccountId))\n ) {\n throw new TypeError(\n \"A valid server-provided booking payment configuration is required.\"\n );\n }\n useEffect(() => {\n let active = true;\n loadStripe(\n props.publishableKey,\n stripeAccountId ? { stripeAccount: stripeAccountId } : undefined\n )\n .then((result) => {\n if (active) {\n setStripe(result);\n setFailed(!result);\n }\n })\n .catch(() => {\n if (active) {\n setFailed(true);\n }\n });\n return () => {\n active = false;\n };\n }, [props.publishableKey, stripeAccountId]);\n if (failed) {\n return (\n <p role=\"alert\">\n Secure card entry could not load. Reload the page to check your booking\n before trying to pay again.\n </p>\n );\n }\n if (!stripe) {\n return <p role=\"status\">Loading secure card entry…</p>;\n }\n if (props.attempt?.status === \"payment_action_required\") {\n return <BookingPaymentAction {...props} stripe={stripe} />;\n }\n return (\n <Elements\n options={{\n allowedPaymentMethodTypes: [\"card\"],\n amount: amountCents,\n currency: \"usd\",\n mode: \"payment\",\n setupFutureUsage: \"off_session\",\n }}\n stripe={stripe}\n >\n <BookingCardForm {...props} />\n </Elements>\n );\n}\n"],"mappings":"kRAWA,MAAM,EAAwB,qBACxB,EAAmB,sBAqBzB,SAAS,EAAkB,EAAuC,CAChE,OAAO,EAAM,SAAS,kBAAoB,IAAA,GACrC,EAAM,iBAAmB,KAC1B,EAAM,QAAQ,eACpB,CAEA,eAAe,EACb,EACA,EACA,EACA,CACA,GACE,EAAE,EAAQ,cAAgB,EAAM,aAC/B,EAAQ,iBAAmB,QAAU,EAAkB,CAAK,EAE7D,MAAU,MAAM,iDAAiD,EAEnE,GAAI,CAIF,IAAI,MAHiB,EAAO,iBAAiB,CAC3C,aAAc,EAAQ,YACxB,CAAC,EAAA,CACU,MACT,MAAU,MAAM,8CAA8C,CAElE,QAAU,CAER,MAAM,EAAM,UAAU,CACxB,CACF,CAEA,SAAS,EAAgB,EAAuC,CAC9D,IAAM,EAAS,EAAU,EACnB,EAAW,EAAY,EACvB,EAAa,EAAgB,EAAK,EAClC,EAAgB,EAAO,EAA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EAEnE,MAAU,UACR,oEACF,EAqCF,OAnCA,MAAgB,CACd,IAAI,EAAS,GAgBb,OAfA,EACE,EAAM,eACN,EAAkB,CAAE,cAAe,CAAgB,EAAI,IAAA,EACzD,CAAC,CACE,KAAM,GAAW,CACZ,IACF,EAAU,CAAM,EAChB,EAAU,CAAC,CAAM,EAErB,CAAC,CAAC,CACD,UAAY,CACP,GACF,EAAU,EAAI,CAElB,CAAC,MACU,CACX,EAAS,EACX,CACF,EAAG,CAAC,EAAM,eAAgB,CAAe,CAAC,EACtC,EAEA,EAAC,IAAD,CAAG,KAAK,QAAQ,SAAA,qGAGb,CAAA,EAGF,EAGD,EAAM,SAAS,SAAW,0BACrB,EAAC,EAAD,CAAsB,GAAI,EAAe,QAAS,CAAA,EAGzD,EAAC,EAAD,CACE,QAAS,CACP,0BAA2B,CAAC,MAAM,EAClC,OAAQ,EACR,SAAU,MACV,KAAM,UACN,iBAAkB,aACpB,EACQ,SAER,SAAA,EAAC,EAAD,CAAiB,GAAI,CAAQ,CAAA,CACrB,CAAA,EAjBH,EAAC,IAAD,CAAG,KAAK,SAAS,SAAA,4BAA6B,CAAA,CAmBzD"}
@@ -1,4 +1,4 @@
1
- import { LockerverseBookingAttempt, LockerverseBookingAttempt as LockerverseBookingAttempt$1, LockerverseBookingAvailability, LockerverseBookingBusiness, LockerverseBookingConfiguration, LockerverseBookingConfiguration as LockerverseBookingConfiguration$1, LockerverseBookingSelection, LockerverseBookingStatus, LockerverseBookingsClient, LockerverseSdkError } from "@lockerverse/sdk/bookings";
1
+ import { LockerverseBookingAttempt, LockerverseBookingAttempt as LockerverseBookingAttempt$1, LockerverseBookingAvailability, LockerverseBookingBusiness, LockerverseBookingConfiguration, LockerverseBookingConfiguration as LockerverseBookingConfiguration$1, LockerverseBookingCustomer, LockerverseBookingSelection, LockerverseBookingSelection as LockerverseBookingSelection$1, LockerverseBookingSession, LockerverseBookingStatus, LockerverseBookingsClient, LockerverseSdkError } from "@lockerverse/sdk/bookings";
2
2
  //#region src/use-lockerverse-bookings.d.ts
3
3
  type UseLockerverseBookingsOptions = {
4
4
  enabled?: boolean;
@@ -15,14 +15,17 @@ type UseLockerverseBookingsResult = {
15
15
  recovered: boolean;
16
16
  error: LockerverseSdkError | null;
17
17
  canPay: boolean;
18
+ needsPaymentAction: boolean;
19
+ /** Keep payment UI mounted while a submission or bank verification is active. */
20
+ paymentVisible: boolean;
18
21
  refresh: () => Promise<void>;
19
22
  findTimes: (date: string) => Promise<LockerverseBookingAvailability>;
20
- initialize: (selection: LockerverseBookingSelection) => Promise<LockerverseBookingAttempt$1>;
23
+ initialize: (selection: LockerverseBookingSelection$1) => Promise<LockerverseBookingAttempt$1>;
21
24
  confirm: (confirmationToken: string) => Promise<LockerverseBookingAttempt$1>;
22
25
  recover: () => Promise<LockerverseBookingAttempt$1 | null>;
23
26
  };
24
27
  /** Recover the business-scoped attempt before permitting a payment submission. */
25
28
  declare function useLockerverseBookings(client: LockerverseBookingsClient, { enabled, sessionKey }?: UseLockerverseBookingsOptions): UseLockerverseBookingsResult;
26
29
  //#endregion
27
- export { type LockerverseBookingAttempt, type LockerverseBookingBusiness, type LockerverseBookingConfiguration, type LockerverseBookingStatus, type UseLockerverseBookingsOptions, type UseLockerverseBookingsResult, useLockerverseBookings };
30
+ export { type LockerverseBookingAttempt, type LockerverseBookingBusiness, type LockerverseBookingConfiguration, type LockerverseBookingCustomer, type LockerverseBookingSelection, type LockerverseBookingSession, type LockerverseBookingStatus, type UseLockerverseBookingsOptions, type UseLockerverseBookingsResult, useLockerverseBookings };
28
31
  //# sourceMappingURL=bookings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bookings.d.ts","names":[],"sources":["../src/use-lockerverse-bookings.ts"],"mappings":";;KAUY;EACV;;EAEA;;KAEU;EACV,eAAe;EACf;EACA;EACA,SAAS;EACT;EACA;EACA;EACA,OAAO;EACP;EACA,eAAe;EACf,YAAY,iBAAiB,QAAQ;EACrC,aACE,WAAW,gCACR,QAAQ;EACb,UAAU,8BAA8B,QAAQ;EAChD,eAAe,QAAQ;;;iBA4CT,uBACd,QAAQ,6BACN,SAAgB,eAAkB,gCACnC"}
1
+ {"version":3,"file":"bookings.d.ts","names":[],"sources":["../src/use-lockerverse-bookings.ts"],"mappings":";;KAUY;EACV;;EAEA;;KAEU;EACV,eAAe;EACf;EACA;EACA,SAAS;EACT;EACA;EACA;EACA,OAAO;EACP;EACA;;EAEA;EACA,eAAe;EACf,YAAY,iBAAiB,QAAQ;EACrC,aACE,WAAW,kCACR,QAAQ;EACb,UAAU,8BAA8B,QAAQ;EAChD,eAAe,QAAQ;;;iBA4CT,uBACd,QAAQ,6BACN,SAAgB,eAAkB,gCACnC"}
package/dist/bookings.js CHANGED
@@ -1,2 +1,2 @@
1
- import{useCallback as e,useEffect as t,useRef as n,useState as r}from"react";import{LockerverseSdkError as i}from"@lockerverse/sdk/bookings";const a=()=>({attempt:null,availabilityMessage:``,busy:!1,configuration:null,error:null,recovered:!1,recovering:!1,slots:[]});function o(e){return new i({code:`booking_request_failed`,message:e,operation:`recover_booking`,recoveryRecommended:!0,reportable:!1})}function s(e){return e instanceof i?e:o(`The booking request could not be completed. Check the saved state before paying.`)}function c(i,{enabled:c=!0,sessionKey:l=0}={}){if(n(i).current!==i)throw Error(`Keep the booking client stable. Remount for another business.`);let[u,d]=r(a),f=n(u),p=n(0),m=n(!1),h=n(l),g=n(!1),_=e(e=>{f.current={...f.current,...e},d(f.current)},[]),v=e(async(e,t,n,r=!1)=>{if(!(c&&m.current)||h.current!==l||g.current)throw o(`A booking request is already in progress or access is disabled.`);g.current=!0;let i=p.current,a=()=>i===p.current;_({busy:!0,error:null,recovered:!n&&f.current.recovered,recovering:r});try{let n=await e();if(!a())throw o(`The booking access session changed. Recover the current session.`);return _(t(n)),n}catch(e){let t=s(e);throw a()&&_({error:t,recovered:!n&&f.current.recovered}),t}finally{i===p.current&&(g.current=!1,_({busy:!1,recovering:!1}))}},[_,c,l]),y=e(async()=>{await v(async()=>{let e=await i.configuration();return{attempt:await i.recover(),configuration:e}},e=>({...e,recovered:!0}),!0,!0)},[i,v]),b=e(()=>v(()=>i.recover(),e=>({attempt:e,recovered:!0}),!0,!0),[i,v]),x=e(e=>v(()=>i.availability(e),e=>({availabilityMessage:e.message,slots:e.slots}),!1),[i,v]),S=e(e=>{let t=f.current;return!(t.configuration?.ready&&t.recovered)||t.attempt?Promise.reject(o(`Recover the saved booking before selecting a new session.`)):v(()=>i.initialize(e),e=>({attempt:e,recovered:!0}),!0)},[i,v]),C=e(e=>{let t=f.current;return t.configuration?.ready&&t.recovered&&t.attempt?.status===`review`?v(()=>i.confirm(e),e=>({attempt:e,recovered:e.status!==`review`}),!0):Promise.reject(o(`Recover this attempt before submitting a payment.`))},[i,v]);return t(()=>(p.current+=1,g.current=!1,m.current=c,h.current=l,f.current=a(),d(f.current),c&&y().catch(()=>void 0),()=>{m.current=!1,p.current+=1}),[c,l,y]),{...u,canPay:!!(c&&h.current===l&&u.configuration?.ready&&u.recovered&&u.attempt?.status===`review`&&!u.busy),confirm:C,findTimes:x,initialize:S,recover:b,refresh:y}}export{c as useLockerverseBookings};
1
+ import{useCallback as e,useEffect as t,useRef as n,useState as r}from"react";import{LockerverseSdkError as i}from"@lockerverse/sdk/bookings";const a=()=>({attempt:null,availabilityMessage:``,busy:!1,configuration:null,error:null,recovered:!1,recovering:!1,slots:[]});function o(e){return new i({code:`booking_request_failed`,message:e,operation:`recover_booking`,recoveryRecommended:!0,reportable:!1})}function s(e){return e instanceof i?e:o(`The booking request could not be completed. Check the saved state before paying.`)}function c(i,{enabled:c=!0,sessionKey:l=0}={}){if(n(i).current!==i)throw Error(`Keep the booking client stable. Remount for another business.`);let[u,d]=r(a),f=n(u),p=n(0),m=n(!1),h=n(l),g=n(!1),_=e(e=>{f.current={...f.current,...e},d(f.current)},[]),v=e(async(e,t,n,r=!1)=>{if(!(c&&m.current)||h.current!==l||g.current)throw o(`A booking request is already in progress or access is disabled.`);g.current=!0;let i=p.current,a=()=>i===p.current;_({busy:!0,error:null,recovered:!n&&f.current.recovered,recovering:r});try{let n=await e();if(!a())throw o(`The booking access session changed. Recover the current session.`);return _(t(n)),n}catch(e){let t=s(e);throw a()&&_({error:t,recovered:!n&&f.current.recovered}),t}finally{i===p.current&&(g.current=!1,_({busy:!1,recovering:!1}))}},[_,c,l]),y=e(async()=>{let e=await v(async()=>{let[e,t]=await Promise.allSettled([i.configuration(),i.recover()]);if(t.status===`rejected`)throw s(t.reason);return{attempt:t.value,configuration:e.status===`fulfilled`?e.value:null,configurationError:e.status===`rejected`?s(e.reason):null}},e=>({attempt:e.attempt,configuration:e.configuration,error:e.configurationError,recovered:!0}),!0,!0);if(e.configurationError)throw e.configurationError},[i,v]),b=e(()=>v(()=>i.recover(),e=>({attempt:e,recovered:!0}),!0,!0),[i,v]),x=e(e=>v(()=>i.availability(e),e=>({availabilityMessage:e.message,slots:e.slots}),!1),[i,v]),S=e(e=>{let t=f.current;return!(t.configuration?.ready&&t.recovered)||t.attempt?Promise.reject(o(`Recover the saved booking before selecting a new session.`)):v(()=>i.initialize(e),e=>({attempt:e,recovered:!0}),!0)},[i,v]),C=e(e=>{let t=f.current;return t.configuration?.ready&&t.recovered&&t.attempt?.status===`review`?v(()=>i.confirm(e),e=>({attempt:e,recovered:e.status!==`review`}),!0):Promise.reject(o(`Recover this attempt before submitting a payment.`))},[i,v]);return t(()=>(p.current+=1,g.current=!1,m.current=c,h.current=l,f.current=a(),d(f.current),c&&y().catch(()=>void 0),()=>{m.current=!1,p.current+=1}),[c,l,y]),{...u,canPay:!!(c&&h.current===l&&u.configuration?.ready&&u.recovered&&u.attempt?.status===`review`&&!u.busy),confirm:C,findTimes:x,initialize:S,needsPaymentAction:!!(c&&h.current===l&&u.recovered&&u.attempt?.status===`payment_action_required`&&u.attempt.clientSecret&&!u.busy),paymentVisible:!!(c&&h.current===l&&u.attempt&&(u.attempt.status===`payment_action_required`||u.configuration?.ready&&u.attempt.status===`review`)),recover:b,refresh:y}}export{c as useLockerverseBookings};
2
2
  //# sourceMappingURL=bookings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bookings.js","names":[],"sources":["../src/use-lockerverse-bookings.ts"],"sourcesContent":["import {\n type LockerverseBookingAttempt,\n type LockerverseBookingAvailability,\n type LockerverseBookingConfiguration,\n type LockerverseBookingSelection,\n type LockerverseBookingsClient,\n LockerverseSdkError,\n} from \"@lockerverse/sdk/bookings\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\nexport type UseLockerverseBookingsOptions = {\n enabled?: boolean;\n /** Non-secret generation value. Change it when the access session changes. */\n sessionKey?: string | number;\n};\nexport type UseLockerverseBookingsResult = {\n configuration: LockerverseBookingConfiguration | null;\n slots: string[];\n availabilityMessage: string;\n attempt: LockerverseBookingAttempt | null;\n busy: boolean;\n recovering: boolean;\n recovered: boolean;\n error: LockerverseSdkError | null;\n canPay: boolean;\n refresh: () => Promise<void>;\n findTimes: (date: string) => Promise<LockerverseBookingAvailability>;\n initialize: (\n selection: LockerverseBookingSelection\n ) => Promise<LockerverseBookingAttempt>;\n confirm: (confirmationToken: string) => Promise<LockerverseBookingAttempt>;\n recover: () => Promise<LockerverseBookingAttempt | null>;\n};\n\ntype BookingState = Pick<\n UseLockerverseBookingsResult,\n | \"configuration\"\n | \"slots\"\n | \"availabilityMessage\"\n | \"attempt\"\n | \"busy\"\n | \"recovering\"\n | \"recovered\"\n | \"error\"\n>;\nconst initialState = (): BookingState => ({\n attempt: null,\n availabilityMessage: \"\",\n busy: false,\n configuration: null,\n error: null,\n recovered: false,\n recovering: false,\n slots: [],\n});\nfunction stateError(message: string) {\n return new LockerverseSdkError({\n code: \"booking_request_failed\",\n message,\n operation: \"recover_booking\",\n recoveryRecommended: true,\n reportable: false,\n });\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Promise rejection values are untrusted and are normalized here.\nfunction safeBookingError(error: unknown): LockerverseSdkError {\n return error instanceof LockerverseSdkError\n ? error\n : stateError(\n \"The booking request could not be completed. Check the saved state before paying.\"\n );\n}\n\n/** Recover the business-scoped attempt before permitting a payment submission. */\nexport function useLockerverseBookings(\n client: LockerverseBookingsClient,\n { enabled = true, sessionKey = 0 }: UseLockerverseBookingsOptions = {}\n): UseLockerverseBookingsResult {\n const identity = useRef(client);\n if (identity.current !== client) {\n throw new Error(\n \"Keep the booking client stable. Remount for another business.\"\n );\n }\n const [state, setState] = useState<BookingState>(initialState);\n const current = useRef(state);\n const generation = useRef(0);\n const active = useRef(false);\n const activeSession = useRef(sessionKey);\n const inFlight = useRef(false);\n const commit = useCallback((change: Partial<BookingState>) => {\n current.current = { ...current.current, ...change };\n setState(current.current);\n }, []);\n\n const run = useCallback(\n async <T>(\n operation: () => Promise<T>,\n accept: (result: T) => Partial<BookingState>,\n changesPaymentState: boolean,\n recovering = false\n ): Promise<T> => {\n if (\n !(enabled && active.current) ||\n activeSession.current !== sessionKey ||\n inFlight.current\n ) {\n throw stateError(\n \"A booking request is already in progress or access is disabled.\"\n );\n }\n inFlight.current = true;\n const version = generation.current;\n const isCurrent = () => version === generation.current;\n commit({\n busy: true,\n error: null,\n recovered: changesPaymentState ? false : current.current.recovered,\n recovering,\n });\n try {\n const result = await operation();\n if (!isCurrent()) {\n throw stateError(\n \"The booking access session changed. Recover the current session.\"\n );\n }\n commit(accept(result));\n return result;\n } catch (error) {\n const safeError = safeBookingError(error);\n if (isCurrent()) {\n commit({\n error: safeError,\n recovered: changesPaymentState ? false : current.current.recovered,\n });\n }\n throw safeError;\n } finally {\n if (version === generation.current) {\n inFlight.current = false;\n commit({ busy: false, recovering: false });\n }\n }\n },\n [commit, enabled, sessionKey]\n );\n\n const refresh = useCallback(async () => {\n await run(\n async () => {\n const configuration = await client.configuration();\n const attempt = await client.recover();\n return { attempt, configuration };\n },\n (result) => ({ ...result, recovered: true }),\n true,\n true\n );\n }, [client, run]);\n const recover = useCallback(\n () =>\n run(\n () => client.recover(),\n (attempt) => ({ attempt, recovered: true }),\n true,\n true\n ),\n [client, run]\n );\n const findTimes = useCallback(\n (date: string) =>\n run(\n () => client.availability(date),\n (result) => ({\n availabilityMessage: result.message,\n slots: result.slots,\n }),\n false\n ),\n [client, run]\n );\n const initialize = useCallback(\n (selection: LockerverseBookingSelection) => {\n const saved = current.current;\n if (!(saved.configuration?.ready && saved.recovered) || saved.attempt) {\n return Promise.reject(\n stateError(\n \"Recover the saved booking before selecting a new session.\"\n )\n );\n }\n return run(\n () => client.initialize(selection),\n (attempt) => ({ attempt, recovered: true }),\n true\n );\n },\n [client, run]\n );\n const confirm = useCallback(\n (confirmationToken: string) => {\n const saved = current.current;\n if (\n !(\n saved.configuration?.ready &&\n saved.recovered &&\n saved.attempt?.status === \"review\"\n )\n ) {\n return Promise.reject(\n stateError(\"Recover this attempt before submitting a payment.\")\n );\n }\n return run(\n () => client.confirm(confirmationToken),\n (attempt) => ({ attempt, recovered: attempt.status !== \"review\" }),\n true\n );\n },\n [client, run]\n );\n\n useEffect(() => {\n generation.current += 1;\n inFlight.current = false;\n active.current = enabled;\n activeSession.current = sessionKey;\n current.current = initialState();\n setState(current.current);\n if (enabled) {\n refresh().catch(() => undefined);\n }\n return () => {\n active.current = false;\n generation.current += 1;\n };\n }, [enabled, sessionKey, refresh]);\n\n return {\n ...state,\n canPay: Boolean(\n enabled &&\n activeSession.current === sessionKey &&\n state.configuration?.ready &&\n state.recovered &&\n state.attempt?.status === \"review\" &&\n !state.busy\n ),\n confirm,\n findTimes,\n initialize,\n recover,\n refresh,\n };\n}\n"],"mappings":"6IA6CA,MAAM,OAAoC,CACxC,QAAS,KACT,oBAAqB,GACrB,KAAM,GACN,cAAe,KACf,MAAO,KACP,UAAW,GACX,WAAY,GACZ,MAAO,CAAC,CACV,GACA,SAAS,EAAW,EAAiB,CACnC,OAAO,IAAI,EAAoB,CAC7B,KAAM,yBACN,UACA,UAAW,kBACX,oBAAqB,GACrB,WAAY,EACd,CAAC,CACH,CAGA,SAAS,EAAiB,EAAqC,CAC7D,OAAO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AG,EACH,OAAQ,GACN,GACE,EAAc,UAAY,GAC1B,EAAM,eAAe,OACrB,EAAM,WACN,EAAM,SAAS,SAAW,UAC1B,CAAC,EAAM,MAEX,UACA,YACA,aACA,UACA,SACF,CACF"}
1
+ {"version":3,"file":"bookings.js","names":[],"sources":["../src/use-lockerverse-bookings.ts"],"sourcesContent":["import {\n type LockerverseBookingAttempt,\n type LockerverseBookingAvailability,\n type LockerverseBookingConfiguration,\n type LockerverseBookingSelection,\n type LockerverseBookingsClient,\n LockerverseSdkError,\n} from \"@lockerverse/sdk/bookings\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\nexport type UseLockerverseBookingsOptions = {\n enabled?: boolean;\n /** Non-secret generation value. Change it when the access session changes. */\n sessionKey?: string | number;\n};\nexport type UseLockerverseBookingsResult = {\n configuration: LockerverseBookingConfiguration | null;\n slots: string[];\n availabilityMessage: string;\n attempt: LockerverseBookingAttempt | null;\n busy: boolean;\n recovering: boolean;\n recovered: boolean;\n error: LockerverseSdkError | null;\n canPay: boolean;\n needsPaymentAction: boolean;\n /** Keep payment UI mounted while a submission or bank verification is active. */\n paymentVisible: boolean;\n refresh: () => Promise<void>;\n findTimes: (date: string) => Promise<LockerverseBookingAvailability>;\n initialize: (\n selection: LockerverseBookingSelection\n ) => Promise<LockerverseBookingAttempt>;\n confirm: (confirmationToken: string) => Promise<LockerverseBookingAttempt>;\n recover: () => Promise<LockerverseBookingAttempt | null>;\n};\n\ntype BookingState = Pick<\n UseLockerverseBookingsResult,\n | \"configuration\"\n | \"slots\"\n | \"availabilityMessage\"\n | \"attempt\"\n | \"busy\"\n | \"recovering\"\n | \"recovered\"\n | \"error\"\n>;\nconst initialState = (): BookingState => ({\n attempt: null,\n availabilityMessage: \"\",\n busy: false,\n configuration: null,\n error: null,\n recovered: false,\n recovering: false,\n slots: [],\n});\nfunction stateError(message: string) {\n return new LockerverseSdkError({\n code: \"booking_request_failed\",\n message,\n operation: \"recover_booking\",\n recoveryRecommended: true,\n reportable: false,\n });\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Promise rejection values are untrusted and are normalized here.\nfunction safeBookingError(error: unknown): LockerverseSdkError {\n return error instanceof LockerverseSdkError\n ? error\n : stateError(\n \"The booking request could not be completed. Check the saved state before paying.\"\n );\n}\n\n/** Recover the business-scoped attempt before permitting a payment submission. */\nexport function useLockerverseBookings(\n client: LockerverseBookingsClient,\n { enabled = true, sessionKey = 0 }: UseLockerverseBookingsOptions = {}\n): UseLockerverseBookingsResult {\n const identity = useRef(client);\n if (identity.current !== client) {\n throw new Error(\n \"Keep the booking client stable. Remount for another business.\"\n );\n }\n const [state, setState] = useState<BookingState>(initialState);\n const current = useRef(state);\n const generation = useRef(0);\n const active = useRef(false);\n const activeSession = useRef(sessionKey);\n const inFlight = useRef(false);\n const commit = useCallback((change: Partial<BookingState>) => {\n current.current = { ...current.current, ...change };\n setState(current.current);\n }, []);\n\n const run = useCallback(\n async <T>(\n operation: () => Promise<T>,\n accept: (result: T) => Partial<BookingState>,\n changesPaymentState: boolean,\n recovering = false\n ): Promise<T> => {\n if (\n !(enabled && active.current) ||\n activeSession.current !== sessionKey ||\n inFlight.current\n ) {\n throw stateError(\n \"A booking request is already in progress or access is disabled.\"\n );\n }\n inFlight.current = true;\n const version = generation.current;\n const isCurrent = () => version === generation.current;\n commit({\n busy: true,\n error: null,\n recovered: changesPaymentState ? false : current.current.recovered,\n recovering,\n });\n try {\n const result = await operation();\n if (!isCurrent()) {\n throw stateError(\n \"The booking access session changed. Recover the current session.\"\n );\n }\n commit(accept(result));\n return result;\n } catch (error) {\n const safeError = safeBookingError(error);\n if (isCurrent()) {\n commit({\n error: safeError,\n recovered: changesPaymentState ? false : current.current.recovered,\n });\n }\n throw safeError;\n } finally {\n if (version === generation.current) {\n inFlight.current = false;\n commit({ busy: false, recovering: false });\n }\n }\n },\n [commit, enabled, sessionKey]\n );\n\n const refresh = useCallback(async () => {\n const result = await run(\n async () => {\n // Recover saved payments even when the owner has changed or paused setup.\n const [configuration, recovery] = await Promise.allSettled([\n client.configuration(),\n client.recover(),\n ]);\n if (recovery.status === \"rejected\") {\n throw safeBookingError(recovery.reason);\n }\n return {\n attempt: recovery.value,\n configuration:\n configuration.status === \"fulfilled\" ? configuration.value : null,\n configurationError:\n configuration.status === \"rejected\"\n ? safeBookingError(configuration.reason)\n : null,\n };\n },\n (loaded) => ({\n attempt: loaded.attempt,\n configuration: loaded.configuration,\n error: loaded.configurationError,\n recovered: true,\n }),\n true,\n true\n );\n if (result.configurationError) {\n throw result.configurationError;\n }\n }, [client, run]);\n const recover = useCallback(\n () =>\n run(\n () => client.recover(),\n (attempt) => ({ attempt, recovered: true }),\n true,\n true\n ),\n [client, run]\n );\n const findTimes = useCallback(\n (date: string) =>\n run(\n () => client.availability(date),\n (result) => ({\n availabilityMessage: result.message,\n slots: result.slots,\n }),\n false\n ),\n [client, run]\n );\n const initialize = useCallback(\n (selection: LockerverseBookingSelection) => {\n const saved = current.current;\n if (!(saved.configuration?.ready && saved.recovered) || saved.attempt) {\n return Promise.reject(\n stateError(\n \"Recover the saved booking before selecting a new session.\"\n )\n );\n }\n return run(\n () => client.initialize(selection),\n (attempt) => ({ attempt, recovered: true }),\n true\n );\n },\n [client, run]\n );\n const confirm = useCallback(\n (confirmationToken: string) => {\n const saved = current.current;\n if (\n !(\n saved.configuration?.ready &&\n saved.recovered &&\n saved.attempt?.status === \"review\"\n )\n ) {\n return Promise.reject(\n stateError(\"Recover this attempt before submitting a payment.\")\n );\n }\n return run(\n () => client.confirm(confirmationToken),\n (attempt) => ({ attempt, recovered: attempt.status !== \"review\" }),\n true\n );\n },\n [client, run]\n );\n\n useEffect(() => {\n generation.current += 1;\n inFlight.current = false;\n active.current = enabled;\n activeSession.current = sessionKey;\n current.current = initialState();\n setState(current.current);\n if (enabled) {\n refresh().catch(() => undefined);\n }\n return () => {\n active.current = false;\n generation.current += 1;\n };\n }, [enabled, sessionKey, refresh]);\n\n return {\n ...state,\n canPay: Boolean(\n enabled &&\n activeSession.current === sessionKey &&\n state.configuration?.ready &&\n state.recovered &&\n state.attempt?.status === \"review\" &&\n !state.busy\n ),\n confirm,\n findTimes,\n initialize,\n needsPaymentAction: Boolean(\n enabled &&\n activeSession.current === sessionKey &&\n state.recovered &&\n state.attempt?.status === \"payment_action_required\" &&\n state.attempt.clientSecret &&\n !state.busy\n ),\n paymentVisible: Boolean(\n enabled &&\n activeSession.current === sessionKey &&\n state.attempt &&\n (state.attempt.status === \"payment_action_required\" ||\n (state.configuration?.ready && state.attempt.status === \"review\"))\n ),\n recover,\n refresh,\n };\n}\n"],"mappings":"6IAgDA,MAAM,OAAoC,CACxC,QAAS,KACT,oBAAqB,GACrB,KAAM,GACN,cAAe,KACf,MAAO,KACP,UAAW,GACX,WAAY,GACZ,MAAO,CAAC,CACV,GACA,SAAS,EAAW,EAAiB,CACnC,OAAO,IAAI,EAAoB,CAC7B,KAAM,yBACN,UACA,UAAW,kBACX,oBAAqB,GACrB,WAAY,EACd,CAAC,CACH,CAGA,SAAS,EAAiB,EAAqC,CAC7D,OAAO,aAAiB,EACpB,EACA,EACE,kFACF,CACN,CAGA,SAAgB,EACd,EACA,CAAE,UAAU,GAAM,aAAa,GAAqC,CAAC,EACvC,CAE9B,GADiB,EAAO,CACb,CAAC,CAAC,UAAY,EACvB,MAAU,MACR,+DACF,EAEF,GAAM,CAAC,EAAO,GAAY,EAAuB,CAAY,EACvD,EAAU,EAAO,CAAK,EACtB,EAAa,EAAO,CAAC,EACrB,EAAS,EAAO,EAAK,EACrB,EAAgB,EAAO,CAAU,EACjC,EAAW,EAAO,EAAK,EACvB,EAAS,EAAa,GAAkC,CAC5D,EAAQ,QAAU,CAAE,GAAG,EAAQ,QAAS,GAAG,CAAO,EAClD,EAAS,EAAQ,OAAO,CAC1B,EAAG,CAAC,CAAC,EAEC,EAAM,EACV,MACE,EACA,EACA,EACA,EAAa,KACE,CACf,GACE,EAAE,GAAW,EAAO,UACpB,EAAc,UAAY,GAC1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M,UACL,EAAM,QAAQ,SAAW,2BACvB,EAAM,eAAe,OAAS,EAAM,QAAQ,SAAW,WAE9D,UACA,SACF,CACF"}
@@ -1,6 +1,6 @@
1
1
  # Lockerverse auctions guide
2
2
 
3
- Package: @lockerverse/react@0.2.224-dev.1
3
+ Package: @lockerverse/react@0.2.225-dev.1
4
4
 
5
5
  Generated from this release's maintained documentation. Do not edit this copy.
6
6
 
@@ -1,6 +1,6 @@
1
1
  # Lockerverse bookings guide
2
2
 
3
- Package: @lockerverse/react@0.2.224-dev.1
3
+ Package: @lockerverse/react@0.2.225-dev.1
4
4
 
5
5
  Generated from this release's maintained documentation. Do not edit this copy.
6
6
 
@@ -35,26 +35,43 @@ non-secret counter that changes when the access code changes. Remount the hook
35
35
  when the business changes. Never place access tokens in public configuration,
36
36
  URLs, logs, analytics, or error messages. Do not bundle provider secrets.
37
37
 
38
+ Call `client.createSession()` to start a browser booking session after the owner
39
+ has enabled bookings. It returns `{ accessToken, expiresAt }`; keep this capability
40
+ in private browser storage and return it from `getAccessToken`. To renew a saved
41
+ session, pass its token to `client.createSession(previousAccessToken)`. This method
42
+ does not read `getAccessToken` or write storage. Keep the same session for saved
43
+ booking recovery, and update `sessionKey` when the token changes. Do not replace
44
+ an uncertain payment with a new session or use an owner/admin token in the public
45
+ booking flow.
46
+
38
47
  The hook loads configuration and recovers the saved attempt before it permits
39
48
  payment. `findTimes(date)` returns `{ slots, message }`; dates use YYYY-MM-DD in
40
- `configuration.business.timeZone`. `initialize({ date, start })` selects one
41
- returned slot. `confirm(confirmationToken)` submits that attempt. Both return the
49
+ `configuration.business.timeZone`. `initialize({ date, start, customer })` selects
50
+ one returned slot. For a live business, pass `customer: { name, email, phone }`
51
+ from the customer's form. The phone uses international format, such as
52
+ `+12025550123`. Keep contact data out of URLs, analytics and logs. Existing sandbox
53
+ hosts can omit `customer`. `confirm(confirmationToken)` submits that attempt. Both return the
42
54
  server attempt. `recover()` returns the saved attempt or null. `refresh()` loads
43
55
  configuration and recovery and returns void. All action promises reject on error;
44
56
  handle the rejection and show `error.message`.
45
57
 
46
- Use `configuration.business.service` for the name, amount, currency and duration.
47
- Render the lazy payment component inside a React `Suspense` boundary **only while
48
- `canPay` is true**, with these props:
58
+ Use `configuration.business.service` for the available service before selection.
59
+ After initialization or recovery, use `attempt.serviceName`, `attempt.amountCents`
60
+ and `attempt.currency` for the payment review and saved booking summary. The owner
61
+ can change the current service after this attempt was created; that must not
62
+ change the amount the customer sees for the saved payment. If an older backend
63
+ does not return the saved amount, keep payment disabled and check the booking.
64
+ Render the lazy payment component inside a React `Suspense` boundary while
65
+ `paymentVisible` is true. Keep it mounted during submission and bank verification:
49
66
 
50
67
  ```tsx
51
68
  <BookingPayment
52
69
  key={booking.attempt.id}
53
70
  publishableKey={booking.attempt.publishableKey}
54
- amountCents={booking.configuration.business.service.amountCents}
55
- currency={booking.configuration.business.service.currency}
71
+ attempt={booking.attempt}
56
72
  onConfirm={booking.confirm}
57
- disabled={booking.busy}
73
+ onRecover={booking.recover}
74
+ disabled={!booking.canPay && !booking.needsPaymentAction}
58
75
  buttonClassName="your-existing-button-style"
59
76
  />
60
77
  ```
@@ -69,6 +86,15 @@ manifest. It creates a confirmation token with off-session setup and sends it to
69
86
  the Lockerverse backend. It does not confirm or charge on the client. Its button
70
87
  locks after submission. It adds no CSS; hosts retain their page and button styles.
71
88
 
89
+ The component uses the attempt's saved amount, currency and `stripeAccountId` for
90
+ card entry. When the payment needs bank verification, it shows **Continue payment**
91
+ instead of another card form. This action uses the private `clientSecret`, then
92
+ recovers the same attempt through `onRecover`. Do not store the client
93
+ secret in a URL, public loader, log or analytics event. If you build custom card UI,
94
+ use the same account, call Stripe `handleNextAction` only for the recovered payment,
95
+ and call `recover()` after either completion or dismissal. Do not submit another
96
+ confirmation token for a payment that needs bank verification.
97
+
72
98
  A timeout or lost response does not mean payment failed. Keep the saved attempt,
73
99
  show recovery, and call `recover()` before any next action. Do not create a new
74
100
  attempt after an unknown result. The hook blocks another payment until recovery
@@ -78,7 +104,14 @@ succeeds, and ignores late responses from an old access session. A returned
78
104
  states remain visible and may need recovery or staff help; never translate them
79
105
  into a fresh payment automatically.
80
106
 
81
- This first release supports one configured service per business and USD. The
107
+ Configuration and recovery load independently. A paused or changed business setup
108
+ can block a new payment without hiding the customer's saved payment or bank
109
+ verification. Keep the saved booking summary and recovery controls visible when
110
+ configuration fails; show the error without clearing that saved state.
111
+
112
+ Booking support uses one configured service per business and USD. The
82
113
  backend owns Square credentials, the payment amount, payment idempotency, booking
83
114
  creation and the staff paid note. SDK availability does not enable production
84
- booking endpoints: configure and approve each backend environment separately.
115
+ booking endpoints: complete the owner's Square and Lockerverse payment setup in
116
+ the backend environment. `configuration.business.environment` identifies Square's sandbox
117
+ or production mode; it is separate from the SDK's API `environment` option.
package/guides/events.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Lockerverse events guide
2
2
 
3
- Package: @lockerverse/react@0.2.224-dev.1
3
+ Package: @lockerverse/react@0.2.225-dev.1
4
4
 
5
5
  Generated from this release's maintained documentation. Do not edit this copy.
6
6
 
@@ -1,6 +1,6 @@
1
1
  # Lockerverse integration guide
2
2
 
3
- Package: @lockerverse/react@0.2.224-dev.1
3
+ Package: @lockerverse/react@0.2.225-dev.1
4
4
 
5
5
  Generated from this release's maintained documentation. Do not edit this copy.
6
6
 
@@ -1,6 +1,6 @@
1
1
  # Lockerverse payment-widgets guide
2
2
 
3
- Package: @lockerverse/react@0.2.224-dev.1
3
+ Package: @lockerverse/react@0.2.225-dev.1
4
4
 
5
5
  Generated from this release's maintained documentation. Do not edit this copy.
6
6
 
package/guides/signup.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Lockerverse signup guide
2
2
 
3
- Package: @lockerverse/react@0.2.224-dev.1
3
+ Package: @lockerverse/react@0.2.225-dev.1
4
4
 
5
5
  Generated from this release's maintained documentation. Do not edit this copy.
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lockerverse/react",
3
- "version": "0.2.224-dev.1",
3
+ "version": "0.2.225-dev.1",
4
4
  "description": "Tree-shakable React payment and signup UI for Lockerverse",
5
5
  "repository": {
6
6
  "type": "git",
@@ -146,7 +146,7 @@
146
146
  "embla-carousel-react": "8.6.0",
147
147
  "lucide-react": "0.536.0",
148
148
  "valibot": "1.4.2",
149
- "@lockerverse/sdk": "0.2.224-dev.1"
149
+ "@lockerverse/sdk": "0.2.225-dev.1"
150
150
  },
151
151
  "devDependencies": {
152
152
  "@size-limit/file": "13.0.3",