@burdenoff/microfe-billing 2026.910.7 → 2026.910.9

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.
@@ -2,57 +2,55 @@ import { useBilling as e } from "../../../providers/BillingProvider.js";
2
2
  import { useConvertCurrencyLazyQuery as t, useInitiatePaymentCheckoutMutation as n, useSpendCreditsCheckoutMutation as r, useValidateCouponLazyQuery as i } from "../../../../generated/global-operations.js";
3
3
  import { useEnsureStoreOrderBillingOrder as a } from "./useStoreShipping.js";
4
4
  import { useCallback as o, useEffect as s, useMemo as c, useState as l } from "react";
5
- //#region src/billing/modules/checkout/hooks/useCheckout.ts
6
- var ee = 100;
7
5
  function u(u = {}) {
8
- let { currentUser: d } = e(), { defaultCurrency: f = "USD", defaultSaveCard: p = !1, upgradeFromSubscriptionId: m, downgradeFromSubscriptionId: h, defaultSubscriptionId: g } = u, [_, v] = l([]), [y, te] = l(null), [b, ne] = l("AUTO"), [x, S] = l(f), [C, w] = l(""), [T, E] = l(0), [re, D] = l("PERCENTAGE"), [O, k] = l(!1), [A, j] = l(0), [M, N] = l("idle"), [ie, P] = l(null), [F, I] = l(0), [ae, L] = l(0), [oe, R] = l("NONE"), [z, B] = l(null), [V, se] = l(p), [H, ce] = l(!1), [U, W] = l(null), [G, le] = l(g ?? null), [ue] = n(), [de] = a(), [fe] = r(), [K, { data: pe, loading: me }] = t(), [he] = i(), q = c(() => _[0]?.currency ?? "USD", [_]), J = c(() => _.reduce((e, t) => e + t.price * t.quantity, 0), [_]), Y = c(() => _.reduce((e, t) => e + (t.priceUSD ?? t.price) * t.quantity, 0), [_]), X = c(() => T ? Math.min(T, J) : 0, [J, T]), Z = c(() => {
9
- let e = J - X;
10
- return (O ? Math.max(0, e - A) : e) + F;
6
+ let { currentUser: d } = e(), { defaultCurrency: f = "USD", defaultSaveCard: p = !1, upgradeFromSubscriptionId: m, downgradeFromSubscriptionId: h, defaultSubscriptionId: g } = u, [_, v] = l([]), [y, ee] = l(null), [b, x] = l("AUTO"), [S, C] = l(f), [w, T] = l(""), [E, D] = l(0), [te, O] = l("PERCENTAGE"), [k, A] = l(!1), [j, M] = l(0), [N, P] = l("idle"), [ne, F] = l(null), [I, L] = l(0), [re, R] = l(0), [ie, z] = l("NONE"), [B, ae] = l(null), [V, oe] = l(p), [H, se] = l(!1), [U, ce] = l(null), [W, le] = l(g ?? null), [ue] = n(), [de] = a(), [fe] = r(), [G, { data: pe, loading: me }] = t(), [he] = i(), K = c(() => _[0]?.currency ?? "USD", [_]), q = c(() => _.reduce((e, t) => e + t.price * t.quantity, 0), [_]), J = c(() => _.reduce((e, t) => e + (t.priceUSD ?? t.price) * t.quantity, 0), [_]), Y = c(() => E ? Math.min(E, q) : 0, [q, E]), X = c(() => {
7
+ let e = q - Y;
8
+ return (k ? Math.max(0, e - j) : e) + I;
11
9
  }, [
12
- J,
13
- X,
14
- O,
15
- A,
16
- F
17
- ]), Q = y?.creditAmount ?? 0, ge = c(() => Q >= Y * ee, [Q, Y]), _e = c(() => !_.some((e) => e.type === "CREDITS") && Q > 0, [_, Q]), ve = pe?.convertCurrency?.amount ?? null, ye = pe?.convertCurrency?.exchangeRate ?? 1, be = ve ?? Z, xe = M === "loading" || me, Se = M === "processing";
10
+ q,
11
+ Y,
12
+ k,
13
+ j,
14
+ I
15
+ ]), Z = y?.creditAmount ?? 0, Q = c(() => J * 100, [J]), ge = c(() => Z >= Q, [Z, Q]), _e = c(() => !_.some((e) => e.type === "CREDITS") && Z > 0, [_, Z]), ve = pe?.convertCurrency?.amount ?? null, ye = pe?.convertCurrency?.exchangeRate ?? 1, be = ve ?? X, xe = N === "loading" || me, Se = N === "processing";
18
16
  s(() => {
19
- if (b !== "CREDITS" && _.length !== 0 && !_.every((e) => e.currency === x || e.type === "CREDITS") && Z > 0 && q !== x) {
20
- if (x === "INR" && F === 0 && J > 0) return;
21
- K({ variables: {
22
- amount: Z,
23
- toCurrency: x,
24
- fromCurrency: q
17
+ if (b !== "CREDITS" && _.length !== 0 && !_.every((e) => e.currency === S || e.type === "CREDITS") && X > 0 && K !== S) {
18
+ if (S === "INR" && I === 0 && q > 0) return;
19
+ G({ variables: {
20
+ amount: X,
21
+ toCurrency: S,
22
+ fromCurrency: K
25
23
  } });
26
24
  }
27
25
  }, [
28
- Z,
29
- x,
26
+ X,
27
+ S,
30
28
  b,
31
- K,
32
- F,
33
- J,
29
+ G,
30
+ I,
31
+ q,
34
32
  _,
35
- q
33
+ K
36
34
  ]), s(() => {
37
- if (!y || J <= 0) {
38
- I(0), L(0), R("NONE");
35
+ if (!y || q <= 0) {
36
+ L(0), R(0), z("NONE");
39
37
  return;
40
38
  }
41
39
  if (b === "CREDITS") {
42
- I(0), L(0), R("NONE");
40
+ L(0), R(0), z("NONE");
43
41
  return;
44
42
  }
45
- if (x !== "INR") {
46
- I(0), L(0), R("NONE");
43
+ if (S !== "INR") {
44
+ L(0), R(0), z("NONE");
47
45
  return;
48
46
  }
49
- let e = J - X, t = .18;
50
- I(e * t), L(t), R("GST");
47
+ let e = q - Y, t = .18;
48
+ L(e * t), R(t), z("GST");
51
49
  }, [
52
50
  y,
53
- J,
54
- X,
55
- x,
51
+ q,
52
+ Y,
53
+ S,
56
54
  b
57
55
  ]);
58
56
  let Ce = o((e) => {
@@ -92,47 +90,48 @@ function u(u = {}) {
92
90
  }, []), Ee = o(() => {
93
91
  v([]);
94
92
  }, []), De = o((e) => {
95
- te(e), k(!1), j(0);
93
+ ee(e), A(!1), M(0), x((e) => e === "CREDITS" ? "AUTO" : e);
96
94
  }, []), Oe = o((e) => {
97
- S(e);
95
+ C(e);
98
96
  let t = _.every((t) => t.currency === e || t.type === "CREDITS");
99
- Z > 0 && q !== e && !t && K({ variables: {
100
- amount: Z,
97
+ X > 0 && K !== e && !t && G({ variables: {
98
+ amount: X,
101
99
  toCurrency: e,
102
- fromCurrency: q
100
+ fromCurrency: K
103
101
  } });
104
102
  }, [
105
- Z,
106
- K,
103
+ X,
104
+ G,
107
105
  _,
108
- q
106
+ K
109
107
  ]);
110
108
  return {
111
109
  items: _,
112
110
  billingAccount: y,
113
111
  selectedProvider: b,
114
- selectedCurrency: x,
115
- promoCode: C,
116
- promoDiscount: T,
117
- promoDiscountType: re,
118
- useCredits: O,
119
- creditsToUse: A,
120
- checkoutState: M,
121
- error: ie,
122
- selectedPaymentMethodId: z,
112
+ selectedCurrency: S,
113
+ promoCode: w,
114
+ promoDiscount: E,
115
+ promoDiscountType: te,
116
+ useCredits: k,
117
+ creditsToUse: j,
118
+ checkoutState: N,
119
+ error: ne,
120
+ selectedPaymentMethodId: B,
123
121
  saveCard: V,
124
122
  autoRenew: H,
125
123
  autoRenewPaymentMethodId: U,
126
- selectedSubscriptionId: G,
127
- subtotal: J,
128
- subtotalUSD: Y,
129
- discountAmount: X,
130
- taxAmount: F,
131
- taxRate: ae,
132
- taxType: oe,
133
- total: Z,
124
+ selectedSubscriptionId: W,
125
+ subtotal: q,
126
+ subtotalUSD: J,
127
+ discountAmount: Y,
128
+ taxAmount: I,
129
+ taxRate: re,
130
+ taxType: ie,
131
+ total: X,
134
132
  totalInSelectedCurrency: be,
135
- availableCredits: Q,
133
+ availableCredits: Z,
134
+ creditsRequired: Q,
136
135
  hasEnoughCredits: ge,
137
136
  canPayWithCredits: _e,
138
137
  isLoading: xe,
@@ -147,12 +146,12 @@ function u(u = {}) {
147
146
  clearItems: Ee,
148
147
  setBillingAccount: De,
149
148
  setPaymentProvider: o((e) => {
150
- ne(e), e === "RAZORPAY" && x !== "INR" && S("INR");
151
- }, [x]),
149
+ x(e), e === "RAZORPAY" && S !== "INR" && C("INR");
150
+ }, [S]),
152
151
  setCurrency: Oe,
153
- setPromoCode: w,
152
+ setPromoCode: T,
154
153
  validatePromoCode: o(async () => {
155
- if (!C.trim()) return {
154
+ if (!w.trim()) return {
156
155
  valid: !1,
157
156
  code: "",
158
157
  discountType: "PERCENTAGE",
@@ -160,48 +159,48 @@ function u(u = {}) {
160
159
  error: "Please enter a promo code"
161
160
  };
162
161
  try {
163
- N("loading");
162
+ P("loading");
164
163
  let { data: e, error: t } = await he({ variables: { input: {
165
- code: C.trim().toUpperCase(),
164
+ code: w.trim().toUpperCase(),
166
165
  userId: d?.id ?? "",
167
166
  userEmail: d?.email,
168
- amount: J,
169
- currency: x
167
+ amount: q,
168
+ currency: S
170
169
  } } });
171
- if (t || !e?.validateCoupon) return E(0), N("idle"), {
170
+ if (t || !e?.validateCoupon) return D(0), P("idle"), {
172
171
  valid: !1,
173
- code: C,
172
+ code: w,
174
173
  discountType: "PERCENTAGE",
175
174
  discountValue: 0,
176
175
  error: "Failed to validate coupon"
177
176
  };
178
177
  let n = e.validateCoupon;
179
- if (!n.valid) return E(0), N("idle"), {
178
+ if (!n.valid) return D(0), P("idle"), {
180
179
  valid: !1,
181
- code: C,
180
+ code: w,
182
181
  discountType: "PERCENTAGE",
183
182
  discountValue: 0,
184
183
  error: n.error || "Invalid coupon code"
185
184
  };
186
185
  let r = n.coupon;
187
- if (!r) return E(0), N("idle"), {
186
+ if (!r) return D(0), P("idle"), {
188
187
  valid: !1,
189
- code: C,
188
+ code: w,
190
189
  discountType: "PERCENTAGE",
191
190
  discountValue: 0,
192
191
  error: "Coupon data not found"
193
192
  };
194
193
  let i = n.discountAmount || 0, a = r.type === "FIXED_AMOUNT" ? "FIXED" : "PERCENTAGE";
195
- return E(i), D(a), N("idle"), {
194
+ return D(i), O(a), P("idle"), {
196
195
  valid: !0,
197
196
  code: r.code,
198
197
  discountType: a,
199
198
  discountValue: i
200
199
  };
201
200
  } catch {
202
- return E(0), N("idle"), {
201
+ return D(0), P("idle"), {
203
202
  valid: !1,
204
- code: C,
203
+ code: w,
205
204
  discountType: "PERCENTAGE",
206
205
  discountValue: 0,
207
206
  error: "Failed to validate coupon"
@@ -210,27 +209,27 @@ function u(u = {}) {
210
209
  }, [
211
210
  d?.email,
212
211
  d?.id,
213
- C,
214
- x,
215
- J,
212
+ w,
213
+ S,
214
+ q,
216
215
  he
217
216
  ]),
218
217
  clearPromoCode: o(() => {
219
- w(""), E(0), D("PERCENTAGE");
218
+ T(""), D(0), O("PERCENTAGE");
220
219
  }, []),
221
- setUseCredits: k,
220
+ setUseCredits: A,
222
221
  setCreditsToUse: o((e) => {
223
- let t = Math.min(e, Q, J - X);
224
- j(Math.max(0, t));
222
+ let t = Math.min(e, Z, q - Y);
223
+ M(Math.max(0, t));
225
224
  }, [
226
- Q,
227
- J,
228
- X
225
+ Z,
226
+ q,
227
+ Y
229
228
  ]),
230
- setSelectedPaymentMethodId: B,
231
- setSaveCard: se,
232
- setAutoRenew: ce,
233
- setAutoRenewPaymentMethodId: W,
229
+ setSelectedPaymentMethodId: ae,
230
+ setSaveCard: oe,
231
+ setAutoRenew: se,
232
+ setAutoRenewPaymentMethodId: ce,
234
233
  setSelectedSubscriptionId: le,
235
234
  initiatePayment: o(async () => {
236
235
  if (!y) return {
@@ -242,7 +241,7 @@ function u(u = {}) {
242
241
  total: 0,
243
242
  taxType: "NONE",
244
243
  jurisdiction: "UNKNOWN",
245
- currency: x,
244
+ currency: S,
246
245
  error: "Please select a billing account"
247
246
  };
248
247
  if (_.length === 0) return {
@@ -254,24 +253,24 @@ function u(u = {}) {
254
253
  total: 0,
255
254
  taxType: "NONE",
256
255
  jurisdiction: "UNKNOWN",
257
- currency: x,
256
+ currency: S,
258
257
  error: "No items in checkout"
259
258
  };
260
259
  try {
261
- N("processing"), P(null);
260
+ P("processing"), F(null);
262
261
  let e = _[0], t = e.type, n = _.find((e) => e.metadata?.storeOrderId)?.metadata?.storeOrderId, r = _.find((e) => e.metadata?.billingOrderId)?.metadata?.billingOrderId || void 0;
263
262
  n && (t = "ORDER");
264
- let i = J - X, a = b;
265
- if (a === "AUTO" && (a = x === "INR" ? "RAZORPAY" : "STRIPE"), t === "ORDER" && !r && n && y) {
263
+ let i = q - Y, a = b;
264
+ if (a === "AUTO" && (a = S === "INR" ? "RAZORPAY" : "STRIPE"), t === "ORDER" && !r && n && y) {
266
265
  let { data: e } = await de({ variables: {
267
266
  storeOrderId: n,
268
267
  billingAccountId: y.id,
269
- currency: x
268
+ currency: S
270
269
  } }), t = e?.ensureStoreOrderBillingOrder;
271
270
  if (t?.success && t.billingOrderId) r = t.billingOrderId;
272
271
  else {
273
272
  let e = t?.error ?? "Failed to create billing order";
274
- return N("error"), P(e), {
273
+ return P("error"), F(e), {
275
274
  success: !1,
276
275
  provider: a,
277
276
  subtotal: i,
@@ -280,7 +279,7 @@ function u(u = {}) {
280
279
  total: i,
281
280
  taxType: "NONE",
282
281
  jurisdiction: "UNKNOWN",
283
- currency: x,
282
+ currency: S,
284
283
  error: e
285
284
  };
286
285
  }
@@ -296,10 +295,10 @@ function u(u = {}) {
296
295
  isAnnual: t?.metadata?.duration === "yearly",
297
296
  upgradeFromSubscriptionId: m || void 0,
298
297
  downgradeFromSubscriptionId: h || void 0,
299
- subscriptionId: e.length > 0 ? G : void 0,
298
+ subscriptionId: e.length > 0 ? W : void 0,
300
299
  seatCount: t?.metadata?.seatCount
301
300
  } } }), r = n?.spendCredits;
302
- return r?.creditTransactionID ? (N("success"), {
301
+ return r?.creditTransactionID ? (P("success"), {
303
302
  success: !0,
304
303
  provider: "CREDITS",
305
304
  subtotal: i,
@@ -308,9 +307,9 @@ function u(u = {}) {
308
307
  total: i,
309
308
  taxType: "NONE",
310
309
  jurisdiction: "UNKNOWN",
311
- currency: x,
310
+ currency: S,
312
311
  orderId: r.creditTransactionID
313
- }) : (N("error"), P("Failed to process credit payment"), {
312
+ }) : (P("error"), F("Failed to process credit payment"), {
314
313
  success: !1,
315
314
  provider: "CREDITS",
316
315
  subtotal: i,
@@ -319,14 +318,14 @@ function u(u = {}) {
319
318
  total: i,
320
319
  taxType: "NONE",
321
320
  jurisdiction: "UNKNOWN",
322
- currency: x,
321
+ currency: S,
323
322
  error: "Failed to process credit payment"
324
323
  });
325
324
  }
326
- let o = _.filter((e) => e.type === "ADDON"), s = o.length > 0 ? o.map((e) => e.metadata?.addonId || e.id) : void 0, c = o.length > 0 ? o.map((e) => e.quantity) : void 0, l = _.find((e) => e.type === "PLAN")?.metadata?.duration === "yearly", ee = t === "PLAN" && H && (U || z) || void 0, { data: u } = await ue({ variables: { input: {
325
+ let o = _.filter((e) => e.type === "ADDON"), s = o.length > 0 ? o.map((e) => e.metadata?.addonId || e.id) : void 0, c = o.length > 0 ? o.map((e) => e.quantity) : void 0, l = _.find((e) => e.type === "PLAN")?.metadata?.duration === "yearly", u = t === "PLAN" && H && (U || B) || void 0, { data: d } = await ue({ variables: { input: {
327
326
  billingAccountId: y.id,
328
327
  amount: i,
329
- currency: x,
328
+ currency: S,
330
329
  purchaseType: t,
331
330
  provider: a,
332
331
  orderId: r || void 0,
@@ -336,17 +335,17 @@ function u(u = {}) {
336
335
  quantity: t === "ADDON" && o.length === 1 && !r ? o[0].quantity : void 0,
337
336
  addonIds: t === "ADDON" && o.length > 1 && !r ? s : void 0,
338
337
  quantities: t === "ADDON" && o.length > 1 && !r ? c : void 0,
339
- subscriptionId: t === "ADDON" && !r ? G : void 0,
340
- paymentMethodId: z || void 0,
341
- saveCard: z ? void 0 : V || H,
338
+ subscriptionId: t === "ADDON" && !r ? W : void 0,
339
+ paymentMethodId: B || void 0,
340
+ saveCard: B ? void 0 : V || H,
342
341
  upgradeFromSubscriptionId: m || void 0,
343
342
  downgradeFromSubscriptionId: h || void 0,
344
343
  isAnnual: l || void 0,
345
- promoCode: C || void 0,
344
+ promoCode: w || void 0,
346
345
  autoRenew: t === "PLAN" && H ? !0 : void 0,
347
- autoRenewPaymentMethodId: ee
348
- } } }), d = u?.initiatePayment;
349
- return d?.success ? (N("success"), d) : (N("error"), P(d?.error ?? "Payment initiation failed"), {
346
+ autoRenewPaymentMethodId: u
347
+ } } }), f = d?.initiatePayment;
348
+ return f?.success ? (P("success"), f) : (P("error"), F(f?.error ?? "Payment initiation failed"), {
350
349
  success: !1,
351
350
  provider: a,
352
351
  subtotal: i,
@@ -355,12 +354,12 @@ function u(u = {}) {
355
354
  total: i,
356
355
  taxType: "NONE",
357
356
  jurisdiction: "UNKNOWN",
358
- currency: x,
359
- error: d?.error ?? "Payment initiation failed"
357
+ currency: S,
358
+ error: f?.error ?? "Payment initiation failed"
360
359
  });
361
360
  } catch (e) {
362
361
  let t = e instanceof Error ? e.message : "An error occurred";
363
- return N("error"), P(t), {
362
+ return P("error"), F(t), {
364
363
  success: !1,
365
364
  provider: "AUTO",
366
365
  subtotal: 0,
@@ -369,23 +368,23 @@ function u(u = {}) {
369
368
  total: 0,
370
369
  taxType: "NONE",
371
370
  jurisdiction: "UNKNOWN",
372
- currency: x,
371
+ currency: S,
373
372
  error: t
374
373
  };
375
374
  }
376
375
  }, [
377
376
  y,
378
377
  _,
379
- x,
378
+ S,
380
379
  b,
381
- J,
382
- X,
383
- C,
384
- z,
380
+ q,
381
+ Y,
382
+ w,
383
+ B,
385
384
  V,
386
385
  H,
387
386
  U,
388
- G,
387
+ W,
389
388
  m,
390
389
  h,
391
390
  ue,
@@ -393,7 +392,7 @@ function u(u = {}) {
393
392
  fe
394
393
  ]),
395
394
  reset: o(() => {
396
- v([]), te(null), ne("AUTO"), S(f), w(""), E(0), D("PERCENTAGE"), k(!1), j(0), N("idle"), P(null), I(0), L(0), R("NONE"), B(null), se(p), ce(!1), W(null), le(g ?? null);
395
+ v([]), ee(null), x("AUTO"), C(f), T(""), D(0), O("PERCENTAGE"), A(!1), M(0), P("idle"), F(null), L(0), R(0), z("NONE"), ae(null), oe(p), se(!1), ce(null), le(g ?? null);
397
396
  }, [
398
397
  f,
399
398
  p,