@aglyn/plugins-commerce 1.13.0 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -13
- package/src/lib/components/account-subscriptions.d.ts +51 -0
- package/src/lib/components/account-subscriptions.js +168 -0
- package/src/lib/components/account-subscriptions.js.map +1 -0
- package/src/lib/components/account.js +12 -48
- package/src/lib/components/account.js.map +1 -1
- package/src/lib/components/cart.js +30 -6
- 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/commerce-console-sections.d.ts +1 -1
- package/src/lib/components/commerce-console-sections.js +5 -0
- package/src/lib/components/commerce-console-sections.js.map +1 -1
- package/src/lib/components/console/paid-media.d.ts +1 -0
- package/src/lib/components/console/paid-media.js +15 -4
- package/src/lib/components/console/paid-media.js.map +1 -1
- package/src/lib/components/console/payments-settings-card.component.js +1 -1
- package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-hardware-api.d.ts +10 -1
- package/src/lib/components/console/pos/pos-hardware-api.js.map +1 -1
- package/src/lib/components/console/pos/pos-hardware-buyer.component.js +2 -2
- package/src/lib/components/console/pos/pos-hardware-buyer.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-hardware-sale-api.d.ts +2 -0
- package/src/lib/components/console/pos/pos-hardware-sale-api.js.map +1 -1
- package/src/lib/components/console/pos-cellular-control.component.d.ts +1 -1
- package/src/lib/components/console/pos-cellular-control.component.js +5 -5
- package/src/lib/components/console/pos-cellular-control.component.js.map +1 -1
- package/src/lib/components/console/pos-devices-card.component.js +2 -2
- package/src/lib/components/console/pos-devices-card.component.js.map +1 -1
- package/src/lib/components/console/pos-hardware-card.component.d.ts +5 -0
- package/src/lib/components/console/pos-hardware-card.component.js +77 -8
- package/src/lib/components/console/pos-hardware-card.component.js.map +1 -1
- package/src/lib/components/console/pos-hardware-orders-staff-page.component.js +137 -19
- package/src/lib/components/console/pos-hardware-orders-staff-page.component.js.map +1 -1
- package/src/lib/components/console/pos-page.component.js +19 -2
- package/src/lib/components/console/pos-page.component.js.map +1 -1
- package/src/lib/components/console/product-editor-dialog.component.js +21 -2
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/subscription-detail-dialog.component.d.ts +58 -0
- package/src/lib/components/console/subscription-detail-dialog.component.js +201 -0
- package/src/lib/components/console/subscription-detail-dialog.component.js.map +1 -0
- package/src/lib/components/console/subscriptions-card.component.d.ts +60 -0
- package/src/lib/components/console/subscriptions-card.component.js +280 -0
- package/src/lib/components/console/subscriptions-card.component.js.map +1 -0
- package/src/lib/components/hardware-terms-consent.d.ts +22 -0
- package/src/lib/components/hardware-terms-consent.js +85 -0
- package/src/lib/components/hardware-terms-consent.js.map +1 -0
- package/src/lib/components/product-detail.js +25 -5
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/constants/operator-alerts.d.ts +1 -1
- package/src/lib/constants/operator-alerts.js +4 -4
- package/src/lib/constants/operator-alerts.js.map +1 -1
- package/src/lib/model/commerce-orders.d.ts +6 -2
- package/src/lib/model/commerce-orders.js.map +1 -1
- package/src/lib/model/commerce-payment-methods.d.ts +24 -0
- package/src/lib/model/commerce-payment-methods.js +35 -0
- package/src/lib/model/commerce-payment-methods.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 +1 -0
- package/src/lib/model/index.js +1 -0
- package/src/lib/model/index.js.map +1 -1
- package/src/lib/model/paid-media.d.ts +8 -0
- package/src/lib/model/paid-media.js +13 -0
- package/src/lib/model/paid-media.js.map +1 -1
- package/src/lib/model/pos-hardware-in-person.d.ts +23 -2
- package/src/lib/model/pos-hardware-in-person.js +52 -20
- package/src/lib/model/pos-hardware-in-person.js.map +1 -1
- package/src/lib/model/pos-hardware-tax-summary.d.ts +5 -1
- package/src/lib/model/pos-hardware-tax-summary.js +2 -1
- package/src/lib/model/pos-hardware-tax-summary.js.map +1 -1
- package/src/lib/model/pos-hardware-terms.d.ts +37 -2
- package/src/lib/model/pos-hardware-terms.js +68 -3
- package/src/lib/model/pos-hardware-terms.js.map +1 -1
- package/src/lib/model/pos-hardware.d.ts +101 -15
- package/src/lib/model/pos-hardware.js +128 -18
- package/src/lib/model/pos-hardware.js.map +1 -1
- package/src/lib/model/pos-reader-splash.js +2 -2
- package/src/lib/model/pos-reader-splash.js.map +1 -1
- package/src/lib/model/product-write.d.ts +3 -0
- package/src/lib/model/subscription-view.d.ts +90 -0
- package/src/lib/model/subscription-view.js +176 -0
- package/src/lib/model/subscription-view.js.map +1 -0
- package/src/lib/server/billing-webhook.d.ts +4 -6
- package/src/lib/server/billing-webhook.js +109 -51
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/cart-checkout.js +45 -10
- package/src/lib/server/cart-checkout.js.map +1 -1
- package/src/lib/server/cart.js +15 -3
- package/src/lib/server/cart.js.map +1 -1
- package/src/lib/server/checkout.js +58 -16
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/draft-order.js +7 -3
- package/src/lib/server/draft-order.js.map +1 -1
- package/src/lib/server/membership-account.d.ts +22 -0
- package/src/lib/server/membership-account.js +52 -8
- package/src/lib/server/membership-account.js.map +1 -1
- package/src/lib/server/pos-auth.d.ts +3 -3
- package/src/lib/server/pos-auth.js +3 -3
- package/src/lib/server/pos-auth.js.map +1 -1
- package/src/lib/server/pos-cellular-billing.js +1 -1
- package/src/lib/server/pos-cellular-billing.js.map +1 -1
- package/src/lib/server/pos-cellular-notify.js +1 -1
- package/src/lib/server/pos-cellular-notify.js.map +1 -1
- package/src/lib/server/pos-cellular.js +1 -1
- package/src/lib/server/pos-cellular.js.map +1 -1
- package/src/lib/server/pos-hardware-admin.js +86 -13
- package/src/lib/server/pos-hardware-admin.js.map +1 -1
- package/src/lib/server/pos-hardware-attach.js +5 -5
- package/src/lib/server/pos-hardware-attach.js.map +1 -1
- package/src/lib/server/pos-hardware-cancel.js +65 -0
- package/src/lib/server/pos-hardware-cancel.js.map +1 -1
- package/src/lib/server/pos-hardware-closure-notices.js +2 -5
- package/src/lib/server/pos-hardware-closure-notices.js.map +1 -1
- package/src/lib/server/pos-hardware-closure.js +5 -8
- package/src/lib/server/pos-hardware-closure.js.map +1 -1
- package/src/lib/server/pos-hardware-in-person.d.ts +2 -1
- package/src/lib/server/pos-hardware-in-person.js +72 -17
- package/src/lib/server/pos-hardware-in-person.js.map +1 -1
- package/src/lib/server/pos-hardware-notify.d.ts +2 -0
- package/src/lib/server/pos-hardware-notify.js +30 -5
- package/src/lib/server/pos-hardware-notify.js.map +1 -1
- package/src/lib/server/pos-hardware-readers.d.ts +25 -0
- package/src/lib/server/pos-hardware-readers.js +206 -85
- package/src/lib/server/pos-hardware-readers.js.map +1 -1
- package/src/lib/server/pos-hardware-returns.d.ts +8 -3
- package/src/lib/server/pos-hardware-returns.js +39 -7
- package/src/lib/server/pos-hardware-returns.js.map +1 -1
- package/src/lib/server/pos-hardware-sale-fields.d.ts +76 -0
- package/src/lib/server/pos-hardware-sale-fields.js +114 -1
- package/src/lib/server/pos-hardware-sale-fields.js.map +1 -1
- package/src/lib/server/pos-hardware-sale.d.ts +2 -0
- package/src/lib/server/pos-hardware-sale.js +1 -0
- package/src/lib/server/pos-hardware-sale.js.map +1 -1
- package/src/lib/server/pos-hardware-tax-return-source.js +7 -4
- package/src/lib/server/pos-hardware-tax-return-source.js.map +1 -1
- package/src/lib/server/pos-hardware-webhook.js +16 -3
- package/src/lib/server/pos-hardware-webhook.js.map +1 -1
- package/src/lib/server/pos-hardware.d.ts +14 -3
- package/src/lib/server/pos-hardware.js +83 -18
- package/src/lib/server/pos-hardware.js.map +1 -1
- package/src/lib/server/pos-ops-routes.js +2 -10
- package/src/lib/server/pos-ops-routes.js.map +1 -1
- package/src/lib/server/quote-pay.js +8 -4
- package/src/lib/server/quote-pay.js.map +1 -1
- package/src/lib/server/stream.d.ts +2 -0
- package/src/lib/server/stream.js +22 -2
- package/src/lib/server/stream.js.map +1 -1
- package/src/lib/server/tax-return-source.js +5 -1
- package/src/lib/server/tax-return-source.js.map +1 -1
- package/src/lib/server.js +2 -2
- package/src/lib/server.js.map +1 -1
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ /**
|
|
17
|
+
* How a storefront subscription (`hosts/{hostId}/subscriptions`) reads to a
|
|
18
|
+
* person (AGL-4191): its status in words, the one date that matters next, and
|
|
19
|
+
* what it is worth a month. One copy for the console's Subscriptions list and
|
|
20
|
+
* the buyer's account page, so the merchant and the subscriber never read two
|
|
21
|
+
* different answers about the same subscription.
|
|
22
|
+
*/ /** Stripe's subscription statuses, in the merchant's words. */ export const SUBSCRIPTION_STATUS_LABELS = {
|
|
23
|
+
active: 'Active',
|
|
24
|
+
trialing: 'Trial',
|
|
25
|
+
past_due: 'Past due',
|
|
26
|
+
unpaid: 'Unpaid',
|
|
27
|
+
incomplete: 'Incomplete',
|
|
28
|
+
incomplete_expired: 'Expired',
|
|
29
|
+
canceled: 'Canceled',
|
|
30
|
+
paused: 'Paused'
|
|
31
|
+
};
|
|
32
|
+
export const SUBSCRIPTION_STATUS_COLOR = {
|
|
33
|
+
active: 'success',
|
|
34
|
+
trialing: 'info',
|
|
35
|
+
past_due: 'warning',
|
|
36
|
+
unpaid: 'error',
|
|
37
|
+
incomplete: 'warning'
|
|
38
|
+
};
|
|
39
|
+
/** The statuses the console's filter offers, in the order a merchant scans them. */ // AGL-1715-EXEMPT: the options of the subscriptions list's status filter, a
|
|
40
|
+
// display vocabulary rather than a "live" test; nothing is granted or refused
|
|
41
|
+
// by membership in it.
|
|
42
|
+
export const SUBSCRIPTION_FILTER_STATUSES = [
|
|
43
|
+
'active',
|
|
44
|
+
'trialing',
|
|
45
|
+
'past_due',
|
|
46
|
+
'unpaid',
|
|
47
|
+
'incomplete',
|
|
48
|
+
'canceled'
|
|
49
|
+
];
|
|
50
|
+
/**
|
|
51
|
+
* The statuses that bring money in every cycle: what monthly recurring revenue
|
|
52
|
+
* counts. A trial has not paid yet, and `unpaid` has stopped paying; `past_due`
|
|
53
|
+
* stays in because Stripe is still collecting and the subscriber has not left,
|
|
54
|
+
* the same reason it stays live for access (`commerce-subscription-status.ts`).
|
|
55
|
+
*/ export const SUBSCRIPTION_PAYING_STATUSES = [
|
|
56
|
+
'active',
|
|
57
|
+
'past_due'
|
|
58
|
+
];
|
|
59
|
+
export function subscriptionStatusLabel(status) {
|
|
60
|
+
var _SUBSCRIPTION_STATUS_LABELS_key;
|
|
61
|
+
const key = String(status != null ? status : '');
|
|
62
|
+
return (_SUBSCRIPTION_STATUS_LABELS_key = SUBSCRIPTION_STATUS_LABELS[key]) != null ? _SUBSCRIPTION_STATUS_LABELS_key : key ? key.replace(/_/g, ' ') : 'Unknown';
|
|
63
|
+
}
|
|
64
|
+
export function subscriptionStatusColor(status) {
|
|
65
|
+
var _SUBSCRIPTION_STATUS_COLOR_String;
|
|
66
|
+
return (_SUBSCRIPTION_STATUS_COLOR_String = SUBSCRIPTION_STATUS_COLOR[String(status != null ? status : '')]) != null ? _SUBSCRIPTION_STATUS_COLOR_String : 'default';
|
|
67
|
+
}
|
|
68
|
+
/** `month` or `year` from a stored value, or null for anything else. */ export function subscriptionInterval(value) {
|
|
69
|
+
return value === 'month' || value === 'year' ? value : null;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A recurring charge as a monthly figure: a yearly price counts a twelfth.
|
|
73
|
+
* Tax is the government's, not the merchant's revenue, so it is left out.
|
|
74
|
+
* Rounded to whole cents.
|
|
75
|
+
*/ export function monthlyRecurringCents(totalCents, taxCents, interval) {
|
|
76
|
+
const net = Math.max(0, (Number(totalCents) || 0) - (Number(taxCents) || 0));
|
|
77
|
+
const cadence = subscriptionInterval(interval);
|
|
78
|
+
if (cadence === 'year') return Math.round(net / 12);
|
|
79
|
+
if (cadence === 'month') return Math.round(net);
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
function positiveMs(value) {
|
|
83
|
+
const ms = Number(value);
|
|
84
|
+
return Number.isFinite(ms) && ms > 0 ? ms : undefined;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The one date that matters next for a subscription, or null when there is
|
|
88
|
+
* nothing honest to say.
|
|
89
|
+
*
|
|
90
|
+
* `cancelAtPeriodEnd` wins over a renewal: a subscriber who cancelled in the
|
|
91
|
+
* billing portal keeps access to the end of the period they paid for and is
|
|
92
|
+
* not charged again, so "Renews" would be a promise of a charge that will not
|
|
93
|
+
* happen. A failed payment names no date, because Stripe moves the period end
|
|
94
|
+
* forward while the unpaid invoice is retried, so that date is neither a
|
|
95
|
+
* renewal nor an end.
|
|
96
|
+
*/ export function subscriptionDateLine(subscription) {
|
|
97
|
+
var _subscription_status, _positiveMs;
|
|
98
|
+
const status = String((_subscription_status = subscription.status) != null ? _subscription_status : '');
|
|
99
|
+
const periodEnd = (_positiveMs = positiveMs(subscription.currentPeriodEndMs)) != null ? _positiveMs : positiveMs(subscription.paidThroughMs);
|
|
100
|
+
const ending = subscription.cancelAtPeriodEnd === true;
|
|
101
|
+
switch(status){
|
|
102
|
+
case 'active':
|
|
103
|
+
if (!periodEnd) return null;
|
|
104
|
+
return {
|
|
105
|
+
kind: ending ? 'ends' : 'renews',
|
|
106
|
+
atMs: periodEnd
|
|
107
|
+
};
|
|
108
|
+
case 'trialing':
|
|
109
|
+
if (!periodEnd) return null;
|
|
110
|
+
return {
|
|
111
|
+
kind: ending ? 'ends' : 'trialEnds',
|
|
112
|
+
atMs: periodEnd
|
|
113
|
+
};
|
|
114
|
+
case 'past_due':
|
|
115
|
+
case 'unpaid':
|
|
116
|
+
return {
|
|
117
|
+
kind: 'paymentFailed'
|
|
118
|
+
};
|
|
119
|
+
case 'incomplete':
|
|
120
|
+
return {
|
|
121
|
+
kind: 'awaitingPayment'
|
|
122
|
+
};
|
|
123
|
+
case 'canceled':
|
|
124
|
+
case 'incomplete_expired':
|
|
125
|
+
return periodEnd ? {
|
|
126
|
+
kind: 'ended',
|
|
127
|
+
atMs: periodEnd
|
|
128
|
+
} : null;
|
|
129
|
+
default:
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** A short date in the reader's own locale: "Dec 4, 2026". */ export function formatSubscriptionDate(ms) {
|
|
134
|
+
return new Date(ms).toLocaleDateString(undefined, {
|
|
135
|
+
month: 'short',
|
|
136
|
+
day: 'numeric',
|
|
137
|
+
year: 'numeric'
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/** The date line in words: "Renews Dec 4, 2026", "Payment failed". */ export function subscriptionDateText(line, formatDate = formatSubscriptionDate) {
|
|
141
|
+
if (!line) return '';
|
|
142
|
+
const on = line.atMs ? formatDate(line.atMs) : '';
|
|
143
|
+
switch(line.kind){
|
|
144
|
+
case 'renews':
|
|
145
|
+
return `Renews ${on}`;
|
|
146
|
+
case 'trialEnds':
|
|
147
|
+
return `Trial ends ${on}`;
|
|
148
|
+
case 'ends':
|
|
149
|
+
return `Ends ${on}`;
|
|
150
|
+
case 'ended':
|
|
151
|
+
return `Ended ${on}`;
|
|
152
|
+
case 'paymentFailed':
|
|
153
|
+
return 'Payment failed';
|
|
154
|
+
case 'awaitingPayment':
|
|
155
|
+
return 'Waiting for the first payment';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/** "/month" or "/year", or "" for a stored value that is neither. */ export function subscriptionIntervalSuffix(interval) {
|
|
159
|
+
const cadence = subscriptionInterval(interval);
|
|
160
|
+
return cadence ? `/${cadence}` : '';
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* What a subscription's plan is called: the line the subscriber bought, with
|
|
164
|
+
* its quantity when more than one, or the product id for a subscription sold
|
|
165
|
+
* before lines were stored (AGL-1732).
|
|
166
|
+
*/ export function subscriptionPlanName(subscription) {
|
|
167
|
+
var _subscription_lineItems;
|
|
168
|
+
const line = (_subscription_lineItems = subscription.lineItems) == null ? void 0 : _subscription_lineItems[0];
|
|
169
|
+
if (line == null ? void 0 : line.name) {
|
|
170
|
+
var _line_quantity;
|
|
171
|
+
return ((_line_quantity = line.quantity) != null ? _line_quantity : 1) > 1 ? `${line.quantity}× ${line.name}` : line.name;
|
|
172
|
+
}
|
|
173
|
+
return subscription.productId || 'Subscription';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
//# sourceMappingURL=subscription-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/subscription-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\n/**\n * How a storefront subscription (`hosts/{hostId}/subscriptions`) reads to a\n * person (AGL-4191): its status in words, the one date that matters next, and\n * what it is worth a month. One copy for the console's Subscriptions list and\n * the buyer's account page, so the merchant and the subscriber never read two\n * different answers about the same subscription.\n */\n\nexport type SubscriptionBillingInterval = 'month' | 'year'\n\n/** Stripe's subscription statuses, in the merchant's words. */\nexport const SUBSCRIPTION_STATUS_LABELS: Readonly<Record<string, string>> = {\n active: 'Active',\n trialing: 'Trial',\n past_due: 'Past due',\n unpaid: 'Unpaid',\n incomplete: 'Incomplete',\n incomplete_expired: 'Expired',\n canceled: 'Canceled',\n paused: 'Paused',\n}\n\nexport const SUBSCRIPTION_STATUS_COLOR: Readonly<\n Record<string, 'success' | 'info' | 'warning' | 'error' | 'default'>\n> = {\n active: 'success',\n trialing: 'info',\n past_due: 'warning',\n unpaid: 'error',\n incomplete: 'warning',\n}\n\n/** The statuses the console's filter offers, in the order a merchant scans them. */\n// AGL-1715-EXEMPT: the options of the subscriptions list's status filter, a\n// display vocabulary rather than a \"live\" test; nothing is granted or refused\n// by membership in it.\nexport const SUBSCRIPTION_FILTER_STATUSES = [\n 'active',\n 'trialing',\n 'past_due',\n 'unpaid',\n 'incomplete',\n 'canceled',\n] as const\n\n/**\n * The statuses that bring money in every cycle: what monthly recurring revenue\n * counts. A trial has not paid yet, and `unpaid` has stopped paying; `past_due`\n * stays in because Stripe is still collecting and the subscriber has not left,\n * the same reason it stays live for access (`commerce-subscription-status.ts`).\n */\nexport const SUBSCRIPTION_PAYING_STATUSES = ['active', 'past_due'] as const\n\nexport function subscriptionStatusLabel(status: unknown): string {\n const key = String(status ?? '')\n return SUBSCRIPTION_STATUS_LABELS[key] ?? (key ? key.replace(/_/g, ' ') : 'Unknown')\n}\n\nexport function subscriptionStatusColor(\n status: unknown,\n): 'success' | 'info' | 'warning' | 'error' | 'default' {\n return SUBSCRIPTION_STATUS_COLOR[String(status ?? '')] ?? 'default'\n}\n\n/** `month` or `year` from a stored value, or null for anything else. */\nexport function subscriptionInterval(value: unknown): SubscriptionBillingInterval | null {\n return value === 'month' || value === 'year' ? value : null\n}\n\n/**\n * A recurring charge as a monthly figure: a yearly price counts a twelfth.\n * Tax is the government's, not the merchant's revenue, so it is left out.\n * Rounded to whole cents.\n */\nexport function monthlyRecurringCents(\n totalCents: unknown,\n taxCents: unknown,\n interval: unknown,\n): number {\n const net = Math.max(0, (Number(totalCents) || 0) - (Number(taxCents) || 0))\n const cadence = subscriptionInterval(interval)\n if (cadence === 'year') return Math.round(net / 12)\n if (cadence === 'month') return Math.round(net)\n return 0\n}\n\n/** The fields of a stored subscription the date line reads. */\nexport interface SubscriptionDateFields {\n status?: unknown\n cancelAtPeriodEnd?: unknown\n currentPeriodEndMs?: unknown\n /** Set by each paid invoice; the fallback when Stripe sent no period end. */\n paidThroughMs?: unknown\n}\n\nexport type SubscriptionDateKind =\n | 'renews'\n | 'trialEnds'\n | 'ends'\n | 'ended'\n | 'paymentFailed'\n | 'awaitingPayment'\n\nexport interface SubscriptionDateLine {\n kind: SubscriptionDateKind\n /** Absent where the line names no date (\"Payment failed\"). */\n atMs?: number\n}\n\nfunction positiveMs(value: unknown): number | undefined {\n const ms = Number(value)\n return Number.isFinite(ms) && ms > 0 ? ms : undefined\n}\n\n/**\n * The one date that matters next for a subscription, or null when there is\n * nothing honest to say.\n *\n * `cancelAtPeriodEnd` wins over a renewal: a subscriber who cancelled in the\n * billing portal keeps access to the end of the period they paid for and is\n * not charged again, so \"Renews\" would be a promise of a charge that will not\n * happen. A failed payment names no date, because Stripe moves the period end\n * forward while the unpaid invoice is retried, so that date is neither a\n * renewal nor an end.\n */\nexport function subscriptionDateLine(\n subscription: SubscriptionDateFields,\n): SubscriptionDateLine | null {\n const status = String(subscription.status ?? '')\n const periodEnd =\n positiveMs(subscription.currentPeriodEndMs) ?? positiveMs(subscription.paidThroughMs)\n const ending = subscription.cancelAtPeriodEnd === true\n switch (status) {\n case 'active':\n if (!periodEnd) return null\n return { kind: ending ? 'ends' : 'renews', atMs: periodEnd }\n case 'trialing':\n if (!periodEnd) return null\n return { kind: ending ? 'ends' : 'trialEnds', atMs: periodEnd }\n case 'past_due':\n case 'unpaid':\n return { kind: 'paymentFailed' }\n case 'incomplete':\n return { kind: 'awaitingPayment' }\n case 'canceled':\n case 'incomplete_expired':\n return periodEnd ? { kind: 'ended', atMs: periodEnd } : null\n default:\n return null\n }\n}\n\n/** A short date in the reader's own locale: \"Dec 4, 2026\". */\nexport function formatSubscriptionDate(ms: number): string {\n return new Date(ms).toLocaleDateString(undefined, {\n month: 'short',\n day: 'numeric',\n year: 'numeric',\n })\n}\n\n/** The date line in words: \"Renews Dec 4, 2026\", \"Payment failed\". */\nexport function subscriptionDateText(\n line: SubscriptionDateLine | null,\n formatDate: (ms: number) => string = formatSubscriptionDate,\n): string {\n if (!line) return ''\n const on = line.atMs ? formatDate(line.atMs) : ''\n switch (line.kind) {\n case 'renews':\n return `Renews ${on}`\n case 'trialEnds':\n return `Trial ends ${on}`\n case 'ends':\n return `Ends ${on}`\n case 'ended':\n return `Ended ${on}`\n case 'paymentFailed':\n return 'Payment failed'\n case 'awaitingPayment':\n return 'Waiting for the first payment'\n }\n}\n\n/** \"/month\" or \"/year\", or \"\" for a stored value that is neither. */\nexport function subscriptionIntervalSuffix(interval: unknown): string {\n const cadence = subscriptionInterval(interval)\n return cadence ? `/${cadence}` : ''\n}\n\n/**\n * What a subscription's plan is called: the line the subscriber bought, with\n * its quantity when more than one, or the product id for a subscription sold\n * before lines were stored (AGL-1732).\n */\nexport function subscriptionPlanName(subscription: {\n lineItems?: Array<{ name?: string; quantity?: number }>\n productId?: string\n}): string {\n const line = subscription.lineItems?.[0]\n if (line?.name) {\n return (line.quantity ?? 1) > 1 ? `${line.quantity}× ${line.name}` : line.name\n }\n return subscription.productId || 'Subscription'\n}\n"],"names":["SUBSCRIPTION_STATUS_LABELS","active","trialing","past_due","unpaid","incomplete","incomplete_expired","canceled","paused","SUBSCRIPTION_STATUS_COLOR","SUBSCRIPTION_FILTER_STATUSES","SUBSCRIPTION_PAYING_STATUSES","subscriptionStatusLabel","status","key","String","replace","subscriptionStatusColor","subscriptionInterval","value","monthlyRecurringCents","totalCents","taxCents","interval","net","Math","max","Number","cadence","round","positiveMs","ms","isFinite","undefined","subscriptionDateLine","subscription","periodEnd","currentPeriodEndMs","paidThroughMs","ending","cancelAtPeriodEnd","kind","atMs","formatSubscriptionDate","Date","toLocaleDateString","month","day","year","subscriptionDateText","line","formatDate","on","subscriptionIntervalSuffix","subscriptionPlanName","lineItems","name","quantity","productId"],"mappings":"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"}
|
|
@@ -16,11 +16,9 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import type { BillingWebhookHandler } from '@aglyn/aglyn/server';
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* assignment helper (AGL-308). Registered via registerCommerceConsoleApi;
|
|
23
|
-
* every section is idempotent by doc key and self-selects on
|
|
24
|
-
* `object.metadata.type`, exactly as the inline route sections did.
|
|
19
|
+
* A Stripe subscription's current period end, in seconds (AGL-4191). Older API
|
|
20
|
+
* versions carry it on the subscription; newer ones moved it to each item.
|
|
21
|
+
* Exported for the spec.
|
|
25
22
|
*/
|
|
23
|
+
export declare function subscriptionPeriodEnd(object: any): number | null;
|
|
26
24
|
export declare const commerceBillingWebhookHandler: BillingWebhookHandler;
|
|
@@ -53,7 +53,19 @@ import { checkoutCreditProvider, checkoutCreditSold, decodeCheckoutCreditMetadat
|
|
|
53
53
|
import { raiseOrderEvent } from "./order-events.js";
|
|
54
54
|
import { handlePosStripeEvent } from "./pos-terminal.js";
|
|
55
55
|
import { notifyPosSaleCompleted } from "./pos-sale.js";
|
|
56
|
+
import { recordSellerStoreSaleHardware, sellerStoreOrderHardwareFields } from "./pos-hardware-sale-fields.js";
|
|
56
57
|
import { posOrderRefundStripeId } from "./pos-order-refund-ids.js";
|
|
58
|
+
/**
|
|
59
|
+
* A Stripe subscription's current period end, in seconds (AGL-4191). Older API
|
|
60
|
+
* versions carry it on the subscription; newer ones moved it to each item.
|
|
61
|
+
* Exported for the spec.
|
|
62
|
+
*/ export function subscriptionPeriodEnd(object) {
|
|
63
|
+
var _object_items_data_, _object_items_data, _object_items;
|
|
64
|
+
const own = Number(object == null ? void 0 : object.current_period_end);
|
|
65
|
+
if (Number.isFinite(own) && own > 0) return own;
|
|
66
|
+
const item = Number(object == null ? void 0 : (_object_items = object.items) == null ? void 0 : (_object_items_data = _object_items.data) == null ? void 0 : (_object_items_data_ = _object_items_data[0]) == null ? void 0 : _object_items_data_.current_period_end);
|
|
67
|
+
return Number.isFinite(item) && item > 0 ? item : null;
|
|
68
|
+
}
|
|
57
69
|
/**
|
|
58
70
|
* Assigns unassigned license keys for a digital product (AGL-308):
|
|
59
71
|
* stamps order/email on the key docs, returns the key strings, and
|
|
@@ -1724,7 +1736,25 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
1724
1736
|
* assignment helper (AGL-308). Registered via registerCommerceConsoleApi;
|
|
1725
1737
|
* every section is idempotent by doc key and self-selects on
|
|
1726
1738
|
* `object.metadata.type`, exactly as the inline route sections did.
|
|
1727
|
-
*/
|
|
1739
|
+
*/ /**
|
|
1740
|
+
* A Stripe address as an order stores it: only the parts Stripe filled.
|
|
1741
|
+
* Stripe sends an empty part as `null`, and the Admin SDK here refuses an
|
|
1742
|
+
* `undefined` value outright (no `ignoreUndefinedProperties`), so a part is
|
|
1743
|
+
* left out rather than written as `undefined`: an address with no second
|
|
1744
|
+
* line used to fail the whole order write.
|
|
1745
|
+
*/ function stripeOrderAddress(name, address) {
|
|
1746
|
+
const parts = {
|
|
1747
|
+
name,
|
|
1748
|
+
line1: address == null ? void 0 : address.line1,
|
|
1749
|
+
line2: address == null ? void 0 : address.line2,
|
|
1750
|
+
city: address == null ? void 0 : address.city,
|
|
1751
|
+
state: address == null ? void 0 : address.state,
|
|
1752
|
+
postalCode: address == null ? void 0 : address.postal_code,
|
|
1753
|
+
country: address == null ? void 0 : address.country
|
|
1754
|
+
};
|
|
1755
|
+
return Object.fromEntries(Object.entries(parts).filter(([, value])=>typeof value === 'string' && value !== ''));
|
|
1756
|
+
}
|
|
1757
|
+
export const commerceBillingWebhookHandler = async ({ type, object, event, requestHost })=>{
|
|
1728
1758
|
var _object_metadata, _object_metadata1, _object_metadata2, _object_metadata3, _object_metadata4;
|
|
1729
1759
|
// THE MERCHANT'S PAYMENT ACCOUNT CHANGED. Every commerce money route —
|
|
1730
1760
|
// checkout, cart checkout, draft orders, reservations, POS — gates the sale
|
|
@@ -1878,7 +1908,14 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
1878
1908
|
var _ref8;
|
|
1879
1909
|
await firebaseAdmin.app().firestore().collection('hosts').doc(String(subHostId)).collection('subscriptions').doc(String(object.id)).set({
|
|
1880
1910
|
status: type === 'customer.subscription.deleted' ? 'canceled' : String((_ref8 = object == null ? void 0 : object.status) != null ? _ref8 : 'active'),
|
|
1881
|
-
|
|
1911
|
+
// Newer Stripe API versions keep the period on the item, not
|
|
1912
|
+
// the subscription; either answers the same question.
|
|
1913
|
+
currentPeriodEndMs: subscriptionPeriodEnd(object) ? Number(subscriptionPeriodEnd(object)) * 1000 : null,
|
|
1914
|
+
// Cancelled in the billing portal: access runs to the period
|
|
1915
|
+
// end and nothing more is charged (AGL-4191). Without this the
|
|
1916
|
+
// account page and the Subscriptions list would promise a
|
|
1917
|
+
// renewal that will not happen.
|
|
1918
|
+
cancelAtPeriodEnd: type !== 'customer.subscription.deleted' && (object == null ? void 0 : object.cancel_at_period_end) === true
|
|
1882
1919
|
}, {
|
|
1883
1920
|
merge: true
|
|
1884
1921
|
}).catch(()=>undefined);
|
|
@@ -2423,7 +2460,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
2423
2460
|
// is when the cycle was PAID — dating a redelivered cycle "now"
|
|
2424
2461
|
// would file it under the wrong day in every orders view.
|
|
2425
2462
|
if (shipsPhysically) {
|
|
2426
|
-
var _ref6, _ref7, _ref8, _ref9, _ref10, _ref11,
|
|
2463
|
+
var _ref6, _ref7, _ref8, _ref9, _ref10, _ref11, _invoiceTotals_feeCents;
|
|
2427
2464
|
const orderNumber = Number((_ref6 = orderCounter == null ? void 0 : orderCounter.get('next')) != null ? _ref6 : 1);
|
|
2428
2465
|
transaction.set(counterRef, {
|
|
2429
2466
|
next: orderNumber + 1
|
|
@@ -2458,15 +2495,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
2458
2495
|
customerName: (_ref8 = (_ref9 = object == null ? void 0 : object.customer_name) != null ? _ref9 : currentSubscription.get('customerName')) != null ? _ref8 : null,
|
|
2459
2496
|
customerEmail: (_ref10 = (_ref11 = object == null ? void 0 : object.customer_email) != null ? _ref11 : currentSubscription.get('customerEmail')) != null ? _ref10 : null
|
|
2460
2497
|
}, (invoiceShipping == null ? void 0 : invoiceShipping.address) ? {
|
|
2461
|
-
shippingAddress:
|
|
2462
|
-
name: (_ref12 = invoiceShipping == null ? void 0 : invoiceShipping.name) != null ? _ref12 : undefined,
|
|
2463
|
-
line1: (_invoiceShipping_address_line1 = invoiceShipping.address.line1) != null ? _invoiceShipping_address_line1 : undefined,
|
|
2464
|
-
line2: (_invoiceShipping_address_line2 = invoiceShipping.address.line2) != null ? _invoiceShipping_address_line2 : undefined,
|
|
2465
|
-
city: (_invoiceShipping_address_city = invoiceShipping.address.city) != null ? _invoiceShipping_address_city : undefined,
|
|
2466
|
-
state: (_invoiceShipping_address_state = invoiceShipping.address.state) != null ? _invoiceShipping_address_state : undefined,
|
|
2467
|
-
postalCode: (_invoiceShipping_address_postal_code = invoiceShipping.address.postal_code) != null ? _invoiceShipping_address_postal_code : undefined,
|
|
2468
|
-
country: (_invoiceShipping_address_country = invoiceShipping.address.country) != null ? _invoiceShipping_address_country : undefined
|
|
2469
|
-
}
|
|
2498
|
+
shippingAddress: stripeOrderAddress(invoiceShipping == null ? void 0 : invoiceShipping.name, invoiceShipping.address)
|
|
2470
2499
|
} : {}, {
|
|
2471
2500
|
amountCents: paidCents,
|
|
2472
2501
|
feeCents: Number((_invoiceTotals_feeCents = invoiceTotals.feeCents) != null ? _invoiceTotals_feeCents : 0),
|
|
@@ -2585,17 +2614,16 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
2585
2614
|
if (!isOpeningInvoice && paidCents > 0) {
|
|
2586
2615
|
var _ref28, _ref29;
|
|
2587
2616
|
const renewalEmail = (_ref28 = (_ref29 = object == null ? void 0 : object.customer_email) != null ? _ref29 : soldSnapshot.get('customerEmail')) != null ? _ref28 : null;
|
|
2588
|
-
// A physical cycle
|
|
2589
|
-
//
|
|
2590
|
-
//
|
|
2591
|
-
// learns the money arrived at all.
|
|
2617
|
+
// A physical cycle lands in Orders (AGL-1750); every cycle, digital
|
|
2618
|
+
// and service ones too, is listed under the subscription in
|
|
2619
|
+
// Products → Subscriptions (AGL-4191), which this links to.
|
|
2592
2620
|
const renewalPrice = `$${(paidCents / 100).toFixed(2)}${interval ? `/${interval}` : ''}`;
|
|
2593
2621
|
void notifyHostManagers(invoiceHostId, {
|
|
2594
2622
|
type: 'content.order',
|
|
2595
2623
|
title: `Subscription renewed on {site} — ${renewalPrice}`,
|
|
2596
2624
|
// Whose subscription, to what and where (AGL-3432).
|
|
2597
2625
|
body: `${renewalEmail ? `${String(renewalEmail)}'s` : 'A'} ` + `subscription to ${snapshot.name || 'a product'} on {site} ` + `renewed for ${renewalPrice}.`,
|
|
2598
|
-
link: `/${invoiceHostId}/products`
|
|
2626
|
+
link: `/${invoiceHostId}/products/subscriptions?subscription=${encodeURIComponent(subscriptionId)}`
|
|
2599
2627
|
});
|
|
2600
2628
|
// RFM (AGL-328): a subscriber in month 12 has paid twelve times, and
|
|
2601
2629
|
// counting only the first charge ranks them as a one-purchase
|
|
@@ -2967,8 +2995,24 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
2967
2995
|
console.error('commerce cart local fulfillment unreadable', String(object.id), error);
|
|
2968
2996
|
return null;
|
|
2969
2997
|
});
|
|
2998
|
+
// Card reader hardware sold online by the platform's own store
|
|
2999
|
+
// (AGL-4038): marked, with the terms the buyer ticked, so it becomes
|
|
3000
|
+
// a hardware order once written. Nothing on any other store.
|
|
3001
|
+
const cartHardware = await sellerStoreOrderHardwareFields({
|
|
3002
|
+
hostId: String(hostId),
|
|
3003
|
+
lineItems,
|
|
3004
|
+
products: productsById,
|
|
3005
|
+
metadata: object == null ? void 0 : object.metadata,
|
|
3006
|
+
createdSeconds: object == null ? void 0 : object.created,
|
|
3007
|
+
orgIdOf: async ()=>{
|
|
3008
|
+
var _ref, _ref1;
|
|
3009
|
+
var _owner_org;
|
|
3010
|
+
const owner = await getOrgForHost(String(hostId));
|
|
3011
|
+
return (_ref = (_ref1 = owner == null ? void 0 : owner.orgId) != null ? _ref1 : owner == null ? void 0 : (_owner_org = owner.org) == null ? void 0 : _owner_org.id) != null ? _ref : null;
|
|
3012
|
+
}
|
|
3013
|
+
});
|
|
2970
3014
|
const created = await firestore.runTransaction(async (transaction)=>{
|
|
2971
|
-
var _counter_get, _ref, _ref1, _ref2, _ref3, _ref4,
|
|
3015
|
+
var _counter_get, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
|
|
2972
3016
|
var _object_metadata, _object_customer_details, _object_customer_details1;
|
|
2973
3017
|
const [existing, counter] = await Promise.all([
|
|
2974
3018
|
transaction.get(orderRef),
|
|
@@ -3073,20 +3117,13 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3073
3117
|
customerName: (_ref2 = object == null ? void 0 : (_object_customer_details = object.customer_details) == null ? void 0 : _object_customer_details.name) != null ? _ref2 : null,
|
|
3074
3118
|
customerEmail: (_ref3 = object == null ? void 0 : (_object_customer_details1 = object.customer_details) == null ? void 0 : _object_customer_details1.email) != null ? _ref3 : null
|
|
3075
3119
|
}, (shipping == null ? void 0 : shipping.address) && (cartLocalFulfillment == null ? void 0 : cartLocalFulfillment.fields.fulfillmentMethod) !== 'pickup' ? {
|
|
3076
|
-
shippingAddress:
|
|
3077
|
-
|
|
3078
|
-
line1: (_shipping_address_line1 = shipping.address.line1) != null ? _shipping_address_line1 : undefined,
|
|
3079
|
-
line2: (_shipping_address_line2 = shipping.address.line2) != null ? _shipping_address_line2 : undefined,
|
|
3080
|
-
city: (_shipping_address_city = shipping.address.city) != null ? _shipping_address_city : undefined,
|
|
3081
|
-
state: (_shipping_address_state = shipping.address.state) != null ? _shipping_address_state : undefined,
|
|
3082
|
-
postalCode: (_shipping_address_postal_code = shipping.address.postal_code) != null ? _shipping_address_postal_code : undefined,
|
|
3083
|
-
country: (_shipping_address_country = shipping.address.country) != null ? _shipping_address_country : undefined
|
|
3084
|
-
}
|
|
3085
|
-
} : {}, (_ref5 = cartLocalFulfillment == null ? void 0 : cartLocalFulfillment.fields) != null ? _ref5 : {}, couponCode ? {
|
|
3120
|
+
shippingAddress: stripeOrderAddress(shipping == null ? void 0 : shipping.name, shipping.address)
|
|
3121
|
+
} : {}, (_ref4 = cartLocalFulfillment == null ? void 0 : cartLocalFulfillment.fields) != null ? _ref4 : {}, couponCode ? {
|
|
3086
3122
|
couponCode
|
|
3087
3123
|
} : {}, {
|
|
3088
|
-
amountCents: Number((
|
|
3089
|
-
feeCents: Number(feeCents != null ? feeCents : 0)
|
|
3124
|
+
amountCents: Number((_ref5 = object == null ? void 0 : object.amount_total) != null ? _ref5 : 0),
|
|
3125
|
+
feeCents: Number(feeCents != null ? feeCents : 0)
|
|
3126
|
+
}, cartHardware, {
|
|
3090
3127
|
createdAtMs: Date.now(),
|
|
3091
3128
|
createdAt: firebaseAdmin.firestore.FieldValue.serverTimestamp()
|
|
3092
3129
|
})));
|
|
@@ -3097,6 +3134,14 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3097
3134
|
// the non-idempotent effects below (inventory / coupon / gift-card
|
|
3098
3135
|
// decrements) that would otherwise double-apply.
|
|
3099
3136
|
if (!created) return;
|
|
3137
|
+
// Its hardware order, by the register's own recorder (AGL-4038). A
|
|
3138
|
+
// miss stays marked and the To attach sweep records it.
|
|
3139
|
+
if (cartHardware.hardwareSalePending) {
|
|
3140
|
+
await recordSellerStoreSaleHardware({
|
|
3141
|
+
hostId: String(hostId),
|
|
3142
|
+
orderId: String(object.id)
|
|
3143
|
+
});
|
|
3144
|
+
}
|
|
3100
3145
|
const cartOrderLabel = CommerceModel.formatOrderNumber({
|
|
3101
3146
|
number: cartOrderNumber
|
|
3102
3147
|
}, String(object.id));
|
|
@@ -3648,7 +3693,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3648
3693
|
// What the money was for, as the alert says it (AGL-4099).
|
|
3649
3694
|
let unmatchedNoun = 'quote';
|
|
3650
3695
|
const flipped = await firestore.runTransaction(async (transaction)=>{
|
|
3651
|
-
var _snapshot_data, _snapshot_data1, _snapshot_data2, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _lifted_totals, _ref6
|
|
3696
|
+
var _snapshot_data, _snapshot_data1, _snapshot_data2, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _lifted_totals, _ref6;
|
|
3652
3697
|
var _object_metadata, _object_customer_details, _object_metadata1, _object_customer_details1, _lifted_totals1;
|
|
3653
3698
|
const snapshot = await transaction.get(orderRef);
|
|
3654
3699
|
if (!snapshot.exists) return false;
|
|
@@ -3828,15 +3873,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3828
3873
|
totalCents: Number.isFinite(chargedTotalCents) ? chargedTotalCents : Number((_ref6 = (_lifted_totals1 = lifted.totals) == null ? void 0 : _lifted_totals1.totalCents) != null ? _ref6 : 0) + shippingCents
|
|
3829
3874
|
})
|
|
3830
3875
|
} : {}, (shipTo == null ? void 0 : shipTo.address) ? {
|
|
3831
|
-
shippingAddress:
|
|
3832
|
-
name: (_shipTo_name = shipTo.name) != null ? _shipTo_name : undefined,
|
|
3833
|
-
line1: (_shipTo_address_line1 = shipTo.address.line1) != null ? _shipTo_address_line1 : undefined,
|
|
3834
|
-
line2: (_shipTo_address_line2 = shipTo.address.line2) != null ? _shipTo_address_line2 : undefined,
|
|
3835
|
-
city: (_shipTo_address_city = shipTo.address.city) != null ? _shipTo_address_city : undefined,
|
|
3836
|
-
state: (_shipTo_address_state = shipTo.address.state) != null ? _shipTo_address_state : undefined,
|
|
3837
|
-
postalCode: (_shipTo_address_postal_code = shipTo.address.postal_code) != null ? _shipTo_address_postal_code : undefined,
|
|
3838
|
-
country: (_shipTo_address_country = shipTo.address.country) != null ? _shipTo_address_country : undefined
|
|
3839
|
-
}
|
|
3876
|
+
shippingAddress: stripeOrderAddress(shipTo.name, shipTo.address)
|
|
3840
3877
|
} : {}), {
|
|
3841
3878
|
merge: true
|
|
3842
3879
|
});
|
|
@@ -4151,8 +4188,30 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4151
4188
|
console.error('commerce buy-now local fulfillment unreadable', String(object.id), error);
|
|
4152
4189
|
return null;
|
|
4153
4190
|
});
|
|
4191
|
+
// Card reader hardware sold online by the platform's own store
|
|
4192
|
+
// (AGL-4038), as the cart branch marks it.
|
|
4193
|
+
const buyNowHardware = await sellerStoreOrderHardwareFields({
|
|
4194
|
+
hostId: String(hostId),
|
|
4195
|
+
lineItems: buyNowLineItems.map((line)=>_extends({}, line, {
|
|
4196
|
+
productId: String(productId)
|
|
4197
|
+
})),
|
|
4198
|
+
products: new Map([
|
|
4199
|
+
[
|
|
4200
|
+
String(productId),
|
|
4201
|
+
liftedForSnapshot
|
|
4202
|
+
]
|
|
4203
|
+
]),
|
|
4204
|
+
metadata: object == null ? void 0 : object.metadata,
|
|
4205
|
+
createdSeconds: object == null ? void 0 : object.created,
|
|
4206
|
+
orgIdOf: async ()=>{
|
|
4207
|
+
var _ref, _ref1;
|
|
4208
|
+
var _owner_org;
|
|
4209
|
+
const owner = await getOrgForHost(String(hostId));
|
|
4210
|
+
return (_ref = (_ref1 = owner == null ? void 0 : owner.orgId) != null ? _ref1 : owner == null ? void 0 : (_owner_org = owner.org) == null ? void 0 : _owner_org.id) != null ? _ref : null;
|
|
4211
|
+
}
|
|
4212
|
+
});
|
|
4154
4213
|
const created = await firestore.runTransaction(async (transaction)=>{
|
|
4155
|
-
var _counter_get, _ref, _ref1, _ref2,
|
|
4214
|
+
var _counter_get, _ref, _ref1, _ref2, _ref3, _ref4;
|
|
4156
4215
|
var _object_metadata, _object_customer_details, _object_shipping_details, _object_customer_details1;
|
|
4157
4216
|
const [existing, counter] = await Promise.all([
|
|
4158
4217
|
transaction.get(orderRef),
|
|
@@ -4193,15 +4252,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4193
4252
|
} : {}, {
|
|
4194
4253
|
customerName: (_ref2 = object == null ? void 0 : (_object_customer_details = object.customer_details) == null ? void 0 : _object_customer_details.name) != null ? _ref2 : null
|
|
4195
4254
|
}, (object == null ? void 0 : (_object_shipping_details = object.shipping_details) == null ? void 0 : _object_shipping_details.address) ? {
|
|
4196
|
-
shippingAddress:
|
|
4197
|
-
name: (_object_shipping_details_name = object.shipping_details.name) != null ? _object_shipping_details_name : undefined,
|
|
4198
|
-
line1: (_object_shipping_details_address_line1 = object.shipping_details.address.line1) != null ? _object_shipping_details_address_line1 : undefined,
|
|
4199
|
-
line2: (_object_shipping_details_address_line2 = object.shipping_details.address.line2) != null ? _object_shipping_details_address_line2 : undefined,
|
|
4200
|
-
city: (_object_shipping_details_address_city = object.shipping_details.address.city) != null ? _object_shipping_details_address_city : undefined,
|
|
4201
|
-
state: (_object_shipping_details_address_state = object.shipping_details.address.state) != null ? _object_shipping_details_address_state : undefined,
|
|
4202
|
-
postalCode: (_object_shipping_details_address_postal_code = object.shipping_details.address.postal_code) != null ? _object_shipping_details_address_postal_code : undefined,
|
|
4203
|
-
country: (_object_shipping_details_address_country = object.shipping_details.address.country) != null ? _object_shipping_details_address_country : undefined
|
|
4204
|
-
}
|
|
4255
|
+
shippingAddress: stripeOrderAddress(object.shipping_details.name, object.shipping_details.address)
|
|
4205
4256
|
} : {}, (_ref3 = buyNowLocalFulfillment == null ? void 0 : buyNowLocalFulfillment.fields) != null ? _ref3 : {}, {
|
|
4206
4257
|
createdAtMs: Date.now(),
|
|
4207
4258
|
// Legacy Commerce Starter fields (AGL-90).
|
|
@@ -4211,7 +4262,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4211
4262
|
customerEmail: (_ref4 = object == null ? void 0 : (_object_customer_details1 = object.customer_details) == null ? void 0 : _object_customer_details1.email) != null ? _ref4 : null
|
|
4212
4263
|
}, couponCode ? {
|
|
4213
4264
|
couponCode
|
|
4214
|
-
} : {}, {
|
|
4265
|
+
} : {}, buyNowHardware, {
|
|
4215
4266
|
createdAt: firebaseAdmin.firestore.FieldValue.serverTimestamp()
|
|
4216
4267
|
})));
|
|
4217
4268
|
return true;
|
|
@@ -4219,6 +4270,13 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4219
4270
|
// Redelivery guard (AGL-498): skip the notification + fulfilment side
|
|
4220
4271
|
// effects when this order already existed.
|
|
4221
4272
|
if (!created) return;
|
|
4273
|
+
// Its hardware order, by the register's own recorder (AGL-4038).
|
|
4274
|
+
if (buyNowHardware.hardwareSalePending) {
|
|
4275
|
+
await recordSellerStoreSaleHardware({
|
|
4276
|
+
hostId: String(hostId),
|
|
4277
|
+
orderId: String(object.id)
|
|
4278
|
+
});
|
|
4279
|
+
}
|
|
4222
4280
|
const buyNowOrderLabel = CommerceModel.formatOrderNumber({
|
|
4223
4281
|
number: buyNowOrderNumber
|
|
4224
4282
|
}, String(object.id));
|