@aglyn/plugins-commerce 1.30.0 → 1.32.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 +4 -0
- package/package.json +13 -13
- package/src/lib/components/cart.js +46 -20
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/commerce-console-page.js +6 -0
- package/src/lib/components/commerce-console-page.js.map +1 -1
- package/src/lib/components/console/currencies-card.component.d.ts +21 -0
- package/src/lib/components/console/currencies-card.component.js +408 -0
- package/src/lib/components/console/currencies-card.component.js.map +1 -0
- 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 +74 -2
- package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
- package/src/lib/components/console/product-editor-dialog.component.js +47 -1
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/product-fixed-prices-fields.component.d.ts +25 -0
- package/src/lib/components/console/product-fixed-prices-fields.component.js +112 -0
- package/src/lib/components/console/product-fixed-prices-fields.component.js.map +1 -0
- package/src/lib/components/console/product-traffic-card.component.d.ts +24 -0
- package/src/lib/components/console/product-traffic-card.component.js +172 -0
- package/src/lib/components/console/product-traffic-card.component.js.map +1 -0
- package/src/lib/components/console/products-hub-card.component.js +181 -59
- package/src/lib/components/console/products-hub-card.component.js.map +1 -1
- package/src/lib/components/console/reservations-card.component.js +32 -15
- package/src/lib/components/console/reservations-card.component.js.map +1 -1
- package/src/lib/components/console/shipping-settings-card.component.js +131 -10
- package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
- package/src/lib/components/console/store-settings-card.component.js +1 -1
- package/src/lib/components/console/store-settings-card.component.js.map +1 -1
- package/src/lib/components/console/use-currency-setup.d.ts +20 -0
- package/src/lib/components/console/use-currency-setup.js +61 -0
- package/src/lib/components/console/use-currency-setup.js.map +1 -0
- package/src/lib/components/currency-selector.d.ts +36 -0
- package/src/lib/components/currency-selector.js +157 -0
- package/src/lib/components/currency-selector.js.map +1 -0
- package/src/lib/components/product-add-ons.d.ts +9 -1
- package/src/lib/components/product-add-ons.js +8 -4
- package/src/lib/components/product-add-ons.js.map +1 -1
- package/src/lib/components/product-choice-cards.d.ts +13 -1
- package/src/lib/components/product-choice-cards.js +5 -4
- package/src/lib/components/product-choice-cards.js.map +1 -1
- package/src/lib/components/product-detail.d.ts +8 -0
- package/src/lib/components/product-detail.js +38 -11
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/product-grid.d.ts +2 -0
- package/src/lib/components/product-grid.js +22 -9
- package/src/lib/components/product-grid.js.map +1 -1
- package/src/lib/components/related-products.js +6 -2
- package/src/lib/components/related-products.js.map +1 -1
- package/src/lib/components/shopper-currency.d.ts +108 -0
- package/src/lib/components/shopper-currency.js +262 -0
- package/src/lib/components/shopper-currency.js.map +1 -0
- package/src/lib/components/wishlist.js +7 -1
- package/src/lib/components/wishlist.js.map +1 -1
- package/src/lib/declarations.server.js +39 -0
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/model/commerce-currency-setup.d.ts +79 -0
- package/src/lib/model/commerce-currency-setup.js +124 -0
- package/src/lib/model/commerce-currency-setup.js.map +1 -0
- package/src/lib/model/commerce-currency.d.ts +215 -0
- package/src/lib/model/commerce-currency.js +511 -0
- package/src/lib/model/commerce-currency.js.map +1 -0
- package/src/lib/model/commerce-orders.d.ts +17 -0
- package/src/lib/model/commerce-orders.js +10 -5
- package/src/lib/model/commerce-orders.js.map +1 -1
- package/src/lib/model/commerce-record-routes.js +56 -0
- package/src/lib/model/commerce-record-routes.js.map +1 -1
- package/src/lib/model/commerce-reservations.d.ts +6 -0
- package/src/lib/model/commerce-reservations.js.map +1 -1
- package/src/lib/model/commerce-shipping.d.ts +61 -17
- package/src/lib/model/commerce-shipping.js +346 -32
- package/src/lib/model/commerce-shipping.js.map +1 -1
- package/src/lib/model/commerce.d.ts +6 -0
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/index.d.ts +2 -0
- package/src/lib/model/index.js +2 -0
- package/src/lib/model/index.js.map +1 -1
- package/src/lib/model/order-figures.js +9 -2
- package/src/lib/model/order-figures.js.map +1 -1
- package/src/lib/model/product-modifiers.d.ts +5 -0
- package/src/lib/model/product-modifiers.js.map +1 -1
- package/src/lib/model/product-write.d.ts +10 -1
- package/src/lib/model/product-write.js +13 -2
- package/src/lib/model/product-write.js.map +1 -1
- package/src/lib/server/billing-webhook.js +37 -24
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/carrier-shipping.js +3 -2
- package/src/lib/server/carrier-shipping.js.map +1 -1
- package/src/lib/server/cart-checkout.js +77 -15
- package/src/lib/server/cart-checkout.js.map +1 -1
- package/src/lib/server/cart.d.ts +12 -0
- package/src/lib/server/cart.js +52 -6
- package/src/lib/server/cart.js.map +1 -1
- package/src/lib/server/catalog.d.ts +5 -0
- package/src/lib/server/catalog.js +7 -0
- package/src/lib/server/catalog.js.map +1 -1
- package/src/lib/server/checkout.js +54 -16
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/currency.d.ts +93 -0
- package/src/lib/server/currency.js +182 -0
- package/src/lib/server/currency.js.map +1 -0
- package/src/lib/server/draft-order.js +3 -3
- package/src/lib/server/draft-order.js.map +1 -1
- package/src/lib/server/order-notifications.js +4 -2
- package/src/lib/server/order-notifications.js.map +1 -1
- package/src/lib/server/product.d.ts +9 -0
- package/src/lib/server/product.js +12 -0
- package/src/lib/server/product.js.map +1 -1
- package/src/lib/server/products-write.js +10 -2
- package/src/lib/server/products-write.js.map +1 -1
- package/src/lib/server/refund.js +3 -3
- package/src/lib/server/refund.js.map +1 -1
- package/src/lib/server/site-chat-tools.d.ts +22 -0
- package/src/lib/server/site-chat-tools.js +369 -0
- package/src/lib/server/site-chat-tools.js.map +1 -0
- package/src/lib/server/site-chat-visitor.d.ts +24 -0
- package/src/lib/server/site-chat-visitor.js +39 -0
- package/src/lib/server/site-chat-visitor.js.map +1 -0
- package/src/lib/server/site-offers.d.ts +31 -0
- package/src/lib/server/site-offers.js +91 -0
- package/src/lib/server/site-offers.js.map +1 -0
- package/src/lib/server/stays-site-search.d.ts +20 -0
- package/src/lib/server/stays-site-search.js +78 -0
- package/src/lib/server/stays-site-search.js.map +1 -0
- package/src/lib/server.js +20 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/site-chat-tool-definitions.d.ts +26 -0
- package/src/lib/site-chat-tool-definitions.js +141 -0
- package/src/lib/site-chat-tool-definitions.js.map +1 -0
- package/src/lib/site.js +8 -0
- package/src/lib/site.js.map +1 -1
- package/src/lib/subprocessors.js +7 -0
- package/src/lib/subprocessors.js.map +1 -1
|
@@ -38,12 +38,13 @@ import * as CommerceModel from "../model/index.js";
|
|
|
38
38
|
if (!quoter) return tablePlan();
|
|
39
39
|
const available = await quoter.available(input.hostId).catch(()=>false);
|
|
40
40
|
if (!available) return tablePlan();
|
|
41
|
-
const
|
|
41
|
+
const countries = CommerceModel.checkoutShippingCountries(settings);
|
|
42
|
+
const country = CommerceModel.normalizeCheckoutShippingCountry(input.destination.country, countries);
|
|
42
43
|
if (!country) {
|
|
43
44
|
// Carrier prices differ by address by construction, so a session that
|
|
44
45
|
// does not know the destination cannot be honest about any of them.
|
|
45
46
|
return {
|
|
46
|
-
countries
|
|
47
|
+
countries,
|
|
47
48
|
options: [],
|
|
48
49
|
refusal: 'destination-required'
|
|
49
50
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/carrier-shipping.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 {\n pluginShippingRateQuoter,\n quotePluginShippingRates,\n type PluginShippingParcel,\n} from '@aglyn/aglyn/plugin-manager/plugin-shipping-rates'\nimport * as CommerceModel from '../model'\n\n/**\n * LIVE CARRIER RATES AT CHECKOUT (AGL-3612): the `carrier` rate kind, priced\n * by asking core's `core.shipping-rate-quoter` — whichever plugin quotes\n * carriers — and never by importing it.\n *\n * ## Quoted before the session exists, on every door\n *\n * Stripe's hosted Checkout cannot change a session's shipping options once\n * the shopper types an address (\"The hosted page integration doesn't support\n * dynamically customizing shipping options\"), and the in-page form can only\n * by a server update after the fact — while this module's callers fix the\n * platform fee and the Connect transfer from the session's options at\n * creation. So the quote is taken BEFORE the session, against the\n * destination the shopper declares (country and postal code), and the\n * session is then restricted to that country exactly as a zone rate is\n * (AGL-1721). The same code serves cart checkout, buy-now and a draft\n * order's link, hosted and in-page, and the fee arithmetic downstream sees\n * ordinary options.\n *\n * ## The fallback is the merchant's own\n *\n * No quoter, a quoter not available for this site, or a quote that fails or\n * takes longer than {@link CommerceModel.CARRIER_QUOTE_TIMEOUT_MS}: the plan\n * is exactly the one {@link CommerceModel.planCheckoutShipping} makes from\n * the table, where a carrier rate offers nothing and its fallback rate is\n * offered. A store with no carrier rate never reaches the quoter at all, so\n * its sessions are byte-identical to the ones before this existed.\n */\n\nexport interface CarrierShippingCart {\n subtotalCents: number\n totalGrams: number\n /** One parcel's dimensions, when the cart is one product that has them. */\n parcel?: Omit<PluginShippingParcel, 'weightGrams'>\n}\n\nexport interface CarrierShippingDestination {\n country?: unknown\n postalCode?: unknown\n state?: unknown\n city?: unknown\n}\n\n/** A postal code a shopper declared, trimmed and bounded, or `undefined`. */\nexport function normalizeCheckoutPostalCode(value: unknown): string | undefined {\n if (typeof value !== 'string') return undefined\n const code = value.trim().toUpperCase().slice(0, 12)\n return /^[A-Z0-9][A-Z0-9 -]{1,11}$/.test(code) ? code : undefined\n}\n\nexport type CarrierShippingPlan = CommerceModel.CheckoutShippingPlan & {\n /** Set when the plan offers live quotes: the postal code they were priced for. */\n quotedPostalCode?: string\n /**\n * The destination's zone prices by carrier and the store can quote, but the\n * shopper has not said where in the country: ask for a postal code.\n */\n needsPostalCode?: boolean\n}\n\n/** What a shopper is told when a postal code is needed. */\nexport const CARRIER_POSTAL_CODE_MESSAGE = 'Enter the postal code you’re shipping to.'\n\n/**\n * The shipping half of a session for a store that may price by carrier.\n * See the module comment; `planCheckoutShipping` is the whole answer for any\n * store without a carrier rate.\n */\nexport async function planCheckoutShippingWithCarriers(input: {\n hostId: string\n settings: CommerceModel.ShippingSettings | undefined\n cart: CarrierShippingCart\n destination: CarrierShippingDestination\n currency?: string\n timeoutMs?: number\n}): Promise<CarrierShippingPlan> {\n const { settings, cart } = input\n const tablePlan = () =>\n CommerceModel.planCheckoutShipping(\n settings,\n { subtotalCents: cart.subtotalCents, totalGrams: cart.totalGrams },\n input.destination.country,\n )\n if (!CommerceModel.hasCarrierRates(settings)) return tablePlan()\n const quoter = pluginShippingRateQuoter()\n if (!quoter) return tablePlan()\n const available = await quoter.available(input.hostId).catch(() => false)\n if (!available) return tablePlan()\n\n const country = CommerceModel.normalizeCheckoutShippingCountry(input.destination.country)\n if (!country) {\n // Carrier prices differ by address by construction, so a session that\n // does not know the destination cannot be honest about any of them.\n return { countries: CommerceModel.CHECKOUT_SHIPPING_COUNTRIES, options: [], refusal: 'destination-required' }\n }\n const carrierRates = CommerceModel.carrierRatesFor(settings, country)\n if (!carrierRates.length) return tablePlan()\n const postalCode = normalizeCheckoutPostalCode(input.destination.postalCode)\n if (!postalCode) {\n return {\n countries: [country],\n options: [],\n refusal: 'destination-required',\n needsPostalCode: true,\n }\n }\n\n const currency = String(input.currency ?? 'usd').toLowerCase()\n const quotes = await quotePluginShippingRates(\n {\n hostId: input.hostId,\n to: {\n country,\n postalCode,\n ...(typeof input.destination.state === 'string' && input.destination.state.trim()\n ? { state: input.destination.state.trim().slice(0, 40) }\n : {}),\n ...(typeof input.destination.city === 'string' && input.destination.city.trim()\n ? { city: input.destination.city.trim().slice(0, 80) }\n : {}),\n },\n parcels: [{ weightGrams: Math.max(0, Math.round(cart.totalGrams)), ...(cart.parcel ?? {}) }],\n currency,\n valueCents: Math.max(0, Math.round(cart.subtotalCents)),\n },\n { timeoutMs: input.timeoutMs ?? CommerceModel.CARRIER_QUOTE_TIMEOUT_MS },\n )\n if (!quotes || !quotes.length) return tablePlan()\n\n const quoted: CommerceModel.ResolvedShippingRate[] = []\n const hidden = new Set<string>()\n for (const rate of carrierRates) {\n const services = (rate.carrier?.services ?? []).map((key) => key.toLowerCase())\n const offered = quotes.filter(\n (quote) => quote.currency === currency && (!services.length || services.includes(quote.serviceKey.toLowerCase())),\n )\n if (!offered.length) continue\n if (rate.carrier?.fallbackRateId) hidden.add(rate.carrier.fallbackRateId)\n for (const quote of offered) {\n quoted.push({\n rateId: CommerceModel.carrierOptionRateId(rate.id, quote.serviceKey),\n name: (quote.estimatedDays\n ? `${quote.label} (${quote.estimatedDays} business day${quote.estimatedDays === 1 ? '' : 's'})`\n : quote.label\n ).slice(0, 100),\n amountCents: CommerceModel.carrierOptionAmountCents(quote.amountCents, rate.carrier),\n })\n }\n }\n if (!quoted.length) return tablePlan()\n\n // The table's own options for this destination stay — a flat rate the\n // merchant offers beside carriers, local pickup — less any fallback a\n // carrier rate replaced now that it has quotes.\n const table = CommerceModel.resolveCheckoutShippingOptions(\n settings,\n [country],\n { subtotalCents: cart.subtotalCents, totalGrams: cart.totalGrams },\n ).filter((option) => !hidden.has(option.rateId))\n // One option per name: two carrier rates quoting the same service keep the\n // cheaper, so a shopper never sees the same service twice.\n const byName = new Map<string, CommerceModel.ResolvedShippingRate>()\n for (const option of [...table, ...quoted]) {\n const existing = byName.get(option.name)\n if (!existing || option.amountCents < existing.amountCents) byName.set(option.name, option)\n }\n const options = [...byName.values()]\n .sort((a, b) => a.amountCents - b.amountCents || a.rateId.localeCompare(b.rateId))\n .slice(0, CommerceModel.MAX_CHECKOUT_SHIPPING_OPTIONS)\n return { countries: [country], options, quotedPostalCode: postalCode }\n}\n"],"names":["pluginShippingRateQuoter","quotePluginShippingRates","CommerceModel","normalizeCheckoutPostalCode","value","undefined","code","trim","toUpperCase","slice","test","CARRIER_POSTAL_CODE_MESSAGE","planCheckoutShippingWithCarriers","input","cart","settings","tablePlan","planCheckoutShipping","subtotalCents","totalGrams","destination","country","hasCarrierRates","quoter","available","hostId","catch","normalizeCheckoutShippingCountry","countries","CHECKOUT_SHIPPING_COUNTRIES","options","refusal","carrierRates","carrierRatesFor","length","postalCode","needsPostalCode","currency","String","toLowerCase","quotes","to","state","city","parcels","weightGrams","Math","max","round","parcel","valueCents","timeoutMs","CARRIER_QUOTE_TIMEOUT_MS","quoted","hidden","Set","rate","services","carrier","map","key","offered","filter","quote","includes","serviceKey","fallbackRateId","add","push","rateId","carrierOptionRateId","id","name","estimatedDays","label","amountCents","carrierOptionAmountCents","table","resolveCheckoutShippingOptions","option","has","byName","Map","existing","get","set","values","sort","a","b","localeCompare","MAX_CHECKOUT_SHIPPING_OPTIONS","quotedPostalCode"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,wBAAwB,EACxBC,wBAAwB,QAEnB,oDAAmD;AAC1D,YAAYC,mBAAmB,oBAAU;AA6CzC,2EAA2E,GAC3E,OAAO,SAASC,4BAA4BC,KAAc;IACxD,IAAI,OAAOA,UAAU,UAAU,OAAOC;IACtC,MAAMC,OAAOF,MAAMG,IAAI,GAAGC,WAAW,GAAGC,KAAK,CAAC,GAAG;IACjD,OAAO,6BAA6BC,IAAI,CAACJ,QAAQA,OAAOD;AAC1D;AAYA,yDAAyD,GACzD,OAAO,MAAMM,8BAA8B,4CAA2C;AAEtF;;;;CAIC,GACD,OAAO,eAAeC,iCAAiCC,KAOtD;QAgCyBA,iBAcmDC,cAI5DD;IAjDf,MAAM,EAAEE,QAAQ,EAAED,IAAI,EAAE,GAAGD;IAC3B,MAAMG,YAA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
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/carrier-shipping.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 {\n pluginShippingRateQuoter,\n quotePluginShippingRates,\n type PluginShippingParcel,\n} from '@aglyn/aglyn/plugin-manager/plugin-shipping-rates'\nimport * as CommerceModel from '../model'\n\n/**\n * LIVE CARRIER RATES AT CHECKOUT (AGL-3612): the `carrier` rate kind, priced\n * by asking core's `core.shipping-rate-quoter` — whichever plugin quotes\n * carriers — and never by importing it.\n *\n * ## Quoted before the session exists, on every door\n *\n * Stripe's hosted Checkout cannot change a session's shipping options once\n * the shopper types an address (\"The hosted page integration doesn't support\n * dynamically customizing shipping options\"), and the in-page form can only\n * by a server update after the fact — while this module's callers fix the\n * platform fee and the Connect transfer from the session's options at\n * creation. So the quote is taken BEFORE the session, against the\n * destination the shopper declares (country and postal code), and the\n * session is then restricted to that country exactly as a zone rate is\n * (AGL-1721). The same code serves cart checkout, buy-now and a draft\n * order's link, hosted and in-page, and the fee arithmetic downstream sees\n * ordinary options.\n *\n * ## The fallback is the merchant's own\n *\n * No quoter, a quoter not available for this site, or a quote that fails or\n * takes longer than {@link CommerceModel.CARRIER_QUOTE_TIMEOUT_MS}: the plan\n * is exactly the one {@link CommerceModel.planCheckoutShipping} makes from\n * the table, where a carrier rate offers nothing and its fallback rate is\n * offered. A store with no carrier rate never reaches the quoter at all, so\n * its sessions are byte-identical to the ones before this existed.\n */\n\nexport interface CarrierShippingCart {\n subtotalCents: number\n totalGrams: number\n /** One parcel's dimensions, when the cart is one product that has them. */\n parcel?: Omit<PluginShippingParcel, 'weightGrams'>\n}\n\nexport interface CarrierShippingDestination {\n country?: unknown\n postalCode?: unknown\n state?: unknown\n city?: unknown\n}\n\n/** A postal code a shopper declared, trimmed and bounded, or `undefined`. */\nexport function normalizeCheckoutPostalCode(value: unknown): string | undefined {\n if (typeof value !== 'string') return undefined\n const code = value.trim().toUpperCase().slice(0, 12)\n return /^[A-Z0-9][A-Z0-9 -]{1,11}$/.test(code) ? code : undefined\n}\n\nexport type CarrierShippingPlan = CommerceModel.CheckoutShippingPlan & {\n /** Set when the plan offers live quotes: the postal code they were priced for. */\n quotedPostalCode?: string\n /**\n * The destination's zone prices by carrier and the store can quote, but the\n * shopper has not said where in the country: ask for a postal code.\n */\n needsPostalCode?: boolean\n}\n\n/** What a shopper is told when a postal code is needed. */\nexport const CARRIER_POSTAL_CODE_MESSAGE = 'Enter the postal code you’re shipping to.'\n\n/**\n * The shipping half of a session for a store that may price by carrier.\n * See the module comment; `planCheckoutShipping` is the whole answer for any\n * store without a carrier rate.\n */\nexport async function planCheckoutShippingWithCarriers(input: {\n hostId: string\n settings: CommerceModel.ShippingSettings | undefined\n cart: CarrierShippingCart\n destination: CarrierShippingDestination\n currency?: string\n timeoutMs?: number\n}): Promise<CarrierShippingPlan> {\n const { settings, cart } = input\n const tablePlan = () =>\n CommerceModel.planCheckoutShipping(\n settings,\n { subtotalCents: cart.subtotalCents, totalGrams: cart.totalGrams },\n input.destination.country,\n )\n if (!CommerceModel.hasCarrierRates(settings)) return tablePlan()\n const quoter = pluginShippingRateQuoter()\n if (!quoter) return tablePlan()\n const available = await quoter.available(input.hostId).catch(() => false)\n if (!available) return tablePlan()\n\n const countries = CommerceModel.checkoutShippingCountries(settings)\n const country = CommerceModel.normalizeCheckoutShippingCountry(input.destination.country, countries)\n if (!country) {\n // Carrier prices differ by address by construction, so a session that\n // does not know the destination cannot be honest about any of them.\n return { countries, options: [], refusal: 'destination-required' }\n }\n const carrierRates = CommerceModel.carrierRatesFor(settings, country)\n if (!carrierRates.length) return tablePlan()\n const postalCode = normalizeCheckoutPostalCode(input.destination.postalCode)\n if (!postalCode) {\n return {\n countries: [country],\n options: [],\n refusal: 'destination-required',\n needsPostalCode: true,\n }\n }\n\n const currency = String(input.currency ?? 'usd').toLowerCase()\n const quotes = await quotePluginShippingRates(\n {\n hostId: input.hostId,\n to: {\n country,\n postalCode,\n ...(typeof input.destination.state === 'string' && input.destination.state.trim()\n ? { state: input.destination.state.trim().slice(0, 40) }\n : {}),\n ...(typeof input.destination.city === 'string' && input.destination.city.trim()\n ? { city: input.destination.city.trim().slice(0, 80) }\n : {}),\n },\n parcels: [{ weightGrams: Math.max(0, Math.round(cart.totalGrams)), ...(cart.parcel ?? {}) }],\n currency,\n valueCents: Math.max(0, Math.round(cart.subtotalCents)),\n },\n { timeoutMs: input.timeoutMs ?? CommerceModel.CARRIER_QUOTE_TIMEOUT_MS },\n )\n if (!quotes || !quotes.length) return tablePlan()\n\n const quoted: CommerceModel.ResolvedShippingRate[] = []\n const hidden = new Set<string>()\n for (const rate of carrierRates) {\n const services = (rate.carrier?.services ?? []).map((key) => key.toLowerCase())\n const offered = quotes.filter(\n (quote) => quote.currency === currency && (!services.length || services.includes(quote.serviceKey.toLowerCase())),\n )\n if (!offered.length) continue\n if (rate.carrier?.fallbackRateId) hidden.add(rate.carrier.fallbackRateId)\n for (const quote of offered) {\n quoted.push({\n rateId: CommerceModel.carrierOptionRateId(rate.id, quote.serviceKey),\n name: (quote.estimatedDays\n ? `${quote.label} (${quote.estimatedDays} business day${quote.estimatedDays === 1 ? '' : 's'})`\n : quote.label\n ).slice(0, 100),\n amountCents: CommerceModel.carrierOptionAmountCents(quote.amountCents, rate.carrier),\n })\n }\n }\n if (!quoted.length) return tablePlan()\n\n // The table's own options for this destination stay — a flat rate the\n // merchant offers beside carriers, local pickup — less any fallback a\n // carrier rate replaced now that it has quotes.\n const table = CommerceModel.resolveCheckoutShippingOptions(\n settings,\n [country],\n { subtotalCents: cart.subtotalCents, totalGrams: cart.totalGrams },\n ).filter((option) => !hidden.has(option.rateId))\n // One option per name: two carrier rates quoting the same service keep the\n // cheaper, so a shopper never sees the same service twice.\n const byName = new Map<string, CommerceModel.ResolvedShippingRate>()\n for (const option of [...table, ...quoted]) {\n const existing = byName.get(option.name)\n if (!existing || option.amountCents < existing.amountCents) byName.set(option.name, option)\n }\n const options = [...byName.values()]\n .sort((a, b) => a.amountCents - b.amountCents || a.rateId.localeCompare(b.rateId))\n .slice(0, CommerceModel.MAX_CHECKOUT_SHIPPING_OPTIONS)\n return { countries: [country], options, quotedPostalCode: postalCode }\n}\n"],"names":["pluginShippingRateQuoter","quotePluginShippingRates","CommerceModel","normalizeCheckoutPostalCode","value","undefined","code","trim","toUpperCase","slice","test","CARRIER_POSTAL_CODE_MESSAGE","planCheckoutShippingWithCarriers","input","cart","settings","tablePlan","planCheckoutShipping","subtotalCents","totalGrams","destination","country","hasCarrierRates","quoter","available","hostId","catch","countries","checkoutShippingCountries","normalizeCheckoutShippingCountry","options","refusal","carrierRates","carrierRatesFor","length","postalCode","needsPostalCode","currency","String","toLowerCase","quotes","to","state","city","parcels","weightGrams","Math","max","round","parcel","valueCents","timeoutMs","CARRIER_QUOTE_TIMEOUT_MS","quoted","hidden","Set","rate","services","carrier","map","key","offered","filter","quote","includes","serviceKey","fallbackRateId","add","push","rateId","carrierOptionRateId","id","name","estimatedDays","label","amountCents","carrierOptionAmountCents","table","resolveCheckoutShippingOptions","option","has","byName","Map","existing","get","set","values","sort","a","b","localeCompare","MAX_CHECKOUT_SHIPPING_OPTIONS","quotedPostalCode"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,wBAAwB,EACxBC,wBAAwB,QAEnB,oDAAmD;AAC1D,YAAYC,mBAAmB,oBAAU;AA6CzC,2EAA2E,GAC3E,OAAO,SAASC,4BAA4BC,KAAc;IACxD,IAAI,OAAOA,UAAU,UAAU,OAAOC;IACtC,MAA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OAAOI,GAAG,CAACN,OAAOP,IAAI,EAAEO;IACtF;IACA,MAAMjD,UAAU;WAAImD,OAAOK,MAAM;KAAG,CACjCC,IAAI,CAAC,CAACC,GAAGC,IAAMD,EAAEb,WAAW,GAAGc,EAAEd,WAAW,IAAIa,EAAEnB,MAAM,CAACqB,aAAa,CAACD,EAAEpB,MAAM,GAC/E5D,KAAK,CAAC,GAAGP,cAAcyF,6BAA6B;IACvD,OAAO;QAAEhE,WAAW;YAACN;SAAQ;QAAES;QAAS8D,kBAAkBzD;IAAW;AACvE"}
|
|
@@ -43,6 +43,7 @@ import { appendLocalFulfillmentMetadata, localFulfillmentLocationId, localStockR
|
|
|
43
43
|
import { applyNativeCheckoutParams, nativeCheckoutStripeHeaders, readCheckoutSessionPayload, resolveNativeCheckoutMode } from "./native-checkout.js";
|
|
44
44
|
import { ensureCheckoutDomain } from "./payment-method-domains.js";
|
|
45
45
|
import { raiseCheckoutStarted } from "./order-events.js";
|
|
46
|
+
import { checkoutAmountMinor, checkoutLineMinor, loadFxRates, resolveCheckoutCurrency, storeCurrencyContextFrom, stripeCurrency } from "./currency.js";
|
|
46
47
|
import { checkoutExtrasCents, encodeCheckoutExtrasMetadata, readChosenCheckoutExtras } from "@aglyn/aglyn/plugin-manager/plugin-checkout-extras";
|
|
47
48
|
import { quoteCartExtras } from "./checkout-extras.js";
|
|
48
49
|
import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCreditMetadata, normalizeCheckoutCreditAccount, normalizeCheckoutCreditCode } from "@aglyn/aglyn/plugin-manager/plugin-checkout-credits";
|
|
@@ -173,6 +174,27 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
173
174
|
snapshot.id,
|
|
174
175
|
snapshot.exists ? CommerceModel.liftLegacyProduct(snapshot.data()) : null
|
|
175
176
|
]));
|
|
177
|
+
/**
|
|
178
|
+
* The currency the shopper is charged in (AGL-4248). Everything below is
|
|
179
|
+
* priced and checked in the store currency as before; only the amounts
|
|
180
|
+
* handed to Stripe are converted, at the emission. A direct sale only: a
|
|
181
|
+
* destination sale's split and platform tax are store-currency figures.
|
|
182
|
+
* A cart that sells a gift card stays in the store currency, because a
|
|
183
|
+
* card's balance is.
|
|
184
|
+
*/ let checkoutCurrency;
|
|
185
|
+
if (body.currency && direct) {
|
|
186
|
+
const currencyStore = await hostRef.collection('settings').doc('store').get();
|
|
187
|
+
const resolved = resolveCheckoutCurrency(storeCurrencyContextFrom(currencyStore.data(), await loadFxRates()), body.currency);
|
|
188
|
+
const sellsGiftCard = cart.lines.some((line)=>{
|
|
189
|
+
var _productsById_get;
|
|
190
|
+
return (_productsById_get = productsById.get(line.productId)) == null ? void 0 : _productsById_get.giftCard;
|
|
191
|
+
});
|
|
192
|
+
if (resolved.foreign && !sellsGiftCard) checkoutCurrency = resolved;
|
|
193
|
+
}
|
|
194
|
+
const chargeCurrency = checkoutCurrency ? stripeCurrency(checkoutCurrency) : 'usd';
|
|
195
|
+
/** The goods in the charge currency, as Stripe will total them. */ let itemsChargeMinor = 0;
|
|
196
|
+
/** Each line's store-currency unit, for the tax engine (it prices in the store currency). */ const baseUnitByIndex = new Map();
|
|
197
|
+
/** Each line's charge-currency unit, in cart order, for the order the webhook writes. */ const chargeUnits = [];
|
|
176
198
|
let itemsCents = 0;
|
|
177
199
|
/** Per-line values for scoped discount pricing. */ const discountLines = [];
|
|
178
200
|
// Gift-card value in the basket, for the cash-out ceiling (AGL-3363).
|
|
@@ -331,11 +353,28 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
331
353
|
if (feePct > 0) feeApplies = true;
|
|
332
354
|
feeCents += Math.round(unitCents * line.quantity * feePct / 100);
|
|
333
355
|
params.set(`line_items[${index}][quantity]`, String(line.quantity));
|
|
334
|
-
|
|
335
|
-
|
|
356
|
+
// The charge-currency unit: the variant's fixed price there or its
|
|
357
|
+
// store price converted, plus each add-on's (AGL-4248).
|
|
358
|
+
const chargeUnit = checkoutCurrency ? checkoutLineMinor(checkoutCurrency, product, variant, chosen.modifiers) : unitCents;
|
|
359
|
+
itemsChargeMinor += chargeUnit * line.quantity;
|
|
360
|
+
baseUnitByIndex.set(index, unitCents);
|
|
361
|
+
chargeUnits[index] = chargeUnit;
|
|
362
|
+
params.set(`line_items[${index}][price_data][currency]`, chargeCurrency);
|
|
363
|
+
params.set(`line_items[${index}][price_data][unit_amount]`, String(chargeUnit));
|
|
364
|
+
// Pinned whenever the charge is not in USD (AGL-1956 invariant 5):
|
|
365
|
+
// Stripe infers tax-inclusive pricing from some currencies otherwise.
|
|
366
|
+
if (checkoutCurrency) {
|
|
367
|
+
params.set(`line_items[${index}][price_data][tax_behavior]`, checkoutCurrency.entry.pricesIncludeTax ? 'inclusive' : 'exclusive');
|
|
368
|
+
}
|
|
336
369
|
// The variant, then the add-ons, as the order line will print them.
|
|
337
370
|
const lineLabel = CommerceModel.lineLabelWithModifiers(Object.keys((_variant_options = variant.options) != null ? _variant_options : {}).length ? Object.values((_variant_options1 = variant.options) != null ? _variant_options1 : {}).join(' / ') : undefined, chosen.modifiers);
|
|
338
|
-
|
|
371
|
+
const lineName = `${product.name}${lineLabel ? ` (${lineLabel})` : ''}`;
|
|
372
|
+
params.set(`line_items[${index}][price_data][product_data][name]`, lineName.slice(0, 120));
|
|
373
|
+
// A long set of choices (sizes, write-ins) is cut from the name at 120,
|
|
374
|
+
// so the payment page also shows all of them in the line's description.
|
|
375
|
+
if (lineName.length > 120 && lineLabel) {
|
|
376
|
+
params.set(`line_items[${index}][price_data][product_data][description]`, lineLabel.slice(0, 500));
|
|
377
|
+
}
|
|
339
378
|
});
|
|
340
379
|
// CARD READER HARDWARE ON THE PLATFORM'S OWN STORE (AGL-4038): taxed as
|
|
341
380
|
// goods, the terms of sale and business use ticked, the online order
|
|
@@ -476,7 +515,7 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
476
515
|
needsShippingCountry: true,
|
|
477
516
|
needsShippingPostalCode: true,
|
|
478
517
|
shippingCountries: [
|
|
479
|
-
...CommerceModel.
|
|
518
|
+
...CommerceModel.checkoutShippingCountries(storeSettings.get('shipping'))
|
|
480
519
|
]
|
|
481
520
|
});
|
|
482
521
|
}
|
|
@@ -490,7 +529,7 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
490
529
|
error: 'Choose where you’re shipping to.',
|
|
491
530
|
needsShippingCountry: true,
|
|
492
531
|
shippingCountries: [
|
|
493
|
-
...CommerceModel.
|
|
532
|
+
...CommerceModel.checkoutShippingCountries(storeSettings.get('shipping'))
|
|
494
533
|
]
|
|
495
534
|
});
|
|
496
535
|
}
|
|
@@ -501,7 +540,7 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
501
540
|
error: `This store does not ship to ${(_CommerceModel_CHECKOUT_SHIPPING_COUNTRY_NAMES_declared = CommerceModel.CHECKOUT_SHIPPING_COUNTRY_NAMES[declared]) != null ? _CommerceModel_CHECKOUT_SHIPPING_COUNTRY_NAMES_declared : 'that country'}.`,
|
|
502
541
|
needsShippingCountry: true,
|
|
503
542
|
shippingCountries: [
|
|
504
|
-
...CommerceModel.
|
|
543
|
+
...CommerceModel.checkoutShippingCountries(storeSettings.get('shipping'))
|
|
505
544
|
]
|
|
506
545
|
});
|
|
507
546
|
}
|
|
@@ -543,8 +582,8 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
543
582
|
chargedExtras.forEach((extra, offset)=>{
|
|
544
583
|
const index = cart.lines.length + offset;
|
|
545
584
|
params.set(`line_items[${index}][quantity]`, '1');
|
|
546
|
-
params.set(`line_items[${index}][price_data][currency]`,
|
|
547
|
-
params.set(`line_items[${index}][price_data][unit_amount]`, String(extra.amountCents));
|
|
585
|
+
params.set(`line_items[${index}][price_data][currency]`, chargeCurrency);
|
|
586
|
+
params.set(`line_items[${index}][price_data][unit_amount]`, String(checkoutCurrency ? checkoutAmountMinor(checkoutCurrency, extra.amountCents) : extra.amountCents));
|
|
548
587
|
params.set(`line_items[${index}][price_data][product_data][name]`, extra.label.slice(0, 120));
|
|
549
588
|
params.set(`line_items[${index}][price_data][product_data][tax_code]`, 'txcd_00000000');
|
|
550
589
|
});
|
|
@@ -987,10 +1026,12 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
987
1026
|
headers: _extends({
|
|
988
1027
|
Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}`,
|
|
989
1028
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
990
|
-
}, stripeKeyHeader(creditHeldCents > 0 ? `coupon-c${creditHeldCents}` : 'coupon'), sellerAccountHeader),
|
|
1029
|
+
}, stripeKeyHeader(`${creditHeldCents > 0 ? `coupon-c${creditHeldCents}` : 'coupon'}${checkoutCurrency ? `-${chargeCurrency}` : ''}`), sellerAccountHeader),
|
|
991
1030
|
body: new URLSearchParams({
|
|
992
|
-
|
|
993
|
-
currency
|
|
1031
|
+
// In the charge currency, as the same share of the goods it is of
|
|
1032
|
+
// the store-currency goods, so a 10% discount stays 10% (AGL-4248).
|
|
1033
|
+
amount_off: String(checkoutCurrency ? Math.min(itemsChargeMinor, Math.round(Math.min(totalOffCents, itemsCents) * itemsChargeMinor / Math.max(1, itemsCents))) : Math.min(totalOffCents, itemsCents)),
|
|
1034
|
+
currency: chargeCurrency,
|
|
994
1035
|
duration: 'once'
|
|
995
1036
|
}).toString()
|
|
996
1037
|
}).then((response)=>response.json());
|
|
@@ -1045,8 +1086,8 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
1045
1086
|
// this session exists. When the service does not answer, the store's
|
|
1046
1087
|
// rate stands and the order says so.
|
|
1047
1088
|
const cartEngineLines = cart.lines.map((line, index)=>{
|
|
1048
|
-
var _params_get;
|
|
1049
|
-
const unitCents = Number((_params_get = params.get(`line_items[${index}][price_data][unit_amount]`)) != null ? _params_get : NaN);
|
|
1089
|
+
var _baseUnitByIndex_get, _params_get;
|
|
1090
|
+
const unitCents = (_baseUnitByIndex_get = baseUnitByIndex.get(index)) != null ? _baseUnitByIndex_get : Number((_params_get = params.get(`line_items[${index}][price_data][unit_amount]`)) != null ? _params_get : NaN);
|
|
1050
1091
|
return {
|
|
1051
1092
|
index,
|
|
1052
1093
|
line,
|
|
@@ -1117,7 +1158,13 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
1117
1158
|
// destinations the declared rates were resolved for. The emission is
|
|
1118
1159
|
// shared with buy-now (AGL-1720).
|
|
1119
1160
|
CommerceModel.appendShippingAddressCollectionParams(params, shippingPlan.countries);
|
|
1120
|
-
CommerceModel.appendCheckoutShippingParams(params, shippingOptions)
|
|
1161
|
+
CommerceModel.appendCheckoutShippingParams(params, checkoutCurrency ? CommerceModel.shippingOptionsInCurrency(shippingOptions, storeSettings.get('shipping'), {
|
|
1162
|
+
code: checkoutCurrency.code,
|
|
1163
|
+
subtotalMinor: itemsChargeMinor,
|
|
1164
|
+
convert: (cents, fixed)=>checkoutAmountMinor(checkoutCurrency, cents, fixed)
|
|
1165
|
+
}) : shippingOptions, chargeCurrency, (checkoutCurrency == null ? void 0 : checkoutCurrency.entry.pricesIncludeTax) ? {
|
|
1166
|
+
taxBehavior: 'inclusive'
|
|
1167
|
+
} : {});
|
|
1121
1168
|
// Taxes (AGL-1953). This block used to be the `stripe` line alone, and a
|
|
1122
1169
|
// `manual`-mode store — the mode the AGL-285 zone editor leaves a merchant
|
|
1123
1170
|
// in by default — collected tax on a buy-now sale and NOTHING on a cart
|
|
@@ -1319,7 +1366,9 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
1319
1366
|
// to hold back. The split is the take as `application_fee_amount`.
|
|
1320
1367
|
const cartTaxOwner = !direct && taxDecision.kind === 'stripe-automatic' ? 'platform' : 'merchant';
|
|
1321
1368
|
const cartShippingFloorCents = CommerceModel.shippingFloorCents(shippingOptions);
|
|
1322
|
-
Object.entries(direct ? directChargeParams(
|
|
1369
|
+
Object.entries(direct ? directChargeParams(// The take in the charge currency (AGL-4248): Stripe reads
|
|
1370
|
+
// `application_fee_amount` in the session's currency.
|
|
1371
|
+
checkoutCurrency ? checkoutAmountMinor(checkoutCurrency, feeCents) : feeCents) : CommerceModel.destinationChargeParams({
|
|
1323
1372
|
accountId: String(accountId),
|
|
1324
1373
|
feeCents,
|
|
1325
1374
|
taxOwner: cartTaxOwner,
|
|
@@ -1345,6 +1394,19 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
1345
1394
|
params.set('metadata[hostId]', hostId);
|
|
1346
1395
|
params.set('metadata[cartId]', cartId);
|
|
1347
1396
|
params.set('metadata[feeCents]', String(Math.max(0, feeCents)));
|
|
1397
|
+
// What the order records about the currency (AGL-4248). `feeCents` above
|
|
1398
|
+
// stays the store-currency take; the order's figures are in the charge
|
|
1399
|
+
// currency, with the store-currency equivalents beside them.
|
|
1400
|
+
if (checkoutCurrency) {
|
|
1401
|
+
for (const [key, value] of Object.entries(CommerceModel.encodeChargeUnitsMetadata(chargeUnits))){
|
|
1402
|
+
params.set(`metadata[${key}]`, value);
|
|
1403
|
+
}
|
|
1404
|
+
params.set('metadata[chargeFeeCents]', String(checkoutAmountMinor(checkoutCurrency, Math.max(0, feeCents))));
|
|
1405
|
+
params.set('metadata[chargeExtrasCents]', String(chargedExtras.reduce((sum, extra)=>sum + checkoutAmountMinor(checkoutCurrency, extra.amountCents), 0)));
|
|
1406
|
+
params.set('metadata[currency]', chargeCurrency);
|
|
1407
|
+
params.set('metadata[baseCurrency]', checkoutCurrency.base.toLowerCase());
|
|
1408
|
+
params.set('metadata[fxRate]', String(checkoutCurrency.rate));
|
|
1409
|
+
}
|
|
1348
1410
|
// Only on the shape where `transfer.amount` is no longer `charge.amount`,
|
|
1349
1411
|
// so the merchant's actual payout stops being derivable from the charge
|
|
1350
1412
|
// (AGL-1956). The shipping baseline is the other half: the difference
|