@aglyn/plugins-commerce 1.10.0 → 1.12.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/package.json +13 -13
- package/src/lib/components/console/host-quotes-card.component.js +20 -11
- package/src/lib/components/console/host-quotes-card.component.js.map +1 -1
- package/src/lib/components/console/invoice-send.component.d.ts +9 -2
- package/src/lib/components/console/invoice-send.component.js +58 -30
- package/src/lib/components/console/invoice-send.component.js.map +1 -1
- package/src/lib/components/console/pay-link-readiness-notice.component.d.ts +84 -0
- package/src/lib/components/console/pay-link-readiness-notice.component.js +164 -0
- package/src/lib/components/console/pay-link-readiness-notice.component.js.map +1 -0
- package/src/lib/components/console/pos-kiosk/kiosk-menu.d.ts +10 -3
- package/src/lib/components/console/pos-kiosk/kiosk-menu.js +29 -8
- package/src/lib/components/console/pos-kiosk/kiosk-menu.js.map +1 -1
- package/src/lib/components/console/pos-kiosk/pos-kiosk-api.d.ts +2 -0
- package/src/lib/components/console/pos-kiosk/pos-kiosk-api.js +7 -0
- package/src/lib/components/console/pos-kiosk/pos-kiosk-api.js.map +1 -1
- package/src/lib/components/console/pos-kiosk-page.component.d.ts +2 -0
- package/src/lib/components/console/pos-kiosk-page.component.js +54 -3
- package/src/lib/components/console/pos-kiosk-page.component.js.map +1 -1
- package/src/lib/components/console/product-add-ons-fields.component.d.ts +0 -2
- package/src/lib/components/console/product-add-ons-fields.component.js +1 -6
- package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
- package/src/lib/components/console/quote-editor-dialog.component.d.ts +2 -0
- package/src/lib/components/console/quote-editor-dialog.component.js +35 -27
- package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/quote-pay-link.component.d.ts +3 -0
- package/src/lib/components/console/quote-pay-link.component.js +9 -0
- package/src/lib/components/console/quote-pay-link.component.js.map +1 -1
- package/src/lib/components/console/quote-send.component.d.ts +3 -0
- package/src/lib/components/console/quote-send.component.js +9 -0
- package/src/lib/components/console/quote-send.component.js.map +1 -1
- package/src/lib/components/product-detail.js +1 -1
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/product-grid.js +5 -3
- package/src/lib/components/product-grid.js.map +1 -1
- package/src/lib/components/product-reviews.js +17 -12
- package/src/lib/components/product-reviews.js.map +1 -1
- package/src/lib/components/quote-page-body.js +5 -3
- package/src/lib/components/quote-page-body.js.map +1 -1
- package/src/lib/components/related-products.js +2 -1
- package/src/lib/components/related-products.js.map +1 -1
- package/src/lib/model/commerce-invoices.d.ts +45 -5
- package/src/lib/model/commerce-invoices.js +46 -9
- package/src/lib/model/commerce-invoices.js.map +1 -1
- package/src/lib/model/commerce-kiosk-search.d.ts +22 -0
- package/src/lib/model/commerce-kiosk-search.js +32 -0
- package/src/lib/model/commerce-kiosk-search.js.map +1 -0
- package/src/lib/model/commerce-pos-kiosk.d.ts +7 -1
- package/src/lib/model/commerce-pos-kiosk.js +1 -1
- package/src/lib/model/commerce-pos-kiosk.js.map +1 -1
- package/src/lib/model/commerce-quote-pay.d.ts +110 -6
- package/src/lib/model/commerce-quote-pay.js +182 -23
- package/src/lib/model/commerce-quote-pay.js.map +1 -1
- package/src/lib/model/product-modifiers.d.ts +4 -0
- package/src/lib/model/product-modifiers.js +5 -0
- package/src/lib/model/product-modifiers.js.map +1 -1
- package/src/lib/server/billing-webhook.js +4 -1
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/commerce-pdf.js +2 -1
- package/src/lib/server/commerce-pdf.js.map +1 -1
- package/src/lib/server/invoice-email.js +2 -1
- package/src/lib/server/invoice-email.js.map +1 -1
- package/src/lib/server/order-invoice-send.js +1 -1
- package/src/lib/server/order-invoice-send.js.map +1 -1
- package/src/lib/server/order-status.d.ts +5 -1
- package/src/lib/server/order-status.js +19 -5
- package/src/lib/server/order-status.js.map +1 -1
- package/src/lib/server/pos-kiosk.js +70 -15
- package/src/lib/server/pos-kiosk.js.map +1 -1
- package/src/lib/server/quote-email.js +2 -1
- package/src/lib/server/quote-email.js.map +1 -1
- package/src/lib/server/quote-pay.d.ts +39 -0
- package/src/lib/server/quote-pay.js +103 -43
- package/src/lib/server/quote-pay.js.map +1 -1
- package/src/lib/server/quote-proofs.js +20 -11
- package/src/lib/server/quote-proofs.js.map +1 -1
- package/src/lib/server/site-page-enricher.js +5 -1
- package/src/lib/server/site-page-enricher.js.map +1 -1
- package/src/lib/testing/fake-firestore.js +34 -5
- package/src/lib/testing/fake-firestore.js.map +1 -1
- package/src/lib/transfer/product-register-cells.d.ts +75 -0
- package/src/lib/transfer/product-register-cells.js +487 -0
- package/src/lib/transfer/product-register-cells.js.map +1 -0
- package/src/lib/transfer/product-transfer.d.ts +12 -0
- package/src/lib/transfer/product-transfer.js +174 -10
- package/src/lib/transfer/product-transfer.js.map +1 -1
- package/src/lib/transfer/products.server.js +24 -9
- package/src/lib/transfer/products.server.js.map +1 -1
- package/src/lib/utils/invoice-email-content.d.ts +3 -1
- package/src/lib/utils/invoice-email-content.js +1 -1
- package/src/lib/utils/invoice-email-content.js.map +1 -1
- package/src/lib/utils/quote-email-content.d.ts +3 -1
- package/src/lib/utils/quote-email-content.js +3 -3
- package/src/lib/utils/quote-email-content.js.map +1 -1
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
import type { ProductType } from './commerce';
|
|
18
18
|
import { type HostOrder, type OrderAddress, type OrderLineItem, type OrderStatus } from './commerce-orders';
|
|
19
19
|
import { type OrderQuote, type QuoteDiscount, type QuoteTaxBasis, type QuoteUnmatchedPayment } from './commerce-quotes';
|
|
20
|
-
import type {
|
|
20
|
+
import type { TaxSettings } from './commerce-tax';
|
|
21
|
+
import { type StorefrontTaxMode } from './commerce-tax-decision';
|
|
21
22
|
import { type OrderListFields } from './order-list-fields';
|
|
22
23
|
/** Stripe's smallest card charge; a quote that totals less cannot be paid by card. */
|
|
23
24
|
export declare const QUOTE_MIN_CHARGE_CENTS = 50;
|
|
@@ -32,6 +33,64 @@ export declare function quoteLinkVersion(quote: Pick<OrderQuote, 'linkVersion'>
|
|
|
32
33
|
export declare function orderPayLinkVersion(order: Partial<Pick<HostOrder, 'quote' | 'payLink'>> | null | undefined): number;
|
|
33
34
|
/** Payments the order's pay link could not take: a quote's on the quote, any other order's on `payLink`. */
|
|
34
35
|
export declare function orderPayLinkUnmatched(order: Partial<Pick<HostOrder, 'quote' | 'payLink'>> | null | undefined): QuoteUnmatchedPayment[];
|
|
36
|
+
/**
|
|
37
|
+
* The store a pay link is read against: its sales tax choice, as
|
|
38
|
+
* `hosts/{hostId}/settings/store` keeps it under `tax`. Absent or null, the
|
|
39
|
+
* store has not chosen.
|
|
40
|
+
*/
|
|
41
|
+
export interface PayLinkStore {
|
|
42
|
+
tax?: TaxSettings | null;
|
|
43
|
+
}
|
|
44
|
+
/** The store a pay link reads, from the store settings document's data (nothing, for no document). */
|
|
45
|
+
export declare function payLinkStoreOf(settings: {
|
|
46
|
+
tax?: unknown;
|
|
47
|
+
} | null | undefined): PayLinkStore;
|
|
48
|
+
/** Whether a basis records that nobody had chosen the store's sales tax, which is no choice at all. */
|
|
49
|
+
export declare function quoteTaxIsUndecided(basis: Pick<QuoteTaxBasis, 'kind' | 'reason'> | null | undefined): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Where a quote's tax comes from when it is shown and paid:
|
|
52
|
+
*
|
|
53
|
+
* - `stored`: the basis it was saved with.
|
|
54
|
+
* - `current`: it was saved before the store chose, and takes the store's
|
|
55
|
+
* choice as it stands now.
|
|
56
|
+
* - `save`: it was saved before the store chose, and the store's choice now
|
|
57
|
+
* prices it only when it is saved again.
|
|
58
|
+
*/
|
|
59
|
+
export type QuotePayTaxSource = 'stored' | 'current' | 'save';
|
|
60
|
+
export interface QuotePayTax {
|
|
61
|
+
basis: QuoteTaxBasis;
|
|
62
|
+
source: QuotePayTaxSource;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The tax a quote is shown, charged and paid under (AGL-4162): the one answer
|
|
66
|
+
* the quote page, Pay, the payment's record (carried on its session) and the
|
|
67
|
+
* console's notice all read.
|
|
68
|
+
*
|
|
69
|
+
* A quote keeps the basis it was saved with, except one saved before the
|
|
70
|
+
* store chose how it handles sales tax. That basis records no choice, so the
|
|
71
|
+
* quote takes the store's choice as it stands now, through the same
|
|
72
|
+
* `quoteTaxBasisFromSettings` the editor prices a save with: no sales tax,
|
|
73
|
+
* prices that include tax, or Stripe Tax at payment. Nothing is written for
|
|
74
|
+
* it; the next save stores the same basis.
|
|
75
|
+
*
|
|
76
|
+
* The store's own rates on prices that exclude tax are the one choice not
|
|
77
|
+
* taken this way. On those settings a save asks the site's tax service where
|
|
78
|
+
* one is connected (`priceQuote` in `server/quote.ts`), and only that save
|
|
79
|
+
* knows the figure: which service is connected is the tax service's own to
|
|
80
|
+
* say. Such a quote keeps its basis, and so stays unpaid, until it is saved.
|
|
81
|
+
*
|
|
82
|
+
* Without a store, the stored basis stands.
|
|
83
|
+
*/
|
|
84
|
+
export declare function quotePayTax(quote: Pick<OrderQuote, 'tax' | 'shipTo'> | null | undefined, store?: PayLinkStore | null): QuotePayTax;
|
|
85
|
+
/**
|
|
86
|
+
* A basis as one short string: what the quote page sends back with Pay, so a
|
|
87
|
+
* payment is refused when the tax it would charge is not the tax the page
|
|
88
|
+
* showed, and what a session records as the basis it charged. Equal bases
|
|
89
|
+
* have one key.
|
|
90
|
+
*/
|
|
91
|
+
export declare function quoteTaxBasisKey(basis: QuoteTaxBasis): string;
|
|
92
|
+
/** A basis back from {@link quoteTaxBasisKey}, or null for anything else. */
|
|
93
|
+
export declare function quoteTaxBasisFromKey(key: unknown): QuoteTaxBasis | null;
|
|
35
94
|
/** An address as the quote page prints it: no phone. */
|
|
36
95
|
export interface QuotePageAddress {
|
|
37
96
|
name: string | null;
|
|
@@ -136,6 +195,19 @@ export interface QuotePageView {
|
|
|
136
195
|
approvalRequired: boolean;
|
|
137
196
|
/** A Pay button belongs on the page. */
|
|
138
197
|
payable: boolean;
|
|
198
|
+
/**
|
|
199
|
+
* What the page says in place of Pay when the business can't take payments
|
|
200
|
+
* online right now (AGL-4162): the Pay route's own refusal, word for word.
|
|
201
|
+
* Null otherwise, and the page asks the customer to contact the business.
|
|
202
|
+
*/
|
|
203
|
+
notPayableMessage: string | null;
|
|
204
|
+
/**
|
|
205
|
+
* The tax the quote's totals are priced under ({@link quoteTaxBasisKey}),
|
|
206
|
+
* which Pay sends back as `tax`: a quote whose tax would charge differently
|
|
207
|
+
* from the page is shown again before it is paid (AGL-4162). Null for an
|
|
208
|
+
* invoice, whose tax is fixed when it is made, and once paid.
|
|
209
|
+
*/
|
|
210
|
+
taxKey: string | null;
|
|
139
211
|
/** The revision the page shows (AGL-4096). */
|
|
140
212
|
revision: number;
|
|
141
213
|
/** That revision's proofs. */
|
|
@@ -160,7 +232,10 @@ export declare function quotePageStatus(status: OrderStatus | string | undefined
|
|
|
160
232
|
/**
|
|
161
233
|
* The quote page's view of an order document on the `quote` channel. Totals
|
|
162
234
|
* are the stored lines' through {@link computeQuoteTotals} until the quote is
|
|
163
|
-
* paid, and the paid order's own totals (what Stripe charged) after.
|
|
235
|
+
* paid, and the paid order's own totals (what Stripe charged) after. The tax
|
|
236
|
+
* is {@link quotePayTax}'s for the store given, and Pay belongs on the page
|
|
237
|
+
* only when nothing would refuse it: the store's payments included, when the
|
|
238
|
+
* caller says whether it can take them.
|
|
164
239
|
*/
|
|
165
240
|
export declare function buildQuotePageView(input: {
|
|
166
241
|
order: Pick<HostOrder, 'number' | 'status' | 'lineItems' | 'totals' | 'quote' | 'timeline'>;
|
|
@@ -169,6 +244,10 @@ export declare function buildQuotePageView(input: {
|
|
|
169
244
|
currency: string;
|
|
170
245
|
/** The order's status page, for a paid quote. */
|
|
171
246
|
receiptUrl?: string | null;
|
|
247
|
+
/** The store's sales tax choice, which a quote saved before it was made takes. */
|
|
248
|
+
store?: PayLinkStore | null;
|
|
249
|
+
/** Whether the business can take a card payment now; absent, it is not judged here. */
|
|
250
|
+
paymentsReady?: boolean;
|
|
172
251
|
}): QuotePageView;
|
|
173
252
|
/** Order lines as the pay link's page lists them: what each charges, nothing about stock or cost. */
|
|
174
253
|
export declare function quotePageLines(lines: readonly OrderLineItem[]): QuotePageLine[];
|
|
@@ -207,7 +286,9 @@ export interface QuoteCheckoutCharge {
|
|
|
207
286
|
/**
|
|
208
287
|
* The charge for a quote, from its stored lines, discount, shipping and tax
|
|
209
288
|
* basis through {@link computeQuoteTotals} — the same function that priced it
|
|
210
|
-
* when it was saved, so the page, the session and the stored quote agree.
|
|
289
|
+
* when it was saved, so the page, the session and the stored quote agree. The
|
|
290
|
+
* basis is {@link quotePayTax}'s: a quote saved before the store chose its
|
|
291
|
+
* sales tax is charged under the store's choice now.
|
|
211
292
|
*
|
|
212
293
|
* The goods are charged as at most two lines, the taxed and the tax-exempt,
|
|
213
294
|
* each after its share of the discount. A store rate is applied to the taxed
|
|
@@ -216,7 +297,7 @@ export interface QuoteCheckoutCharge {
|
|
|
216
297
|
* service's figure is carried the same way, as the percentage of the taxed
|
|
217
298
|
* line it amounts to. Included lines charge nothing and are not sent.
|
|
218
299
|
*/
|
|
219
|
-
export declare function quoteCheckoutCharge(order: Pick<HostOrder, 'number' | 'lineItems' | 'quote'>, orderId: string): QuoteCheckoutCharge;
|
|
300
|
+
export declare function quoteCheckoutCharge(order: Pick<HostOrder, 'number' | 'lineItems' | 'quote'>, orderId: string, store?: PayLinkStore | null): QuoteCheckoutCharge;
|
|
220
301
|
/**
|
|
221
302
|
* What a pay link's Checkout Session charges for stored lines, a discount,
|
|
222
303
|
* fixed shipping and a tax basis, under a label (`Quote #1042`,
|
|
@@ -231,8 +312,21 @@ export declare function payLinkCheckoutCharge(input: {
|
|
|
231
312
|
label: string;
|
|
232
313
|
}): QuoteCheckoutCharge;
|
|
233
314
|
export type QuotePayRefusal = 'paid' | 'closed' | 'approval-required' | 'tax-undecided' | 'nothing-to-pay';
|
|
234
|
-
/**
|
|
235
|
-
|
|
315
|
+
/**
|
|
316
|
+
* Why a quote cannot be paid now, or null when it can. With the store, its
|
|
317
|
+
* tax is {@link quotePayTax}'s, and a store that has not chosen its sales tax
|
|
318
|
+
* refuses every sale (AGL-1999), whatever basis the quote was saved with.
|
|
319
|
+
*/
|
|
320
|
+
export declare function quotePayRefusal(order: Pick<HostOrder, 'number' | 'status' | 'lineItems' | 'quote'>, orderId: string, store?: PayLinkStore | null): QuotePayRefusal | null;
|
|
321
|
+
/**
|
|
322
|
+
* A pay link's refusal once the store's payments are judged too: a business
|
|
323
|
+
* that can't take a card payment now outranks every refusal but the ones a
|
|
324
|
+
* payment never gets past (paid, closed, not linked, waiting on the
|
|
325
|
+
* customer's approval). `paymentsReady` absent leaves the refusal as it is.
|
|
326
|
+
*/
|
|
327
|
+
export declare function payLinkRefusalWithPayments<Reason extends string>(reason: Reason | null, paymentsReady: boolean | undefined): Reason | 'payments-unavailable' | null;
|
|
328
|
+
/** What the customer is told when the business can't take a card payment now: the page's words and Pay's. */
|
|
329
|
+
export declare function payLinkPaymentsUnavailableMessage(storeName: string, kind: 'quote' | 'invoice'): string;
|
|
236
330
|
/** What the customer is told for a {@link QuotePayRefusal}, naming the business. */
|
|
237
331
|
export declare function quotePayRefusalMessage(reason: QuotePayRefusal, storeName: string): string;
|
|
238
332
|
/** What a completed Checkout Session says about the quote it paid. */
|
|
@@ -255,6 +349,13 @@ export interface QuotePaymentFacts {
|
|
|
255
349
|
taxMode: StorefrontTaxMode;
|
|
256
350
|
/** The address Stripe collected, when the session asked for one. */
|
|
257
351
|
shippingAddress: OrderAddress | null;
|
|
352
|
+
/**
|
|
353
|
+
* The tax the session charged under when it was not the quote's stored
|
|
354
|
+
* basis: {@link quotePayTax}'s answer for a quote saved before the store
|
|
355
|
+
* chose its sales tax, carried on the session (`quoteTax`,
|
|
356
|
+
* {@link quoteTaxBasisKey}) by the press that opened it (AGL-4162).
|
|
357
|
+
*/
|
|
358
|
+
taxBasis?: QuoteTaxBasis | null;
|
|
258
359
|
}
|
|
259
360
|
/**
|
|
260
361
|
* What a completed payment does to a quote:
|
|
@@ -291,6 +392,9 @@ export declare function quoteUnmatchedPaymentDetail(entry: QuoteUnmatchedPayment
|
|
|
291
392
|
* quote's bill-to bills it.
|
|
292
393
|
* - The totals are what Stripe charged: its shipping and tax where it charged
|
|
293
394
|
* any, the platform fee the session was minted with, and its total.
|
|
395
|
+
* - The quote keeps the tax basis it was paid under: the session's
|
|
396
|
+
* ({@link QuotePaymentFacts.taxBasis}) where the press took the store's
|
|
397
|
+
* choice for it, so the order says how its tax was worked out.
|
|
294
398
|
* - The list fields (`withOrderListFields`) are stamped from all of that.
|
|
295
399
|
*/
|
|
296
400
|
export declare function paidQuoteOrder(order: HostOrder, orderId: string, facts: QuotePaymentFacts): HostOrder & OrderListFields & {
|
|
@@ -16,9 +16,10 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/ import { visitorUploadIsInline } from "@aglyn/aglyn/app-utils/visitor-upload";
|
|
18
18
|
import { appendOrderEvent, formatOrderNumber } from "./commerce-orders.js";
|
|
19
|
-
import { computeQuoteTotals, describeQuoteTax, formatQuoteNumber, quoteLineAmounts, quotePaymentBlockedByApproval } from "./commerce-quotes.js";
|
|
19
|
+
import { computeQuoteTotals, describeQuoteTax, formatQuoteNumber, quoteLineAmounts, quotePaymentBlockedByApproval, quoteTaxBasisFromSettings } from "./commerce-quotes.js";
|
|
20
20
|
import { currentQuoteProofs, latestQuoteResponse, quoteRespondRefusal } from "./commerce-quote-proofs.js";
|
|
21
|
-
import {
|
|
21
|
+
import { storefrontTaxDecision } from "./commerce-tax-decision.js";
|
|
22
|
+
import { engineLineTaxPercentages, storeTaxAllowsEngine } from "./commerce-tax-engine.js";
|
|
22
23
|
import { withOrderListFields } from "./order-list-fields.js";
|
|
23
24
|
/*==========================================
|
|
24
25
|
* PAYING A QUOTE (AGL-4094).
|
|
@@ -36,6 +37,8 @@ import { withOrderListFields } from "./order-list-fields.js";
|
|
|
36
37
|
* - {@link quotePayRefusal}: why a quote cannot be paid now, if it cannot.
|
|
37
38
|
* - {@link quotePaymentDisposition} and {@link paidQuoteOrder}: what a
|
|
38
39
|
* completed payment does to the quote, and the order it becomes.
|
|
40
|
+
* - {@link quotePayTax}: the tax every one of them reads, which for a quote
|
|
41
|
+
* saved before the store chose its sales tax is the store's choice now.
|
|
39
42
|
*
|
|
40
43
|
* The customer side has no expiry and no open or closed states: a quote and
|
|
41
44
|
* its link stay until the quote is paid or the business replaces the link.
|
|
@@ -60,6 +63,130 @@ import { withOrderListFields } from "./order-list-fields.js";
|
|
|
60
63
|
const list = (order == null ? void 0 : order.quote) ? order.quote.unmatchedPayments : order == null ? void 0 : (_order_payLink = order.payLink) == null ? void 0 : _order_payLink.unmatchedPayments;
|
|
61
64
|
return Array.isArray(list) ? list.filter((entry)=>entry && typeof entry === 'object') : [];
|
|
62
65
|
}
|
|
66
|
+
/** The store a pay link reads, from the store settings document's data (nothing, for no document). */ export function payLinkStoreOf(settings) {
|
|
67
|
+
const tax = settings == null ? void 0 : settings.tax;
|
|
68
|
+
return {
|
|
69
|
+
tax: tax && typeof tax === 'object' ? tax : null
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** Whether a basis records that nobody had chosen the store's sales tax, which is no choice at all. */ export function quoteTaxIsUndecided(basis) {
|
|
73
|
+
return (basis == null ? void 0 : basis.kind) === 'none' && basis.reason === 'undecided';
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The tax a quote is shown, charged and paid under (AGL-4162): the one answer
|
|
77
|
+
* the quote page, Pay, the payment's record (carried on its session) and the
|
|
78
|
+
* console's notice all read.
|
|
79
|
+
*
|
|
80
|
+
* A quote keeps the basis it was saved with, except one saved before the
|
|
81
|
+
* store chose how it handles sales tax. That basis records no choice, so the
|
|
82
|
+
* quote takes the store's choice as it stands now, through the same
|
|
83
|
+
* `quoteTaxBasisFromSettings` the editor prices a save with: no sales tax,
|
|
84
|
+
* prices that include tax, or Stripe Tax at payment. Nothing is written for
|
|
85
|
+
* it; the next save stores the same basis.
|
|
86
|
+
*
|
|
87
|
+
* The store's own rates on prices that exclude tax are the one choice not
|
|
88
|
+
* taken this way. On those settings a save asks the site's tax service where
|
|
89
|
+
* one is connected (`priceQuote` in `server/quote.ts`), and only that save
|
|
90
|
+
* knows the figure: which service is connected is the tax service's own to
|
|
91
|
+
* say. Such a quote keeps its basis, and so stays unpaid, until it is saved.
|
|
92
|
+
*
|
|
93
|
+
* Without a store, the stored basis stands.
|
|
94
|
+
*/ export function quotePayTax(quote, store) {
|
|
95
|
+
var _ref;
|
|
96
|
+
const stored = (_ref = quote == null ? void 0 : quote.tax) != null ? _ref : {
|
|
97
|
+
kind: 'none',
|
|
98
|
+
reason: 'not-collected'
|
|
99
|
+
};
|
|
100
|
+
if (!store || !quoteTaxIsUndecided(stored)) return {
|
|
101
|
+
basis: stored,
|
|
102
|
+
source: 'stored'
|
|
103
|
+
};
|
|
104
|
+
if (storefrontTaxDecision({
|
|
105
|
+
settings: store.tax
|
|
106
|
+
}).kind === 'undecided') return {
|
|
107
|
+
basis: stored,
|
|
108
|
+
source: 'stored'
|
|
109
|
+
};
|
|
110
|
+
if (storeTaxAllowsEngine(store.tax)) return {
|
|
111
|
+
basis: stored,
|
|
112
|
+
source: 'save'
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
basis: quoteTaxBasisFromSettings(store.tax, quote == null ? void 0 : quote.shipTo),
|
|
116
|
+
source: 'current'
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const TAX_KINDS = new Set([
|
|
120
|
+
'rate',
|
|
121
|
+
'service',
|
|
122
|
+
'at-payment',
|
|
123
|
+
'none'
|
|
124
|
+
]);
|
|
125
|
+
const NO_TAX_REASONS = new Set([
|
|
126
|
+
'not-collected',
|
|
127
|
+
'prices-include-tax',
|
|
128
|
+
'no-rate',
|
|
129
|
+
'undecided'
|
|
130
|
+
]);
|
|
131
|
+
const BASIS_LABEL_MAX = 120;
|
|
132
|
+
/** A basis holding only what its kind carries, in one order, or null for anything that is not one. */ function tidyTaxBasis(raw) {
|
|
133
|
+
var _source_kind, _source_reason;
|
|
134
|
+
if (!raw || typeof raw !== 'object') return null;
|
|
135
|
+
const source = raw;
|
|
136
|
+
const kind = String((_source_kind = source['kind']) != null ? _source_kind : '');
|
|
137
|
+
if (!TAX_KINDS.has(kind)) return null;
|
|
138
|
+
const label = (value)=>typeof value === 'string' && value.trim() ? value.trim().slice(0, BASIS_LABEL_MAX) : '';
|
|
139
|
+
if (kind === 'rate') {
|
|
140
|
+
const pct = Number(source['pct']);
|
|
141
|
+
if (!Number.isFinite(pct)) return null;
|
|
142
|
+
const named = label(source['label']);
|
|
143
|
+
return _extends({
|
|
144
|
+
kind,
|
|
145
|
+
pct
|
|
146
|
+
}, named ? {
|
|
147
|
+
label: named
|
|
148
|
+
} : {});
|
|
149
|
+
}
|
|
150
|
+
if (kind === 'service') {
|
|
151
|
+
const taxCents = Math.round(Number(source['taxCents']));
|
|
152
|
+
if (!Number.isFinite(taxCents) || taxCents < 0) return null;
|
|
153
|
+
const named = label(source['providerLabel']);
|
|
154
|
+
return _extends({
|
|
155
|
+
kind,
|
|
156
|
+
taxCents
|
|
157
|
+
}, named ? {
|
|
158
|
+
providerLabel: named
|
|
159
|
+
} : {});
|
|
160
|
+
}
|
|
161
|
+
if (kind === 'at-payment') return {
|
|
162
|
+
kind
|
|
163
|
+
};
|
|
164
|
+
const reason = String((_source_reason = source['reason']) != null ? _source_reason : '');
|
|
165
|
+
return {
|
|
166
|
+
kind: 'none',
|
|
167
|
+
reason: NO_TAX_REASONS.has(reason) ? reason : 'not-collected'
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* A basis as one short string: what the quote page sends back with Pay, so a
|
|
172
|
+
* payment is refused when the tax it would charge is not the tax the page
|
|
173
|
+
* showed, and what a session records as the basis it charged. Equal bases
|
|
174
|
+
* have one key.
|
|
175
|
+
*/ export function quoteTaxBasisKey(basis) {
|
|
176
|
+
var _tidyTaxBasis;
|
|
177
|
+
return JSON.stringify((_tidyTaxBasis = tidyTaxBasis(basis)) != null ? _tidyTaxBasis : {
|
|
178
|
+
kind: 'none',
|
|
179
|
+
reason: 'not-collected'
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/** A basis back from {@link quoteTaxBasisKey}, or null for anything else. */ export function quoteTaxBasisFromKey(key) {
|
|
183
|
+
if (typeof key !== 'string' || !key || key.length > 500) return null;
|
|
184
|
+
try {
|
|
185
|
+
return tidyTaxBasis(JSON.parse(key));
|
|
186
|
+
} catch (unused) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
63
190
|
const text = (value)=>{
|
|
64
191
|
const trimmed = typeof value === 'string' ? value.trim() : '';
|
|
65
192
|
return trimmed ? trimmed : null;
|
|
@@ -115,16 +242,20 @@ function discountLabel(discount) {
|
|
|
115
242
|
/**
|
|
116
243
|
* The quote page's view of an order document on the `quote` channel. Totals
|
|
117
244
|
* are the stored lines' through {@link computeQuoteTotals} until the quote is
|
|
118
|
-
* paid, and the paid order's own totals (what Stripe charged) after.
|
|
245
|
+
* paid, and the paid order's own totals (what Stripe charged) after. The tax
|
|
246
|
+
* is {@link quotePayTax}'s for the store given, and Pay belongs on the page
|
|
247
|
+
* only when nothing would refuse it: the store's payments included, when the
|
|
248
|
+
* caller says whether it can take them.
|
|
119
249
|
*/ export function buildQuotePageView(input) {
|
|
120
250
|
var _order_lineItems, _ref, _text, _input_receiptUrl, _ref1;
|
|
121
|
-
var
|
|
251
|
+
var _quote_customer, _quote_customer1, _quote_customer2, _quote_customer3;
|
|
122
252
|
const { order } = input;
|
|
123
253
|
const quote = order.quote;
|
|
124
254
|
const lines = (_order_lineItems = order.lineItems) != null ? _order_lineItems : [];
|
|
125
255
|
const status = quotePageStatus(order.status);
|
|
126
256
|
const unpaid = status.status === 'unpaid';
|
|
127
|
-
const
|
|
257
|
+
const payTax = quotePayTax(quote, input.store);
|
|
258
|
+
const charge = quoteCheckoutCharge(order, input.orderId, input.store);
|
|
128
259
|
const stored = order.totals;
|
|
129
260
|
const totals = unpaid || !stored ? {
|
|
130
261
|
itemsCents: charge.itemsCents,
|
|
@@ -140,7 +271,8 @@ function discountLabel(discount) {
|
|
|
140
271
|
totalCents: cents(stored.totalCents)
|
|
141
272
|
};
|
|
142
273
|
const approvalRequired = unpaid && quotePaymentBlockedByApproval(quote);
|
|
143
|
-
const taxAtPayment = unpaid &&
|
|
274
|
+
const taxAtPayment = unpaid && payTax.basis.kind === 'at-payment';
|
|
275
|
+
const refused = unpaid ? payLinkRefusalWithPayments(quotePayRefusal(order, input.orderId, input.store), input.paymentsReady) : null;
|
|
144
276
|
return {
|
|
145
277
|
state: 'quote',
|
|
146
278
|
kind: 'quote',
|
|
@@ -157,7 +289,7 @@ function discountLabel(discount) {
|
|
|
157
289
|
totals,
|
|
158
290
|
discountLabel: discountLabel(quote == null ? void 0 : quote.discount),
|
|
159
291
|
// Once paid, the tax is what was charged: Stripe's figure under Stripe Tax.
|
|
160
|
-
taxLabel: unpaid ||
|
|
292
|
+
taxLabel: unpaid || payTax.basis.kind !== 'at-payment' ? describeQuoteTax(payTax.basis) : 'Tax',
|
|
161
293
|
taxAtPayment,
|
|
162
294
|
shippingAtPayment: false,
|
|
163
295
|
notes: text(quote == null ? void 0 : quote.notes),
|
|
@@ -167,7 +299,9 @@ function discountLabel(discount) {
|
|
|
167
299
|
paidAtMs: paidAt(order),
|
|
168
300
|
receiptUrl: unpaid ? null : (_input_receiptUrl = input.receiptUrl) != null ? _input_receiptUrl : null,
|
|
169
301
|
approvalRequired,
|
|
170
|
-
payable: unpaid &&
|
|
302
|
+
payable: unpaid && refused === null,
|
|
303
|
+
notPayableMessage: refused === 'payments-unavailable' ? payLinkPaymentsUnavailableMessage(input.storeName, 'quote') : null,
|
|
304
|
+
taxKey: unpaid ? quoteTaxBasisKey(payTax.basis) : null,
|
|
171
305
|
revision: Math.max(1, Number((_ref1 = quote == null ? void 0 : quote.revision) != null ? _ref1 : 1) || 1),
|
|
172
306
|
proofs: currentQuoteProofs(quote).map((proof)=>{
|
|
173
307
|
var _proof_name, _proof_contentType, _proof_contentType1;
|
|
@@ -240,7 +374,9 @@ function lineSummary(lines) {
|
|
|
240
374
|
/**
|
|
241
375
|
* The charge for a quote, from its stored lines, discount, shipping and tax
|
|
242
376
|
* basis through {@link computeQuoteTotals} — the same function that priced it
|
|
243
|
-
* when it was saved, so the page, the session and the stored quote agree.
|
|
377
|
+
* when it was saved, so the page, the session and the stored quote agree. The
|
|
378
|
+
* basis is {@link quotePayTax}'s: a quote saved before the store chose its
|
|
379
|
+
* sales tax is charged under the store's choice now.
|
|
244
380
|
*
|
|
245
381
|
* The goods are charged as at most two lines, the taxed and the tax-exempt,
|
|
246
382
|
* each after its share of the discount. A store rate is applied to the taxed
|
|
@@ -248,17 +384,14 @@ function lineSummary(lines) {
|
|
|
248
384
|
* amount the quote taxed, and the quote's figure is what is collected. A tax
|
|
249
385
|
* service's figure is carried the same way, as the percentage of the taxed
|
|
250
386
|
* line it amounts to. Included lines charge nothing and are not sent.
|
|
251
|
-
*/ export function quoteCheckoutCharge(order, orderId) {
|
|
252
|
-
var _order_lineItems, _ref
|
|
253
|
-
var _order_quote,
|
|
387
|
+
*/ export function quoteCheckoutCharge(order, orderId, store) {
|
|
388
|
+
var _order_lineItems, _ref;
|
|
389
|
+
var _order_quote, _order_quote_shipping, _order_quote1;
|
|
254
390
|
return payLinkCheckoutCharge({
|
|
255
391
|
lineItems: (_order_lineItems = order.lineItems) != null ? _order_lineItems : [],
|
|
256
|
-
tax: (
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
},
|
|
260
|
-
discount: (_ref1 = (_order_quote1 = order.quote) == null ? void 0 : _order_quote1.discount) != null ? _ref1 : null,
|
|
261
|
-
shippingCents: Math.max(0, cents((_order_quote2 = order.quote) == null ? void 0 : (_order_quote_shipping = _order_quote2.shipping) == null ? void 0 : _order_quote_shipping.amountCents)),
|
|
392
|
+
tax: quotePayTax(order.quote, store).basis,
|
|
393
|
+
discount: (_ref = (_order_quote = order.quote) == null ? void 0 : _order_quote.discount) != null ? _ref : null,
|
|
394
|
+
shippingCents: Math.max(0, cents((_order_quote1 = order.quote) == null ? void 0 : (_order_quote_shipping = _order_quote1.shipping) == null ? void 0 : _order_quote_shipping.amountCents)),
|
|
262
395
|
label: formatQuoteNumber(order, orderId)
|
|
263
396
|
});
|
|
264
397
|
}
|
|
@@ -329,15 +462,36 @@ function lineSummary(lines) {
|
|
|
329
462
|
feeProductType: feeProductTypeOf(lineItems)
|
|
330
463
|
};
|
|
331
464
|
}
|
|
332
|
-
/**
|
|
333
|
-
|
|
465
|
+
/**
|
|
466
|
+
* Why a quote cannot be paid now, or null when it can. With the store, its
|
|
467
|
+
* tax is {@link quotePayTax}'s, and a store that has not chosen its sales tax
|
|
468
|
+
* refuses every sale (AGL-1999), whatever basis the quote was saved with.
|
|
469
|
+
*/ export function quotePayRefusal(order, orderId, store) {
|
|
334
470
|
if (order.status === 'cancelled' || order.status === 'refunded') return 'closed';
|
|
335
471
|
if (order.status !== 'pending') return 'paid';
|
|
336
472
|
if (quotePaymentBlockedByApproval(order.quote)) return 'approval-required';
|
|
337
|
-
if (
|
|
338
|
-
|
|
473
|
+
if (store && storefrontTaxDecision({
|
|
474
|
+
settings: store.tax
|
|
475
|
+
}).kind === 'undecided') return 'tax-undecided';
|
|
476
|
+
if (quoteTaxIsUndecided(quotePayTax(order.quote, store).basis)) return 'tax-undecided';
|
|
477
|
+
if (quoteCheckoutCharge(order, orderId, store).totalCents < QUOTE_MIN_CHARGE_CENTS) return 'nothing-to-pay';
|
|
339
478
|
return null;
|
|
340
479
|
}
|
|
480
|
+
/**
|
|
481
|
+
* A pay link's refusal once the store's payments are judged too: a business
|
|
482
|
+
* that can't take a card payment now outranks every refusal but the ones a
|
|
483
|
+
* payment never gets past (paid, closed, not linked, waiting on the
|
|
484
|
+
* customer's approval). `paymentsReady` absent leaves the refusal as it is.
|
|
485
|
+
*/ export function payLinkRefusalWithPayments(reason, paymentsReady) {
|
|
486
|
+
if (paymentsReady !== false) return reason;
|
|
487
|
+
if (reason === 'paid' || reason === 'closed' || reason === 'not-payable' || reason === 'approval-required') {
|
|
488
|
+
return reason;
|
|
489
|
+
}
|
|
490
|
+
return 'payments-unavailable';
|
|
491
|
+
}
|
|
492
|
+
/** What the customer is told when the business can't take a card payment now: the page's words and Pay's. */ export function payLinkPaymentsUnavailableMessage(storeName, kind) {
|
|
493
|
+
return `${storeName || 'This business'} can’t take payments online right now. Contact them to pay this ${kind === 'invoice' ? 'invoice' : 'quote'}.`;
|
|
494
|
+
}
|
|
341
495
|
/** What the customer is told for a {@link QuotePayRefusal}, naming the business. */ export function quotePayRefusalMessage(reason, storeName) {
|
|
342
496
|
const business = storeName.trim() || 'the business';
|
|
343
497
|
switch(reason){
|
|
@@ -401,6 +555,9 @@ export function quotePaymentDisposition(order, payment) {
|
|
|
401
555
|
* quote's bill-to bills it.
|
|
402
556
|
* - The totals are what Stripe charged: its shipping and tax where it charged
|
|
403
557
|
* any, the platform fee the session was minted with, and its total.
|
|
558
|
+
* - The quote keeps the tax basis it was paid under: the session's
|
|
559
|
+
* ({@link QuotePaymentFacts.taxBasis}) where the press took the store's
|
|
560
|
+
* choice for it, so the order says how its tax was worked out.
|
|
404
561
|
* - The list fields (`withOrderListFields`) are stamped from all of that.
|
|
405
562
|
*/ export function paidQuoteOrder(order, orderId, facts) {
|
|
406
563
|
var _ref, _order_totals, _ref1, _facts_shippingAddress, _text, _ref2, _text1, _facts_paymentIntentId;
|
|
@@ -446,7 +603,9 @@ export function quotePaymentDisposition(order, payment) {
|
|
|
446
603
|
paymentIntentId: (_facts_paymentIntentId = facts.paymentIntentId) != null ? _facts_paymentIntentId : undefined,
|
|
447
604
|
checkoutSessionId: facts.sessionId,
|
|
448
605
|
timeline: appendOrderEvent(order, 'paid', `${label} paid through its pay link`, facts.paidAtMs),
|
|
449
|
-
quote: _extends({}, quote, {
|
|
606
|
+
quote: _extends({}, quote, facts.taxBasis ? {
|
|
607
|
+
tax: facts.taxBasis
|
|
608
|
+
} : {}, {
|
|
450
609
|
paidAtMs: facts.paidAtMs
|
|
451
610
|
}),
|
|
452
611
|
// New to a shipping tool's feed from the moment it is paid.
|