@artisanpack-ui/ecommerce-storefront-react 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +67 -2
- package/dist/Addresses-D3ESHG3L.mjs +27 -0
- package/dist/Addresses-D3ESHG3L.mjs.map +1 -0
- package/dist/CategoryShow-OAGROEMA.mjs +12 -0
- package/dist/CategoryShow-OAGROEMA.mjs.map +1 -0
- package/dist/Claim-CJ4UOAUD.mjs +22 -0
- package/dist/Claim-CJ4UOAUD.mjs.map +1 -0
- package/dist/Confirmation-TLMMBPWS.mjs +20 -0
- package/dist/Confirmation-TLMMBPWS.mjs.map +1 -0
- package/dist/Dashboard-ARXORMTL.mjs +24 -0
- package/dist/Dashboard-ARXORMTL.mjs.map +1 -0
- package/dist/Downloads-CEQBY7JO.mjs +25 -0
- package/dist/Downloads-CEQBY7JO.mjs.map +1 -0
- package/dist/Index-KRR3Q7EJ.mjs +12 -0
- package/dist/Index-KRR3Q7EJ.mjs.map +1 -0
- package/dist/Index-RLQFEBTX.mjs +22 -0
- package/dist/Index-RLQFEBTX.mjs.map +1 -0
- package/dist/Index-WDJYGR5Q.mjs +12 -0
- package/dist/Index-WDJYGR5Q.mjs.map +1 -0
- package/dist/Index-XYU5QLUT.mjs +23 -0
- package/dist/Index-XYU5QLUT.mjs.map +1 -0
- package/dist/Lookup-QNUQKUID.mjs +19 -0
- package/dist/Lookup-QNUQKUID.mjs.map +1 -0
- package/dist/OrderShow-RYTP62YA.mjs +27 -0
- package/dist/OrderShow-RYTP62YA.mjs.map +1 -0
- package/dist/Orders-LZW57GE6.mjs +25 -0
- package/dist/Orders-LZW57GE6.mjs.map +1 -0
- package/dist/Profile-ZAAWFCAL.mjs +25 -0
- package/dist/Profile-ZAAWFCAL.mjs.map +1 -0
- package/dist/Show-LFWUO3KR.mjs +14 -0
- package/dist/Show-LFWUO3KR.mjs.map +1 -0
- package/dist/TagShow-FXKXRGY2.mjs +12 -0
- package/dist/TagShow-FXKXRGY2.mjs.map +1 -0
- package/dist/chunk-5UUNH3EH.mjs +1888 -0
- package/dist/chunk-5UUNH3EH.mjs.map +1 -0
- package/dist/chunk-A3MMQ2RY.mjs +183 -0
- package/dist/chunk-A3MMQ2RY.mjs.map +1 -0
- package/dist/chunk-ABGPTZ3Q.mjs +198 -0
- package/dist/chunk-ABGPTZ3Q.mjs.map +1 -0
- package/dist/chunk-BJ3FJFZQ.mjs +32 -0
- package/dist/chunk-BJ3FJFZQ.mjs.map +1 -0
- package/dist/chunk-BSASRFQ7.mjs +89 -0
- package/dist/chunk-BSASRFQ7.mjs.map +1 -0
- package/dist/chunk-CGCW3555.mjs +148 -0
- package/dist/chunk-CGCW3555.mjs.map +1 -0
- package/dist/chunk-DWR23FJD.mjs +643 -0
- package/dist/chunk-DWR23FJD.mjs.map +1 -0
- package/dist/chunk-ENY3MH2W.mjs +148 -0
- package/dist/chunk-ENY3MH2W.mjs.map +1 -0
- package/dist/chunk-EWJLRWPO.mjs +280 -0
- package/dist/chunk-EWJLRWPO.mjs.map +1 -0
- package/dist/chunk-FL5XL3ET.mjs +212 -0
- package/dist/chunk-FL5XL3ET.mjs.map +1 -0
- package/dist/chunk-FOOP6UK3.mjs +218 -0
- package/dist/chunk-FOOP6UK3.mjs.map +1 -0
- package/dist/chunk-HCC7GTVO.mjs +115 -0
- package/dist/chunk-HCC7GTVO.mjs.map +1 -0
- package/dist/chunk-HXZMY3GE.mjs +2331 -0
- package/dist/chunk-HXZMY3GE.mjs.map +1 -0
- package/dist/chunk-IOL2YQ62.mjs +109 -0
- package/dist/chunk-IOL2YQ62.mjs.map +1 -0
- package/dist/chunk-JH7SFSZA.mjs +104 -0
- package/dist/chunk-JH7SFSZA.mjs.map +1 -0
- package/dist/chunk-JJOPX4PI.mjs +205 -0
- package/dist/chunk-JJOPX4PI.mjs.map +1 -0
- package/dist/chunk-LT3GG7YQ.mjs +32 -0
- package/dist/chunk-LT3GG7YQ.mjs.map +1 -0
- package/dist/chunk-MZFULGDI.mjs +267 -0
- package/dist/chunk-MZFULGDI.mjs.map +1 -0
- package/dist/chunk-O4WPMMSH.mjs +58 -0
- package/dist/chunk-O4WPMMSH.mjs.map +1 -0
- package/dist/chunk-OU3WYFIH.mjs +397 -0
- package/dist/chunk-OU3WYFIH.mjs.map +1 -0
- package/dist/chunk-P3NIV4YG.mjs +998 -0
- package/dist/chunk-P3NIV4YG.mjs.map +1 -0
- package/dist/chunk-PEBBSZ5R.mjs +201 -0
- package/dist/chunk-PEBBSZ5R.mjs.map +1 -0
- package/dist/chunk-T5OWL6EG.mjs +73 -0
- package/dist/chunk-T5OWL6EG.mjs.map +1 -0
- package/dist/chunk-THPUK35U.mjs +132 -0
- package/dist/chunk-THPUK35U.mjs.map +1 -0
- package/dist/chunk-TPOKMH5E.mjs +142 -0
- package/dist/chunk-TPOKMH5E.mjs.map +1 -0
- package/dist/chunk-VX5TEJNU.mjs +1898 -0
- package/dist/chunk-VX5TEJNU.mjs.map +1 -0
- package/dist/chunk-WUL34MB2.mjs +268 -0
- package/dist/chunk-WUL34MB2.mjs.map +1 -0
- package/dist/chunk-WYGOMIZK.mjs +140 -0
- package/dist/chunk-WYGOMIZK.mjs.map +1 -0
- package/dist/chunk-Y2IOBBN7.mjs +127 -0
- package/dist/chunk-Y2IOBBN7.mjs.map +1 -0
- package/dist/chunk-Y5BRPEHA.mjs +54 -0
- package/dist/chunk-Y5BRPEHA.mjs.map +1 -0
- package/dist/index.d.ts +4607 -0
- package/dist/index.mjs +1515 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +112 -4
|
@@ -0,0 +1,1888 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AddressForm
|
|
3
|
+
} from "./chunk-A3MMQ2RY.mjs";
|
|
4
|
+
import {
|
|
5
|
+
Address
|
|
6
|
+
} from "./chunk-O4WPMMSH.mjs";
|
|
7
|
+
import {
|
|
8
|
+
OrderTotals
|
|
9
|
+
} from "./chunk-T5OWL6EG.mjs";
|
|
10
|
+
import {
|
|
11
|
+
Field
|
|
12
|
+
} from "./chunk-WYGOMIZK.mjs";
|
|
13
|
+
import {
|
|
14
|
+
EmptyState,
|
|
15
|
+
Money,
|
|
16
|
+
addBuiltInRegistration,
|
|
17
|
+
cx,
|
|
18
|
+
filled,
|
|
19
|
+
getRegistries,
|
|
20
|
+
postJson,
|
|
21
|
+
usePageErrors
|
|
22
|
+
} from "./chunk-VX5TEJNU.mjs";
|
|
23
|
+
|
|
24
|
+
// src/checkout/payment/usePaymentDriver.ts
|
|
25
|
+
import {
|
|
26
|
+
__,
|
|
27
|
+
paymentFailureMessage
|
|
28
|
+
} from "@artisanpack-ui/ecommerce-storefront-core";
|
|
29
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
30
|
+
function usePaymentDriver(driver, { context, report, failure }) {
|
|
31
|
+
const elementRef = useRef(null);
|
|
32
|
+
const contextRef = useRef(context);
|
|
33
|
+
const busy = useRef(false);
|
|
34
|
+
const [status, setStatus] = useState("idle");
|
|
35
|
+
const [error, setErrorText] = useState(() => failure?.message ?? null);
|
|
36
|
+
const [errorId, setErrorId] = useState(0);
|
|
37
|
+
const [seenFailure, setSeenFailure] = useState(failure);
|
|
38
|
+
const refusal = null !== failure && "driver" !== failure.source;
|
|
39
|
+
if (failure !== seenFailure) {
|
|
40
|
+
setSeenFailure(failure);
|
|
41
|
+
if (refusal) {
|
|
42
|
+
setStatus("idle");
|
|
43
|
+
setErrorText(failure.message);
|
|
44
|
+
setErrorId((id) => id + 1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
contextRef.current = context;
|
|
49
|
+
});
|
|
50
|
+
const showError = useCallback((message) => {
|
|
51
|
+
setErrorText(message);
|
|
52
|
+
setErrorId((id) => id + 1);
|
|
53
|
+
}, []);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
void Promise.resolve(driver.mount(elementRef.current, contextRef.current)).catch(() => {
|
|
56
|
+
showError(paymentFailureMessage(null));
|
|
57
|
+
});
|
|
58
|
+
return () => {
|
|
59
|
+
driver.unmount?.();
|
|
60
|
+
};
|
|
61
|
+
}, [driver, showError]);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (null === failure || "driver" === failure.source) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
busy.current = false;
|
|
67
|
+
driver.error?.(failure.message);
|
|
68
|
+
}, [driver, failure]);
|
|
69
|
+
const pay = useCallback(async () => {
|
|
70
|
+
if (busy.current) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
busy.current = true;
|
|
74
|
+
setStatus("paying");
|
|
75
|
+
setErrorText(null);
|
|
76
|
+
let result;
|
|
77
|
+
try {
|
|
78
|
+
result = await driver.confirm(contextRef.current);
|
|
79
|
+
} catch {
|
|
80
|
+
result = {
|
|
81
|
+
status: "failed",
|
|
82
|
+
message: __("Your payment couldn't be completed. Try again or use another payment method.")
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if ("failed" === result.status) {
|
|
86
|
+
const message = paymentFailureMessage(result.message);
|
|
87
|
+
busy.current = false;
|
|
88
|
+
setStatus("idle");
|
|
89
|
+
showError(message);
|
|
90
|
+
if (false !== result.report) {
|
|
91
|
+
await report({ status: "failed", message });
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
setStatus("placing");
|
|
96
|
+
if ("stayed" === await report(result)) {
|
|
97
|
+
busy.current = false;
|
|
98
|
+
setStatus("idle");
|
|
99
|
+
}
|
|
100
|
+
}, [driver, report, showError]);
|
|
101
|
+
return { elementRef, pay, status, error, errorId };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/checkout/payment/RedirectPayment.tsx
|
|
105
|
+
import {
|
|
106
|
+
__ as __2,
|
|
107
|
+
createRedirectDriver
|
|
108
|
+
} from "@artisanpack-ui/ecommerce-storefront-core";
|
|
109
|
+
import { Alert, Button, Card, Icon } from "@artisanpack-ui/react";
|
|
110
|
+
import { useState as useState2 } from "react";
|
|
111
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
112
|
+
function isHttpUrl(url) {
|
|
113
|
+
return "string" === typeof url && /^https?:\/\//i.test(url);
|
|
114
|
+
}
|
|
115
|
+
function RedirectPayment(props) {
|
|
116
|
+
const [driver] = useState2(createRedirectDriver);
|
|
117
|
+
const { pay, status } = usePaymentDriver(driver, props);
|
|
118
|
+
const { payment } = props.context;
|
|
119
|
+
const label = payment.label;
|
|
120
|
+
return /* @__PURE__ */ jsx("div", { className: "ec-redirect", "data-payment-driver": "redirect", children: isHttpUrl(payment.props.redirectUrl) ? /* @__PURE__ */ jsxs(Card, { className: "ec-redirect__card", children: [
|
|
121
|
+
/* @__PURE__ */ jsxs("div", { className: "ec-redirect__intro", children: [
|
|
122
|
+
/* @__PURE__ */ jsx(Icon, { name: "external-link", variant: "tile" }),
|
|
123
|
+
/* @__PURE__ */ jsxs("div", { className: "ec-redirect__text", children: [
|
|
124
|
+
/* @__PURE__ */ jsx("p", { className: "ec-redirect__title", children: __2("Pay with :gateway", { gateway: label }) }),
|
|
125
|
+
/* @__PURE__ */ jsx("p", { className: "ec-redirect__description", children: __2("You'll finish paying on :gateway's site, then come back here.", {
|
|
126
|
+
gateway: label
|
|
127
|
+
}) })
|
|
128
|
+
] })
|
|
129
|
+
] }),
|
|
130
|
+
/* @__PURE__ */ jsx(
|
|
131
|
+
Button,
|
|
132
|
+
{
|
|
133
|
+
color: "neutral",
|
|
134
|
+
trailingIcon: "arrow-right",
|
|
135
|
+
className: "ec-redirect__continue",
|
|
136
|
+
disabled: "idle" !== status,
|
|
137
|
+
onClick: () => void pay(),
|
|
138
|
+
"data-payment-redirect": "",
|
|
139
|
+
children: __2("Continue to :gateway", { gateway: label })
|
|
140
|
+
}
|
|
141
|
+
)
|
|
142
|
+
] }) : /* @__PURE__ */ jsx(
|
|
143
|
+
Alert,
|
|
144
|
+
{
|
|
145
|
+
color: "warning",
|
|
146
|
+
icon: "triangle-alert",
|
|
147
|
+
title: __2("This payment method isn't available."),
|
|
148
|
+
"data-payment-unavailable": ""
|
|
149
|
+
}
|
|
150
|
+
) });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/checkout/payment/stripeDriver.ts
|
|
154
|
+
import {
|
|
155
|
+
__ as __3,
|
|
156
|
+
paymentFailureMessage as paymentFailureMessage2
|
|
157
|
+
} from "@artisanpack-ui/ecommerce-storefront-core";
|
|
158
|
+
var defaultLoader = async (publishableKey, options) => {
|
|
159
|
+
const { loadStripe } = await import("@stripe/stripe-js");
|
|
160
|
+
return loadStripe(publishableKey, options);
|
|
161
|
+
};
|
|
162
|
+
function toRgb(value) {
|
|
163
|
+
if ("" === value) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
let context = null;
|
|
167
|
+
try {
|
|
168
|
+
context = document.createElement("canvas").getContext("2d", { willReadFrequently: true });
|
|
169
|
+
} catch {
|
|
170
|
+
context = null;
|
|
171
|
+
}
|
|
172
|
+
if (null === context || void 0 === context) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
context.clearRect(0, 0, 1, 1);
|
|
176
|
+
context.fillStyle = value;
|
|
177
|
+
context.fillRect(0, 0, 1, 1);
|
|
178
|
+
const [red, green, blue] = context.getImageData(0, 0, 1, 1).data;
|
|
179
|
+
return `rgb(${red}, ${green}, ${blue})`;
|
|
180
|
+
}
|
|
181
|
+
function declared(declarations) {
|
|
182
|
+
return Object.fromEntries(
|
|
183
|
+
Object.entries(declarations).filter(
|
|
184
|
+
(entry) => "string" === typeof entry[1] && "" !== entry[1]
|
|
185
|
+
)
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
function stripeAppearance(root, custom) {
|
|
189
|
+
const styles = getComputedStyle(root);
|
|
190
|
+
const token = (name) => styles.getPropertyValue(name).trim();
|
|
191
|
+
const color = (name) => toRgb(token(name));
|
|
192
|
+
const px = (name, fallback) => Number.parseFloat(token(name)) || fallback;
|
|
193
|
+
const variables = declared({
|
|
194
|
+
colorPrimary: color("--apui-color-primary"),
|
|
195
|
+
colorBackground: color("--apui-surface-default"),
|
|
196
|
+
colorText: color("--apui-text-default"),
|
|
197
|
+
colorTextSecondary: color("--apui-text-muted"),
|
|
198
|
+
colorTextPlaceholder: color("--apui-text-subtle"),
|
|
199
|
+
colorDanger: color("--apui-color-error-text"),
|
|
200
|
+
borderRadius: token("--apui-radius-field") || null,
|
|
201
|
+
fontFamily: styles.fontFamily || null
|
|
202
|
+
});
|
|
203
|
+
const border = color("--apui-border-default");
|
|
204
|
+
const ring = color("--apui-focus-ring-color");
|
|
205
|
+
const ringOffset = color("--apui-focus-ring-offset-color") ?? variables.colorBackground ?? null;
|
|
206
|
+
const offset = px("--apui-focus-ring-offset", 2);
|
|
207
|
+
const spread = offset + px("--apui-focus-ring-width", 2);
|
|
208
|
+
const rules = Object.fromEntries(
|
|
209
|
+
Object.entries({
|
|
210
|
+
".Input": declared({
|
|
211
|
+
border: null === border ? null : `${px("--apui-border-width", 1)}px solid ${border}`,
|
|
212
|
+
boxShadow: "none"
|
|
213
|
+
}),
|
|
214
|
+
".Input:hover": declared({ borderColor: color("--apui-border-strong") }),
|
|
215
|
+
// A transparent outline is invisible until forced colors paints it,
|
|
216
|
+
// where the box-shadow ring is dropped.
|
|
217
|
+
".Input:focus": declared({
|
|
218
|
+
outline: `${px("--apui-focus-ring-width", 2)}px solid transparent`,
|
|
219
|
+
boxShadow: null === ring ? null : `0 0 0 ${offset}px ${ringOffset ?? "transparent"}, 0 0 0 ${spread}px ${ring}`
|
|
220
|
+
}),
|
|
221
|
+
".Label": declared({
|
|
222
|
+
color: variables.colorText,
|
|
223
|
+
fontWeight: token("--apui-font-weight-medium")
|
|
224
|
+
}),
|
|
225
|
+
".Error": declared({ color: variables.colorDanger })
|
|
226
|
+
}).filter(([, declarations]) => Object.keys(declarations).length > 0)
|
|
227
|
+
);
|
|
228
|
+
const customVariables = custom.variables ?? {};
|
|
229
|
+
const customRules = custom.rules ?? {};
|
|
230
|
+
return {
|
|
231
|
+
theme: "stripe",
|
|
232
|
+
...custom,
|
|
233
|
+
variables: { ...variables, ...customVariables },
|
|
234
|
+
rules: { ...rules, ...customRules }
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function createStripePaymentElementDriver(callbacks, loader = defaultLoader) {
|
|
238
|
+
const loadFailed = __3(
|
|
239
|
+
"The payment form couldn't load. Check your connection and reload the page."
|
|
240
|
+
);
|
|
241
|
+
let stripe = null;
|
|
242
|
+
let elements = null;
|
|
243
|
+
let element = null;
|
|
244
|
+
let teardown = null;
|
|
245
|
+
let mounts = 0;
|
|
246
|
+
let current = 0;
|
|
247
|
+
return {
|
|
248
|
+
async mount(root, { payment }) {
|
|
249
|
+
const props = payment.props;
|
|
250
|
+
const mountNumber = ++mounts;
|
|
251
|
+
current = mountNumber;
|
|
252
|
+
if (null === root || !props.available) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
try {
|
|
256
|
+
const locale = props.locale || "auto";
|
|
257
|
+
const loaded = await loader(props.publishableKey, { locale });
|
|
258
|
+
if (mountNumber !== current) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (null === loaded) {
|
|
262
|
+
callbacks.onLoadError(loadFailed);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
stripe = loaded;
|
|
266
|
+
elements = loaded.elements({
|
|
267
|
+
clientSecret: props.clientSecret,
|
|
268
|
+
appearance: stripeAppearance(root, props.appearance),
|
|
269
|
+
locale
|
|
270
|
+
});
|
|
271
|
+
element = elements.create("payment");
|
|
272
|
+
element.on("ready", () => callbacks.onReady());
|
|
273
|
+
element.on("loaderror", (event) => {
|
|
274
|
+
callbacks.onLoadError(event?.error?.message || loadFailed);
|
|
275
|
+
});
|
|
276
|
+
element.mount(root);
|
|
277
|
+
const retheme = () => {
|
|
278
|
+
elements?.update({ appearance: stripeAppearance(root, props.appearance) });
|
|
279
|
+
};
|
|
280
|
+
const scheme = window.matchMedia?.("(prefers-color-scheme: dark)");
|
|
281
|
+
const observer = "undefined" !== typeof MutationObserver ? new MutationObserver(retheme) : null;
|
|
282
|
+
scheme?.addEventListener?.("change", retheme);
|
|
283
|
+
observer?.observe(document.documentElement, {
|
|
284
|
+
attributes: true,
|
|
285
|
+
attributeFilter: ["class", "data-theme"]
|
|
286
|
+
});
|
|
287
|
+
teardown = () => {
|
|
288
|
+
observer?.disconnect();
|
|
289
|
+
scheme?.removeEventListener?.("change", retheme);
|
|
290
|
+
};
|
|
291
|
+
} catch {
|
|
292
|
+
if (mountNumber === current) {
|
|
293
|
+
callbacks.onLoadError(loadFailed);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
async confirm(context) {
|
|
298
|
+
if (null === stripe || null === elements) {
|
|
299
|
+
return { status: "failed", message: paymentFailureMessage2(null) };
|
|
300
|
+
}
|
|
301
|
+
if (true !== await context.stillPayable()) {
|
|
302
|
+
return {
|
|
303
|
+
status: "failed",
|
|
304
|
+
message: __3(
|
|
305
|
+
"Your order changed, so we're updating the payment form. Check the new total, then pay."
|
|
306
|
+
)
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
const returnUrl = context.returnUrl ?? context.payment.props.returnUrl;
|
|
310
|
+
const { error } = await stripe.confirmPayment({
|
|
311
|
+
elements,
|
|
312
|
+
...null !== returnUrl ? { confirmParams: { return_url: returnUrl } } : {},
|
|
313
|
+
redirect: "if_required"
|
|
314
|
+
});
|
|
315
|
+
if (void 0 !== error) {
|
|
316
|
+
return {
|
|
317
|
+
status: "failed",
|
|
318
|
+
message: paymentFailureMessage2(error.message),
|
|
319
|
+
..."validation_error" === error.type ? { report: false } : {}
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return { status: "confirmed", reference: context.payment.reference };
|
|
323
|
+
},
|
|
324
|
+
unmount() {
|
|
325
|
+
current = 0;
|
|
326
|
+
teardown?.();
|
|
327
|
+
teardown = null;
|
|
328
|
+
element?.destroy();
|
|
329
|
+
element = null;
|
|
330
|
+
elements = null;
|
|
331
|
+
stripe = null;
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// src/checkout/payment/StripePayment.tsx
|
|
337
|
+
import {
|
|
338
|
+
__ as __4
|
|
339
|
+
} from "@artisanpack-ui/ecommerce-storefront-core";
|
|
340
|
+
import { Alert as Alert2, Button as Button2, Card as Card2, Icon as Icon2, Loading, Skeleton } from "@artisanpack-ui/react";
|
|
341
|
+
import { useState as useState3 } from "react";
|
|
342
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
343
|
+
function StripePayment({ loader, ...props }) {
|
|
344
|
+
const [loading, setLoading] = useState3(true);
|
|
345
|
+
const [ready, setReady] = useState3(false);
|
|
346
|
+
const [loadError, setLoadError] = useState3(null);
|
|
347
|
+
const [driver] = useState3(
|
|
348
|
+
() => createStripePaymentElementDriver(
|
|
349
|
+
{
|
|
350
|
+
onReady: () => {
|
|
351
|
+
setLoading(false);
|
|
352
|
+
setReady(true);
|
|
353
|
+
},
|
|
354
|
+
onLoadError: (message) => {
|
|
355
|
+
setLoading(false);
|
|
356
|
+
setLoadError(message);
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
loader
|
|
360
|
+
)
|
|
361
|
+
);
|
|
362
|
+
const { elementRef, pay, status, error, errorId } = usePaymentDriver(driver, props);
|
|
363
|
+
const shownError = error ?? loadError;
|
|
364
|
+
if (!props.context.payment.props.available) {
|
|
365
|
+
return /* @__PURE__ */ jsx2("div", { className: "ec-stripe", "data-payment-driver": "stripe-payment-element", children: /* @__PURE__ */ jsx2(
|
|
366
|
+
Alert2,
|
|
367
|
+
{
|
|
368
|
+
color: "warning",
|
|
369
|
+
icon: "triangle-alert",
|
|
370
|
+
title: __4("This payment method isn't available."),
|
|
371
|
+
"data-payment-unavailable": ""
|
|
372
|
+
}
|
|
373
|
+
) });
|
|
374
|
+
}
|
|
375
|
+
return /* @__PURE__ */ jsx2("div", { className: "ec-stripe", "data-payment-driver": "stripe-payment-element", children: /* @__PURE__ */ jsx2(Card2, { className: "ec-stripe__card", children: /* @__PURE__ */ jsxs2("div", { className: "ec-stripe__form", children: [
|
|
376
|
+
/* @__PURE__ */ jsxs2("div", { className: "ec-stripe__field", "data-loading": loading ? "" : void 0, children: [
|
|
377
|
+
/* @__PURE__ */ jsxs2("div", { className: "ec-stripe__loading", hidden: !loading, "data-stripe-loading": "", children: [
|
|
378
|
+
/* @__PURE__ */ jsxs2("div", { className: "ec-stripe__skeletons", "aria-hidden": "true", children: [
|
|
379
|
+
/* @__PURE__ */ jsx2(Skeleton, { className: "ec-stripe__skeleton" }),
|
|
380
|
+
/* @__PURE__ */ jsxs2("div", { className: "ec-stripe__skeleton-row", children: [
|
|
381
|
+
/* @__PURE__ */ jsx2(Skeleton, { className: "ec-stripe__skeleton" }),
|
|
382
|
+
/* @__PURE__ */ jsx2(Skeleton, { className: "ec-stripe__skeleton" })
|
|
383
|
+
] })
|
|
384
|
+
] }),
|
|
385
|
+
/* @__PURE__ */ jsx2(Loading, { overlay: true, delay: 0, children: __4("Loading the payment form\u2026") })
|
|
386
|
+
] }),
|
|
387
|
+
/* @__PURE__ */ jsx2("div", { ref: elementRef, className: "ec-stripe__element", "data-stripe-element": "" })
|
|
388
|
+
] }),
|
|
389
|
+
/* @__PURE__ */ jsx2(
|
|
390
|
+
"p",
|
|
391
|
+
{
|
|
392
|
+
className: "ec-stripe__error",
|
|
393
|
+
role: "alert",
|
|
394
|
+
"aria-live": "assertive",
|
|
395
|
+
"data-stripe-error": "",
|
|
396
|
+
children: shownError
|
|
397
|
+
},
|
|
398
|
+
`stripe-error-${errorId}`
|
|
399
|
+
),
|
|
400
|
+
/* @__PURE__ */ jsxs2("p", { className: "ec-stripe__reassurance", children: [
|
|
401
|
+
/* @__PURE__ */ jsx2(Icon2, { name: "shield" }),
|
|
402
|
+
/* @__PURE__ */ jsx2("span", { children: __4("Your card details go straight to Stripe. This store never sees or stores them.") })
|
|
403
|
+
] }),
|
|
404
|
+
/* @__PURE__ */ jsx2(
|
|
405
|
+
Button2,
|
|
406
|
+
{
|
|
407
|
+
color: "primary",
|
|
408
|
+
leadingIcon: "lock",
|
|
409
|
+
className: "ec-stripe__pay",
|
|
410
|
+
disabled: !ready || "idle" !== status,
|
|
411
|
+
"aria-busy": "placing" === status ? "true" : void 0,
|
|
412
|
+
onClick: () => void pay(),
|
|
413
|
+
"data-stripe-pay": "",
|
|
414
|
+
children: /* @__PURE__ */ jsx2("span", { "data-stripe-pay-label": "", children: "placing" === status ? __4("Placing your order\u2026") : __4("Pay now") })
|
|
415
|
+
}
|
|
416
|
+
)
|
|
417
|
+
] }) }) });
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// src/checkout/payment/registerPaymentDrivers.ts
|
|
421
|
+
var CORE_PAYMENT_DRIVERS = {
|
|
422
|
+
"stripe-payment-element": StripePayment,
|
|
423
|
+
redirect: RedirectPayment
|
|
424
|
+
};
|
|
425
|
+
var registered = false;
|
|
426
|
+
function registerPaymentDrivers() {
|
|
427
|
+
if (registered) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
registered = true;
|
|
431
|
+
addBuiltInRegistration((registries) => {
|
|
432
|
+
let position = 10;
|
|
433
|
+
for (const [key, component] of Object.entries(CORE_PAYMENT_DRIVERS)) {
|
|
434
|
+
registries.paymentDrivers.register(key, component, { position });
|
|
435
|
+
position += 10;
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// src/checkout/checkoutState.tsx
|
|
441
|
+
import { router } from "@inertiajs/react";
|
|
442
|
+
import { createContext, useCallback as useCallback2, useContext, useState as useState4 } from "react";
|
|
443
|
+
var CheckoutContext = createContext(null);
|
|
444
|
+
var focusRequested = false;
|
|
445
|
+
function requestStepFocus() {
|
|
446
|
+
focusRequested = true;
|
|
447
|
+
}
|
|
448
|
+
function takeStepFocus() {
|
|
449
|
+
const requested = focusRequested;
|
|
450
|
+
focusRequested = false;
|
|
451
|
+
return requested;
|
|
452
|
+
}
|
|
453
|
+
function stepUrl(urls, step) {
|
|
454
|
+
if (null === urls.checkout) {
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
const base = "undefined" !== typeof window ? window.location.href : "http://localhost";
|
|
458
|
+
const url = new URL(urls.checkout, base);
|
|
459
|
+
url.searchParams.set("step", step);
|
|
460
|
+
return url.origin === new URL(base).origin ? url.pathname + url.search : url.toString();
|
|
461
|
+
}
|
|
462
|
+
function useCheckoutState(props, pageErrors) {
|
|
463
|
+
const [processing, setProcessing] = useState4(null);
|
|
464
|
+
const [errorRound, setErrorRound] = useState4(0);
|
|
465
|
+
const [paymentFailure, setPaymentFailure] = useState4(null);
|
|
466
|
+
const errors = { ...props.problems, ...pageErrors };
|
|
467
|
+
const post = useCallback2(
|
|
468
|
+
(url, data, mode = "step", callbacks = {}) => {
|
|
469
|
+
if (null === url) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
router.post(url, data, {
|
|
473
|
+
preserveScroll: true,
|
|
474
|
+
preserveState: "keep" === mode ? true : "errors",
|
|
475
|
+
onStart: () => setProcessing(url),
|
|
476
|
+
onFinish: () => {
|
|
477
|
+
setProcessing(null);
|
|
478
|
+
callbacks.onFinish?.();
|
|
479
|
+
},
|
|
480
|
+
onSuccess: () => {
|
|
481
|
+
if ("step" === mode) {
|
|
482
|
+
requestStepFocus();
|
|
483
|
+
}
|
|
484
|
+
callbacks.onSuccess?.();
|
|
485
|
+
},
|
|
486
|
+
onError: (next) => {
|
|
487
|
+
setErrorRound((round) => round + 1);
|
|
488
|
+
callbacks.onError?.(next);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
},
|
|
492
|
+
[]
|
|
493
|
+
);
|
|
494
|
+
const goTo = useCallback2(
|
|
495
|
+
(step) => {
|
|
496
|
+
const url = stepUrl(props.urls, step);
|
|
497
|
+
if (null === url) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
requestStepFocus();
|
|
501
|
+
router.get(url, {}, { preserveScroll: true });
|
|
502
|
+
},
|
|
503
|
+
[props.urls]
|
|
504
|
+
);
|
|
505
|
+
const reportPaymentFailure = useCallback2((message, source) => {
|
|
506
|
+
setPaymentFailure((previous) => ({ id: (previous?.id ?? 0) + 1, message, source }));
|
|
507
|
+
}, []);
|
|
508
|
+
const clearPaymentFailure = useCallback2(() => setPaymentFailure(null), []);
|
|
509
|
+
return {
|
|
510
|
+
props,
|
|
511
|
+
errors,
|
|
512
|
+
post,
|
|
513
|
+
goTo,
|
|
514
|
+
processing,
|
|
515
|
+
errorRound,
|
|
516
|
+
paymentFailure,
|
|
517
|
+
reportPaymentFailure,
|
|
518
|
+
clearPaymentFailure
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
var CheckoutProvider = CheckoutContext.Provider;
|
|
522
|
+
function useCheckout() {
|
|
523
|
+
const value = useContext(CheckoutContext);
|
|
524
|
+
if (null === value) {
|
|
525
|
+
throw new Error("useCheckout() must be used inside the checkout.");
|
|
526
|
+
}
|
|
527
|
+
return value;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// src/checkout/CheckoutErrorSummary.tsx
|
|
531
|
+
import { __ as __5, trans_choice } from "@artisanpack-ui/ecommerce-storefront-core";
|
|
532
|
+
import { ValidationSummary } from "@artisanpack-ui/react";
|
|
533
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
534
|
+
function focusField(event) {
|
|
535
|
+
if (event.defaultPrevented) {
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
const link = event.target.closest("a");
|
|
539
|
+
if (null === link || "" === link.hash) {
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
const key = decodeURIComponent(link.hash.slice(1));
|
|
543
|
+
const field = [...document.querySelectorAll("[data-field-key], [data-field]")].find(
|
|
544
|
+
(element) => (element.dataset.fieldKey ?? element.dataset.field) === key
|
|
545
|
+
);
|
|
546
|
+
const control = field?.querySelector("input:not([type=hidden]), select, textarea");
|
|
547
|
+
if (void 0 !== control && null !== control) {
|
|
548
|
+
event.preventDefault();
|
|
549
|
+
control.focus();
|
|
550
|
+
control.scrollIntoView?.({ block: "center" });
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
function CheckoutErrorSummary() {
|
|
554
|
+
const { errors, errorRound, props } = useCheckout();
|
|
555
|
+
const entries = Object.entries(errors).filter(([, message]) => "" !== message);
|
|
556
|
+
if (0 === entries.length) {
|
|
557
|
+
return null;
|
|
558
|
+
}
|
|
559
|
+
const labelled = Object.fromEntries(
|
|
560
|
+
entries.map(([field, message]) => {
|
|
561
|
+
const label = props.errorLabels[field];
|
|
562
|
+
return [
|
|
563
|
+
field,
|
|
564
|
+
void 0 === label ? message : __5(":field: :message", { field: label, message })
|
|
565
|
+
];
|
|
566
|
+
})
|
|
567
|
+
);
|
|
568
|
+
return /* @__PURE__ */ jsx3(
|
|
569
|
+
ValidationSummary,
|
|
570
|
+
{
|
|
571
|
+
errors: labelled,
|
|
572
|
+
title: trans_choice(
|
|
573
|
+
"There is :count problem to fix:|There are :count problems to fix:",
|
|
574
|
+
entries.length,
|
|
575
|
+
{ count: entries.length }
|
|
576
|
+
),
|
|
577
|
+
id: "ec-checkout-errors",
|
|
578
|
+
className: "ec-error-summary",
|
|
579
|
+
onClick: focusField,
|
|
580
|
+
"data-checkout-errors": ""
|
|
581
|
+
},
|
|
582
|
+
`checkout-errors-${errorRound}`
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// src/checkout/CheckoutOrderSummary.tsx
|
|
587
|
+
import { __ as __6 } from "@artisanpack-ui/ecommerce-storefront-core";
|
|
588
|
+
import { Icon as Icon3, Link } from "@artisanpack-ui/react";
|
|
589
|
+
import { useState as useState5 } from "react";
|
|
590
|
+
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
591
|
+
function CheckoutOrderSummary({
|
|
592
|
+
summary,
|
|
593
|
+
cartUrl
|
|
594
|
+
}) {
|
|
595
|
+
const [open, setOpen] = useState5(false);
|
|
596
|
+
const totals = summary?.totals ?? null;
|
|
597
|
+
const lines = summary?.lines ?? [];
|
|
598
|
+
return /* @__PURE__ */ jsxs3(
|
|
599
|
+
"section",
|
|
600
|
+
{
|
|
601
|
+
className: "apui-card ec-checkout-summary",
|
|
602
|
+
"data-surface": "default",
|
|
603
|
+
"aria-labelledby": "ec-checkout-summary-heading",
|
|
604
|
+
"data-checkout-summary": "",
|
|
605
|
+
children: [
|
|
606
|
+
/* @__PURE__ */ jsxs3(
|
|
607
|
+
"button",
|
|
608
|
+
{
|
|
609
|
+
type: "button",
|
|
610
|
+
className: "ec-checkout-summary__toggle",
|
|
611
|
+
"aria-expanded": open ? "true" : "false",
|
|
612
|
+
"aria-controls": "ec-checkout-summary-body",
|
|
613
|
+
onClick: () => setOpen((current) => !current),
|
|
614
|
+
"data-checkout-summary-toggle": "",
|
|
615
|
+
children: [
|
|
616
|
+
/* @__PURE__ */ jsxs3("span", { className: "ec-checkout-summary__toggle-label", children: [
|
|
617
|
+
/* @__PURE__ */ jsx4(Icon3, { name: "shopping-bag", "aria-hidden": "true" }),
|
|
618
|
+
/* @__PURE__ */ jsx4("span", { children: open ? __6("Hide order summary") : __6("Show order summary") })
|
|
619
|
+
] }),
|
|
620
|
+
null !== totals ? /* @__PURE__ */ jsx4(Money, { money: totals.total, className: "ec-checkout-summary__toggle-total" }) : null
|
|
621
|
+
]
|
|
622
|
+
}
|
|
623
|
+
),
|
|
624
|
+
/* @__PURE__ */ jsxs3(
|
|
625
|
+
"div",
|
|
626
|
+
{
|
|
627
|
+
id: "ec-checkout-summary-body",
|
|
628
|
+
className: cx("ec-checkout-summary__body", open && "is-open"),
|
|
629
|
+
"data-checkout-summary-body": "",
|
|
630
|
+
children: [
|
|
631
|
+
/* @__PURE__ */ jsxs3("div", { className: "ec-checkout-summary__header", children: [
|
|
632
|
+
/* @__PURE__ */ jsx4("h2", { id: "ec-checkout-summary-heading", className: "ec-checkout-summary__title", children: __6("Order summary") }),
|
|
633
|
+
null !== cartUrl ? /* @__PURE__ */ jsx4(Link, { href: cartUrl, "data-checkout-edit-cart": "", children: __6("Edit cart") }) : null
|
|
634
|
+
] }),
|
|
635
|
+
/* @__PURE__ */ jsx4("ul", { role: "list", className: "ec-checkout-summary__lines", "data-checkout-lines": "", children: lines.map((line) => /* @__PURE__ */ jsxs3("li", { className: "ec-checkout-summary__line", "data-checkout-line": line.id, children: [
|
|
636
|
+
/* @__PURE__ */ jsxs3("span", { className: "ec-checkout-summary__thumb", children: [
|
|
637
|
+
null !== line.image ? /* @__PURE__ */ jsx4(
|
|
638
|
+
"img",
|
|
639
|
+
{
|
|
640
|
+
src: line.image.url,
|
|
641
|
+
srcSet: line.image.srcset ?? void 0,
|
|
642
|
+
sizes: null !== line.image.srcset ? "56px" : void 0,
|
|
643
|
+
width: 56,
|
|
644
|
+
height: 56,
|
|
645
|
+
alt: "",
|
|
646
|
+
loading: "lazy",
|
|
647
|
+
decoding: "async"
|
|
648
|
+
}
|
|
649
|
+
) : /* @__PURE__ */ jsx4(Icon3, { name: "image", "aria-hidden": "true" }),
|
|
650
|
+
/* @__PURE__ */ jsx4("span", { className: "ec-checkout-summary__quantity", "aria-hidden": "true", children: line.quantity })
|
|
651
|
+
] }),
|
|
652
|
+
/* @__PURE__ */ jsxs3("span", { className: "ec-checkout-summary__details", children: [
|
|
653
|
+
/* @__PURE__ */ jsxs3("span", { className: "ec-checkout-summary__name", children: [
|
|
654
|
+
line.name,
|
|
655
|
+
" ",
|
|
656
|
+
/* @__PURE__ */ jsx4("span", { className: "apui-sr-only", children: __6("\xD7 :quantity", { quantity: line.quantity }) })
|
|
657
|
+
] }),
|
|
658
|
+
line.free ? /* @__PURE__ */ jsx4("span", { className: "ec-checkout-summary__meta", children: __6("Free gift") }) : line.options.length > 0 ? /* @__PURE__ */ jsx4("span", { className: "ec-checkout-summary__meta", children: line.options.join(" \xB7 ") }) : null
|
|
659
|
+
] }),
|
|
660
|
+
/* @__PURE__ */ jsx4("span", { className: "ec-checkout-summary__amount", children: line.free ? __6("Free") : /* @__PURE__ */ jsx4(Money, { money: line.total }) })
|
|
661
|
+
] }, line.id)) }),
|
|
662
|
+
null !== totals ? /* @__PURE__ */ jsx4(
|
|
663
|
+
OrderTotals,
|
|
664
|
+
{
|
|
665
|
+
totals,
|
|
666
|
+
shippingPending: __6("Calculated at the shipping step"),
|
|
667
|
+
taxPending: __6("Calculated once we have your address")
|
|
668
|
+
}
|
|
669
|
+
) : null
|
|
670
|
+
]
|
|
671
|
+
}
|
|
672
|
+
)
|
|
673
|
+
]
|
|
674
|
+
}
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// src/checkout/addressLines.ts
|
|
679
|
+
function part(values, field) {
|
|
680
|
+
return (values[field] ?? "").trim();
|
|
681
|
+
}
|
|
682
|
+
function optionLabel(options, value) {
|
|
683
|
+
const upper = value.toUpperCase();
|
|
684
|
+
return options.find((option) => option.value.toUpperCase() === upper)?.label ?? value;
|
|
685
|
+
}
|
|
686
|
+
function regionText(values, form) {
|
|
687
|
+
const region = part(values, "region");
|
|
688
|
+
if ("" !== region) {
|
|
689
|
+
return region;
|
|
690
|
+
}
|
|
691
|
+
const code = part(values, "region_code");
|
|
692
|
+
const country = part(values, "country_code").toUpperCase();
|
|
693
|
+
if ("" === code || null === form || (form.format.country ?? "").toUpperCase() !== country) {
|
|
694
|
+
return code;
|
|
695
|
+
}
|
|
696
|
+
return optionLabel(form.format.regions, code);
|
|
697
|
+
}
|
|
698
|
+
function addressLines(values, form = null) {
|
|
699
|
+
const name = [part(values, "first_name"), part(values, "last_name")].filter(Boolean).join(" ");
|
|
700
|
+
const locality = [
|
|
701
|
+
[part(values, "city"), regionText(values, form)].filter(Boolean).join(", "),
|
|
702
|
+
part(values, "postal_code")
|
|
703
|
+
].filter(Boolean).join(" ");
|
|
704
|
+
const country = part(values, "country_code");
|
|
705
|
+
return [
|
|
706
|
+
name,
|
|
707
|
+
part(values, "company"),
|
|
708
|
+
part(values, "address1"),
|
|
709
|
+
part(values, "address2"),
|
|
710
|
+
locality,
|
|
711
|
+
"" === country || null === form ? country : optionLabel(form.countries, country)
|
|
712
|
+
].filter((line) => "" !== line);
|
|
713
|
+
}
|
|
714
|
+
function shipToLine(values) {
|
|
715
|
+
const region = part(values, "region_code") || part(values, "region");
|
|
716
|
+
return [
|
|
717
|
+
part(values, "address1"),
|
|
718
|
+
part(values, "city"),
|
|
719
|
+
`${region} ${part(values, "postal_code")}`.trim()
|
|
720
|
+
].filter((segment) => "" !== segment).join(", ");
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// src/checkout/CheckoutStepSummary.tsx
|
|
724
|
+
import { __ as __7 } from "@artisanpack-ui/ecommerce-storefront-core";
|
|
725
|
+
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
726
|
+
function CheckoutStepSummary({ step }) {
|
|
727
|
+
const { props } = useCheckout();
|
|
728
|
+
const { forms, address, shipping, review, payment } = props;
|
|
729
|
+
switch (step) {
|
|
730
|
+
case "contact":
|
|
731
|
+
return /* @__PURE__ */ jsx5("p", { className: "ec-step-summary__text", children: forms?.email ?? "" });
|
|
732
|
+
case "address":
|
|
733
|
+
return /* @__PURE__ */ jsxs4("div", { className: "ec-step-summary__addresses", children: [
|
|
734
|
+
address.ships && null !== forms ? /* @__PURE__ */ jsxs4("div", { children: [
|
|
735
|
+
/* @__PURE__ */ jsx5("p", { className: "ec-step-summary__label", children: __7("Ship to") }),
|
|
736
|
+
/* @__PURE__ */ jsx5(Address, { lines: addressLines(forms.shipping, address.shippingForm) })
|
|
737
|
+
] }) : null,
|
|
738
|
+
/* @__PURE__ */ jsxs4("div", { children: [
|
|
739
|
+
/* @__PURE__ */ jsx5("p", { className: "ec-step-summary__label", children: __7("Bill to") }),
|
|
740
|
+
null !== forms && (!address.ships || !forms.billingSameAsShipping) ? /* @__PURE__ */ jsx5(Address, { lines: addressLines(forms.billing, address.billingForm) }) : /* @__PURE__ */ jsx5("p", { className: "ec-step-summary__text", children: __7("Same as shipping") })
|
|
741
|
+
] })
|
|
742
|
+
] });
|
|
743
|
+
case "shipping": {
|
|
744
|
+
if (null === shipping.chosen) {
|
|
745
|
+
return null;
|
|
746
|
+
}
|
|
747
|
+
const charged = props.summary?.totals?.shipping ?? null;
|
|
748
|
+
return /* @__PURE__ */ jsxs4("p", { className: "ec-step-summary__text", children: [
|
|
749
|
+
shipping.chosen.label,
|
|
750
|
+
" \xB7",
|
|
751
|
+
" ",
|
|
752
|
+
null !== charged && "chosen" === charged.state && (charged.amount.amount ?? 0) > 0 ? /* @__PURE__ */ jsx5(Money, { money: charged.amount }) : __7("Free")
|
|
753
|
+
] });
|
|
754
|
+
}
|
|
755
|
+
case "review": {
|
|
756
|
+
const parts = [
|
|
757
|
+
review.summary?.terms ? __7("Terms accepted") : null,
|
|
758
|
+
review.summary?.account ? __7("Account will be created") : null,
|
|
759
|
+
review.summary?.note ? __7("Note added") : null
|
|
760
|
+
].filter((part2) => null !== part2);
|
|
761
|
+
return /* @__PURE__ */ jsx5("p", { className: "ec-step-summary__text", children: 0 === parts.length ? __7("Done") : parts.join(" \xB7 ") });
|
|
762
|
+
}
|
|
763
|
+
case "payment":
|
|
764
|
+
return /* @__PURE__ */ jsx5("p", { className: "ec-step-summary__text", children: payment.required ? payment.gatewayLabel ?? __7("Payment confirmed") : __7("No payment needed") });
|
|
765
|
+
default:
|
|
766
|
+
return /* @__PURE__ */ jsx5("p", { className: "ec-step-summary__text", children: __7("Done") });
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// src/checkout/payment/PaymentDriverHost.tsx
|
|
771
|
+
import {
|
|
772
|
+
paymentFailureMessage as paymentFailureMessage3
|
|
773
|
+
} from "@artisanpack-ui/ecommerce-storefront-core";
|
|
774
|
+
import { router as router2 } from "@inertiajs/react";
|
|
775
|
+
import { useCallback as useCallback3, useEffect as useEffect2, useMemo, useRef as useRef2 } from "react";
|
|
776
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
777
|
+
function isHttpUrl2(url) {
|
|
778
|
+
return /^https?:\/\//i.test(url);
|
|
779
|
+
}
|
|
780
|
+
function PaymentDriverHost({ setup, token }) {
|
|
781
|
+
const { props, paymentFailure, reportPaymentFailure, clearPaymentFailure } = useCheckout();
|
|
782
|
+
const { urls } = props;
|
|
783
|
+
const stillPayable = useCallback3(async () => {
|
|
784
|
+
if (null === urls.paymentPayable) {
|
|
785
|
+
return true;
|
|
786
|
+
}
|
|
787
|
+
const answer = await postJson(urls.paymentPayable, {
|
|
788
|
+
reference: setup.reference
|
|
789
|
+
});
|
|
790
|
+
if (200 === answer.status && true === answer.body?.payable) {
|
|
791
|
+
return true;
|
|
792
|
+
}
|
|
793
|
+
if (200 === answer.status && false === answer.body?.payable) {
|
|
794
|
+
router2.reload();
|
|
795
|
+
} else if (429 !== answer.status) {
|
|
796
|
+
reportPaymentFailure(paymentFailureMessage3(null), "server");
|
|
797
|
+
}
|
|
798
|
+
return false;
|
|
799
|
+
}, [setup.reference, urls.paymentPayable, reportPaymentFailure]);
|
|
800
|
+
const context = useMemo(
|
|
801
|
+
() => ({ payment: setup, returnUrl: urls.return, stillPayable }),
|
|
802
|
+
[setup, urls.return, stillPayable]
|
|
803
|
+
);
|
|
804
|
+
const mounted = useRef2(true);
|
|
805
|
+
useEffect2(() => {
|
|
806
|
+
mounted.current = true;
|
|
807
|
+
return () => {
|
|
808
|
+
mounted.current = false;
|
|
809
|
+
};
|
|
810
|
+
}, []);
|
|
811
|
+
const report = useCallback3(
|
|
812
|
+
(result) => new Promise((resolve) => {
|
|
813
|
+
if ("failed" === result.status) {
|
|
814
|
+
reportPaymentFailure(result.message, "driver");
|
|
815
|
+
} else {
|
|
816
|
+
clearPaymentFailure();
|
|
817
|
+
}
|
|
818
|
+
if ("redirect" === result.status) {
|
|
819
|
+
if (isHttpUrl2(result.url)) {
|
|
820
|
+
window.location.assign(result.url);
|
|
821
|
+
resolve("left");
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
reportPaymentFailure(paymentFailureMessage3(null), "server");
|
|
825
|
+
resolve("stayed");
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
const url = "confirmed" === result.status ? urls.paymentConfirmed : urls.paymentFailed;
|
|
829
|
+
if (null === url) {
|
|
830
|
+
resolve("stayed");
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
let answered = false;
|
|
834
|
+
let left = false;
|
|
835
|
+
const checkoutPath = window.location.pathname;
|
|
836
|
+
router2.post(
|
|
837
|
+
url,
|
|
838
|
+
"confirmed" === result.status ? { reference: result.reference, token: token ?? "" } : {},
|
|
839
|
+
{
|
|
840
|
+
preserveScroll: true,
|
|
841
|
+
preserveState: true,
|
|
842
|
+
onSuccess: (page) => {
|
|
843
|
+
answered = true;
|
|
844
|
+
left = new URL(page.url, window.location.origin).pathname !== checkoutPath;
|
|
845
|
+
},
|
|
846
|
+
onError: (errors) => {
|
|
847
|
+
answered = true;
|
|
848
|
+
if ("confirmed" !== result.status) {
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
const message = paymentFailureMessage3(
|
|
852
|
+
errors.gateway ?? errors.payment ?? Object.values(errors)[0]
|
|
853
|
+
);
|
|
854
|
+
reportPaymentFailure(message, "server");
|
|
855
|
+
},
|
|
856
|
+
onFinish: () => {
|
|
857
|
+
if (left || !mounted.current) {
|
|
858
|
+
resolve("left");
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
if (!answered && "confirmed" === result.status) {
|
|
862
|
+
reportPaymentFailure(paymentFailureMessage3(null), "server");
|
|
863
|
+
}
|
|
864
|
+
resolve("stayed");
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
);
|
|
868
|
+
}),
|
|
869
|
+
[token, urls.paymentConfirmed, urls.paymentFailed, reportPaymentFailure, clearPaymentFailure]
|
|
870
|
+
);
|
|
871
|
+
const Component = getRegistries().paymentDrivers.get(setup.component)?.component;
|
|
872
|
+
if (void 0 === Component) {
|
|
873
|
+
return null;
|
|
874
|
+
}
|
|
875
|
+
return /* @__PURE__ */ jsx6(Component, { context, report, failure: paymentFailure });
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// src/checkout/Placement.tsx
|
|
879
|
+
import { __ as __8 } from "@artisanpack-ui/ecommerce-storefront-core";
|
|
880
|
+
import { Alert as Alert3, Card as Card3, Icon as Icon4 } from "@artisanpack-ui/react";
|
|
881
|
+
import { useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
882
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
883
|
+
function Placement({ placement }) {
|
|
884
|
+
const { props, errors } = useCheckout();
|
|
885
|
+
const { payment } = props;
|
|
886
|
+
const order = placement.order;
|
|
887
|
+
const Heading = false === props.showTitle ? "h2" : "h1";
|
|
888
|
+
const heading = useRef3(null);
|
|
889
|
+
const shipping = order?.totals.shipping ?? null;
|
|
890
|
+
useEffect3(() => {
|
|
891
|
+
if (takeStepFocus()) {
|
|
892
|
+
heading.current?.focus();
|
|
893
|
+
}
|
|
894
|
+
}, []);
|
|
895
|
+
return /* @__PURE__ */ jsxs5("div", { className: "ec-placement", "data-checkout-placement": placement.number, children: [
|
|
896
|
+
/* @__PURE__ */ jsx7(CheckoutErrorSummary, {}),
|
|
897
|
+
/* @__PURE__ */ jsxs5(
|
|
898
|
+
Card3,
|
|
899
|
+
{
|
|
900
|
+
className: "ec-placement__card",
|
|
901
|
+
role: "region",
|
|
902
|
+
"aria-labelledby": "ec-checkout-placement-heading",
|
|
903
|
+
children: [
|
|
904
|
+
/* @__PURE__ */ jsx7(Icon4, { name: "clock", variant: "tile", color: "warning", size: "lg" }),
|
|
905
|
+
/* @__PURE__ */ jsxs5("div", { className: "ec-placement__intro", children: [
|
|
906
|
+
/* @__PURE__ */ jsx7(
|
|
907
|
+
Heading,
|
|
908
|
+
{
|
|
909
|
+
ref: heading,
|
|
910
|
+
id: "ec-checkout-placement-heading",
|
|
911
|
+
tabIndex: -1,
|
|
912
|
+
className: "ec-placement__title",
|
|
913
|
+
children: __8("Finish paying for order :number", { number: placement.number })
|
|
914
|
+
}
|
|
915
|
+
),
|
|
916
|
+
/* @__PURE__ */ jsx7("p", { className: "ec-placement__lead", children: __8("Your order is saved, and we'll hold it while you finish paying.") })
|
|
917
|
+
] }),
|
|
918
|
+
null !== payment.problem ? /* @__PURE__ */ jsx7(
|
|
919
|
+
Alert3,
|
|
920
|
+
{
|
|
921
|
+
color: "error",
|
|
922
|
+
icon: "circle-alert",
|
|
923
|
+
title: payment.problem,
|
|
924
|
+
"data-checkout-payment-problem": ""
|
|
925
|
+
}
|
|
926
|
+
) : null,
|
|
927
|
+
null !== order ? /* @__PURE__ */ jsxs5("dl", { className: "ec-placement__meta", "data-checkout-summary": "", children: [
|
|
928
|
+
/* @__PURE__ */ jsxs5("div", { className: "ec-placement__meta-row", children: [
|
|
929
|
+
/* @__PURE__ */ jsx7("dt", { children: __8("Items") }),
|
|
930
|
+
/* @__PURE__ */ jsx7("dd", { "data-checkout-placement-items": "", children: order.itemCount })
|
|
931
|
+
] }),
|
|
932
|
+
null !== shipping && filled(shipping.label) ? /* @__PURE__ */ jsxs5("div", { className: "ec-placement__meta-row", children: [
|
|
933
|
+
/* @__PURE__ */ jsx7("dt", { children: __8("Shipping") }),
|
|
934
|
+
/* @__PURE__ */ jsxs5("dd", { "data-checkout-placement-shipping": "", children: [
|
|
935
|
+
shipping.label,
|
|
936
|
+
/* @__PURE__ */ jsx7("span", { "aria-hidden": "true", children: " \xB7 " }),
|
|
937
|
+
/* @__PURE__ */ jsx7("span", { className: "apui-sr-only", children: ", " }),
|
|
938
|
+
(shipping.amount.amount ?? 0) > 0 ? /* @__PURE__ */ jsx7(Money, { money: shipping.amount }) : __8("Free")
|
|
939
|
+
] })
|
|
940
|
+
] }) : null,
|
|
941
|
+
/* @__PURE__ */ jsxs5("div", { className: "ec-placement__meta-row ec-placement__meta-row--total", children: [
|
|
942
|
+
/* @__PURE__ */ jsx7("dt", { children: __8("Total") }),
|
|
943
|
+
/* @__PURE__ */ jsx7("dd", { children: /* @__PURE__ */ jsx7(Money, { money: order.totals.total, "data-cart-total": "" }) })
|
|
944
|
+
] })
|
|
945
|
+
] }) : null,
|
|
946
|
+
/* @__PURE__ */ jsxs5("div", { className: "ec-placement__payment", "data-field": "gateway", children: [
|
|
947
|
+
null !== payment.setup ? /* @__PURE__ */ jsx7("div", { "data-checkout-payment-driver": payment.setup.driver, children: /* @__PURE__ */ jsx7(
|
|
948
|
+
PaymentDriverHost,
|
|
949
|
+
{
|
|
950
|
+
setup: payment.setup,
|
|
951
|
+
token: payment.token
|
|
952
|
+
},
|
|
953
|
+
payment.setup.reference
|
|
954
|
+
) }) : /* @__PURE__ */ jsx7(
|
|
955
|
+
Alert3,
|
|
956
|
+
{
|
|
957
|
+
color: "warning",
|
|
958
|
+
icon: "triangle-alert",
|
|
959
|
+
title: __8("This payment can't be finished here"),
|
|
960
|
+
description: __8("Please contact the store to complete your order."),
|
|
961
|
+
"data-checkout-placement-unavailable": ""
|
|
962
|
+
}
|
|
963
|
+
),
|
|
964
|
+
void 0 !== errors.gateway ? /* @__PURE__ */ jsxs5("p", { className: "ec-placement__error", children: [
|
|
965
|
+
/* @__PURE__ */ jsx7(Icon4, { name: "circle-alert", size: "sm" }),
|
|
966
|
+
/* @__PURE__ */ jsx7("span", { children: errors.gateway })
|
|
967
|
+
] }) : null
|
|
968
|
+
] })
|
|
969
|
+
]
|
|
970
|
+
}
|
|
971
|
+
)
|
|
972
|
+
] });
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
// src/checkout/steps/AddressStep.tsx
|
|
976
|
+
import {
|
|
977
|
+
__ as __9
|
|
978
|
+
} from "@artisanpack-ui/ecommerce-storefront-core";
|
|
979
|
+
import { Button as Button3, Checkbox, RadioGroup } from "@artisanpack-ui/react";
|
|
980
|
+
import { useState as useState6 } from "react";
|
|
981
|
+
import { Fragment, jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
982
|
+
function savedOptions(saved) {
|
|
983
|
+
return saved.map((address) => ({
|
|
984
|
+
value: address.id,
|
|
985
|
+
label: address.name,
|
|
986
|
+
...null !== address.hint ? { description: address.hint } : {}
|
|
987
|
+
}));
|
|
988
|
+
}
|
|
989
|
+
function AddressGroup({
|
|
990
|
+
model,
|
|
991
|
+
saved,
|
|
992
|
+
choice,
|
|
993
|
+
onChoice,
|
|
994
|
+
form,
|
|
995
|
+
values,
|
|
996
|
+
onChange,
|
|
997
|
+
legend,
|
|
998
|
+
newLegend
|
|
999
|
+
}) {
|
|
1000
|
+
const { props, errors } = useCheckout();
|
|
1001
|
+
const hasSaved = saved.length > 0;
|
|
1002
|
+
return /* @__PURE__ */ jsxs6("div", { className: "ec-checkout-form__group", ...{ [`data-checkout-${model}-address`]: "" }, children: [
|
|
1003
|
+
hasSaved ? /* @__PURE__ */ jsx8(
|
|
1004
|
+
RadioGroup,
|
|
1005
|
+
{
|
|
1006
|
+
id: `ec-checkout-saved-${model}`,
|
|
1007
|
+
name: `saved_${model}`,
|
|
1008
|
+
label: legend,
|
|
1009
|
+
variant: "cards",
|
|
1010
|
+
className: "ec-checkout-choices",
|
|
1011
|
+
options: savedOptions(saved),
|
|
1012
|
+
value: choice,
|
|
1013
|
+
onValueChange: (value) => onChoice(String(value)),
|
|
1014
|
+
"data-checkout-saved": model
|
|
1015
|
+
}
|
|
1016
|
+
) : null,
|
|
1017
|
+
(!hasSaved || "new" === choice) && null !== form ? /* @__PURE__ */ jsx8(
|
|
1018
|
+
AddressForm,
|
|
1019
|
+
{
|
|
1020
|
+
name: model,
|
|
1021
|
+
form,
|
|
1022
|
+
values,
|
|
1023
|
+
onChange,
|
|
1024
|
+
errors,
|
|
1025
|
+
legend: hasSaved ? newLegend : legend,
|
|
1026
|
+
section: model,
|
|
1027
|
+
formatUrl: props.urls.addressFormat
|
|
1028
|
+
}
|
|
1029
|
+
) : null
|
|
1030
|
+
] });
|
|
1031
|
+
}
|
|
1032
|
+
function AddressStep() {
|
|
1033
|
+
const { props, post, processing } = useCheckout();
|
|
1034
|
+
const { address, urls } = props;
|
|
1035
|
+
const forms = props.forms;
|
|
1036
|
+
const [shipping, setShipping] = useState6(forms?.shipping ?? {});
|
|
1037
|
+
const [billing, setBilling] = useState6(forms?.billing ?? {});
|
|
1038
|
+
const [sameAsShipping, setSameAsShipping] = useState6(forms?.billingSameAsShipping ?? true);
|
|
1039
|
+
const [savedShipping, setSavedShipping] = useState6(forms?.savedShipping ?? "new");
|
|
1040
|
+
const [savedBilling, setSavedBilling] = useState6(forms?.savedBilling ?? "new");
|
|
1041
|
+
const [saveToAddressBook, setSaveToAddressBook] = useState6(false);
|
|
1042
|
+
const hasSaved = address.savedAddresses.length > 0;
|
|
1043
|
+
const newAddress = !hasSaved || "new" === (address.ships ? savedShipping : savedBilling);
|
|
1044
|
+
const asksBilling = !address.ships || !sameAsShipping;
|
|
1045
|
+
const submit = (event) => {
|
|
1046
|
+
event.preventDefault();
|
|
1047
|
+
post(urls.address, {
|
|
1048
|
+
shipping: address.ships ? shipping : null,
|
|
1049
|
+
billing: asksBilling ? billing : null,
|
|
1050
|
+
billing_same_as_shipping: address.ships && sameAsShipping,
|
|
1051
|
+
saved_shipping: hasSaved && address.ships ? savedShipping : null,
|
|
1052
|
+
saved_billing: hasSaved && asksBilling ? savedBilling : null,
|
|
1053
|
+
save_to_address_book: newAddress && address.canSave && saveToAddressBook
|
|
1054
|
+
});
|
|
1055
|
+
};
|
|
1056
|
+
return /* @__PURE__ */ jsxs6(
|
|
1057
|
+
"form",
|
|
1058
|
+
{
|
|
1059
|
+
noValidate: true,
|
|
1060
|
+
className: "ec-checkout-form ec-checkout-form--loose",
|
|
1061
|
+
onSubmit: submit,
|
|
1062
|
+
"data-checkout-address-form": "",
|
|
1063
|
+
children: [
|
|
1064
|
+
address.ships ? /* @__PURE__ */ jsxs6(Fragment, { children: [
|
|
1065
|
+
/* @__PURE__ */ jsx8(
|
|
1066
|
+
AddressGroup,
|
|
1067
|
+
{
|
|
1068
|
+
model: "shipping",
|
|
1069
|
+
saved: address.savedAddresses,
|
|
1070
|
+
choice: savedShipping,
|
|
1071
|
+
onChoice: setSavedShipping,
|
|
1072
|
+
form: address.shippingForm,
|
|
1073
|
+
values: shipping,
|
|
1074
|
+
onChange: (field, value) => setShipping((current) => ({ ...current, [field]: value })),
|
|
1075
|
+
legend: __9("Ship to"),
|
|
1076
|
+
newLegend: __9("Shipping address")
|
|
1077
|
+
}
|
|
1078
|
+
),
|
|
1079
|
+
/* @__PURE__ */ jsx8(
|
|
1080
|
+
Checkbox,
|
|
1081
|
+
{
|
|
1082
|
+
label: __9("Billing address is the same as shipping"),
|
|
1083
|
+
checked: sameAsShipping,
|
|
1084
|
+
onCheckedChange: setSameAsShipping,
|
|
1085
|
+
"data-checkout-billing-same": ""
|
|
1086
|
+
}
|
|
1087
|
+
)
|
|
1088
|
+
] }) : /* @__PURE__ */ jsx8("p", { className: "ec-checkout-form__note", "data-checkout-digital-only": "", children: __9("Nothing in your order ships, so we only need your billing address.") }),
|
|
1089
|
+
asksBilling ? /* @__PURE__ */ jsx8(
|
|
1090
|
+
AddressGroup,
|
|
1091
|
+
{
|
|
1092
|
+
model: "billing",
|
|
1093
|
+
saved: address.savedAddresses,
|
|
1094
|
+
choice: savedBilling,
|
|
1095
|
+
onChoice: setSavedBilling,
|
|
1096
|
+
form: address.billingForm,
|
|
1097
|
+
values: billing,
|
|
1098
|
+
onChange: (field, value) => setBilling((current) => ({ ...current, [field]: value })),
|
|
1099
|
+
legend: __9("Bill to"),
|
|
1100
|
+
newLegend: __9("Billing address")
|
|
1101
|
+
}
|
|
1102
|
+
) : null,
|
|
1103
|
+
newAddress && address.canSave ? /* @__PURE__ */ jsx8(
|
|
1104
|
+
Checkbox,
|
|
1105
|
+
{
|
|
1106
|
+
label: __9("Save this address to my address book"),
|
|
1107
|
+
checked: saveToAddressBook,
|
|
1108
|
+
onCheckedChange: setSaveToAddressBook,
|
|
1109
|
+
"data-checkout-save-address": ""
|
|
1110
|
+
}
|
|
1111
|
+
) : null,
|
|
1112
|
+
/* @__PURE__ */ jsx8("div", { className: "ec-checkout-form__actions", children: /* @__PURE__ */ jsx8(
|
|
1113
|
+
Button3,
|
|
1114
|
+
{
|
|
1115
|
+
type: "submit",
|
|
1116
|
+
color: "primary",
|
|
1117
|
+
className: "ec-checkout-form__submit",
|
|
1118
|
+
disabled: urls.address === processing,
|
|
1119
|
+
"data-checkout-address-submit": "",
|
|
1120
|
+
children: __9("Continue")
|
|
1121
|
+
}
|
|
1122
|
+
) })
|
|
1123
|
+
]
|
|
1124
|
+
}
|
|
1125
|
+
);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
// src/checkout/steps/ContactStep.tsx
|
|
1129
|
+
import { __ as __10 } from "@artisanpack-ui/ecommerce-storefront-core";
|
|
1130
|
+
import { Alert as Alert4, Button as Button4, Checkbox as Checkbox2, Icon as Icon5 } from "@artisanpack-ui/react";
|
|
1131
|
+
import { useState as useState7 } from "react";
|
|
1132
|
+
import { Fragment as Fragment2, jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1133
|
+
function ContactStep() {
|
|
1134
|
+
const { props, errors, post, processing } = useCheckout();
|
|
1135
|
+
const { status, urls } = props;
|
|
1136
|
+
const [email, setEmail] = useState7(props.forms?.email ?? "");
|
|
1137
|
+
const [marketingConsent, setMarketingConsent] = useState7(props.forms?.marketingConsent ?? false);
|
|
1138
|
+
const submit = (event) => {
|
|
1139
|
+
event.preventDefault();
|
|
1140
|
+
post(urls.contact, { email, marketing_consent: marketingConsent });
|
|
1141
|
+
};
|
|
1142
|
+
return /* @__PURE__ */ jsxs7("form", { noValidate: true, className: "ec-checkout-form", onSubmit: submit, "data-checkout-contact-form": "", children: [
|
|
1143
|
+
status.isGuest && null !== urls.login && !status.needsAccount ? /* @__PURE__ */ jsxs7("div", { className: "ec-checkout-callout", "data-checkout-sign-in-link": "", children: [
|
|
1144
|
+
/* @__PURE__ */ jsx9(Icon5, { name: "user", className: "ec-checkout-callout__icon", "aria-hidden": "true" }),
|
|
1145
|
+
/* @__PURE__ */ jsx9("p", { className: "ec-checkout-callout__text", children: __10("Have an account? Sign in for faster checkout.") }),
|
|
1146
|
+
/* @__PURE__ */ jsx9(
|
|
1147
|
+
Button4,
|
|
1148
|
+
{
|
|
1149
|
+
href: urls.login,
|
|
1150
|
+
variant: "outline",
|
|
1151
|
+
color: "neutral",
|
|
1152
|
+
size: "sm",
|
|
1153
|
+
className: "ec-checkout-callout__action",
|
|
1154
|
+
children: __10("Sign in")
|
|
1155
|
+
}
|
|
1156
|
+
)
|
|
1157
|
+
] }) : null,
|
|
1158
|
+
status.needsAccount ? /* @__PURE__ */ jsx9(
|
|
1159
|
+
Alert4,
|
|
1160
|
+
{
|
|
1161
|
+
color: "info",
|
|
1162
|
+
icon: "info",
|
|
1163
|
+
title: __10("You'll need an account to pay"),
|
|
1164
|
+
description: __10(
|
|
1165
|
+
"Fill in your details now, then sign in or create an account before paying."
|
|
1166
|
+
),
|
|
1167
|
+
actions: /* @__PURE__ */ jsxs7(Fragment2, { children: [
|
|
1168
|
+
null !== urls.login ? /* @__PURE__ */ jsx9(Button4, { variant: "outline", color: "neutral", size: "sm", href: urls.login, children: __10("Sign in") }) : null,
|
|
1169
|
+
null !== urls.register ? /* @__PURE__ */ jsx9(Button4, { variant: "outline", color: "neutral", size: "sm", href: urls.register, children: __10("Create an account") }) : null
|
|
1170
|
+
] }),
|
|
1171
|
+
"data-checkout-account-needed": ""
|
|
1172
|
+
}
|
|
1173
|
+
) : null,
|
|
1174
|
+
/* @__PURE__ */ jsx9("div", { "data-field": "email", children: /* @__PURE__ */ jsx9(
|
|
1175
|
+
Field,
|
|
1176
|
+
{
|
|
1177
|
+
id: "ec-checkout-email",
|
|
1178
|
+
name: "email",
|
|
1179
|
+
type: "email",
|
|
1180
|
+
label: __10("Email"),
|
|
1181
|
+
hint: __10("We'll send your receipt and shipping updates here."),
|
|
1182
|
+
leadingIcon: "mail",
|
|
1183
|
+
autoComplete: "email",
|
|
1184
|
+
inputMode: "email",
|
|
1185
|
+
required: true,
|
|
1186
|
+
value: email,
|
|
1187
|
+
error: errors.email ?? null,
|
|
1188
|
+
onValueChange: setEmail
|
|
1189
|
+
}
|
|
1190
|
+
) }),
|
|
1191
|
+
/* @__PURE__ */ jsx9(
|
|
1192
|
+
Checkbox2,
|
|
1193
|
+
{
|
|
1194
|
+
label: __10("Email me news and offers"),
|
|
1195
|
+
checked: marketingConsent,
|
|
1196
|
+
onCheckedChange: setMarketingConsent,
|
|
1197
|
+
"data-checkout-marketing": ""
|
|
1198
|
+
}
|
|
1199
|
+
),
|
|
1200
|
+
/* @__PURE__ */ jsx9("div", { className: "ec-checkout-form__actions", children: /* @__PURE__ */ jsx9(
|
|
1201
|
+
Button4,
|
|
1202
|
+
{
|
|
1203
|
+
type: "submit",
|
|
1204
|
+
color: "primary",
|
|
1205
|
+
className: "ec-checkout-form__submit",
|
|
1206
|
+
disabled: urls.contact === processing,
|
|
1207
|
+
"data-checkout-contact-submit": "",
|
|
1208
|
+
children: __10("Continue")
|
|
1209
|
+
}
|
|
1210
|
+
) })
|
|
1211
|
+
] });
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
// src/checkout/steps/PaymentStep.tsx
|
|
1215
|
+
import { __ as __11 } from "@artisanpack-ui/ecommerce-storefront-core";
|
|
1216
|
+
import { Alert as Alert5, Button as Button5, Icon as Icon6 } from "@artisanpack-ui/react";
|
|
1217
|
+
import { useState as useState8 } from "react";
|
|
1218
|
+
import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1219
|
+
function PaymentStep() {
|
|
1220
|
+
const { props, errors, post, processing, clearPaymentFailure } = useCheckout();
|
|
1221
|
+
const { payment, status, urls, summary } = props;
|
|
1222
|
+
const [gateway, setGateway] = useState8(props.forms?.gateway ?? "");
|
|
1223
|
+
const total = summary?.totals?.total ?? null;
|
|
1224
|
+
const placeOrder = null === total || (total.amount ?? 0) <= 0 ? __11("Place order") : __11("Place order \xB7 :total", { total: total.formatted ?? "" });
|
|
1225
|
+
const single = 1 === payment.methods.length;
|
|
1226
|
+
const settingUp = null !== processing && urls.gateway === processing;
|
|
1227
|
+
const gatewayError = errors.gateway ?? null;
|
|
1228
|
+
const choose = (key) => {
|
|
1229
|
+
if (key !== gateway) {
|
|
1230
|
+
clearPaymentFailure();
|
|
1231
|
+
}
|
|
1232
|
+
setGateway(key);
|
|
1233
|
+
post(urls.gateway, { gateway: key }, "keep");
|
|
1234
|
+
};
|
|
1235
|
+
let body;
|
|
1236
|
+
if (null !== payment.stranded) {
|
|
1237
|
+
body = /* @__PURE__ */ jsx10("p", { className: "ec-checkout-form__note", "data-checkout-payment-stranded-note": "", children: __11("Don't pay again. Contact us about your payment.") });
|
|
1238
|
+
} else if (!payment.required || payment.confirmed) {
|
|
1239
|
+
body = /* @__PURE__ */ jsxs8(Fragment3, { children: [
|
|
1240
|
+
payment.required ? /* @__PURE__ */ jsx10(
|
|
1241
|
+
Alert5,
|
|
1242
|
+
{
|
|
1243
|
+
color: "success",
|
|
1244
|
+
icon: "circle-check",
|
|
1245
|
+
title: __11("Your payment is confirmed. Place your order to finish."),
|
|
1246
|
+
"data-checkout-payment-confirmed": ""
|
|
1247
|
+
}
|
|
1248
|
+
) : /* @__PURE__ */ jsx10("p", { className: "ec-checkout-form__note", "data-checkout-payment-free": "", children: __11("Your order is free, so there's nothing to pay.") }),
|
|
1249
|
+
/* @__PURE__ */ jsx10("div", { className: "ec-checkout-form__actions", children: /* @__PURE__ */ jsx10(
|
|
1250
|
+
Button5,
|
|
1251
|
+
{
|
|
1252
|
+
color: "primary",
|
|
1253
|
+
className: "ec-checkout-form__submit",
|
|
1254
|
+
disabled: urls.place === processing,
|
|
1255
|
+
onClick: () => post(urls.place, { token: payment.token ?? "" }),
|
|
1256
|
+
"data-checkout-place-order": "",
|
|
1257
|
+
children: placeOrder
|
|
1258
|
+
}
|
|
1259
|
+
) })
|
|
1260
|
+
] });
|
|
1261
|
+
} else if (status.needsAccount) {
|
|
1262
|
+
body = /* @__PURE__ */ jsx10(
|
|
1263
|
+
Alert5,
|
|
1264
|
+
{
|
|
1265
|
+
color: "info",
|
|
1266
|
+
icon: "lock",
|
|
1267
|
+
title: __11("Sign in or create an account to pay"),
|
|
1268
|
+
description: __11(
|
|
1269
|
+
"This store needs an account to place an order. You'll come back here afterwards."
|
|
1270
|
+
),
|
|
1271
|
+
actions: /* @__PURE__ */ jsxs8(Fragment3, { children: [
|
|
1272
|
+
null !== urls.login ? /* @__PURE__ */ jsx10(Button5, { size: "sm", href: urls.login, color: "primary", children: __11("Sign in") }) : null,
|
|
1273
|
+
null !== urls.register ? /* @__PURE__ */ jsx10(Button5, { variant: "outline", color: "neutral", size: "sm", href: urls.register, children: __11("Create an account") }) : null
|
|
1274
|
+
] }),
|
|
1275
|
+
"data-checkout-payment-account-needed": ""
|
|
1276
|
+
}
|
|
1277
|
+
);
|
|
1278
|
+
} else if (0 === payment.methods.length) {
|
|
1279
|
+
body = /* @__PURE__ */ jsx10(
|
|
1280
|
+
Alert5,
|
|
1281
|
+
{
|
|
1282
|
+
color: "warning",
|
|
1283
|
+
icon: "triangle-alert",
|
|
1284
|
+
title: __11("No payment methods are available"),
|
|
1285
|
+
description: __11("Please contact the store to complete your order."),
|
|
1286
|
+
"data-checkout-no-gateways": ""
|
|
1287
|
+
}
|
|
1288
|
+
);
|
|
1289
|
+
} else {
|
|
1290
|
+
body = /* @__PURE__ */ jsxs8(Fragment3, { children: [
|
|
1291
|
+
/* @__PURE__ */ jsx10("div", { "data-field": "gateway", children: /* @__PURE__ */ jsxs8(
|
|
1292
|
+
"fieldset",
|
|
1293
|
+
{
|
|
1294
|
+
className: "apui-radio-group ec-payment-methods",
|
|
1295
|
+
id: "ec-checkout-gateway",
|
|
1296
|
+
"data-orientation": "vertical",
|
|
1297
|
+
"data-variant": "cards",
|
|
1298
|
+
"data-invalid": null !== gatewayError ? "" : void 0,
|
|
1299
|
+
"aria-describedby": null !== gatewayError ? "ec-checkout-gateway-error" : void 0,
|
|
1300
|
+
"data-checkout-gateways": single ? void 0 : "",
|
|
1301
|
+
children: [
|
|
1302
|
+
/* @__PURE__ */ jsx10("legend", { "data-scope": "radio-group", "data-part": "label", children: __11("Payment method") }),
|
|
1303
|
+
/* @__PURE__ */ jsx10("div", { "data-scope": "radio-group", "data-part": "items", children: payment.methods.map((method, index) => {
|
|
1304
|
+
const methodId = `ec-checkout-gateway-${index}`;
|
|
1305
|
+
const selected = single || gateway === method.key;
|
|
1306
|
+
const showsDriver = selected && null !== payment.setup && payment.setup.gateway === method.key;
|
|
1307
|
+
return /* @__PURE__ */ jsxs8(
|
|
1308
|
+
"div",
|
|
1309
|
+
{
|
|
1310
|
+
className: "ec-payment-method",
|
|
1311
|
+
"data-selected": selected ? "" : void 0,
|
|
1312
|
+
"data-checkout-gateway": method.key,
|
|
1313
|
+
children: [
|
|
1314
|
+
single ? /* @__PURE__ */ jsxs8("div", { className: "ec-payment-method__header", "data-checkout-gateway-single": "", children: [
|
|
1315
|
+
/* @__PURE__ */ jsx10("span", { className: "ec-payment-method__text", children: __11("Pay with :gateway", { gateway: method.label }) }),
|
|
1316
|
+
null !== method.description ? /* @__PURE__ */ jsx10("span", { className: "ec-payment-method__description", children: method.description }) : null,
|
|
1317
|
+
null !== method.icon ? /* @__PURE__ */ jsx10(
|
|
1318
|
+
Icon6,
|
|
1319
|
+
{
|
|
1320
|
+
name: method.icon,
|
|
1321
|
+
className: "ec-payment-method__icon",
|
|
1322
|
+
"aria-hidden": "true"
|
|
1323
|
+
}
|
|
1324
|
+
) : null
|
|
1325
|
+
] }) : /* @__PURE__ */ jsxs8(
|
|
1326
|
+
"label",
|
|
1327
|
+
{
|
|
1328
|
+
"data-scope": "radio-group",
|
|
1329
|
+
"data-part": "item",
|
|
1330
|
+
className: "ec-payment-method__header",
|
|
1331
|
+
htmlFor: methodId,
|
|
1332
|
+
children: [
|
|
1333
|
+
/* @__PURE__ */ jsxs8("span", { "data-scope": "radio-group", "data-part": "box", children: [
|
|
1334
|
+
/* @__PURE__ */ jsx10(
|
|
1335
|
+
"input",
|
|
1336
|
+
{
|
|
1337
|
+
type: "radio",
|
|
1338
|
+
"data-scope": "radio-group",
|
|
1339
|
+
"data-part": "control",
|
|
1340
|
+
id: methodId,
|
|
1341
|
+
name: "ec-checkout-gateway",
|
|
1342
|
+
value: method.key,
|
|
1343
|
+
checked: selected,
|
|
1344
|
+
onChange: () => choose(method.key),
|
|
1345
|
+
"aria-invalid": null !== gatewayError ? "true" : void 0,
|
|
1346
|
+
"aria-describedby": null !== method.description ? `${methodId}-description` : void 0
|
|
1347
|
+
}
|
|
1348
|
+
),
|
|
1349
|
+
/* @__PURE__ */ jsx10("span", { "data-scope": "radio-group", "data-part": "indicator", "aria-hidden": "true" })
|
|
1350
|
+
] }),
|
|
1351
|
+
/* @__PURE__ */ jsx10("span", { "data-scope": "radio-group", "data-part": "item-text", children: method.label }),
|
|
1352
|
+
null !== method.description ? /* @__PURE__ */ jsx10(
|
|
1353
|
+
"span",
|
|
1354
|
+
{
|
|
1355
|
+
"data-scope": "radio-group",
|
|
1356
|
+
"data-part": "item-description",
|
|
1357
|
+
id: `${methodId}-description`,
|
|
1358
|
+
children: method.description
|
|
1359
|
+
}
|
|
1360
|
+
) : null,
|
|
1361
|
+
null !== method.icon ? /* @__PURE__ */ jsx10(
|
|
1362
|
+
Icon6,
|
|
1363
|
+
{
|
|
1364
|
+
name: method.icon,
|
|
1365
|
+
className: "ec-payment-method__icon",
|
|
1366
|
+
"aria-hidden": "true"
|
|
1367
|
+
}
|
|
1368
|
+
) : null
|
|
1369
|
+
]
|
|
1370
|
+
}
|
|
1371
|
+
),
|
|
1372
|
+
showsDriver && null !== payment.setup && !settingUp ? /* @__PURE__ */ jsx10(
|
|
1373
|
+
"div",
|
|
1374
|
+
{
|
|
1375
|
+
className: "ec-payment-method__panel",
|
|
1376
|
+
"data-checkout-payment-driver": payment.setup.driver,
|
|
1377
|
+
children: /* @__PURE__ */ jsx10(
|
|
1378
|
+
PaymentDriverHost,
|
|
1379
|
+
{
|
|
1380
|
+
setup: payment.setup,
|
|
1381
|
+
token: payment.token
|
|
1382
|
+
},
|
|
1383
|
+
payment.setup.reference
|
|
1384
|
+
)
|
|
1385
|
+
}
|
|
1386
|
+
) : null
|
|
1387
|
+
]
|
|
1388
|
+
},
|
|
1389
|
+
method.key
|
|
1390
|
+
);
|
|
1391
|
+
}) }),
|
|
1392
|
+
null !== gatewayError ? /* @__PURE__ */ jsxs8("p", { "data-scope": "radio-group", "data-part": "error", id: "ec-checkout-gateway-error", children: [
|
|
1393
|
+
/* @__PURE__ */ jsx10(Icon6, { name: "circle-alert", "aria-hidden": "true" }),
|
|
1394
|
+
gatewayError
|
|
1395
|
+
] }) : null
|
|
1396
|
+
]
|
|
1397
|
+
}
|
|
1398
|
+
) }),
|
|
1399
|
+
settingUp ? /* @__PURE__ */ jsx10("p", { className: "ec-checkout-form__note", "data-checkout-payment-loading": "", children: __11("Setting up your payment\u2026") }) : null !== payment.setup ? /* @__PURE__ */ jsx10("p", { className: "ec-checkout-form__note", "data-checkout-payment-places-order": "", children: __11("Your order is placed as soon as your payment is confirmed.") }) : null
|
|
1400
|
+
] });
|
|
1401
|
+
}
|
|
1402
|
+
return /* @__PURE__ */ jsxs8("div", { className: "ec-checkout-form", "data-checkout-payment": "", children: [
|
|
1403
|
+
body,
|
|
1404
|
+
/* @__PURE__ */ jsx10("div", { "data-field": "payment", children: void 0 !== errors.payment ? /* @__PURE__ */ jsxs8("p", { className: "ec-checkout-form__error", "data-checkout-payment-error": "", children: [
|
|
1405
|
+
/* @__PURE__ */ jsx10(Icon6, { name: "circle-alert", "aria-hidden": "true" }),
|
|
1406
|
+
/* @__PURE__ */ jsx10("span", { children: errors.payment })
|
|
1407
|
+
] }) : null })
|
|
1408
|
+
] });
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
// src/checkout/steps/ReviewStep.tsx
|
|
1412
|
+
import { __ as __12 } from "@artisanpack-ui/ecommerce-storefront-core";
|
|
1413
|
+
import { Button as Button6, Checkbox as Checkbox3 } from "@artisanpack-ui/react";
|
|
1414
|
+
import { useState as useState9 } from "react";
|
|
1415
|
+
import { Fragment as Fragment4, jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1416
|
+
function ReviewStep() {
|
|
1417
|
+
const { props, errors, post, processing } = useCheckout();
|
|
1418
|
+
const { review, urls } = props;
|
|
1419
|
+
const [note, setNote] = useState9(props.forms?.note ?? "");
|
|
1420
|
+
const [acceptTerms, setAcceptTerms] = useState9(props.forms?.acceptTerms ?? false);
|
|
1421
|
+
const [createAccount, setCreateAccount] = useState9(props.forms?.createAccount ?? false);
|
|
1422
|
+
const [password, setPassword] = useState9("");
|
|
1423
|
+
const [termsBefore, termsAfter = ""] = __12("I accept the :terms").split(":terms", 2);
|
|
1424
|
+
const submit = (event) => {
|
|
1425
|
+
event.preventDefault();
|
|
1426
|
+
post(urls.review, {
|
|
1427
|
+
note,
|
|
1428
|
+
accept_terms: null !== review.termsUrl && acceptTerms,
|
|
1429
|
+
create_account: review.offersAccount && createAccount,
|
|
1430
|
+
password: review.offersAccount && createAccount ? password : null
|
|
1431
|
+
});
|
|
1432
|
+
};
|
|
1433
|
+
return /* @__PURE__ */ jsxs9(
|
|
1434
|
+
"form",
|
|
1435
|
+
{
|
|
1436
|
+
noValidate: true,
|
|
1437
|
+
className: "ec-checkout-form ec-checkout-form--loose",
|
|
1438
|
+
onSubmit: submit,
|
|
1439
|
+
"data-checkout-review-form": "",
|
|
1440
|
+
children: [
|
|
1441
|
+
/* @__PURE__ */ jsx11("div", { "data-field": "note", children: /* @__PURE__ */ jsx11(
|
|
1442
|
+
Field,
|
|
1443
|
+
{
|
|
1444
|
+
control: "textarea",
|
|
1445
|
+
id: "ec-checkout-order-note",
|
|
1446
|
+
name: "note",
|
|
1447
|
+
label: __12("Order note"),
|
|
1448
|
+
optional: true,
|
|
1449
|
+
placeholder: __12("Anything the store should know about your order"),
|
|
1450
|
+
hint: __12("Anything the store should know about your order. Up to :max characters.", {
|
|
1451
|
+
max: review.noteMaxLength
|
|
1452
|
+
}),
|
|
1453
|
+
maxLength: review.noteMaxLength,
|
|
1454
|
+
value: note,
|
|
1455
|
+
error: errors.note ?? null,
|
|
1456
|
+
onValueChange: setNote,
|
|
1457
|
+
attributes: { rows: 3, "data-checkout-order-note": "" }
|
|
1458
|
+
}
|
|
1459
|
+
) }),
|
|
1460
|
+
review.offersAccount ? /* @__PURE__ */ jsxs9("div", { className: "ec-checkout-callout ec-checkout-callout--stacked", "data-checkout-account": "", children: [
|
|
1461
|
+
/* @__PURE__ */ jsx11(
|
|
1462
|
+
Checkbox3,
|
|
1463
|
+
{
|
|
1464
|
+
label: __12("Create an account with this email"),
|
|
1465
|
+
description: __12("Track this order and check out faster next time."),
|
|
1466
|
+
checked: createAccount,
|
|
1467
|
+
onCheckedChange: setCreateAccount,
|
|
1468
|
+
"data-checkout-create-account": ""
|
|
1469
|
+
}
|
|
1470
|
+
),
|
|
1471
|
+
createAccount ? /* @__PURE__ */ jsx11("div", { className: "ec-checkout-callout__nested", "data-field": "password", children: /* @__PURE__ */ jsx11(
|
|
1472
|
+
Field,
|
|
1473
|
+
{
|
|
1474
|
+
control: "password",
|
|
1475
|
+
id: "ec-checkout-password",
|
|
1476
|
+
name: "password",
|
|
1477
|
+
label: __12("Password"),
|
|
1478
|
+
autoComplete: "new-password",
|
|
1479
|
+
value: password,
|
|
1480
|
+
error: errors.password ?? null,
|
|
1481
|
+
onValueChange: setPassword,
|
|
1482
|
+
attributes: { "data-checkout-password": "" }
|
|
1483
|
+
}
|
|
1484
|
+
) }) : null
|
|
1485
|
+
] }) : null,
|
|
1486
|
+
null !== review.termsUrl ? /* @__PURE__ */ jsx11("div", { "data-field": "accept_terms", children: /* @__PURE__ */ jsx11(
|
|
1487
|
+
Checkbox3,
|
|
1488
|
+
{
|
|
1489
|
+
id: "ec-checkout-terms",
|
|
1490
|
+
name: "accept_terms",
|
|
1491
|
+
checked: acceptTerms,
|
|
1492
|
+
onCheckedChange: setAcceptTerms,
|
|
1493
|
+
error: errors.accept_terms,
|
|
1494
|
+
label: /* @__PURE__ */ jsxs9(Fragment4, { children: [
|
|
1495
|
+
termsBefore,
|
|
1496
|
+
/* @__PURE__ */ jsxs9(
|
|
1497
|
+
"a",
|
|
1498
|
+
{
|
|
1499
|
+
href: review.termsUrl,
|
|
1500
|
+
className: "apui-link",
|
|
1501
|
+
target: "_blank",
|
|
1502
|
+
rel: "noopener noreferrer",
|
|
1503
|
+
"data-checkout-terms-link": "",
|
|
1504
|
+
children: [
|
|
1505
|
+
__12("terms and conditions"),
|
|
1506
|
+
/* @__PURE__ */ jsxs9("span", { className: "apui-sr-only", children: [
|
|
1507
|
+
" ",
|
|
1508
|
+
__12("(opens in a new tab)")
|
|
1509
|
+
] })
|
|
1510
|
+
]
|
|
1511
|
+
}
|
|
1512
|
+
),
|
|
1513
|
+
termsAfter
|
|
1514
|
+
] }),
|
|
1515
|
+
"data-checkout-terms": ""
|
|
1516
|
+
}
|
|
1517
|
+
) }) : null,
|
|
1518
|
+
/* @__PURE__ */ jsx11("div", { className: "ec-checkout-form__actions", children: /* @__PURE__ */ jsx11(
|
|
1519
|
+
Button6,
|
|
1520
|
+
{
|
|
1521
|
+
type: "submit",
|
|
1522
|
+
color: "primary",
|
|
1523
|
+
className: "ec-checkout-form__submit",
|
|
1524
|
+
disabled: urls.review === processing,
|
|
1525
|
+
"data-checkout-review-submit": "",
|
|
1526
|
+
children: __12("Continue to payment")
|
|
1527
|
+
}
|
|
1528
|
+
) })
|
|
1529
|
+
]
|
|
1530
|
+
}
|
|
1531
|
+
);
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
// src/checkout/steps/ShippingStep.tsx
|
|
1535
|
+
import { __ as __13 } from "@artisanpack-ui/ecommerce-storefront-core";
|
|
1536
|
+
import { Alert as Alert6, Button as Button7, RadioGroup as RadioGroup2 } from "@artisanpack-ui/react";
|
|
1537
|
+
import { useState as useState10 } from "react";
|
|
1538
|
+
import { Fragment as Fragment5, jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1539
|
+
function ShippingStep() {
|
|
1540
|
+
const { props, errors, post, goTo, processing } = useCheckout();
|
|
1541
|
+
const { shipping, urls } = props;
|
|
1542
|
+
const [rate, setRate] = useState10(props.forms?.rate || shipping.chosen?.id || "");
|
|
1543
|
+
const rates = shipping.rates ?? [];
|
|
1544
|
+
const shipTo = shipToLine(props.forms?.shipping ?? {});
|
|
1545
|
+
const [before, after = ""] = __13("Shipping to :address").split(":address", 2);
|
|
1546
|
+
const busy = null !== processing && (urls.shipping === processing || urls.shippingRate === processing);
|
|
1547
|
+
const choose = (value) => {
|
|
1548
|
+
setRate(value);
|
|
1549
|
+
post(urls.shippingRate, { rate: value }, "keep");
|
|
1550
|
+
};
|
|
1551
|
+
const submit = (event) => {
|
|
1552
|
+
event.preventDefault();
|
|
1553
|
+
post(urls.shipping, { rate });
|
|
1554
|
+
};
|
|
1555
|
+
return /* @__PURE__ */ jsxs10("form", { noValidate: true, className: "ec-checkout-form", onSubmit: submit, "data-checkout-shipping-form": "", children: [
|
|
1556
|
+
"" !== shipTo ? /* @__PURE__ */ jsxs10("div", { className: "ec-checkout-ship-to", "data-checkout-ship-to": "", children: [
|
|
1557
|
+
/* @__PURE__ */ jsxs10("p", { className: "ec-checkout-ship-to__text", children: [
|
|
1558
|
+
before,
|
|
1559
|
+
/* @__PURE__ */ jsx12("span", { className: "ec-checkout-ship-to__address", children: shipTo }),
|
|
1560
|
+
after
|
|
1561
|
+
] }),
|
|
1562
|
+
/* @__PURE__ */ jsx12(
|
|
1563
|
+
Button7,
|
|
1564
|
+
{
|
|
1565
|
+
variant: "link",
|
|
1566
|
+
size: "sm",
|
|
1567
|
+
onClick: () => goTo("address"),
|
|
1568
|
+
"data-checkout-change-address": "",
|
|
1569
|
+
children: __13("Change address")
|
|
1570
|
+
}
|
|
1571
|
+
)
|
|
1572
|
+
] }) : null,
|
|
1573
|
+
null !== shipping.notice ? /* @__PURE__ */ jsx12(
|
|
1574
|
+
Alert6,
|
|
1575
|
+
{
|
|
1576
|
+
color: "warning",
|
|
1577
|
+
icon: "triangle-alert",
|
|
1578
|
+
title: shipping.notice,
|
|
1579
|
+
"data-checkout-shipping-notice": ""
|
|
1580
|
+
}
|
|
1581
|
+
) : null,
|
|
1582
|
+
null !== shipping.rates && 0 === rates.length ? /* @__PURE__ */ jsx12(
|
|
1583
|
+
Alert6,
|
|
1584
|
+
{
|
|
1585
|
+
color: "warning",
|
|
1586
|
+
icon: "truck",
|
|
1587
|
+
title: __13("We can't ship to this address"),
|
|
1588
|
+
description: __13("Check the address, or use a different one."),
|
|
1589
|
+
actions: /* @__PURE__ */ jsx12(
|
|
1590
|
+
Button7,
|
|
1591
|
+
{
|
|
1592
|
+
variant: "outline",
|
|
1593
|
+
color: "neutral",
|
|
1594
|
+
size: "sm",
|
|
1595
|
+
onClick: () => goTo("address"),
|
|
1596
|
+
"data-checkout-change-address": "",
|
|
1597
|
+
children: __13("Change address")
|
|
1598
|
+
}
|
|
1599
|
+
),
|
|
1600
|
+
"data-checkout-no-rates": ""
|
|
1601
|
+
}
|
|
1602
|
+
) : rates.length > 0 ? /* @__PURE__ */ jsxs10(Fragment5, { children: [
|
|
1603
|
+
/* @__PURE__ */ jsx12("div", { "data-field": "rate", children: /* @__PURE__ */ jsx12(
|
|
1604
|
+
RadioGroup2,
|
|
1605
|
+
{
|
|
1606
|
+
id: "ec-checkout-shipping-rate",
|
|
1607
|
+
name: "rate",
|
|
1608
|
+
label: __13("Shipping option"),
|
|
1609
|
+
variant: "cards",
|
|
1610
|
+
className: "ec-checkout-choices ec-checkout-choices--priced",
|
|
1611
|
+
options: rates.map((option) => ({
|
|
1612
|
+
value: option.id,
|
|
1613
|
+
label: option.label,
|
|
1614
|
+
...null !== option.estimate ? { description: option.estimate } : {},
|
|
1615
|
+
meta: (option.amount.amount ?? 0) > 0 ? option.amount.formatted ?? "" : __13("Free")
|
|
1616
|
+
})),
|
|
1617
|
+
value: "" === rate ? null : rate,
|
|
1618
|
+
error: errors.rate,
|
|
1619
|
+
onValueChange: (value) => choose(String(value)),
|
|
1620
|
+
"data-checkout-rates": ""
|
|
1621
|
+
}
|
|
1622
|
+
) }),
|
|
1623
|
+
/* @__PURE__ */ jsx12("div", { className: "ec-checkout-form__actions", children: /* @__PURE__ */ jsx12(
|
|
1624
|
+
Button7,
|
|
1625
|
+
{
|
|
1626
|
+
type: "submit",
|
|
1627
|
+
color: "primary",
|
|
1628
|
+
className: "ec-checkout-form__submit",
|
|
1629
|
+
disabled: busy,
|
|
1630
|
+
"data-checkout-shipping-submit": "",
|
|
1631
|
+
children: __13("Continue")
|
|
1632
|
+
}
|
|
1633
|
+
) })
|
|
1634
|
+
] }) : null
|
|
1635
|
+
] });
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
// src/checkout/Checkout.tsx
|
|
1639
|
+
import { __ as __14 } from "@artisanpack-ui/ecommerce-storefront-core";
|
|
1640
|
+
import { Alert as Alert7, Button as Button8, Icon as Icon7, Step, Steps } from "@artisanpack-ui/react";
|
|
1641
|
+
import { useCallback as useCallback4, useEffect as useEffect4, useRef as useRef4 } from "react";
|
|
1642
|
+
import { Fragment as Fragment6, jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
1643
|
+
registerPaymentDrivers();
|
|
1644
|
+
var CORE_STEPS = {
|
|
1645
|
+
contact: ContactStep,
|
|
1646
|
+
address: AddressStep,
|
|
1647
|
+
shipping: ShippingStep,
|
|
1648
|
+
review: ReviewStep,
|
|
1649
|
+
payment: PaymentStep
|
|
1650
|
+
};
|
|
1651
|
+
function StepBody({ step }) {
|
|
1652
|
+
const { post } = useCheckout();
|
|
1653
|
+
const complete = useCallback4(
|
|
1654
|
+
(data = {}) => post(step.completeUrl, data),
|
|
1655
|
+
[post, step.completeUrl]
|
|
1656
|
+
);
|
|
1657
|
+
if (null !== step.component) {
|
|
1658
|
+
const Satellite = getRegistries().checkoutSteps.get(step.component)?.component;
|
|
1659
|
+
return void 0 === Satellite ? null : /* @__PURE__ */ jsx13(Satellite, { step, complete });
|
|
1660
|
+
}
|
|
1661
|
+
const Core = CORE_STEPS[step.key];
|
|
1662
|
+
return void 0 === Core ? null : /* @__PURE__ */ jsx13(Core, {});
|
|
1663
|
+
}
|
|
1664
|
+
function Title() {
|
|
1665
|
+
const { props } = useCheckout();
|
|
1666
|
+
return false === props.showTitle ? null : /* @__PURE__ */ jsx13("h1", { className: "ec-checkout__title", children: __14("Checkout") });
|
|
1667
|
+
}
|
|
1668
|
+
function Placed({ number }) {
|
|
1669
|
+
const root = useRef4(null);
|
|
1670
|
+
useEffect4(() => {
|
|
1671
|
+
const heading = root.current?.querySelector("h1, h2");
|
|
1672
|
+
if (void 0 !== heading && null !== heading) {
|
|
1673
|
+
heading.setAttribute("tabindex", "-1");
|
|
1674
|
+
heading.focus();
|
|
1675
|
+
}
|
|
1676
|
+
}, []);
|
|
1677
|
+
return /* @__PURE__ */ jsxs11("div", { ref: root, className: "ec-checkout__placed", "data-checkout-placed": "", children: [
|
|
1678
|
+
/* @__PURE__ */ jsx13(Title, {}),
|
|
1679
|
+
/* @__PURE__ */ jsx13(
|
|
1680
|
+
EmptyState,
|
|
1681
|
+
{
|
|
1682
|
+
icon: "circle-check",
|
|
1683
|
+
title: __14("Thank you for your order"),
|
|
1684
|
+
description: __14("Your order :number is placed. We've emailed you a confirmation.", {
|
|
1685
|
+
number
|
|
1686
|
+
}),
|
|
1687
|
+
card: true
|
|
1688
|
+
}
|
|
1689
|
+
)
|
|
1690
|
+
] });
|
|
1691
|
+
}
|
|
1692
|
+
function CheckoutSteps() {
|
|
1693
|
+
const { props, goTo } = useCheckout();
|
|
1694
|
+
const { steps, layout, status, payment } = props;
|
|
1695
|
+
const singlePage = "single_page" === layout;
|
|
1696
|
+
const current = steps.find((step) => step.current) ?? null;
|
|
1697
|
+
const blocking = [...steps].reverse().find((step) => step.reachable)?.label ?? "";
|
|
1698
|
+
const currentKey = current?.key ?? null;
|
|
1699
|
+
useEffect4(() => {
|
|
1700
|
+
if (takeStepFocus() && null !== currentKey) {
|
|
1701
|
+
document.getElementById(`ec-checkout-step-${currentKey}`)?.focus();
|
|
1702
|
+
}
|
|
1703
|
+
}, [currentKey]);
|
|
1704
|
+
return /* @__PURE__ */ jsxs11("div", { className: "ec-checkout__layout", children: [
|
|
1705
|
+
/* @__PURE__ */ jsxs11("div", { className: "ec-checkout__main", children: [
|
|
1706
|
+
/* @__PURE__ */ jsx13(Title, {}),
|
|
1707
|
+
!singlePage && steps.length > 0 ? /* @__PURE__ */ jsxs11(Fragment6, { children: [
|
|
1708
|
+
null !== current ? (
|
|
1709
|
+
// Below 768px; the live announcement says the same to assistive tech.
|
|
1710
|
+
/* @__PURE__ */ jsxs11("p", { className: "ec-checkout__step-line", "aria-hidden": "true", "data-checkout-step-line": "", children: [
|
|
1711
|
+
__14("Step :number of :total", { number: current.number, total: steps.length }),
|
|
1712
|
+
" ",
|
|
1713
|
+
"\xB7 ",
|
|
1714
|
+
/* @__PURE__ */ jsx13("span", { children: current.label })
|
|
1715
|
+
] })
|
|
1716
|
+
) : null,
|
|
1717
|
+
/* @__PURE__ */ jsx13("div", { "aria-hidden": "true", className: "ec-checkout__progress", "data-checkout-progress": "", children: /* @__PURE__ */ jsx13(Steps, { value: props.progress, children: steps.map((step) => /* @__PURE__ */ jsx13(Step, { title: step.label }, step.key)) }) })
|
|
1718
|
+
] }) : null,
|
|
1719
|
+
status.adjustments.length > 0 ? /* @__PURE__ */ jsx13(Alert7, { color: "warning", title: __14("We've updated your cart"), "data-checkout-adjustments": "", children: /* @__PURE__ */ jsx13("ul", { className: "ec-checkout__adjustments", children: status.adjustments.map((adjustment, index) => /* @__PURE__ */ jsx13("li", { children: adjustment }, index)) }) }) : null,
|
|
1720
|
+
null !== payment.stranded ? /* @__PURE__ */ jsx13(
|
|
1721
|
+
Alert7,
|
|
1722
|
+
{
|
|
1723
|
+
color: "warning",
|
|
1724
|
+
icon: "circle-alert",
|
|
1725
|
+
title: payment.stranded.title,
|
|
1726
|
+
description: payment.stranded.message,
|
|
1727
|
+
"data-checkout-payment-stranded": ""
|
|
1728
|
+
}
|
|
1729
|
+
) : null,
|
|
1730
|
+
/* @__PURE__ */ jsx13(CheckoutErrorSummary, {}),
|
|
1731
|
+
/* @__PURE__ */ jsx13(
|
|
1732
|
+
"ol",
|
|
1733
|
+
{
|
|
1734
|
+
role: "list",
|
|
1735
|
+
className: "ec-checkout__steps",
|
|
1736
|
+
"aria-label": __14("Checkout steps"),
|
|
1737
|
+
"data-checkout-steps": "",
|
|
1738
|
+
children: steps.map((step) => {
|
|
1739
|
+
const done = !step.current && step.complete && step.reachable;
|
|
1740
|
+
const state = step.current ? "current" : done ? "complete" : "upcoming";
|
|
1741
|
+
return /* @__PURE__ */ jsxs11(
|
|
1742
|
+
"li",
|
|
1743
|
+
{
|
|
1744
|
+
className: "ec-checkout-step",
|
|
1745
|
+
"data-state": state,
|
|
1746
|
+
"aria-current": step.current ? "step" : void 0,
|
|
1747
|
+
"data-checkout-step": step.key,
|
|
1748
|
+
"data-checkout-step-state": state,
|
|
1749
|
+
children: [
|
|
1750
|
+
/* @__PURE__ */ jsxs11("div", { className: "ec-checkout-step__header", children: [
|
|
1751
|
+
/* @__PURE__ */ jsxs11(
|
|
1752
|
+
"h2",
|
|
1753
|
+
{
|
|
1754
|
+
id: `ec-checkout-step-${step.key}`,
|
|
1755
|
+
tabIndex: -1,
|
|
1756
|
+
className: "ec-checkout-step__title",
|
|
1757
|
+
children: [
|
|
1758
|
+
/* @__PURE__ */ jsx13("span", { className: "ec-checkout-step__number", "aria-hidden": "true", children: done ? /* @__PURE__ */ jsx13(Icon7, { name: "check" }) : step.number }),
|
|
1759
|
+
/* @__PURE__ */ jsx13("span", { className: "apui-sr-only", children: __14("Step :number:", { number: step.number }) }),
|
|
1760
|
+
/* @__PURE__ */ jsx13("span", { children: step.label }),
|
|
1761
|
+
done ? /* @__PURE__ */ jsx13("span", { className: "apui-sr-only", children: __14("(completed)") }) : !step.reachable ? /* @__PURE__ */ jsx13("span", { className: "apui-sr-only", "data-checkout-step-unavailable": "", children: __14("(not available yet)") }) : null
|
|
1762
|
+
]
|
|
1763
|
+
}
|
|
1764
|
+
),
|
|
1765
|
+
done ? /* @__PURE__ */ jsx13(
|
|
1766
|
+
Button8,
|
|
1767
|
+
{
|
|
1768
|
+
variant: "ghost",
|
|
1769
|
+
color: "neutral",
|
|
1770
|
+
size: "sm",
|
|
1771
|
+
leadingIcon: "pencil",
|
|
1772
|
+
onClick: () => goTo(step.key),
|
|
1773
|
+
"aria-label": __14("Edit :step", { step: step.label }),
|
|
1774
|
+
"data-checkout-edit": step.key,
|
|
1775
|
+
children: __14("Edit")
|
|
1776
|
+
}
|
|
1777
|
+
) : null
|
|
1778
|
+
] }),
|
|
1779
|
+
step.current ? /* @__PURE__ */ jsx13("div", { className: "ec-checkout-step__body", children: /* @__PURE__ */ jsx13(StepBody, { step }) }) : done ? /* @__PURE__ */ jsx13("div", { className: "ec-checkout-step__summary", "data-checkout-step-summary": step.key, children: /* @__PURE__ */ jsx13(CheckoutStepSummary, { step: step.key }) }) : singlePage && !step.reachable ? /* @__PURE__ */ jsx13("p", { className: "ec-checkout-step__locked", "data-checkout-step-locked": step.key, children: __14("Complete \u201C:step\u201D first.", { step: blocking }) }) : null
|
|
1780
|
+
]
|
|
1781
|
+
},
|
|
1782
|
+
`${step.key}-${state}`
|
|
1783
|
+
);
|
|
1784
|
+
})
|
|
1785
|
+
}
|
|
1786
|
+
)
|
|
1787
|
+
] }),
|
|
1788
|
+
/* @__PURE__ */ jsx13(CheckoutOrderSummary, { summary: props.summary, cartUrl: props.urls.cart })
|
|
1789
|
+
] });
|
|
1790
|
+
}
|
|
1791
|
+
function CheckoutBody() {
|
|
1792
|
+
const { props } = useCheckout();
|
|
1793
|
+
const { status, urls } = props;
|
|
1794
|
+
if (null !== status.placedOrder) {
|
|
1795
|
+
return /* @__PURE__ */ jsx13(Placed, { number: status.placedOrder });
|
|
1796
|
+
}
|
|
1797
|
+
if (null !== status.unavailable) {
|
|
1798
|
+
return /* @__PURE__ */ jsxs11(Fragment6, { children: [
|
|
1799
|
+
/* @__PURE__ */ jsx13(Title, {}),
|
|
1800
|
+
/* @__PURE__ */ jsx13(
|
|
1801
|
+
EmptyState,
|
|
1802
|
+
{
|
|
1803
|
+
icon: "shopping-bag",
|
|
1804
|
+
title: status.unavailable,
|
|
1805
|
+
card: true,
|
|
1806
|
+
"data-checkout-unavailable": "",
|
|
1807
|
+
children: null !== urls.cart ? /* @__PURE__ */ jsx13(Button8, { href: urls.cart, color: "primary", children: __14("Go to your cart") }) : null
|
|
1808
|
+
}
|
|
1809
|
+
)
|
|
1810
|
+
] });
|
|
1811
|
+
}
|
|
1812
|
+
if (status.signInRequired) {
|
|
1813
|
+
return /* @__PURE__ */ jsxs11(Fragment6, { children: [
|
|
1814
|
+
/* @__PURE__ */ jsx13(Title, {}),
|
|
1815
|
+
/* @__PURE__ */ jsxs11(
|
|
1816
|
+
EmptyState,
|
|
1817
|
+
{
|
|
1818
|
+
icon: "lock",
|
|
1819
|
+
title: __14("Sign in to check out"),
|
|
1820
|
+
description: __14("You need an account to place an order with this store."),
|
|
1821
|
+
card: true,
|
|
1822
|
+
"data-checkout-sign-in-required": "",
|
|
1823
|
+
children: [
|
|
1824
|
+
null !== urls.login ? /* @__PURE__ */ jsx13(Button8, { href: urls.login, color: "primary", "data-checkout-login": "", children: __14("Sign in") }) : null,
|
|
1825
|
+
null !== urls.register ? /* @__PURE__ */ jsx13(
|
|
1826
|
+
Button8,
|
|
1827
|
+
{
|
|
1828
|
+
variant: "outline",
|
|
1829
|
+
color: "neutral",
|
|
1830
|
+
href: urls.register,
|
|
1831
|
+
"data-checkout-register": "",
|
|
1832
|
+
children: __14("Create an account")
|
|
1833
|
+
}
|
|
1834
|
+
) : null
|
|
1835
|
+
]
|
|
1836
|
+
}
|
|
1837
|
+
)
|
|
1838
|
+
] });
|
|
1839
|
+
}
|
|
1840
|
+
if (null !== props.placement) {
|
|
1841
|
+
return /* @__PURE__ */ jsx13(Placement, { placement: props.placement });
|
|
1842
|
+
}
|
|
1843
|
+
return /* @__PURE__ */ jsx13(CheckoutSteps, {});
|
|
1844
|
+
}
|
|
1845
|
+
function Checkout(props) {
|
|
1846
|
+
const state = useCheckoutState(props, usePageErrors());
|
|
1847
|
+
return /* @__PURE__ */ jsx13(CheckoutProvider, { value: state, children: /* @__PURE__ */ jsxs11("div", { className: "ec-checkout", "data-ecommerce-checkout": "", "data-checkout-layout": props.layout, children: [
|
|
1848
|
+
/* @__PURE__ */ jsx13(
|
|
1849
|
+
"p",
|
|
1850
|
+
{
|
|
1851
|
+
className: "apui-sr-only",
|
|
1852
|
+
role: "status",
|
|
1853
|
+
"aria-live": "polite",
|
|
1854
|
+
"aria-atomic": "true",
|
|
1855
|
+
"data-checkout-announcement": "",
|
|
1856
|
+
children: props.status.announcement
|
|
1857
|
+
}
|
|
1858
|
+
),
|
|
1859
|
+
/* @__PURE__ */ jsx13(CheckoutBody, {})
|
|
1860
|
+
] }) });
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
export {
|
|
1864
|
+
usePaymentDriver,
|
|
1865
|
+
RedirectPayment,
|
|
1866
|
+
stripeAppearance,
|
|
1867
|
+
createStripePaymentElementDriver,
|
|
1868
|
+
StripePayment,
|
|
1869
|
+
CORE_PAYMENT_DRIVERS,
|
|
1870
|
+
registerPaymentDrivers,
|
|
1871
|
+
requestStepFocus,
|
|
1872
|
+
stepUrl,
|
|
1873
|
+
useCheckout,
|
|
1874
|
+
CheckoutErrorSummary,
|
|
1875
|
+
CheckoutOrderSummary,
|
|
1876
|
+
addressLines,
|
|
1877
|
+
shipToLine,
|
|
1878
|
+
CheckoutStepSummary,
|
|
1879
|
+
PaymentDriverHost,
|
|
1880
|
+
Placement,
|
|
1881
|
+
AddressStep,
|
|
1882
|
+
ContactStep,
|
|
1883
|
+
PaymentStep,
|
|
1884
|
+
ReviewStep,
|
|
1885
|
+
ShippingStep,
|
|
1886
|
+
Checkout
|
|
1887
|
+
};
|
|
1888
|
+
//# sourceMappingURL=chunk-5UUNH3EH.mjs.map
|