@aglyn/plugins-commerce 1.15.1 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +13 -13
- package/src/lib/components/cart.js +2 -1
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/console/payments-settings-card.component.js +6 -1
- package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-api.d.ts +5 -0
- package/src/lib/components/console/pos/pos-api.js.map +1 -1
- package/src/lib/components/console/pos/pos-tender-dialogs.component.d.ts +2 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js +13 -6
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-tender-panel.component.js +7 -4
- package/src/lib/components/console/pos/pos-tender-panel.component.js.map +1 -1
- package/src/lib/components/console/product-add-ons-fields.component.d.ts +13 -0
- package/src/lib/components/console/product-add-ons-fields.component.js +96 -3
- package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
- package/src/lib/components/console/product-builder-fields.component.d.ts +39 -0
- package/src/lib/components/console/product-builder-fields.component.js +195 -0
- package/src/lib/components/console/product-builder-fields.component.js.map +1 -0
- package/src/lib/components/console/product-editor-dialog.component.js +35 -2
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/quote-editor-dialog.component.js +43 -6
- package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/quote-messages.component.d.ts +21 -0
- package/src/lib/components/console/quote-messages.component.js +185 -0
- package/src/lib/components/console/quote-messages.component.js.map +1 -0
- package/src/lib/components/console/quote-pay-link.component.js +1 -1
- package/src/lib/components/console/quote-pay-link.component.js.map +1 -1
- package/src/lib/components/console/quote-proofs.component.js +30 -3
- package/src/lib/components/console/quote-proofs.component.js.map +1 -1
- package/src/lib/components/console/quote-settings-card.component.d.ts +7 -3
- package/src/lib/components/console/quote-settings-card.component.js +154 -24
- package/src/lib/components/console/quote-settings-card.component.js.map +1 -1
- package/src/lib/components/product-builder-context.d.ts +22 -0
- package/src/lib/components/product-builder-context.js +21 -0
- package/src/lib/components/product-builder-context.js.map +1 -0
- package/src/lib/components/product-builder-mockup.d.ts +42 -0
- package/src/lib/components/product-builder-mockup.js +120 -0
- package/src/lib/components/product-builder-mockup.js.map +1 -0
- package/src/lib/components/product-builder-sample.d.ts +63 -0
- package/src/lib/components/product-builder-sample.js +96 -0
- package/src/lib/components/product-builder-sample.js.map +1 -0
- package/src/lib/components/product-choice-cards.d.ts +51 -0
- package/src/lib/components/product-choice-cards.js +311 -0
- package/src/lib/components/product-choice-cards.js.map +1 -0
- package/src/lib/components/product-detail-panels.d.ts +42 -0
- package/src/lib/components/product-detail-panels.js +185 -0
- package/src/lib/components/product-detail-panels.js.map +1 -0
- package/src/lib/components/product-detail.d.ts +20 -12
- package/src/lib/components/product-detail.js +136 -221
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/product-grid.d.ts +7 -0
- package/src/lib/components/product-grid.js +11 -8
- package/src/lib/components/product-grid.js.map +1 -1
- package/src/lib/components/product-options-field-body.d.ts +9 -8
- package/src/lib/components/product-options-field-body.js +152 -3
- package/src/lib/components/product-options-field-body.js.map +1 -1
- package/src/lib/components/product-options-field.js +1 -1
- package/src/lib/components/product-options-field.js.map +1 -1
- package/src/lib/components/product-photo-fit.d.ts +49 -0
- package/src/lib/components/product-photo-fit.js +58 -0
- package/src/lib/components/product-photo-fit.js.map +1 -0
- package/src/lib/components/product-restock-notify.d.ts +12 -0
- package/src/lib/components/product-restock-notify.js +86 -0
- package/src/lib/components/product-restock-notify.js.map +1 -0
- package/src/lib/components/quote-messages-panel.d.ts +21 -0
- package/src/lib/components/quote-messages-panel.js +191 -0
- package/src/lib/components/quote-messages-panel.js.map +1 -0
- package/src/lib/components/quote-page-body.js +15 -1
- package/src/lib/components/quote-page-body.js.map +1 -1
- package/src/lib/components/quote-proof-panel.d.ts +6 -3
- package/src/lib/components/quote-proof-panel.js +139 -14
- package/src/lib/components/quote-proof-panel.js.map +1 -1
- package/src/lib/components/related-products.d.ts +7 -0
- package/src/lib/components/related-products.js +8 -6
- package/src/lib/components/related-products.js.map +1 -1
- package/src/lib/constants/quote-page.d.ts +8 -0
- package/src/lib/constants/quote-page.js +11 -0
- package/src/lib/constants/quote-page.js.map +1 -1
- package/src/lib/model/commerce-cart.d.ts +6 -1
- package/src/lib/model/commerce-cart.js +5 -1
- package/src/lib/model/commerce-cart.js.map +1 -1
- package/src/lib/model/commerce-invoices.js +5 -1
- package/src/lib/model/commerce-invoices.js.map +1 -1
- package/src/lib/model/commerce-pos-ops.d.ts +3 -0
- package/src/lib/model/commerce-pos-ops.js +3 -0
- package/src/lib/model/commerce-pos-ops.js.map +1 -1
- package/src/lib/model/commerce-pos.d.ts +8 -0
- package/src/lib/model/commerce-pos.js.map +1 -1
- package/src/lib/model/commerce-quote-messages.d.ts +106 -0
- package/src/lib/model/commerce-quote-messages.js +146 -0
- package/src/lib/model/commerce-quote-messages.js.map +1 -0
- package/src/lib/model/commerce-quote-pay.d.ts +31 -2
- package/src/lib/model/commerce-quote-pay.js +31 -7
- package/src/lib/model/commerce-quote-pay.js.map +1 -1
- package/src/lib/model/commerce-quote-proofs.d.ts +47 -8
- package/src/lib/model/commerce-quote-proofs.js +73 -18
- package/src/lib/model/commerce-quote-proofs.js.map +1 -1
- package/src/lib/model/commerce-quote-request.d.ts +14 -4
- package/src/lib/model/commerce-quote-request.js +25 -2
- package/src/lib/model/commerce-quote-request.js.map +1 -1
- package/src/lib/model/commerce-quotes.d.ts +56 -3
- package/src/lib/model/commerce-quotes.js +47 -2
- package/src/lib/model/commerce-quotes.js.map +1 -1
- package/src/lib/model/commerce.d.ts +12 -1
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/index.d.ts +1 -0
- package/src/lib/model/index.js +1 -0
- package/src/lib/model/index.js.map +1 -1
- package/src/lib/model/pos-cellular.d.ts +5 -0
- package/src/lib/model/pos-cellular.js.map +1 -1
- package/src/lib/model/product-card-rules.d.ts +41 -0
- package/src/lib/model/product-card-rules.js +90 -0
- package/src/lib/model/product-card-rules.js.map +1 -0
- package/src/lib/model/product-modifiers.d.ts +11 -0
- package/src/lib/model/product-modifiers.js +10 -0
- package/src/lib/model/product-modifiers.js.map +1 -1
- package/src/lib/model/product-write.d.ts +3 -0
- package/src/lib/server/billing-webhook.js +6 -2
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/cancel-order.js +15 -0
- package/src/lib/server/cancel-order.js.map +1 -1
- package/src/lib/server/channel-order-updates.js +15 -1
- package/src/lib/server/channel-order-updates.js.map +1 -1
- package/src/lib/server/channel-orders.js +20 -0
- package/src/lib/server/channel-orders.js.map +1 -1
- package/src/lib/server/checkout.js +1 -1
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/local-fulfillment.js +1 -1
- package/src/lib/server/local-fulfillment.js.map +1 -1
- package/src/lib/server/pos-cellular-billing.d.ts +1 -1
- package/src/lib/server/pos-cellular-billing.js +2 -1
- package/src/lib/server/pos-cellular-billing.js.map +1 -1
- package/src/lib/server/pos-cellular.d.ts +3 -1
- package/src/lib/server/pos-cellular.js +15 -8
- package/src/lib/server/pos-cellular.js.map +1 -1
- package/src/lib/server/pos-offline-sync.d.ts +3 -3
- package/src/lib/server/pos-offline-sync.js +17 -4
- package/src/lib/server/pos-offline-sync.js.map +1 -1
- package/src/lib/server/pos-order.js +17 -6
- package/src/lib/server/pos-order.js.map +1 -1
- package/src/lib/server/pos-payment.js +27 -11
- package/src/lib/server/pos-payment.js.map +1 -1
- package/src/lib/server/pos-reader-splash.js +10 -5
- package/src/lib/server/pos-reader-splash.js.map +1 -1
- package/src/lib/server/pos-readers.js +34 -10
- package/src/lib/server/pos-readers.js.map +1 -1
- package/src/lib/server/pos-return.js +19 -3
- package/src/lib/server/pos-return.js.map +1 -1
- package/src/lib/server/pos-stripe.d.ts +14 -0
- package/src/lib/server/pos-stripe.js +6 -2
- package/src/lib/server/pos-stripe.js.map +1 -1
- package/src/lib/server/pos-terminal-connection-token.js +23 -9
- package/src/lib/server/pos-terminal-connection-token.js.map +1 -1
- package/src/lib/server/pos-terminal.d.ts +80 -14
- package/src/lib/server/pos-terminal.js +393 -123
- package/src/lib/server/pos-terminal.js.map +1 -1
- package/src/lib/server/product-drafts.d.ts +1 -1
- package/src/lib/server/product-drafts.js +4 -3
- package/src/lib/server/product-drafts.js.map +1 -1
- package/src/lib/server/product-writer.js +5 -4
- package/src/lib/server/product-writer.js.map +1 -1
- package/src/lib/server/product.d.ts +11 -0
- package/src/lib/server/product.js +18 -3
- package/src/lib/server/product.js.map +1 -1
- package/src/lib/server/products-write.js +4 -3
- package/src/lib/server/products-write.js.map +1 -1
- package/src/lib/server/quote-email.d.ts +26 -0
- package/src/lib/server/quote-email.js +73 -7
- package/src/lib/server/quote-email.js.map +1 -1
- package/src/lib/server/quote-messages.d.ts +72 -0
- package/src/lib/server/quote-messages.js +356 -0
- package/src/lib/server/quote-messages.js.map +1 -0
- package/src/lib/server/quote-pay.d.ts +42 -0
- package/src/lib/server/quote-pay.js +81 -4
- package/src/lib/server/quote-pay.js.map +1 -1
- package/src/lib/server/quote-proofs.d.ts +1 -1
- package/src/lib/server/quote-proofs.js +63 -19
- package/src/lib/server/quote-proofs.js.map +1 -1
- package/src/lib/server/quote.d.ts +12 -0
- package/src/lib/server/quote.js +44 -14
- package/src/lib/server/quote.js.map +1 -1
- package/src/lib/server/refund.js +3 -1
- package/src/lib/server/refund.js.map +1 -1
- package/src/lib/server/reserve-stock.js +9 -0
- package/src/lib/server/reserve-stock.js.map +1 -1
- package/src/lib/server/returns.js +15 -1
- package/src/lib/server/returns.js.map +1 -1
- package/src/lib/server/reviews.js +15 -0
- package/src/lib/server/reviews.js.map +1 -1
- package/src/lib/server/sold-out-drop.d.ts +58 -0
- package/src/lib/server/sold-out-drop.js +81 -0
- package/src/lib/server/sold-out-drop.js.map +1 -0
- package/src/lib/server/stock-levels.js +9 -0
- package/src/lib/server/stock-levels.js.map +1 -1
- package/src/lib/server/stripe-refund.d.ts +7 -0
- package/src/lib/server/stripe-refund.js +26 -7
- package/src/lib/server/stripe-refund.js.map +1 -1
- package/src/lib/server.js +2 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/tenant-emails.js +85 -2
- package/src/lib/tenant-emails.js.map +1 -1
- package/src/lib/testing/fake-seller-payment-account.d.ts +29 -0
- package/src/lib/testing/fake-seller-payment-account.js +40 -0
- package/src/lib/testing/fake-seller-payment-account.js.map +1 -0
- package/src/lib/transfer/product-transfer.js +6 -5
- package/src/lib/transfer/product-transfer.js.map +1 -1
- package/src/lib/transfer/products.server.js +4 -3
- package/src/lib/transfer/products.server.js.map +1 -1
- package/src/lib/utils/quote-email-content.d.ts +6 -0
- package/src/lib/utils/quote-email-content.js +6 -3
- package/src/lib/utils/quote-email-content.js.map +1 -1
|
@@ -16,8 +16,8 @@ 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, formatProofNumber, formatQuoteNumber, quoteIsProofOnly, quoteLineAmounts, quotePaymentBlockedByApproval, quoteTaxBasisFromSettings } from "./commerce-quotes.js";
|
|
20
|
-
import { currentQuoteProofs, latestQuoteResponse, quoteRespondRefusal } from "./commerce-quote-proofs.js";
|
|
19
|
+
import { computeQuoteTotals, describeQuoteTax, formatProofNumber, formatQuoteNumber, QUOTE_DEFAULT_APPROVAL_STATEMENTS, quoteIsProofOnly, quoteLineAmounts, quotePaymentBlockedByApproval, quoteTaxBasisFromSettings } from "./commerce-quotes.js";
|
|
20
|
+
import { currentQuoteProofs, latestQuoteResponse, quoteProofAccessMessage, quoteRespondRefusal } from "./commerce-quote-proofs.js";
|
|
21
21
|
import { storefrontTaxDecision } from "./commerce-tax-decision.js";
|
|
22
22
|
import { engineLineTaxPercentages, storeTaxAllowsEngine } from "./commerce-tax-engine.js";
|
|
23
23
|
import { withOrderListFields } from "./order-list-fields.js";
|
|
@@ -247,7 +247,7 @@ function discountLabel(discount) {
|
|
|
247
247
|
* only when nothing would refuse it: the store's payments included, when the
|
|
248
248
|
* caller says whether it can take them.
|
|
249
249
|
*/ export function buildQuotePageView(input) {
|
|
250
|
-
var _order_lineItems, _ref, _text, _input_receiptUrl, _ref1;
|
|
250
|
+
var _order_lineItems, _ref, _text, _input_receiptUrl, _ref1, _input_messages, _input_approvalStatements, _input_proofAccess;
|
|
251
251
|
var _quote_customer, _quote_customer1, _quote_customer2, _quote_customer3;
|
|
252
252
|
const { order } = input;
|
|
253
253
|
const quote = order.quote;
|
|
@@ -280,7 +280,7 @@ function discountLabel(discount) {
|
|
|
280
280
|
const approvalRequired = unpaid && !proofOnly && quotePaymentBlockedByApproval(quote);
|
|
281
281
|
const taxAtPayment = unpaid && !proofOnly && payTax.basis.kind === 'at-payment';
|
|
282
282
|
const refused = unpaid ? payLinkRefusalWithPayments(quotePayRefusal(order, input.orderId, input.store), input.paymentsReady) : null;
|
|
283
|
-
|
|
283
|
+
const view = {
|
|
284
284
|
state: 'quote',
|
|
285
285
|
kind: 'quote',
|
|
286
286
|
proofOnly,
|
|
@@ -327,8 +327,31 @@ function discountLabel(discount) {
|
|
|
327
327
|
channel: 'quote',
|
|
328
328
|
status: order.status,
|
|
329
329
|
quote
|
|
330
|
-
}) === null
|
|
330
|
+
}) === null,
|
|
331
|
+
messages: (_input_messages = input.messages) != null ? _input_messages : [],
|
|
332
|
+
approvalStatements: [],
|
|
333
|
+
proofAccess: 'open',
|
|
334
|
+
proofAccessMessage: null
|
|
331
335
|
};
|
|
336
|
+
const page = _extends({}, view, {
|
|
337
|
+
approvalStatements: view.respondable ? [
|
|
338
|
+
...(_input_approvalStatements = input.approvalStatements) != null ? _input_approvalStatements : QUOTE_DEFAULT_APPROVAL_STATEMENTS
|
|
339
|
+
] : []
|
|
340
|
+
});
|
|
341
|
+
const access = (_input_proofAccess = input.proofAccess) != null ? _input_proofAccess : 'open';
|
|
342
|
+
// A revision with no proof has nothing to sign in for.
|
|
343
|
+
if (access === 'open' || page.proofs.length === 0) return page;
|
|
344
|
+
// Waiting on a sign-in, the view carries nothing of the proof or the answer.
|
|
345
|
+
return _extends({}, page, {
|
|
346
|
+
proofs: [],
|
|
347
|
+
response: null,
|
|
348
|
+
respondable: false,
|
|
349
|
+
// The conversation is about the proof, so it waits on the same sign-in (AGL-4207).
|
|
350
|
+
messages: [],
|
|
351
|
+
approvalStatements: [],
|
|
352
|
+
proofAccess: access,
|
|
353
|
+
proofAccessMessage: quoteProofAccessMessage(access, input.storeName)
|
|
354
|
+
});
|
|
332
355
|
}
|
|
333
356
|
/** Order lines as the pay link's page lists them: what each charges, nothing about stock or cost. */ export function quotePageLines(lines) {
|
|
334
357
|
return lines.map((line)=>{
|
|
@@ -356,9 +379,10 @@ function discountLabel(discount) {
|
|
|
356
379
|
return {
|
|
357
380
|
action: latest.action === 'approve' ? 'approve' : 'changes',
|
|
358
381
|
atMs: Number(latest.atMs) || 0,
|
|
359
|
-
name:
|
|
382
|
+
name: text(latest.name),
|
|
360
383
|
comment: latest.action === 'changes' ? text(latest.comment) : null,
|
|
361
|
-
files: (_ref = (_latest_files = latest.files) == null ? void 0 : _latest_files.length) != null ? _ref : 0
|
|
384
|
+
files: (_ref = (_latest_files = latest.files) == null ? void 0 : _latest_files.length) != null ? _ref : 0,
|
|
385
|
+
confirmed: latest.action === 'approve' && Array.isArray(latest.confirmed) ? latest.confirmed.map(String) : []
|
|
362
386
|
};
|
|
363
387
|
}
|
|
364
388
|
const LINE_DESCRIPTION_MAX = 500;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce-quote-pay.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { visitorUploadIsInline } from '@aglyn/aglyn/app-utils/visitor-upload'\nimport type { ProductType } from './commerce'\nimport {\n appendOrderEvent,\n formatOrderNumber,\n type HostOrder,\n type OrderAddress,\n type OrderLineItem,\n type OrderStatus,\n} from './commerce-orders'\nimport {\n computeQuoteTotals,\n describeQuoteTax,\n formatProofNumber,\n formatQuoteNumber,\n quoteIsProofOnly,\n quoteLineAmounts,\n quotePaymentBlockedByApproval,\n quoteTaxBasisFromSettings,\n type OrderQuote,\n type QuoteDiscount,\n type QuoteNoTaxReason,\n type QuoteTaxBasis,\n type QuoteTaxKind,\n type QuoteUnmatchedPayment,\n} from './commerce-quotes'\nimport { currentQuoteProofs, latestQuoteResponse, quoteRespondRefusal } from './commerce-quote-proofs'\nimport type { TaxSettings } from './commerce-tax'\nimport { storefrontTaxDecision, type StorefrontTaxMode } from './commerce-tax-decision'\nimport { engineLineTaxPercentages, storeTaxAllowsEngine } from './commerce-tax-engine'\nimport { withOrderListFields, type OrderListFields } from './order-list-fields'\n\n/*==========================================\n * PAYING A QUOTE (AGL-4094).\n *\n * The customer opens the quote on the business's own site from a signed pay\n * link, sees it, and pays it. Everything here is pure, so the page's view,\n * the pay route's charge and the webhook's paid order all come from one\n * reading of the stored quote, and none of them from anything the browser\n * sends:\n *\n * - {@link buildQuotePageView}: the ONE projection of a quote that leaves the\n * server for a visitor holding the link, allow-listed field by field.\n * - {@link quoteCheckoutCharge}: what a Checkout Session charges, priced from\n * the stored lines, discount, shipping and tax basis.\n * - {@link quotePayRefusal}: why a quote cannot be paid now, if it cannot.\n * - {@link quotePaymentDisposition} and {@link paidQuoteOrder}: what a\n * completed payment does to the quote, and the order it becomes.\n * - {@link quotePayTax}: the tax every one of them reads, which for a quote\n * saved before the store chose its sales tax is the store's choice now.\n *\n * The customer side has no expiry and no open or closed states: a quote and\n * its link stay until the quote is paid or the business replaces the link.\n *=========================================*/\n\n/** Stripe's smallest card charge; a quote that totals less cannot be paid by card. */\nexport const QUOTE_MIN_CHARGE_CENTS = 50\n\n/** The pay link version a quote is on; absent reads as the first. */\nexport function quoteLinkVersion(quote: Pick<OrderQuote, 'linkVersion'> | null | undefined): number {\n const version = Math.floor(Number(quote?.linkVersion))\n return Number.isFinite(version) && version >= 1 ? version : 1\n}\n\n/**\n * The pay link version any order is on (AGL-4099). A quote keeps its version\n * where slice 2 put it, `quote.linkVersion`, so every link already sent keeps\n * verifying; any other order keeps it as `payLink.version`. Absent reads as\n * the first either way.\n */\nexport function orderPayLinkVersion(order: Partial<Pick<HostOrder, 'quote' | 'payLink'>> | null | undefined): number {\n if (order?.quote) return quoteLinkVersion(order.quote)\n const version = Math.floor(Number(order?.payLink?.version))\n return Number.isFinite(version) && version >= 1 ? version : 1\n}\n\n/** Payments the order's pay link could not take: a quote's on the quote, any other order's on `payLink`. */\nexport function orderPayLinkUnmatched(\n order: Partial<Pick<HostOrder, 'quote' | 'payLink'>> | null | undefined,\n): QuoteUnmatchedPayment[] {\n const list = order?.quote ? order.quote.unmatchedPayments : order?.payLink?.unmatchedPayments\n return Array.isArray(list) ? list.filter((entry) => entry && typeof entry === 'object') : []\n}\n\n/*==========================================\n * THE TAX A QUOTE IS SHOWN AND PAID UNDER\n *=========================================*/\n\n/**\n * The store a pay link is read against: its sales tax choice, as\n * `hosts/{hostId}/settings/store` keeps it under `tax`. Absent or null, the\n * store has not chosen.\n */\nexport interface PayLinkStore {\n tax?: TaxSettings | null\n}\n\n/** The store a pay link reads, from the store settings document's data (nothing, for no document). */\nexport function payLinkStoreOf(settings: { tax?: unknown } | null | undefined): PayLinkStore {\n const tax = settings?.tax\n return { tax: tax && typeof tax === 'object' ? (tax as TaxSettings) : null }\n}\n\n/** Whether a basis records that nobody had chosen the store's sales tax, which is no choice at all. */\nexport function quoteTaxIsUndecided(basis: Pick<QuoteTaxBasis, 'kind' | 'reason'> | null | undefined): boolean {\n return basis?.kind === 'none' && basis.reason === 'undecided'\n}\n\n/**\n * Where a quote's tax comes from when it is shown and paid:\n *\n * - `stored`: the basis it was saved with.\n * - `current`: it was saved before the store chose, and takes the store's\n * choice as it stands now.\n * - `save`: it was saved before the store chose, and the store's choice now\n * prices it only when it is saved again.\n */\nexport type QuotePayTaxSource = 'stored' | 'current' | 'save'\n\nexport interface QuotePayTax {\n basis: QuoteTaxBasis\n source: QuotePayTaxSource\n}\n\n/**\n * The tax a quote is shown, charged and paid under (AGL-4162): the one answer\n * the quote page, Pay, the payment's record (carried on its session) and the\n * console's notice all read.\n *\n * A quote keeps the basis it was saved with, except one saved before the\n * store chose how it handles sales tax. That basis records no choice, so the\n * quote takes the store's choice as it stands now, through the same\n * `quoteTaxBasisFromSettings` the editor prices a save with: no sales tax,\n * prices that include tax, or Stripe Tax at payment. Nothing is written for\n * it; the next save stores the same basis.\n *\n * The store's own rates on prices that exclude tax are the one choice not\n * taken this way. On those settings a save asks the site's tax service where\n * one is connected (`priceQuote` in `server/quote.ts`), and only that save\n * knows the figure: which service is connected is the tax service's own to\n * say. Such a quote keeps its basis, and so stays unpaid, until it is saved.\n *\n * Without a store, the stored basis stands.\n */\nexport function quotePayTax(\n quote: Pick<OrderQuote, 'tax' | 'shipTo'> | null | undefined,\n store?: PayLinkStore | null,\n): QuotePayTax {\n const stored: QuoteTaxBasis = quote?.tax ?? { kind: 'none', reason: 'not-collected' }\n if (!store || !quoteTaxIsUndecided(stored)) return { basis: stored, source: 'stored' }\n if (storefrontTaxDecision({ settings: store.tax }).kind === 'undecided') return { basis: stored, source: 'stored' }\n if (storeTaxAllowsEngine(store.tax)) return { basis: stored, source: 'save' }\n return { basis: quoteTaxBasisFromSettings(store.tax, quote?.shipTo), source: 'current' }\n}\n\nconst TAX_KINDS: ReadonlySet<string> = new Set<QuoteTaxKind>(['rate', 'service', 'at-payment', 'none'])\nconst NO_TAX_REASONS: ReadonlySet<string> = new Set<QuoteNoTaxReason>([\n 'not-collected',\n 'prices-include-tax',\n 'no-rate',\n 'undecided',\n])\nconst BASIS_LABEL_MAX = 120\n\n/** A basis holding only what its kind carries, in one order, or null for anything that is not one. */\nfunction tidyTaxBasis(raw: unknown): QuoteTaxBasis | null {\n if (!raw || typeof raw !== 'object') return null\n const source = raw as Record<string, unknown>\n const kind = String(source['kind'] ?? '')\n if (!TAX_KINDS.has(kind)) return null\n const label = (value: unknown) => (typeof value === 'string' && value.trim() ? value.trim().slice(0, BASIS_LABEL_MAX) : '')\n if (kind === 'rate') {\n const pct = Number(source['pct'])\n if (!Number.isFinite(pct)) return null\n const named = label(source['label'])\n return { kind, pct, ...(named ? { label: named } : {}) }\n }\n if (kind === 'service') {\n const taxCents = Math.round(Number(source['taxCents']))\n if (!Number.isFinite(taxCents) || taxCents < 0) return null\n const named = label(source['providerLabel'])\n return { kind, taxCents, ...(named ? { providerLabel: named } : {}) }\n }\n if (kind === 'at-payment') return { kind }\n const reason = String(source['reason'] ?? '')\n return { kind: 'none', reason: (NO_TAX_REASONS.has(reason) ? reason : 'not-collected') as QuoteNoTaxReason }\n}\n\n/**\n * A basis as one short string: what the quote page sends back with Pay, so a\n * payment is refused when the tax it would charge is not the tax the page\n * showed, and what a session records as the basis it charged. Equal bases\n * have one key.\n */\nexport function quoteTaxBasisKey(basis: QuoteTaxBasis): string {\n return JSON.stringify(tidyTaxBasis(basis) ?? { kind: 'none', reason: 'not-collected' })\n}\n\n/** A basis back from {@link quoteTaxBasisKey}, or null for anything else. */\nexport function quoteTaxBasisFromKey(key: unknown): QuoteTaxBasis | null {\n if (typeof key !== 'string' || !key || key.length > 500) return null\n try {\n return tidyTaxBasis(JSON.parse(key))\n } catch {\n return null\n }\n}\n\n/*==========================================\n * THE CUSTOMER'S PAGE\n *=========================================*/\n\n/** An address as the quote page prints it: no phone. */\nexport interface QuotePageAddress {\n name: string | null\n line1: string | null\n line2: string | null\n city: string | null\n state: string | null\n postalCode: string | null\n country: string | null\n}\n\nexport interface QuotePageLine {\n name: string\n /** The option and add-ons chosen, as order lines print them. */\n variantLabel: string | null\n description: string | null\n sku: string | null\n quantity: number\n unitAmountCents: number\n /** What the line charges: 0 for an included line. */\n amountCents: number\n /** Included at no charge. */\n included: boolean\n}\n\n/** Where the quote stands, as its customer sees it. */\nexport type QuotePageStatus = 'unpaid' | 'paid' | 'canceled' | 'refunded'\n\n/** A proof as the quote page lists it: no storage path, nothing about who attached it. */\nexport interface QuotePageProof {\n id: string\n name: string\n contentType: string\n size: number\n /** Shown in the page as a picture; everything else is a download. */\n inline: boolean\n}\n\n/** The customer's latest answer to the revision the page shows. */\nexport interface QuotePageResponse {\n action: 'approve' | 'changes'\n atMs: number\n /** With an approval: the name it was given under. */\n name: string | null\n comment: string | null\n /** How many files came with it. */\n files: number\n}\n\n/**\n * What the quote page shows. Allow-listed, never spread: the order document\n * carries the customer's email and phone, Stripe ids, the business's own\n * timeline and who wrote the quote, none of which a forwarded link may show.\n * New fields are added here deliberately, or not at all.\n */\nexport interface QuotePageView {\n state: 'quote'\n /**\n * What the page shows (AGL-4099): a quote, or an invoice for an order the\n * business sent one for. An invoice has no proofs and no approval, and the\n * page says \"invoice\" where a quote's says \"quote\".\n */\n kind: 'quote' | 'invoice'\n /**\n * A proof for the customer to answer, with no price yet (AGL-4184): the page\n * shows no lines, totals or Pay, and the view carries none of them.\n */\n proofOnly: boolean\n storeName: string\n /** `Quote #1042`, `Proof #1042` for a proof only quote, or `Invoice #1042`. */\n number: string\n /** When the quote was last written, which is the date it carries. */\n dateMs: number | null\n /**\n * The edit of the quote this view shows. Pay sends it back, and a quote\n * changed since is refused, so nobody pays for a version they have not seen.\n */\n version: number\n currency: string\n customerName: string | null\n company: string | null\n billTo: QuotePageAddress | null\n shipTo: QuotePageAddress | null\n lines: QuotePageLine[]\n totals: {\n itemsCents: number\n discountCents: number\n shippingCents: number\n taxCents: number\n totalCents: number\n }\n /** `10% off`, or null for an amount or no discount. */\n discountLabel: string | null\n /** The tax line's label, or `Tax is added at payment`. */\n taxLabel: string\n /** Stripe Tax works the tax out when the customer pays; `taxCents` is 0 until then. */\n taxAtPayment: boolean\n /**\n * The customer picks a shipping rate when they pay (an invoiced draft\n * order, AGL-4099); `shippingCents` is 0 until then. A quote's shipping is\n * priced on it, so this is false for every quote.\n */\n shippingAtPayment: boolean\n notes: string | null\n terms: string | null\n status: QuotePageStatus\n statusLabel: string\n paidAtMs: number | null\n /** The order's status page, once paid. */\n receiptUrl: string | null\n /** The business asks the customer to approve the proof before paying. */\n approvalRequired: boolean\n /** A Pay button belongs on the page. */\n payable: boolean\n /**\n * What the page says in place of Pay when the business can't take payments\n * online right now (AGL-4162): the Pay route's own refusal, word for word.\n * Null otherwise, and the page asks the customer to contact the business.\n */\n notPayableMessage: string | null\n /**\n * The tax the quote's totals are priced under ({@link quoteTaxBasisKey}),\n * which Pay sends back as `tax`: a quote whose tax would charge differently\n * from the page is shown again before it is paid (AGL-4162). Null for an\n * invoice, whose tax is fixed when it is made, and once paid.\n */\n taxKey: string | null\n /** The revision the page shows (AGL-4096). */\n revision: number\n /** That revision's proofs. */\n proofs: QuotePageProof[]\n /** The customer's latest answer to it, if any. */\n response: QuotePageResponse | null\n /** Approve and Request changes belong on the page. */\n respondable: boolean\n}\n\n/** What a signed link for an older version of the quote opens: nothing of the quote. */\nexport interface QuotePageReplacedView {\n state: 'replaced'\n storeName: string\n}\n\nconst text = (value: unknown): string | null => {\n const trimmed = typeof value === 'string' ? value.trim() : ''\n return trimmed ? trimmed : null\n}\n\nconst cents = (value: unknown): number => {\n const number = Math.round(Number(value))\n return Number.isFinite(number) ? number : 0\n}\n\n/** An address as the pay link's page prints it, or null when it says nothing. */\nexport function quotePageAddress(address: OrderAddress | null | undefined): QuotePageAddress | null {\n if (!address) return null\n const view: QuotePageAddress = {\n name: text(address.name),\n line1: text(address.line1),\n line2: text(address.line2),\n city: text(address.city),\n state: text(address.state),\n postalCode: text(address.postalCode),\n country: text(address.country),\n }\n return Object.values(view).some(Boolean) ? view : null\n}\n\n/** Where an order stands as the pay link's page says it. */\nexport function quotePageStatus(status: OrderStatus | string | undefined): { status: QuotePageStatus; label: string } {\n if (status === 'pending') return { status: 'unpaid', label: 'Unpaid' }\n if (status === 'cancelled') return { status: 'canceled', label: 'Canceled' }\n if (status === 'refunded') return { status: 'refunded', label: 'Refunded' }\n return { status: 'paid', label: 'Paid' }\n}\n\nfunction discountLabel(discount: QuoteDiscount | null | undefined): string | null {\n if (discount?.kind !== 'percent' || !(Number(discount.pct) > 0)) return null\n return `${Number(discount.pct)}% off`\n}\n\n/** When the quote was paid: its stamp, else the timeline's `paid` event. */\nfunction paidAt(order: Pick<HostOrder, 'status' | 'quote' | 'timeline'>): number | null {\n if (order.status === 'pending') return null\n const stamped = Number(order.quote?.paidAtMs)\n if (Number.isFinite(stamped) && stamped > 0) return stamped\n const event = (order.timeline ?? []).find((entry) => entry?.event === 'paid')\n return event ? Number(event.atMs) || null : null\n}\n\n/**\n * The quote page's view of an order document on the `quote` channel. Totals\n * are the stored lines' through {@link computeQuoteTotals} until the quote is\n * paid, and the paid order's own totals (what Stripe charged) after. The tax\n * is {@link quotePayTax}'s for the store given, and Pay belongs on the page\n * only when nothing would refuse it: the store's payments included, when the\n * caller says whether it can take them.\n */\nexport function buildQuotePageView(input: {\n order: Pick<HostOrder, 'number' | 'status' | 'lineItems' | 'totals' | 'quote' | 'timeline'>\n orderId: string\n storeName: string\n currency: string\n /** The order's status page, for a paid quote. */\n receiptUrl?: string | null\n /** The store's sales tax choice, which a quote saved before it was made takes. */\n store?: PayLinkStore | null\n /** Whether the business can take a card payment now; absent, it is not judged here. */\n paymentsReady?: boolean\n}): QuotePageView {\n const { order } = input\n const quote = order.quote\n const lines = order.lineItems ?? []\n const status = quotePageStatus(order.status)\n const unpaid = status.status === 'unpaid'\n const proofOnly = quoteIsProofOnly(order)\n const payTax = quotePayTax(quote, input.store)\n const charge = quoteCheckoutCharge(order, input.orderId, input.store)\n const stored = order.totals\n const totals = proofOnly\n ? { itemsCents: 0, discountCents: 0, shippingCents: 0, taxCents: 0, totalCents: 0 }\n : unpaid || !stored\n ? {\n itemsCents: charge.itemsCents,\n discountCents: charge.discountCents,\n shippingCents: charge.shippingCents,\n taxCents: charge.taxCents,\n totalCents: charge.totalCents,\n }\n : {\n itemsCents: cents(stored.itemsCents),\n discountCents: cents(stored.discountCents),\n shippingCents: cents(stored.shippingCents),\n taxCents: cents(stored.taxCents),\n totalCents: cents(stored.totalCents),\n }\n const approvalRequired = unpaid && !proofOnly && quotePaymentBlockedByApproval(quote)\n const taxAtPayment = unpaid && !proofOnly && payTax.basis.kind === 'at-payment'\n const refused = unpaid\n ? payLinkRefusalWithPayments(quotePayRefusal(order, input.orderId, input.store), input.paymentsReady)\n : null\n return {\n state: 'quote',\n kind: 'quote',\n proofOnly,\n storeName: input.storeName,\n number: proofOnly ? formatProofNumber(order, input.orderId) : formatQuoteNumber(order, input.orderId),\n dateMs: Number(quote?.updatedAtMs ?? quote?.createdAtMs) || null,\n version: Number(quote?.updatedAtMs) || 0,\n currency: input.currency || 'USD',\n customerName: text(quote?.customer?.name) ?? text(quote?.customer?.company),\n company: text(quote?.customer?.name) ? text(quote?.customer?.company) : null,\n billTo: quotePageAddress(quote?.billTo),\n shipTo: quotePageAddress(quote?.shipTo),\n lines: quotePageLines(lines),\n totals,\n discountLabel: discountLabel(quote?.discount),\n // Once paid, the tax is what was charged: Stripe's figure under Stripe Tax.\n taxLabel: proofOnly ? '' : unpaid || payTax.basis.kind !== 'at-payment' ? describeQuoteTax(payTax.basis) : 'Tax',\n taxAtPayment,\n shippingAtPayment: false,\n notes: text(quote?.notes),\n terms: text(quote?.terms),\n status: status.status,\n statusLabel: status.label,\n paidAtMs: paidAt(order),\n receiptUrl: unpaid ? null : (input.receiptUrl ?? null),\n approvalRequired,\n payable: unpaid && refused === null,\n notPayableMessage:\n !proofOnly && refused === 'payments-unavailable' ? payLinkPaymentsUnavailableMessage(input.storeName, 'quote') : null,\n taxKey: unpaid && !proofOnly ? quoteTaxBasisKey(payTax.basis) : null,\n revision: Math.max(1, Number(quote?.revision ?? 1) || 1),\n proofs: currentQuoteProofs(quote).map((proof) => ({\n id: String(proof.id),\n name: String(proof.name ?? 'Proof'),\n contentType: String(proof.contentType ?? ''),\n size: Math.max(0, cents(proof.size)),\n inline: visitorUploadIsInline(String(proof.contentType ?? '')),\n })),\n response: pageResponse(quote),\n // The page is only ever a quote's, whatever the caller picked off the order.\n respondable: quoteRespondRefusal({ channel: 'quote', status: order.status, quote }) === null,\n }\n}\n\n/** Order lines as the pay link's page lists them: what each charges, nothing about stock or cost. */\nexport function quotePageLines(lines: readonly OrderLineItem[]): QuotePageLine[] {\n return lines.map((line) => {\n const included = line.included === true\n const quantity = Math.max(0, cents(line.quantity))\n const unitAmountCents = included ? 0 : Math.max(0, cents(line.unitAmountCents))\n return {\n name: String(line.name ?? ''),\n variantLabel: text(line.variantLabel),\n description: text(line.description),\n sku: text(line.sku),\n quantity,\n unitAmountCents,\n amountCents: unitAmountCents * quantity,\n included,\n }\n })\n}\n\n/** The latest answer, as the page may show it back to the link's holder: never the address or browser. */\nfunction pageResponse(quote: OrderQuote | null | undefined): QuotePageResponse | null {\n const latest = latestQuoteResponse(quote)\n if (!latest) return null\n return {\n action: latest.action === 'approve' ? 'approve' : 'changes',\n atMs: Number(latest.atMs) || 0,\n name: latest.action === 'approve' ? text(latest.name) : null,\n comment: latest.action === 'changes' ? text(latest.comment) : null,\n files: latest.files?.length ?? 0,\n }\n}\n\n/*==========================================\n * WHAT A PAYMENT CHARGES\n *=========================================*/\n\n/** One line of a quote's Checkout Session. */\nexport interface QuoteCheckoutLine {\n name: string\n /** The quote's lines this one charges for, as the hosted page lists them. */\n description: string\n amountCents: number\n /** False for tax-exempt products: no rate is applied and Stripe Tax is told it is nontaxable. */\n taxable: boolean\n}\n\n/** What a quote's Checkout Session charges, priced from the stored quote alone. */\nexport interface QuoteCheckoutCharge {\n /** The goods grouped by whether they are taxed, so one rate taxes exactly the quote's taxable amount. */\n lines: QuoteCheckoutLine[]\n itemsCents: number\n discountCents: number\n /** The goods after the discount: what the business is paid for them. */\n goodsCents: number\n taxableCents: number\n shippingCents: number\n /** The quote's tax; 0 when Stripe Tax works it out at payment. */\n taxCents: number\n /**\n * The percentage applied to the taxed line as a Stripe tax rate, or null\n * when no rate is applied (no tax, Stripe Tax, or tax charged as its own line).\n */\n taxPct: number | null\n taxAtPayment: boolean\n /** Goods, shipping and the quote's tax. Stripe Tax adds to it at payment. */\n totalCents: number\n /** What the platform fee prices the goods as. */\n feeProductType: ProductType\n}\n\nconst LINE_DESCRIPTION_MAX = 500\n\nfunction lineSummary(lines: readonly OrderLineItem[]): string {\n const parts = lines.map((line) => {\n const label = line.variantLabel ? `${line.name} (${line.variantLabel})` : line.name\n return `${Math.max(1, cents(line.quantity))} × ${label}`\n })\n const summary = parts.join(', ')\n return summary.length > LINE_DESCRIPTION_MAX ? `${summary.slice(0, LINE_DESCRIPTION_MAX - 1)}…` : summary\n}\n\n/** What the fee ladder prices the quote's charged goods as: physical when any line ships. */\nfunction feeProductTypeOf(lines: readonly OrderLineItem[]): ProductType {\n const charged = lines.filter((line) => !line.included)\n const types = new Set(charged.map((line) => line.productType ?? 'physical'))\n if (types.has('physical') || types.size === 0) return 'physical'\n return types.has('service') ? 'service' : 'digital'\n}\n\n/**\n * The charge for a quote, from its stored lines, discount, shipping and tax\n * basis through {@link computeQuoteTotals} — the same function that priced it\n * when it was saved, so the page, the session and the stored quote agree. The\n * basis is {@link quotePayTax}'s: a quote saved before the store chose its\n * sales tax is charged under the store's choice now.\n *\n * The goods are charged as at most two lines, the taxed and the tax-exempt,\n * each after its share of the discount. A store rate is applied to the taxed\n * line as one Stripe tax rate, so Stripe's tax is the rate on exactly the\n * amount the quote taxed, and the quote's figure is what is collected. A tax\n * service's figure is carried the same way, as the percentage of the taxed\n * line it amounts to. Included lines charge nothing and are not sent.\n */\nexport function quoteCheckoutCharge(\n order: Pick<HostOrder, 'number' | 'lineItems' | 'quote'>,\n orderId: string,\n store?: PayLinkStore | null,\n): QuoteCheckoutCharge {\n return payLinkCheckoutCharge({\n lineItems: order.lineItems ?? [],\n tax: quotePayTax(order.quote, store).basis,\n discount: order.quote?.discount ?? null,\n shippingCents: Math.max(0, cents(order.quote?.shipping?.amountCents)),\n label: formatQuoteNumber(order, orderId),\n })\n}\n\n/**\n * What a pay link's Checkout Session charges for stored lines, a discount,\n * fixed shipping and a tax basis, under a label (`Quote #1042`,\n * `Invoice #1042`): {@link quoteCheckoutCharge}'s pricing, shared with an\n * invoiced order's (AGL-4099), so both are charged the same way.\n */\nexport function payLinkCheckoutCharge(input: {\n lineItems: readonly OrderLineItem[]\n tax: QuoteTaxBasis\n discount: QuoteDiscount | null\n shippingCents: number\n label: string\n}): QuoteCheckoutCharge {\n const { lineItems, tax, discount, shippingCents, label } = input\n const totals = computeQuoteTotals({ lines: lineItems, discount, shippingCents, tax })\n const amounts = quoteLineAmounts(lineItems, discount)\n const groups = [true, false].map((taxable) => {\n const members = lineItems\n .map((line, index) => ({ line, net: amounts.netCents[index] }))\n .filter(({ line, net }) => net > 0 && (line.taxExempt !== true) === taxable)\n return {\n taxable,\n amountCents: members.reduce((sum, { net }) => sum + net, 0),\n description: lineSummary(members.map(({ line }) => line)),\n }\n })\n const charged = groups.filter((group) => group.amountCents > 0)\n const lines: QuoteCheckoutLine[] = charged.map((group) => ({\n name: charged.length > 1 && !group.taxable ? `${label} (tax-exempt items)` : label,\n description: group.description,\n amountCents: group.amountCents,\n taxable: group.taxable,\n }))\n const taxableCents = groups[0].amountCents\n const taxPct =\n totals.taxCents > 0 && taxableCents > 0\n ? tax.kind === 'rate'\n ? Number(tax.pct)\n : engineLineTaxPercentages([{ amountCents: taxableCents, taxCents: totals.taxCents }], 0)[0]\n : null\n // A tax service can tax a quote whose goods are all exempt (on its\n // shipping, say): with no taxed line to carry a rate, its figure is\n // charged as a line of its own, so the customer still pays what the quote says.\n if (totals.taxCents > 0 && taxPct === null) {\n lines.push({\n name: tax.providerLabel ? `Sales tax (${tax.providerLabel})` : 'Sales tax',\n description: label,\n amountCents: totals.taxCents,\n taxable: false,\n })\n }\n return {\n lines,\n itemsCents: totals.itemsCents,\n discountCents: totals.discountCents,\n goodsCents: totals.itemsCents - totals.discountCents,\n taxableCents,\n shippingCents,\n taxCents: totals.taxCents,\n taxPct,\n taxAtPayment: totals.taxAtPayment,\n totalCents: totals.totalCents,\n feeProductType: feeProductTypeOf(lineItems),\n }\n}\n\n/*==========================================\n * WHETHER IT CAN BE PAID NOW\n *=========================================*/\n\nexport type QuotePayRefusal =\n | 'paid'\n | 'closed'\n | 'approval-required'\n | 'tax-undecided'\n | 'nothing-to-pay'\n\n/**\n * Why a quote cannot be paid now, or null when it can. With the store, its\n * tax is {@link quotePayTax}'s, and a store that has not chosen its sales tax\n * refuses every sale (AGL-1999), whatever basis the quote was saved with.\n */\nexport function quotePayRefusal(\n order: Pick<HostOrder, 'number' | 'status' | 'lineItems' | 'quote'>,\n orderId: string,\n store?: PayLinkStore | null,\n): QuotePayRefusal | null {\n if (order.status === 'cancelled' || order.status === 'refunded') return 'closed'\n if (order.status !== 'pending') return 'paid'\n // No lines, no price: nothing to pay, whatever the proof or the store's setup says (AGL-4184).\n if (quoteIsProofOnly(order)) return 'nothing-to-pay'\n if (quotePaymentBlockedByApproval(order.quote)) return 'approval-required'\n if (store && storefrontTaxDecision({ settings: store.tax }).kind === 'undecided') return 'tax-undecided'\n if (quoteTaxIsUndecided(quotePayTax(order.quote, store).basis)) return 'tax-undecided'\n if (quoteCheckoutCharge(order, orderId, store).totalCents < QUOTE_MIN_CHARGE_CENTS) return 'nothing-to-pay'\n return null\n}\n\n/**\n * A pay link's refusal once the store's payments are judged too: a business\n * that can't take a card payment now outranks every refusal but the ones a\n * payment never gets past (paid, closed, not linked, waiting on the\n * customer's approval). `paymentsReady` absent leaves the refusal as it is.\n */\nexport function payLinkRefusalWithPayments<Reason extends string>(\n reason: Reason | null,\n paymentsReady: boolean | undefined,\n): Reason | 'payments-unavailable' | null {\n if (paymentsReady !== false) return reason\n if (reason === 'paid' || reason === 'closed' || reason === 'not-payable' || reason === 'approval-required') {\n return reason\n }\n return 'payments-unavailable'\n}\n\n/** What the customer is told when the business can't take a card payment now: the page's words and Pay's. */\nexport function payLinkPaymentsUnavailableMessage(storeName: string, kind: 'quote' | 'invoice'): string {\n return `${storeName || 'This business'} can’t take payments online right now. Contact them to pay this ${kind === 'invoice' ? 'invoice' : 'quote'}.`\n}\n\n/** What the customer is told for a {@link QuotePayRefusal}, naming the business. */\nexport function quotePayRefusalMessage(reason: QuotePayRefusal, storeName: string): string {\n const business = storeName.trim() || 'the business'\n switch (reason) {\n case 'paid':\n return 'This quote has been paid.'\n case 'closed':\n return `This quote is closed. Contact ${business} with any questions.`\n case 'approval-required':\n return `${business} asks you to approve the proof before you pay.`\n case 'tax-undecided':\n return `${business} has not finished setting up payments. Contact them to pay this quote.`\n case 'nothing-to-pay':\n return `This quote has nothing to pay by card. Contact ${business} with any questions.`\n }\n}\n\n/*==========================================\n * WHEN A PAYMENT COMPLETES\n *=========================================*/\n\n/** What a completed Checkout Session says about the quote it paid. */\nexport interface QuotePaymentFacts {\n sessionId: string\n paymentIntentId: string | null\n /** The link version and quote edit the session was minted for, from its metadata. */\n linkVersion?: string | number | null\n quoteUpdatedAtMs?: string | number | null\n paidAtMs: number\n /** The payer, as Stripe collected them. */\n email: string | null\n name: string | null\n /** What Stripe charged in all, and its shipping and tax parts. */\n amountTotalCents: number | null\n shippingCents: number\n taxCents: number\n /** The platform fee the session was minted with. */\n feeCents: number\n taxMode: StorefrontTaxMode\n /** The address Stripe collected, when the session asked for one. */\n shippingAddress: OrderAddress | null\n /**\n * The tax the session charged under when it was not the quote's stored\n * basis: {@link quotePayTax}'s answer for a quote saved before the store\n * chose its sales tax, carried on the session (`quoteTax`,\n * {@link quoteTaxBasisKey}) by the press that opened it (AGL-4162).\n */\n taxBasis?: QuoteTaxBasis | null\n}\n\n/**\n * What a completed payment does to a quote:\n *\n * - `pay`: the quote is unpaid and the payment is for it as it stands, so it\n * becomes the order.\n * - `superseded`: the quote is unpaid, but the payment was made through a pay\n * link the business replaced, or for a version of the quote it has since\n * changed. Taking it would record a sale at a price or for a link the\n * business withdrew.\n * - `already-paid`: another payment paid the quote first.\n * - `redelivery`: Stripe sending this same payment again; nothing to do.\n *\n * The two refusals keep the money visible: they are recorded on the quote and\n * the business is told, so a payment is never fulfilled twice and never lost.\n */\nexport type QuotePaymentDisposition = 'pay' | 'superseded' | 'already-paid' | 'redelivery'\n\nexport function quotePaymentDisposition(\n order: Pick<HostOrder, 'status' | 'quote' | 'checkoutSessionId' | 'paymentIntentId'> &\n Partial<Pick<HostOrder, 'payLink'>>,\n payment: Pick<QuotePaymentFacts, 'sessionId' | 'paymentIntentId' | 'linkVersion' | 'quoteUpdatedAtMs'>,\n): QuotePaymentDisposition {\n // Any order's pay link answers the same way (AGL-4099): an invoiced order\n // reads its version and its recorded payments off `payLink`, and its\n // session carries no quote edit to compare.\n const recorded = orderPayLinkUnmatched(order).some((entry) => entry?.sessionId === payment.sessionId)\n if (recorded) return 'redelivery'\n if (order.status !== 'pending') {\n const same =\n (order.checkoutSessionId && order.checkoutSessionId === payment.sessionId) ||\n (payment.paymentIntentId && order.paymentIntentId === payment.paymentIntentId)\n return same ? 'redelivery' : 'already-paid'\n }\n const sentVersion = payment.linkVersion\n if (sentVersion != null && sentVersion !== '' && Number(sentVersion) !== orderPayLinkVersion(order)) {\n return 'superseded'\n }\n const sentEdit = payment.quoteUpdatedAtMs\n if (sentEdit != null && sentEdit !== '' && Number(sentEdit) !== Number(order.quote?.updatedAtMs)) {\n return 'superseded'\n }\n return 'pay'\n}\n\n/** A payment the quote could not take, as {@link QuoteUnmatchedPayment} records it. */\nexport function quoteUnmatchedPayment(\n facts: Pick<QuotePaymentFacts, 'sessionId' | 'paymentIntentId' | 'amountTotalCents' | 'paidAtMs'>,\n reason: QuoteUnmatchedPayment['reason'],\n): QuoteUnmatchedPayment {\n return {\n sessionId: facts.sessionId,\n paymentIntentId: facts.paymentIntentId,\n amountCents: Math.max(0, cents(facts.amountTotalCents)),\n atMs: facts.paidAtMs,\n reason,\n }\n}\n\n/** The timeline line for a payment the quote (or an order's invoice, AGL-4099) could not take. */\nexport function quoteUnmatchedPaymentDetail(\n entry: QuoteUnmatchedPayment,\n noun: 'quote' | 'invoice' = 'quote',\n): string {\n const amount = `$${(entry.amountCents / 100).toFixed(2)}`\n return entry.reason === 'superseded'\n ? `A payment of ${amount} came through a pay link that was replaced, or for an earlier ` +\n `version of this ${noun}. The money is in Stripe and this ${noun} records no sale for it; ` +\n 'refund it in Stripe, or reconcile it by hand.'\n : `A second payment of ${amount} came in after this ${noun} was paid. The money is in Stripe ` +\n 'and no second sale was recorded; refund it in Stripe, or reconcile it by hand.'\n}\n\n/**\n * The order a paid quote becomes, the whole document as it will stand. A\n * quote carries none of the fields order lists read (`commerce-quotes.ts`);\n * paying it writes them:\n *\n * - `createdAtMs` is the time it was paid, the moment it became an order, so\n * it lists and counts on the day the money came in.\n * - The customer moves to the top-level fields every order reader asks\n * (`customerEmail`, `customerName`, `customerPhone`, `customerRecord`), the\n * payer's own email first, as a paid draft takes it.\n * - The address Stripe collected ships it, else the quote's ship-to; the\n * quote's bill-to bills it.\n * - The totals are what Stripe charged: its shipping and tax where it charged\n * any, the platform fee the session was minted with, and its total.\n * - The quote keeps the tax basis it was paid under: the session's\n * ({@link QuotePaymentFacts.taxBasis}) where the press took the store's\n * choice for it, so the order says how its tax was worked out.\n * - The list fields (`withOrderListFields`) are stamped from all of that.\n */\nexport function paidQuoteOrder(\n order: HostOrder,\n orderId: string,\n facts: QuotePaymentFacts,\n): HostOrder & OrderListFields & { updatedAtMs: number; requiresShipping: boolean } {\n const quote = order.quote as OrderQuote\n const customer = quote?.customer ?? {}\n const stored = order.totals ?? { itemsCents: 0, discountCents: 0, shippingCents: 0, taxCents: 0, feeCents: 0, totalCents: 0 }\n const shippingCents = facts.shippingCents > 0 ? facts.shippingCents : cents(stored.shippingCents)\n const taxCents = facts.taxCents > 0 ? facts.taxCents : cents(stored.taxCents)\n const totalCents =\n facts.amountTotalCents != null && Number.isFinite(facts.amountTotalCents)\n ? facts.amountTotalCents\n : cents(stored.itemsCents) - cents(stored.discountCents) + shippingCents + taxCents\n const shippingAddress = facts.shippingAddress ?? quote?.shipTo ?? null\n const label = formatOrderNumber(order, orderId)\n const paid: HostOrder & { updatedAtMs: number } = {\n ...order,\n status: 'paid',\n createdAtMs: facts.paidAtMs,\n customerEmail: text(facts.email) ?? text(customer.email),\n customerName: text(customer.name) ?? text(facts.name) ?? text(customer.company),\n ...(text(customer.phone) ? { customerPhone: text(customer.phone) } : {}),\n ...(customer.record?.kind && customer.record?.id ? { customerRecord: { ...customer.record } } : {}),\n ...(shippingAddress ? { shippingAddress: { ...shippingAddress } } : {}),\n ...(quote?.billTo ? { billingAddress: { ...quote.billTo } } : {}),\n totals: {\n itemsCents: cents(stored.itemsCents),\n discountCents: cents(stored.discountCents),\n shippingCents,\n taxCents,\n feeCents: Math.max(0, cents(facts.feeCents)),\n totalCents,\n },\n taxMode: facts.taxMode,\n paymentIntentId: facts.paymentIntentId ?? undefined,\n checkoutSessionId: facts.sessionId,\n timeline: appendOrderEvent(order, 'paid', `${label} paid through its pay link`, facts.paidAtMs),\n quote: { ...quote, ...(facts.taxBasis ? { tax: facts.taxBasis } : {}), paidAtMs: facts.paidAtMs },\n // New to a shipping tool's feed from the moment it is paid.\n updatedAtMs: facts.paidAtMs,\n }\n if (!paid.paymentIntentId) delete paid.paymentIntentId\n return withOrderListFields(orderId, paid)\n}\n"],"names":["visitorUploadIsInline","appendOrderEvent","formatOrderNumber","computeQuoteTotals","describeQuoteTax","formatProofNumber","formatQuoteNumber","quoteIsProofOnly","quoteLineAmounts","quotePaymentBlockedByApproval","quoteTaxBasisFromSettings","currentQuoteProofs","latestQuoteResponse","quoteRespondRefusal","storefrontTaxDecision","engineLineTaxPercentages","storeTaxAllowsEngine","withOrderListFields","QUOTE_MIN_CHARGE_CENTS","quoteLinkVersion","quote","version","Math","floor","Number","linkVersion","isFinite","orderPayLinkVersion","order","payLink","orderPayLinkUnmatched","list","unmatchedPayments","Array","isArray","filter","entry","payLinkStoreOf","settings","tax","quoteTaxIsUndecided","basis","kind","reason","quotePayTax","store","stored","source","shipTo","TAX_KINDS","Set","NO_TAX_REASONS","BASIS_LABEL_MAX","tidyTaxBasis","raw","String","has","label","value","trim","slice","pct","named","taxCents","round","providerLabel","quoteTaxBasisKey","JSON","stringify","quoteTaxBasisFromKey","key","length","parse","text","trimmed","cents","number","quotePageAddress","address","view","name","line1","line2","city","state","postalCode","country","Object","values","some","Boolean","quotePageStatus","status","discountLabel","discount","paidAt","stamped","paidAtMs","event","timeline","find","atMs","buildQuotePageView","input","lines","lineItems","unpaid","proofOnly","payTax","charge","quoteCheckoutCharge","orderId","totals","itemsCents","discountCents","shippingCents","totalCents","approvalRequired","taxAtPayment","refused","payLinkRefusalWithPayments","quotePayRefusal","paymentsReady","storeName","dateMs","updatedAtMs","createdAtMs","currency","customerName","customer","company","billTo","quotePageLines","taxLabel","shippingAtPayment","notes","terms","statusLabel","receiptUrl","payable","notPayableMessage","payLinkPaymentsUnavailableMessage","taxKey","revision","max","proofs","map","proof","id","contentType","size","inline","response","pageResponse","respondable","channel","line","included","quantity","unitAmountCents","variantLabel","description","sku","amountCents","latest","action","comment","files","LINE_DESCRIPTION_MAX","lineSummary","parts","summary","join","feeProductTypeOf","charged","types","productType","payLinkCheckoutCharge","shipping","amounts","groups","taxable","members","index","net","netCents","taxExempt","reduce","sum","group","taxableCents","taxPct","push","goodsCents","feeProductType","quotePayRefusalMessage","business","quotePaymentDisposition","payment","recorded","sessionId","same","checkoutSessionId","paymentIntentId","sentVersion","sentEdit","quoteUpdatedAtMs","quoteUnmatchedPayment","facts","amountTotalCents","quoteUnmatchedPaymentDetail","noun","amount","toFixed","paidQuoteOrder","feeCents","shippingAddress","paid","customerEmail","email","phone","customerPhone","record","customerRecord","billingAddress","taxMode","undefined","taxBasis"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,qBAAqB,QAAQ,wCAAuC;AAE7E,SACEC,gBAAgB,EAChBC,iBAAiB,QAKZ,uBAAmB;AAC1B,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,iBAAiB,EACjBC,iBAAiB,EACjBC,gBAAgB,EAChBC,gBAAgB,EAChBC,6BAA6B,EAC7BC,yBAAyB,QAOpB,uBAAmB;AAC1B,SAASC,kBAAkB,EAAEC,mBAAmB,EAAEC,mBAAmB,QAAQ,6BAAyB;AAEtG,SAASC,qBAAqB,QAAgC,6BAAyB;AACvF,SAASC,wBAAwB,EAAEC,oBAAoB,QAAQ,2BAAuB;AACtF,SAASC,mBAAmB,QAA8B,yBAAqB;AAE/E;;;;;;;;;;;;;;;;;;;;;2CAqB2C,GAE3C,oFAAoF,GACpF,OAAO,MAAMC,yBAAyB,GAAE;AAExC,mEAAmE,GACnE,OAAO,SAASC,iBAAiBC,KAAyD;IACxF,MAAMC,UAAUC,KAAKC,KAAK,CAACC,OAAOJ,yBAAAA,MAAOK,WAAW;IACpD,OAAOD,OAAOE,QAAQ,CAACL,YAAYA,WAAW,IAAIA,UAAU;AAC9D;AAEA;;;;;CAKC,GACD,OAAO,SAASM,oBAAoBC,KAAuE;QAEvEA;IADlC,IAAIA,yBAAAA,MAAOR,KAAK,EAAE,OAAOD,iBAAiBS,MAAMR,KAAK;IACrD,MAAMC,UAAUC,KAAKC,KAAK,CAACC,OAAOI,0BAAAA,iBAAAA,MAAOC,OAAO,qBAAdD,eA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B,MAAM,0BAA0B,CAAC,EAAEuJ,MAAM/G,QAAQ;QAC9F7E,OAAO,aAAKA,OAAW4L,MAAMmB,QAAQ,GAAG;YAAE5L,KAAKyK,MAAMmB,QAAQ;QAAC,IAAI,CAAC;YAAIlI,UAAU+G,MAAM/G,QAAQ;;QAC/F,4DAA4D;QAC5D4B,aAAamF,MAAM/G,QAAQ;;IAE7B,IAAI,CAACwH,KAAKd,eAAe,EAAE,OAAOc,KAAKd,eAAe;IACtD,OAAO1L,oBAAoB8F,SAAS0G;AACtC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce-quote-pay.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { visitorUploadIsInline } from '@aglyn/aglyn/app-utils/visitor-upload'\nimport type { ProductType } from './commerce'\nimport {\n appendOrderEvent,\n formatOrderNumber,\n type HostOrder,\n type OrderAddress,\n type OrderLineItem,\n type OrderStatus,\n} from './commerce-orders'\nimport {\n computeQuoteTotals,\n describeQuoteTax,\n formatProofNumber,\n formatQuoteNumber,\n QUOTE_DEFAULT_APPROVAL_STATEMENTS,\n quoteIsProofOnly,\n quoteLineAmounts,\n quotePaymentBlockedByApproval,\n quoteTaxBasisFromSettings,\n type OrderQuote,\n type QuoteDiscount,\n type QuoteNoTaxReason,\n type QuoteTaxBasis,\n type QuoteTaxKind,\n type QuoteUnmatchedPayment,\n} from './commerce-quotes'\nimport {\n currentQuoteProofs,\n latestQuoteResponse,\n quoteProofAccessMessage,\n quoteRespondRefusal,\n type QuoteProofAccess,\n} from './commerce-quote-proofs'\nimport type { QuotePageMessage } from './commerce-quote-messages'\nimport type { TaxSettings } from './commerce-tax'\nimport { storefrontTaxDecision, type StorefrontTaxMode } from './commerce-tax-decision'\nimport { engineLineTaxPercentages, storeTaxAllowsEngine } from './commerce-tax-engine'\nimport { withOrderListFields, type OrderListFields } from './order-list-fields'\n\n/*==========================================\n * PAYING A QUOTE (AGL-4094).\n *\n * The customer opens the quote on the business's own site from a signed pay\n * link, sees it, and pays it. Everything here is pure, so the page's view,\n * the pay route's charge and the webhook's paid order all come from one\n * reading of the stored quote, and none of them from anything the browser\n * sends:\n *\n * - {@link buildQuotePageView}: the ONE projection of a quote that leaves the\n * server for a visitor holding the link, allow-listed field by field.\n * - {@link quoteCheckoutCharge}: what a Checkout Session charges, priced from\n * the stored lines, discount, shipping and tax basis.\n * - {@link quotePayRefusal}: why a quote cannot be paid now, if it cannot.\n * - {@link quotePaymentDisposition} and {@link paidQuoteOrder}: what a\n * completed payment does to the quote, and the order it becomes.\n * - {@link quotePayTax}: the tax every one of them reads, which for a quote\n * saved before the store chose its sales tax is the store's choice now.\n *\n * The customer side has no expiry and no open or closed states: a quote and\n * its link stay until the quote is paid or the business replaces the link.\n *=========================================*/\n\n/** Stripe's smallest card charge; a quote that totals less cannot be paid by card. */\nexport const QUOTE_MIN_CHARGE_CENTS = 50\n\n/** The pay link version a quote is on; absent reads as the first. */\nexport function quoteLinkVersion(quote: Pick<OrderQuote, 'linkVersion'> | null | undefined): number {\n const version = Math.floor(Number(quote?.linkVersion))\n return Number.isFinite(version) && version >= 1 ? version : 1\n}\n\n/**\n * The pay link version any order is on (AGL-4099). A quote keeps its version\n * where slice 2 put it, `quote.linkVersion`, so every link already sent keeps\n * verifying; any other order keeps it as `payLink.version`. Absent reads as\n * the first either way.\n */\nexport function orderPayLinkVersion(order: Partial<Pick<HostOrder, 'quote' | 'payLink'>> | null | undefined): number {\n if (order?.quote) return quoteLinkVersion(order.quote)\n const version = Math.floor(Number(order?.payLink?.version))\n return Number.isFinite(version) && version >= 1 ? version : 1\n}\n\n/** Payments the order's pay link could not take: a quote's on the quote, any other order's on `payLink`. */\nexport function orderPayLinkUnmatched(\n order: Partial<Pick<HostOrder, 'quote' | 'payLink'>> | null | undefined,\n): QuoteUnmatchedPayment[] {\n const list = order?.quote ? order.quote.unmatchedPayments : order?.payLink?.unmatchedPayments\n return Array.isArray(list) ? list.filter((entry) => entry && typeof entry === 'object') : []\n}\n\n/*==========================================\n * THE TAX A QUOTE IS SHOWN AND PAID UNDER\n *=========================================*/\n\n/**\n * The store a pay link is read against: its sales tax choice, as\n * `hosts/{hostId}/settings/store` keeps it under `tax`. Absent or null, the\n * store has not chosen.\n */\nexport interface PayLinkStore {\n tax?: TaxSettings | null\n}\n\n/** The store a pay link reads, from the store settings document's data (nothing, for no document). */\nexport function payLinkStoreOf(settings: { tax?: unknown } | null | undefined): PayLinkStore {\n const tax = settings?.tax\n return { tax: tax && typeof tax === 'object' ? (tax as TaxSettings) : null }\n}\n\n/** Whether a basis records that nobody had chosen the store's sales tax, which is no choice at all. */\nexport function quoteTaxIsUndecided(basis: Pick<QuoteTaxBasis, 'kind' | 'reason'> | null | undefined): boolean {\n return basis?.kind === 'none' && basis.reason === 'undecided'\n}\n\n/**\n * Where a quote's tax comes from when it is shown and paid:\n *\n * - `stored`: the basis it was saved with.\n * - `current`: it was saved before the store chose, and takes the store's\n * choice as it stands now.\n * - `save`: it was saved before the store chose, and the store's choice now\n * prices it only when it is saved again.\n */\nexport type QuotePayTaxSource = 'stored' | 'current' | 'save'\n\nexport interface QuotePayTax {\n basis: QuoteTaxBasis\n source: QuotePayTaxSource\n}\n\n/**\n * The tax a quote is shown, charged and paid under (AGL-4162): the one answer\n * the quote page, Pay, the payment's record (carried on its session) and the\n * console's notice all read.\n *\n * A quote keeps the basis it was saved with, except one saved before the\n * store chose how it handles sales tax. That basis records no choice, so the\n * quote takes the store's choice as it stands now, through the same\n * `quoteTaxBasisFromSettings` the editor prices a save with: no sales tax,\n * prices that include tax, or Stripe Tax at payment. Nothing is written for\n * it; the next save stores the same basis.\n *\n * The store's own rates on prices that exclude tax are the one choice not\n * taken this way. On those settings a save asks the site's tax service where\n * one is connected (`priceQuote` in `server/quote.ts`), and only that save\n * knows the figure: which service is connected is the tax service's own to\n * say. Such a quote keeps its basis, and so stays unpaid, until it is saved.\n *\n * Without a store, the stored basis stands.\n */\nexport function quotePayTax(\n quote: Pick<OrderQuote, 'tax' | 'shipTo'> | null | undefined,\n store?: PayLinkStore | null,\n): QuotePayTax {\n const stored: QuoteTaxBasis = quote?.tax ?? { kind: 'none', reason: 'not-collected' }\n if (!store || !quoteTaxIsUndecided(stored)) return { basis: stored, source: 'stored' }\n if (storefrontTaxDecision({ settings: store.tax }).kind === 'undecided') return { basis: stored, source: 'stored' }\n if (storeTaxAllowsEngine(store.tax)) return { basis: stored, source: 'save' }\n return { basis: quoteTaxBasisFromSettings(store.tax, quote?.shipTo), source: 'current' }\n}\n\nconst TAX_KINDS: ReadonlySet<string> = new Set<QuoteTaxKind>(['rate', 'service', 'at-payment', 'none'])\nconst NO_TAX_REASONS: ReadonlySet<string> = new Set<QuoteNoTaxReason>([\n 'not-collected',\n 'prices-include-tax',\n 'no-rate',\n 'undecided',\n])\nconst BASIS_LABEL_MAX = 120\n\n/** A basis holding only what its kind carries, in one order, or null for anything that is not one. */\nfunction tidyTaxBasis(raw: unknown): QuoteTaxBasis | null {\n if (!raw || typeof raw !== 'object') return null\n const source = raw as Record<string, unknown>\n const kind = String(source['kind'] ?? '')\n if (!TAX_KINDS.has(kind)) return null\n const label = (value: unknown) => (typeof value === 'string' && value.trim() ? value.trim().slice(0, BASIS_LABEL_MAX) : '')\n if (kind === 'rate') {\n const pct = Number(source['pct'])\n if (!Number.isFinite(pct)) return null\n const named = label(source['label'])\n return { kind, pct, ...(named ? { label: named } : {}) }\n }\n if (kind === 'service') {\n const taxCents = Math.round(Number(source['taxCents']))\n if (!Number.isFinite(taxCents) || taxCents < 0) return null\n const named = label(source['providerLabel'])\n return { kind, taxCents, ...(named ? { providerLabel: named } : {}) }\n }\n if (kind === 'at-payment') return { kind }\n const reason = String(source['reason'] ?? '')\n return { kind: 'none', reason: (NO_TAX_REASONS.has(reason) ? reason : 'not-collected') as QuoteNoTaxReason }\n}\n\n/**\n * A basis as one short string: what the quote page sends back with Pay, so a\n * payment is refused when the tax it would charge is not the tax the page\n * showed, and what a session records as the basis it charged. Equal bases\n * have one key.\n */\nexport function quoteTaxBasisKey(basis: QuoteTaxBasis): string {\n return JSON.stringify(tidyTaxBasis(basis) ?? { kind: 'none', reason: 'not-collected' })\n}\n\n/** A basis back from {@link quoteTaxBasisKey}, or null for anything else. */\nexport function quoteTaxBasisFromKey(key: unknown): QuoteTaxBasis | null {\n if (typeof key !== 'string' || !key || key.length > 500) return null\n try {\n return tidyTaxBasis(JSON.parse(key))\n } catch {\n return null\n }\n}\n\n/*==========================================\n * THE CUSTOMER'S PAGE\n *=========================================*/\n\n/** An address as the quote page prints it: no phone. */\nexport interface QuotePageAddress {\n name: string | null\n line1: string | null\n line2: string | null\n city: string | null\n state: string | null\n postalCode: string | null\n country: string | null\n}\n\nexport interface QuotePageLine {\n name: string\n /** The option and add-ons chosen, as order lines print them. */\n variantLabel: string | null\n description: string | null\n sku: string | null\n quantity: number\n unitAmountCents: number\n /** What the line charges: 0 for an included line. */\n amountCents: number\n /** Included at no charge. */\n included: boolean\n}\n\n/** Where the quote stands, as its customer sees it. */\nexport type QuotePageStatus = 'unpaid' | 'paid' | 'canceled' | 'refunded'\n\n/** A proof as the quote page lists it: no storage path, nothing about who attached it. */\nexport interface QuotePageProof {\n id: string\n name: string\n contentType: string\n size: number\n /** Shown in the page as a picture; everything else is a download. */\n inline: boolean\n}\n\n/** The customer's latest answer to the revision the page shows. */\nexport interface QuotePageResponse {\n action: 'approve' | 'changes'\n atMs: number\n /** The name it was given under: an approval's, or a rejection's (AGL-4206). */\n name: string | null\n comment: string | null\n /** How many files came with it. */\n files: number\n /** With an approval: what they ticked before approving (AGL-4206). */\n confirmed: string[]\n}\n\n/**\n * What the quote page shows. Allow-listed, never spread: the order document\n * carries the customer's email and phone, Stripe ids, the business's own\n * timeline and who wrote the quote, none of which a forwarded link may show.\n * New fields are added here deliberately, or not at all.\n */\nexport interface QuotePageView {\n state: 'quote'\n /**\n * What the page shows (AGL-4099): a quote, or an invoice for an order the\n * business sent one for. An invoice has no proofs and no approval, and the\n * page says \"invoice\" where a quote's says \"quote\".\n */\n kind: 'quote' | 'invoice'\n /**\n * A proof for the customer to answer, with no price yet (AGL-4184): the page\n * shows no lines, totals or Pay, and the view carries none of them.\n */\n proofOnly: boolean\n storeName: string\n /** `Quote #1042`, `Proof #1042` for a proof only quote, or `Invoice #1042`. */\n number: string\n /** When the quote was last written, which is the date it carries. */\n dateMs: number | null\n /**\n * The edit of the quote this view shows. Pay sends it back, and a quote\n * changed since is refused, so nobody pays for a version they have not seen.\n */\n version: number\n currency: string\n customerName: string | null\n company: string | null\n billTo: QuotePageAddress | null\n shipTo: QuotePageAddress | null\n lines: QuotePageLine[]\n totals: {\n itemsCents: number\n discountCents: number\n shippingCents: number\n taxCents: number\n totalCents: number\n }\n /** `10% off`, or null for an amount or no discount. */\n discountLabel: string | null\n /** The tax line's label, or `Tax is added at payment`. */\n taxLabel: string\n /** Stripe Tax works the tax out when the customer pays; `taxCents` is 0 until then. */\n taxAtPayment: boolean\n /**\n * The customer picks a shipping rate when they pay (an invoiced draft\n * order, AGL-4099); `shippingCents` is 0 until then. A quote's shipping is\n * priced on it, so this is false for every quote.\n */\n shippingAtPayment: boolean\n notes: string | null\n terms: string | null\n status: QuotePageStatus\n statusLabel: string\n paidAtMs: number | null\n /** The order's status page, once paid. */\n receiptUrl: string | null\n /** The business asks the customer to approve the proof before paying. */\n approvalRequired: boolean\n /** A Pay button belongs on the page. */\n payable: boolean\n /**\n * What the page says in place of Pay when the business can't take payments\n * online right now (AGL-4162): the Pay route's own refusal, word for word.\n * Null otherwise, and the page asks the customer to contact the business.\n */\n notPayableMessage: string | null\n /**\n * The tax the quote's totals are priced under ({@link quoteTaxBasisKey}),\n * which Pay sends back as `tax`: a quote whose tax would charge differently\n * from the page is shown again before it is paid (AGL-4162). Null for an\n * invoice, whose tax is fixed when it is made, and once paid.\n */\n taxKey: string | null\n /** The revision the page shows (AGL-4096). */\n revision: number\n /** That revision's proofs. */\n proofs: QuotePageProof[]\n /** The customer's latest answer to it, if any. */\n response: QuotePageResponse | null\n /** Approve and Reject with changes belong on the page. */\n respondable: boolean\n /**\n * What the customer ticks before Approve works (AGL-4206), word for word;\n * Approve sends them back. Empty when the page takes no answer.\n */\n approvalStatements: string[]\n /**\n * Whether this browser may see the proof (AGL-4206): `open`, or a sign-in\n * the quote waits on. While it waits the view carries no proofs, no answer\n * and nothing to respond with, and `proofAccessMessage` says what to do.\n */\n proofAccess: QuoteProofAccess\n proofAccessMessage: string | null\n /**\n * The quote's conversation with the business, oldest first (AGL-4207):\n * what each side wrote, never an address or who on the team sent it. The\n * customer writes back on the page. Empty for an invoice, and while the\n * proof waits on a sign-in.\n */\n messages: QuotePageMessage[]\n}\n\n/** What a signed link for an older version of the quote opens: nothing of the quote. */\nexport interface QuotePageReplacedView {\n state: 'replaced'\n storeName: string\n}\n\nconst text = (value: unknown): string | null => {\n const trimmed = typeof value === 'string' ? value.trim() : ''\n return trimmed ? trimmed : null\n}\n\nconst cents = (value: unknown): number => {\n const number = Math.round(Number(value))\n return Number.isFinite(number) ? number : 0\n}\n\n/** An address as the pay link's page prints it, or null when it says nothing. */\nexport function quotePageAddress(address: OrderAddress | null | undefined): QuotePageAddress | null {\n if (!address) return null\n const view: QuotePageAddress = {\n name: text(address.name),\n line1: text(address.line1),\n line2: text(address.line2),\n city: text(address.city),\n state: text(address.state),\n postalCode: text(address.postalCode),\n country: text(address.country),\n }\n return Object.values(view).some(Boolean) ? view : null\n}\n\n/** Where an order stands as the pay link's page says it. */\nexport function quotePageStatus(status: OrderStatus | string | undefined): { status: QuotePageStatus; label: string } {\n if (status === 'pending') return { status: 'unpaid', label: 'Unpaid' }\n if (status === 'cancelled') return { status: 'canceled', label: 'Canceled' }\n if (status === 'refunded') return { status: 'refunded', label: 'Refunded' }\n return { status: 'paid', label: 'Paid' }\n}\n\nfunction discountLabel(discount: QuoteDiscount | null | undefined): string | null {\n if (discount?.kind !== 'percent' || !(Number(discount.pct) > 0)) return null\n return `${Number(discount.pct)}% off`\n}\n\n/** When the quote was paid: its stamp, else the timeline's `paid` event. */\nfunction paidAt(order: Pick<HostOrder, 'status' | 'quote' | 'timeline'>): number | null {\n if (order.status === 'pending') return null\n const stamped = Number(order.quote?.paidAtMs)\n if (Number.isFinite(stamped) && stamped > 0) return stamped\n const event = (order.timeline ?? []).find((entry) => entry?.event === 'paid')\n return event ? Number(event.atMs) || null : null\n}\n\n/**\n * The quote page's view of an order document on the `quote` channel. Totals\n * are the stored lines' through {@link computeQuoteTotals} until the quote is\n * paid, and the paid order's own totals (what Stripe charged) after. The tax\n * is {@link quotePayTax}'s for the store given, and Pay belongs on the page\n * only when nothing would refuse it: the store's payments included, when the\n * caller says whether it can take them.\n */\nexport function buildQuotePageView(input: {\n order: Pick<HostOrder, 'number' | 'status' | 'lineItems' | 'totals' | 'quote' | 'timeline'>\n orderId: string\n storeName: string\n currency: string\n /** The order's status page, for a paid quote. */\n receiptUrl?: string | null\n /** The store's sales tax choice, which a quote saved before it was made takes. */\n store?: PayLinkStore | null\n /** Whether the business can take a card payment now; absent, it is not judged here. */\n paymentsReady?: boolean\n /** What the customer ticks before approving: the store's {@link quoteApprovalStatements}. */\n approvalStatements?: readonly string[]\n /** Whether this browser may see the proof ({@link quoteProofAccess}); absent reads as `open`. */\n proofAccess?: QuoteProofAccess\n /** The quote's conversation ({@link quotePageMessages}); absent, none is shown. */\n messages?: QuotePageMessage[]\n}): QuotePageView {\n const { order } = input\n const quote = order.quote\n const lines = order.lineItems ?? []\n const status = quotePageStatus(order.status)\n const unpaid = status.status === 'unpaid'\n const proofOnly = quoteIsProofOnly(order)\n const payTax = quotePayTax(quote, input.store)\n const charge = quoteCheckoutCharge(order, input.orderId, input.store)\n const stored = order.totals\n const totals = proofOnly\n ? { itemsCents: 0, discountCents: 0, shippingCents: 0, taxCents: 0, totalCents: 0 }\n : unpaid || !stored\n ? {\n itemsCents: charge.itemsCents,\n discountCents: charge.discountCents,\n shippingCents: charge.shippingCents,\n taxCents: charge.taxCents,\n totalCents: charge.totalCents,\n }\n : {\n itemsCents: cents(stored.itemsCents),\n discountCents: cents(stored.discountCents),\n shippingCents: cents(stored.shippingCents),\n taxCents: cents(stored.taxCents),\n totalCents: cents(stored.totalCents),\n }\n const approvalRequired = unpaid && !proofOnly && quotePaymentBlockedByApproval(quote)\n const taxAtPayment = unpaid && !proofOnly && payTax.basis.kind === 'at-payment'\n const refused = unpaid\n ? payLinkRefusalWithPayments(quotePayRefusal(order, input.orderId, input.store), input.paymentsReady)\n : null\n const view: QuotePageView = {\n state: 'quote',\n kind: 'quote',\n proofOnly,\n storeName: input.storeName,\n number: proofOnly ? formatProofNumber(order, input.orderId) : formatQuoteNumber(order, input.orderId),\n dateMs: Number(quote?.updatedAtMs ?? quote?.createdAtMs) || null,\n version: Number(quote?.updatedAtMs) || 0,\n currency: input.currency || 'USD',\n customerName: text(quote?.customer?.name) ?? text(quote?.customer?.company),\n company: text(quote?.customer?.name) ? text(quote?.customer?.company) : null,\n billTo: quotePageAddress(quote?.billTo),\n shipTo: quotePageAddress(quote?.shipTo),\n lines: quotePageLines(lines),\n totals,\n discountLabel: discountLabel(quote?.discount),\n // Once paid, the tax is what was charged: Stripe's figure under Stripe Tax.\n taxLabel: proofOnly ? '' : unpaid || payTax.basis.kind !== 'at-payment' ? describeQuoteTax(payTax.basis) : 'Tax',\n taxAtPayment,\n shippingAtPayment: false,\n notes: text(quote?.notes),\n terms: text(quote?.terms),\n status: status.status,\n statusLabel: status.label,\n paidAtMs: paidAt(order),\n receiptUrl: unpaid ? null : (input.receiptUrl ?? null),\n approvalRequired,\n payable: unpaid && refused === null,\n notPayableMessage:\n !proofOnly && refused === 'payments-unavailable' ? payLinkPaymentsUnavailableMessage(input.storeName, 'quote') : null,\n taxKey: unpaid && !proofOnly ? quoteTaxBasisKey(payTax.basis) : null,\n revision: Math.max(1, Number(quote?.revision ?? 1) || 1),\n proofs: currentQuoteProofs(quote).map((proof) => ({\n id: String(proof.id),\n name: String(proof.name ?? 'Proof'),\n contentType: String(proof.contentType ?? ''),\n size: Math.max(0, cents(proof.size)),\n inline: visitorUploadIsInline(String(proof.contentType ?? '')),\n })),\n response: pageResponse(quote),\n // The page is only ever a quote's, whatever the caller picked off the order.\n respondable: quoteRespondRefusal({ channel: 'quote', status: order.status, quote }) === null,\n messages: input.messages ?? [],\n approvalStatements: [],\n proofAccess: 'open',\n proofAccessMessage: null,\n }\n const page: QuotePageView = {\n ...view,\n approvalStatements: view.respondable ? [...(input.approvalStatements ?? QUOTE_DEFAULT_APPROVAL_STATEMENTS)] : [],\n }\n const access = input.proofAccess ?? 'open'\n // A revision with no proof has nothing to sign in for.\n if (access === 'open' || page.proofs.length === 0) return page\n // Waiting on a sign-in, the view carries nothing of the proof or the answer.\n return {\n ...page,\n proofs: [],\n response: null,\n respondable: false,\n // The conversation is about the proof, so it waits on the same sign-in (AGL-4207).\n messages: [],\n approvalStatements: [],\n proofAccess: access,\n proofAccessMessage: quoteProofAccessMessage(access, input.storeName),\n }\n}\n\n/** Order lines as the pay link's page lists them: what each charges, nothing about stock or cost. */\nexport function quotePageLines(lines: readonly OrderLineItem[]): QuotePageLine[] {\n return lines.map((line) => {\n const included = line.included === true\n const quantity = Math.max(0, cents(line.quantity))\n const unitAmountCents = included ? 0 : Math.max(0, cents(line.unitAmountCents))\n return {\n name: String(line.name ?? ''),\n variantLabel: text(line.variantLabel),\n description: text(line.description),\n sku: text(line.sku),\n quantity,\n unitAmountCents,\n amountCents: unitAmountCents * quantity,\n included,\n }\n })\n}\n\n/** The latest answer, as the page may show it back to the link's holder: never the address or browser. */\nfunction pageResponse(quote: OrderQuote | null | undefined): QuotePageResponse | null {\n const latest = latestQuoteResponse(quote)\n if (!latest) return null\n return {\n action: latest.action === 'approve' ? 'approve' : 'changes',\n atMs: Number(latest.atMs) || 0,\n name: text(latest.name),\n comment: latest.action === 'changes' ? text(latest.comment) : null,\n files: latest.files?.length ?? 0,\n confirmed: latest.action === 'approve' && Array.isArray(latest.confirmed) ? latest.confirmed.map(String) : [],\n }\n}\n\n/*==========================================\n * WHAT A PAYMENT CHARGES\n *=========================================*/\n\n/** One line of a quote's Checkout Session. */\nexport interface QuoteCheckoutLine {\n name: string\n /** The quote's lines this one charges for, as the hosted page lists them. */\n description: string\n amountCents: number\n /** False for tax-exempt products: no rate is applied and Stripe Tax is told it is nontaxable. */\n taxable: boolean\n}\n\n/** What a quote's Checkout Session charges, priced from the stored quote alone. */\nexport interface QuoteCheckoutCharge {\n /** The goods grouped by whether they are taxed, so one rate taxes exactly the quote's taxable amount. */\n lines: QuoteCheckoutLine[]\n itemsCents: number\n discountCents: number\n /** The goods after the discount: what the business is paid for them. */\n goodsCents: number\n taxableCents: number\n shippingCents: number\n /** The quote's tax; 0 when Stripe Tax works it out at payment. */\n taxCents: number\n /**\n * The percentage applied to the taxed line as a Stripe tax rate, or null\n * when no rate is applied (no tax, Stripe Tax, or tax charged as its own line).\n */\n taxPct: number | null\n taxAtPayment: boolean\n /** Goods, shipping and the quote's tax. Stripe Tax adds to it at payment. */\n totalCents: number\n /** What the platform fee prices the goods as. */\n feeProductType: ProductType\n}\n\nconst LINE_DESCRIPTION_MAX = 500\n\nfunction lineSummary(lines: readonly OrderLineItem[]): string {\n const parts = lines.map((line) => {\n const label = line.variantLabel ? `${line.name} (${line.variantLabel})` : line.name\n return `${Math.max(1, cents(line.quantity))} × ${label}`\n })\n const summary = parts.join(', ')\n return summary.length > LINE_DESCRIPTION_MAX ? `${summary.slice(0, LINE_DESCRIPTION_MAX - 1)}…` : summary\n}\n\n/** What the fee ladder prices the quote's charged goods as: physical when any line ships. */\nfunction feeProductTypeOf(lines: readonly OrderLineItem[]): ProductType {\n const charged = lines.filter((line) => !line.included)\n const types = new Set(charged.map((line) => line.productType ?? 'physical'))\n if (types.has('physical') || types.size === 0) return 'physical'\n return types.has('service') ? 'service' : 'digital'\n}\n\n/**\n * The charge for a quote, from its stored lines, discount, shipping and tax\n * basis through {@link computeQuoteTotals} — the same function that priced it\n * when it was saved, so the page, the session and the stored quote agree. The\n * basis is {@link quotePayTax}'s: a quote saved before the store chose its\n * sales tax is charged under the store's choice now.\n *\n * The goods are charged as at most two lines, the taxed and the tax-exempt,\n * each after its share of the discount. A store rate is applied to the taxed\n * line as one Stripe tax rate, so Stripe's tax is the rate on exactly the\n * amount the quote taxed, and the quote's figure is what is collected. A tax\n * service's figure is carried the same way, as the percentage of the taxed\n * line it amounts to. Included lines charge nothing and are not sent.\n */\nexport function quoteCheckoutCharge(\n order: Pick<HostOrder, 'number' | 'lineItems' | 'quote'>,\n orderId: string,\n store?: PayLinkStore | null,\n): QuoteCheckoutCharge {\n return payLinkCheckoutCharge({\n lineItems: order.lineItems ?? [],\n tax: quotePayTax(order.quote, store).basis,\n discount: order.quote?.discount ?? null,\n shippingCents: Math.max(0, cents(order.quote?.shipping?.amountCents)),\n label: formatQuoteNumber(order, orderId),\n })\n}\n\n/**\n * What a pay link's Checkout Session charges for stored lines, a discount,\n * fixed shipping and a tax basis, under a label (`Quote #1042`,\n * `Invoice #1042`): {@link quoteCheckoutCharge}'s pricing, shared with an\n * invoiced order's (AGL-4099), so both are charged the same way.\n */\nexport function payLinkCheckoutCharge(input: {\n lineItems: readonly OrderLineItem[]\n tax: QuoteTaxBasis\n discount: QuoteDiscount | null\n shippingCents: number\n label: string\n}): QuoteCheckoutCharge {\n const { lineItems, tax, discount, shippingCents, label } = input\n const totals = computeQuoteTotals({ lines: lineItems, discount, shippingCents, tax })\n const amounts = quoteLineAmounts(lineItems, discount)\n const groups = [true, false].map((taxable) => {\n const members = lineItems\n .map((line, index) => ({ line, net: amounts.netCents[index] }))\n .filter(({ line, net }) => net > 0 && (line.taxExempt !== true) === taxable)\n return {\n taxable,\n amountCents: members.reduce((sum, { net }) => sum + net, 0),\n description: lineSummary(members.map(({ line }) => line)),\n }\n })\n const charged = groups.filter((group) => group.amountCents > 0)\n const lines: QuoteCheckoutLine[] = charged.map((group) => ({\n name: charged.length > 1 && !group.taxable ? `${label} (tax-exempt items)` : label,\n description: group.description,\n amountCents: group.amountCents,\n taxable: group.taxable,\n }))\n const taxableCents = groups[0].amountCents\n const taxPct =\n totals.taxCents > 0 && taxableCents > 0\n ? tax.kind === 'rate'\n ? Number(tax.pct)\n : engineLineTaxPercentages([{ amountCents: taxableCents, taxCents: totals.taxCents }], 0)[0]\n : null\n // A tax service can tax a quote whose goods are all exempt (on its\n // shipping, say): with no taxed line to carry a rate, its figure is\n // charged as a line of its own, so the customer still pays what the quote says.\n if (totals.taxCents > 0 && taxPct === null) {\n lines.push({\n name: tax.providerLabel ? `Sales tax (${tax.providerLabel})` : 'Sales tax',\n description: label,\n amountCents: totals.taxCents,\n taxable: false,\n })\n }\n return {\n lines,\n itemsCents: totals.itemsCents,\n discountCents: totals.discountCents,\n goodsCents: totals.itemsCents - totals.discountCents,\n taxableCents,\n shippingCents,\n taxCents: totals.taxCents,\n taxPct,\n taxAtPayment: totals.taxAtPayment,\n totalCents: totals.totalCents,\n feeProductType: feeProductTypeOf(lineItems),\n }\n}\n\n/*==========================================\n * WHETHER IT CAN BE PAID NOW\n *=========================================*/\n\nexport type QuotePayRefusal =\n | 'paid'\n | 'closed'\n | 'approval-required'\n | 'tax-undecided'\n | 'nothing-to-pay'\n\n/**\n * Why a quote cannot be paid now, or null when it can. With the store, its\n * tax is {@link quotePayTax}'s, and a store that has not chosen its sales tax\n * refuses every sale (AGL-1999), whatever basis the quote was saved with.\n */\nexport function quotePayRefusal(\n order: Pick<HostOrder, 'number' | 'status' | 'lineItems' | 'quote'>,\n orderId: string,\n store?: PayLinkStore | null,\n): QuotePayRefusal | null {\n if (order.status === 'cancelled' || order.status === 'refunded') return 'closed'\n if (order.status !== 'pending') return 'paid'\n // No lines, no price: nothing to pay, whatever the proof or the store's setup says (AGL-4184).\n if (quoteIsProofOnly(order)) return 'nothing-to-pay'\n if (quotePaymentBlockedByApproval(order.quote)) return 'approval-required'\n if (store && storefrontTaxDecision({ settings: store.tax }).kind === 'undecided') return 'tax-undecided'\n if (quoteTaxIsUndecided(quotePayTax(order.quote, store).basis)) return 'tax-undecided'\n if (quoteCheckoutCharge(order, orderId, store).totalCents < QUOTE_MIN_CHARGE_CENTS) return 'nothing-to-pay'\n return null\n}\n\n/**\n * A pay link's refusal once the store's payments are judged too: a business\n * that can't take a card payment now outranks every refusal but the ones a\n * payment never gets past (paid, closed, not linked, waiting on the\n * customer's approval). `paymentsReady` absent leaves the refusal as it is.\n */\nexport function payLinkRefusalWithPayments<Reason extends string>(\n reason: Reason | null,\n paymentsReady: boolean | undefined,\n): Reason | 'payments-unavailable' | null {\n if (paymentsReady !== false) return reason\n if (reason === 'paid' || reason === 'closed' || reason === 'not-payable' || reason === 'approval-required') {\n return reason\n }\n return 'payments-unavailable'\n}\n\n/** What the customer is told when the business can't take a card payment now: the page's words and Pay's. */\nexport function payLinkPaymentsUnavailableMessage(storeName: string, kind: 'quote' | 'invoice'): string {\n return `${storeName || 'This business'} can’t take payments online right now. Contact them to pay this ${kind === 'invoice' ? 'invoice' : 'quote'}.`\n}\n\n/** What the customer is told for a {@link QuotePayRefusal}, naming the business. */\nexport function quotePayRefusalMessage(reason: QuotePayRefusal, storeName: string): string {\n const business = storeName.trim() || 'the business'\n switch (reason) {\n case 'paid':\n return 'This quote has been paid.'\n case 'closed':\n return `This quote is closed. Contact ${business} with any questions.`\n case 'approval-required':\n return `${business} asks you to approve the proof before you pay.`\n case 'tax-undecided':\n return `${business} has not finished setting up payments. Contact them to pay this quote.`\n case 'nothing-to-pay':\n return `This quote has nothing to pay by card. Contact ${business} with any questions.`\n }\n}\n\n/*==========================================\n * WHEN A PAYMENT COMPLETES\n *=========================================*/\n\n/** What a completed Checkout Session says about the quote it paid. */\nexport interface QuotePaymentFacts {\n sessionId: string\n paymentIntentId: string | null\n /** The link version and quote edit the session was minted for, from its metadata. */\n linkVersion?: string | number | null\n quoteUpdatedAtMs?: string | number | null\n paidAtMs: number\n /** The payer, as Stripe collected them. */\n email: string | null\n name: string | null\n /** What Stripe charged in all, and its shipping and tax parts. */\n amountTotalCents: number | null\n shippingCents: number\n taxCents: number\n /** The platform fee the session was minted with. */\n feeCents: number\n taxMode: StorefrontTaxMode\n /** The address Stripe collected, when the session asked for one. */\n shippingAddress: OrderAddress | null\n /**\n * The tax the session charged under when it was not the quote's stored\n * basis: {@link quotePayTax}'s answer for a quote saved before the store\n * chose its sales tax, carried on the session (`quoteTax`,\n * {@link quoteTaxBasisKey}) by the press that opened it (AGL-4162).\n */\n taxBasis?: QuoteTaxBasis | null\n}\n\n/**\n * What a completed payment does to a quote:\n *\n * - `pay`: the quote is unpaid and the payment is for it as it stands, so it\n * becomes the order.\n * - `superseded`: the quote is unpaid, but the payment was made through a pay\n * link the business replaced, or for a version of the quote it has since\n * changed. Taking it would record a sale at a price or for a link the\n * business withdrew.\n * - `already-paid`: another payment paid the quote first.\n * - `redelivery`: Stripe sending this same payment again; nothing to do.\n *\n * The two refusals keep the money visible: they are recorded on the quote and\n * the business is told, so a payment is never fulfilled twice and never lost.\n */\nexport type QuotePaymentDisposition = 'pay' | 'superseded' | 'already-paid' | 'redelivery'\n\nexport function quotePaymentDisposition(\n order: Pick<HostOrder, 'status' | 'quote' | 'checkoutSessionId' | 'paymentIntentId'> &\n Partial<Pick<HostOrder, 'payLink'>>,\n payment: Pick<QuotePaymentFacts, 'sessionId' | 'paymentIntentId' | 'linkVersion' | 'quoteUpdatedAtMs'>,\n): QuotePaymentDisposition {\n // Any order's pay link answers the same way (AGL-4099): an invoiced order\n // reads its version and its recorded payments off `payLink`, and its\n // session carries no quote edit to compare.\n const recorded = orderPayLinkUnmatched(order).some((entry) => entry?.sessionId === payment.sessionId)\n if (recorded) return 'redelivery'\n if (order.status !== 'pending') {\n const same =\n (order.checkoutSessionId && order.checkoutSessionId === payment.sessionId) ||\n (payment.paymentIntentId && order.paymentIntentId === payment.paymentIntentId)\n return same ? 'redelivery' : 'already-paid'\n }\n const sentVersion = payment.linkVersion\n if (sentVersion != null && sentVersion !== '' && Number(sentVersion) !== orderPayLinkVersion(order)) {\n return 'superseded'\n }\n const sentEdit = payment.quoteUpdatedAtMs\n if (sentEdit != null && sentEdit !== '' && Number(sentEdit) !== Number(order.quote?.updatedAtMs)) {\n return 'superseded'\n }\n return 'pay'\n}\n\n/** A payment the quote could not take, as {@link QuoteUnmatchedPayment} records it. */\nexport function quoteUnmatchedPayment(\n facts: Pick<QuotePaymentFacts, 'sessionId' | 'paymentIntentId' | 'amountTotalCents' | 'paidAtMs'>,\n reason: QuoteUnmatchedPayment['reason'],\n): QuoteUnmatchedPayment {\n return {\n sessionId: facts.sessionId,\n paymentIntentId: facts.paymentIntentId,\n amountCents: Math.max(0, cents(facts.amountTotalCents)),\n atMs: facts.paidAtMs,\n reason,\n }\n}\n\n/** The timeline line for a payment the quote (or an order's invoice, AGL-4099) could not take. */\nexport function quoteUnmatchedPaymentDetail(\n entry: QuoteUnmatchedPayment,\n noun: 'quote' | 'invoice' = 'quote',\n): string {\n const amount = `$${(entry.amountCents / 100).toFixed(2)}`\n return entry.reason === 'superseded'\n ? `A payment of ${amount} came through a pay link that was replaced, or for an earlier ` +\n `version of this ${noun}. The money is in Stripe and this ${noun} records no sale for it; ` +\n 'refund it in Stripe, or reconcile it by hand.'\n : `A second payment of ${amount} came in after this ${noun} was paid. The money is in Stripe ` +\n 'and no second sale was recorded; refund it in Stripe, or reconcile it by hand.'\n}\n\n/**\n * The order a paid quote becomes, the whole document as it will stand. A\n * quote carries none of the fields order lists read (`commerce-quotes.ts`);\n * paying it writes them:\n *\n * - `createdAtMs` is the time it was paid, the moment it became an order, so\n * it lists and counts on the day the money came in.\n * - The customer moves to the top-level fields every order reader asks\n * (`customerEmail`, `customerName`, `customerPhone`, `customerRecord`), the\n * payer's own email first, as a paid draft takes it.\n * - The address Stripe collected ships it, else the quote's ship-to; the\n * quote's bill-to bills it.\n * - The totals are what Stripe charged: its shipping and tax where it charged\n * any, the platform fee the session was minted with, and its total.\n * - The quote keeps the tax basis it was paid under: the session's\n * ({@link QuotePaymentFacts.taxBasis}) where the press took the store's\n * choice for it, so the order says how its tax was worked out.\n * - The list fields (`withOrderListFields`) are stamped from all of that.\n */\nexport function paidQuoteOrder(\n order: HostOrder,\n orderId: string,\n facts: QuotePaymentFacts,\n): HostOrder & OrderListFields & { updatedAtMs: number; requiresShipping: boolean } {\n const quote = order.quote as OrderQuote\n const customer = quote?.customer ?? {}\n const stored = order.totals ?? { itemsCents: 0, discountCents: 0, shippingCents: 0, taxCents: 0, feeCents: 0, totalCents: 0 }\n const shippingCents = facts.shippingCents > 0 ? facts.shippingCents : cents(stored.shippingCents)\n const taxCents = facts.taxCents > 0 ? facts.taxCents : cents(stored.taxCents)\n const totalCents =\n facts.amountTotalCents != null && Number.isFinite(facts.amountTotalCents)\n ? facts.amountTotalCents\n : cents(stored.itemsCents) - cents(stored.discountCents) + shippingCents + taxCents\n const shippingAddress = facts.shippingAddress ?? quote?.shipTo ?? null\n const label = formatOrderNumber(order, orderId)\n const paid: HostOrder & { updatedAtMs: number } = {\n ...order,\n status: 'paid',\n createdAtMs: facts.paidAtMs,\n customerEmail: text(facts.email) ?? text(customer.email),\n customerName: text(customer.name) ?? text(facts.name) ?? text(customer.company),\n ...(text(customer.phone) ? { customerPhone: text(customer.phone) } : {}),\n ...(customer.record?.kind && customer.record?.id ? { customerRecord: { ...customer.record } } : {}),\n ...(shippingAddress ? { shippingAddress: { ...shippingAddress } } : {}),\n ...(quote?.billTo ? { billingAddress: { ...quote.billTo } } : {}),\n totals: {\n itemsCents: cents(stored.itemsCents),\n discountCents: cents(stored.discountCents),\n shippingCents,\n taxCents,\n feeCents: Math.max(0, cents(facts.feeCents)),\n totalCents,\n },\n taxMode: facts.taxMode,\n paymentIntentId: facts.paymentIntentId ?? undefined,\n checkoutSessionId: facts.sessionId,\n timeline: appendOrderEvent(order, 'paid', `${label} paid through its pay link`, facts.paidAtMs),\n quote: { ...quote, ...(facts.taxBasis ? { tax: facts.taxBasis } : {}), paidAtMs: facts.paidAtMs },\n // New to a shipping tool's feed from the moment it is paid.\n updatedAtMs: facts.paidAtMs,\n }\n if (!paid.paymentIntentId) delete paid.paymentIntentId\n return withOrderListFields(orderId, paid)\n}\n"],"names":["visitorUploadIsInline","appendOrderEvent","formatOrderNumber","computeQuoteTotals","describeQuoteTax","formatProofNumber","formatQuoteNumber","QUOTE_DEFAULT_APPROVAL_STATEMENTS","quoteIsProofOnly","quoteLineAmounts","quotePaymentBlockedByApproval","quoteTaxBasisFromSettings","currentQuoteProofs","latestQuoteResponse","quoteProofAccessMessage","quoteRespondRefusal","storefrontTaxDecision","engineLineTaxPercentages","storeTaxAllowsEngine","withOrderListFields","QUOTE_MIN_CHARGE_CENTS","quoteLinkVersion","quote","version","Math","floor","Number","linkVersion","isFinite","orderPayLinkVersion","order","payLink","orderPayLinkUnmatched","list","unmatchedPayments","Array","isArray","filter","entry","payLinkStoreOf","settings","tax","quoteTaxIsUndecided","basis","kind","reason","quotePayTax","store","stored","source","shipTo","TAX_KINDS","Set","NO_TAX_REASONS","BASIS_LABEL_MAX","tidyTaxBasis","raw","String","has","label","value","trim","slice","pct","named","taxCents","round","providerLabel","quoteTaxBasisKey","JSON","stringify","quoteTaxBasisFromKey","key","length","parse","text","trimmed","cents","number","quotePageAddress","address","view","name","line1","line2","city","state","postalCode","country","Object","values","some","Boolean","quotePageStatus","status","discountLabel","discount","paidAt","stamped","paidAtMs","event","timeline","find","atMs","buildQuotePageView","input","lines","lineItems","unpaid","proofOnly","payTax","charge","quoteCheckoutCharge","orderId","totals","itemsCents","discountCents","shippingCents","totalCents","approvalRequired","taxAtPayment","refused","payLinkRefusalWithPayments","quotePayRefusal","paymentsReady","storeName","dateMs","updatedAtMs","createdAtMs","currency","customerName","customer","company","billTo","quotePageLines","taxLabel","shippingAtPayment","notes","terms","statusLabel","receiptUrl","payable","notPayableMessage","payLinkPaymentsUnavailableMessage","taxKey","revision","max","proofs","map","proof","id","contentType","size","inline","response","pageResponse","respondable","channel","messages","approvalStatements","proofAccess","proofAccessMessage","page","access","line","included","quantity","unitAmountCents","variantLabel","description","sku","amountCents","latest","action","comment","files","confirmed","LINE_DESCRIPTION_MAX","lineSummary","parts","summary","join","feeProductTypeOf","charged","types","productType","payLinkCheckoutCharge","shipping","amounts","groups","taxable","members","index","net","netCents","taxExempt","reduce","sum","group","taxableCents","taxPct","push","goodsCents","feeProductType","quotePayRefusalMessage","business","quotePaymentDisposition","payment","recorded","sessionId","same","checkoutSessionId","paymentIntentId","sentVersion","sentEdit","quoteUpdatedAtMs","quoteUnmatchedPayment","facts","amountTotalCents","quoteUnmatchedPaymentDetail","noun","amount","toFixed","paidQuoteOrder","feeCents","shippingAddress","paid","customerEmail","email","phone","customerPhone","record","customerRecord","billingAddress","taxMode","undefined","taxBasis"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,qBAAqB,QAAQ,wCAAuC;AAE7E,SACEC,gBAAgB,EAChBC,iBAAiB,QAKZ,uBAAmB;AAC1B,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,iBAAiB,EACjBC,iBAAiB,EACjBC,iCAAiC,EACjCC,gBAAgB,EAChBC,gBAAgB,EAChBC,6BAA6B,EAC7BC,yBAAyB,QAOpB,uBAAmB;AAC1B,SACEC,kBAAkB,EAClBC,mBAAmB,EACnBC,uBAAuB,EACvBC,mBAAmB,QAEd,6BAAyB;AAGhC,SAASC,qBAAqB,QAAgC,6BAAyB;AACvF,SAASC,wBAAwB,EAAEC,oBAAoB,QAAQ,2BAAuB;AACtF,SAASC,mBAAmB,QAA8B,yBAAq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GAAG6B,MAAM,0BAA0B,CAAC,EAAE8J,MAAMtH,QAAQ;QAC9F7E,OAAO,aAAKA,OAAWmM,MAAMmB,QAAQ,GAAG;YAAEnM,KAAKgL,MAAMmB,QAAQ;QAAC,IAAI,CAAC;YAAIzI,UAAUsH,MAAMtH,QAAQ;;QAC/F,4DAA4D;QAC5D4B,aAAa0F,MAAMtH,QAAQ;;IAE7B,IAAI,CAAC+H,KAAKd,eAAe,EAAE,OAAOc,KAAKd,eAAe;IACtD,OAAOjM,oBAAoB8F,SAASiH;AACtC"}
|
|
@@ -150,27 +150,42 @@ export type QuoteRespondRefusal = 'not-a-quote' | 'paid' | 'no-proof' | 'too-man
|
|
|
150
150
|
/** Why the customer cannot answer the current revision now, if they cannot. */
|
|
151
151
|
export declare function quoteRespondRefusal(order: Pick<HostOrder, 'channel' | 'status' | 'quote'> | null | undefined): QuoteRespondRefusal | null;
|
|
152
152
|
export declare function quoteRespondRefusalMessage(reason: QuoteRespondRefusal, storeName: string): string;
|
|
153
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* What the customer sends: approve under a name with every statement ticked,
|
|
155
|
+
* or reject with changes (AGL-4206): what to change, under a name, with any
|
|
156
|
+
* files.
|
|
157
|
+
*/
|
|
154
158
|
export type QuoteResponseInput = {
|
|
155
159
|
action: 'approve';
|
|
156
160
|
name: string;
|
|
161
|
+
confirmed: string[];
|
|
157
162
|
} | {
|
|
158
163
|
action: 'changes';
|
|
159
164
|
comment: string;
|
|
165
|
+
name: string;
|
|
160
166
|
fileIds: string[];
|
|
161
167
|
};
|
|
162
|
-
/**
|
|
163
|
-
export
|
|
164
|
-
ok: true;
|
|
165
|
-
input: QuoteResponseInput;
|
|
166
|
-
} | {
|
|
168
|
+
/** Why an answer was refused before it reached the quote: what to fix, and (for stale statements) that the page is out of date. */
|
|
169
|
+
export type QuoteResponseInputProblem = {
|
|
167
170
|
ok: false;
|
|
168
171
|
error: string;
|
|
172
|
+
reason?: 'statements-changed';
|
|
169
173
|
};
|
|
174
|
+
/**
|
|
175
|
+
* The customer's answer as the route received it, checked and trimmed, or what
|
|
176
|
+
* to fix. An approval must tick every one of `statements` (AGL-4206), the
|
|
177
|
+
* statements the store asks for now, word for word: a statement the page
|
|
178
|
+
* showed that the store has since reworded is `statements-changed`, and the
|
|
179
|
+
* page shows them again.
|
|
180
|
+
*/
|
|
181
|
+
export declare function parseQuoteResponseInput(raw: unknown, statements?: readonly string[]): {
|
|
182
|
+
ok: true;
|
|
183
|
+
input: QuoteResponseInput;
|
|
184
|
+
} | QuoteResponseInputProblem;
|
|
170
185
|
/**
|
|
171
186
|
* The quote with the customer's answer recorded on its current revision.
|
|
172
187
|
* Approving names the revision approved and moves the quote to Approved;
|
|
173
|
-
*
|
|
188
|
+
* rejecting with changes moves it to Rejected with changes and withdraws an approval
|
|
174
189
|
* of the same revision. The latest answer is the one that counts. The
|
|
175
190
|
* business's edit stamp (`updatedAtMs`) is not touched: the quote's content
|
|
176
191
|
* did not change, and the page that sent the answer can still pay it.
|
|
@@ -189,5 +204,29 @@ export declare function applyQuoteResponse(order: HostOrder, input: QuoteRespons
|
|
|
189
204
|
ok: false;
|
|
190
205
|
reason: QuoteRespondRefusal;
|
|
191
206
|
};
|
|
192
|
-
/** One line on what the customer last said: `Approved by Jordan Lee`, `
|
|
207
|
+
/** One line on what the customer last said: `Approved by Jordan Lee`, `Rejected with changes by Jordan Lee`. */
|
|
193
208
|
export declare function describeQuoteResponse(response: Pick<QuoteCustomerResponse, 'action' | 'name'>): string;
|
|
209
|
+
/**
|
|
210
|
+
* Whether the person holding the link may see the proof and answer it:
|
|
211
|
+
* `open` (the link is enough, or they are signed in to the customer's
|
|
212
|
+
* account), `sign-in` (the customer has an account on the site and this
|
|
213
|
+
* browser is not signed in to it), or `other-account` (signed in, but to
|
|
214
|
+
* someone else's account).
|
|
215
|
+
*
|
|
216
|
+
* Only a quote that asks for it (`requireProofSignIn`) and whose customer has
|
|
217
|
+
* an account on the site (`accountId`) needs a sign-in. A guest, with no
|
|
218
|
+
* account to sign in to, keeps the private link, and Replace link still
|
|
219
|
+
* shuts that off. Nothing here opens, closes or expires.
|
|
220
|
+
*/
|
|
221
|
+
export type QuoteProofAccess = 'open' | 'sign-in' | 'other-account';
|
|
222
|
+
export declare function quoteProofAccess(input: {
|
|
223
|
+
quote: Pick<OrderQuote, 'requireProofSignIn'> | null | undefined;
|
|
224
|
+
/** The customer's own account on the site, when they have one. */
|
|
225
|
+
accountId: string | null;
|
|
226
|
+
/** The account this browser is signed in to on the site, if any. */
|
|
227
|
+
signedInAccountId: string | null;
|
|
228
|
+
}): QuoteProofAccess;
|
|
229
|
+
/** The address a quote's customer signs in with, lower-cased, or '' for a customer with none. */
|
|
230
|
+
export declare function quoteCustomerAccountEmail(quote: Pick<OrderQuote, 'customer'> | null | undefined): string;
|
|
231
|
+
/** What the page and the routes say when the proof waits on a sign-in. */
|
|
232
|
+
export declare function quoteProofAccessMessage(access: Exclude<QuoteProofAccess, 'open'>, storeName: string): string;
|