@aglyn/plugins-commerce 1.0.0-beta.288 → 1.0.0-beta.290

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.
Files changed (129) hide show
  1. package/README.md +2 -2
  2. package/package.json +13 -13
  3. package/src/lib/components/commerce-console-page.js +29 -2
  4. package/src/lib/components/commerce-console-page.js.map +1 -1
  5. package/src/lib/components/console/commerce-analytics-card.component.js +4 -2
  6. package/src/lib/components/console/commerce-analytics-card.component.js.map +1 -1
  7. package/src/lib/components/console/commerce-pdf-download.d.ts +30 -0
  8. package/src/lib/components/console/commerce-pdf-download.js +53 -0
  9. package/src/lib/components/console/commerce-pdf-download.js.map +1 -0
  10. package/src/lib/components/console/host-orders-card.component.js +5 -1
  11. package/src/lib/components/console/host-orders-card.component.js.map +1 -1
  12. package/src/lib/components/console/host-quotes-card.component.d.ts +34 -0
  13. package/src/lib/components/console/host-quotes-card.component.js +263 -0
  14. package/src/lib/components/console/host-quotes-card.component.js.map +1 -0
  15. package/src/lib/components/console/order-invoice.component.d.ts +6 -4
  16. package/src/lib/components/console/order-invoice.component.js +67 -11
  17. package/src/lib/components/console/order-invoice.component.js.map +1 -1
  18. package/src/lib/components/console/pos-ops/pos-check-ins-card.component.js +33 -28
  19. package/src/lib/components/console/pos-ops/pos-check-ins-card.component.js.map +1 -1
  20. package/src/lib/components/console/quote-editor-dialog.component.d.ts +45 -0
  21. package/src/lib/components/console/quote-editor-dialog.component.js +1317 -0
  22. package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -0
  23. package/src/lib/components/console/quote-pay-link.component.d.ts +38 -0
  24. package/src/lib/components/console/quote-pay-link.component.js +213 -0
  25. package/src/lib/components/console/quote-pay-link.component.js.map +1 -0
  26. package/src/lib/components/console/quote-proofs.component.d.ts +37 -0
  27. package/src/lib/components/console/quote-proofs.component.js +626 -0
  28. package/src/lib/components/console/quote-proofs.component.js.map +1 -0
  29. package/src/lib/components/console/quote-settings-card.component.d.ts +29 -0
  30. package/src/lib/components/console/quote-settings-card.component.js +121 -0
  31. package/src/lib/components/console/quote-settings-card.component.js.map +1 -0
  32. package/src/lib/components/console/tax-settings-card.component.js +4 -1
  33. package/src/lib/components/console/tax-settings-card.component.js.map +1 -1
  34. package/src/lib/components/quote-page-body.d.ts +33 -0
  35. package/src/lib/components/quote-page-body.js +724 -0
  36. package/src/lib/components/quote-page-body.js.map +1 -0
  37. package/src/lib/components/quote-page.d.ts +29 -0
  38. package/src/lib/components/quote-page.js +96 -0
  39. package/src/lib/components/quote-page.js.map +1 -0
  40. package/src/lib/components/quote-proof-panel.d.ts +42 -0
  41. package/src/lib/components/quote-proof-panel.js +436 -0
  42. package/src/lib/components/quote-proof-panel.js.map +1 -0
  43. package/src/lib/components/storefront-payment-element.d.ts +7 -1
  44. package/src/lib/components/storefront-payment-element.js +8 -3
  45. package/src/lib/components/storefront-payment-element.js.map +1 -1
  46. package/src/lib/constants/orders-list-query.js +6 -1
  47. package/src/lib/constants/orders-list-query.js.map +1 -1
  48. package/src/lib/constants/quote-page.d.ts +30 -0
  49. package/src/lib/constants/quote-page.js +35 -0
  50. package/src/lib/constants/quote-page.js.map +1 -0
  51. package/src/lib/model/commerce-orders.d.ts +25 -2
  52. package/src/lib/model/commerce-orders.js +10 -1
  53. package/src/lib/model/commerce-orders.js.map +1 -1
  54. package/src/lib/model/commerce-quote-pay.d.ts +256 -0
  55. package/src/lib/model/commerce-quote-pay.js +426 -0
  56. package/src/lib/model/commerce-quote-pay.js.map +1 -0
  57. package/src/lib/model/commerce-quote-proofs.d.ts +159 -0
  58. package/src/lib/model/commerce-quote-proofs.js +348 -0
  59. package/src/lib/model/commerce-quote-proofs.js.map +1 -0
  60. package/src/lib/model/commerce-quotes.d.ts +335 -0
  61. package/src/lib/model/commerce-quotes.js +522 -0
  62. package/src/lib/model/commerce-quotes.js.map +1 -0
  63. package/src/lib/model/index.d.ts +3 -0
  64. package/src/lib/model/index.js +3 -0
  65. package/src/lib/model/index.js.map +1 -1
  66. package/src/lib/model/plugin-permissions.d.ts +1 -1
  67. package/src/lib/model/plugin-permissions.js +20 -0
  68. package/src/lib/model/plugin-permissions.js.map +1 -1
  69. package/src/lib/server/api-v1/orders-and-products.js +6 -2
  70. package/src/lib/server/api-v1/orders-and-products.js.map +1 -1
  71. package/src/lib/server/billing-webhook.js +127 -52
  72. package/src/lib/server/billing-webhook.js.map +1 -1
  73. package/src/lib/server/checkout-session-expiry.d.ts +36 -0
  74. package/src/lib/server/checkout-session-expiry.js +63 -0
  75. package/src/lib/server/checkout-session-expiry.js.map +1 -0
  76. package/src/lib/server/commerce-pdf.d.ts +100 -0
  77. package/src/lib/server/commerce-pdf.js +283 -0
  78. package/src/lib/server/commerce-pdf.js.map +1 -0
  79. package/src/lib/server/draft-order.js +16 -8
  80. package/src/lib/server/draft-order.js.map +1 -1
  81. package/src/lib/server/order-print.d.ts +6 -0
  82. package/src/lib/server/order-print.js +22 -5
  83. package/src/lib/server/order-print.js.map +1 -1
  84. package/src/lib/server/pdf-response.d.ts +31 -0
  85. package/src/lib/server/pdf-response.js +30 -0
  86. package/src/lib/server/pdf-response.js.map +1 -0
  87. package/src/lib/server/person-eraser.d.ts +7 -0
  88. package/src/lib/server/person-eraser.js +24 -2
  89. package/src/lib/server/person-eraser.js.map +1 -1
  90. package/src/lib/server/pos-reader-splash.d.ts +2 -18
  91. package/src/lib/server/pos-reader-splash.js +8 -93
  92. package/src/lib/server/pos-reader-splash.js.map +1 -1
  93. package/src/lib/server/pos-return.js +3 -1
  94. package/src/lib/server/pos-return.js.map +1 -1
  95. package/src/lib/server/quote-link-token.d.ts +39 -0
  96. package/src/lib/server/quote-link-token.js +97 -0
  97. package/src/lib/server/quote-link-token.js.map +1 -0
  98. package/src/lib/server/quote-pay.d.ts +110 -0
  99. package/src/lib/server/quote-pay.js +606 -0
  100. package/src/lib/server/quote-pay.js.map +1 -0
  101. package/src/lib/server/quote-proofs.d.ts +51 -0
  102. package/src/lib/server/quote-proofs.js +500 -0
  103. package/src/lib/server/quote-proofs.js.map +1 -0
  104. package/src/lib/server/quote-uploads.d.ts +33 -0
  105. package/src/lib/server/quote-uploads.js +29 -0
  106. package/src/lib/server/quote-uploads.js.map +1 -0
  107. package/src/lib/server/quote.d.ts +63 -0
  108. package/src/lib/server/quote.js +846 -0
  109. package/src/lib/server/quote.js.map +1 -0
  110. package/src/lib/server/related.js +2 -0
  111. package/src/lib/server/related.js.map +1 -1
  112. package/src/lib/server/site-image-source.d.ts +38 -0
  113. package/src/lib/server/site-image-source.js +130 -0
  114. package/src/lib/server/site-image-source.js.map +1 -0
  115. package/src/lib/server/site-page-resolver.d.ts +2 -0
  116. package/src/lib/server/site-page-resolver.js +75 -0
  117. package/src/lib/server/site-page-resolver.js.map +1 -1
  118. package/src/lib/server.js +33 -1
  119. package/src/lib/server.js.map +1 -1
  120. package/src/lib/site.js +6 -0
  121. package/src/lib/site.js.map +1 -1
  122. package/src/lib/transfer/tracking.server.js +6 -0
  123. package/src/lib/transfer/tracking.server.js.map +1 -1
  124. package/src/lib/utils/commerce-document-pdf.d.ts +77 -0
  125. package/src/lib/utils/commerce-document-pdf.js +608 -0
  126. package/src/lib/utils/commerce-document-pdf.js.map +1 -0
  127. package/src/lib/utils/order-invoice.d.ts +52 -3
  128. package/src/lib/utils/order-invoice.js +116 -64
  129. package/src/lib/utils/order-invoice.js.map +1 -1
@@ -0,0 +1,724 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
3
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
4
+ /**
5
+ * @license
6
+ * Copyright 2026 Aglyn LLC
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */ import * as Aglyn from "@aglyn/aglyn";
20
+ import Alert from "@mui/material/Alert";
21
+ import Box from "@mui/material/Box";
22
+ import Button from "@mui/material/Button";
23
+ import Chip from "@mui/material/Chip";
24
+ import CircularProgress from "@mui/material/CircularProgress";
25
+ import Divider from "@mui/material/Divider";
26
+ import Paper from "@mui/material/Paper";
27
+ import Stack from "@mui/material/Stack";
28
+ import Typography from "@mui/material/Typography";
29
+ import { forwardRef, lazy, Suspense, useCallback, useEffect, useRef, useState } from "react";
30
+ import { formatOrderMoney, readStorefrontCheckoutWallets } from "../model/index.js";
31
+ import { QuoteProofPanel } from "./quote-proof-panel.js";
32
+ import { StorefrontPaymentElementFallback } from "./storefront-payment-element-fallback.js";
33
+ /** The Payment Element, lazily: Stripe.js loads only when a customer presses Pay. */ const StorefrontPaymentElement = /*#__PURE__*/ lazy(()=>import("./storefront-payment-element.js").then((module)=>({
34
+ default: module.StorefrontPaymentElement
35
+ })));
36
+ /** After a payment returns here, how often and how long the page asks whether it landed. */ const CONFIRM_POLL_MS = 2000;
37
+ const CONFIRM_POLLS = 15;
38
+ function dateLabel(atMs) {
39
+ if (!atMs) return '';
40
+ return new Date(atMs).toLocaleDateString(undefined, {
41
+ month: 'short',
42
+ day: 'numeric',
43
+ year: 'numeric'
44
+ });
45
+ }
46
+ function addressLines(address) {
47
+ const cityLine = [
48
+ address.city,
49
+ [
50
+ address.state,
51
+ address.postalCode
52
+ ].filter(Boolean).join(' ')
53
+ ].filter(Boolean).join(', ');
54
+ return [
55
+ address.name,
56
+ address.line1,
57
+ address.line2,
58
+ cityLine,
59
+ address.country
60
+ ].filter((line)=>Boolean(line));
61
+ }
62
+ function stripeContact(address) {
63
+ if (!(address == null ? void 0 : address.country)) return undefined;
64
+ return {
65
+ name: address.name,
66
+ address: {
67
+ country: address.country,
68
+ line1: address.line1,
69
+ line2: address.line2,
70
+ city: address.city,
71
+ state: address.state,
72
+ postal_code: address.postalCode
73
+ }
74
+ };
75
+ }
76
+ function AddressBlock({ label, lines }) {
77
+ return /*#__PURE__*/ _jsxs(Stack, {
78
+ spacing: 0.25,
79
+ sx: {
80
+ minWidth: 0,
81
+ flex: 1
82
+ },
83
+ children: [
84
+ /*#__PURE__*/ _jsx(Typography, {
85
+ variant: "overline",
86
+ color: "text.secondary",
87
+ children: label
88
+ }),
89
+ lines.map((line, index)=>/*#__PURE__*/ _jsx(Typography, {
90
+ variant: "body2",
91
+ children: line
92
+ }, index))
93
+ ]
94
+ });
95
+ }
96
+ function TotalRow({ label, value, strong }) {
97
+ return /*#__PURE__*/ _jsxs(Stack, {
98
+ direction: "row",
99
+ spacing: 2,
100
+ sx: {
101
+ justifyContent: 'space-between'
102
+ },
103
+ children: [
104
+ /*#__PURE__*/ _jsx(Typography, {
105
+ variant: strong ? 'subtitle1' : 'body2',
106
+ color: strong ? 'text.primary' : 'text.secondary',
107
+ children: label
108
+ }),
109
+ /*#__PURE__*/ _jsx(Typography, {
110
+ variant: strong ? 'subtitle1' : 'body2',
111
+ color: strong ? 'text.primary' : 'text.secondary',
112
+ children: value
113
+ })
114
+ ]
115
+ });
116
+ }
117
+ /**
118
+ * The customer's quote page (AGL-4094), loaded when the page draws it (see
119
+ * `quote-page.tsx`): what a customer sees when they open
120
+ * the pay link a business sent them. The commerce page resolver serves it at
121
+ * `/pay-quote` inside the site's own header and footer; a business can also
122
+ * place it on a page of their own design at that address.
123
+ *
124
+ * The quote is read AFTER hydration from `?q=&t=`, so the page itself is the
125
+ * same for every customer and may be cached, and the quote never is. Pay asks
126
+ * the server for a fresh payment for the quote as the page shows it: Stripe's
127
+ * own page, or the payment form here when in-page payments are on. Nothing
128
+ * here decides a quote is paid; after paying, the page reads that from the
129
+ * server like any other visit.
130
+ */ const QuotePageBody = /*#__PURE__*/ forwardRef((props, ref)=>{
131
+ const { heading } = props, rest = _object_without_properties_loose(props, [
132
+ "heading"
133
+ ]);
134
+ const nodeSx = Array.isArray(props['sx']) ? props['sx'] : [
135
+ props['sx']
136
+ ];
137
+ const { hostId } = Aglyn.useSite();
138
+ const siteFetch = Aglyn.useSiteFetch();
139
+ const [state, setState] = useState({
140
+ kind: 'loading'
141
+ });
142
+ const [paying, setPaying] = useState(false);
143
+ const [payError, setPayError] = useState('');
144
+ const [nativeCheckout, setNativeCheckout] = useState(null);
145
+ /** What a return from paying turned out to be: still being confirmed, or not paid. */ const [returned, setReturned] = useState(null);
146
+ const link = useRef({
147
+ quoteId: '',
148
+ token: '',
149
+ sessionId: ''
150
+ });
151
+ const load = useCallback(async ()=>{
152
+ const { quoteId, token } = link.current;
153
+ try {
154
+ var _payload_storeName;
155
+ const response = await siteFetch(`/api/commerce/quote-view?hostId=${encodeURIComponent(hostId != null ? hostId : '')}` + `&q=${encodeURIComponent(quoteId)}&t=${encodeURIComponent(token)}`);
156
+ const payload = await response.json().catch(()=>({}));
157
+ if (!response.ok) {
158
+ var _ref;
159
+ return {
160
+ kind: 'missing',
161
+ message: String((_ref = payload == null ? void 0 : payload.error) != null ? _ref : 'We could not find that quote.')
162
+ };
163
+ }
164
+ if ((payload == null ? void 0 : payload.state) === 'replaced') return {
165
+ kind: 'replaced',
166
+ storeName: String((_payload_storeName = payload.storeName) != null ? _payload_storeName : '')
167
+ };
168
+ return {
169
+ kind: 'ready',
170
+ view: payload
171
+ };
172
+ } catch (unused) {
173
+ return {
174
+ kind: 'missing',
175
+ message: 'This quote could not be loaded. Check your connection and try again.'
176
+ };
177
+ }
178
+ }, [
179
+ hostId,
180
+ siteFetch
181
+ ]);
182
+ useEffect(()=>{
183
+ var _params_get, _params_get1, _params_get2;
184
+ if (!hostId) return;
185
+ const params = new URLSearchParams(window.location.search);
186
+ link.current = {
187
+ quoteId: (_params_get = params.get('q')) != null ? _params_get : '',
188
+ token: (_params_get1 = params.get('t')) != null ? _params_get1 : '',
189
+ sessionId: (_params_get2 = params.get('session_id')) != null ? _params_get2 : ''
190
+ };
191
+ if (!link.current.quoteId || !link.current.token) {
192
+ setState({
193
+ kind: 'missing',
194
+ message: 'Open this page from the link you were sent with your quote.'
195
+ });
196
+ return;
197
+ }
198
+ let live = true;
199
+ void (async ()=>{
200
+ const first = await load();
201
+ if (!live) return;
202
+ setState(first);
203
+ const sessionId = link.current.sessionId;
204
+ if (first.kind !== 'ready' || first.view.status !== 'unpaid' || !sessionId) return;
205
+ // Back from paying: the payment may have landed before the record of it.
206
+ const status = await siteFetch(`/api/commerce/checkout-status?hostId=${encodeURIComponent(hostId)}` + `&sessionId=${encodeURIComponent(sessionId)}`).then((response)=>response.ok ? response.json() : null).catch(()=>null);
207
+ if (!live) return;
208
+ if ((status == null ? void 0 : status.status) === 'open') {
209
+ setReturned('failed');
210
+ return;
211
+ }
212
+ if ((status == null ? void 0 : status.status) !== 'complete') return;
213
+ setReturned('confirming');
214
+ for(let poll = 0; poll < CONFIRM_POLLS && live; poll++){
215
+ await new Promise((resolve)=>setTimeout(resolve, CONFIRM_POLL_MS));
216
+ if (!live) return;
217
+ const next = await load();
218
+ if (!live) return;
219
+ if (next.kind === 'ready' && next.view.status !== 'unpaid') {
220
+ setState(next);
221
+ setReturned(null);
222
+ return;
223
+ }
224
+ }
225
+ if (live) setReturned('unconfirmed');
226
+ })();
227
+ return ()=>{
228
+ live = false;
229
+ };
230
+ }, [
231
+ hostId,
232
+ load,
233
+ siteFetch
234
+ ]);
235
+ const view = state.kind === 'ready' ? state.view : null;
236
+ const pay = useCallback(async ()=>{
237
+ var _ref;
238
+ var _globalThis_crypto_randomUUID, _globalThis_crypto;
239
+ if (!view || paying) return;
240
+ setPaying(true);
241
+ setPayError('');
242
+ setReturned(null);
243
+ // One key per press: a press is one attempt, and a retry after a failure is a new one.
244
+ const attemptKey = (_ref = (_globalThis_crypto = globalThis.crypto) == null ? void 0 : (_globalThis_crypto_randomUUID = _globalThis_crypto.randomUUID) == null ? void 0 : _globalThis_crypto_randomUUID.call(_globalThis_crypto)) != null ? _ref : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
245
+ try {
246
+ var _ref1;
247
+ const response = await siteFetch('/api/commerce/quote-pay', {
248
+ method: 'POST',
249
+ headers: {
250
+ 'Content-Type': 'application/json',
251
+ 'Idempotency-Key': attemptKey
252
+ },
253
+ body: JSON.stringify({
254
+ hostId,
255
+ q: link.current.quoteId,
256
+ t: link.current.token,
257
+ v: view.version
258
+ })
259
+ });
260
+ const payload = await response.json().catch(()=>({}));
261
+ // A session with a client secret is the in-page form; checked before the
262
+ // redirect, so a form is never navigated away from.
263
+ if (response.ok && (payload == null ? void 0 : payload.clientSecret) && (payload == null ? void 0 : payload.publishableKey)) {
264
+ setNativeCheckout({
265
+ clientSecret: String(payload.clientSecret),
266
+ publishableKey: String(payload.publishableKey),
267
+ wallets: readStorefrontCheckoutWallets(payload.wallets)
268
+ });
269
+ setPaying(false);
270
+ return;
271
+ }
272
+ if (response.ok && (payload == null ? void 0 : payload.url)) {
273
+ window.location.assign(String(payload.url));
274
+ return;
275
+ }
276
+ if (payload == null ? void 0 : payload.replaced) {
277
+ setState({
278
+ kind: 'replaced',
279
+ storeName: view.storeName
280
+ });
281
+ return;
282
+ }
283
+ if ((payload == null ? void 0 : payload.reason) === 'paid' || (payload == null ? void 0 : payload.reason) === 'updated') {
284
+ const next = await load();
285
+ setState(next);
286
+ }
287
+ setPayError(String((_ref1 = payload == null ? void 0 : payload.error) != null ? _ref1 : 'Your payment could not be set up. Try again.'));
288
+ setPaying(false);
289
+ } catch (unused) {
290
+ setPayError('Your payment could not be set up. Check your connection and try again.');
291
+ setPaying(false);
292
+ }
293
+ }, [
294
+ view,
295
+ paying,
296
+ siteFetch,
297
+ hostId,
298
+ load
299
+ ]);
300
+ if (!hostId) {
301
+ return /*#__PURE__*/ _jsx(Box, _extends({
302
+ ref: ref
303
+ }, rest, {
304
+ sx: [
305
+ {
306
+ p: 3,
307
+ border: '1px dashed',
308
+ borderColor: 'divider',
309
+ borderRadius: 1
310
+ },
311
+ ...nodeSx
312
+ ],
313
+ children: /*#__PURE__*/ _jsx(Typography, {
314
+ variant: "body2",
315
+ color: "text.secondary",
316
+ children: 'Quote — a customer’s quote and its Pay button render here'
317
+ })
318
+ }));
319
+ }
320
+ if (state.kind === 'loading') {
321
+ return /*#__PURE__*/ _jsx(Box, _extends({
322
+ ref: ref
323
+ }, rest, {
324
+ sx: [
325
+ {
326
+ py: 6,
327
+ textAlign: 'center'
328
+ },
329
+ ...nodeSx
330
+ ],
331
+ children: /*#__PURE__*/ _jsx(CircularProgress, {
332
+ size: 28,
333
+ "aria-label": "Loading your quote"
334
+ })
335
+ }));
336
+ }
337
+ if (state.kind === 'missing') {
338
+ return /*#__PURE__*/ _jsx(Box, _extends({
339
+ ref: ref
340
+ }, rest, {
341
+ sx: nodeSx,
342
+ children: /*#__PURE__*/ _jsxs(Stack, {
343
+ spacing: 2,
344
+ children: [
345
+ /*#__PURE__*/ _jsx(Typography, {
346
+ variant: "h4",
347
+ component: "h1",
348
+ children: heading || 'Your quote'
349
+ }),
350
+ /*#__PURE__*/ _jsx(Alert, {
351
+ severity: "info",
352
+ children: state.message
353
+ })
354
+ ]
355
+ })
356
+ }));
357
+ }
358
+ if (state.kind === 'replaced') {
359
+ const business = state.storeName || 'The business';
360
+ return /*#__PURE__*/ _jsx(Box, _extends({
361
+ ref: ref
362
+ }, rest, {
363
+ sx: nodeSx,
364
+ children: /*#__PURE__*/ _jsxs(Stack, {
365
+ spacing: 2,
366
+ children: [
367
+ state.storeName ? /*#__PURE__*/ _jsx(Typography, {
368
+ variant: "overline",
369
+ color: "text.secondary",
370
+ children: state.storeName
371
+ }) : null,
372
+ /*#__PURE__*/ _jsx(Typography, {
373
+ variant: "h4",
374
+ component: "h1",
375
+ children: 'This quote was updated'
376
+ }),
377
+ /*#__PURE__*/ _jsx(Typography, {
378
+ variant: "body1",
379
+ color: "text.secondary",
380
+ children: `${business} updated this quote and sent you a newer link. Open their most recent message to see it.`
381
+ })
382
+ ]
383
+ })
384
+ }));
385
+ }
386
+ const quote = state.view;
387
+ const money = (cents)=>formatOrderMoney(cents, quote.currency);
388
+ // The same signed link as the page's data; the server makes the PDF from the same view.
389
+ const pdfHref = `/api/commerce/quote-pdf?hostId=${encodeURIComponent(hostId)}` + `&q=${encodeURIComponent(link.current.quoteId)}&t=${encodeURIComponent(link.current.token)}`;
390
+ const unpaid = quote.status === 'unpaid';
391
+ const addresses = [
392
+ quote.customerName || quote.company ? {
393
+ label: 'Prepared for',
394
+ lines: [
395
+ quote.customerName,
396
+ quote.company
397
+ ].filter((line)=>Boolean(line))
398
+ } : null,
399
+ quote.billTo ? {
400
+ label: 'Bill to',
401
+ lines: addressLines(quote.billTo)
402
+ } : null,
403
+ quote.shipTo ? {
404
+ label: 'Ship to',
405
+ lines: addressLines(quote.shipTo)
406
+ } : null
407
+ ].filter((block)=>Boolean(block && block.lines.length));
408
+ const totalRows = [
409
+ [
410
+ 'Subtotal',
411
+ money(quote.totals.itemsCents),
412
+ true
413
+ ],
414
+ [
415
+ quote.discountLabel ? `Discount (${quote.discountLabel})` : 'Discount',
416
+ `−${money(quote.totals.discountCents)}`,
417
+ quote.totals.discountCents > 0
418
+ ],
419
+ [
420
+ 'Shipping',
421
+ money(quote.totals.shippingCents),
422
+ quote.totals.shippingCents > 0
423
+ ],
424
+ [
425
+ quote.taxLabel,
426
+ money(quote.totals.taxCents),
427
+ quote.totals.taxCents > 0
428
+ ],
429
+ // `Tax is added at payment`, with no figure: Stripe works it out from the address.
430
+ [
431
+ quote.taxLabel,
432
+ '',
433
+ quote.taxAtPayment
434
+ ]
435
+ ].filter(([, , shown])=>shown);
436
+ return /*#__PURE__*/ _jsx(Box, _extends({
437
+ ref: ref
438
+ }, rest, {
439
+ sx: nodeSx,
440
+ children: /*#__PURE__*/ _jsxs(Stack, {
441
+ spacing: 3,
442
+ children: [
443
+ /*#__PURE__*/ _jsxs(Stack, {
444
+ spacing: 1,
445
+ children: [
446
+ quote.storeName ? /*#__PURE__*/ _jsx(Typography, {
447
+ variant: "overline",
448
+ color: "text.secondary",
449
+ children: quote.storeName
450
+ }) : null,
451
+ /*#__PURE__*/ _jsxs(Stack, {
452
+ direction: "row",
453
+ spacing: 1.5,
454
+ sx: {
455
+ alignItems: 'center',
456
+ flexWrap: 'wrap',
457
+ rowGap: 1
458
+ },
459
+ children: [
460
+ /*#__PURE__*/ _jsx(Typography, {
461
+ variant: "h4",
462
+ component: "h1",
463
+ children: heading || quote.number
464
+ }),
465
+ /*#__PURE__*/ _jsx(Chip, {
466
+ label: quote.statusLabel,
467
+ color: quote.status === 'paid' ? 'success' : unpaid ? 'primary' : 'default',
468
+ size: "small"
469
+ })
470
+ ]
471
+ }),
472
+ quote.dateMs ? /*#__PURE__*/ _jsx(Typography, {
473
+ variant: "body2",
474
+ color: "text.secondary",
475
+ children: `Dated ${dateLabel(quote.dateMs)}`
476
+ }) : null,
477
+ /*#__PURE__*/ _jsx(Box, {
478
+ children: /*#__PURE__*/ _jsx(Button, {
479
+ variant: "outlined",
480
+ size: "small",
481
+ href: pdfHref,
482
+ download: true,
483
+ children: 'Download PDF'
484
+ })
485
+ })
486
+ ]
487
+ }),
488
+ addresses.length ? /*#__PURE__*/ _jsx(Stack, {
489
+ direction: {
490
+ xs: 'column',
491
+ sm: 'row'
492
+ },
493
+ spacing: {
494
+ xs: 2,
495
+ sm: 3
496
+ },
497
+ children: addresses.map((block)=>/*#__PURE__*/ _jsx(AddressBlock, {
498
+ label: block.label,
499
+ lines: block.lines
500
+ }, block.label))
501
+ }) : null,
502
+ /*#__PURE__*/ _jsxs(Stack, {
503
+ spacing: 1.5,
504
+ children: [
505
+ /*#__PURE__*/ _jsx(Typography, {
506
+ variant: "h6",
507
+ component: "h2",
508
+ children: 'Items'
509
+ }),
510
+ quote.lines.map((line, index)=>/*#__PURE__*/ _jsxs(Stack, {
511
+ direction: "row",
512
+ spacing: 2,
513
+ sx: {
514
+ justifyContent: 'space-between'
515
+ },
516
+ children: [
517
+ /*#__PURE__*/ _jsxs(Stack, {
518
+ spacing: 0.25,
519
+ sx: {
520
+ minWidth: 0
521
+ },
522
+ children: [
523
+ /*#__PURE__*/ _jsxs(Typography, {
524
+ variant: "body2",
525
+ children: [
526
+ line.name,
527
+ line.variantLabel ? ` (${line.variantLabel})` : ''
528
+ ]
529
+ }),
530
+ line.description ? /*#__PURE__*/ _jsx(Typography, {
531
+ variant: "body2",
532
+ color: "text.secondary",
533
+ sx: {
534
+ whiteSpace: 'pre-line'
535
+ },
536
+ children: line.description
537
+ }) : null,
538
+ /*#__PURE__*/ _jsx(Typography, {
539
+ variant: "caption",
540
+ color: "text.secondary",
541
+ children: [
542
+ line.included ? `${line.quantity} included` : `${line.quantity} × ${money(line.unitAmountCents)}`,
543
+ line.sku ? `SKU ${line.sku}` : ''
544
+ ].filter(Boolean).join(' · ')
545
+ })
546
+ ]
547
+ }),
548
+ /*#__PURE__*/ _jsx(Typography, {
549
+ variant: "body2",
550
+ sx: {
551
+ flexShrink: 0
552
+ },
553
+ children: line.included ? 'Included' : money(line.amountCents)
554
+ })
555
+ ]
556
+ }, index)),
557
+ /*#__PURE__*/ _jsx(Divider, {}),
558
+ totalRows.map(([label, value])=>/*#__PURE__*/ _jsx(TotalRow, {
559
+ label: label,
560
+ value: value
561
+ }, `${label}-${value}`)),
562
+ /*#__PURE__*/ _jsx(TotalRow, {
563
+ label: "Total",
564
+ value: money(quote.totals.totalCents),
565
+ strong: true
566
+ })
567
+ ]
568
+ }),
569
+ quote.notes ? /*#__PURE__*/ _jsxs(Stack, {
570
+ spacing: 0.5,
571
+ children: [
572
+ /*#__PURE__*/ _jsx(Typography, {
573
+ variant: "h6",
574
+ component: "h2",
575
+ children: 'Notes'
576
+ }),
577
+ /*#__PURE__*/ _jsx(Typography, {
578
+ variant: "body2",
579
+ sx: {
580
+ whiteSpace: 'pre-line'
581
+ },
582
+ children: quote.notes
583
+ })
584
+ ]
585
+ }) : null,
586
+ quote.terms ? /*#__PURE__*/ _jsxs(Stack, {
587
+ spacing: 0.5,
588
+ children: [
589
+ /*#__PURE__*/ _jsx(Typography, {
590
+ variant: "h6",
591
+ component: "h2",
592
+ children: 'Terms'
593
+ }),
594
+ /*#__PURE__*/ _jsx(Typography, {
595
+ variant: "body2",
596
+ color: "text.secondary",
597
+ sx: {
598
+ whiteSpace: 'pre-line'
599
+ },
600
+ children: quote.terms
601
+ })
602
+ ]
603
+ }) : null,
604
+ /*#__PURE__*/ _jsx(QuoteProofPanel, {
605
+ view: quote,
606
+ hostId: hostId,
607
+ quoteId: link.current.quoteId,
608
+ token: link.current.token,
609
+ siteFetch: siteFetch,
610
+ onView: (next)=>setState({
611
+ kind: 'ready',
612
+ view: next
613
+ }),
614
+ onReload: ()=>void load().then(setState),
615
+ onReplaced: ()=>setState({
616
+ kind: 'replaced',
617
+ storeName: quote.storeName
618
+ })
619
+ }),
620
+ unpaid ? /*#__PURE__*/ _jsx(Paper, {
621
+ variant: "outlined",
622
+ sx: {
623
+ p: {
624
+ xs: 2,
625
+ sm: 3
626
+ }
627
+ },
628
+ children: /*#__PURE__*/ _jsx(Stack, {
629
+ spacing: 2,
630
+ children: returned === 'confirming' ? /*#__PURE__*/ _jsx(Alert, {
631
+ severity: "info",
632
+ icon: /*#__PURE__*/ _jsx(CircularProgress, {
633
+ size: 20
634
+ }),
635
+ children: 'Thank you. We’re confirming your payment.'
636
+ }) : returned === 'unconfirmed' ? /*#__PURE__*/ _jsx(Alert, {
637
+ severity: "info",
638
+ children: 'Your payment is still being confirmed. Your receipt will arrive by email.'
639
+ }) : quote.approvalRequired ? /*#__PURE__*/ _jsx(Alert, {
640
+ severity: "info",
641
+ children: `${quote.storeName || 'The business'} asks you to approve the proof before you pay.`
642
+ }) : quote.payable ? /*#__PURE__*/ _jsxs(_Fragment, {
643
+ children: [
644
+ returned === 'failed' ? /*#__PURE__*/ _jsx(Alert, {
645
+ severity: "warning",
646
+ children: 'Your payment did not go through. Nothing was charged.'
647
+ }) : null,
648
+ nativeCheckout ? /*#__PURE__*/ _jsx(Suspense, {
649
+ fallback: /*#__PURE__*/ _jsx(StorefrontPaymentElementFallback, {}),
650
+ children: /*#__PURE__*/ _jsx(StorefrontPaymentElement, {
651
+ clientSecret: nativeCheckout.clientSecret,
652
+ publishableKey: nativeCheckout.publishableKey,
653
+ wallets: nativeCheckout.wallets,
654
+ payLabel: quote.taxAtPayment ? 'Pay now' : `Pay ${money(quote.totals.totalCents)}`,
655
+ defaultShippingAddress: stripeContact(quote.shipTo),
656
+ // An expired or unloadable session is replaced by a new press.
657
+ onRestart: ()=>{
658
+ setNativeCheckout(null);
659
+ void pay();
660
+ },
661
+ onCancel: ()=>setNativeCheckout(null)
662
+ })
663
+ }) : /*#__PURE__*/ _jsx(Button, {
664
+ variant: "contained",
665
+ size: "large",
666
+ onClick: ()=>void pay(),
667
+ disabled: paying,
668
+ sx: {
669
+ alignSelf: {
670
+ xs: 'stretch',
671
+ sm: 'flex-start'
672
+ }
673
+ },
674
+ children: paying ? 'Opening…' : quote.taxAtPayment ? `Pay ${money(quote.totals.totalCents)} plus tax` : `Pay ${money(quote.totals.totalCents)}`
675
+ }),
676
+ payError ? /*#__PURE__*/ _jsx(Alert, {
677
+ severity: "error",
678
+ children: payError
679
+ }) : null
680
+ ]
681
+ }) : /*#__PURE__*/ _jsx(Alert, {
682
+ severity: "info",
683
+ children: `Contact ${quote.storeName || 'the business'} to pay this quote.`
684
+ })
685
+ })
686
+ }) : /*#__PURE__*/ _jsx(Paper, {
687
+ variant: "outlined",
688
+ sx: {
689
+ p: {
690
+ xs: 2,
691
+ sm: 3
692
+ }
693
+ },
694
+ children: /*#__PURE__*/ _jsxs(Stack, {
695
+ spacing: 1.5,
696
+ sx: {
697
+ alignItems: 'flex-start'
698
+ },
699
+ children: [
700
+ /*#__PURE__*/ _jsx(Typography, {
701
+ variant: "body1",
702
+ children: quote.status === 'paid' ? quote.paidAtMs ? `Paid ${dateLabel(quote.paidAtMs)}. Thank you.` : 'Paid. Thank you.' : `This quote is ${quote.statusLabel.toLowerCase()}.`
703
+ }),
704
+ quote.receiptUrl ? /*#__PURE__*/ _jsx(Button, {
705
+ variant: "outlined",
706
+ href: quote.receiptUrl,
707
+ children: 'View your order'
708
+ }) : null
709
+ ]
710
+ })
711
+ }),
712
+ /*#__PURE__*/ _jsx(Typography, {
713
+ variant: "body2",
714
+ color: "text.secondary",
715
+ children: `Questions about this quote? Contact ${quote.storeName || 'the business'}.`
716
+ })
717
+ ]
718
+ })
719
+ }));
720
+ });
721
+ QuotePageBody.displayName = 'QuotePageBody';
722
+ export default QuotePageBody;
723
+
724
+ //# sourceMappingURL=quote-page-body.js.map