@nextblock-cms/ecom 0.20.3 → 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,482 +1,422 @@
1
- import { getStripeClient as _e } from "../stripe/client.es.js";
2
- import { createClient as we } from "@supabase/supabase-js";
3
- import { countries as Pe } from "../countries.es.js";
4
- import { normalizeOrderCustomerDetails as be } from "../customer.es.js";
5
- import { getCouponQuote as qe, getQuoteLineDiscountMap as Te, recordCouponRedemption as Ae } from "../coupon-server.es.js";
6
- import { getCartLineCouponKey as Ie } from "../coupons.es.js";
7
- import { upsertDefaultUserAddresses as De, fillMissingUserProfileCheckoutDetails as Ue } from "../customer-addresses.es.js";
8
- import { getEcommerceInventorySettings as Le, createInventoryUnavailableError as se, createInventoryInsufficientError as ue } from "../inventory-settings.es.js";
9
- import { calculateCheckoutTaxes as Me, STRIPE_TAX_CODE_SHIPPING as Fe, STRIPE_TAX_CODE_NONTAXABLE as le, getStripeTaxCodeForProduct as Re } from "../tax-calculation.es.js";
10
- import { getDefaultCurrency as Ne, resolveEffectivePriceForCurrency as de, normalizePriceMap as I, convertMinorUnitAmount as Ke } from "../currency.es.js";
11
- import { buildOrderTaxDetailsFromCalculation as Be } from "../order-tax-details.es.js";
12
- import { isDigitalItem as Oe } from "../types.es.js";
13
- import { resolveTranslatedText as Qe } from "../variation-utils.es.js";
14
- const ze = Pe.map((r) => r.code), $e = /* @__PURE__ */ new Set([
15
- "bg",
16
- "cs",
17
- "da",
18
- "de",
19
- "el",
20
- "en",
21
- "en-GB",
22
- "es",
23
- "es-419",
24
- "et",
25
- "fi",
26
- "fil",
27
- "fr",
28
- "hr",
29
- "hu",
30
- "id",
31
- "it",
32
- "ja",
33
- "ko",
34
- "lt",
35
- "lv",
36
- "ms",
37
- "mt",
38
- "nb",
39
- "nl",
40
- "pl",
41
- "pt",
42
- "pt-BR",
43
- "ro",
44
- "ru",
45
- "sk",
46
- "sl",
47
- "sv",
48
- "th",
49
- "tr",
50
- "vi",
51
- "zh",
52
- "zh-HK",
53
- "zh-TW"
54
- ]);
55
- function pe(r) {
56
- if (r)
57
- return {
58
- line1: r.line1 || void 0,
59
- line2: r.line2 || void 0,
60
- city: r.city || void 0,
61
- state: r.state || void 0,
62
- postal_code: r.postal_code || void 0,
63
- country: r.country_code || void 0
64
- };
1
+ import { isDigitalItem as e } from "../types.es.js";
2
+ import { convertMinorUnitAmount as t, getDefaultCurrency as n, normalizePriceMap as r, resolveEffectivePriceForCurrency as i } from "../currency.es.js";
3
+ import { getCartLineCouponKey as a } from "../coupons.es.js";
4
+ import { getCouponQuote as o, getQuoteLineDiscountMap as s, recordCouponRedemption as c } from "../coupon-server.es.js";
5
+ import { countries as l } from "../countries.es.js";
6
+ import { resolveTranslatedText as u } from "../variation-utils.es.js";
7
+ import { createInventoryInsufficientError as d, createInventoryUnavailableError as f, getEcommerceInventorySettings as ee } from "../inventory-settings.es.js";
8
+ import { STRIPE_TAX_CODE_NONTAXABLE as p, STRIPE_TAX_CODE_SHIPPING as te, calculateCheckoutTaxes as ne, getStripeTaxCodeForProduct as re } from "../tax-calculation.es.js";
9
+ import { normalizeOrderCustomerDetails as ie } from "../customer.es.js";
10
+ import { fillMissingUserProfileCheckoutDetails as ae, upsertDefaultUserAddresses as oe } from "../customer-addresses.es.js";
11
+ import { buildOrderTaxDetailsFromCalculation as se } from "../order-tax-details.es.js";
12
+ import { getStripeClient as m } from "../stripe/client.es.js";
13
+ import { createClient as ce } from "@supabase/supabase-js";
14
+ //#region libs/ecommerce/src/lib/providers/stripe.ts
15
+ var le = l.map((e) => e.code), h = /* @__PURE__ */ new Set(/* @__PURE__ */ "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("."));
16
+ function g(e) {
17
+ if (e) return {
18
+ line1: e.line1 || void 0,
19
+ line2: e.line2 || void 0,
20
+ city: e.city || void 0,
21
+ state: e.state || void 0,
22
+ postal_code: e.postal_code || void 0,
23
+ country: e.country_code || void 0
24
+ };
65
25
  }
66
- function Xe(r) {
67
- const i = r?.trim().replace("_", "-");
68
- if (!i)
69
- return;
70
- const l = [i, i.toLowerCase(), i.split("-")[0].toLowerCase()];
71
- for (const d of l)
72
- if ($e.has(d))
73
- return d;
26
+ function ue(e) {
27
+ let t = e?.trim().replace("_", "-");
28
+ if (!t) return;
29
+ let n = [
30
+ t,
31
+ t.toLowerCase(),
32
+ t.split("-")[0].toLowerCase()
33
+ ];
34
+ for (let e of n) if (h.has(e)) return e;
74
35
  }
75
- function He(r, i) {
76
- return Qe(
77
- r.name,
78
- r.name_translations || null,
79
- i
80
- );
36
+ function de(e, t) {
37
+ return u(e.name, e.name_translations || null, t);
81
38
  }
82
- async function Ge(r) {
83
- if (!r.email)
84
- return null;
85
- const i = await _e(), l = pe(r.shippingAddress), d = r.shippingAddress?.recipient_name || r.billingAddress?.recipient_name || void 0, p = {
86
- email: r.email,
87
- name: r.billingAddress?.recipient_name || r.shippingAddress?.recipient_name || void 0,
88
- phone: r.phone || void 0,
89
- address: pe(r.billingAddress),
90
- metadata: r.userId ? { userId: r.userId } : void 0,
91
- ...l && d ? {
92
- shipping: {
93
- name: d,
94
- phone: r.phone || void 0,
95
- address: l
96
- }
97
- } : {}
98
- };
99
- try {
100
- const _ = (await i.customers.list({
101
- email: r.email,
102
- limit: 1
103
- })).data[0];
104
- return _ ? (await i.customers.update(_.id, p), _.id) : (await i.customers.create(p)).id;
105
- } catch (u) {
106
- return console.error("Failed to upsert Stripe customer for checkout prefill:", u), null;
107
- }
39
+ async function fe(e) {
40
+ if (!e.email) return null;
41
+ let t = await m(), n = g(e.shippingAddress), r = e.shippingAddress?.recipient_name || e.billingAddress?.recipient_name || void 0, i = {
42
+ email: e.email,
43
+ name: e.billingAddress?.recipient_name || e.shippingAddress?.recipient_name || void 0,
44
+ phone: e.phone || void 0,
45
+ address: g(e.billingAddress),
46
+ metadata: e.userId ? { userId: e.userId } : void 0,
47
+ ...n && r ? { shipping: {
48
+ name: r,
49
+ phone: e.phone || void 0,
50
+ address: n
51
+ } } : {}
52
+ };
53
+ try {
54
+ let n = (await t.customers.list({
55
+ email: e.email,
56
+ limit: 1
57
+ })).data[0];
58
+ return n ? (await t.customers.update(n.id, i), n.id) : (await t.customers.create(i)).id;
59
+ } catch (e) {
60
+ return console.error("Failed to upsert Stripe customer for checkout prefill:", e), null;
61
+ }
108
62
  }
109
- class ct {
110
- getProviderName() {
111
- return "Stripe";
112
- }
113
- async createCheckoutSession({
114
- items: i,
115
- customerEmail: l,
116
- customerPhone: d,
117
- userId: p,
118
- billingAddress: u,
119
- shippingAddress: _,
120
- shippingMethodId: D,
121
- currencyCode: me,
122
- locale: R,
123
- couponCode: N,
124
- couponContextItems: U
125
- }) {
126
- const he = await _e(), K = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL, B = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_SECRET_KEY;
127
- if (!K || !B)
128
- return console.error("Missing Supabase credentials for checkout (Service Key required)."), { error: "Internal Server Error", url: null };
129
- const a = we(K, B), O = process.env.NEXT_PUBLIC_URL || "http://localhost:4200", Q = i.some((e) => !Oe(e));
130
- if (!i.length)
131
- return { error: "Cart is empty", url: null };
132
- const { data: fe, error: z } = await a.from("currencies").select(
133
- "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"
134
- ).eq("is_active", !0).order("code", { ascending: !0 }), y = fe ?? [];
135
- if (z || y.length === 0)
136
- return console.error("Error fetching currencies for checkout:", z), { error: "Failed to resolve store currencies", url: null };
137
- const $ = Ne(y), m = y.find((e) => e.code === (me || "").toUpperCase()) ?? $, L = m.code.toLowerCase(), X = await Le(a), ve = i.map((e) => e.product_id), H = i.map((e) => e.variant_id).filter((e) => !!e), { data: G, error: V } = 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", ve);
138
- if (V || !G)
139
- return console.error("Error fetching products for validation:", V), { error: "Failed to validate product prices", url: null };
140
- const { data: ye, error: W } = H.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", H) : { data: [], error: null };
141
- if (W)
142
- return console.error("Error fetching variants for validation:", W), { error: "Failed to validate product variants", url: null };
143
- const Y = new Map(G.map((e) => [e.id, e])), j = new Map((ye || []).map((e) => [e.id, e])), M = /* @__PURE__ */ new Set(), b = /* @__PURE__ */ new Map();
144
- for (const e of i) {
145
- const t = Y.get(e.product_id);
146
- if (!t)
147
- continue;
148
- const n = (e.variant_id ? j.get(e.variant_id) : null)?.sku || t.sku;
149
- n && (M.add(n), b.set(
150
- n,
151
- (b.get(n) ?? 0) + e.quantity
152
- ));
153
- }
154
- const { data: ge, error: J } = M.size ? await a.from("inventory_items").select("sku, quantity").in("sku", [...M]) : { data: [], error: null };
155
- if (J)
156
- return console.error("Error fetching SKU inventory for validation:", J), { error: "Failed to validate SKU inventory", url: null };
157
- const q = new Map(
158
- (ge || []).map((e) => [
159
- e.sku,
160
- Math.max(0, e.quantity ?? 0)
161
- ])
162
- ), g = [], Z = [], ee = [];
163
- let f = 0, S = 0, c = null;
164
- if (N) {
165
- const e = await qe({
166
- client: a,
167
- code: N,
168
- items: U && U.length > 0 ? U : i,
169
- currencyCode: m.code
170
- });
171
- if (!e.success)
172
- return {
173
- error: e.error,
174
- errorKey: e.errorKey,
175
- errorStatus: 400,
176
- url: null
177
- };
178
- c = e.quote;
179
- }
180
- const Se = Te(c), Ce = (e) => {
181
- const t = e.unitAmount * e.quantity, v = Math.max(0, t - e.lineDiscount);
182
- if (v <= 0)
183
- return;
184
- const n = Math.floor(v / e.quantity), w = v - n * e.quantity, E = (P, x) => {
185
- x <= 0 || P <= 0 || g.push({
186
- price_data: {
187
- currency: e.currency,
188
- product_data: {
189
- name: e.name,
190
- tax_code: Re(e.isTaxable),
191
- metadata: {
192
- productId: e.productId,
193
- variantId: e.variantId || ""
194
- }
195
- },
196
- tax_behavior: "exclusive",
197
- unit_amount: P
198
- },
199
- quantity: x
200
- });
201
- };
202
- E(n, e.quantity - w), E(n + 1, w);
203
- };
204
- for (const e of i) {
205
- const t = Y.get(e.product_id);
206
- if (!t)
207
- return console.warn(`Product ${e.product_id} not found in DB.`), {
208
- url: null,
209
- ...se(e.title)
210
- };
211
- const v = de({
212
- prices: I(t.prices),
213
- salePrices: t.sale_prices || {},
214
- fallbackPrice: t.price,
215
- fallbackSalePrice: t.sale_price,
216
- saleStartAt: t.sale_start_at,
217
- saleEndAt: t.sale_end_at,
218
- scheduledPrice: t.scheduled_price,
219
- scheduledPrices: I(t.scheduled_prices),
220
- scheduledPriceAt: t.scheduled_price_at,
221
- currencyCode: m.code,
222
- currencies: y
223
- });
224
- let n = v.sale_price ?? v.price, w = t.title, E = null;
225
- if (e.variant_id) {
226
- const o = j.get(e.variant_id);
227
- if (!o || o.product_id !== e.product_id)
228
- return {
229
- url: null,
230
- ...se(e.title)
231
- };
232
- const A = b.get(o.sku) ?? e.quantity, ne = q.has(o.sku) ? q.get(o.sku) ?? 0 : Math.max(0, o.stock_quantity ?? 0);
233
- if (X.trackQuantities && A > ne)
234
- return {
235
- url: null,
236
- ...ue(e.title, ne)
237
- };
238
- const ce = de({
239
- prices: I(o.prices),
240
- salePrices: o.sale_prices || {},
241
- fallbackPrice: o.price,
242
- fallbackSalePrice: o.sale_price,
243
- saleStartAt: o.sale_start_at,
244
- saleEndAt: o.sale_end_at,
245
- scheduledPrice: o.scheduled_price,
246
- scheduledPrices: I(o.scheduled_prices),
247
- scheduledPriceAt: o.scheduled_price_at,
248
- currencyCode: m.code,
249
- currencies: y
250
- });
251
- n = ce.sale_price ?? ce.price, E = o.id, w = e.variant_label ? `${t.title} - ${e.variant_label}` : `${t.title} - ${o.sku}`;
252
- } else {
253
- const o = b.get(t.sku) ?? e.quantity, A = q.has(t.sku) ? q.get(t.sku) ?? 0 : Math.max(0, t.stock ?? 0);
254
- if (X.trackQuantities && o > A)
255
- return {
256
- url: null,
257
- ...ue(e.title, A)
258
- };
259
- }
260
- const P = t.is_taxable ?? !0;
261
- if (n < 0)
262
- return { error: "A product variation produced an invalid price.", url: null };
263
- const x = Math.min(
264
- n * e.quantity,
265
- Se.get(Ie(e)) ?? 0
266
- );
267
- Ce({
268
- name: w,
269
- currency: L,
270
- productId: t.id,
271
- variantId: E,
272
- isTaxable: P,
273
- unitAmount: n,
274
- quantity: e.quantity,
275
- lineDiscount: x
276
- }), f += n * e.quantity, S += x, ee.push({
277
- product_id: t.id,
278
- quantity: e.quantity,
279
- price_at_purchase: n,
280
- variant_id: E
281
- }), Z.push({
282
- product_id: t.id,
283
- quantity: e.quantity,
284
- unit_amount: n,
285
- discount_amount: x,
286
- is_taxable: P
287
- });
288
- }
289
- if (g.length === 0 && S >= f)
290
- return {
291
- error: "This coupon would reduce the Stripe order to zero. Use a smaller discount for Stripe checkout.",
292
- errorKey: "ecommerce.coupon_zero_total_not_supported",
293
- errorStatus: 400,
294
- url: null
295
- };
296
- if (g.length === 0)
297
- return { error: "No valid items in cart", url: null };
298
- let h = 0, F = null;
299
- if (D) {
300
- const { data: e, error: t } = await a.from("shipping_zone_methods").select("id, name, name_translations, cost_amount, cost_currency").eq("id", D).single();
301
- if (t)
302
- return console.error("Failed to load shipping method:", t), { error: "Failed to load shipping method", url: null };
303
- h = Ke({
304
- amount: e.cost_amount ?? 0,
305
- fromCurrencyCode: e.cost_currency || $.code,
306
- toCurrencyCode: m.code,
307
- currencies: y
308
- }), F = He(e, R);
309
- }
310
- const te = Q ? _ ?? u : u;
311
- let s;
312
- try {
313
- s = await Me(a, {
314
- items: Z,
315
- destination: {
316
- country_code: te?.country_code,
317
- state: te?.state
318
- }
319
- });
320
- } catch (e) {
321
- return console.error("Failed to calculate checkout taxes:", e), { error: "Failed to calculate taxes", url: null };
322
- }
323
- h > 0 && F && g.push({
324
- price_data: {
325
- currency: L,
326
- product_data: {
327
- name: F,
328
- tax_code: s.enabled && s.mode === "automatic" ? Fe : le
329
- },
330
- tax_behavior: "exclusive",
331
- unit_amount: h
332
- },
333
- quantity: 1
334
- });
335
- const C = s.enabled && s.mode === "manual" && !s.isPendingExternalCalculation ? s.amount : 0;
336
- C > 0 && g.push({
337
- price_data: {
338
- currency: L,
339
- product_data: {
340
- name: "Tax",
341
- tax_code: le
342
- },
343
- tax_behavior: "exclusive",
344
- unit_amount: C
345
- },
346
- quantity: 1
347
- });
348
- const ke = be({
349
- email: l,
350
- phone: d,
351
- name: u?.recipient_name,
352
- billing: u,
353
- shipping: _
354
- }), re = m.code, Ee = Be({
355
- calculation: s,
356
- subtotal: f,
357
- shippingTotal: h,
358
- total: Math.max(0, f - S) + h + C,
359
- currency: re
360
- }), xe = Math.max(0, f - S) + h + C, { data: oe, error: ie } = await a.from("orders").insert({
361
- status: "pending",
362
- total: xe,
363
- currency: re,
364
- exchange_rate_at_purchase: m.exchange_rate,
365
- subtotal: f,
366
- shipping_total: h,
367
- tax_total: C,
368
- tax_details: Ee,
369
- coupon_id: c?.couponId ?? null,
370
- coupon_code: c?.code ?? null,
371
- discount_total: S,
372
- discount_details: c ? {
373
- code: c.code,
374
- discount_type: c.discountType,
375
- discount_amount: c.discountAmount,
376
- provider: "stripe",
377
- provider_discounts: c.providerDiscounts,
378
- line_discounts: c.lineDiscounts
379
- } : null,
380
- provider: "stripe",
381
- user_id: p,
382
- customer_details: ke
383
- }).select("id").single();
384
- if (ie || !oe)
385
- return console.error("Failed to create pending order:", ie), { error: "Failed to initiate order", url: null };
386
- const k = oe.id, { error: ae } = await a.from("order_items").insert(
387
- ee.map((e) => ({
388
- order_id: k,
389
- product_id: e.product_id,
390
- variant_id: e.variant_id ?? null,
391
- quantity: e.quantity,
392
- price_at_purchase: e.price_at_purchase
393
- }))
394
- );
395
- if (ae)
396
- return console.error("Failed to insert order items:", ae), await a.from("orders").update({ status: "failed" }).eq("id", k), { error: "Failed to record order items", url: null };
397
- if (p)
398
- try {
399
- await De({
400
- userId: p,
401
- billingAddress: u,
402
- shippingAddress: _,
403
- client: a
404
- }), await Ue({
405
- userId: p,
406
- fullName: u?.recipient_name ?? _?.recipient_name ?? null,
407
- phone: d,
408
- client: a
409
- });
410
- } catch (e) {
411
- console.error(
412
- "Failed to sync checkout profile defaults before checkout:",
413
- e
414
- );
415
- }
416
- c && await Ae({
417
- client: a,
418
- quote: c,
419
- orderId: k,
420
- provider: "stripe",
421
- discountTotal: S,
422
- userId: p,
423
- customerEmail: l,
424
- metadata: {
425
- currency: m.code,
426
- subtotal: f,
427
- shipping_total: h,
428
- tax_total: C
429
- }
430
- });
431
- const T = await Ge({
432
- email: l,
433
- phone: d,
434
- userId: p,
435
- billingAddress: u,
436
- shippingAddress: _
437
- });
438
- try {
439
- const e = await he.checkout.sessions.create({
440
- mode: "payment",
441
- success_url: `${O}/checkout/success?session_id={CHECKOUT_SESSION_ID}`,
442
- cancel_url: `${O}/checkout`,
443
- locale: Xe(R),
444
- line_items: g,
445
- automatic_tax: s.enabled && s.mode === "automatic" ? { enabled: !0 } : void 0,
446
- billing_address_collection: "auto",
447
- customer: T || void 0,
448
- customer_email: T ? void 0 : l || void 0,
449
- customer_creation: T ? void 0 : "if_required",
450
- customer_update: T ? {
451
- name: "auto",
452
- address: "auto",
453
- shipping: "auto"
454
- } : void 0,
455
- shipping_address_collection: Q ? {
456
- allowed_countries: ze
457
- } : void 0,
458
- metadata: {
459
- orderId: k,
460
- taxMode: s.mode,
461
- currencyCode: m.code,
462
- couponCode: c?.code || ""
463
- }
464
- }), { error: t } = await a.from("orders").update({ stripe_session_id: e.id }).eq("id", k);
465
- return t && console.error("Failed to save Stripe session ID on order:", t), { url: e.url };
466
- } catch (e) {
467
- return console.error("Stripe session creation failed:", e), await a.from("orders").update({ status: "failed" }).eq("id", k), e?.name === "StripeNotConfiguredError" || e?.type === "StripeAuthenticationError" ? {
468
- error: "This store is not able to take payments right now. Please contact the seller to complete your purchase.",
469
- errorKey: "ecommerce.checkout_payments_unavailable",
470
- errorStatus: 503,
471
- url: null
472
- } : {
473
- error: "Something went wrong while preparing your checkout. Please try again.",
474
- errorKey: "ecommerce.checkout_internal_server_error",
475
- url: null
476
- };
477
- }
478
- }
479
- }
480
- export {
481
- ct as StripeProvider
63
+ var _ = class {
64
+ getProviderName() {
65
+ return "Stripe";
66
+ }
67
+ async createCheckoutSession({ items: l, customerEmail: u, customerPhone: h, userId: g, billingAddress: _, shippingAddress: v, shippingMethodId: pe, currencyCode: me, locale: he, couponCode: y, couponContextItems: b }) {
68
+ let ge = await m(), x = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL, S = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_SECRET_KEY;
69
+ if (!x || !S) return console.error("Missing Supabase credentials for checkout (Service Key required)."), {
70
+ error: "Internal Server Error",
71
+ url: null
72
+ };
73
+ let C = ce(x, S), w = process.env.NEXT_PUBLIC_URL || "http://localhost:4200", T = l.some((t) => !e(t));
74
+ if (!l.length) return {
75
+ error: "Cart is empty",
76
+ url: null
77
+ };
78
+ let { data: _e, error: E } = await C.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 }), D = _e ?? [];
79
+ if (E || D.length === 0) return console.error("Error fetching currencies for checkout:", E), {
80
+ error: "Failed to resolve store currencies",
81
+ url: null
82
+ };
83
+ let O = n(D), k = D.find((e) => e.code === (me || "").toUpperCase()) ?? O, A = k.code.toLowerCase(), j = await ee(C), ve = l.map((e) => e.product_id), M = l.map((e) => e.variant_id).filter((e) => !!e), { data: N, error: P } = await C.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", ve);
84
+ if (P || !N) return console.error("Error fetching products for validation:", P), {
85
+ error: "Failed to validate product prices",
86
+ url: null
87
+ };
88
+ let { data: ye, error: F } = M.length ? await C.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", M) : {
89
+ data: [],
90
+ error: null
91
+ };
92
+ if (F) return console.error("Error fetching variants for validation:", F), {
93
+ error: "Failed to validate product variants",
94
+ url: null
95
+ };
96
+ let I = new Map(N.map((e) => [e.id, e])), L = new Map((ye || []).map((e) => [e.id, e])), R = /* @__PURE__ */ new Set(), z = /* @__PURE__ */ new Map();
97
+ for (let e of l) {
98
+ let t = I.get(e.product_id);
99
+ if (!t) continue;
100
+ let n = (e.variant_id ? L.get(e.variant_id) : null)?.sku || t.sku;
101
+ n && (R.add(n), z.set(n, (z.get(n) ?? 0) + e.quantity));
102
+ }
103
+ let { data: be, error: B } = R.size ? await C.from("inventory_items").select("sku, quantity").in("sku", [...R]) : {
104
+ data: [],
105
+ error: null
106
+ };
107
+ if (B) return console.error("Error fetching SKU inventory for validation:", B), {
108
+ error: "Failed to validate SKU inventory",
109
+ url: null
110
+ };
111
+ let V = new Map((be || []).map((e) => [e.sku, Math.max(0, e.quantity ?? 0)])), H = [], U = [], W = [], G = 0, K = 0, q = null;
112
+ if (y) {
113
+ let e = await o({
114
+ client: C,
115
+ code: y,
116
+ items: b && b.length > 0 ? b : l,
117
+ currencyCode: k.code
118
+ });
119
+ if (!e.success) return {
120
+ error: e.error,
121
+ errorKey: e.errorKey,
122
+ errorStatus: 400,
123
+ url: null
124
+ };
125
+ q = e.quote;
126
+ }
127
+ let xe = s(q), Se = (e) => {
128
+ let t = e.unitAmount * e.quantity, n = Math.max(0, t - e.lineDiscount);
129
+ if (n <= 0) return;
130
+ let r = Math.floor(n / e.quantity), i = n - r * e.quantity, a = (t, n) => {
131
+ n <= 0 || t <= 0 || H.push({
132
+ price_data: {
133
+ currency: e.currency,
134
+ product_data: {
135
+ name: e.name,
136
+ tax_code: re(e.isTaxable),
137
+ metadata: {
138
+ productId: e.productId,
139
+ variantId: e.variantId || ""
140
+ }
141
+ },
142
+ tax_behavior: "exclusive",
143
+ unit_amount: t
144
+ },
145
+ quantity: n
146
+ });
147
+ };
148
+ a(r, e.quantity - i), a(r + 1, i);
149
+ };
150
+ for (let e of l) {
151
+ let t = I.get(e.product_id);
152
+ if (!t) return console.warn(`Product ${e.product_id} not found in DB.`), {
153
+ url: null,
154
+ ...f(e.title)
155
+ };
156
+ let n = i({
157
+ prices: r(t.prices),
158
+ salePrices: t.sale_prices || {},
159
+ fallbackPrice: t.price,
160
+ fallbackSalePrice: t.sale_price,
161
+ saleStartAt: t.sale_start_at,
162
+ saleEndAt: t.sale_end_at,
163
+ scheduledPrice: t.scheduled_price,
164
+ scheduledPrices: r(t.scheduled_prices),
165
+ scheduledPriceAt: t.scheduled_price_at,
166
+ currencyCode: k.code,
167
+ currencies: D
168
+ }), o = n.sale_price ?? n.price, s = t.title, c = null;
169
+ if (e.variant_id) {
170
+ let n = L.get(e.variant_id);
171
+ if (!n || n.product_id !== e.product_id) return {
172
+ url: null,
173
+ ...f(e.title)
174
+ };
175
+ let a = z.get(n.sku) ?? e.quantity, l = V.has(n.sku) ? V.get(n.sku) ?? 0 : Math.max(0, n.stock_quantity ?? 0);
176
+ if (j.trackQuantities && a > l) return {
177
+ url: null,
178
+ ...d(e.title, l)
179
+ };
180
+ let u = i({
181
+ prices: r(n.prices),
182
+ salePrices: n.sale_prices || {},
183
+ fallbackPrice: n.price,
184
+ fallbackSalePrice: n.sale_price,
185
+ saleStartAt: n.sale_start_at,
186
+ saleEndAt: n.sale_end_at,
187
+ scheduledPrice: n.scheduled_price,
188
+ scheduledPrices: r(n.scheduled_prices),
189
+ scheduledPriceAt: n.scheduled_price_at,
190
+ currencyCode: k.code,
191
+ currencies: D
192
+ });
193
+ o = u.sale_price ?? u.price, c = n.id, s = e.variant_label ? `${t.title} - ${e.variant_label}` : `${t.title} - ${n.sku}`;
194
+ } else {
195
+ let n = z.get(t.sku) ?? e.quantity, r = V.has(t.sku) ? V.get(t.sku) ?? 0 : Math.max(0, t.stock ?? 0);
196
+ if (j.trackQuantities && n > r) return {
197
+ url: null,
198
+ ...d(e.title, r)
199
+ };
200
+ }
201
+ let l = t.is_taxable ?? !0;
202
+ if (o < 0) return {
203
+ error: "A product variation produced an invalid price.",
204
+ url: null
205
+ };
206
+ let u = Math.min(o * e.quantity, xe.get(a(e)) ?? 0);
207
+ Se({
208
+ name: s,
209
+ currency: A,
210
+ productId: t.id,
211
+ variantId: c,
212
+ isTaxable: l,
213
+ unitAmount: o,
214
+ quantity: e.quantity,
215
+ lineDiscount: u
216
+ }), G += o * e.quantity, K += u, W.push({
217
+ product_id: t.id,
218
+ quantity: e.quantity,
219
+ price_at_purchase: o,
220
+ variant_id: c
221
+ }), U.push({
222
+ product_id: t.id,
223
+ quantity: e.quantity,
224
+ unit_amount: o,
225
+ discount_amount: u,
226
+ is_taxable: l
227
+ });
228
+ }
229
+ if (H.length === 0 && K >= G) return {
230
+ error: "This coupon would reduce the Stripe order to zero. Use a smaller discount for Stripe checkout.",
231
+ errorKey: "ecommerce.coupon_zero_total_not_supported",
232
+ errorStatus: 400,
233
+ url: null
234
+ };
235
+ if (H.length === 0) return {
236
+ error: "No valid items in cart",
237
+ url: null
238
+ };
239
+ let J = 0, Y = null;
240
+ if (pe) {
241
+ let { data: e, error: n } = await C.from("shipping_zone_methods").select("id, name, name_translations, cost_amount, cost_currency").eq("id", pe).single();
242
+ if (n) return console.error("Failed to load shipping method:", n), {
243
+ error: "Failed to load shipping method",
244
+ url: null
245
+ };
246
+ J = t({
247
+ amount: e.cost_amount ?? 0,
248
+ fromCurrencyCode: e.cost_currency || O.code,
249
+ toCurrencyCode: k.code,
250
+ currencies: D
251
+ }), Y = de(e, he);
252
+ }
253
+ let Ce = T ? v ?? _ : _, X;
254
+ try {
255
+ X = await ne(C, {
256
+ items: U,
257
+ destination: {
258
+ country_code: Ce?.country_code,
259
+ state: Ce?.state
260
+ }
261
+ });
262
+ } catch (e) {
263
+ return console.error("Failed to calculate checkout taxes:", e), {
264
+ error: "Failed to calculate taxes",
265
+ url: null
266
+ };
267
+ }
268
+ J > 0 && Y && H.push({
269
+ price_data: {
270
+ currency: A,
271
+ product_data: {
272
+ name: Y,
273
+ tax_code: X.enabled && X.mode === "automatic" ? te : p
274
+ },
275
+ tax_behavior: "exclusive",
276
+ unit_amount: J
277
+ },
278
+ quantity: 1
279
+ });
280
+ let Z = X.enabled && X.mode === "manual" && !X.isPendingExternalCalculation ? X.amount : 0;
281
+ Z > 0 && H.push({
282
+ price_data: {
283
+ currency: A,
284
+ product_data: {
285
+ name: "Tax",
286
+ tax_code: p
287
+ },
288
+ tax_behavior: "exclusive",
289
+ unit_amount: Z
290
+ },
291
+ quantity: 1
292
+ });
293
+ let we = ie({
294
+ email: u,
295
+ phone: h,
296
+ name: _?.recipient_name,
297
+ billing: _,
298
+ shipping: v
299
+ }), Te = k.code, Ee = se({
300
+ calculation: X,
301
+ subtotal: G,
302
+ shippingTotal: J,
303
+ total: Math.max(0, G - K) + J + Z,
304
+ currency: Te
305
+ }), De = Math.max(0, G - K) + J + Z, { data: Oe, error: ke } = await C.from("orders").insert({
306
+ status: "pending",
307
+ total: De,
308
+ currency: Te,
309
+ exchange_rate_at_purchase: k.exchange_rate,
310
+ subtotal: G,
311
+ shipping_total: J,
312
+ tax_total: Z,
313
+ tax_details: Ee,
314
+ coupon_id: q?.couponId ?? null,
315
+ coupon_code: q?.code ?? null,
316
+ discount_total: K,
317
+ discount_details: q ? {
318
+ code: q.code,
319
+ discount_type: q.discountType,
320
+ discount_amount: q.discountAmount,
321
+ provider: "stripe",
322
+ provider_discounts: q.providerDiscounts,
323
+ line_discounts: q.lineDiscounts
324
+ } : null,
325
+ provider: "stripe",
326
+ user_id: g,
327
+ customer_details: we
328
+ }).select("id").single();
329
+ if (ke || !Oe) return console.error("Failed to create pending order:", ke), {
330
+ error: "Failed to initiate order",
331
+ url: null
332
+ };
333
+ let Q = Oe.id, { error: Ae } = await C.from("order_items").insert(W.map((e) => ({
334
+ order_id: Q,
335
+ product_id: e.product_id,
336
+ variant_id: e.variant_id ?? null,
337
+ quantity: e.quantity,
338
+ price_at_purchase: e.price_at_purchase
339
+ })));
340
+ if (Ae) return console.error("Failed to insert order items:", Ae), await C.from("orders").update({ status: "failed" }).eq("id", Q), {
341
+ error: "Failed to record order items",
342
+ url: null
343
+ };
344
+ if (g) try {
345
+ await oe({
346
+ userId: g,
347
+ billingAddress: _,
348
+ shippingAddress: v,
349
+ client: C
350
+ }), await ae({
351
+ userId: g,
352
+ fullName: _?.recipient_name ?? v?.recipient_name ?? null,
353
+ phone: h,
354
+ client: C
355
+ });
356
+ } catch (e) {
357
+ console.error("Failed to sync checkout profile defaults before checkout:", e);
358
+ }
359
+ q && await c({
360
+ client: C,
361
+ quote: q,
362
+ orderId: Q,
363
+ provider: "stripe",
364
+ discountTotal: K,
365
+ userId: g,
366
+ customerEmail: u,
367
+ metadata: {
368
+ currency: k.code,
369
+ subtotal: G,
370
+ shipping_total: J,
371
+ tax_total: Z
372
+ }
373
+ });
374
+ let $ = await fe({
375
+ email: u,
376
+ phone: h,
377
+ userId: g,
378
+ billingAddress: _,
379
+ shippingAddress: v
380
+ });
381
+ try {
382
+ let e = await ge.checkout.sessions.create({
383
+ mode: "payment",
384
+ success_url: `${w}/checkout/success?session_id={CHECKOUT_SESSION_ID}`,
385
+ cancel_url: `${w}/checkout`,
386
+ locale: ue(he),
387
+ line_items: H,
388
+ automatic_tax: X.enabled && X.mode === "automatic" ? { enabled: !0 } : void 0,
389
+ billing_address_collection: "auto",
390
+ customer: $ || void 0,
391
+ customer_email: $ ? void 0 : u || void 0,
392
+ customer_creation: $ ? void 0 : "if_required",
393
+ customer_update: $ ? {
394
+ name: "auto",
395
+ address: "auto",
396
+ shipping: "auto"
397
+ } : void 0,
398
+ shipping_address_collection: T ? { allowed_countries: le } : void 0,
399
+ metadata: {
400
+ orderId: Q,
401
+ taxMode: X.mode,
402
+ currencyCode: k.code,
403
+ couponCode: q?.code || ""
404
+ }
405
+ }), { error: t } = await C.from("orders").update({ stripe_session_id: e.id }).eq("id", Q);
406
+ return t && console.error("Failed to save Stripe session ID on order:", t), { url: e.url };
407
+ } catch (e) {
408
+ return console.error("Stripe session creation failed:", e), await C.from("orders").update({ status: "failed" }).eq("id", Q), e?.name === "StripeNotConfiguredError" || e?.type === "StripeAuthenticationError" ? {
409
+ error: "This store is not able to take payments right now. Please contact the seller to complete your purchase.",
410
+ errorKey: "ecommerce.checkout_payments_unavailable",
411
+ errorStatus: 503,
412
+ url: null
413
+ } : {
414
+ error: "Something went wrong while preparing your checkout. Please try again.",
415
+ errorKey: "ecommerce.checkout_internal_server_error",
416
+ url: null
417
+ };
418
+ }
419
+ }
482
420
  };
421
+ //#endregion
422
+ export { _ as StripeProvider };