@aglyn/plugins-commerce 1.22.4 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -13
- package/src/lib/contracts.d.ts +16 -0
- package/src/lib/contracts.js.map +1 -1
- package/src/lib/model/commerce-orders.d.ts +11 -0
- package/src/lib/model/commerce-orders.js.map +1 -1
- package/src/lib/server/api-v1/order-view.d.ts +20 -0
- package/src/lib/server/api-v1/order-view.js +38 -2
- package/src/lib/server/api-v1/order-view.js.map +1 -1
- package/src/lib/server/billing-webhook.js +7 -3
- package/src/lib/server/billing-webhook.js.map +1 -1
|
@@ -18,12 +18,13 @@ import { fulfillmentLineQuantities } from "../../model/order-fulfillment.js";
|
|
|
18
18
|
import { fulfillmentTrackingUrl } from "../../model/tracking-url.js";
|
|
19
19
|
import { orderTaxEngineView } from "../../model/commerce-tax-engine.js";
|
|
20
20
|
import { orderIsTestMode } from "../../model/commerce-orders.js";
|
|
21
|
+
import { orderPayments } from "../../model/commerce-pos.js";
|
|
21
22
|
/**
|
|
22
23
|
* The public order shape from an order's data (AGL-3611): the same object the
|
|
23
24
|
* API returns, so an order event and an outbound webhook carry exactly what
|
|
24
25
|
* `GET /v1/sites/{id}/orders/{id}` would.
|
|
25
26
|
*/ export function orderViewFromData(id, data) {
|
|
26
|
-
var _data_totals, _data_amountCents, _data_feeCents, _data_status, _data_channel, _data_customerEmail, _data_customerName, _data_lineItems, _totals_itemsCents, _totals_shippingCents, _totals_taxCents, _totals_discountCents, _totals_extrasCents, _data_refundedCents, _serialize, _data_couponCode, _serialize1;
|
|
27
|
+
var _data_totals, _data_amountCents, _data_feeCents, _data_status, _data_channel, _data_customerEmail, _data_customerName, _data_lineItems, _totals_itemsCents, _totals_shippingCents, _totals_taxCents, _totals_discountCents, _totals_extrasCents, _totals_tipCents, _data_giftCardRedeemedCents, _data_refundedCents, _serialize, _data_couponCode, _serialize1;
|
|
27
28
|
const totals = (_data_totals = data.totals) != null ? _data_totals : {};
|
|
28
29
|
const legacyTotal = Number((_data_amountCents = data.amountCents) != null ? _data_amountCents : NaN);
|
|
29
30
|
const totalCents = Number.isFinite(Number(totals.totalCents)) ? Number(totals.totalCents) : Number.isFinite(legacyTotal) ? legacyTotal : null;
|
|
@@ -50,8 +51,17 @@ import { orderIsTestMode } from "../../model/commerce-orders.js";
|
|
|
50
51
|
feeCents: Number.isFinite(Number(totals.feeCents)) ? Number(totals.feeCents) : Number.isFinite(legacyFee) ? legacyFee : 0,
|
|
51
52
|
// Optional lines the buyer added at checkout (AGL-3635), inside
|
|
52
53
|
// `totalCents` and outside `itemsCents`.
|
|
53
|
-
extrasCents: Number((_totals_extrasCents = totals.extrasCents) != null ? _totals_extrasCents : 0) || 0
|
|
54
|
+
extrasCents: Number((_totals_extrasCents = totals.extrasCents) != null ? _totals_extrasCents : 0) || 0,
|
|
55
|
+
// A register tip (AGL-3607), on top of `totalCents` and not revenue.
|
|
56
|
+
tipCents: Math.max(0, Math.round(Number((_totals_tipCents = totals.tipCents) != null ? _totals_tipCents : 0)) || 0)
|
|
54
57
|
},
|
|
58
|
+
// How a register sale was paid (AGL-3614): one entry per tender that
|
|
59
|
+
// succeeded. A ledger needs it because only the card tenders went through
|
|
60
|
+
// Stripe; cash went in the drawer, a gift card spent value the store
|
|
61
|
+
// already held. Empty for every sale that is not the register's.
|
|
62
|
+
payments: orderPaymentsView(data),
|
|
63
|
+
// The part of `discountCents` a gift card paid online (AGL-3614).
|
|
64
|
+
giftCardRedeemedCents: Math.max(0, Math.round(Number((_data_giftCardRedeemedCents = data.giftCardRedeemedCents) != null ? _data_giftCardRedeemedCents : 0)) || 0),
|
|
55
65
|
// What those lines were and whose offer each was: the fact a plugin that
|
|
56
66
|
// insures a parcel reads off `order.paid` to know it was bought.
|
|
57
67
|
extras: (Array.isArray(data.extras) ? data.extras : []).filter((entry)=>entry && typeof entry.id === 'string').map((entry)=>{
|
|
@@ -161,5 +171,31 @@ import { orderIsTestMode } from "../../model/commerce-orders.js";
|
|
|
161
171
|
...register
|
|
162
172
|
].filter((credit)=>credit.reference && credit.amountCents > 0);
|
|
163
173
|
}
|
|
174
|
+
const CARD_METHODS = new Set([
|
|
175
|
+
'card_present',
|
|
176
|
+
'card_keyed',
|
|
177
|
+
'card_link'
|
|
178
|
+
]);
|
|
179
|
+
/**
|
|
180
|
+
* A register sale's settled tenders as the order event names them (AGL-3614).
|
|
181
|
+
* An order from before the split-tender ledger is one payment, inferred the
|
|
182
|
+
* way the register's own reader infers it, with the order's tip and fee.
|
|
183
|
+
*/ export function orderPaymentsView(data) {
|
|
184
|
+
if ((data == null ? void 0 : data.channel) !== 'pos') return [];
|
|
185
|
+
const whole = (value)=>Math.max(0, Math.round(Number(value != null ? value : 0)) || 0);
|
|
186
|
+
return orderPayments(data).filter((payment)=>payment.status === 'succeeded').map((payment)=>{
|
|
187
|
+
var _ref;
|
|
188
|
+
var _data_totals, _data_totals1;
|
|
189
|
+
const legacy = payment.id === 'legacy';
|
|
190
|
+
return {
|
|
191
|
+
method: payment.method,
|
|
192
|
+
amountCents: whole(payment.amountCents),
|
|
193
|
+
tipCents: whole(legacy ? (_data_totals = data.totals) == null ? void 0 : _data_totals.tipCents : payment.tipCents),
|
|
194
|
+
// The application fee Stripe took from this payment; a tender Stripe
|
|
195
|
+
// never saw carried none.
|
|
196
|
+
feeCents: legacy ? CARD_METHODS.has(payment.method) ? whole((_ref = (_data_totals1 = data.totals) == null ? void 0 : _data_totals1.feeCents) != null ? _ref : data.feeCents) : 0 : whole(payment.feeCents)
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
}
|
|
164
200
|
|
|
165
201
|
//# sourceMappingURL=order-view.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/server/api-v1/order-view.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 { serialize } from '@aglyn/tenant-data-admin/server/api-v1-kit'\nimport { fulfillmentLineQuantities } from '../../model/order-fulfillment'\nimport { fulfillmentTrackingUrl } from '../../model/tracking-url'\nimport { orderTaxEngineView } from '../../model/commerce-tax-engine'\nimport { orderIsTestMode } from '../../model/commerce-orders'\n\n/**\n * The public order shape from an order's data (AGL-3611): the same object the\n * API returns, so an order event and an outbound webhook carry exactly what\n * `GET /v1/sites/{id}/orders/{id}` would.\n */\nexport function orderViewFromData(id: string, data: Record<string, any>) {\n const totals = (data.totals ?? {}) as Record<string, unknown>\n const legacyTotal = Number(data.amountCents ?? NaN)\n const totalCents = Number.isFinite(Number(totals.totalCents))\n ? Number(totals.totalCents)\n : Number.isFinite(legacyTotal)\n ? legacyTotal\n : null\n const legacyFee = Number(data.feeCents ?? NaN)\n return {\n id,\n object: 'order',\n number: typeof data.number === 'number' ? data.number : null,\n status: (data.status as string) ?? null,\n channel: (data.channel as string) ?? 'online',\n currency: 'usd',\n customerEmail: data.customerEmail ?? null,\n customerName: data.customerName ?? null,\n lineItems: serialize(data.lineItems ?? []),\n totals: {\n itemsCents: Number(totals.itemsCents ?? 0),\n shippingCents: Number(totals.shippingCents ?? 0),\n taxCents: Number(totals.taxCents ?? 0),\n discountCents: Number(totals.discountCents ?? 0),\n totalCents,\n // The Connect application fee. NOT subtracted from `totalCents` — it is\n // Aglyn's cut of a total the shopper already paid in full, so a client\n // that nets it out of revenue would understate what it collected.\n feeCents: Number.isFinite(Number(totals.feeCents))\n ? Number(totals.feeCents)\n : Number.isFinite(legacyFee)\n ? legacyFee\n : 0,\n // Optional lines the buyer added at checkout (AGL-3635), inside\n // `totalCents` and outside `itemsCents`.\n extrasCents: Number(totals.extrasCents ?? 0) || 0,\n },\n // What those lines were and whose offer each was: the fact a plugin that\n // insures a parcel reads off `order.paid` to know it was bought.\n extras: (Array.isArray(data.extras) ? data.extras : [])\n .filter((entry: Record<string, unknown>) => entry && typeof entry.id === 'string')\n .map((entry: Record<string, unknown>) => ({\n id: String(entry.id),\n pluginId: String(entry.pluginId ?? ''),\n key: String(entry.key ?? ''),\n label: String(entry.label ?? ''),\n amountCents: Number(entry.amountCents ?? 0) || 0,\n quoteRef: typeof entry.quoteRef === 'string' ? entry.quoteRef : null,\n })),\n // Store credit another plugin kept that paid part of the sale (AGL-3640):\n // a rewards redemption online comes off the goods (`discount`), one at\n // the register is one of its payments (`tender`). The provider reads its\n // own `reference` back off `order.paid` and `order.refunded`.\n credits: orderCreditsView(data),\n // Money already handed back, for any reason. A chargeback lands here too,\n // so `refundedCents > 0` does not by itself mean the merchant chose it.\n refundedCents: Number(data.refundedCents ?? 0),\n // Whether real money moved (AGL-3699): `false` for a Stripe test-mode\n // order, so a subscriber that tells an outside service about a sale —\n // a review invitation, a ledger — can leave a store's rehearsal out.\n // The seller's own rule: the recorded fact, else the session id.\n livemode: !orderIsTestMode({\n livemode: data.livemode,\n checkoutSessionId: data.checkoutSessionId,\n $id: id,\n }),\n // Who the tax was charged under (AGL-3614): `stripe-automatic` tax is\n // Aglyn's to remit as marketplace facilitator and never reaches the\n // merchant's account, which a ledger posting the sale has to know. An\n // order from before the regime was recorded says `null`, never a guess.\n taxMode: typeof data.taxMode === 'string' && data.taxMode ? data.taxMode : null,\n // The merchant's own tax service (AGL-3631): which one priced the sale, or\n // that it was asked and the store's own rates were charged instead\n // (`status: 'fallback'`). `null` when no service was asked. The regime is\n // still `taxMode` — a service the merchant connected answers for tax the\n // merchant remits.\n taxEngine: orderTaxEngineView(data.taxEngine),\n disputed: Boolean(data.dispute),\n shippingAddress: serialize(data.shippingAddress) ?? null,\n couponCode: data.couponCode ?? null,\n // Shipment records — the half of fulfilment an integration can use\n // without a write (AGL-2460). `status` says an order is `fulfilled`; it\n // does not say which carrier took it or under what tracking number, so a\n // 3PL or accounting reconcile could see THAT an order shipped and never\n // WHICH shipment it was. The console's order dialog shows both, and an\n // order that has been shipped twice (a split shipment) is indistinguish-\n // able from one shipped once when only the status is published.\n //\n // `atMs` is a number of milliseconds, not a Firestore Timestamp, so\n // `serialize` passes it through untouched. It is republished as `at` in\n // ISO 8601 to match `created` and every other time this API emits: one\n // object publishing two time formats is a bug an integrator finds late,\n // in their own timezone conversion, and blames on their own code.\n fulfillments: (Array.isArray(data.fulfillments) ? data.fulfillments : []).map(\n (entry: Record<string, unknown>) => {\n const atMs = Number((entry ?? {}).atMs)\n return {\n id: (entry ?? {}).id ?? null,\n lineItemIds: Array.isArray((entry ?? {}).lineItemIds)\n ? (entry as { lineItemIds: unknown[] }).lineItemIds\n : [],\n // Units per line (AGL-3611); a fulfillment recorded before\n // quantities shipped every unit of the lines it names.\n lines: fulfillmentLineQuantities(\n { lineItems: Array.isArray(data.lineItems) ? data.lineItems : [] },\n (entry ?? {}) as never,\n ),\n status: (entry ?? {}).status === 'cancelled' ? 'cancelled' : 'active',\n carrier: (entry ?? {}).carrier ?? null,\n trackingNumber: (entry ?? {}).trackingNumber ?? null,\n trackingUrl: fulfillmentTrackingUrl((entry ?? {}) as never),\n labelUrl: (entry ?? {}).labelUrl ?? null,\n at: Number.isFinite(atMs) ? new Date(atMs).toISOString() : null,\n }\n },\n ),\n created: serialize(data.createdAt) ?? null,\n }\n}\n\n/** The plugin credits an order carries, online and at the register (AGL-3640). */\nexport function orderCreditsView(data: Record<string, any>): Array<{\n providerId: string\n pluginId: string\n reference: string\n label: string\n last4: string\n amountCents: number\n appliedAs: 'discount' | 'tender'\n}> {\n const online = (Array.isArray(data.credits) ? data.credits : [])\n .filter((entry: Record<string, unknown>) => entry && typeof entry.providerId === 'string')\n .map((entry: Record<string, unknown>) => ({\n providerId: String(entry.providerId),\n pluginId: String(entry.pluginId ?? String(entry.providerId).split('.')[0]),\n reference: String(entry.reference ?? ''),\n label: String(entry.label ?? ''),\n last4: String(entry.last4 ?? ''),\n amountCents: Math.max(0, Math.trunc(Number(entry.amountCents) || 0)),\n appliedAs: entry.appliedAs === 'tender' ? ('tender' as const) : ('discount' as const),\n }))\n const register = (Array.isArray(data.payments) ? data.payments : [])\n .filter(\n (payment: Record<string, unknown>) =>\n payment &&\n payment.method === 'credit' &&\n payment.status === 'succeeded' &&\n typeof payment.creditProviderId === 'string',\n )\n .map((payment: Record<string, unknown>) => ({\n providerId: String(payment.creditProviderId),\n pluginId: String(payment.creditProviderId).split('.')[0],\n reference: String(payment.creditReference ?? ''),\n label: String(payment.creditLabel ?? ''),\n last4: String(payment.last4 ?? ''),\n amountCents: Math.max(0, Math.trunc(Number(payment.amountCents) || 0)),\n appliedAs: 'tender' as const,\n }))\n return [...online, ...register].filter((credit) => credit.reference && credit.amountCents > 0)\n}\n"],"names":["serialize","fulfillmentLineQuantities","fulfillmentTrackingUrl","orderTaxEngineView","orderIsTestMode","orderViewFromData","id","data","totals","legacyTotal","Number","amountCents","NaN","totalCents","isFinite","legacyFee","feeCents","object","number","status","channel","currency","customerEmail","customerName","lineItems","itemsCents","shippingCents","taxCents","discountCents","extrasCents","extras","Array","isArray","filter","entry","map","String","pluginId","key","label","quoteRef","credits","orderCreditsView","refundedCents","livemode","checkoutSessionId","$id","taxMode","taxEngine","disputed","Boolean","dispute","shippingAddress","couponCode","fulfillments","atMs","lineItemIds","lines","carrier","trackingNumber","trackingUrl","labelUrl","at","Date","toISOString","created","createdAt","online","providerId","split","reference","last4","Math","max","trunc","appliedAs","register","payments","payment","method","creditProviderId","creditReference","creditLabel","credit"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,SAAS,QAAQ,6CAA4C;AACtE,SAASC,yBAAyB,QAAQ,mCAA+B;AACzE,SAASC,sBAAsB,QAAQ,8BAA0B;AACjE,SAASC,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MAAMqC,KAAK,YAAXrC,eAAe;YAC7BvB,aAAa6D,KAAKC,GAAG,CAAC,GAAGD,KAAKE,KAAK,CAAChE,OAAOwB,MAAMvB,WAAW,KAAK;YACjEgE,WAAWzC,MAAMyC,SAAS,KAAK,WAAY,WAAsB;QACnE;;IACF,MAAMC,WAAW,AAAC7C,CAAAA,MAAMC,OAAO,CAACzB,KAAKsE,QAAQ,IAAItE,KAAKsE,QAAQ,GAAG,EAAE,AAAD,EAC/D5C,MAAM,CACL,CAAC6C,UACCA,WACAA,QAAQC,MAAM,KAAK,YACnBD,QAAQ3D,MAAM,KAAK,eACnB,OAAO2D,QAAQE,gBAAgB,KAAK,UAEvC7C,GAAG,CAAC,CAAC2C;YAGcA,0BACJA,sBACAA;eAL4B;YAC1CV,YAAYhC,OAAO0C,QAAQE,gBAAgB;YAC3C3C,UAAUD,OAAO0C,QAAQE,gBAAgB,EAAEX,KAAK,CAAC,IAAI,CAAC,EAAE;YACxDC,WAAWlC,QAAO0C,2BAAAA,QAAQG,eAAe,YAAvBH,2BAA2B;YAC7CvC,OAAOH,QAAO0C,uBAAAA,QAAQI,WAAW,YAAnBJ,uBAAuB;YACrCP,OAAOnC,QAAO0C,iBAAAA,QAAQP,KAAK,YAAbO,iBAAiB;YAC/BnE,aAAa6D,KAAKC,GAAG,CAAC,GAAGD,KAAKE,KAAK,CAAChE,OAAOoE,QAAQnE,WAAW,KAAK;YACnEgE,WAAW;QACb;;IACF,OAAO;WAAIR;WAAWS;KAAS,CAAC3C,MAAM,CAAC,CAACkD,SAAWA,OAAOb,SAAS,IAAIa,OAAOxE,WAAW,GAAG;AAC9F"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/server/api-v1/order-view.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 { serialize } from '@aglyn/tenant-data-admin/server/api-v1-kit'\nimport { fulfillmentLineQuantities } from '../../model/order-fulfillment'\nimport { fulfillmentTrackingUrl } from '../../model/tracking-url'\nimport { orderTaxEngineView } from '../../model/commerce-tax-engine'\nimport { orderIsTestMode } from '../../model/commerce-orders'\nimport { orderPayments, type OrderPaymentMethod } from '../../model/commerce-pos'\n\n/**\n * The public order shape from an order's data (AGL-3611): the same object the\n * API returns, so an order event and an outbound webhook carry exactly what\n * `GET /v1/sites/{id}/orders/{id}` would.\n */\nexport function orderViewFromData(id: string, data: Record<string, any>) {\n const totals = (data.totals ?? {}) as Record<string, unknown>\n const legacyTotal = Number(data.amountCents ?? NaN)\n const totalCents = Number.isFinite(Number(totals.totalCents))\n ? Number(totals.totalCents)\n : Number.isFinite(legacyTotal)\n ? legacyTotal\n : null\n const legacyFee = Number(data.feeCents ?? NaN)\n return {\n id,\n object: 'order',\n number: typeof data.number === 'number' ? data.number : null,\n status: (data.status as string) ?? null,\n channel: (data.channel as string) ?? 'online',\n currency: 'usd',\n customerEmail: data.customerEmail ?? null,\n customerName: data.customerName ?? null,\n lineItems: serialize(data.lineItems ?? []),\n totals: {\n itemsCents: Number(totals.itemsCents ?? 0),\n shippingCents: Number(totals.shippingCents ?? 0),\n taxCents: Number(totals.taxCents ?? 0),\n discountCents: Number(totals.discountCents ?? 0),\n totalCents,\n // The Connect application fee. NOT subtracted from `totalCents` — it is\n // Aglyn's cut of a total the shopper already paid in full, so a client\n // that nets it out of revenue would understate what it collected.\n feeCents: Number.isFinite(Number(totals.feeCents))\n ? Number(totals.feeCents)\n : Number.isFinite(legacyFee)\n ? legacyFee\n : 0,\n // Optional lines the buyer added at checkout (AGL-3635), inside\n // `totalCents` and outside `itemsCents`.\n extrasCents: Number(totals.extrasCents ?? 0) || 0,\n // A register tip (AGL-3607), on top of `totalCents` and not revenue.\n tipCents: Math.max(0, Math.round(Number(totals.tipCents ?? 0)) || 0),\n },\n // How a register sale was paid (AGL-3614): one entry per tender that\n // succeeded. A ledger needs it because only the card tenders went through\n // Stripe; cash went in the drawer, a gift card spent value the store\n // already held. Empty for every sale that is not the register's.\n payments: orderPaymentsView(data),\n // The part of `discountCents` a gift card paid online (AGL-3614).\n giftCardRedeemedCents: Math.max(0, Math.round(Number(data.giftCardRedeemedCents ?? 0)) || 0),\n // What those lines were and whose offer each was: the fact a plugin that\n // insures a parcel reads off `order.paid` to know it was bought.\n extras: (Array.isArray(data.extras) ? data.extras : [])\n .filter((entry: Record<string, unknown>) => entry && typeof entry.id === 'string')\n .map((entry: Record<string, unknown>) => ({\n id: String(entry.id),\n pluginId: String(entry.pluginId ?? ''),\n key: String(entry.key ?? ''),\n label: String(entry.label ?? ''),\n amountCents: Number(entry.amountCents ?? 0) || 0,\n quoteRef: typeof entry.quoteRef === 'string' ? entry.quoteRef : null,\n })),\n // Store credit another plugin kept that paid part of the sale (AGL-3640):\n // a rewards redemption online comes off the goods (`discount`), one at\n // the register is one of its payments (`tender`). The provider reads its\n // own `reference` back off `order.paid` and `order.refunded`.\n credits: orderCreditsView(data),\n // Money already handed back, for any reason. A chargeback lands here too,\n // so `refundedCents > 0` does not by itself mean the merchant chose it.\n refundedCents: Number(data.refundedCents ?? 0),\n // Whether real money moved (AGL-3699): `false` for a Stripe test-mode\n // order, so a subscriber that tells an outside service about a sale —\n // a review invitation, a ledger — can leave a store's rehearsal out.\n // The seller's own rule: the recorded fact, else the session id.\n livemode: !orderIsTestMode({\n livemode: data.livemode,\n checkoutSessionId: data.checkoutSessionId,\n $id: id,\n }),\n // Who the tax was charged under (AGL-3614): `stripe-automatic` tax is\n // Aglyn's to remit as marketplace facilitator and never reaches the\n // merchant's account, which a ledger posting the sale has to know. An\n // order from before the regime was recorded says `null`, never a guess.\n taxMode: typeof data.taxMode === 'string' && data.taxMode ? data.taxMode : null,\n // The merchant's own tax service (AGL-3631): which one priced the sale, or\n // that it was asked and the store's own rates were charged instead\n // (`status: 'fallback'`). `null` when no service was asked. The regime is\n // still `taxMode` — a service the merchant connected answers for tax the\n // merchant remits.\n taxEngine: orderTaxEngineView(data.taxEngine),\n disputed: Boolean(data.dispute),\n shippingAddress: serialize(data.shippingAddress) ?? null,\n couponCode: data.couponCode ?? null,\n // Shipment records — the half of fulfilment an integration can use\n // without a write (AGL-2460). `status` says an order is `fulfilled`; it\n // does not say which carrier took it or under what tracking number, so a\n // 3PL or accounting reconcile could see THAT an order shipped and never\n // WHICH shipment it was. The console's order dialog shows both, and an\n // order that has been shipped twice (a split shipment) is indistinguish-\n // able from one shipped once when only the status is published.\n //\n // `atMs` is a number of milliseconds, not a Firestore Timestamp, so\n // `serialize` passes it through untouched. It is republished as `at` in\n // ISO 8601 to match `created` and every other time this API emits: one\n // object publishing two time formats is a bug an integrator finds late,\n // in their own timezone conversion, and blames on their own code.\n fulfillments: (Array.isArray(data.fulfillments) ? data.fulfillments : []).map(\n (entry: Record<string, unknown>) => {\n const atMs = Number((entry ?? {}).atMs)\n return {\n id: (entry ?? {}).id ?? null,\n lineItemIds: Array.isArray((entry ?? {}).lineItemIds)\n ? (entry as { lineItemIds: unknown[] }).lineItemIds\n : [],\n // Units per line (AGL-3611); a fulfillment recorded before\n // quantities shipped every unit of the lines it names.\n lines: fulfillmentLineQuantities(\n { lineItems: Array.isArray(data.lineItems) ? data.lineItems : [] },\n (entry ?? {}) as never,\n ),\n status: (entry ?? {}).status === 'cancelled' ? 'cancelled' : 'active',\n carrier: (entry ?? {}).carrier ?? null,\n trackingNumber: (entry ?? {}).trackingNumber ?? null,\n trackingUrl: fulfillmentTrackingUrl((entry ?? {}) as never),\n labelUrl: (entry ?? {}).labelUrl ?? null,\n at: Number.isFinite(atMs) ? new Date(atMs).toISOString() : null,\n }\n },\n ),\n created: serialize(data.createdAt) ?? null,\n }\n}\n\n/** The plugin credits an order carries, online and at the register (AGL-3640). */\nexport function orderCreditsView(data: Record<string, any>): Array<{\n providerId: string\n pluginId: string\n reference: string\n label: string\n last4: string\n amountCents: number\n appliedAs: 'discount' | 'tender'\n}> {\n const online = (Array.isArray(data.credits) ? data.credits : [])\n .filter((entry: Record<string, unknown>) => entry && typeof entry.providerId === 'string')\n .map((entry: Record<string, unknown>) => ({\n providerId: String(entry.providerId),\n pluginId: String(entry.pluginId ?? String(entry.providerId).split('.')[0]),\n reference: String(entry.reference ?? ''),\n label: String(entry.label ?? ''),\n last4: String(entry.last4 ?? ''),\n amountCents: Math.max(0, Math.trunc(Number(entry.amountCents) || 0)),\n appliedAs: entry.appliedAs === 'tender' ? ('tender' as const) : ('discount' as const),\n }))\n const register = (Array.isArray(data.payments) ? data.payments : [])\n .filter(\n (payment: Record<string, unknown>) =>\n payment &&\n payment.method === 'credit' &&\n payment.status === 'succeeded' &&\n typeof payment.creditProviderId === 'string',\n )\n .map((payment: Record<string, unknown>) => ({\n providerId: String(payment.creditProviderId),\n pluginId: String(payment.creditProviderId).split('.')[0],\n reference: String(payment.creditReference ?? ''),\n label: String(payment.creditLabel ?? ''),\n last4: String(payment.last4 ?? ''),\n amountCents: Math.max(0, Math.trunc(Number(payment.amountCents) || 0)),\n appliedAs: 'tender' as const,\n }))\n return [...online, ...register].filter((credit) => credit.reference && credit.amountCents > 0)\n}\n\nconst CARD_METHODS: ReadonlySet<OrderPaymentMethod> = new Set(['card_present', 'card_keyed', 'card_link'])\n\n/**\n * A register sale's settled tenders as the order event names them (AGL-3614).\n * An order from before the split-tender ledger is one payment, inferred the\n * way the register's own reader infers it, with the order's tip and fee.\n */\nexport function orderPaymentsView(data: Record<string, any>): Array<{\n method: OrderPaymentMethod\n amountCents: number\n tipCents: number\n feeCents: number\n}> {\n if (data?.channel !== 'pos') return []\n const whole = (value: unknown) => Math.max(0, Math.round(Number(value ?? 0)) || 0)\n return orderPayments(data)\n .filter((payment) => payment.status === 'succeeded')\n .map((payment) => {\n const legacy = payment.id === 'legacy'\n return {\n method: payment.method,\n amountCents: whole(payment.amountCents),\n tipCents: whole(legacy ? data.totals?.tipCents : payment.tipCents),\n // The application fee Stripe took from this payment; a tender Stripe\n // never saw carried none.\n feeCents: legacy\n ? CARD_METHODS.has(payment.method) ? whole(data.totals?.feeCents ?? data.feeCents) : 0\n : whole(payment.feeCents),\n }\n })\n}\n"],"names":["serialize","fulfillmentLineQuantities","fulfillmentTrackingUrl","orderTaxEngineView","orderIsTestMode","orderPayments","orderViewFromData","id","data","totals","legacyTotal","Number","amountCents","NaN","totalCents","isFinite","legacyFee","feeCents","object","number","status","channel","currency","customerEmail","customerName","lineItems","itemsCents","shippingCents","taxCents","discountCents","extrasCents","tipCents","Math","max","round","payments","orderPaymentsView","giftCardRedeemedCents","extras","Array","isArray","filter","entry","map","String","pluginId","key","label","quoteRef","credits","orderCreditsView","refundedCents","livemode","checkoutSessionId","$id","taxMode","taxEngine","disputed","Boolean","dispute","shippingAddress","couponCode","fulfillments","atMs","lineItemIds","lines","carrier","trackingNumber","trackingUrl","labelUrl","at","Date","toISOString","created","createdAt","online","providerId","split","reference","last4","trunc","appliedAs","register","payment","method","creditProviderId","creditReference","creditLabel","credit","CARD_METHODS","Set","whole","value","legacy","has"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,SAAS,QAAQ,6CAA4C;AACtE,SAASC,yBAAyB,QAAQ,mCAA+B;AACzE,SAASC,sBAAsB,QAAQ,8BAA0B;AACjE,SAASC,kBAAkB,QAAQ,qCAAiC;AACpE,SAASC,eAAe,QAAQ,iCAA6B;AAC7D,SAASC,aAAa,QAAiC,8BAA0B;AAEjF;;;;CAIC,GACD,OAAO,SAASC,kBAAkBC,EAAU,EAAEC,IAAyB;QACrDA,cACWA,mBAMFA,gBAKdA,cACCA,eAEKA,qBACDA,oBACOA,iBAEAC,oBACGA,uBACLA,kBACKA,uBAYFA,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AEzG;;;;CAIC,GACD,OAAO,SAAStD,kBAAkB5B,IAAyB;IAMzD,IAAIA,CAAAA,wBAAAA,KAAMa,OAAO,MAAK,OAAO,OAAO,EAAE;IACtC,MAAMsE,QAAQ,CAACC,QAAmB5D,KAAKC,GAAG,CAAC,GAAGD,KAAKE,KAAK,CAACvB,OAAOiF,gBAAAA,QAAS,OAAO;IAChF,OAAOvF,cAAcG,MAClBiC,MAAM,CAAC,CAAC0C,UAAYA,QAAQ/D,MAAM,KAAK,aACvCuB,GAAG,CAAC,CAACwC;;YAKuB3E,cAIoBA;QAR/C,MAAMqF,SAASV,QAAQ5E,EAAE,KAAK;QAC9B,OAAO;YACL6E,QAAQD,QAAQC,MAAM;YACtBxE,aAAa+E,MAAMR,QAAQvE,WAAW;YACtCmB,UAAU4D,MAAME,UAASrF,eAAAA,KAAKC,MAAM,qBAAXD,aAAauB,QAAQ,GAAGoD,QAAQpD,QAAQ;YACjE,qEAAqE;YACrE,0BAA0B;YAC1Bd,UAAU4E,SACNJ,aAAaK,GAAG,CAACX,QAAQC,MAAM,IAAIO,eAAMnF,gBAAAA,KAAKC,MAAM,qBAAXD,cAAaS,QAAQ,mBAAIT,KAAKS,QAAQ,IAAI,IACnF0E,MAAMR,QAAQlE,QAAQ;QAC5B;IACF;AACJ"}
|
|
@@ -3075,7 +3075,9 @@ export const commerceBillingWebhookHandler = async ({ type, object, event, reque
|
|
|
3075
3075
|
sku: variant.sku
|
|
3076
3076
|
} : {}, {
|
|
3077
3077
|
productType: product.type
|
|
3078
|
-
}, product.
|
|
3078
|
+
}, product.giftCard ? {
|
|
3079
|
+
giftCard: true
|
|
3080
|
+
} : {}, product.supplierId ? {
|
|
3079
3081
|
supplierId: product.supplierId
|
|
3080
3082
|
} : {}, {
|
|
3081
3083
|
quantity: line.quantity,
|
|
@@ -3132,7 +3134,7 @@ export const commerceBillingWebhookHandler = async ({ type, object, event, reque
|
|
|
3132
3134
|
});
|
|
3133
3135
|
const created = await firestore.runTransaction(async (transaction)=>{
|
|
3134
3136
|
var _counter_get, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
|
|
3135
|
-
var _object_metadata, _object_customer_details, _object_customer_details1;
|
|
3137
|
+
var _object_metadata, _object_metadata1, _object_metadata2, _object_customer_details, _object_customer_details1;
|
|
3136
3138
|
const [existing, counter] = await Promise.all([
|
|
3137
3139
|
transaction.get(orderRef),
|
|
3138
3140
|
transaction.get(counterRef)
|
|
@@ -3195,6 +3197,8 @@ export const commerceBillingWebhookHandler = async ({ type, object, event, reque
|
|
|
3195
3197
|
credits: [
|
|
3196
3198
|
creditSold
|
|
3197
3199
|
]
|
|
3200
|
+
} : {}, (object == null ? void 0 : (_object_metadata = object.metadata) == null ? void 0 : _object_metadata.giftCardCode) && Number(object == null ? void 0 : (_object_metadata1 = object.metadata) == null ? void 0 : _object_metadata1.giftCardCents) > 0 ? {
|
|
3201
|
+
giftCardRedeemedCents: Math.round(Number(object.metadata.giftCardCents))
|
|
3198
3202
|
} : {}, {
|
|
3199
3203
|
// WHICH TAX THIS SALE CARRIED (AGL-2451). `totals.taxCents` above
|
|
3200
3204
|
// says how much; this says who computed it, which is the fact that
|
|
@@ -3203,7 +3207,7 @@ export const commerceBillingWebhookHandler = async ({ type, object, event, reque
|
|
|
3203
3207
|
// the order and the filed row cannot disagree. A manual cart's tax
|
|
3204
3208
|
// rides a real Stripe Tax Rate since AGL-1953 and therefore has a
|
|
3205
3209
|
// populated breakdown — the flag is what tells the two apart.
|
|
3206
|
-
taxMode: storefrontTaxModeOf(object, Number((_ref = object == null ? void 0 : (
|
|
3210
|
+
taxMode: storefrontTaxModeOf(object, Number((_ref = object == null ? void 0 : (_object_metadata2 = object.metadata) == null ? void 0 : _object_metadata2.taxCents) != null ? _ref : 0))
|
|
3207
3211
|
}, taxEngineStampFromMetadata(object == null ? void 0 : object.metadata), {
|
|
3208
3212
|
timeline: [
|
|
3209
3213
|
{
|