@bowlos/reservations 0.1.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -0
- package/dist/account-COEgvwfx.d.cts +43 -0
- package/dist/account-CzyIERC5.d.ts +43 -0
- package/dist/{chunk-TZTFJVDI.js → chunk-2RMK6BWO.js} +2 -2
- package/dist/{chunk-TZTFJVDI.js.map → chunk-2RMK6BWO.js.map} +1 -1
- package/dist/{chunk-T5DDHWEC.js → chunk-4FL2QYSS.js} +3 -3
- package/dist/{chunk-T5DDHWEC.js.map → chunk-4FL2QYSS.js.map} +1 -1
- package/dist/chunk-NYTGLAQH.js +299 -0
- package/dist/chunk-NYTGLAQH.js.map +1 -0
- package/dist/{chunk-TCYTNCUL.js → chunk-QGTGKNJW.js} +11 -3
- package/dist/chunk-QGTGKNJW.js.map +1 -0
- package/dist/cli.cjs +74 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +76 -6
- package/dist/cli.js.map +1 -1
- package/dist/components.cjs +1120 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +353 -0
- package/dist/components.d.ts +353 -0
- package/dist/components.js +765 -0
- package/dist/components.js.map +1 -0
- package/dist/{account-Cl6hElpL.d.cts → data-DrM0D6Pi.d.cts} +1 -41
- package/dist/{account-Cl6hElpL.d.ts → data-DrM0D6Pi.d.ts} +1 -41
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -3
- package/dist/react-B_8H7AyT.d.cts +43 -0
- package/dist/react-bG9YV_xP.d.ts +43 -0
- package/dist/react.d.cts +7 -42
- package/dist/react.d.ts +7 -42
- package/dist/react.js +3 -297
- package/dist/react.js.map +1 -1
- package/package.json +14 -3
- package/templates/center-site/README.md +85 -0
- package/templates/center-site/app/account/page.tsx +19 -0
- package/templates/center-site/app/book/checkout-form.tsx +85 -0
- package/templates/center-site/app/book/page.tsx +181 -0
- package/templates/center-site/app/flash/[slug]/page.tsx +24 -0
- package/templates/center-site/app/layout.tsx +17 -0
- package/templates/center-site/app/page.tsx +26 -0
- package/templates/center-site/app/providers.tsx +21 -0
- package/templates/center-site/env.example +18 -0
- package/templates/center-site/gitignore +8 -0
- package/templates/center-site/lib/bowlos.ts +31 -0
- package/templates/center-site/next.config.mjs +8 -0
- package/templates/center-site/package.json +26 -0
- package/templates/center-site/tsconfig.json +38 -0
- package/dist/chunk-TCYTNCUL.js.map +0 -1
package/dist/react.js
CHANGED
|
@@ -1,299 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { jsx } from 'react/jsx-runtime';
|
|
5
|
-
|
|
6
|
-
var BowlosContext = createContext(null);
|
|
7
|
-
function BowlosProvider({ client, config, children }) {
|
|
8
|
-
const ref = useRef(client ?? null);
|
|
9
|
-
if (!ref.current) {
|
|
10
|
-
if (!config) {
|
|
11
|
-
throw new Error("BowlosProvider requires either a `client` or a `config`.");
|
|
12
|
-
}
|
|
13
|
-
ref.current = createBowlosClient(config);
|
|
14
|
-
}
|
|
15
|
-
return /* @__PURE__ */ jsx(BowlosContext.Provider, { value: ref.current, children });
|
|
16
|
-
}
|
|
17
|
-
function useBowlosClient() {
|
|
18
|
-
const client = useContext(BowlosContext);
|
|
19
|
-
if (!client) {
|
|
20
|
-
throw new Error("useBowlosClient must be used within a <BowlosProvider>.");
|
|
21
|
-
}
|
|
22
|
-
return client;
|
|
23
|
-
}
|
|
24
|
-
function useAccount() {
|
|
25
|
-
const client = useBowlosClient();
|
|
26
|
-
const [status, setStatus] = useState("loading");
|
|
27
|
-
const [customer, setCustomer] = useState(null);
|
|
28
|
-
const [error, setError] = useState(null);
|
|
29
|
-
const refresh = useCallback(async () => {
|
|
30
|
-
try {
|
|
31
|
-
const state = await client.probe();
|
|
32
|
-
setStatus(state);
|
|
33
|
-
setCustomer(state === "linked" ? await client.me() : null);
|
|
34
|
-
setError(null);
|
|
35
|
-
} catch (e) {
|
|
36
|
-
setStatus("unauthenticated");
|
|
37
|
-
setCustomer(null);
|
|
38
|
-
if (e instanceof BowlosApiError) setError(e);
|
|
39
|
-
}
|
|
40
|
-
}, [client]);
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
void refresh();
|
|
43
|
-
}, [refresh]);
|
|
44
|
-
const run = useCallback(
|
|
45
|
-
async (action) => {
|
|
46
|
-
setError(null);
|
|
47
|
-
try {
|
|
48
|
-
await action();
|
|
49
|
-
await refresh();
|
|
50
|
-
} catch (e) {
|
|
51
|
-
if (e instanceof BowlosApiError) setError(e);
|
|
52
|
-
throw e;
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
[refresh]
|
|
56
|
-
);
|
|
57
|
-
const signIn = useCallback(
|
|
58
|
-
(email, password) => run(() => client.signIn(email, password)),
|
|
59
|
-
[client, run]
|
|
60
|
-
);
|
|
61
|
-
const signUp = useCallback(
|
|
62
|
-
(email, password) => run(() => client.signUp(email, password)),
|
|
63
|
-
[client, run]
|
|
64
|
-
);
|
|
65
|
-
const link = useCallback((profile) => run(() => client.link(profile)), [client, run]);
|
|
66
|
-
const signOut = useCallback(() => run(() => client.signOut()), [client, run]);
|
|
67
|
-
return { status, customer, error, signIn, signUp, link, signOut, refresh };
|
|
68
|
-
}
|
|
69
|
-
function useBowlosQuery(name, args = {}, options = {}) {
|
|
70
|
-
const client = useBowlosClient();
|
|
71
|
-
const auth = options.auth ?? false;
|
|
72
|
-
const enabled = options.enabled ?? true;
|
|
73
|
-
const [data, setData] = useState(null);
|
|
74
|
-
const [error, setError] = useState(null);
|
|
75
|
-
const [loading, setLoading] = useState(enabled);
|
|
76
|
-
const argsKey = JSON.stringify(args);
|
|
77
|
-
const refetch = useCallback(async () => {
|
|
78
|
-
setLoading(true);
|
|
79
|
-
setError(null);
|
|
80
|
-
try {
|
|
81
|
-
const result = await client.call(name, JSON.parse(argsKey), {
|
|
82
|
-
auth
|
|
83
|
-
});
|
|
84
|
-
setData(result);
|
|
85
|
-
} catch (e) {
|
|
86
|
-
if (e instanceof BowlosApiError) setError(e);
|
|
87
|
-
setData(null);
|
|
88
|
-
} finally {
|
|
89
|
-
setLoading(false);
|
|
90
|
-
}
|
|
91
|
-
}, [client, name, argsKey, auth]);
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
if (enabled) void refetch();
|
|
94
|
-
}, [enabled, refetch]);
|
|
95
|
-
return { data, error, loading, refetch };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// src/hooks.tsx
|
|
99
|
-
function useAvailability(args, options) {
|
|
100
|
-
return useBowlosQuery("checkAvailability", args, options);
|
|
101
|
-
}
|
|
102
|
-
function useBookingPreview(args, options) {
|
|
103
|
-
return useBowlosQuery("bookingPreview", args, options);
|
|
104
|
-
}
|
|
105
|
-
function useMyReservations(args, options) {
|
|
106
|
-
return useBowlosQuery("listMyReservations", args, { ...options, auth: true });
|
|
107
|
-
}
|
|
108
|
-
function useMyReservationDetail(args, options) {
|
|
109
|
-
return useBowlosQuery("getMyReservationDetail", args, { ...options, auth: true });
|
|
110
|
-
}
|
|
111
|
-
function useMyMemberships(args, options) {
|
|
112
|
-
return useBowlosQuery("listMyMemberships", args, { ...options, auth: true });
|
|
113
|
-
}
|
|
114
|
-
function useMyMembershipDetail(args, options) {
|
|
115
|
-
return useBowlosQuery("getMyMembershipDetail", args, { ...options, auth: true });
|
|
116
|
-
}
|
|
117
|
-
function useMyLoyalty(args, options) {
|
|
118
|
-
return useBowlosQuery("getMyLoyalty", args, { ...options, auth: true });
|
|
119
|
-
}
|
|
120
|
-
function useMyCredits(args, options) {
|
|
121
|
-
return useBowlosQuery("listMyCredits", args, { ...options, auth: true });
|
|
122
|
-
}
|
|
123
|
-
function useMyPasses(args, options) {
|
|
124
|
-
return useBowlosQuery("listMyPasses", args, { ...options, auth: true });
|
|
125
|
-
}
|
|
126
|
-
function useFlashSale(args, options) {
|
|
127
|
-
return useBowlosQuery("getPublicFlashSaleBySlug", args, { ...options, auth: true });
|
|
128
|
-
}
|
|
129
|
-
function useFlashSaleBookingOptions(args, options) {
|
|
130
|
-
return useBowlosQuery("getFlashSaleBookingOptions", args, { ...options, auth: true });
|
|
131
|
-
}
|
|
132
|
-
var DEFAULT_POLL_MS = 2500;
|
|
133
|
-
function useBookingFlow() {
|
|
134
|
-
const client = useBowlosClient();
|
|
135
|
-
const [status, setStatus] = useState("idle");
|
|
136
|
-
const [hold, setHold] = useState(null);
|
|
137
|
-
const [refToken, setRefToken] = useState(null);
|
|
138
|
-
const [paymentIntent, setPaymentIntent] = useState(null);
|
|
139
|
-
const [reservation, setReservation] = useState(null);
|
|
140
|
-
const [error, setError] = useState(null);
|
|
141
|
-
const refTokenRef = useRef(null);
|
|
142
|
-
const pollRef = useRef(null);
|
|
143
|
-
const stopPolling = useCallback(() => {
|
|
144
|
-
if (pollRef.current !== null) {
|
|
145
|
-
clearInterval(pollRef.current);
|
|
146
|
-
pollRef.current = null;
|
|
147
|
-
}
|
|
148
|
-
}, []);
|
|
149
|
-
useEffect(() => stopPolling, [stopPolling]);
|
|
150
|
-
const reset = useCallback(() => {
|
|
151
|
-
stopPolling();
|
|
152
|
-
refTokenRef.current = null;
|
|
153
|
-
setRefToken(null);
|
|
154
|
-
setHold(null);
|
|
155
|
-
setPaymentIntent(null);
|
|
156
|
-
setReservation(null);
|
|
157
|
-
setError(null);
|
|
158
|
-
setStatus("idle");
|
|
159
|
-
}, [stopPolling]);
|
|
160
|
-
const applyStatus = useCallback(
|
|
161
|
-
(s) => {
|
|
162
|
-
switch (s.status) {
|
|
163
|
-
case "paid_materialized":
|
|
164
|
-
setReservation({
|
|
165
|
-
reservationId: s.reservationId,
|
|
166
|
-
reservationDisplayId: s.reservationDisplayId
|
|
167
|
-
});
|
|
168
|
-
setStatus("confirmed");
|
|
169
|
-
stopPolling();
|
|
170
|
-
break;
|
|
171
|
-
case "expired":
|
|
172
|
-
setStatus("expired");
|
|
173
|
-
stopPolling();
|
|
174
|
-
break;
|
|
175
|
-
case "abandoned":
|
|
176
|
-
setStatus("abandoned");
|
|
177
|
-
stopPolling();
|
|
178
|
-
break;
|
|
179
|
-
case "payment_failed_retryable":
|
|
180
|
-
setStatus("failed");
|
|
181
|
-
stopPolling();
|
|
182
|
-
break;
|
|
183
|
-
case "not_found":
|
|
184
|
-
setError(new BowlosApiError(BOWLOS_ERROR_CODES.NOT_FOUND, "Checkout not found.", 404));
|
|
185
|
-
setStatus("error");
|
|
186
|
-
stopPolling();
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
[stopPolling]
|
|
191
|
-
);
|
|
192
|
-
const startHold = useCallback(
|
|
193
|
-
async (args) => {
|
|
194
|
-
stopPolling();
|
|
195
|
-
setError(null);
|
|
196
|
-
setPaymentIntent(null);
|
|
197
|
-
setReservation(null);
|
|
198
|
-
setStatus("holding");
|
|
199
|
-
try {
|
|
200
|
-
const h = await createBooking(client, args);
|
|
201
|
-
setHold(h);
|
|
202
|
-
const rt = typeof h.checkoutRefToken === "string" ? h.checkoutRefToken : null;
|
|
203
|
-
refTokenRef.current = rt;
|
|
204
|
-
setRefToken(rt);
|
|
205
|
-
if (!h.requiresPayment) {
|
|
206
|
-
setReservation({
|
|
207
|
-
reservationId: h.reservationId ?? null,
|
|
208
|
-
reservationDisplayId: h.reservationDisplayId ?? null
|
|
209
|
-
});
|
|
210
|
-
setStatus("confirmed");
|
|
211
|
-
} else if (rt) {
|
|
212
|
-
setStatus("held");
|
|
213
|
-
} else {
|
|
214
|
-
setError(
|
|
215
|
-
new BowlosApiError(
|
|
216
|
-
"UNSUPPORTED_BOOKING_PATH",
|
|
217
|
-
"This booking requires payment but no checkout hold was returned.",
|
|
218
|
-
0
|
|
219
|
-
)
|
|
220
|
-
);
|
|
221
|
-
setStatus("error");
|
|
222
|
-
}
|
|
223
|
-
} catch (e) {
|
|
224
|
-
if (e instanceof BowlosApiError) setError(e);
|
|
225
|
-
setStatus("error");
|
|
226
|
-
}
|
|
227
|
-
},
|
|
228
|
-
[client, stopPolling]
|
|
229
|
-
);
|
|
230
|
-
const preparePayment = useCallback(async () => {
|
|
231
|
-
const rt = refTokenRef.current;
|
|
232
|
-
if (!rt) return null;
|
|
233
|
-
setError(null);
|
|
234
|
-
setStatus("preparingPayment");
|
|
235
|
-
try {
|
|
236
|
-
const pi = await createCheckoutPaymentIntent(client, rt);
|
|
237
|
-
setPaymentIntent(pi);
|
|
238
|
-
setStatus("awaitingPayment");
|
|
239
|
-
return pi;
|
|
240
|
-
} catch (e) {
|
|
241
|
-
if (e instanceof BowlosApiError) setError(e);
|
|
242
|
-
setStatus("error");
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
}, [client]);
|
|
246
|
-
const pollStatus = useCallback(async () => {
|
|
247
|
-
const rt = refTokenRef.current;
|
|
248
|
-
if (!rt) return null;
|
|
249
|
-
try {
|
|
250
|
-
const s = await getCheckoutStatus(client, rt);
|
|
251
|
-
applyStatus(s);
|
|
252
|
-
return s;
|
|
253
|
-
} catch (e) {
|
|
254
|
-
if (e instanceof BowlosApiError) setError(e);
|
|
255
|
-
return null;
|
|
256
|
-
}
|
|
257
|
-
}, [client, applyStatus]);
|
|
258
|
-
const startPolling = useCallback(
|
|
259
|
-
(intervalMs = DEFAULT_POLL_MS) => {
|
|
260
|
-
stopPolling();
|
|
261
|
-
void pollStatus();
|
|
262
|
-
pollRef.current = setInterval(() => {
|
|
263
|
-
void pollStatus();
|
|
264
|
-
}, intervalMs);
|
|
265
|
-
},
|
|
266
|
-
[pollStatus, stopPolling]
|
|
267
|
-
);
|
|
268
|
-
const abandon = useCallback(async () => {
|
|
269
|
-
stopPolling();
|
|
270
|
-
const rt = refTokenRef.current;
|
|
271
|
-
if (rt) {
|
|
272
|
-
try {
|
|
273
|
-
await abandonCheckout(client, rt);
|
|
274
|
-
} catch {
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
setStatus("abandoned");
|
|
278
|
-
}, [client, stopPolling]);
|
|
279
|
-
return {
|
|
280
|
-
status,
|
|
281
|
-
hold,
|
|
282
|
-
refToken,
|
|
283
|
-
paymentIntent,
|
|
284
|
-
reservation,
|
|
285
|
-
requiresPayment: hold ? hold.requiresPayment : null,
|
|
286
|
-
error,
|
|
287
|
-
startHold,
|
|
288
|
-
preparePayment,
|
|
289
|
-
pollStatus,
|
|
290
|
-
startPolling,
|
|
291
|
-
stopPolling,
|
|
292
|
-
abandon,
|
|
293
|
-
reset
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
export { BowlosProvider, useAccount, useAvailability, useBookingFlow, useBookingPreview, useBowlosClient, useBowlosQuery, useFlashSale, useFlashSaleBookingOptions, useMyCredits, useMyLoyalty, useMyMembershipDetail, useMyMemberships, useMyPasses, useMyReservationDetail, useMyReservations };
|
|
1
|
+
export { BowlosProvider, useAccount, useAvailability, useBookingFlow, useBookingPreview, useBowlosClient, useBowlosQuery, useFlashSale, useFlashSaleBookingOptions, useMyCredits, useMyLoyalty, useMyMembershipDetail, useMyMemberships, useMyPasses, useMyReservationDetail, useMyReservations } from './chunk-NYTGLAQH.js';
|
|
2
|
+
import './chunk-2RMK6BWO.js';
|
|
3
|
+
import './chunk-QGTGKNJW.js';
|
|
298
4
|
//# sourceMappingURL=react.js.map
|
|
299
5
|
//# sourceMappingURL=react.js.map
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react.tsx","../src/hooks.tsx","../src/use-booking-flow.tsx"],"names":["useState","useRef","useCallback","useEffect"],"mappings":";;;;;AAwBA,IAAM,aAAA,GAAgB,cAAmC,IAAI,CAAA;AAStD,SAAS,cAAA,CAAe,EAAE,MAAA,EAAQ,MAAA,EAAQ,UAAS,EAAwB;AAChF,EAAA,MAAM,GAAA,GAAM,MAAA,CAA4B,MAAA,IAAU,IAAI,CAAA;AACtD,EAAA,IAAI,CAAC,IAAI,OAAA,EAAS;AAChB,IAAA,IAAI,CAAC,MAAA,EAAQ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A,WAAAA;AAAA,IACnB,CAAC,aAAqB,eAAA,KAAoB;AACxC,MAAA,WAAA,EAAY;AACZ,MAAA,KAAK,UAAA,EAAW;AAChB,MAAA,OAAA,CAAQ,OAAA,GAAU,YAAY,MAAM;AAClC,QAAA,KAAK,UAAA,EAAW;AAAA,MAClB,GAAG,UAAU,CAAA;AAAA,IACf,CAAA;AAAA,IACA,CAAC,YAAY,WAAW;AAAA,GAC1B;AAEA,EAAA,MAAM,OAAA,GAAUA,YAAY,YAAY;AACtC,IAAA,WAAA,EAAY;AACZ,IAAA,MAAM,KAAK,WAAA,CAAY,OAAA;AACvB,IAAA,IAAI,EAAA,EAAI;AACN,MAAA,IAAI;AACF,QAAA,MAAM,eAAA,CAAoB,QAAQ,EAAE,CAAA;AAAA,MACtC,CAAA,CAAA,MAAQ;AAAA,MAER;AAAA,IACF;AACA,IAAA,SAAA,CAAU,WAAW,CAAA;AAAA,EACvB,CAAA,EAAG,CAAC,MAAA,EAAQ,WAAW,CAAC,CAAA;AAExB,EAAA,OAAO;AAAA,IACL,MAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,aAAA;AAAA,IACA,WAAA;AAAA,IACA,eAAA,EAAiB,IAAA,GAAO,IAAA,CAAK,eAAA,GAAkB,IAAA;AAAA,IAC/C,KAAA;AAAA,IACA,SAAA;AAAA,IACA,cAAA;AAAA,IACA,UAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF;AACF","file":"react.js","sourcesContent":["/**\n * React layer for @bowlos/reservations.\n *\n * `<BowlosProvider>` holds one `BowlosClient`; `useAccount()` manages the\n * customer session (probe on mount, sign-in/up/link/out, current customer);\n * `useBowlosQuery()` is the generic read hook the typed data hooks\n * (`useAvailability`, `useBookingFlow`, …) will build on next.\n *\n * Lives in its own module so non-React consumers of the core never pull React.\n * (The `@bowlos/reservations/react` export subpath is wired with the publish build.)\n */\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n type ReactNode,\n} from \"react\";\nimport { BowlosClient, createBowlosClient } from \"./client\";\nimport { BowlosApiError } from \"./errors\";\nimport type { AuthState, BowlosClientConfig, Customer, LinkProfile } from \"./types\";\n\nconst BowlosContext = createContext<BowlosClient | null>(null);\n\nexport interface BowlosProviderProps {\n /** A prebuilt client, or pass `config` to have one created and memoized. */\n client?: BowlosClient;\n config?: BowlosClientConfig;\n children: ReactNode;\n}\n\nexport function BowlosProvider({ client, config, children }: BowlosProviderProps) {\n const ref = useRef<BowlosClient | null>(client ?? null);\n if (!ref.current) {\n if (!config) {\n throw new Error(\"BowlosProvider requires either a `client` or a `config`.\");\n }\n ref.current = createBowlosClient(config);\n }\n return <BowlosContext.Provider value={ref.current}>{children}</BowlosContext.Provider>;\n}\n\nexport function useBowlosClient(): BowlosClient {\n const client = useContext(BowlosContext);\n if (!client) {\n throw new Error(\"useBowlosClient must be used within a <BowlosProvider>.\");\n }\n return client;\n}\n\n// ── useAccount ──────────────────────────────────────────────────────────────\n\nexport type AccountStatus = \"loading\" | AuthState;\n\nexport interface UseAccountResult {\n status: AccountStatus;\n customer: Customer | null;\n error: BowlosApiError | null;\n signIn: (email: string, password: string) => Promise<void>;\n signUp: (email: string, password: string) => Promise<void>;\n link: (profile: LinkProfile) => Promise<void>;\n signOut: () => Promise<void>;\n refresh: () => Promise<void>;\n}\n\n/** Customer session state + actions. Probes once on mount; each action\n * re-probes so `status`/`customer` stay current. */\nexport function useAccount(): UseAccountResult {\n const client = useBowlosClient();\n const [status, setStatus] = useState<AccountStatus>(\"loading\");\n const [customer, setCustomer] = useState<Customer | null>(null);\n const [error, setError] = useState<BowlosApiError | null>(null);\n\n const refresh = useCallback(async () => {\n try {\n const state = await client.probe();\n setStatus(state);\n setCustomer(state === \"linked\" ? await client.me() : null);\n setError(null);\n } catch (e) {\n setStatus(\"unauthenticated\");\n setCustomer(null);\n if (e instanceof BowlosApiError) setError(e);\n }\n }, [client]);\n\n useEffect(() => {\n void refresh();\n }, [refresh]);\n\n const run = useCallback(\n async (action: () => Promise<unknown>) => {\n setError(null);\n try {\n await action();\n await refresh();\n } catch (e) {\n if (e instanceof BowlosApiError) setError(e);\n throw e;\n }\n },\n [refresh],\n );\n\n const signIn = useCallback(\n (email: string, password: string) => run(() => client.signIn(email, password)),\n [client, run],\n );\n const signUp = useCallback(\n (email: string, password: string) => run(() => client.signUp(email, password)),\n [client, run],\n );\n const link = useCallback((profile: LinkProfile) => run(() => client.link(profile)), [client, run]);\n const signOut = useCallback(() => run(() => client.signOut()), [client, run]);\n\n return { status, customer, error, signIn, signUp, link, signOut, refresh };\n}\n\n// ── useBowlosQuery ────────────────────────────────────────────────────────────\n\nexport interface UseQueryOptions {\n /** Send the customer bearer token (for session-scoped reads). */\n auth?: boolean;\n /** Skip fetching until true. Defaults to true. */\n enabled?: boolean;\n}\n\nexport interface UseQueryResult<T> {\n data: T | null;\n error: BowlosApiError | null;\n loading: boolean;\n refetch: () => Promise<void>;\n}\n\n/** Generic read hook over a gateway route. The typed data hooks\n * (`useAvailability`, etc.) will wrap this with route names + arg types. */\nexport function useBowlosQuery<T = unknown>(\n name: string,\n args: Record<string, unknown> = {},\n options: UseQueryOptions = {},\n): UseQueryResult<T> {\n const client = useBowlosClient();\n const auth = options.auth ?? false;\n const enabled = options.enabled ?? true;\n const [data, setData] = useState<T | null>(null);\n const [error, setError] = useState<BowlosApiError | null>(null);\n const [loading, setLoading] = useState<boolean>(enabled);\n // Stabilize the args object across renders so the effect doesn't loop.\n const argsKey = JSON.stringify(args);\n\n const refetch = useCallback(async () => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.call<T>(name, JSON.parse(argsKey) as Record<string, unknown>, {\n auth,\n });\n setData(result);\n } catch (e) {\n if (e instanceof BowlosApiError) setError(e);\n setData(null);\n } finally {\n setLoading(false);\n }\n }, [client, name, argsKey, auth]);\n\n useEffect(() => {\n if (enabled) void refetch();\n }, [enabled, refetch]);\n\n return { data, error, loading, refetch };\n}\n","/**\n * Typed React data hooks for the booking funnel, built on `useBowlosQuery`.\n * Same arg/result types as the framework-agnostic functions in `data.ts`.\n */\nimport { useBowlosQuery, type UseQueryOptions, type UseQueryResult } from \"./react\";\nimport type {\n AvailabilityArgs,\n AvailabilityResult,\n BookingPreviewArgs,\n BookingQuote,\n} from \"./data\";\nimport type {\n BrandScoped,\n FlashBookingOptionsArgs,\n FlashSaleArgs,\n MembershipDetailArgs,\n ReservationDetailArgs,\n} from \"./account\";\n\n/** Live free-unit availability for a product / date / time window. */\nexport function useAvailability(\n args: AvailabilityArgs,\n options?: UseQueryOptions,\n): UseQueryResult<AvailabilityResult> {\n return useBowlosQuery<AvailabilityResult>(\"checkAvailability\", args, options);\n}\n\n/** Authoritative price quote for the chosen booking inputs. */\nexport function useBookingPreview(\n args: BookingPreviewArgs,\n options?: UseQueryOptions,\n): UseQueryResult<BookingQuote> {\n return useBowlosQuery<BookingQuote>(\"bookingPreview\", args, options);\n}\n\n// ── account (require a signed-in customer) ───────────────────────────────────\n// Results are generic (`<T = unknown>`) — parameterize with your own shape.\n\n/** The signed-in customer's reservations. */\nexport function useMyReservations<T = unknown>(\n args: BrandScoped,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"listMyReservations\", args, { ...options, auth: true });\n}\n\n/** One of the customer's reservations, by displayId. */\nexport function useMyReservationDetail<T = unknown>(\n args: ReservationDetailArgs,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"getMyReservationDetail\", args, { ...options, auth: true });\n}\n\n/** The customer's memberships. */\nexport function useMyMemberships<T = unknown>(\n args: BrandScoped,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"listMyMemberships\", args, { ...options, auth: true });\n}\n\n/** One membership's detail. */\nexport function useMyMembershipDetail<T = unknown>(\n args: MembershipDetailArgs,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"getMyMembershipDetail\", args, { ...options, auth: true });\n}\n\n/** Loyalty tier + points. */\nexport function useMyLoyalty<T = unknown>(\n args: BrandScoped,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"getMyLoyalty\", args, { ...options, auth: true });\n}\n\n/** Account credit balance + ledger. */\nexport function useMyCredits<T = unknown>(\n args: BrandScoped,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"listMyCredits\", args, { ...options, auth: true });\n}\n\n/** Issued wallet passes. */\nexport function useMyPasses<T = unknown>(\n args: BrandScoped,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"listMyPasses\", args, { ...options, auth: true });\n}\n\n// ── flash sales (session-aware: members see prices) ──────────────────────────\n\n/** The public flash-sale page (members see prices; anonymous gets the locked view). */\nexport function useFlashSale<T = unknown>(\n args: FlashSaleArgs,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"getPublicFlashSaleBySlug\", args, { ...options, auth: true });\n}\n\n/** Per-start-hour options for a flash-sale reservation item (members only). */\nexport function useFlashSaleBookingOptions<T = unknown>(\n args: FlashBookingOptionsArgs,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"getFlashSaleBookingOptions\", args, { ...options, auth: true });\n}\n","/**\n * useBookingFlow — the hold → pay → confirm state machine.\n *\n * Orchestrates the booking funnel and HANDS the Stripe (Connect) payment data\n * to the UI layer; it does NOT load Stripe.js. After `preparePayment()`, render\n * Stripe Elements from `paymentIntent` (initialize Stripe with\n * `connectedAccountId` + `clientSecret`), let the customer pay, then\n * `startPolling()` until the webhook materializes the booking\n * (`status: \"confirmed\"`).\n *\n * Flow:\n * startHold(args) → \"held\" (requiresPayment) | \"confirmed\" (credit covered)\n * preparePayment() → \"awaitingPayment\" (+ paymentIntent)\n * [consumer renders Stripe Elements + the customer pays]\n * startPolling() → \"confirmed\" | \"expired\" | \"failed\" | \"abandoned\"\n */\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useBowlosClient } from \"./react\";\nimport { BowlosApiError, BOWLOS_ERROR_CODES } from \"./errors\";\nimport {\n abandonCheckout as abandonCheckoutCall,\n createBooking as createBookingCall,\n createCheckoutPaymentIntent as createPaymentIntentCall,\n getCheckoutStatus as getCheckoutStatusCall,\n type BookingHold,\n type CheckoutStatusResult,\n type CreateBookingArgs,\n type PaymentIntentInfo,\n} from \"./data\";\n\nexport type BookingFlowStatus =\n | \"idle\"\n | \"holding\"\n | \"held\"\n | \"preparingPayment\"\n | \"awaitingPayment\"\n | \"confirmed\"\n | \"expired\"\n | \"failed\"\n | \"abandoned\"\n | \"error\";\n\nexport interface BookingReservationRef {\n reservationId: string | null;\n reservationDisplayId: string | null;\n}\n\nexport interface UseBookingFlowResult {\n status: BookingFlowStatus;\n hold: BookingHold | null;\n refToken: string | null;\n paymentIntent: PaymentIntentInfo | null;\n reservation: BookingReservationRef | null;\n requiresPayment: boolean | null;\n error: BowlosApiError | null;\n startHold: (args: CreateBookingArgs) => Promise<void>;\n preparePayment: () => Promise<PaymentIntentInfo | null>;\n pollStatus: () => Promise<CheckoutStatusResult | null>;\n startPolling: (intervalMs?: number) => void;\n stopPolling: () => void;\n abandon: () => Promise<void>;\n reset: () => void;\n}\n\nconst DEFAULT_POLL_MS = 2500;\n\nexport function useBookingFlow(): UseBookingFlowResult {\n const client = useBowlosClient();\n const [status, setStatus] = useState<BookingFlowStatus>(\"idle\");\n const [hold, setHold] = useState<BookingHold | null>(null);\n const [refToken, setRefToken] = useState<string | null>(null);\n const [paymentIntent, setPaymentIntent] = useState<PaymentIntentInfo | null>(null);\n const [reservation, setReservation] = useState<BookingReservationRef | null>(null);\n const [error, setError] = useState<BowlosApiError | null>(null);\n\n // Mirror of refToken for the polling interval (avoids a stale closure).\n const refTokenRef = useRef<string | null>(null);\n const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);\n\n const stopPolling = useCallback(() => {\n if (pollRef.current !== null) {\n clearInterval(pollRef.current);\n pollRef.current = null;\n }\n }, []);\n\n useEffect(() => stopPolling, [stopPolling]); // clear the interval on unmount\n\n const reset = useCallback(() => {\n stopPolling();\n refTokenRef.current = null;\n setRefToken(null);\n setHold(null);\n setPaymentIntent(null);\n setReservation(null);\n setError(null);\n setStatus(\"idle\");\n }, [stopPolling]);\n\n const applyStatus = useCallback(\n (s: CheckoutStatusResult) => {\n switch (s.status) {\n case \"paid_materialized\":\n setReservation({\n reservationId: s.reservationId,\n reservationDisplayId: s.reservationDisplayId,\n });\n setStatus(\"confirmed\");\n stopPolling();\n break;\n case \"expired\":\n setStatus(\"expired\");\n stopPolling();\n break;\n case \"abandoned\":\n setStatus(\"abandoned\");\n stopPolling();\n break;\n case \"payment_failed_retryable\":\n setStatus(\"failed\");\n stopPolling();\n break;\n case \"not_found\":\n setError(new BowlosApiError(BOWLOS_ERROR_CODES.NOT_FOUND, \"Checkout not found.\", 404));\n setStatus(\"error\");\n stopPolling();\n break;\n case \"pending_payment\":\n default:\n break; // keep waiting\n }\n },\n [stopPolling],\n );\n\n const startHold = useCallback(\n async (args: CreateBookingArgs) => {\n stopPolling();\n setError(null);\n setPaymentIntent(null);\n setReservation(null);\n setStatus(\"holding\");\n try {\n const h = await createBookingCall(client, args);\n setHold(h);\n const rt = typeof h.checkoutRefToken === \"string\" ? h.checkoutRefToken : null;\n refTokenRef.current = rt;\n setRefToken(rt);\n if (!h.requiresPayment) {\n setReservation({\n reservationId: h.reservationId ?? null,\n reservationDisplayId: h.reservationDisplayId ?? null,\n });\n setStatus(\"confirmed\");\n } else if (rt) {\n setStatus(\"held\");\n } else {\n setError(\n new BowlosApiError(\n \"UNSUPPORTED_BOOKING_PATH\",\n \"This booking requires payment but no checkout hold was returned.\",\n 0,\n ),\n );\n setStatus(\"error\");\n }\n } catch (e) {\n if (e instanceof BowlosApiError) setError(e);\n setStatus(\"error\");\n }\n },\n [client, stopPolling],\n );\n\n const preparePayment = useCallback(async (): Promise<PaymentIntentInfo | null> => {\n const rt = refTokenRef.current;\n if (!rt) return null;\n setError(null);\n setStatus(\"preparingPayment\");\n try {\n const pi = await createPaymentIntentCall(client, rt);\n setPaymentIntent(pi);\n setStatus(\"awaitingPayment\");\n return pi;\n } catch (e) {\n if (e instanceof BowlosApiError) setError(e);\n setStatus(\"error\");\n return null;\n }\n }, [client]);\n\n const pollStatus = useCallback(async (): Promise<CheckoutStatusResult | null> => {\n const rt = refTokenRef.current;\n if (!rt) return null;\n try {\n const s = await getCheckoutStatusCall(client, rt);\n applyStatus(s);\n return s;\n } catch (e) {\n if (e instanceof BowlosApiError) setError(e);\n return null;\n }\n }, [client, applyStatus]);\n\n const startPolling = useCallback(\n (intervalMs: number = DEFAULT_POLL_MS) => {\n stopPolling();\n void pollStatus();\n pollRef.current = setInterval(() => {\n void pollStatus();\n }, intervalMs);\n },\n [pollStatus, stopPolling],\n );\n\n const abandon = useCallback(async () => {\n stopPolling();\n const rt = refTokenRef.current;\n if (rt) {\n try {\n await abandonCheckoutCall(client, rt);\n } catch {\n // best-effort: the hold also frees itself on its TTL\n }\n }\n setStatus(\"abandoned\");\n }, [client, stopPolling]);\n\n return {\n status,\n hold,\n refToken,\n paymentIntent,\n reservation,\n requiresPayment: hold ? hold.requiresPayment : null,\n error,\n startHold,\n preparePayment,\n pollStatus,\n startPolling,\n stopPolling,\n abandon,\n reset,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"react.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bowlos/reservations",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "BowlOS Reservations SDK — headless client + React hooks for the Module 14 public API gateway. White-label booking, account, and flash-sale reads for third-party-hosted center sites.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "BowlOS",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"type": "module",
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"files": [
|
|
20
|
-
"dist"
|
|
20
|
+
"dist",
|
|
21
|
+
"templates"
|
|
21
22
|
],
|
|
22
23
|
"main": "./dist/index.cjs",
|
|
23
24
|
"module": "./dist/index.js",
|
|
@@ -46,10 +47,20 @@
|
|
|
46
47
|
"default": "./dist/react.cjs"
|
|
47
48
|
}
|
|
48
49
|
},
|
|
50
|
+
"./components": {
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./dist/components.d.ts",
|
|
53
|
+
"default": "./dist/components.js"
|
|
54
|
+
},
|
|
55
|
+
"require": {
|
|
56
|
+
"types": "./dist/components.d.cts",
|
|
57
|
+
"default": "./dist/components.cjs"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
49
60
|
"./package.json": "./package.json"
|
|
50
61
|
},
|
|
51
62
|
"scripts": {
|
|
52
|
-
"build": "tsup",
|
|
63
|
+
"build": "tsup && node scripts/build-templates.mjs",
|
|
53
64
|
"lint": "echo \"reservations lint deferred until ESLint workspace plumbing lands\"",
|
|
54
65
|
"typecheck": "tsc --noEmit",
|
|
55
66
|
"test": "echo \"reservations tests run via the root vitest config (packages/**/*.test.{ts,tsx})\"",
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Example: a center website on `@bowlos/reservations`
|
|
2
|
+
|
|
3
|
+
A complete, minimal center site built entirely on the **`@bowlos/reservations`** SDK — the
|
|
4
|
+
**agent-build proof**: it's the reference an AI agent (or a developer) follows to stand up a
|
|
5
|
+
white-label booking site against the BowlOS public-API gateway, with **Stripe Connect** payments.
|
|
6
|
+
|
|
7
|
+
It is a **standalone Next.js (App Router) app** — deliberately *not* part of the BowlOS monorepo
|
|
8
|
+
build. You copy this folder, `npm install`, point it at a gateway + key, and run it.
|
|
9
|
+
|
|
10
|
+
## What it demonstrates
|
|
11
|
+
|
|
12
|
+
The full headless funnel, using only the SDK's public API:
|
|
13
|
+
|
|
14
|
+
| Concern | SDK surface used |
|
|
15
|
+
|---|---|
|
|
16
|
+
| Provider / client | `createBowlosClient`, `localStorageTokenStore`, `BowlosProvider` |
|
|
17
|
+
| Live availability + price | `useAvailability`, `useBookingPreview`, `availableUnitCount` |
|
|
18
|
+
| Book → pay → confirm | `useBookingFlow` (`startHold → preparePayment → startPolling`) |
|
|
19
|
+
| **Stripe Connect handoff** | `PaymentIntentInfo.{clientSecret, connectedAccountId}` → Stripe Elements |
|
|
20
|
+
| Auth lifecycle | `useAccount` (`signIn` / `signUp` / `link` / `signOut`) |
|
|
21
|
+
| Account reads | `useMyReservations` (gated with `enabled`) |
|
|
22
|
+
|
|
23
|
+
The **payment handoff** is the key bit (`app/book/checkout-form.tsx`): the SDK never loads
|
|
24
|
+
Stripe.js. `preparePayment()` returns a `PaymentIntentInfo`; the app initializes Stripe.js with the
|
|
25
|
+
**platform publishable key scoped to the operator's connected account** (`stripeAccount:
|
|
26
|
+
connectedAccountId`) and confirms the `clientSecret`. The charge lands on the operator's Stripe
|
|
27
|
+
account, so their name appears on the statement / receipt / wallet sheet.
|
|
28
|
+
|
|
29
|
+
## File map
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
app/
|
|
33
|
+
layout.tsx BowlosProvider (via providers.tsx)
|
|
34
|
+
providers.tsx creates the client once, provides it
|
|
35
|
+
page.tsx home
|
|
36
|
+
book/
|
|
37
|
+
page.tsx the booking funnel (useBookingFlow state machine)
|
|
38
|
+
checkout-form.tsx Stripe Connect payment handoff
|
|
39
|
+
account/
|
|
40
|
+
page.tsx sign in / sign up + link / my reservations
|
|
41
|
+
lib/
|
|
42
|
+
bowlos.ts client config + env + helpers
|
|
43
|
+
env.example the env vars you must set
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Run it
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
cp env.example .env.local # then fill in the values
|
|
50
|
+
npm install
|
|
51
|
+
npm run dev # http://localhost:3000
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Every value in `env.example` is `NEXT_PUBLIC_*` on purpose — the brand API key is a *publishable*
|
|
55
|
+
key, gated by the gateway's per-key **origin allow-list** (like a Stripe publishable key). Add your
|
|
56
|
+
dev + deployed origins to the key's allow-list in the operator admin.
|
|
57
|
+
|
|
58
|
+
Before you start, run the doctor to confirm the wiring:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npx bowlos doctor --api-key "$NEXT_PUBLIC_BOWLOS_API_KEY" --base-url "$NEXT_PUBLIC_BOWLOS_BASE_URL"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## The live proof (closes the readiness gate)
|
|
65
|
+
|
|
66
|
+
This template is the *code* proof. The *live* proof — a real sandbox paid booking — needs a brand
|
|
67
|
+
key and a connected Stripe test account:
|
|
68
|
+
|
|
69
|
+
1. **Mint a brand API key** (operator admin → Super-Admin → API keys). Set its allowed origins to
|
|
70
|
+
include `http://localhost:3000`. Use a **test**-mode key.
|
|
71
|
+
2. **Connect a Test-Brand Stripe account** (Payments → Connect) and make sure it's charges-enabled.
|
|
72
|
+
(Reservation/flash direct charges are already live on the gateway.)
|
|
73
|
+
3. Fill `.env.local` (key, base URL, brand/center/product ids, `pk_test_…` Stripe key) and
|
|
74
|
+
`npm run dev`.
|
|
75
|
+
4. Book a lane → pay with a Stripe **test card** (`4242 4242 4242 4242`, any future expiry / CVC).
|
|
76
|
+
5. Confirm the page reaches **"You're booked"** (the gateway webhook materialized the reservation),
|
|
77
|
+
the reservation shows under **/account**, and — the F7 white-label check — the **operator's**
|
|
78
|
+
business name (not BowlOS/REDcloud) appears on the Stripe receipt + statement descriptor.
|
|
79
|
+
|
|
80
|
+
## Notes
|
|
81
|
+
|
|
82
|
+
- Product/center/brand ids are read from env to keep the proof focused on the funnel. A production
|
|
83
|
+
site would discover them via `listPublicCenters` / `listPublicProducts` (also on the gateway).
|
|
84
|
+
- Versions mirror the BowlOS web app (Next 16.2.4, React 19.2, `@stripe/*` 9.4 / 6.3). Bump as you
|
|
85
|
+
like — `@bowlos/reservations` only requires React as a peer.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { AccountDashboard } from "@bowlos/reservations/components";
|
|
3
|
+
import { BRAND_ID } from "../../lib/bowlos";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The whole account surface as one drop-in component: `<AccountDashboard>` signs
|
|
7
|
+
* the customer in (sign in / create account / finish profile) and then shows
|
|
8
|
+
* their reservations, memberships, loyalty, account credit, and passes — all on
|
|
9
|
+
* the SDK hooks, themed by the `<BowlosTheme>` in `providers.tsx`. Compare
|
|
10
|
+
* `app/book/page.tsx`, which drives the lower-level hooks by hand.
|
|
11
|
+
*/
|
|
12
|
+
export default function AccountPage() {
|
|
13
|
+
return (
|
|
14
|
+
<main>
|
|
15
|
+
<h1>My account</h1>
|
|
16
|
+
<AccountDashboard brandId={BRAND_ID} />
|
|
17
|
+
</main>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo, useState, type FormEvent } from "react";
|
|
3
|
+
import { loadStripe } from "@stripe/stripe-js";
|
|
4
|
+
import { Elements, PaymentElement, useElements, useStripe } from "@stripe/react-stripe-js";
|
|
5
|
+
import type { PaymentIntentInfo } from "@bowlos/reservations";
|
|
6
|
+
import { STRIPE_PUBLISHABLE_KEY } from "../../lib/bowlos";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* THE PAYMENT HANDOFF.
|
|
10
|
+
*
|
|
11
|
+
* The SDK never loads Stripe.js — `useBookingFlow().preparePayment()` returns a
|
|
12
|
+
* `PaymentIntentInfo` and hands it here. We initialize Stripe.js with the
|
|
13
|
+
* PLATFORM publishable key but scoped to the operator's CONNECTED account
|
|
14
|
+
* (`stripeAccount: connectedAccountId`), so the charge is created directly on
|
|
15
|
+
* the operator's Stripe account — their business name lands on the card
|
|
16
|
+
* statement, receipt, and wallet sheet (the white-label requirement). Then we
|
|
17
|
+
* confirm the PaymentIntent with its `clientSecret`.
|
|
18
|
+
*/
|
|
19
|
+
export function CheckoutForm({
|
|
20
|
+
paymentIntent,
|
|
21
|
+
onPaid,
|
|
22
|
+
}: {
|
|
23
|
+
paymentIntent: PaymentIntentInfo;
|
|
24
|
+
onPaid: () => void;
|
|
25
|
+
}) {
|
|
26
|
+
const stripePromise = useMemo(
|
|
27
|
+
() => loadStripe(STRIPE_PUBLISHABLE_KEY, { stripeAccount: paymentIntent.connectedAccountId }),
|
|
28
|
+
[paymentIntent.connectedAccountId],
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Elements
|
|
33
|
+
stripe={stripePromise}
|
|
34
|
+
options={{
|
|
35
|
+
clientSecret: paymentIntent.clientSecret,
|
|
36
|
+
// For saved cards across this operator, also pass the SDK's customer
|
|
37
|
+
// session: customerSessionClientSecret: paymentIntent.customerSessionClientSecret
|
|
38
|
+
}}
|
|
39
|
+
>
|
|
40
|
+
<PayForm onPaid={onPaid} />
|
|
41
|
+
</Elements>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function PayForm({ onPaid }: { onPaid: () => void }) {
|
|
46
|
+
const stripe = useStripe();
|
|
47
|
+
const elements = useElements();
|
|
48
|
+
const [submitting, setSubmitting] = useState(false);
|
|
49
|
+
const [message, setMessage] = useState<string | null>(null);
|
|
50
|
+
|
|
51
|
+
async function handleSubmit(e: FormEvent) {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
if (!stripe || !elements) return;
|
|
54
|
+
setSubmitting(true);
|
|
55
|
+
setMessage(null);
|
|
56
|
+
|
|
57
|
+
// `redirect: "if_required"` keeps the customer on-page for card payments;
|
|
58
|
+
// wallets that need a redirect still work.
|
|
59
|
+
const { error } = await stripe.confirmPayment({ elements, redirect: "if_required" });
|
|
60
|
+
|
|
61
|
+
if (error) {
|
|
62
|
+
setMessage(error.message ?? "Payment failed — please try again.");
|
|
63
|
+
setSubmitting(false);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Paid. The gateway's Stripe webhook materializes the reservation
|
|
68
|
+
// asynchronously, so hand control back so the page can poll for it.
|
|
69
|
+
onPaid();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<form onSubmit={handleSubmit}>
|
|
74
|
+
<PaymentElement />
|
|
75
|
+
<button type="submit" disabled={!stripe || submitting} style={{ marginTop: "1rem" }}>
|
|
76
|
+
{submitting ? "Paying…" : "Pay now"}
|
|
77
|
+
</button>
|
|
78
|
+
{message && (
|
|
79
|
+
<p role="alert" style={{ color: "crimson" }}>
|
|
80
|
+
{message}
|
|
81
|
+
</p>
|
|
82
|
+
)}
|
|
83
|
+
</form>
|
|
84
|
+
);
|
|
85
|
+
}
|