@nextblock-cms/ecom 0.20.1 → 0.21.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.
Files changed (317) hide show
  1. package/_virtual/_rolldown/runtime.cjs.js +1 -0
  2. package/index.cjs.js +1 -1
  3. package/index.es.js +38 -146
  4. package/lib/CurrencyProvider.cjs.js +1 -1
  5. package/lib/CurrencyProvider.d.ts +1 -1
  6. package/lib/CurrencyProvider.es.js +85 -95
  7. package/lib/PaymentReadinessProvider.cjs.js +1 -1
  8. package/lib/PaymentReadinessProvider.d.ts +1 -1
  9. package/lib/PaymentReadinessProvider.es.js +24 -27
  10. package/lib/cart-store.cjs.js +1 -1
  11. package/lib/cart-store.es.js +109 -121
  12. package/lib/components/AccountNavigationMenu.cjs.js +1 -1
  13. package/lib/components/AccountNavigationMenu.d.ts +1 -1
  14. package/lib/components/AccountNavigationMenu.es.js +36 -50
  15. package/lib/components/AddToCartButton.cjs.js +1 -1
  16. package/lib/components/AddToCartButton.d.ts +1 -1
  17. package/lib/components/AddToCartButton.es.js +94 -89
  18. package/lib/components/Cart.cjs.js +1 -1
  19. package/lib/components/Cart.d.ts +1 -1
  20. package/lib/components/Cart.es.js +261 -180
  21. package/lib/components/CartDrawer.cjs.js +1 -1
  22. package/lib/components/CartDrawer.d.ts +1 -1
  23. package/lib/components/CartDrawer.es.js +218 -148
  24. package/lib/components/CartIcon.cjs.js +1 -1
  25. package/lib/components/CartIcon.d.ts +1 -1
  26. package/lib/components/CartIcon.es.js +33 -35
  27. package/lib/components/Checkout.cjs.js +1 -1
  28. package/lib/components/Checkout.d.ts +1 -1
  29. package/lib/components/Checkout.es.js +1092 -1108
  30. package/lib/components/CouponForm.cjs.js +1 -1
  31. package/lib/components/CouponForm.d.ts +1 -1
  32. package/lib/components/CouponForm.es.js +136 -148
  33. package/lib/components/CurrencySwitcher.cjs.js +1 -1
  34. package/lib/components/CurrencySwitcher.d.ts +1 -1
  35. package/lib/components/CurrencySwitcher.es.js +22 -18
  36. package/lib/components/CustomerProfileForm.cjs.js +1 -1
  37. package/lib/components/CustomerProfileForm.es.js +454 -313
  38. package/lib/components/FeaturedProduct.cjs.js +1 -1
  39. package/lib/components/FeaturedProduct.d.ts +1 -1
  40. package/lib/components/FeaturedProduct.es.js +98 -83
  41. package/lib/components/FreemiusLicensePanel.cjs.js +1 -1
  42. package/lib/components/FreemiusLicensePanel.d.ts +1 -1
  43. package/lib/components/FreemiusLicensePanel.es.js +70 -65
  44. package/lib/components/InvoiceDocument.cjs.js +1 -1
  45. package/lib/components/InvoiceDocument.es.js +256 -192
  46. package/lib/components/InvoiceViewerShell.cjs.js +2 -2
  47. package/lib/components/InvoiceViewerShell.d.ts +1 -1
  48. package/lib/components/InvoiceViewerShell.es.js +75 -106
  49. package/lib/components/ProductCard.cjs.js +1 -1
  50. package/lib/components/ProductCard.d.ts +1 -1
  51. package/lib/components/ProductCard.es.js +186 -171
  52. package/lib/components/ProductDetailsLayout.cjs.js +1 -1
  53. package/lib/components/ProductDetailsLayout.es.js +405 -404
  54. package/lib/components/ProductGallery.cjs.js +1 -1
  55. package/lib/components/ProductGallery.d.ts +1 -1
  56. package/lib/components/ProductGallery.es.js +51 -54
  57. package/lib/components/ProductGrid.cjs.js +1 -1
  58. package/lib/components/ProductGrid.d.ts +1 -1
  59. package/lib/components/ProductGrid.es.js +23 -25
  60. package/lib/components/ShippingEstimator.cjs.js +1 -1
  61. package/lib/components/ShippingEstimator.d.ts +1 -1
  62. package/lib/components/ShippingEstimator.es.js +158 -153
  63. package/lib/components/ShortDescription.cjs.js +1 -1
  64. package/lib/components/ShortDescription.es.js +17 -17
  65. package/lib/components/SimpleTiptapRenderer.cjs.js +1 -1
  66. package/lib/components/SimpleTiptapRenderer.es.js +238 -211
  67. package/lib/components/SubscriptionSelector.cjs.js +1 -1
  68. package/lib/components/SubscriptionSelector.es.js +159 -154
  69. package/lib/countries.cjs.js +1 -1
  70. package/lib/countries.es.js +232 -75
  71. package/lib/coupon-server.cjs.js +1 -1
  72. package/lib/coupon-server.es.js +180 -224
  73. package/lib/coupons.cjs.js +1 -1
  74. package/lib/coupons.es.js +12 -14
  75. package/lib/currency-constants.cjs.js +1 -1
  76. package/lib/currency-constants.es.js +4 -4
  77. package/lib/currency-rest-client.cjs.js +1 -1
  78. package/lib/currency-rest-client.es.js +15 -22
  79. package/lib/currency-store.cjs.js +1 -1
  80. package/lib/currency-store.es.js +20 -27
  81. package/lib/currency-sync.cjs.js +1 -1
  82. package/lib/currency-sync.es.js +124 -170
  83. package/lib/currency.cjs.js +1 -1
  84. package/lib/currency.es.js +242 -310
  85. package/lib/customer-addresses.cjs.js +1 -1
  86. package/lib/customer-addresses.es.js +80 -109
  87. package/lib/customer-orders.cjs.js +1 -1
  88. package/lib/customer-orders.es.js +31 -43
  89. package/lib/customer.cjs.js +1 -1
  90. package/lib/customer.es.js +43 -52
  91. package/lib/export-helpers.cjs.js +1 -1
  92. package/lib/export-helpers.es.js +53 -52
  93. package/lib/factory.cjs.js +1 -1
  94. package/lib/factory.es.js +10 -7
  95. package/lib/freemius-coupons.cjs.js +1 -1
  96. package/lib/freemius-coupons.es.js +245 -262
  97. package/lib/freemius-license-claim.cjs.js +1 -1
  98. package/lib/freemius-license-claim.es.js +87 -71
  99. package/lib/freemius-license.cjs.js +1 -1
  100. package/lib/freemius-license.es.js +32 -39
  101. package/lib/freemius-order-sync.cjs.js +1 -1
  102. package/lib/freemius-order-sync.es.js +226 -290
  103. package/lib/freemius-trial-provision.cjs.js +1 -1
  104. package/lib/freemius-trial-provision.es.js +136 -130
  105. package/lib/inventory-settings.cjs.js +1 -1
  106. package/lib/inventory-settings.es.js +69 -77
  107. package/lib/invoice-server.cjs.js +3 -3
  108. package/lib/invoice-server.es.js +94 -141
  109. package/lib/invoice-ui.cjs.js +1 -1
  110. package/lib/invoice-ui.es.js +50 -66
  111. package/lib/invoice.cjs.js +1 -1
  112. package/lib/invoice.es.js +85 -94
  113. package/lib/order-inventory.cjs.js +25 -25
  114. package/lib/order-inventory.es.js +67 -79
  115. package/lib/order-tax-details.cjs.js +1 -1
  116. package/lib/order-tax-details.es.js +142 -153
  117. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -1
  118. package/lib/pages/cms/coupons/CouponEditorForm.d.ts +1 -1
  119. package/lib/pages/cms/coupons/CouponEditorForm.es.js +227 -185
  120. package/lib/pages/cms/coupons/CouponsPage.cjs.js +2 -2
  121. package/lib/pages/cms/coupons/CouponsPage.d.ts +1 -1
  122. package/lib/pages/cms/coupons/CouponsPage.es.js +235 -166
  123. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -1
  124. package/lib/pages/cms/coupons/CreateCouponDialog.d.ts +1 -1
  125. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -34
  126. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -1
  127. package/lib/pages/cms/coupons/EditCouponPage.d.ts +1 -1
  128. package/lib/pages/cms/coupons/EditCouponPage.es.js +47 -47
  129. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -1
  130. package/lib/pages/cms/coupons/ProductScopePicker.d.ts +1 -1
  131. package/lib/pages/cms/coupons/ProductScopePicker.es.js +128 -117
  132. package/lib/pages/cms/coupons/actions.cjs.js +1 -1
  133. package/lib/pages/cms/coupons/actions.es.js +112 -115
  134. package/lib/pages/cms/coupons/index.cjs.js +1 -0
  135. package/lib/pages/cms/coupons/index.es.js +3 -0
  136. package/lib/pages/cms/coupons/product-options.cjs.js +1 -1
  137. package/lib/pages/cms/coupons/product-options.es.js +21 -23
  138. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -1
  139. package/lib/pages/cms/orders/ExportReportsDialog.es.js +135 -129
  140. package/lib/pages/cms/orders/MarkPaidButton.d.ts +1 -1
  141. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -1
  142. package/lib/pages/cms/orders/OrderDetailPage.d.ts +1 -1
  143. package/lib/pages/cms/orders/OrderDetailPage.es.js +186 -134
  144. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -1
  145. package/lib/pages/cms/orders/OrderPrintButton.d.ts +1 -1
  146. package/lib/pages/cms/orders/OrderPrintButton.es.js +15 -21
  147. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -1
  148. package/lib/pages/cms/orders/OrderStatusForm.d.ts +1 -1
  149. package/lib/pages/cms/orders/OrderStatusForm.es.js +85 -69
  150. package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -1
  151. package/lib/pages/cms/orders/OrdersPage.d.ts +1 -1
  152. package/lib/pages/cms/orders/OrdersPage.es.js +170 -102
  153. package/lib/pages/cms/orders/actions.cjs.js +3 -3
  154. package/lib/pages/cms/orders/actions.es.js +53 -69
  155. package/lib/pages/cms/orders/export-actions.cjs.js +1 -1
  156. package/lib/pages/cms/orders/export-actions.es.js +23 -26
  157. package/lib/pages/cms/orders/index.cjs.js +1 -0
  158. package/lib/pages/cms/orders/index.es.js +6 -0
  159. package/lib/pages/cms/orders/server-actions.cjs.js +1 -1
  160. package/lib/pages/cms/orders/server-actions.es.js +60 -51
  161. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -1
  162. package/lib/pages/cms/payments/PaymentsClient.d.ts +1 -1
  163. package/lib/pages/cms/payments/PaymentsClient.es.js +316 -346
  164. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -1
  165. package/lib/pages/cms/payments/PaymentsPage.d.ts +1 -1
  166. package/lib/pages/cms/payments/PaymentsPage.es.js +29 -32
  167. package/lib/pages/cms/payments/actions.cjs.js +1 -1
  168. package/lib/pages/cms/payments/actions.es.js +38 -48
  169. package/lib/pages/cms/payments/index.cjs.js +1 -0
  170. package/lib/pages/cms/payments/index.es.js +3 -0
  171. package/lib/pages/cms/payments/queries.cjs.js +1 -1
  172. package/lib/pages/cms/payments/queries.es.js +38 -48
  173. package/lib/pages/cms/products/ProductsPage.cjs.js +1 -1
  174. package/lib/pages/cms/products/ProductsPage.d.ts +1 -1
  175. package/lib/pages/cms/products/ProductsPage.es.js +63 -66
  176. package/lib/pages/cms/products/[id]/edit/EditProductPage.d.ts +1 -1
  177. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -1
  178. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +138 -155
  179. package/lib/pages/cms/products/actions.cjs.js +4 -4
  180. package/lib/pages/cms/products/actions.es.js +121 -162
  181. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -1
  182. package/lib/pages/cms/products/attributes/AttributeManagementPage.d.ts +1 -1
  183. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +55 -47
  184. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -1
  185. package/lib/pages/cms/products/attributes/components/AttributeManager.d.ts +1 -1
  186. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +285 -290
  187. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -1
  188. package/lib/pages/cms/products/categories/CategoryManagementPage.d.ts +1 -1
  189. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +43 -35
  190. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -1
  191. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +315 -262
  192. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -1
  193. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +115 -113
  194. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
  195. package/lib/pages/cms/products/components/CurrencyPriceFields.d.ts +1 -1
  196. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +136 -145
  197. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -1
  198. package/lib/pages/cms/products/components/DeleteProductButton.d.ts +1 -1
  199. package/lib/pages/cms/products/components/DeleteProductButton.es.js +35 -47
  200. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -1
  201. package/lib/pages/cms/products/components/FreemiusPricingDashboard.d.ts +1 -1
  202. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +106 -84
  203. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -1
  204. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +156 -159
  205. package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -1
  206. package/lib/pages/cms/products/components/ProductForm.es.js +872 -693
  207. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -1
  208. package/lib/pages/cms/products/components/ProductMediaManager.es.js +106 -103
  209. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -1
  210. package/lib/pages/cms/products/components/ProductsBulkTable.d.ts +1 -1
  211. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +303 -294
  212. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -1
  213. package/lib/pages/cms/products/components/SaleScheduleFields.d.ts +1 -1
  214. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +111 -134
  215. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -1
  216. package/lib/pages/cms/products/components/SyncFreemiusButton.d.ts +1 -1
  217. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +29 -35
  218. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +2 -2
  219. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.d.ts +1 -1
  220. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +36 -48
  221. package/lib/pages/cms/products/components/SyncProductForm.d.ts +1 -1
  222. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -1
  223. package/lib/pages/cms/products/components/VariationsEditor.d.ts +1 -1
  224. package/lib/pages/cms/products/components/VariationsEditor.es.js +396 -405
  225. package/lib/pages/cms/products/index.cjs.js +1 -0
  226. package/lib/pages/cms/products/index.es.js +8 -0
  227. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -1
  228. package/lib/pages/cms/products/inventory/InventoryPage.d.ts +1 -1
  229. package/lib/pages/cms/products/inventory/InventoryPage.es.js +21 -15
  230. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -2
  231. package/lib/pages/cms/products/inventory/InventoryTableClient.d.ts +1 -1
  232. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +230 -209
  233. package/lib/pages/cms/products/inventory/actions.cjs.js +3 -3
  234. package/lib/pages/cms/products/inventory/actions.es.js +83 -91
  235. package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -1
  236. package/lib/pages/cms/products/new/NewProductPage.d.ts +1 -1
  237. package/lib/pages/cms/products/new/NewProductPage.es.js +58 -74
  238. package/lib/pages/cms/products/product-price-sync.cjs.js +1 -1
  239. package/lib/pages/cms/products/product-price-sync.es.js +74 -89
  240. package/lib/pages/cms/products/server-actions.cjs.js +1 -1
  241. package/lib/pages/cms/products/server-actions.es.js +250 -233
  242. package/lib/pages/cms/shipping/ShippingPage.cjs.js +2 -2
  243. package/lib/pages/cms/shipping/ShippingPage.es.js +287 -209
  244. package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -1
  245. package/lib/pages/cms/shipping/components/RateForm.d.ts +1 -1
  246. package/lib/pages/cms/shipping/components/RateForm.es.js +439 -436
  247. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -1
  248. package/lib/pages/cms/shipping/components/ZoneForm.es.js +245 -224
  249. package/lib/pages/cms/shipping/index.cjs.js +1 -0
  250. package/lib/pages/cms/shipping/index.es.js +3 -0
  251. package/lib/pages/cms/shipping/server-actions.cjs.js +1 -1
  252. package/lib/pages/cms/shipping/server-actions.es.js +131 -149
  253. package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -1
  254. package/lib/pages/cms/taxes/TaxesPage.d.ts +1 -1
  255. package/lib/pages/cms/taxes/TaxesPage.es.js +211 -169
  256. package/lib/pages/cms/taxes/actions.cjs.js +1 -1
  257. package/lib/pages/cms/taxes/actions.es.js +41 -53
  258. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -1
  259. package/lib/pages/cms/taxes/components/TaxRateForm.d.ts +1 -1
  260. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +112 -99
  261. package/lib/pages/cms/taxes/index.cjs.js +1 -0
  262. package/lib/pages/cms/taxes/index.es.js +3 -0
  263. package/lib/payment-config.cjs.js +1 -1
  264. package/lib/payment-config.es.js +110 -126
  265. package/lib/product-actions.cjs.js +4 -4
  266. package/lib/product-actions.es.js +289 -544
  267. package/lib/product-context.cjs.js +1 -1
  268. package/lib/product-context.es.js +13 -15
  269. package/lib/product-schema.cjs.js +1 -1
  270. package/lib/product-schema.es.js +99 -134
  271. package/lib/providers/freemius.cjs.js +1 -5
  272. package/lib/providers/freemius.es.js +446 -530
  273. package/lib/providers/stripe.cjs.js +1 -1
  274. package/lib/providers/stripe.es.js +417 -477
  275. package/lib/server-actions/coupon-actions.cjs.js +1 -1
  276. package/lib/server-actions/coupon-actions.es.js +22 -22
  277. package/lib/server-actions/customer-actions.cjs.js +1 -1
  278. package/lib/server-actions/customer-actions.es.js +26 -28
  279. package/lib/server-actions/product-actions.cjs.js +1 -1
  280. package/lib/server-actions/product-actions.es.js +9 -15
  281. package/lib/server-actions/shipping-actions.cjs.js +1 -1
  282. package/lib/server-actions/shipping-actions.es.js +27 -24
  283. package/lib/server-actions/tax-actions.cjs.js +1 -1
  284. package/lib/server-actions/tax-actions.es.js +33 -39
  285. package/lib/shared-inventory.cjs.js +2 -2
  286. package/lib/shared-inventory.es.js +111 -160
  287. package/lib/shipping/resolver.cjs.js +2 -2
  288. package/lib/shipping/resolver.es.js +44 -61
  289. package/lib/shipping-rate-currency.cjs.js +1 -1
  290. package/lib/shipping-rate-currency.es.js +52 -67
  291. package/lib/states.cjs.js +1 -1
  292. package/lib/states.es.js +333 -154
  293. package/lib/stripe/checkout.cjs.js +1 -1
  294. package/lib/stripe/checkout.es.js +125 -181
  295. package/lib/stripe/client.cjs.js +1 -1
  296. package/lib/stripe/client.es.js +14 -19
  297. package/lib/stripe/order-sync.cjs.js +1 -1
  298. package/lib/stripe/order-sync.es.js +106 -126
  299. package/lib/stripe/webhooks.cjs.js +1 -1
  300. package/lib/stripe/webhooks.es.js +37 -31
  301. package/lib/tax-calculation.cjs.js +1 -1
  302. package/lib/tax-calculation.es.js +84 -98
  303. package/lib/trials.cjs.js +1 -1
  304. package/lib/trials.es.js +24 -30
  305. package/lib/types.cjs.js +1 -1
  306. package/lib/types.es.js +21 -27
  307. package/lib/use-cart.cjs.js +1 -1
  308. package/lib/use-cart.es.js +38 -40
  309. package/lib/use-price-formatter.cjs.js +1 -1
  310. package/lib/use-price-formatter.es.js +10 -11
  311. package/lib/variation-utils.cjs.js +1 -1
  312. package/lib/variation-utils.es.js +199 -261
  313. package/lib/zod-config.cjs.js +1 -1
  314. package/lib/zod-config.es.js +5 -6
  315. package/package.json +16 -16
  316. package/server.cjs.js +1 -1
  317. package/server.es.js +56 -211
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=require("../stripe/client.cjs.js"),xe=require("@supabase/supabase-js"),Pe=require("../countries.cjs.js"),be=require("../customer.cjs.js"),O=require("../coupon-server.cjs.js"),we=require("../coupons.cjs.js"),de=require("../customer-addresses.cjs.js"),w=require("../inventory-settings.cjs.js"),T=require("../tax-calculation.cjs.js"),v=require("../currency.cjs.js"),Te=require("../order-tax-details.cjs.js"),Ae=require("../types.cjs.js"),Ie=require("../variation-utils.cjs.js"),De=Pe.countries.map(t=>t.code),Me=new Set(["bg","cs","da","de","el","en","en-GB","es","es-419","et","fi","fil","fr","hr","hu","id","it","ja","ko","lt","lv","ms","mt","nb","nl","pl","pt","pt-BR","ro","ru","sk","sl","sv","th","tr","vi","zh","zh-HK","zh-TW"]);function pe(t){if(t)return{line1:t.line1||void 0,line2:t.line2||void 0,city:t.city||void 0,state:t.state||void 0,postal_code:t.postal_code||void 0,country:t.country_code||void 0}}function Ue(t){const i=t?.trim().replace("_","-");if(!i)return;const l=[i,i.toLowerCase(),i.split("-")[0].toLowerCase()];for(const d of l)if(Me.has(d))return d}function Le(t,i){return Ie.resolveTranslatedText(t.name,t.name_translations||null,i)}async function Fe(t){if(!t.email)return null;const i=await _e.getStripeClient(),l=pe(t.shippingAddress),d=t.shippingAddress?.recipient_name||t.billingAddress?.recipient_name||void 0,p={email:t.email,name:t.billingAddress?.recipient_name||t.shippingAddress?.recipient_name||void 0,phone:t.phone||void 0,address:pe(t.billingAddress),metadata:t.userId?{userId:t.userId}:void 0,...l&&d?{shipping:{name:d,phone:t.phone||void 0,address:l}}:{}};try{const _=(await i.customers.list({email:t.email,limit:1})).data[0];return _?(await i.customers.update(_.id,p),_.id):(await i.customers.create(p)).id}catch(u){return console.error("Failed to upsert Stripe customer for checkout prefill:",u),null}}class Re{getProviderName(){return"Stripe"}async createCheckoutSession({items:i,customerEmail:l,customerPhone:d,userId:p,billingAddress:u,shippingAddress:_,shippingMethodId:U,currencyCode:me,locale:B,couponCode:K,couponContextItems:L}){const he=await _e.getStripeClient(),z=process.env.NEXT_PUBLIC_SUPABASE_URL||process.env.SUPABASE_URL,Q=process.env.SUPABASE_SERVICE_ROLE_KEY||process.env.SUPABASE_SECRET_KEY;if(!z||!Q)return console.error("Missing Supabase credentials for checkout (Service Key required)."),{error:"Internal Server Error",url:null};const a=xe.createClient(z,Q),$=process.env.NEXT_PUBLIC_URL||"http://localhost:4200",X=i.some(e=>!Ae.isDigitalItem(e));if(!i.length)return{error:"Cart is empty",url:null};const{data:ve,error:H}=await a.from("currencies").select("code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount").eq("is_active",!0).order("code",{ascending:!0}),g=ve??[];if(H||g.length===0)return console.error("Error fetching currencies for checkout:",H),{error:"Failed to resolve store currencies",url:null};const j=v.getDefaultCurrency(g),m=g.find(e=>e.code===(me||"").toUpperCase())??j,F=m.code.toLowerCase(),G=await w.getEcommerceInventorySettings(a),fe=i.map(e=>e.product_id),V=i.map(e=>e.variant_id).filter(e=>!!e),{data:W,error:Y}=await a.from("products").select("id, title, sku, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, stock, is_taxable").in("id",fe);if(Y||!W)return console.error("Error fetching products for validation:",Y),{error:"Failed to validate product prices",url:null};const{data:ye,error:J}=V.length?await a.from("product_variants").select("id, product_id, sku, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, stock_quantity").in("id",V):{data:[],error:null};if(J)return console.error("Error fetching variants for validation:",J),{error:"Failed to validate product variants",url:null};const Z=new Map(W.map(e=>[e.id,e])),ee=new Map((ye||[]).map(e=>[e.id,e])),R=new Set,A=new Map;for(const e of i){const r=Z.get(e.product_id);if(!r)continue;const n=(e.variant_id?ee.get(e.variant_id):null)?.sku||r.sku;n&&(R.add(n),A.set(n,(A.get(n)??0)+e.quantity))}const{data:ge,error:re}=R.size?await a.from("inventory_items").select("sku, quantity").in("sku",[...R]):{data:[],error:null};if(re)return console.error("Error fetching SKU inventory for validation:",re),{error:"Failed to validate SKU inventory",url:null};const I=new Map((ge||[]).map(e=>[e.sku,Math.max(0,e.quantity??0)])),S=[],te=[],oe=[];let f=0,C=0,c=null;if(K){const e=await O.getCouponQuote({client:a,code:K,items:L&&L.length>0?L:i,currencyCode:m.code});if(!e.success)return{error:e.error,errorKey:e.errorKey,errorStatus:400,url:null};c=e.quote}const Se=O.getQuoteLineDiscountMap(c),Ce=e=>{const r=e.unitAmount*e.quantity,y=Math.max(0,r-e.lineDiscount);if(y<=0)return;const n=Math.floor(y/e.quantity),P=y-n*e.quantity,q=(b,x)=>{x<=0||b<=0||S.push({price_data:{currency:e.currency,product_data:{name:e.name,tax_code:T.getStripeTaxCodeForProduct(e.isTaxable),metadata:{productId:e.productId,variantId:e.variantId||""}},tax_behavior:"exclusive",unit_amount:b},quantity:x})};q(n,e.quantity-P),q(n+1,P)};for(const e of i){const r=Z.get(e.product_id);if(!r)return console.warn(`Product ${e.product_id} not found in DB.`),{url:null,...w.createInventoryUnavailableError(e.title)};const y=v.resolveEffectivePriceForCurrency({prices:v.normalizePriceMap(r.prices),salePrices:r.sale_prices||{},fallbackPrice:r.price,fallbackSalePrice:r.sale_price,saleStartAt:r.sale_start_at,saleEndAt:r.sale_end_at,scheduledPrice:r.scheduled_price,scheduledPrices:v.normalizePriceMap(r.scheduled_prices),scheduledPriceAt:r.scheduled_price_at,currencyCode:m.code,currencies:g});let n=y.sale_price??y.price,P=r.title,q=null;if(e.variant_id){const o=ee.get(e.variant_id);if(!o||o.product_id!==e.product_id)return{url:null,...w.createInventoryUnavailableError(e.title)};const M=A.get(o.sku)??e.quantity,ue=I.has(o.sku)?I.get(o.sku)??0:Math.max(0,o.stock_quantity??0);if(G.trackQuantities&&M>ue)return{url:null,...w.createInventoryInsufficientError(e.title,ue)};const le=v.resolveEffectivePriceForCurrency({prices:v.normalizePriceMap(o.prices),salePrices:o.sale_prices||{},fallbackPrice:o.price,fallbackSalePrice:o.sale_price,saleStartAt:o.sale_start_at,saleEndAt:o.sale_end_at,scheduledPrice:o.scheduled_price,scheduledPrices:v.normalizePriceMap(o.scheduled_prices),scheduledPriceAt:o.scheduled_price_at,currencyCode:m.code,currencies:g});n=le.sale_price??le.price,q=o.id,P=e.variant_label?`${r.title} - ${e.variant_label}`:`${r.title} - ${o.sku}`}else{const o=A.get(r.sku)??e.quantity,M=I.has(r.sku)?I.get(r.sku)??0:Math.max(0,r.stock??0);if(G.trackQuantities&&o>M)return{url:null,...w.createInventoryInsufficientError(e.title,M)}}const b=r.is_taxable??!0;if(n<0)return{error:"A product variation produced an invalid price.",url:null};const x=Math.min(n*e.quantity,Se.get(we.getCartLineCouponKey(e))??0);Ce({name:P,currency:F,productId:r.id,variantId:q,isTaxable:b,unitAmount:n,quantity:e.quantity,lineDiscount:x}),f+=n*e.quantity,C+=x,oe.push({product_id:r.id,quantity:e.quantity,price_at_purchase:n,variant_id:q}),te.push({product_id:r.id,quantity:e.quantity,unit_amount:n,discount_amount:x,is_taxable:b})}if(S.length===0&&C>=f)return{error:"This coupon would reduce the Stripe order to zero. Use a smaller discount for Stripe checkout.",errorKey:"ecommerce.coupon_zero_total_not_supported",errorStatus:400,url:null};if(S.length===0)return{error:"No valid items in cart",url:null};let h=0,N=null;if(U){const{data:e,error:r}=await a.from("shipping_zone_methods").select("id, name, name_translations, cost_amount, cost_currency").eq("id",U).single();if(r)return console.error("Failed to load shipping method:",r),{error:"Failed to load shipping method",url:null};h=v.convertMinorUnitAmount({amount:e.cost_amount??0,fromCurrencyCode:e.cost_currency||j.code,toCurrencyCode:m.code,currencies:g}),N=Le(e,B)}const ie=X?_??u:u;let s;try{s=await T.calculateCheckoutTaxes(a,{items:te,destination:{country_code:ie?.country_code,state:ie?.state}})}catch(e){return console.error("Failed to calculate checkout taxes:",e),{error:"Failed to calculate taxes",url:null}}h>0&&N&&S.push({price_data:{currency:F,product_data:{name:N,tax_code:s.enabled&&s.mode==="automatic"?T.STRIPE_TAX_CODE_SHIPPING:T.STRIPE_TAX_CODE_NONTAXABLE},tax_behavior:"exclusive",unit_amount:h},quantity:1});const E=s.enabled&&s.mode==="manual"&&!s.isPendingExternalCalculation?s.amount:0;E>0&&S.push({price_data:{currency:F,product_data:{name:"Tax",tax_code:T.STRIPE_TAX_CODE_NONTAXABLE},tax_behavior:"exclusive",unit_amount:E},quantity:1});const Ee=be.normalizeOrderCustomerDetails({email:l,phone:d,name:u?.recipient_name,billing:u,shipping:_}),ae=m.code,ke=Te.buildOrderTaxDetailsFromCalculation({calculation:s,subtotal:f,shippingTotal:h,total:Math.max(0,f-C)+h+E,currency:ae}),qe=Math.max(0,f-C)+h+E,{data:ne,error:ce}=await a.from("orders").insert({status:"pending",total:qe,currency:ae,exchange_rate_at_purchase:m.exchange_rate,subtotal:f,shipping_total:h,tax_total:E,tax_details:ke,coupon_id:c?.couponId??null,coupon_code:c?.code??null,discount_total:C,discount_details:c?{code:c.code,discount_type:c.discountType,discount_amount:c.discountAmount,provider:"stripe",provider_discounts:c.providerDiscounts,line_discounts:c.lineDiscounts}:null,provider:"stripe",user_id:p,customer_details:Ee}).select("id").single();if(ce||!ne)return console.error("Failed to create pending order:",ce),{error:"Failed to initiate order",url:null};const k=ne.id,{error:se}=await a.from("order_items").insert(oe.map(e=>({order_id:k,product_id:e.product_id,variant_id:e.variant_id??null,quantity:e.quantity,price_at_purchase:e.price_at_purchase})));if(se)return console.error("Failed to insert order items:",se),await a.from("orders").update({status:"failed"}).eq("id",k),{error:"Failed to record order items",url:null};if(p)try{await de.upsertDefaultUserAddresses({userId:p,billingAddress:u,shippingAddress:_,client:a}),await de.fillMissingUserProfileCheckoutDetails({userId:p,fullName:u?.recipient_name??_?.recipient_name??null,phone:d,client:a})}catch(e){console.error("Failed to sync checkout profile defaults before checkout:",e)}c&&await O.recordCouponRedemption({client:a,quote:c,orderId:k,provider:"stripe",discountTotal:C,userId:p,customerEmail:l,metadata:{currency:m.code,subtotal:f,shipping_total:h,tax_total:E}});const D=await Fe({email:l,phone:d,userId:p,billingAddress:u,shippingAddress:_});try{const e=await he.checkout.sessions.create({mode:"payment",success_url:`${$}/checkout/success?session_id={CHECKOUT_SESSION_ID}`,cancel_url:`${$}/checkout`,locale:Ue(B),line_items:S,automatic_tax:s.enabled&&s.mode==="automatic"?{enabled:!0}:void 0,billing_address_collection:"auto",customer:D||void 0,customer_email:D?void 0:l||void 0,customer_creation:D?void 0:"if_required",customer_update:D?{name:"auto",address:"auto",shipping:"auto"}:void 0,shipping_address_collection:X?{allowed_countries:De}:void 0,metadata:{orderId:k,taxMode:s.mode,currencyCode:m.code,couponCode:c?.code||""}}),{error:r}=await a.from("orders").update({stripe_session_id:e.id}).eq("id",k);return r&&console.error("Failed to save Stripe session ID on order:",r),{url:e.url}}catch(e){return console.error("Stripe session creation failed:",e),await a.from("orders").update({status:"failed"}).eq("id",k),e?.name==="StripeNotConfiguredError"||e?.type==="StripeAuthenticationError"?{error:"This store is not able to take payments right now. Please contact the seller to complete your purchase.",errorKey:"ecommerce.checkout_payments_unavailable",errorStatus:503,url:null}:{error:"Something went wrong while preparing your checkout. Please try again.",errorKey:"ecommerce.checkout_internal_server_error",url:null}}}}exports.StripeProvider=Re;
1
+ const e=require("../types.cjs.js"),t=require("../currency.cjs.js"),n=require("../coupons.cjs.js"),r=require("../coupon-server.cjs.js"),i=require("../countries.cjs.js"),a=require("../variation-utils.cjs.js"),o=require("../inventory-settings.cjs.js"),s=require("../tax-calculation.cjs.js"),c=require("../customer.cjs.js"),l=require("../customer-addresses.cjs.js"),u=require("../order-tax-details.cjs.js"),d=require("../stripe/client.cjs.js");let ee=require("@supabase/supabase-js");var te=i.countries.map(e=>e.code),f=new Set(`bg.cs.da.de.el.en.en-GB.es.es-419.et.fi.fil.fr.hr.hu.id.it.ja.ko.lt.lv.ms.mt.nb.nl.pl.pt.pt-BR.ro.ru.sk.sl.sv.th.tr.vi.zh.zh-HK.zh-TW`.split(`.`));function p(e){if(e)return{line1:e.line1||void 0,line2:e.line2||void 0,city:e.city||void 0,state:e.state||void 0,postal_code:e.postal_code||void 0,country:e.country_code||void 0}}function ne(e){let t=e?.trim().replace(`_`,`-`);if(!t)return;let n=[t,t.toLowerCase(),t.split(`-`)[0].toLowerCase()];for(let e of n)if(f.has(e))return e}function re(e,t){return a.resolveTranslatedText(e.name,e.name_translations||null,t)}async function ie(e){if(!e.email)return null;let t=await d.getStripeClient(),n=p(e.shippingAddress),r=e.shippingAddress?.recipient_name||e.billingAddress?.recipient_name||void 0,i={email:e.email,name:e.billingAddress?.recipient_name||e.shippingAddress?.recipient_name||void 0,phone:e.phone||void 0,address:p(e.billingAddress),metadata:e.userId?{userId:e.userId}:void 0,...n&&r?{shipping:{name:r,phone:e.phone||void 0,address:n}}:{}};try{let n=(await t.customers.list({email:e.email,limit:1})).data[0];return n?(await t.customers.update(n.id,i),n.id):(await t.customers.create(i)).id}catch(e){return console.error(`Failed to upsert Stripe customer for checkout prefill:`,e),null}}var m=class{getProviderName(){return`Stripe`}async createCheckoutSession({items:i,customerEmail:a,customerPhone:f,userId:p,billingAddress:m,shippingAddress:h,shippingMethodId:g,currencyCode:ae,locale:_,couponCode:v,couponContextItems:y}){let oe=await d.getStripeClient(),b=process.env.NEXT_PUBLIC_SUPABASE_URL||process.env.SUPABASE_URL,x=process.env.SUPABASE_SERVICE_ROLE_KEY||process.env.SUPABASE_SECRET_KEY;if(!b||!x)return console.error(`Missing Supabase credentials for checkout (Service Key required).`),{error:`Internal Server Error`,url:null};let S=(0,ee.createClient)(b,x),C=process.env.NEXT_PUBLIC_URL||`http://localhost:4200`,se=i.some(t=>!e.isDigitalItem(t));if(!i.length)return{error:`Cart is empty`,url:null};let{data:ce,error:le}=await S.from(`currencies`).select(`code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount`).eq(`is_active`,!0).order(`code`,{ascending:!0}),w=ce??[];if(le||w.length===0)return console.error(`Error fetching currencies for checkout:`,le),{error:`Failed to resolve store currencies`,url:null};let T=t.getDefaultCurrency(w),E=w.find(e=>e.code===(ae||``).toUpperCase())??T,D=E.code.toLowerCase(),O=await o.getEcommerceInventorySettings(S),ue=i.map(e=>e.product_id),k=i.map(e=>e.variant_id).filter(e=>!!e),{data:A,error:j}=await S.from(`products`).select(`id, title, sku, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, stock, is_taxable`).in(`id`,ue);if(j||!A)return console.error(`Error fetching products for validation:`,j),{error:`Failed to validate product prices`,url:null};let{data:de,error:M}=k.length?await S.from(`product_variants`).select(`id, product_id, sku, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, stock_quantity`).in(`id`,k):{data:[],error:null};if(M)return console.error(`Error fetching variants for validation:`,M),{error:`Failed to validate product variants`,url:null};let N=new Map(A.map(e=>[e.id,e])),P=new Map((de||[]).map(e=>[e.id,e])),F=new Set,I=new Map;for(let e of i){let t=N.get(e.product_id);if(!t)continue;let n=(e.variant_id?P.get(e.variant_id):null)?.sku||t.sku;n&&(F.add(n),I.set(n,(I.get(n)??0)+e.quantity))}let{data:fe,error:L}=F.size?await S.from(`inventory_items`).select(`sku, quantity`).in(`sku`,[...F]):{data:[],error:null};if(L)return console.error(`Error fetching SKU inventory for validation:`,L),{error:`Failed to validate SKU inventory`,url:null};let R=new Map((fe||[]).map(e=>[e.sku,Math.max(0,e.quantity??0)])),z=[],B=[],pe=[],V=0,H=0,U=null;if(v){let e=await r.getCouponQuote({client:S,code:v,items:y&&y.length>0?y:i,currencyCode:E.code});if(!e.success)return{error:e.error,errorKey:e.errorKey,errorStatus:400,url:null};U=e.quote}let me=r.getQuoteLineDiscountMap(U),he=e=>{let t=e.unitAmount*e.quantity,n=Math.max(0,t-e.lineDiscount);if(n<=0)return;let r=Math.floor(n/e.quantity),i=n-r*e.quantity,a=(t,n)=>{n<=0||t<=0||z.push({price_data:{currency:e.currency,product_data:{name:e.name,tax_code:s.getStripeTaxCodeForProduct(e.isTaxable),metadata:{productId:e.productId,variantId:e.variantId||``}},tax_behavior:`exclusive`,unit_amount:t},quantity:n})};a(r,e.quantity-i),a(r+1,i)};for(let e of i){let r=N.get(e.product_id);if(!r)return console.warn(`Product ${e.product_id} not found in DB.`),{url:null,...o.createInventoryUnavailableError(e.title)};let i=t.resolveEffectivePriceForCurrency({prices:t.normalizePriceMap(r.prices),salePrices:r.sale_prices||{},fallbackPrice:r.price,fallbackSalePrice:r.sale_price,saleStartAt:r.sale_start_at,saleEndAt:r.sale_end_at,scheduledPrice:r.scheduled_price,scheduledPrices:t.normalizePriceMap(r.scheduled_prices),scheduledPriceAt:r.scheduled_price_at,currencyCode:E.code,currencies:w}),a=i.sale_price??i.price,s=r.title,c=null;if(e.variant_id){let n=P.get(e.variant_id);if(!n||n.product_id!==e.product_id)return{url:null,...o.createInventoryUnavailableError(e.title)};let i=I.get(n.sku)??e.quantity,l=R.has(n.sku)?R.get(n.sku)??0:Math.max(0,n.stock_quantity??0);if(O.trackQuantities&&i>l)return{url:null,...o.createInventoryInsufficientError(e.title,l)};let u=t.resolveEffectivePriceForCurrency({prices:t.normalizePriceMap(n.prices),salePrices:n.sale_prices||{},fallbackPrice:n.price,fallbackSalePrice:n.sale_price,saleStartAt:n.sale_start_at,saleEndAt:n.sale_end_at,scheduledPrice:n.scheduled_price,scheduledPrices:t.normalizePriceMap(n.scheduled_prices),scheduledPriceAt:n.scheduled_price_at,currencyCode:E.code,currencies:w});a=u.sale_price??u.price,c=n.id,s=e.variant_label?`${r.title} - ${e.variant_label}`:`${r.title} - ${n.sku}`}else{let t=I.get(r.sku)??e.quantity,n=R.has(r.sku)?R.get(r.sku)??0:Math.max(0,r.stock??0);if(O.trackQuantities&&t>n)return{url:null,...o.createInventoryInsufficientError(e.title,n)}}let l=r.is_taxable??!0;if(a<0)return{error:`A product variation produced an invalid price.`,url:null};let u=Math.min(a*e.quantity,me.get(n.getCartLineCouponKey(e))??0);he({name:s,currency:D,productId:r.id,variantId:c,isTaxable:l,unitAmount:a,quantity:e.quantity,lineDiscount:u}),V+=a*e.quantity,H+=u,pe.push({product_id:r.id,quantity:e.quantity,price_at_purchase:a,variant_id:c}),B.push({product_id:r.id,quantity:e.quantity,unit_amount:a,discount_amount:u,is_taxable:l})}if(z.length===0&&H>=V)return{error:`This coupon would reduce the Stripe order to zero. Use a smaller discount for Stripe checkout.`,errorKey:`ecommerce.coupon_zero_total_not_supported`,errorStatus:400,url:null};if(z.length===0)return{error:`No valid items in cart`,url:null};let W=0,G=null;if(g){let{data:e,error:n}=await S.from(`shipping_zone_methods`).select(`id, name, name_translations, cost_amount, cost_currency`).eq(`id`,g).single();if(n)return console.error(`Failed to load shipping method:`,n),{error:`Failed to load shipping method`,url:null};W=t.convertMinorUnitAmount({amount:e.cost_amount??0,fromCurrencyCode:e.cost_currency||T.code,toCurrencyCode:E.code,currencies:w}),G=re(e,_)}let K=se?h??m:m,q;try{q=await s.calculateCheckoutTaxes(S,{items:B,destination:{country_code:K?.country_code,state:K?.state}})}catch(e){return console.error(`Failed to calculate checkout taxes:`,e),{error:`Failed to calculate taxes`,url:null}}W>0&&G&&z.push({price_data:{currency:D,product_data:{name:G,tax_code:q.enabled&&q.mode===`automatic`?s.STRIPE_TAX_CODE_SHIPPING:s.STRIPE_TAX_CODE_NONTAXABLE},tax_behavior:`exclusive`,unit_amount:W},quantity:1});let J=q.enabled&&q.mode===`manual`&&!q.isPendingExternalCalculation?q.amount:0;J>0&&z.push({price_data:{currency:D,product_data:{name:`Tax`,tax_code:s.STRIPE_TAX_CODE_NONTAXABLE},tax_behavior:`exclusive`,unit_amount:J},quantity:1});let ge=c.normalizeOrderCustomerDetails({email:a,phone:f,name:m?.recipient_name,billing:m,shipping:h}),Y=E.code,_e=u.buildOrderTaxDetailsFromCalculation({calculation:q,subtotal:V,shippingTotal:W,total:Math.max(0,V-H)+W+J,currency:Y}),ve=Math.max(0,V-H)+W+J,{data:X,error:Z}=await S.from(`orders`).insert({status:`pending`,total:ve,currency:Y,exchange_rate_at_purchase:E.exchange_rate,subtotal:V,shipping_total:W,tax_total:J,tax_details:_e,coupon_id:U?.couponId??null,coupon_code:U?.code??null,discount_total:H,discount_details:U?{code:U.code,discount_type:U.discountType,discount_amount:U.discountAmount,provider:`stripe`,provider_discounts:U.providerDiscounts,line_discounts:U.lineDiscounts}:null,provider:`stripe`,user_id:p,customer_details:ge}).select(`id`).single();if(Z||!X)return console.error(`Failed to create pending order:`,Z),{error:`Failed to initiate order`,url:null};let Q=X.id,{error:ye}=await S.from(`order_items`).insert(pe.map(e=>({order_id:Q,product_id:e.product_id,variant_id:e.variant_id??null,quantity:e.quantity,price_at_purchase:e.price_at_purchase})));if(ye)return console.error(`Failed to insert order items:`,ye),await S.from(`orders`).update({status:`failed`}).eq(`id`,Q),{error:`Failed to record order items`,url:null};if(p)try{await l.upsertDefaultUserAddresses({userId:p,billingAddress:m,shippingAddress:h,client:S}),await l.fillMissingUserProfileCheckoutDetails({userId:p,fullName:m?.recipient_name??h?.recipient_name??null,phone:f,client:S})}catch(e){console.error(`Failed to sync checkout profile defaults before checkout:`,e)}U&&await r.recordCouponRedemption({client:S,quote:U,orderId:Q,provider:`stripe`,discountTotal:H,userId:p,customerEmail:a,metadata:{currency:E.code,subtotal:V,shipping_total:W,tax_total:J}});let $=await ie({email:a,phone:f,userId:p,billingAddress:m,shippingAddress:h});try{let e=await oe.checkout.sessions.create({mode:`payment`,success_url:`${C}/checkout/success?session_id={CHECKOUT_SESSION_ID}`,cancel_url:`${C}/checkout`,locale:ne(_),line_items:z,automatic_tax:q.enabled&&q.mode===`automatic`?{enabled:!0}:void 0,billing_address_collection:`auto`,customer:$||void 0,customer_email:$?void 0:a||void 0,customer_creation:$?void 0:`if_required`,customer_update:$?{name:`auto`,address:`auto`,shipping:`auto`}:void 0,shipping_address_collection:se?{allowed_countries:te}:void 0,metadata:{orderId:Q,taxMode:q.mode,currencyCode:E.code,couponCode:U?.code||``}}),{error:t}=await S.from(`orders`).update({stripe_session_id:e.id}).eq(`id`,Q);return t&&console.error(`Failed to save Stripe session ID on order:`,t),{url:e.url}}catch(e){return console.error(`Stripe session creation failed:`,e),await S.from(`orders`).update({status:`failed`}).eq(`id`,Q),e?.name===`StripeNotConfiguredError`||e?.type===`StripeAuthenticationError`?{error:`This store is not able to take payments right now. Please contact the seller to complete your purchase.`,errorKey:`ecommerce.checkout_payments_unavailable`,errorStatus:503,url:null}:{error:`Something went wrong while preparing your checkout. Please try again.`,errorKey:`ecommerce.checkout_internal_server_error`,url:null}}}};exports.StripeProvider=m;