@aglyn/plugins-commerce 1.14.0 → 1.15.1

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.
Files changed (214) hide show
  1. package/package.json +13 -13
  2. package/src/lib/components/account-subscriptions.d.ts +51 -0
  3. package/src/lib/components/account-subscriptions.js +168 -0
  4. package/src/lib/components/account-subscriptions.js.map +1 -0
  5. package/src/lib/components/account.js +12 -48
  6. package/src/lib/components/account.js.map +1 -1
  7. package/src/lib/components/cart.js +38 -9
  8. package/src/lib/components/cart.js.map +1 -1
  9. package/src/lib/components/commerce-console-page.js +6 -0
  10. package/src/lib/components/commerce-console-page.js.map +1 -1
  11. package/src/lib/components/commerce-console-sections.d.ts +1 -1
  12. package/src/lib/components/commerce-console-sections.js +5 -0
  13. package/src/lib/components/commerce-console-sections.js.map +1 -1
  14. package/src/lib/components/console/paid-media.d.ts +1 -0
  15. package/src/lib/components/console/paid-media.js +15 -4
  16. package/src/lib/components/console/paid-media.js.map +1 -1
  17. package/src/lib/components/console/payments-settings-card.component.js +1 -1
  18. package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
  19. package/src/lib/components/console/pos/pos-hardware-api.d.ts +10 -1
  20. package/src/lib/components/console/pos/pos-hardware-api.js.map +1 -1
  21. package/src/lib/components/console/pos/pos-hardware-buyer.component.js +2 -2
  22. package/src/lib/components/console/pos/pos-hardware-buyer.component.js.map +1 -1
  23. package/src/lib/components/console/pos/pos-hardware-sale-api.d.ts +2 -0
  24. package/src/lib/components/console/pos/pos-hardware-sale-api.js.map +1 -1
  25. package/src/lib/components/console/pos-cellular-control.component.d.ts +1 -1
  26. package/src/lib/components/console/pos-cellular-control.component.js +5 -5
  27. package/src/lib/components/console/pos-cellular-control.component.js.map +1 -1
  28. package/src/lib/components/console/pos-devices-card.component.js +2 -2
  29. package/src/lib/components/console/pos-devices-card.component.js.map +1 -1
  30. package/src/lib/components/console/pos-hardware-card.component.d.ts +5 -0
  31. package/src/lib/components/console/pos-hardware-card.component.js +77 -8
  32. package/src/lib/components/console/pos-hardware-card.component.js.map +1 -1
  33. package/src/lib/components/console/pos-hardware-orders-staff-page.component.js +137 -19
  34. package/src/lib/components/console/pos-hardware-orders-staff-page.component.js.map +1 -1
  35. package/src/lib/components/console/pos-page.component.js +19 -2
  36. package/src/lib/components/console/pos-page.component.js.map +1 -1
  37. package/src/lib/components/console/product-editor-dialog.component.js +21 -2
  38. package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
  39. package/src/lib/components/console/subscription-detail-dialog.component.d.ts +58 -0
  40. package/src/lib/components/console/subscription-detail-dialog.component.js +201 -0
  41. package/src/lib/components/console/subscription-detail-dialog.component.js.map +1 -0
  42. package/src/lib/components/console/subscriptions-card.component.d.ts +60 -0
  43. package/src/lib/components/console/subscriptions-card.component.js +282 -0
  44. package/src/lib/components/console/subscriptions-card.component.js.map +1 -0
  45. package/src/lib/components/hardware-terms-consent.d.ts +22 -0
  46. package/src/lib/components/hardware-terms-consent.js +85 -0
  47. package/src/lib/components/hardware-terms-consent.js.map +1 -0
  48. package/src/lib/components/product-detail.js +32 -8
  49. package/src/lib/components/product-detail.js.map +1 -1
  50. package/src/lib/components/quote-page-body.js +7 -3
  51. package/src/lib/components/quote-page-body.js.map +1 -1
  52. package/src/lib/components/related-products.js +6 -3
  53. package/src/lib/components/related-products.js.map +1 -1
  54. package/src/lib/components/storefront-payment-element.d.ts +7 -1
  55. package/src/lib/components/storefront-payment-element.js +11 -7
  56. package/src/lib/components/storefront-payment-element.js.map +1 -1
  57. package/src/lib/constants/operator-alerts.d.ts +1 -1
  58. package/src/lib/constants/operator-alerts.js +4 -4
  59. package/src/lib/constants/operator-alerts.js.map +1 -1
  60. package/src/lib/model/commerce-orders.d.ts +6 -2
  61. package/src/lib/model/commerce-orders.js.map +1 -1
  62. package/src/lib/model/commerce-payment-methods.d.ts +27 -16
  63. package/src/lib/model/commerce-payment-methods.js +11 -83
  64. package/src/lib/model/commerce-payment-methods.js.map +1 -1
  65. package/src/lib/model/commerce.d.ts +6 -0
  66. package/src/lib/model/commerce.js.map +1 -1
  67. package/src/lib/model/index.d.ts +1 -0
  68. package/src/lib/model/index.js +1 -0
  69. package/src/lib/model/index.js.map +1 -1
  70. package/src/lib/model/paid-media.d.ts +8 -0
  71. package/src/lib/model/paid-media.js +13 -0
  72. package/src/lib/model/paid-media.js.map +1 -1
  73. package/src/lib/model/pos-hardware-in-person.d.ts +23 -2
  74. package/src/lib/model/pos-hardware-in-person.js +52 -20
  75. package/src/lib/model/pos-hardware-in-person.js.map +1 -1
  76. package/src/lib/model/pos-hardware-tax-summary.d.ts +5 -1
  77. package/src/lib/model/pos-hardware-tax-summary.js +2 -1
  78. package/src/lib/model/pos-hardware-tax-summary.js.map +1 -1
  79. package/src/lib/model/pos-hardware-terms.d.ts +37 -2
  80. package/src/lib/model/pos-hardware-terms.js +68 -3
  81. package/src/lib/model/pos-hardware-terms.js.map +1 -1
  82. package/src/lib/model/pos-hardware.d.ts +101 -15
  83. package/src/lib/model/pos-hardware.js +128 -18
  84. package/src/lib/model/pos-hardware.js.map +1 -1
  85. package/src/lib/model/pos-reader-splash.js +2 -2
  86. package/src/lib/model/pos-reader-splash.js.map +1 -1
  87. package/src/lib/model/product-write.d.ts +3 -0
  88. package/src/lib/model/subscription-view.d.ts +90 -0
  89. package/src/lib/model/subscription-view.js +176 -0
  90. package/src/lib/model/subscription-view.js.map +1 -0
  91. package/src/lib/server/billing-webhook.d.ts +27 -6
  92. package/src/lib/server/billing-webhook.js +271 -81
  93. package/src/lib/server/billing-webhook.js.map +1 -1
  94. package/src/lib/server/cancel-order.js +4 -3
  95. package/src/lib/server/cancel-order.js.map +1 -1
  96. package/src/lib/server/cart-checkout.js +105 -23
  97. package/src/lib/server/cart-checkout.js.map +1 -1
  98. package/src/lib/server/cart.js +15 -3
  99. package/src/lib/server/cart.js.map +1 -1
  100. package/src/lib/server/catalog.js +58 -22
  101. package/src/lib/server/catalog.js.map +1 -1
  102. package/src/lib/server/checkout-session-expiry.d.ts +1 -1
  103. package/src/lib/server/checkout-session-expiry.js +19 -5
  104. package/src/lib/server/checkout-session-expiry.js.map +1 -1
  105. package/src/lib/server/checkout-status.js +4 -3
  106. package/src/lib/server/checkout-status.js.map +1 -1
  107. package/src/lib/server/checkout.js +98 -26
  108. package/src/lib/server/checkout.js.map +1 -1
  109. package/src/lib/server/connect.js +42 -11
  110. package/src/lib/server/connect.js.map +1 -1
  111. package/src/lib/server/draft-order.js +36 -7
  112. package/src/lib/server/draft-order.js.map +1 -1
  113. package/src/lib/server/manual-tax-rate.d.ts +11 -3
  114. package/src/lib/server/manual-tax-rate.js +10 -6
  115. package/src/lib/server/manual-tax-rate.js.map +1 -1
  116. package/src/lib/server/membership-account.d.ts +22 -0
  117. package/src/lib/server/membership-account.js +52 -8
  118. package/src/lib/server/membership-account.js.map +1 -1
  119. package/src/lib/server/native-checkout.d.ts +10 -3
  120. package/src/lib/server/native-checkout.js +8 -3
  121. package/src/lib/server/native-checkout.js.map +1 -1
  122. package/src/lib/server/payment-method-domains.d.ts +50 -9
  123. package/src/lib/server/payment-method-domains.js +150 -51
  124. package/src/lib/server/payment-method-domains.js.map +1 -1
  125. package/src/lib/server/payment-methods.js +3 -2
  126. package/src/lib/server/payment-methods.js.map +1 -1
  127. package/src/lib/server/pos-auth.d.ts +3 -3
  128. package/src/lib/server/pos-auth.js +3 -3
  129. package/src/lib/server/pos-auth.js.map +1 -1
  130. package/src/lib/server/pos-cellular-billing.js +1 -1
  131. package/src/lib/server/pos-cellular-billing.js.map +1 -1
  132. package/src/lib/server/pos-cellular-notify.js +1 -1
  133. package/src/lib/server/pos-cellular-notify.js.map +1 -1
  134. package/src/lib/server/pos-cellular.js +1 -1
  135. package/src/lib/server/pos-cellular.js.map +1 -1
  136. package/src/lib/server/pos-hardware-admin.js +86 -13
  137. package/src/lib/server/pos-hardware-admin.js.map +1 -1
  138. package/src/lib/server/pos-hardware-attach.js +5 -5
  139. package/src/lib/server/pos-hardware-attach.js.map +1 -1
  140. package/src/lib/server/pos-hardware-cancel.js +65 -0
  141. package/src/lib/server/pos-hardware-cancel.js.map +1 -1
  142. package/src/lib/server/pos-hardware-closure-notices.js +2 -5
  143. package/src/lib/server/pos-hardware-closure-notices.js.map +1 -1
  144. package/src/lib/server/pos-hardware-closure.js +5 -8
  145. package/src/lib/server/pos-hardware-closure.js.map +1 -1
  146. package/src/lib/server/pos-hardware-in-person.d.ts +2 -1
  147. package/src/lib/server/pos-hardware-in-person.js +72 -17
  148. package/src/lib/server/pos-hardware-in-person.js.map +1 -1
  149. package/src/lib/server/pos-hardware-notify.d.ts +2 -0
  150. package/src/lib/server/pos-hardware-notify.js +30 -5
  151. package/src/lib/server/pos-hardware-notify.js.map +1 -1
  152. package/src/lib/server/pos-hardware-readers.d.ts +25 -0
  153. package/src/lib/server/pos-hardware-readers.js +206 -85
  154. package/src/lib/server/pos-hardware-readers.js.map +1 -1
  155. package/src/lib/server/pos-hardware-returns.d.ts +8 -3
  156. package/src/lib/server/pos-hardware-returns.js +39 -7
  157. package/src/lib/server/pos-hardware-returns.js.map +1 -1
  158. package/src/lib/server/pos-hardware-sale-fields.d.ts +76 -0
  159. package/src/lib/server/pos-hardware-sale-fields.js +114 -1
  160. package/src/lib/server/pos-hardware-sale-fields.js.map +1 -1
  161. package/src/lib/server/pos-hardware-sale.d.ts +2 -0
  162. package/src/lib/server/pos-hardware-sale.js +1 -0
  163. package/src/lib/server/pos-hardware-sale.js.map +1 -1
  164. package/src/lib/server/pos-hardware-tax-return-source.js +7 -4
  165. package/src/lib/server/pos-hardware-tax-return-source.js.map +1 -1
  166. package/src/lib/server/pos-hardware-webhook.js +16 -3
  167. package/src/lib/server/pos-hardware-webhook.js.map +1 -1
  168. package/src/lib/server/pos-hardware.d.ts +14 -3
  169. package/src/lib/server/pos-hardware.js +83 -18
  170. package/src/lib/server/pos-hardware.js.map +1 -1
  171. package/src/lib/server/pos-ops-routes.js +2 -10
  172. package/src/lib/server/pos-ops-routes.js.map +1 -1
  173. package/src/lib/server/pos-order.js +5 -1
  174. package/src/lib/server/pos-order.js.map +1 -1
  175. package/src/lib/server/pos-stripe.d.ts +7 -7
  176. package/src/lib/server/pos-stripe.js +15 -13
  177. package/src/lib/server/pos-stripe.js.map +1 -1
  178. package/src/lib/server/pos-terminal.js +11 -3
  179. package/src/lib/server/pos-terminal.js.map +1 -1
  180. package/src/lib/server/quote-pay.d.ts +23 -1
  181. package/src/lib/server/quote-pay.js +111 -27
  182. package/src/lib/server/quote-pay.js.map +1 -1
  183. package/src/lib/server/quote.d.ts +2 -1
  184. package/src/lib/server/quote.js +12 -11
  185. package/src/lib/server/quote.js.map +1 -1
  186. package/src/lib/server/refund.js +13 -6
  187. package/src/lib/server/refund.js.map +1 -1
  188. package/src/lib/server/related.js +10 -3
  189. package/src/lib/server/related.js.map +1 -1
  190. package/src/lib/server/reserve.js +19 -6
  191. package/src/lib/server/reserve.js.map +1 -1
  192. package/src/lib/server/revenue-source.d.ts +6 -0
  193. package/src/lib/server/revenue-source.js +25 -9
  194. package/src/lib/server/revenue-source.js.map +1 -1
  195. package/src/lib/server/seller-stripe-account.d.ts +45 -0
  196. package/src/lib/server/seller-stripe-account.js +99 -0
  197. package/src/lib/server/seller-stripe-account.js.map +1 -0
  198. package/src/lib/server/storefront-tax-record.js +6 -1
  199. package/src/lib/server/storefront-tax-record.js.map +1 -1
  200. package/src/lib/server/storefront-tax.d.ts +33 -2
  201. package/src/lib/server/storefront-tax.js +39 -3
  202. package/src/lib/server/storefront-tax.js.map +1 -1
  203. package/src/lib/server/stream.d.ts +2 -0
  204. package/src/lib/server/stream.js +22 -2
  205. package/src/lib/server/stream.js.map +1 -1
  206. package/src/lib/server/stripe-refund.d.ts +15 -0
  207. package/src/lib/server/stripe-refund.js +54 -26
  208. package/src/lib/server/stripe-refund.js.map +1 -1
  209. package/src/lib/server/subscription-portal.js +8 -3
  210. package/src/lib/server/subscription-portal.js.map +1 -1
  211. package/src/lib/server/tax-return-source.js +5 -1
  212. package/src/lib/server/tax-return-source.js.map +1 -1
  213. package/src/lib/server.js +2 -2
  214. package/src/lib/server.js.map +1 -1
@@ -30,16 +30,30 @@
30
30
  * - `missing`: Stripe does not know it (another mode's id, or never created).
31
31
  * - `open`: it could not be closed and may still be paid. The caller treats
32
32
  * this as a failure to retry, never as closed.
33
- */ const SESSION_ID = /^cs_(test|live)_[A-Za-z0-9]{8,255}$/;
34
- export async function expireCheckoutSession(sessionId) {
35
- var _process_env_STRIPE_SECRET_KEY;
33
+ */ import { _ as _extends } from "@swc/helpers/_/_extends";
34
+ const SESSION_ID = /^cs_(test|live)_[A-Za-z0-9]{8,255}$/;
35
+ export async function expireCheckoutSession(sessionId, sellerAccount) {
36
36
  if (!SESSION_ID.test(String(sessionId != null ? sessionId : ''))) return 'missing';
37
+ // A direct-charge session lives on the seller's account. Asked there first,
38
+ // then on the platform, where a session opened before the seller switched
39
+ // (or Aglyn's own hardware sale) lives: left open, either is a second way
40
+ // to pay.
41
+ if (sellerAccount) {
42
+ const onSeller = await expireOn(sessionId, sellerAccount);
43
+ if (onSeller !== 'missing') return onSeller;
44
+ }
45
+ return expireOn(sessionId, null);
46
+ }
47
+ async function expireOn(sessionId, account) {
48
+ var _process_env_STRIPE_SECRET_KEY;
37
49
  const secretKey = String((_process_env_STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY) != null ? _process_env_STRIPE_SECRET_KEY : '').trim();
38
50
  if (!secretKey) return 'open';
39
- const headers = {
51
+ const headers = _extends({
40
52
  Authorization: `Bearer ${secretKey}`,
41
53
  'Content-Type': 'application/x-www-form-urlencoded'
42
- };
54
+ }, account ? {
55
+ 'Stripe-Account': account
56
+ } : {});
43
57
  try {
44
58
  const expired = await fetch(`https://api.stripe.com/v1/checkout/sessions/${sessionId}/expire`, {
45
59
  method: 'POST',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/checkout-session-expiry.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 * Closing a Checkout Session so it can no longer be paid, and saying what it\n * was (AGL-4094).\n *\n * Stripe answers 200 to `expire` for a session that was open, and 400 for one\n * that is not — already expired, or already PAID. Those two must not be read\n * alike: a caller about to open a fresh session for the same quote has to\n * know that the old one was paid a moment ago, or it hands the customer a\n * second way to pay. So a refused expiry reads the session back and answers\n * its status.\n *\n * - `expired`: it can no longer be paid (it was open and is now closed, or it\n * had expired already).\n * - `complete`: it was paid; the webhook has, or will, record it.\n * - `missing`: Stripe does not know it (another mode's id, or never created).\n * - `open`: it could not be closed and may still be paid. The caller treats\n * this as a failure to retry, never as closed.\n */\nexport type CheckoutSessionExpiry = 'expired' | 'complete' | 'missing' | 'open'\n\nconst SESSION_ID = /^cs_(test|live)_[A-Za-z0-9]{8,255}$/\n\nexport async function expireCheckoutSession(sessionId: string): Promise<CheckoutSessionExpiry> {\n if (!SESSION_ID.test(String(sessionId ?? ''))) return 'missing'\n const secretKey = String(process.env.STRIPE_SECRET_KEY ?? '').trim()\n if (!secretKey) return 'open'\n const headers = {\n Authorization: `Bearer ${secretKey}`,\n 'Content-Type': 'application/x-www-form-urlencoded',\n }\n try {\n const expired = await fetch(`https://api.stripe.com/v1/checkout/sessions/${sessionId}/expire`, {\n method: 'POST',\n headers,\n })\n if (expired.ok) return 'expired'\n const read = await fetch(`https://api.stripe.com/v1/checkout/sessions/${sessionId}`, { headers })\n if (read.status === 404) return 'missing'\n if (!read.ok) return 'open'\n const session = (await read.json().catch(() => ({}))) as { status?: string }\n if (session.status === 'complete') return 'complete'\n if (session.status === 'expired') return 'expired'\n return 'open'\n } catch {\n return 'open'\n }\n}\n"],"names":["SESSION_ID","expireCheckoutSession","sessionId","process","test","String","secretKey","env","STRIPE_SECRET_KEY","trim","headers","Authorization","expired","fetch","method","ok","read","status","session","json","catch"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;CAiBC,GAGD,MAAMA,aAAa;AAEnB,OAAO,eAAeC,sBAAsBC,SAAiB;QAElCC;IADzB,IAAI,CAACH,WAAWI,IAAI,CAACC,OAAOH,oBAAAA,YAAa,MAAM,OAAO;IACtD,MAAMI,YAAYD,QAAOF,iCAAAA,QAAQI,GAAG,CAACC,iBAAiB,YAA7BL,iCAAiC,IAAIM,IAAI;IAClE,IAAI,CAACH,WAAW,OAAO;IACvB,MAAMI,UAAU;QACdC,eAAe,CAAC,OAAO,EAAEL,WAAW;QACpC,gBAAgB;IAClB;IACA,IAAI;QACF,MAAMM,UAAU,MAAMC,MAAM,CAAC,4CAA4C,EAAEX,UAAU,OAAO,CAAC,EAAE;YAC7FY,QAAQ;YACRJ;QACF;QACA,IAAIE,QAAQG,EAAE,EAAE,OAAO;QACvB,MAAMC,OAAO,MAAMH,MAAM,CAAC,4CAA4C,EAAEX,WAAW,EAAE;YAAEQ;QAAQ;QAC/F,IAAIM,KAAKC,MAAM,KAAK,KAAK,OAAO;QAChC,IAAI,CAACD,KAAKD,EAAE,EAAE,OAAO;QACrB,MAAMG,UAAW,MAAMF,KAAKG,IAAI,GAAGC,KAAK,CAAC,IAAO,CAAA,CAAC,CAAA;QACjD,IAAIF,QAAQD,MAAM,KAAK,YAAY,OAAO;QAC1C,IAAIC,QAAQD,MAAM,KAAK,WAAW,OAAO;QACzC,OAAO;IACT,EAAE,eAAM;QACN,OAAO;IACT;AACF"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/checkout-session-expiry.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 * Closing a Checkout Session so it can no longer be paid, and saying what it\n * was (AGL-4094).\n *\n * Stripe answers 200 to `expire` for a session that was open, and 400 for one\n * that is not — already expired, or already PAID. Those two must not be read\n * alike: a caller about to open a fresh session for the same quote has to\n * know that the old one was paid a moment ago, or it hands the customer a\n * second way to pay. So a refused expiry reads the session back and answers\n * its status.\n *\n * - `expired`: it can no longer be paid (it was open and is now closed, or it\n * had expired already).\n * - `complete`: it was paid; the webhook has, or will, record it.\n * - `missing`: Stripe does not know it (another mode's id, or never created).\n * - `open`: it could not be closed and may still be paid. The caller treats\n * this as a failure to retry, never as closed.\n */\nexport type CheckoutSessionExpiry = 'expired' | 'complete' | 'missing' | 'open'\n\nconst SESSION_ID = /^cs_(test|live)_[A-Za-z0-9]{8,255}$/\n\nexport async function expireCheckoutSession(\n sessionId: string,\n sellerAccount?: string | null,\n): Promise<CheckoutSessionExpiry> {\n if (!SESSION_ID.test(String(sessionId ?? ''))) return 'missing'\n // A direct-charge session lives on the seller's account. Asked there first,\n // then on the platform, where a session opened before the seller switched\n // (or Aglyn's own hardware sale) lives: left open, either is a second way\n // to pay.\n if (sellerAccount) {\n const onSeller = await expireOn(sessionId, sellerAccount)\n if (onSeller !== 'missing') return onSeller\n }\n return expireOn(sessionId, null)\n}\n\nasync function expireOn(\n sessionId: string,\n account: string | null,\n): Promise<CheckoutSessionExpiry> {\n const secretKey = String(process.env.STRIPE_SECRET_KEY ?? '').trim()\n if (!secretKey) return 'open'\n const headers = {\n Authorization: `Bearer ${secretKey}`,\n 'Content-Type': 'application/x-www-form-urlencoded',\n ...(account ? { 'Stripe-Account': account } : {}),\n }\n try {\n const expired = await fetch(`https://api.stripe.com/v1/checkout/sessions/${sessionId}/expire`, {\n method: 'POST',\n headers,\n })\n if (expired.ok) return 'expired'\n const read = await fetch(`https://api.stripe.com/v1/checkout/sessions/${sessionId}`, { headers })\n if (read.status === 404) return 'missing'\n if (!read.ok) return 'open'\n const session = (await read.json().catch(() => ({}))) as { status?: string }\n if (session.status === 'complete') return 'complete'\n if (session.status === 'expired') return 'expired'\n return 'open'\n } catch {\n return 'open'\n }\n}\n"],"names":["SESSION_ID","expireCheckoutSession","sessionId","sellerAccount","test","String","onSeller","expireOn","account","process","secretKey","env","STRIPE_SECRET_KEY","trim","headers","Authorization","expired","fetch","method","ok","read","status","session","json","catch"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;CAiBC;AAGD,MAAMA,aAAa;AAEnB,OAAO,eAAeC,sBACpBC,SAAiB,EACjBC,aAA6B;IAE7B,IAAI,CAACH,WAAWI,IAAI,CAACC,OAAOH,oBAAAA,YAAa,MAAM,OAAO;IACtD,4EAA4E;IAC5E,0EAA0E;IAC1E,0EAA0E;IAC1E,UAAU;IACV,IAAIC,eAAe;QACjB,MAAMG,WAAW,MAAMC,SAASL,WAAWC;QAC3C,IAAIG,aAAa,WAAW,OAAOA;IACrC;IACA,OAAOC,SAASL,WAAW;AAC7B;AAEA,eAAeK,SACbL,SAAiB,EACjBM,OAAsB;QAEGC;IAAzB,MAAMC,YAAYL,QAAOI,iCAAAA,QAAQE,GAAG,CAACC,iBAAiB,YAA7BH,iCAAiC,IAAII,IAAI;IAClE,IAAI,CAACH,WAAW,OAAO;IACvB,MAAMI,UAAU;QACdC,eAAe,CAAC,OAAO,EAAEL,WAAW;QACpC,gBAAgB;OACZF,UAAU;QAAE,kBAAkBA;IAAQ,IAAI,CAAC;IAEjD,IAAI;QACF,MAAMQ,UAAU,MAAMC,MAAM,CAAC,4CAA4C,EAAEf,UAAU,OAAO,CAAC,EAAE;YAC7FgB,QAAQ;YACRJ;QACF;QACA,IAAIE,QAAQG,EAAE,EAAE,OAAO;QACvB,MAAMC,OAAO,MAAMH,MAAM,CAAC,4CAA4C,EAAEf,WAAW,EAAE;YAAEY;QAAQ;QAC/F,IAAIM,KAAKC,MAAM,KAAK,KAAK,OAAO;QAChC,IAAI,CAACD,KAAKD,EAAE,EAAE,OAAO;QACrB,MAAMG,UAAW,MAAMF,KAAKG,IAAI,GAAGC,KAAK,CAAC,IAAO,CAAA,CAAC,CAAA;QACjD,IAAIF,QAAQD,MAAM,KAAK,YAAY,OAAO;QAC1C,IAAIC,QAAQD,MAAM,KAAK,WAAW,OAAO;QACzC,OAAO;IACT,EAAE,eAAM;QACN,OAAO;IACT;AACF"}
@@ -13,7 +13,8 @@
13
13
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
- */ /**
16
+ */ import { directSellerAccountForHost, fetchOnSellerThenPlatform } from "./seller-stripe-account.js";
17
+ /**
17
18
  * What became of a storefront Checkout Session, for the page Stripe returned
18
19
  * the shopper to (AGL-3606).
19
20
  *
@@ -70,11 +71,11 @@ export const checkoutStatusHandler = async (req, res)=>{
70
71
  try {
71
72
  var _ref, _session_status, _session_payment_status;
72
73
  var _session_metadata;
73
- const response = await fetch(`https://api.stripe.com/v1/checkout/sessions/${sessionId}`, {
74
+ const response = await fetchOnSellerThenPlatform(`https://api.stripe.com/v1/checkout/sessions/${sessionId}`, {
74
75
  headers: {
75
76
  Authorization: `Bearer ${secretKey}`
76
77
  }
77
- });
78
+ }, await directSellerAccountForHost(hostId));
78
79
  if (!response.ok) {
79
80
  // A test-mode id under a live key (or the reverse) is a 404 at Stripe,
80
81
  // and so is an id that never existed. Both are "not ours".
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/checkout-status.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 type { PluginApiHandler } from '@aglyn/aglyn/server'\n\n/**\n * What became of a storefront Checkout Session, for the page Stripe returned\n * the shopper to (AGL-3606).\n *\n * ## Why the return page has to ask\n *\n * The in-page checkout sends every successful confirm to `return_url` — the\n * same `?order=success&session_id=…` the hosted redirect lands on. But a\n * redirect-based payment method (a bank redirect, a wallet that leaves the\n * page) comes back to that SAME url when the shopper abandons or fails the\n * bank step, with the session still open and nothing charged. The url alone\n * cannot tell the two apart, so a shopper whose bank step failed was shown a\n * store that said nothing at all, and had no reason to try again.\n *\n * ## What it answers, and what it never does\n *\n * Only the session's `status` and `payment_status`, and only for a session\n * this host created (`metadata[hostId]`, which both checkout routes set). No\n * email, no address, no amount, and no client secret: the session id rides a\n * url that lands in browser history and referrers, and must not become a key\n * to the shopper's details or to paying for their basket.\n *\n * It does not fulfil, and its answer fulfils nothing: the order is still\n * `checkout.session.completed` in `billing-webhook.ts`, and nothing here\n * writes anywhere.\n */\n\nconst SESSION_ID = /^cs_(test|live)_[A-Za-z0-9]{8,255}$/\n\nexport type CheckoutReturnStatus = 'open' | 'complete' | 'expired'\n\nexport const checkoutStatusHandler: PluginApiHandler = async (req, res) => {\n if (req.method && req.method !== 'GET') {\n res.setHeader('Allow', 'GET')\n return res.status(405).json({ error: 'Method not allowed' })\n }\n const hostId = String(req.query.hostId ?? '').trim()\n const sessionId = String(req.query.sessionId ?? '').trim()\n if (!hostId || !sessionId) {\n return res.status(400).json({ error: 'Missing hostId or sessionId' })\n }\n // Shape-checked before it is interpolated into a Stripe URL path.\n if (!SESSION_ID.test(sessionId)) {\n return res.status(400).json({ error: 'Invalid sessionId' })\n }\n const secretKey = String(process.env.STRIPE_SECRET_KEY ?? '').trim()\n if (!secretKey) {\n return res.status(501).json({ error: 'Payments are not configured' })\n }\n res.setHeader('Cache-Control', 'no-store')\n try {\n const response = await fetch(\n `https://api.stripe.com/v1/checkout/sessions/${sessionId}`,\n { headers: { Authorization: `Bearer ${secretKey}` } },\n )\n if (!response.ok) {\n // A test-mode id under a live key (or the reverse) is a 404 at Stripe,\n // and so is an id that never existed. Both are \"not ours\".\n return res.status(404).json({ error: 'Not found' })\n }\n const session = (await response.json()) as {\n status?: string\n payment_status?: string\n metadata?: Record<string, string>\n }\n // The same 404 as a missing session, so this route cannot be used to\n // learn that a session exists on ANOTHER merchant's storefront.\n if (String(session?.metadata?.hostId ?? '') !== hostId) {\n return res.status(404).json({ error: 'Not found' })\n }\n const status = String(session.status ?? '')\n if (status !== 'open' && status !== 'complete' && status !== 'expired') {\n return res.status(404).json({ error: 'Not found' })\n }\n return res.status(200).json({\n status: status as CheckoutReturnStatus,\n paymentStatus: String(session.payment_status ?? ''),\n })\n } catch (error) {\n console.error('checkout-status lookup failed', error)\n return res.status(502).json({ error: 'Lookup failed' })\n }\n}\n"],"names":["SESSION_ID","checkoutStatusHandler","req","res","process","method","setHeader","status","json","error","hostId","String","query","trim","sessionId","test","secretKey","env","STRIPE_SECRET_KEY","session","response","fetch","headers","Authorization","ok","metadata","paymentStatus","payment_status","console"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAID;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GAED,MAAMA,aAAa;AAInB,OAAO,MAAMC,wBAA0C,OAAOC,KAAKC;QAK3CD,mBACGA,sBAQAE;IAbzB,IAAIF,IAAIG,MAAM,IAAIH,IAAIG,MAAM,KAAK,OAAO;QACtCF,IAAIG,SAAS,CAAC,SAAS;QACvB,OAAOH,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEC,OAAO;QAAqB;IAC5D;IACA,MAAMC,SAASC,QAAOT,oBAAAA,IAAIU,KAAK,CAACF,MAAM,YAAhBR,oBAAoB,IAAIW,IAAI;IAClD,MAAMC,YAAYH,QAAOT,uBAAAA,IAAIU,KAAK,CAACE,SAAS,YAAnBZ,uBAAuB,IAAIW,IAAI;IACxD,IAAI,CAACH,UAAU,CAACI,WAAW;QACzB,OAAOX,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEC,OAAO;QAA8B;IACrE;IACA,kEAAkE;IAClE,IAAI,CAACT,WAAWe,IAAI,CAACD,YAAY;QAC/B,OAAOX,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEC,OAAO;QAAoB;IAC3D;IACA,MAAMO,YAAYL,QAAOP,iCAAAA,QAAQa,GAAG,CAACC,iBAAiB,YAA7Bd,iCAAiC,IAAIS,IAAI;IAClE,IAAI,CAACG,WAAW;QACd,OAAOb,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEC,OAAO;QAA8B;IACrE;IACAN,IAAIG,SAAS,CAAC,iBAAiB;IAC/B,IAAI;kBAoBoBa,iBAMEA;YATbA;QAhBX,MAAMC,WAAW,MAAMC,MACrB,CAAC,4CAA4C,EAAEP,WAAW,EAC1D;YAAEQ,SAAS;gBAAEC,eAAe,CAAC,OAAO,EAAEP,WAAW;YAAC;QAAE;QAEtD,IAAI,CAACI,SAASI,EAAE,EAAE;YAChB,uEAAuE;YACvE,2DAA2D;YAC3D,OAAOrB,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;gBAAEC,OAAO;YAAY;QACnD;QACA,MAAMU,UAAW,MAAMC,SAASZ,IAAI;QAKpC,qEAAqE;QACrE,gEAAgE;QAChE,IAAIG,eAAOQ,4BAAAA,oBAAAA,QAASM,QAAQ,qBAAjBN,kBAAmBT,MAAM,mBAAI,QAAQA,QAAQ;YACtD,OAAOP,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;gBAAEC,OAAO;YAAY;QACnD;QACA,MAAMF,SAASI,QAAOQ,kBAAAA,QAAQZ,MAAM,YAAdY,kBAAkB;QACxC,IAAIZ,WAAW,UAAUA,WAAW,cAAcA,WAAW,WAAW;YACtE,OAAOJ,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;gBAAEC,OAAO;YAAY;QACnD;QACA,OAAON,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;YAC1BD,QAAQA;YACRmB,eAAef,QAAOQ,0BAAAA,QAAQQ,cAAc,YAAtBR,0BAA0B;QAClD;IACF,EAAE,OAAOV,OAAO;QACdmB,QAAQnB,KAAK,CAAC,iCAAiCA;QAC/C,OAAON,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEC,OAAO;QAAgB;IACvD;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/checkout-status.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 { directSellerAccountForHost, fetchOnSellerThenPlatform } from './seller-stripe-account'\nimport type { PluginApiHandler } from '@aglyn/aglyn/server'\n\n/**\n * What became of a storefront Checkout Session, for the page Stripe returned\n * the shopper to (AGL-3606).\n *\n * ## Why the return page has to ask\n *\n * The in-page checkout sends every successful confirm to `return_url` — the\n * same `?order=success&session_id=…` the hosted redirect lands on. But a\n * redirect-based payment method (a bank redirect, a wallet that leaves the\n * page) comes back to that SAME url when the shopper abandons or fails the\n * bank step, with the session still open and nothing charged. The url alone\n * cannot tell the two apart, so a shopper whose bank step failed was shown a\n * store that said nothing at all, and had no reason to try again.\n *\n * ## What it answers, and what it never does\n *\n * Only the session's `status` and `payment_status`, and only for a session\n * this host created (`metadata[hostId]`, which both checkout routes set). No\n * email, no address, no amount, and no client secret: the session id rides a\n * url that lands in browser history and referrers, and must not become a key\n * to the shopper's details or to paying for their basket.\n *\n * It does not fulfil, and its answer fulfils nothing: the order is still\n * `checkout.session.completed` in `billing-webhook.ts`, and nothing here\n * writes anywhere.\n */\n\nconst SESSION_ID = /^cs_(test|live)_[A-Za-z0-9]{8,255}$/\n\nexport type CheckoutReturnStatus = 'open' | 'complete' | 'expired'\n\nexport const checkoutStatusHandler: PluginApiHandler = async (req, res) => {\n if (req.method && req.method !== 'GET') {\n res.setHeader('Allow', 'GET')\n return res.status(405).json({ error: 'Method not allowed' })\n }\n const hostId = String(req.query.hostId ?? '').trim()\n const sessionId = String(req.query.sessionId ?? '').trim()\n if (!hostId || !sessionId) {\n return res.status(400).json({ error: 'Missing hostId or sessionId' })\n }\n // Shape-checked before it is interpolated into a Stripe URL path.\n if (!SESSION_ID.test(sessionId)) {\n return res.status(400).json({ error: 'Invalid sessionId' })\n }\n const secretKey = String(process.env.STRIPE_SECRET_KEY ?? '').trim()\n if (!secretKey) {\n return res.status(501).json({ error: 'Payments are not configured' })\n }\n res.setHeader('Cache-Control', 'no-store')\n try {\n const response = await fetchOnSellerThenPlatform(\n `https://api.stripe.com/v1/checkout/sessions/${sessionId}`,\n { headers: { Authorization: `Bearer ${secretKey}` } },\n await directSellerAccountForHost(hostId),\n )\n if (!response.ok) {\n // A test-mode id under a live key (or the reverse) is a 404 at Stripe,\n // and so is an id that never existed. Both are \"not ours\".\n return res.status(404).json({ error: 'Not found' })\n }\n const session = (await response.json()) as {\n status?: string\n payment_status?: string\n metadata?: Record<string, string>\n }\n // The same 404 as a missing session, so this route cannot be used to\n // learn that a session exists on ANOTHER merchant's storefront.\n if (String(session?.metadata?.hostId ?? '') !== hostId) {\n return res.status(404).json({ error: 'Not found' })\n }\n const status = String(session.status ?? '')\n if (status !== 'open' && status !== 'complete' && status !== 'expired') {\n return res.status(404).json({ error: 'Not found' })\n }\n return res.status(200).json({\n status: status as CheckoutReturnStatus,\n paymentStatus: String(session.payment_status ?? ''),\n })\n } catch (error) {\n console.error('checkout-status lookup failed', error)\n return res.status(502).json({ error: 'Lookup failed' })\n }\n}\n"],"names":["directSellerAccountForHost","fetchOnSellerThenPlatform","SESSION_ID","checkoutStatusHandler","req","res","process","method","setHeader","status","json","error","hostId","String","query","trim","sessionId","test","secretKey","env","STRIPE_SECRET_KEY","session","response","headers","Authorization","ok","metadata","paymentStatus","payment_status","console"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,0BAA0B,EAAEC,yBAAyB,QAAQ,6BAAyB;AAG/F;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GAED,MAAMC,aAAa;AAInB,OAAO,MAAMC,wBAA0C,OAAOC,KAAKC;QAK3CD,mBACGA,sBAQAE;IAbzB,IAAIF,IAAIG,MAAM,IAAIH,IAAIG,MAAM,KAAK,OAAO;QACtCF,IAAIG,SAAS,CAAC,SAAS;QACvB,OAAOH,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEC,OAAO;QAAqB;IAC5D;IACA,MAAMC,SAASC,QAAOT,oBAAAA,IAAIU,KAAK,CAACF,MAAM,YAAhBR,oBAAoB,IAAIW,IAAI;IAClD,MAAMC,YAAYH,QAAOT,uBAAAA,IAAIU,KAAK,CAACE,SAAS,YAAnBZ,uBAAuB,IAAIW,IAAI;IACxD,IAAI,CAACH,UAAU,CAACI,WAAW;QACzB,OAAOX,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEC,OAAO;QAA8B;IACrE;IACA,kEAAkE;IAClE,IAAI,CAACT,WAAWe,IAAI,CAACD,YAAY;QAC/B,OAAOX,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEC,OAAO;QAAoB;IAC3D;IACA,MAAMO,YAAYL,QAAOP,iCAAAA,QAAQa,GAAG,CAACC,iBAAiB,YAA7Bd,iCAAiC,IAAIS,IAAI;IAClE,IAAI,CAACG,WAAW;QACd,OAAOb,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEC,OAAO;QAA8B;IACrE;IACAN,IAAIG,SAAS,CAAC,iBAAiB;IAC/B,IAAI;kBAqBoBa,iBAMEA;YATbA;QAjBX,MAAMC,WAAW,MAAMrB,0BACrB,CAAC,4CAA4C,EAAEe,WAAW,EAC1D;YAAEO,SAAS;gBAAEC,eAAe,CAAC,OAAO,EAAEN,WAAW;YAAC;QAAE,GACpD,MAAMlB,2BAA2BY;QAEnC,IAAI,CAACU,SAASG,EAAE,EAAE;YAChB,uEAAuE;YACvE,2DAA2D;YAC3D,OAAOpB,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;gBAAEC,OAAO;YAAY;QACnD;QACA,MAAMU,UAAW,MAAMC,SAASZ,IAAI;QAKpC,qEAAqE;QACrE,gEAAgE;QAChE,IAAIG,eAAOQ,4BAAAA,oBAAAA,QAASK,QAAQ,qBAAjBL,kBAAmBT,MAAM,mBAAI,QAAQA,QAAQ;YACtD,OAAOP,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;gBAAEC,OAAO;YAAY;QACnD;QACA,MAAMF,SAASI,QAAOQ,kBAAAA,QAAQZ,MAAM,YAAdY,kBAAkB;QACxC,IAAIZ,WAAW,UAAUA,WAAW,cAAcA,WAAW,WAAW;YACtE,OAAOJ,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;gBAAEC,OAAO;YAAY;QACnD;QACA,OAAON,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;YAC1BD,QAAQA;YACRkB,eAAed,QAAOQ,0BAAAA,QAAQO,cAAc,YAAtBP,0BAA0B;QAClD;IACF,EAAE,OAAOV,OAAO;QACdkB,QAAQlB,KAAK,CAAC,iCAAiCA;QAC/C,OAAON,IAAII,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEC,OAAO;QAAgB;IACvD;AACF,EAAC"}
@@ -1,4 +1,5 @@
1
1
  import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
2
3
  /**
3
4
  * @license
4
5
  * Copyright 2026 Aglyn LLC
@@ -21,11 +22,15 @@ import { planLabelGrantingFeature } from "@aglyn/aglyn/app-utils/plan-entitlemen
21
22
  import * as CommerceModel from "../model/index.js";
22
23
  import { claimAttempt, deriveStripeObjectKey } from "@aglyn/aglyn/server";
23
24
  import { firebaseAdmin, getOrgForHost } from "@aglyn/tenant-data-admin";
24
- import { merchantAccountIsReady } from "@aglyn/tenant-data-admin/server/payment-provider";
25
+ import { connectedAccountHeader, directChargeParams, merchantAccountIsReady, saleChargeModel } from "@aglyn/tenant-data-admin/server/payment-provider";
25
26
  import { checkoutSessionCardAuthenticationParams } from "@aglyn/tenant-data-admin/server/stripe-card-authentication";
26
27
  import { CARRIER_POSTAL_CODE_MESSAGE, planCheckoutShippingWithCarriers } from "./carrier-shipping.js";
27
28
  import { readActiveMemberSession } from "./membership.js";
28
29
  import { readStoreDay } from "./store-day.js";
30
+ import { readClientIp } from "@aglyn/aglyn/app-utils/request-ip";
31
+ import { POS_HARDWARE_TAX_CODE } from "../model/pos-hardware.js";
32
+ import { posHardwareTermsMetadata } from "../model/pos-hardware-terms.js";
33
+ import { sellerStoreHardwareCheckout } from "./pos-hardware-sale-fields.js";
29
34
  import { resolveManualTaxRateId } from "./manual-tax-rate.js";
30
35
  import { taxEngineSessionMetadata } from "../model/commerce-tax-engine.js";
31
36
  import { quoteSaleTaxWithEngine } from "./tax-engine-quote.js";
@@ -34,6 +39,7 @@ import { holdStock, stockHoldKey } from "./stock-hold.js";
34
39
  import { appendLocalFulfillmentMetadata, localFulfillmentLocationId, localStockRefusalMessage, planLocalFulfillment, readLocalFulfillmentRequest, readLocalFulfillmentStore } from "./local-fulfillment.js";
35
40
  import { applyNativeCheckoutParams, nativeCheckoutStripeHeaders, readCheckoutSessionPayload, resolveNativeCheckoutMode } from "./native-checkout.js";
36
41
  import { ensureCheckoutDomain } from "./payment-method-domains.js";
42
+ import { SELLER_STRIPE_TAX_NOT_SET_UP_MESSAGE, sellerStripeTaxActive } from "./seller-stripe-account.js";
37
43
  /**
38
44
  * Commerce Starter checkout (AGL-90): a site visitor buys a product. The
39
45
  * price ALWAYS comes from the host's product doc (never the request), the
@@ -125,8 +131,8 @@ export const checkoutHandler = async (req, res)=>{
125
131
  if (held) await held.release();
126
132
  };
127
133
  try {
128
- var _variant_priceUsd, _variant_options, _variant_options1, _req_headers_referer, _req_headers_host, _storeSettings_get, _lifted_type, _ref1, _ref2, _lifted_name, _ref3, _lifted_type1, _variant_weightGrams, _lifted_type2, _lifted_type3, _product_name, _ref4, _session_id;
129
- var _ownerOrg_org, _ownerOrg_org1, _ownerOrg_org2;
134
+ var _variant_priceUsd, _variant_options, _variant_options1, _ref1, _ref2, _readClientIp, _ref3, _req_headers_referer, _req_headers_host, _storeSettings_get, _lifted_type, _ref4, _ref5, _lifted_name, _ref6, _lifted_type1, _variant_weightGrams, _lifted_type2, _lifted_type3, _product_name, _ref7, _session_id;
135
+ var _ownerOrg_org, _ownerOrg_org1, _req_headers, _ownerOrg_org2, _ownerOrg_org3;
130
136
  const firestore = firebaseAdmin.app().firestore();
131
137
  const hostRef = firestore.collection('hosts').doc(hostId);
132
138
  const [hostSnapshot, productSnapshot] = await Promise.all([
@@ -211,14 +217,14 @@ export const checkoutHandler = async (req, res)=>{
211
217
  // that has not passed on the store's calendar. Refused before anything
212
218
  // is held, so a wrong day costs the buyer nothing.
213
219
  if (useDayKey) {
214
- var _ref5, _hostSnapshot_data;
220
+ var _ref8, _hostSnapshot_data;
215
221
  if (!CommerceModel.productAsksUseDate(lifted, variant.id)) {
216
222
  return res.status(400).json({
217
223
  error: 'This item has no day to choose.'
218
224
  });
219
225
  }
220
226
  const storeDay = await readStoreDay(hostRef, {
221
- org: (_ref5 = ownerOrg == null ? void 0 : ownerOrg.org) != null ? _ref5 : null,
227
+ org: (_ref8 = ownerOrg == null ? void 0 : ownerOrg.org) != null ? _ref8 : null,
222
228
  host: (_hostSnapshot_data = hostSnapshot.data()) != null ? _hostSnapshot_data : null
223
229
  });
224
230
  const problem = CommerceModel.checkInUseDayProblem(useDayKey, storeDay.todayKey);
@@ -256,6 +262,43 @@ export const checkoutHandler = async (req, res)=>{
256
262
  error: planRequiredMessage('Subscription products', 'storefrontSubscriptions')
257
263
  });
258
264
  }
265
+ // CARD READER HARDWARE ON THE PLATFORM'S OWN STORE (AGL-4038), as the
266
+ // cart reads it: the terms of sale and business use ticked, the online
267
+ // order limits held, never by subscription, taxed as goods, and the
268
+ // acceptance carried for the order. Before anything is held or claimed.
269
+ const hardware = sellerStoreHardwareCheckout({
270
+ hostId,
271
+ orgId: String((_ref1 = (_ref2 = ownerOrg == null ? void 0 : (_ownerOrg_org1 = ownerOrg.org) == null ? void 0 : _ownerOrg_org1.id) != null ? _ref2 : ownerOrg == null ? void 0 : ownerOrg.orgId) != null ? _ref1 : ''),
272
+ lines: [
273
+ {
274
+ productId: String(productId),
275
+ quantity
276
+ }
277
+ ],
278
+ products: new Map([
279
+ [
280
+ String(productId),
281
+ lifted
282
+ ]
283
+ ]),
284
+ hardwareTerms: body.hardwareTerms,
285
+ subscription: isSubscription
286
+ });
287
+ if (hardware.refusal) {
288
+ const _hardware_refusal = hardware.refusal, { status: refusedStatus } = _hardware_refusal, refusal = _object_without_properties_loose(_hardware_refusal, [
289
+ "status"
290
+ ]);
291
+ return res.status(refusedStatus).json(refusal);
292
+ }
293
+ const hardwareParams = hardware.hardware ? _extends({
294
+ 'line_items[0][price_data][product_data][tax_code]': POS_HARDWARE_TAX_CODE
295
+ }, Object.fromEntries(Object.entries(posHardwareTermsMetadata({
296
+ ip: (_readClientIp = readClientIp(req.headers)) != null ? _readClientIp : null,
297
+ userAgent: String((_ref3 = (_req_headers = req.headers) == null ? void 0 : _req_headers['user-agent']) != null ? _ref3 : '') || null
298
+ })).map(([key, value])=>[
299
+ `metadata[${key}]`,
300
+ value
301
+ ]))) : {};
259
302
  // ALREADY SUBSCRIBED? (AGL-1849)
260
303
  //
261
304
  // The idempotency key closes the RETRY shape: one attempt, one key, one
@@ -334,6 +377,14 @@ export const checkoutHandler = async (req, res)=>{
334
377
  error: 'This site has not enabled payments yet'
335
378
  });
336
379
  }
380
+ // WHO SELLS (direct charges). A seller on their own full Stripe account
381
+ // is the merchant of record: the session is created ON that account and
382
+ // Aglyn keeps its take as an application fee. Express accounts from
383
+ // before the switch stay destination charges, and so does Aglyn's own
384
+ // card-reader hardware, which Aglyn sells and taxes itself.
385
+ const chargeModel = hardware.hardware ? 'destination' : saleChargeModel(ownerProfile.get('stripeChargeModel'));
386
+ const direct = chargeModel === 'direct';
387
+ const sellerAccountHeader = connectedAccountHeader(chargeModel, accountId);
337
388
  // The list price per unit, before any coupon (AGL-1711). This is what the
338
389
  // order's line-item snapshot records, and it is carried in the session
339
390
  // metadata so the webhook never has to re-price from the product doc.
@@ -393,10 +444,10 @@ export const checkoutHandler = async (req, res)=>{
393
444
  // hub did not already answer for this code.
394
445
  let appliedCoupon = '';
395
446
  if (couponCode && !resolvedDiscount) {
396
- var _ref6;
447
+ var _ref9;
397
448
  const couponSnapshot = await hostRef.collection('coupons').doc(couponCode).get();
398
449
  const coupon = couponSnapshot.data();
399
- const percentOff = Number((_ref6 = coupon == null ? void 0 : coupon.percentOff) != null ? _ref6 : 0);
450
+ const percentOff = Number((_ref9 = coupon == null ? void 0 : coupon.percentOff) != null ? _ref9 : 0);
400
451
  const expired = (coupon == null ? void 0 : coupon.expiresAtMs) != null && Number(coupon.expiresAtMs) < Date.now();
401
452
  // A PRE-FILTER, no longer the enforcement (AGL-2453). It answers early so
402
453
  // an obviously spent code 400s before a claim is minted, and it counts
@@ -461,9 +512,9 @@ export const checkoutHandler = async (req, res)=>{
461
512
  hasPhysicalLine: true,
462
513
  store: await readLocalFulfillmentStore({
463
514
  hostRef,
464
- storeSettings: (_ref1 = storeSettings.data == null ? void 0 : storeSettings.data.call(storeSettings)) != null ? _ref1 : null,
515
+ storeSettings: (_ref4 = storeSettings.data == null ? void 0 : storeSettings.data.call(storeSettings)) != null ? _ref4 : null,
465
516
  org: ownerOrg.org,
466
- host: (_ref2 = hostSnapshot.data == null ? void 0 : hostSnapshot.data.call(hostSnapshot)) != null ? _ref2 : null
517
+ host: (_ref5 = hostSnapshot.data == null ? void 0 : hostSnapshot.data.call(hostSnapshot)) != null ? _ref5 : null
467
518
  })
468
519
  }) : {
469
520
  kind: 'shipping'
@@ -505,6 +556,13 @@ export const checkoutHandler = async (req, res)=>{
505
556
  });
506
557
  }
507
558
  const useStripeTax = taxDecision.kind === 'stripe-automatic';
559
+ // A direct-charge store's Stripe Tax runs on ITS account, against its
560
+ // registrations, and Stripe refuses the session where it is not set up.
561
+ if (direct && useStripeTax && !await sellerStripeTaxActive(String(accountId))) {
562
+ return res.status(409).json({
563
+ error: SELLER_STRIPE_TAX_NOT_SET_UP_MESSAGE
564
+ });
565
+ }
508
566
  let taxCents = 0;
509
567
  let taxLabel = '';
510
568
  let taxPct = 0;
@@ -582,7 +640,7 @@ export const checkoutHandler = async (req, res)=>{
582
640
  const claimed = await claimAttempt(firestore, {
583
641
  kind: 'commerce-checkout',
584
642
  scopeId: hostId,
585
- orgId: String((_ref3 = ownerOrg == null ? void 0 : (_ownerOrg_org1 = ownerOrg.org) == null ? void 0 : _ownerOrg_org1.id) != null ? _ref3 : ''),
643
+ orgId: String((_ref6 = ownerOrg == null ? void 0 : (_ownerOrg_org2 = ownerOrg.org) == null ? void 0 : _ownerOrg_org2.id) != null ? _ref6 : ''),
586
644
  key: idempotencyKey,
587
645
  busyMessage: 'This checkout is already being processed'
588
646
  });
@@ -693,13 +751,15 @@ export const checkoutHandler = async (req, res)=>{
693
751
  // paths quietly diverge. Behaviour here is unchanged.
694
752
  let recurringTaxRateId = '';
695
753
  if (isSubscription && taxCents > 0) {
696
- var _ref7;
697
- recurringTaxRateId = (_ref7 = await resolveManualTaxRateId({
754
+ var _ref10;
755
+ recurringTaxRateId = (_ref10 = await resolveManualTaxRateId(_extends({
698
756
  hostRef,
699
757
  taxPct,
700
758
  taxLabel,
701
759
  headers: stripeKeyHeader('tax-rate')
702
- })) != null ? _ref7 : '';
760
+ }, direct ? {
761
+ stripeAccount: String(accountId)
762
+ } : {}))) != null ? _ref10 : '';
703
763
  if (!recurringTaxRateId) {
704
764
  // Nothing was sold — hand the key back so the same button works
705
765
  // once Stripe does (AGL-1697).
@@ -792,10 +852,10 @@ export const checkoutHandler = async (req, res)=>{
792
852
  // The unnamed `Local pickup` rate gives way to the store's pickup
793
853
  // locations, which the shopper chooses before checkout (AGL-3624).
794
854
  if (localPlan.kind === 'shipping' && (shippingSettings == null ? void 0 : shippingSettings.localPickup) && shippingPlan.options.some((option)=>option.rateId === CommerceModel.LOCAL_PICKUP_RATE_ID)) {
795
- var _ref8;
855
+ var _ref11;
796
856
  const { pickupLocations } = await readLocalFulfillmentStore({
797
857
  hostRef,
798
- storeSettings: (_ref8 = storeSettings.data == null ? void 0 : storeSettings.data.call(storeSettings)) != null ? _ref8 : null,
858
+ storeSettings: (_ref11 = storeSettings.data == null ? void 0 : storeSettings.data.call(storeSettings)) != null ? _ref11 : null,
799
859
  host: null
800
860
  });
801
861
  if (pickupLocations.length) {
@@ -890,8 +950,14 @@ export const checkoutHandler = async (req, res)=>{
890
950
  // out on `subscription_data` further down, and `feeCents` here is what
891
951
  // that percent takes of the opening cycle's goods — the figure
892
952
  // `metadata[feeCents]` records as what Aglyn keeps.
893
- const subscriptionFeePercent = isSubscription ? Aglyn.resolveSubscriptionFeePercent(ownerOrg.org, (_lifted_type2 = lifted.type) != null ? _lifted_type2 : 'physical', amountCents) : 0;
894
- const feeCents = isSubscription ? subscriptionFeePercent > 0 ? Math.max(1, Math.round(amountCents * subscriptionFeePercent / 100)) : 0 : Aglyn.resolveTransactionFeeCents(ownerOrg.org, (_lifted_type3 = lifted.type) != null ? _lifted_type3 : 'physical', amountCents, amountCents + taxCents + shippingCeilingCents);
953
+ const subscriptionFeePercent = isSubscription ? Aglyn.resolveSubscriptionFeePercent(ownerOrg.org, (_lifted_type2 = lifted.type) != null ? _lifted_type2 : 'physical', amountCents, {
954
+ stripeTax: useStripeTax,
955
+ direct
956
+ }) : 0;
957
+ const feeCents = isSubscription ? subscriptionFeePercent > 0 ? Math.max(1, Math.round(amountCents * subscriptionFeePercent / 100)) : 0 : Aglyn.resolveTransactionFeeCents(ownerOrg.org, (_lifted_type3 = lifted.type) != null ? _lifted_type3 : 'physical', amountCents, amountCents + taxCents + shippingCeilingCents, {
958
+ stripeTax: useStripeTax,
959
+ direct
960
+ });
895
961
  // The unit price Stripe actually charges — the coupon is priced INTO it
896
962
  // rather than sent as a Stripe discount, which is why `amount_discount` is
897
963
  // 0 on every buy-now session and the discount has to ride the metadata
@@ -947,7 +1013,9 @@ export const checkoutHandler = async (req, res)=>{
947
1013
  'line_items[0][price_data][recurring][interval]': lifted.subscription.interval
948
1014
  }, lifted.subscription.trialDays ? {
949
1015
  'subscription_data[trial_period_days]': String(lifted.subscription.trialDays)
950
- } : {}, {
1016
+ } : {}, direct ? {
1017
+ 'subscription_data[metadata][chargeModel]': 'direct'
1018
+ } : {
951
1019
  'subscription_data[transfer_data][destination]': String(accountId)
952
1020
  }, subscriptionFeePercent > 0 ? {
953
1021
  'subscription_data[application_fee_percent]': String(subscriptionFeePercent)
@@ -967,7 +1035,9 @@ export const checkoutHandler = async (req, res)=>{
967
1035
  'line_items[0][tax_rates][0]': recurringTaxRateId
968
1036
  } : {}, useStripeTax ? {
969
1037
  'automatic_tax[enabled]': 'true'
970
- } : {}, !isSubscription ? CommerceModel.destinationChargeParams({
1038
+ } : {}, direct && !isSubscription ? directChargeParams(feeCents) : {}, direct ? {
1039
+ 'metadata[chargeModel]': 'direct'
1040
+ } : {}, !isSubscription && !direct ? CommerceModel.destinationChargeParams({
971
1041
  accountId: String(accountId),
972
1042
  feeCents,
973
1043
  taxOwner: useStripeTax ? 'platform' : 'merchant',
@@ -991,9 +1061,9 @@ export const checkoutHandler = async (req, res)=>{
991
1061
  } : {}, {
992
1062
  'metadata[quantity]': String(quantity),
993
1063
  'metadata[feeCents]': String(feeCents)
994
- }, shippingPlan.quotedPostalCode ? {
1064
+ }, hardwareParams, shippingPlan.quotedPostalCode ? {
995
1065
  'metadata[shippingQuotePostalCode]': shippingPlan.quotedPostalCode
996
- } : {}, useStripeTax && !isSubscription ? {
1066
+ } : {}, useStripeTax && !isSubscription && !direct ? {
997
1067
  'metadata[transferCents]': String(CommerceModel.platformLiableTransferCents({
998
1068
  feeCents,
999
1069
  merchantGoodsCents: amountCents,
@@ -1077,24 +1147,26 @@ export const checkoutHandler = async (req, res)=>{
1077
1147
  //
1078
1148
  // Off unless the flag is on for this org AND a publishable key exists, so
1079
1149
  // the default remains the redirect — see `resolveNativeCheckoutMode`.
1080
- const nativeMode = await resolveNativeCheckoutMode(String((_ref4 = ownerOrg == null ? void 0 : (_ownerOrg_org2 = ownerOrg.org) == null ? void 0 : _ownerOrg_org2.id) != null ? _ref4 : ''));
1150
+ const nativeMode = await resolveNativeCheckoutMode(String((_ref7 = ownerOrg == null ? void 0 : (_ownerOrg_org3 = ownerOrg.org) == null ? void 0 : _ownerOrg_org3.id) != null ? _ref7 : ''));
1081
1151
  if (nativeMode.native) {
1082
1152
  applyNativeCheckoutParams(params, `${backUrl}${separator}order=success&session_id={CHECKOUT_SESSION_ID}`);
1083
1153
  }
1084
1154
  // Apple Pay shows on a registered domain only (AGL-3629). Started beside
1085
1155
  // the session create rather than before it, inside a fixed budget, and
1086
1156
  // never throws: a sale does not wait on, or fail for, a registration.
1087
- const domainRegistration = nativeMode.native ? ensureCheckoutDomain({
1157
+ const domainRegistration = nativeMode.native ? ensureCheckoutDomain(_extends({
1088
1158
  pageUrl: backUrl,
1089
1159
  site: hostSnapshot.data == null ? void 0 : hostSnapshot.data.call(hostSnapshot),
1090
1160
  hostId
1091
- }).catch(()=>null) : Promise.resolve(null);
1161
+ }, direct ? {
1162
+ stripeAccount: String(accountId)
1163
+ } : {})).catch(()=>null) : Promise.resolve(null);
1092
1164
  const response = await fetch('https://api.stripe.com/v1/checkout/sessions', {
1093
1165
  method: 'POST',
1094
1166
  headers: _extends({
1095
1167
  Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}`,
1096
1168
  'Content-Type': 'application/x-www-form-urlencoded'
1097
- }, stripeKeyHeader(engineTax.stamp ? `session-tax-${taxCents}-${engineTax.stamp.status}` : 'session'), nativeCheckoutStripeHeaders(nativeMode)),
1169
+ }, stripeKeyHeader(engineTax.stamp ? `session-tax-${taxCents}-${engineTax.stamp.status}` : 'session'), nativeCheckoutStripeHeaders(nativeMode), sellerAccountHeader),
1098
1170
  body: params.toString()
1099
1171
  });
1100
1172
  const session = await response.json();
@@ -1102,7 +1174,7 @@ export const checkoutHandler = async (req, res)=>{
1102
1174
  // url — so the check moves with the mode rather than staying behind and
1103
1175
  // reading every successful native session as a Stripe failure (AGL-1944).
1104
1176
  await domainRegistration;
1105
- const payload = response.ok ? readCheckoutSessionPayload(session, nativeMode, paymentMethodControls.wallets) : null;
1177
+ const payload = response.ok ? readCheckoutSessionPayload(session, nativeMode, paymentMethodControls.wallets, direct ? String(accountId) : undefined) : null;
1106
1178
  if (!payload) {
1107
1179
  console.error('Stripe checkout error', session.error);
1108
1180
  // Nothing was sold — hand the key back so one flaky moment does not