@arcblock/payment-service 1.29.9 → 1.29.11

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 (170) hide show
  1. package/dist/cf.js +51 -51
  2. package/dist/index.js +196 -43
  3. package/package.json +3 -3
  4. package/web/assets/{account-Clbqiiw3.js → account-DrsnH5wP.js} +1 -1
  5. package/web/assets/{action-DENqSeOa.js → action-C2c0yWuW.js} +1 -1
  6. package/web/assets/{actions-CDsj5j8l.js → actions--FNKSNIs.js} +1 -1
  7. package/web/assets/{actions-BJDN6Op2.js → actions-BEUwbsq1.js} +1 -1
  8. package/web/assets/{actions-CSpJGOX7.js → actions-C9AfME83.js} +1 -1
  9. package/web/assets/{actions-BD9BAp3M.js → actions-D2-s31n3.js} +1 -1
  10. package/web/assets/{actions-BSNy5bOd.js → actions-DXMceTgd.js} +1 -1
  11. package/web/assets/{actions-0iWP2mcx.js → actions-DeCPtfTK.js} +1 -1
  12. package/web/assets/{actions-DGQs8fFF.js → actions-DtNZGZWf.js} +1 -1
  13. package/web/assets/{actions-D3tJgrUn.js → actions-JHsqbHpB.js} +1 -1
  14. package/web/assets/{actions-CZL47E9r.js → actions-izdZ2Mn4.js} +1 -1
  15. package/web/assets/{add-price-BpnICuHO.js → add-price-TdXAR3NW.js} +1 -1
  16. package/web/assets/{admin-CD8ViZ7D.js → admin-BpFv3eF5.js} +1 -1
  17. package/web/assets/{assign-0vMUDW_C.js → assign-DKRfmN7W.js} +1 -1
  18. package/web/assets/{attempts-CKlxkJuE.js → attempts-BfbYfiJa.js} +1 -1
  19. package/web/assets/browser-DF2vfpBa.js +1 -0
  20. package/web/assets/{change-payment-gAlRmJpv.js → change-payment-j5UC8_h0.js} +1 -1
  21. package/web/assets/{change-plan-C47wfWH8.js → change-plan-CtXvsIDw.js} +1 -1
  22. package/web/assets/{click-boundary-CafubiPp.js → click-boundary-Bi28Y0Fq.js} +1 -1
  23. package/web/assets/{connect-BHHzrwLA.js → connect-CXek4LAE.js} +1 -1
  24. package/web/assets/{copyable-QrCyyiou.js → copyable-CprMHdhV.js} +1 -1
  25. package/web/assets/{create-ke4FrPx1.js → create-B-Ubepl_.js} +1 -1
  26. package/web/assets/{create-DNar5UQD.js → create-BVt_sQ_7.js} +1 -1
  27. package/web/assets/{create-0PUtkJZY.js → create-BWviSWbC.js} +1 -1
  28. package/web/assets/{create-BJ1asdcy.js → create-C6jihslA.js} +1 -1
  29. package/web/assets/{create-C7GOgZZM.js → create-IaalYGmm.js} +1 -1
  30. package/web/assets/{create-Bgv5ux17.js → create-jzl1m8ZK.js} +1 -1
  31. package/web/assets/{credit-grant-item-list-CeDAM3qV.js → credit-grant-item-list-DQcvdSRs.js} +1 -1
  32. package/web/assets/{credit-overview-4zh0H02x.js → credit-overview-CPId2vzk.js} +1 -1
  33. package/web/assets/{currency-restrictions-BcEm8W45.js → currency-restrictions-Dsupz2ce.js} +1 -1
  34. package/web/assets/{currency-select-B4ieQBvv.js → currency-select-C8j7QQMP.js} +1 -1
  35. package/web/assets/{dayjs-DUTDpcNU.js → dayjs-DUNWtvju.js} +1 -1
  36. package/web/assets/{description-SnR5WxWT.js → description-BHxdy5I3.js} +1 -1
  37. package/web/assets/{detail-DNcp_u5S.js → detail-B17BN6kU.js} +1 -1
  38. package/web/assets/detail-BJ-hl5PK.js +10 -0
  39. package/web/assets/{detail-46aLUdJj.js → detail-BJEqTXDS.js} +1 -1
  40. package/web/assets/{detail-BQpDGZJQ.js → detail-BdC9VIc6.js} +1 -1
  41. package/web/assets/{detail-DbU3p040.js → detail-BkRkrKyw.js} +1 -1
  42. package/web/assets/{detail-DACnmls3.js → detail-BvcI9cB_.js} +1 -1
  43. package/web/assets/detail-C--ATvwm.js +24 -0
  44. package/web/assets/{detail-Cg505nKX.js → detail-CHJqYZ0W.js} +1 -1
  45. package/web/assets/{detail-B0IHl4MI.js → detail-CfvKZ7IV.js} +1 -1
  46. package/web/assets/{detail-Ct5QNBqu.js → detail-CmIweOLE.js} +1 -1
  47. package/web/assets/{detail-BXTsnQny.js → detail-D729Bgs6.js} +1 -1
  48. package/web/assets/{detail-C_Zdfa0y.js → detail-DD1YBtex.js} +1 -1
  49. package/web/assets/detail-DOcm4Kqg.js +15 -0
  50. package/web/assets/{detail-Bfnkg0A1.js → detail-DQj1mbhA.js} +1 -1
  51. package/web/assets/detail-DTXDMIR9.js +15 -0
  52. package/web/assets/{detail-CsGZMimg.js → detail-DUAJzKsu.js} +1 -1
  53. package/web/assets/{detail-BwH0DwAi.js → detail-De8PyTyx.js} +1 -1
  54. package/web/assets/{detail-B_lpOomD.js → detail-DqfxOHky.js} +1 -1
  55. package/web/assets/{detail-CMBRd4Ct.js → detail-Dzt5tfyZ.js} +1 -1
  56. package/web/assets/{detail-Tn2R5C8i.js → detail-H0dkKVyS.js} +1 -1
  57. package/web/assets/{detail-CyMhK5K_.js → detail-MgdgGj5J.js} +1 -1
  58. package/web/assets/{detail-DCTb8R7F.js → detail-WAmPM6yq.js} +1 -1
  59. package/web/assets/{detail-B-ceWfZr.js → detail-g6el9Fxj.js} +1 -1
  60. package/web/assets/did-Bqcz-NjH.js +1 -0
  61. package/web/assets/{drawer-form-DspWWj3x.js → drawer-form-CQjNFFWk.js} +1 -1
  62. package/web/assets/{edit-Bkj-OTJh.js → edit-DAU8AWzT.js} +1 -1
  63. package/web/assets/{editor-AmthipP2.js → editor-vZvxDUTl.js} +1 -1
  64. package/web/assets/{embed-rRKjDoHi.js → embed-ClYNqZbf.js} +1 -1
  65. package/web/assets/{filter-toolbar-DXGSTq57.js → filter-toolbar-VvmMATj0.js} +1 -1
  66. package/web/assets/{form-BmQlJZ84.js → form-4_MzglPj.js} +1 -1
  67. package/web/assets/{form-cX026J4G.js → form-AFzUvoFE.js} +1 -1
  68. package/web/assets/{form-B5WW-lS5.js → form-Bro99BjK.js} +1 -1
  69. package/web/assets/{form-CAPjlw7l.js → form-CnrBCyTJ.js} +1 -1
  70. package/web/assets/form-Cuvruf4H.js +16 -0
  71. package/web/assets/{gas-nyR96dB0.js → gas-kw2KMH1u.js} +1 -1
  72. package/web/assets/{generateCategoricalChart-BadryV3H.js → generateCategoricalChart-BCpuUeC_.js} +1 -1
  73. package/web/assets/{home-_eX1aim8.js → home-ZNJREzbw.js} +1 -1
  74. package/web/assets/{index-CbSXdD6E.js → index-ASk8vU2H.js} +1 -1
  75. package/web/assets/{index-ajD9Iotk.js → index-B4n6PvPu.js} +1 -1
  76. package/web/assets/{index-BarN7DfU.js → index-B4yaPb7B.js} +5 -5
  77. package/web/assets/{index-DSe7Dot_.js → index-BHwID_s4.js} +1 -1
  78. package/web/assets/index-BMcnd_jZ.js +1 -0
  79. package/web/assets/{index-BTfJ08JU.js → index-BRmN8ViQ.js} +1 -1
  80. package/web/assets/index-BdbLl6St.js +1 -0
  81. package/web/assets/{index-CCVDDX0c.js → index-BjKRyxNQ.js} +1 -1
  82. package/web/assets/index-BjLJQRKY.js +1 -0
  83. package/web/assets/index-BkNCPnTn.js +1 -0
  84. package/web/assets/index-BlAwTTmu.js +1 -0
  85. package/web/assets/{index-C136x0O2.js → index-BtWfmATr.js} +1 -1
  86. package/web/assets/{index-DNGmCIRP.js → index-C-5n472s.js} +1 -1
  87. package/web/assets/{index-CW8VfoJO.js → index-C3AP4jq0.js} +1 -1
  88. package/web/assets/{index-C-RT84yb.js → index-C3Rh1SaB.js} +1 -1
  89. package/web/assets/index-CDyxbCzc.js +1 -0
  90. package/web/assets/{index-SOzRg0yJ.js → index-CH_k9MVv.js} +1 -1
  91. package/web/assets/{index-XaFn2ySq.js → index-CKPfOW6M.js} +1 -1
  92. package/web/assets/{index-BQjlhCSt.js → index-CPFlZhA2.js} +1 -1
  93. package/web/assets/{index-Du0Ieh1F.js → index-CPyGjEd3.js} +2 -2
  94. package/web/assets/index-ChC-jsE2.js +1 -0
  95. package/web/assets/{index-D-bx9Kam.js → index-CiWvs3j9.js} +1 -1
  96. package/web/assets/{index-mn5Zdrtn.js → index-D6gv9jHh.js} +1 -1
  97. package/web/assets/{index-Cd_BD9TM.js → index-D7pWd60Z.js} +1 -1
  98. package/web/assets/{index-YG5oc8O3.js → index-DAen2-cr.js} +1 -1
  99. package/web/assets/{index-BRENdB5m.js → index-DNobX-Tr.js} +1 -1
  100. package/web/assets/{index-Kd_qCyRG.js → index-DY-g0BPU.js} +1 -1
  101. package/web/assets/{index-D0mynT6_.js → index-DZkpxY-C.js} +1 -1
  102. package/web/assets/{index-DcddP3R9.js → index-Dh9agU9O.js} +1 -1
  103. package/web/assets/{index-BBHMsIxJ.js → index-Dju8k6mq.js} +1 -1
  104. package/web/assets/{index-DeK5Pqjv.js → index-DwDNPqjF.js} +1 -1
  105. package/web/assets/{index-DEiuhiEo.js → index-Dze0CpfQ.js} +1 -1
  106. package/web/assets/{index-UYeD8rTJ.js → index-eDERHpkr.js} +1 -1
  107. package/web/assets/{index-BzABukCz.js → index-mgPU1lyd.js} +1 -1
  108. package/web/assets/{index-W2uZUlFs.js → index-olGOY5KB.js} +1 -1
  109. package/web/assets/{index-DoX0A-rP.js → index-oy7LrXGT.js} +1 -1
  110. package/web/assets/{index-qulrJQ4J.js → index-x7sBb6oM.js} +1 -1
  111. package/web/assets/{index.es-C8dcCHdW.js → index.es-C2Q6Owow.js} +1 -1
  112. package/web/assets/{info-card-BvIMFQo5.js → info-card-C9dRgztS.js} +1 -1
  113. package/web/assets/{info-metric-Dl4ZDm0Z.js → info-metric-ukWq8INi.js} +1 -1
  114. package/web/assets/{info-row-jI0h_hv4.js → info-row-CaPaNF4L.js} +1 -1
  115. package/web/assets/{info-row-group-CFuMWJf1.js → info-row-group-Cxo-4Gk5.js} +1 -1
  116. package/web/assets/{libphonenumber-Qs8PCdM-.js → libphonenumber-CTvobi0D.js} +1 -1
  117. package/web/assets/{link-CmPoIweR.js → link-DsltSF2Q.js} +1 -1
  118. package/web/assets/{list-CkHExntK.js → list-B2b-s8wM.js} +1 -1
  119. package/web/assets/{list-DLB_hd0Q.js → list-BzgF4i3i.js} +1 -1
  120. package/web/assets/{list-BdSkPjIa.js → list-Cd1O-aDi.js} +1 -1
  121. package/web/assets/{list-DaK9287Y.js → list-CvM46TsP.js} +1 -1
  122. package/web/assets/{list-CWMEf-_C.js → list-DtEjqlED.js} +1 -1
  123. package/web/assets/{list-DVFJwd_I.js → list-O_uCSLFq.js} +1 -1
  124. package/web/assets/{list-DghnUOc4.js → list-YNWVqjwW.js} +1 -1
  125. package/web/assets/{list-eFkvVlp5.js → list-ZaBapEXW.js} +1 -1
  126. package/web/assets/{metadata-BmQTVFku.js → metadata-_hV0ZaVh.js} +1 -1
  127. package/web/assets/{meter-event-B1JIhVpb.js → meter-event-CPVBpekF.js} +1 -1
  128. package/web/assets/{metrics-UvxyQbUF.js → metrics-DVPdwpyf.js} +1 -1
  129. package/web/assets/{overview-Cxc6WKba.js → overview-CGdVIJrJ.js} +1 -1
  130. package/web/assets/{overview-DrMaIptb.js → overview-CN59I5Sc.js} +1 -1
  131. package/web/assets/{past-due-CUXkxns0.js → past-due-C3PtU8uo.js} +1 -1
  132. package/web/assets/pay-XVdSNq__.js +4 -0
  133. package/web/assets/{payment-method-info-Bsf89VxV.js → payment-method-info-D_qR04xC.js} +1 -1
  134. package/web/assets/{preview-C-H8pGVw.js → preview-Bdtbh-xk.js} +1 -1
  135. package/web/assets/{preview-BifsgUGT.js → preview-F3lma170.js} +1 -1
  136. package/web/assets/{pricing-table-BUJdtkMq.js → pricing-table-Bt2WljzE.js} +1 -1
  137. package/web/assets/{pricing-table-B3QOaAB5.js → pricing-table-D9FGYBVa.js} +1 -1
  138. package/web/assets/{product-select-ChEyoJqJ.js → product-select-_72p-5lF.js} +1 -1
  139. package/web/assets/{recharge-BVT4USAO.js → recharge-CSlKshbU.js} +1 -1
  140. package/web/assets/{related-credit-grants-JV2ICsR5.js → related-credit-grants-DnKdAit6.js} +3 -3
  141. package/web/assets/{safe-did-address-CiG_V6Gy.js → safe-did-address-CRTPYo34.js} +1 -1
  142. package/web/assets/{source-data-viewer-i1q9wNIG.js → source-data-viewer-D1GShrs5.js} +1 -1
  143. package/web/assets/{status-CUVYrUIG.js → status-3Swm2gK5.js} +1 -1
  144. package/web/assets/subscription-BX00k6FU.js +1 -0
  145. package/web/assets/{subscription-DrnSPIfs.js → subscription-Bzeblscr.js} +1 -1
  146. package/web/assets/table-BN3WBnr3.js +1 -0
  147. package/web/assets/{tax-code-select-TS07I0rB.js → tax-code-select-j2arPbaE.js} +1 -1
  148. package/web/assets/{tax-utils-bPjALcVG.js → tax-utils-B8J0Kfnz.js} +1 -1
  149. package/web/assets/{uploader-CsQNHG4I.js → uploader-BLdAbLR6.js} +1 -1
  150. package/web/assets/{usage-records-DAUQMJAW.js → usage-records-BAwNs1y8.js} +1 -1
  151. package/web/assets/{util-DxXTXkeY.js → util-B8B3fsMa.js} +1 -1
  152. package/web/assets/{vendor-arcblock-BTCAQSUK.js → vendor-arcblock-D1drrE7q.js} +1 -1
  153. package/web/assets/{vendor-blocklet-DcLR2Cyf.js → vendor-blocklet-B67R14so.js} +2 -2
  154. package/web/index.html +1 -1
  155. package/web/assets/browser-DDv4_sgY.js +0 -1
  156. package/web/assets/detail-B8eOBVSQ.js +0 -15
  157. package/web/assets/detail-BO3zglCn.js +0 -15
  158. package/web/assets/detail-C1FupF1D.js +0 -24
  159. package/web/assets/detail-wU4wNf4s.js +0 -10
  160. package/web/assets/form-DD-EiA7W.js +0 -16
  161. package/web/assets/index-BhcoukR2.js +0 -1
  162. package/web/assets/index-BturOfxo.js +0 -1
  163. package/web/assets/index-CDVogp6E.js +0 -1
  164. package/web/assets/index-DcrGSDby.js +0 -1
  165. package/web/assets/index-Dybqd298.js +0 -1
  166. package/web/assets/index-EXZPddtw.js +0 -1
  167. package/web/assets/index-brUCsnBA.js +0 -1
  168. package/web/assets/pay-omLYkqRA.js +0 -4
  169. package/web/assets/subscription-BYz_k9dq.js +0 -1
  170. package/web/assets/table-BrtHemkA.js +0 -1
package/dist/index.js CHANGED
@@ -6642,6 +6642,23 @@ var init_customer = __esm({
6642
6642
  });
6643
6643
 
6644
6644
  // ../../blocklets/core/api/src/middlewares/hono/security.ts
6645
+ function stripDidPrefix(did) {
6646
+ if (!did) return "";
6647
+ return did.startsWith("did:abt:") ? did.slice("did:abt:".length) : did;
6648
+ }
6649
+ function isSameDid(a, b) {
6650
+ const x = stripDidPrefix(a);
6651
+ const y = stripDidPrefix(b);
6652
+ return !!x && x === y;
6653
+ }
6654
+ async function findCustomerByEitherDid(did) {
6655
+ if (!did) return null;
6656
+ const bare = stripDidPrefix(did);
6657
+ if (!bare) return null;
6658
+ const prefixed = `did:abt:${bare}`;
6659
+ const found = await Customer.findOne({ where: { did: [bare, prefixed] } });
6660
+ return found;
6661
+ }
6645
6662
  function authenticate({
6646
6663
  component: component4,
6647
6664
  roles,
@@ -6757,7 +6774,7 @@ function authenticate({
6757
6774
  return next();
6758
6775
  }
6759
6776
  if (mine) {
6760
- const customer = await Customer.findOne({ where: { did: user4.did } });
6777
+ const customer = await findCustomerByEitherDid(user4.did);
6761
6778
  if (customer) {
6762
6779
  c.set("customer", customer);
6763
6780
  c.set("customer_id", customer.id);
@@ -6769,7 +6786,7 @@ function authenticate({
6769
6786
  const id = c.req.param("id");
6770
6787
  const doc = findById && typeof findById === "function" ? await findById(id) : await model.findByPk(id);
6771
6788
  if (doc && doc[field]) {
6772
- const customer = await Customer.findOne({ where: { did: user4.did } });
6789
+ const customer = await findCustomerByEitherDid(user4.did);
6773
6790
  c.set("doc", doc);
6774
6791
  c.set("customer", customer);
6775
6792
  if (customer && customer.id === doc[field]) {
@@ -16328,6 +16345,7 @@ async function ensureStakedForGas() {
16328
16345
  logger_default.info(`app already staked for gas on chain ${host}`, { source: stakeResult.source });
16329
16346
  continue;
16330
16347
  }
16348
+ await client.getContext();
16331
16349
  const result = await client.getForgeState({});
16332
16350
  const { token, txConfig } = result.state;
16333
16351
  const holding = (account?.tokens || []).find((x) => x.address === token.address);
@@ -33831,7 +33849,7 @@ async function handleSubscriptionEvent(event, _) {
33831
33849
  if (["incomplete", "incomplete_expired"].includes(subscription.status)) {
33832
33850
  logger_default.warn("subscription not ended on stripe event", { id: subscription.id });
33833
33851
  } else {
33834
- await subscription.update({ status: "canceled", ended_at: event.data.object.ended_at });
33852
+ await subscription.update({ status: "canceled", end_at: event.data.object.ended_at });
33835
33853
  logger_default.info("subscription ended on stripe event", { id: subscription.id });
33836
33854
  }
33837
33855
  }
@@ -34484,7 +34502,8 @@ async function handleStripePaymentSucceed(paymentIntent, event) {
34484
34502
  await handlePaymentSucceed(paymentIntent, triggerRenew);
34485
34503
  }
34486
34504
  async function syncStripePayment(paymentIntent) {
34487
- if (!paymentIntent?.metadata?.stripe_id) {
34505
+ const stripePaymentIntentId = paymentIntent?.payment_details?.stripe?.payment_intent_id || paymentIntent?.metadata?.stripe_id;
34506
+ if (!stripePaymentIntentId) {
34488
34507
  return;
34489
34508
  }
34490
34509
  const method = await PaymentMethod.findByPk(paymentIntent.payment_method_id);
@@ -34493,7 +34512,7 @@ async function syncStripePayment(paymentIntent) {
34493
34512
  }
34494
34513
  const triggerRenew = paymentIntent.status !== "succeeded";
34495
34514
  const client = await method.getStripeClient();
34496
- const stripeIntent = await client.paymentIntents.retrieve(paymentIntent.metadata.stripe_id);
34515
+ const stripeIntent = await client.paymentIntents.retrieve(stripePaymentIntentId);
34497
34516
  if (stripeIntent) {
34498
34517
  await paymentIntent.update({
34499
34518
  amount: String(stripeIntent.amount),
@@ -42636,6 +42655,85 @@ var init_url = __esm({
42636
42655
  }
42637
42656
  });
42638
42657
 
42658
+ // ../../blocklets/core/api/src/integrations/stripe/reconcile-checkout-core.ts
42659
+ async function reconcileStripeCheckoutSessionWithDeps(sessionId, deps) {
42660
+ const checkoutSession = await deps.findCheckoutSession(sessionId);
42661
+ if (!checkoutSession) {
42662
+ throw new Error("Checkout session not found");
42663
+ }
42664
+ if (checkoutSession.status === "complete") {
42665
+ return {
42666
+ status: checkoutSession.status,
42667
+ paymentStatus: checkoutSession.payment_status,
42668
+ reconciled: false
42669
+ };
42670
+ }
42671
+ let reconciled = false;
42672
+ if (checkoutSession.payment_intent_id) {
42673
+ const paymentIntent = await deps.findPaymentIntent(checkoutSession.payment_intent_id);
42674
+ if (paymentIntent && paymentIntent.status !== "succeeded") {
42675
+ await deps.syncPayment(paymentIntent);
42676
+ reconciled = true;
42677
+ }
42678
+ }
42679
+ const subscriptionIds = deps.getSubscriptionIds(checkoutSession);
42680
+ if (subscriptionIds.length > 0) {
42681
+ const subscriptions = await deps.findSubscriptions(subscriptionIds);
42682
+ for (const subscription of subscriptions) {
42683
+ if (subscription.status === "incomplete") {
42684
+ await deps.syncSubscription(subscription);
42685
+ reconciled = true;
42686
+ }
42687
+ }
42688
+ }
42689
+ await checkoutSession.reload();
42690
+ return {
42691
+ status: checkoutSession.status,
42692
+ paymentStatus: checkoutSession.payment_status,
42693
+ reconciled
42694
+ };
42695
+ }
42696
+ var init_reconcile_checkout_core = __esm({
42697
+ "../../blocklets/core/api/src/integrations/stripe/reconcile-checkout-core.ts"() {
42698
+ "use strict";
42699
+ }
42700
+ });
42701
+
42702
+ // ../../blocklets/core/api/src/integrations/stripe/reconcile-checkout.ts
42703
+ async function syncSubscription(subscription) {
42704
+ if (!subscription.payment_details?.stripe?.subscription_id) return;
42705
+ const method = await PaymentMethod.findByPk(subscription.default_payment_method_id);
42706
+ if (!method || method.type !== "stripe") return;
42707
+ const remote = await method.getStripeClient().subscriptions.retrieve(subscription.payment_details.stripe.subscription_id, {
42708
+ expand: ["latest_invoice.payment_intent", "pending_setup_intent"]
42709
+ });
42710
+ if (["active", "trialing"].includes(remote.status)) {
42711
+ await handleStripeSubscriptionSucceed(subscription, remote.status);
42712
+ }
42713
+ }
42714
+ function reconcileStripeCheckoutSession(sessionId, deps = defaultDeps) {
42715
+ return reconcileStripeCheckoutSessionWithDeps(sessionId, deps);
42716
+ }
42717
+ var defaultDeps;
42718
+ var init_reconcile_checkout = __esm({
42719
+ "../../blocklets/core/api/src/integrations/stripe/reconcile-checkout.ts"() {
42720
+ "use strict";
42721
+ init_session2();
42722
+ init_models();
42723
+ init_payment_intent2();
42724
+ init_subscription3();
42725
+ init_reconcile_checkout_core();
42726
+ defaultDeps = {
42727
+ findCheckoutSession: (id) => CheckoutSession.findByPk(id),
42728
+ findPaymentIntent: (id) => PaymentIntent.findByPk(id),
42729
+ getSubscriptionIds: getCheckoutSessionSubscriptionIds,
42730
+ findSubscriptions: (ids) => Subscription.findAll({ where: { id: ids } }),
42731
+ syncPayment: syncStripePayment,
42732
+ syncSubscription
42733
+ };
42734
+ }
42735
+ });
42736
+
42639
42737
  // ../../blocklets/core/api/src/routes/hono/checkout-sessions.ts
42640
42738
  async function validateInventory(line_items, includePendingQuantity = false) {
42641
42739
  const checks = line_items.map((item) => async () => {
@@ -43981,6 +44079,7 @@ var init_checkout_sessions = __esm({
43981
44079
  init_token_address_mapping();
43982
44080
  init_sequelize();
43983
44081
  init_session();
44082
+ init_reconcile_checkout();
43984
44083
  app6 = new import_hono6.Hono();
43985
44084
  user2 = sessionMiddleware({ accessKey: true });
43986
44085
  auth6 = authenticate({ component: true, roles: ["owner", "admin"] });
@@ -44297,6 +44396,27 @@ var init_checkout_sessions = __esm({
44297
44396
  paymentIntent: piStatus
44298
44397
  });
44299
44398
  });
44399
+ app6.post("/:id/stripe-reconcile", user2, async (c) => {
44400
+ const currentUser = c.get("user");
44401
+ if (!currentUser) {
44402
+ return c.json({ error: "Unauthorized" }, 403);
44403
+ }
44404
+ const doc = await CheckoutSession.findByPk(c.req.param("id"), {
44405
+ attributes: ["id", "customer_did"]
44406
+ });
44407
+ if (!doc) {
44408
+ return c.json({ error: "Checkout session not found" }, 404);
44409
+ }
44410
+ if (!["owner", "admin"].includes(currentUser.role) && !isSameDid(doc.customer_did, currentUser.did)) {
44411
+ return c.json({ error: "Not authorized to reconcile this checkout session" }, 403);
44412
+ }
44413
+ try {
44414
+ return c.json(await reconcileStripeCheckoutSession(doc.id));
44415
+ } catch (err) {
44416
+ logger_default.error("stripe checkout reconciliation failed", { checkoutSessionId: doc.id, error: err });
44417
+ return c.json({ error: err.message }, 502);
44418
+ }
44419
+ });
44300
44420
  app6.get("/retrieve/:id", user2, async (c) => {
44301
44421
  const doc = await CheckoutSession.findByPk(c.req.param("id"));
44302
44422
  if (!doc) {
@@ -44785,21 +44905,23 @@ var init_checkout_sessions = __esm({
44785
44905
  invoice_prefix: Customer.getInvoicePrefix()
44786
44906
  });
44787
44907
  logger_default.info("customer created on checkout session submit", { did: c.get("user").did, id: customer.id });
44788
- try {
44789
- await blocklet.updateUserAddress(
44790
- {
44791
- did: customer.did,
44792
- address: Customer.formatAddressFromCustomer(customer)
44793
- },
44794
- {
44795
- headers: {
44796
- cookie: c.req.header("cookie") || ""
44908
+ if (isBlockletServer()) {
44909
+ try {
44910
+ await blocklet.updateUserAddress(
44911
+ {
44912
+ did: customer.did,
44913
+ address: Customer.formatAddressFromCustomer(customer)
44914
+ },
44915
+ {
44916
+ headers: {
44917
+ cookie: c.req.header("cookie") || ""
44918
+ }
44797
44919
  }
44798
- }
44799
- );
44800
- logger_default.info("updateUserAddress success", { did: customer.did });
44801
- } catch (err) {
44802
- logger_default.error("updateUserAddress failed", { error: err, customerId: customer.id });
44920
+ );
44921
+ logger_default.info("updateUserAddress success", { did: customer.did });
44922
+ } catch (err) {
44923
+ logger_default.error("updateUserAddress failed", { error: err, customerId: customer.id });
44924
+ }
44803
44925
  }
44804
44926
  } else {
44805
44927
  const updates = {};
@@ -44825,23 +44947,25 @@ var init_checkout_sessions = __esm({
44825
44947
  } else {
44826
44948
  await customer.update(updates);
44827
44949
  logger_default.info("customer updated", { did: customer.did });
44828
- try {
44829
- await blocklet.updateUserAddress(
44830
- {
44831
- did: customer.did,
44832
- address: Customer.formatAddressFromCustomer(customer),
44833
- // @ts-ignore
44834
- phone: customer.phone
44835
- },
44836
- {
44837
- headers: {
44838
- cookie: c.req.header("cookie") || ""
44950
+ if (isBlockletServer()) {
44951
+ try {
44952
+ await blocklet.updateUserAddress(
44953
+ {
44954
+ did: customer.did,
44955
+ address: Customer.formatAddressFromCustomer(customer),
44956
+ // @ts-ignore
44957
+ phone: customer.phone
44958
+ },
44959
+ {
44960
+ headers: {
44961
+ cookie: c.req.header("cookie") || ""
44962
+ }
44839
44963
  }
44840
- }
44841
- );
44842
- logger_default.info("updateUserAddress success", { did: customer.did });
44843
- } catch (err) {
44844
- logger_default.error("updateUserAddress failed", { error: err, customerId: customer.id });
44964
+ );
44965
+ logger_default.info("updateUserAddress success", { did: customer.did });
44966
+ } catch (err) {
44967
+ logger_default.error("updateUserAddress failed", { error: err, customerId: customer.id });
44968
+ }
44845
44969
  }
44846
44970
  }
44847
44971
  }
@@ -58506,12 +58630,14 @@ async function ingestVerifiedAppStorePurchase({
58506
58630
  }
58507
58631
  const newExpiresAt = transaction.expiresDate ? Math.floor(Number(transaction.expiresDate) / 1e3) : 0;
58508
58632
  const newTxnValid = !!newExpiresAt && newExpiresAt * 1e3 > Date.now();
58509
- const lapsed = ["canceled", "incomplete_expired", "past_due"].includes(existing.status);
58633
+ const storedExpiresAt = existing.current_period_end ?? 0;
58634
+ const storedExpired = !!storedExpiresAt && storedExpiresAt * 1e3 < Date.now();
58635
+ const lapsed = ["canceled", "incomplete_expired", "past_due"].includes(existing.status) || storedExpired;
58510
58636
  if (lapsed && newTxnValid) {
58511
58637
  const updatePatch = {
58512
58638
  status: "active",
58513
58639
  current_period_end: newExpiresAt,
58514
- ended_at: null,
58640
+ end_at: null,
58515
58641
  cancel_at_period_end: false,
58516
58642
  payment_details: {
58517
58643
  ...existing.payment_details || {},
@@ -58547,6 +58673,31 @@ async function ingestVerifiedAppStorePurchase({
58547
58673
  });
58548
58674
  return { subscription: existing, isFirstSubscribe: false, transaction };
58549
58675
  }
58676
+ if (lapsed && !newTxnValid) {
58677
+ await existing.update({
58678
+ status: "incomplete_expired",
58679
+ end_at: Math.floor(Date.now() / 1e3),
58680
+ cancel_at_period_end: false,
58681
+ payment_details: {
58682
+ ...existing.payment_details || {},
58683
+ app_store: {
58684
+ ...existing.payment_details?.app_store || {},
58685
+ transaction_id: transaction.transactionId,
58686
+ expires_at: newExpiresAt || existing.payment_details?.app_store?.expires_at
58687
+ }
58688
+ }
58689
+ });
58690
+ logger_default.info(
58691
+ "app_store verify: subscription fully lapsed (stored + replay both expired) \u2014 marked incomplete_expired",
58692
+ {
58693
+ subscriptionId: existing.id,
58694
+ originalTransactionId: transaction.originalTransactionId,
58695
+ storedExpiresAt,
58696
+ newExpiresAt
58697
+ }
58698
+ );
58699
+ return { subscription: existing, isFirstSubscribe: false, transaction };
58700
+ }
58550
58701
  const storedAppStoreSku = existing.payment_details?.app_store?.product_id;
58551
58702
  if (storedAppStoreSku && storedAppStoreSku !== transaction.productId) {
58552
58703
  const newPrice = await Price.findOne({
@@ -58864,7 +59015,7 @@ async function handleAppStoreRenewed(subscription, transaction) {
58864
59015
  }
58865
59016
  async function markAppStoreExpired(subscription) {
58866
59017
  if (["canceled", "incomplete_expired"].includes(subscription.status)) return;
58867
- await subscription.update({ status: "canceled", ended_at: Math.floor(Date.now() / 1e3) });
59018
+ await subscription.update({ status: "canceled", end_at: Math.floor(Date.now() / 1e3) });
58868
59019
  createEvent("Subscription", "customer.subscription.deleted", subscription).catch(reportAuditFailure);
58869
59020
  }
58870
59021
  async function markAppStorePastDue(subscription) {
@@ -58884,7 +59035,7 @@ async function handleAppStoreRevoked(subscription, notificationType, subtype) {
58884
59035
  const now = Math.floor(Date.now() / 1e3);
58885
59036
  await subscription.update({
58886
59037
  status: "canceled",
58887
- ended_at: now,
59038
+ end_at: now,
58888
59039
  cancelation_details: {
58889
59040
  ...subscription.cancelation_details ?? { comment: "", feedback: "other" },
58890
59041
  reason: "cancellation_requested"
@@ -59515,7 +59666,7 @@ async function handleRevoked(subscription) {
59515
59666
  const now = Math.floor(Date.now() / 1e3);
59516
59667
  await subscription.update({
59517
59668
  status: "canceled",
59518
- ended_at: now,
59669
+ end_at: now,
59519
59670
  cancelation_details: {
59520
59671
  ...subscription.cancelation_details ?? { comment: "", feedback: "other" },
59521
59672
  reason: "cancellation_requested"
@@ -59591,7 +59742,7 @@ async function handleGooglePlayVoidedPurchase({
59591
59742
  if (subscription.status !== "canceled" && subscription.status !== "incomplete_expired") {
59592
59743
  await subscription.update({
59593
59744
  status: "canceled",
59594
- ended_at: Math.floor(Date.now() / 1e3),
59745
+ end_at: Math.floor(Date.now() / 1e3),
59595
59746
  cancelation_details: {
59596
59747
  ...subscription.cancelation_details ?? { comment: "", feedback: "other" },
59597
59748
  reason: "cancellation_requested"
@@ -60746,7 +60897,8 @@ async function checkEntitlement({
60746
60897
  channel: await inferChannelFromSubscription(best),
60747
60898
  expires_at: best.current_period_end ?? null,
60748
60899
  subscription_id: best.id,
60749
- source: "subscription"
60900
+ source: "subscription",
60901
+ cancel_at_period_end: !!best.cancel_at_period_end
60750
60902
  };
60751
60903
  }
60752
60904
  const grant = await findGrantCoveringProduct(customer, product_id);
@@ -60828,7 +60980,8 @@ async function listEntitlements({
60828
60980
  channel: await inferChannelFromSubscription(best),
60829
60981
  expires_at: best.current_period_end ?? null,
60830
60982
  subscription_id: best.id,
60831
- source: "subscription"
60983
+ source: "subscription",
60984
+ cancel_at_period_end: !!best.cancel_at_period_end
60832
60985
  };
60833
60986
  return item;
60834
60987
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/payment-service",
3
- "version": "1.29.9",
3
+ "version": "1.29.11",
4
4
  "description": "Embedded payment service factory (W2) — side-effect-free core for arc / blocklet server / standalone worker hosts",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -44,7 +44,7 @@
44
44
  "@blocklet/constant": "^1.17.13-beta-20260613-094425-b81920c8",
45
45
  "@blocklet/error": "^0.3.5",
46
46
  "@blocklet/logger": "^1.17.13-beta-20260613-094425-b81920c8",
47
- "@blocklet/payment-vendor": "1.29.9",
47
+ "@blocklet/payment-vendor": "1.29.11",
48
48
  "@blocklet/sdk": "^1.17.13-beta-20260613-094425-b81920c8",
49
49
  "@blocklet/xss": "^0.15.4",
50
50
  "@hono/node-server": "^2.0.4",
@@ -90,5 +90,5 @@
90
90
  "ts-jest": "^29.1.2",
91
91
  "typescript": "^5.4.3"
92
92
  },
93
- "gitHead": "249bd9bf3c6cc54f77c260edb4b4d3c0be60f126"
93
+ "gitHead": "775c2d6b9624e70d12a3872f46f7b2deb52591ba"
94
94
  }
@@ -1 +1 @@
1
- import{r as s,j as e,B as m,w as pe,x as R,bv as N,A as ge,a3 as i,q as n,N as fe,bL as be,bx as ye,$ as p,bg as I,bl as V,a2 as je,Y as ve,bf as ee}from"./vendor-mui-BXZut9Pz.js";import{e as Ce,b as Re,a as Se}from"./vendor-react-BPknnnEA.js";import{V as we,af as ke,H as X,G as H,Z as q,F as Ae}from"./vendor-blocklet-DcLR2Cyf.js";import{a as Ne,u as Be,i as Ie,a4 as Pe,a8 as Te,f as Ee,e as Z,k as J,l as Fe,G as De}from"./index-BarN7DfU.js";import{R as Me}from"./recharge-BVT4USAO.js";import{g as B,M as K}from"./util-DxXTXkeY.js";import{f as S}from"./dayjs-DUTDpcNU.js";import{u as We}from"./browser-DDv4_sgY.js";import"./table-BrtHemkA.js";import"./lodash-B4Ozcv0x.js";const _e=ee(i)(({theme:t})=>({marginBottom:t.spacing(3),gap:t.spacing(3),flexDirection:"column"})),Q=ee(I)(({theme:t})=>({padding:t.spacing(2),backgroundColor:t.palette.background.paper,border:`1px solid ${t.palette.divider}`,borderRadius:t.shape.borderRadius,marginBottom:t.spacing(2)}));function qe(){const{t,locale:P}=we(),{currencyId:u}=Ce(),[re]=Re(),w=We(),T=re.get("rechargeAddress"),E=Se(),{connect:k}=Ne(),[a,g]=s.useState("50"),[f,te]=s.useState(""),[F,D]=s.useState(!0),[M,W]=s.useState(""),_=s.useRef(null),[h,oe]=s.useState({amount:"0",interval:"month",cycle:1}),[z,se]=s.useState(null),[d,L]=s.useState(!1),[ne,$]=s.useState([]),{session:b}=Be(),[o,ae]=s.useState(null),[O,ce]=s.useState([]),y=T||z?.paymentAddress||b?.user?.did,Y=async()=>{try{if(D(!0),!u){E("/customer");return}const{data:r}=await Z.get(`/api/customers/recharge?currencyId=${u}`);if(r.currency){if(ae(r.currency),ce(r.relatedSubscriptions||[]),r.recommendedRecharge&&r.recommendedRecharge.amount&&r.recommendedRecharge.amount!=="0"){const c=r.recommendedRecharge.amount,v=r.currency.decimal||0,C=A=>{const xe=X(new H(c).mul(new H(String(A))).toString(),v);return Math.ceil(parseFloat(xe)).toString()};oe({amount:X(c,v),interval:r.recommendedRecharge.interval,cycle:r.recommendedRecharge.cycle});const U=[{amount:C(1),multiplier:r.recommendedRecharge.cycle,label:t("common.estimatedDuration",{duration:S(1,r.recommendedRecharge.interval,{t})})},{amount:C(4),multiplier:r.recommendedRecharge.cycle*4,label:t("common.estimatedDuration",{duration:S(4,r.recommendedRecharge.interval,{t})})},{amount:C(8),multiplier:r.recommendedRecharge.cycle*8,label:t("common.estimatedDuration",{duration:S(8,r.recommendedRecharge.interval,{t})})}];$(U);const G=C(4);!d&&!U.find(A=>A.amount===G)&&g(G)}else $([{amount:"10",multiplier:0,label:""},{amount:"50",multiplier:0,label:""},{amount:"100",multiplier:0,label:""}]);if(["arcblock","ethereum","base"].includes(r.currency?.paymentMethod?.type)){const c=await Z.get(`/api/customers/payer-token?currencyId=${u}&payerAddress=${y}`);c?.data&&se(c.data)}}else W(t("customer.balance.currency.notFound"))}catch(r){W(J(r)||t("common.fetchError")),console.error(r)}finally{D(!1)}},j=s.useRef(null);s.useEffect(()=>{Y()},[u]),s.useEffect(()=>{j.current&&o&&setTimeout(()=>{if(j.current){const r=j.current.getBoundingClientRect(),c=window.scrollY+r.top-120;window.scrollTo({top:c,behavior:"smooth"})}},200)},[o,F]);const ie=()=>{o&&(Number.isNaN(Number(a))||k.open({containerEl:void 0,saveConnect:!1,action:"recharge-account",locale:P,prefix:Ae(Fe(),"/api/did"),extraParams:{customerDid:b?.user?.did,currencyId:o.id,amount:Number(a),rechargeAddress:T||b?.user?.did},messages:{scan:t("common.connect.defaultScan"),title:t("customer.recharge.title"),confirm:t("common.connect.confirm")},onSuccess:()=>{k.close(),q.success(t("customer.recharge.success")),Y()},onClose:()=>{k.close()},onError:r=>{q.error(J(r))}}))},le=r=>{const{value:l}=r.target;if(!o||!/^\d*\.?\d*$/.test(l)||l.startsWith(".")||Number(l)>K)return;const c=o.maximum_precision,v=De(l,P,c||6);te(v||""),g(l)},me=r=>{g(r),L(!1)},de=()=>{L(!0),g(""),setTimeout(()=>{_.current?.focus()},0)},ue=r=>{E(`/customer/subscription/${r}`)};if(F)return e.jsx(m,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"50vh"},children:e.jsx(pe,{})});if(!["arcblock","ethereum","base"].includes(o?.paymentMethod?.type||""))return e.jsxs(m,{children:[!w&&e.jsx(R,{startIcon:e.jsx(N,{}),variant:"outlined",onClick:()=>B("/customer"),children:t("common.previous")}),e.jsx(ke,{children:t("customer.recharge.unsupported")})]});if(M)return e.jsxs(m,{children:[!w&&e.jsx(R,{startIcon:e.jsx(N,{}),variant:"outlined",onClick:()=>B("/customer"),children:t("common.previous")}),e.jsx(ge,{severity:"error",sx:{mt:2},children:M})]});const he=Ie(z?.token||"0",o?.decimal||0,6,!1),x=o?.paymentMethod?Pe(o.paymentMethod,y||""):void 0;return e.jsxs(_e,{children:[e.jsx(i,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center",position:"relative"},children:w?e.jsx(m,{}):e.jsx(R,{startIcon:e.jsx(N,{}),variant:"text",color:"inherit",onClick:()=>B("/customer"),sx:{color:"text.secondary"},children:t("common.previous")})}),e.jsxs(n,{variant:"h2",gutterBottom:!0,children:[o?.symbol," ",t("customer.recharge.title")]}),o&&e.jsxs(m,{ref:j,children:[e.jsxs(i,{sx:{maxWidth:"760px"},children:[e.jsxs(m,{sx:{mb:4},children:[e.jsx(Q,{elevation:0,children:e.jsxs(i,{direction:"row",spacing:2,sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(i,{spacing:.5,children:[e.jsx(n,{variant:"body2",sx:{color:"text.secondary"},children:t("customer.recharge.receiveAddress")}),e.jsx(n,{variant:"body1",sx:{wordBreak:"break-all",fontFamily:"monospace"},children:y||t("customer.balance.addressNotFound")})]}),o.logo&&e.jsx(fe,{src:o.logo,alt:o.name,sx:{width:{xs:30,sm:40},height:{xs:30,sm:40}}})]})}),e.jsx(Q,{elevation:0,onClick:()=>x&&window.open(x,"_blank"),sx:{color:"text.primary",borderRadius:1,transition:"all 0.2s ease-in-out",cursor:x?"pointer":"default",position:"relative","&:hover":x?{"& .arrow-icon":{opacity:1,transform:"translateX(0)"}}:void 0},children:e.jsxs(i,{direction:"row",sx:{alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(i,{children:[e.jsxs(n,{variant:"body1",color:"inherit",sx:{display:"flex",alignItems:"center",gap:1,color:"text.secondary"},children:[e.jsx(be,{color:"success",fontSize:"small"}),t("admin.customer.summary.balance")]}),e.jsxs(n,{variant:"h3",sx:{fontWeight:"bold",mt:1,color:"text.primary"},children:[he," ",o.symbol]})]}),x&&e.jsx(ye,{className:"arrow-icon",sx:{opacity:0,transform:"translateX(-10px)",transition:"all 0.2s ease-in-out",color:"inherit",fontSize:30}})]})})]}),e.jsx(i,{sx:{mb:3,backgroundColor:"background.default",borderRadius:"16px"},children:e.jsxs(p,{container:!0,spacing:2,children:[ne.map(({amount:r,label:l,multiplier:c})=>e.jsx(p,{size:{xs:6,sm:3},children:e.jsx(I,{variant:"outlined",sx:{height:"100%",display:"flex",flexDirection:"column",justifyContent:"center",transition:"all 0.2s",cursor:"pointer",borderRadius:"12px","&:hover":{transform:"translateY(-4px)",boxShadow:3},...a===r&&!d?{borderColor:"primary.main",borderWidth:2,backgroundColor:"primary.lighter"}:{}},children:e.jsxs(V,{onClick:()=>me(r),sx:{height:"100%",p:1.5,textAlign:"center"},children:[e.jsxs(n,{variant:"h6",align:"center",sx:{fontWeight:600,color:a===r&&!d?"primary.main":"text.primary"},children:[Te(r)," ",o.symbol]}),c>0&&l&&e.jsx(n,{variant:"caption",align:"center",sx:{color:"text.secondary"},children:l})]})})},r)),e.jsx(p,{size:{xs:6,sm:3},children:e.jsx(I,{variant:"outlined",sx:{height:"100%",display:"flex",flexDirection:"column",justifyContent:"center",transition:"all 0.2s",cursor:"pointer",borderRadius:"12px","&:hover":{transform:"translateY(-4px)",boxShadow:"0 4px 10px rgba(0,0,0,0.1)"},...d?{borderColor:"primary.main",borderWidth:2,backgroundColor:"primary.lighter"}:{}},children:e.jsx(V,{onClick:de,sx:{height:"100%",p:1},children:e.jsx(i,{direction:"row",spacing:1,sx:{justifyContent:"center",alignItems:"center"},children:e.jsx(n,{variant:"h6",align:"center",sx:{fontWeight:600,color:d?"primary.main":"text.primary"},children:t("customer.recharge.custom")||t("common.custom")})})})})})]})}),d&&e.jsxs(m,{sx:{mb:3},children:[e.jsx(je,{fullWidth:!0,label:t("customer.recharge.amount"),variant:"outlined",type:"text",value:a,error:!!f,helperText:f,onChange:le,inputRef:_,autoComplete:"off",slotProps:{input:{endAdornment:e.jsx(n,{children:o.symbol})},htmlInput:{min:0,max:K}}}),a&&Number(a)>0&&Number(h.amount)>0&&!f&&e.jsx(n,{variant:"body2",sx:{fontSize:12,color:"text.lighter",mt:1},children:t("common.estimatedDuration",{duration:S(Math.floor(Number(a)/Number(h.amount))<1?parseFloat((Number(a)/Number(h.amount)).toFixed(1)):Math.floor(Number(a)/Number(h.amount)),h.interval,{t})})})]}),e.jsx(R,{fullWidth:!0,size:"large",variant:"contained",color:"primary",onClick:ie,disabled:!a||parseFloat(a)<=0||!!f,sx:{mb:4,py:1.5,borderRadius:"8px",boxShadow:"0 4px 10px rgba(0,0,0,0.1)","&:hover":{boxShadow:"0 6px 15px rgba(0,0,0,0.15)",transform:"translateY(-2px)"},transition:"all 0.2s"},children:t("customer.recharge.submit")})]}),O.length>0&&e.jsxs(m,{sx:{mb:3},children:[e.jsx(n,{variant:"h4",gutterBottom:!0,children:t("customer.recharge.relatedSubscriptions")}),e.jsx(p,{container:!0,spacing:2,children:O.map(r=>e.jsx(p,{size:{xs:12,sm:6,md:4,lg:3},children:e.jsxs(i,{onClick:()=>ue(r.id),className:"base-card",sx:{height:"100%"},children:[e.jsx(i,{direction:"row",spacing:1.5,sx:{alignItems:"center",mb:1},children:e.jsx(n,{variant:"subtitle1",sx:{fontWeight:"medium",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"text.link",cursor:"pointer"},children:r.description||r.id})}),r.items&&r.items[0]&&o&&e.jsx(n,{variant:"body1",sx:{color:"text.secondary"},children:Ee(r.items[0].price,o,r.items[0].price?.product?.unit_label)})]})},r.id))})]}),e.jsx(ve,{sx:{mb:3}}),e.jsx(n,{variant:"h4",gutterBottom:!0,children:t("customer.recharge.history")}),e.jsx(Me,{currency_id:u,customer_id:b?.user?.did,recharge_address:y})]})]})}export{qe as default};
1
+ import{r as s,j as e,B as m,w as pe,x as R,bv as N,A as ge,a3 as i,q as n,N as fe,bL as be,bx as ye,$ as p,bg as I,bl as V,a2 as je,Y as ve,bf as ee}from"./vendor-mui-BXZut9Pz.js";import{e as Ce,b as Re,a as Se}from"./vendor-react-BPknnnEA.js";import{V as we,af as ke,H as X,G as H,Z as q,F as Ae}from"./vendor-blocklet-B67R14so.js";import{a as Ne,u as Be,i as Ie,a4 as Pe,a8 as Te,f as Ee,e as Z,k as J,l as Fe,G as De}from"./index-B4yaPb7B.js";import{R as Me}from"./recharge-CSlKshbU.js";import{g as B,M as K}from"./util-B8B3fsMa.js";import{f as S}from"./dayjs-DUNWtvju.js";import{u as We}from"./browser-DF2vfpBa.js";import"./table-BN3WBnr3.js";import"./lodash-B4Ozcv0x.js";const _e=ee(i)(({theme:t})=>({marginBottom:t.spacing(3),gap:t.spacing(3),flexDirection:"column"})),Q=ee(I)(({theme:t})=>({padding:t.spacing(2),backgroundColor:t.palette.background.paper,border:`1px solid ${t.palette.divider}`,borderRadius:t.shape.borderRadius,marginBottom:t.spacing(2)}));function qe(){const{t,locale:P}=we(),{currencyId:u}=Ce(),[re]=Re(),w=We(),T=re.get("rechargeAddress"),E=Se(),{connect:k}=Ne(),[a,g]=s.useState("50"),[f,te]=s.useState(""),[F,D]=s.useState(!0),[M,W]=s.useState(""),_=s.useRef(null),[h,oe]=s.useState({amount:"0",interval:"month",cycle:1}),[z,se]=s.useState(null),[d,L]=s.useState(!1),[ne,$]=s.useState([]),{session:b}=Be(),[o,ae]=s.useState(null),[O,ce]=s.useState([]),y=T||z?.paymentAddress||b?.user?.did,Y=async()=>{try{if(D(!0),!u){E("/customer");return}const{data:r}=await Z.get(`/api/customers/recharge?currencyId=${u}`);if(r.currency){if(ae(r.currency),ce(r.relatedSubscriptions||[]),r.recommendedRecharge&&r.recommendedRecharge.amount&&r.recommendedRecharge.amount!=="0"){const c=r.recommendedRecharge.amount,v=r.currency.decimal||0,C=A=>{const xe=X(new H(c).mul(new H(String(A))).toString(),v);return Math.ceil(parseFloat(xe)).toString()};oe({amount:X(c,v),interval:r.recommendedRecharge.interval,cycle:r.recommendedRecharge.cycle});const U=[{amount:C(1),multiplier:r.recommendedRecharge.cycle,label:t("common.estimatedDuration",{duration:S(1,r.recommendedRecharge.interval,{t})})},{amount:C(4),multiplier:r.recommendedRecharge.cycle*4,label:t("common.estimatedDuration",{duration:S(4,r.recommendedRecharge.interval,{t})})},{amount:C(8),multiplier:r.recommendedRecharge.cycle*8,label:t("common.estimatedDuration",{duration:S(8,r.recommendedRecharge.interval,{t})})}];$(U);const G=C(4);!d&&!U.find(A=>A.amount===G)&&g(G)}else $([{amount:"10",multiplier:0,label:""},{amount:"50",multiplier:0,label:""},{amount:"100",multiplier:0,label:""}]);if(["arcblock","ethereum","base"].includes(r.currency?.paymentMethod?.type)){const c=await Z.get(`/api/customers/payer-token?currencyId=${u}&payerAddress=${y}`);c?.data&&se(c.data)}}else W(t("customer.balance.currency.notFound"))}catch(r){W(J(r)||t("common.fetchError")),console.error(r)}finally{D(!1)}},j=s.useRef(null);s.useEffect(()=>{Y()},[u]),s.useEffect(()=>{j.current&&o&&setTimeout(()=>{if(j.current){const r=j.current.getBoundingClientRect(),c=window.scrollY+r.top-120;window.scrollTo({top:c,behavior:"smooth"})}},200)},[o,F]);const ie=()=>{o&&(Number.isNaN(Number(a))||k.open({containerEl:void 0,saveConnect:!1,action:"recharge-account",locale:P,prefix:Ae(Fe(),"/api/did"),extraParams:{customerDid:b?.user?.did,currencyId:o.id,amount:Number(a),rechargeAddress:T||b?.user?.did},messages:{scan:t("common.connect.defaultScan"),title:t("customer.recharge.title"),confirm:t("common.connect.confirm")},onSuccess:()=>{k.close(),q.success(t("customer.recharge.success")),Y()},onClose:()=>{k.close()},onError:r=>{q.error(J(r))}}))},le=r=>{const{value:l}=r.target;if(!o||!/^\d*\.?\d*$/.test(l)||l.startsWith(".")||Number(l)>K)return;const c=o.maximum_precision,v=De(l,P,c||6);te(v||""),g(l)},me=r=>{g(r),L(!1)},de=()=>{L(!0),g(""),setTimeout(()=>{_.current?.focus()},0)},ue=r=>{E(`/customer/subscription/${r}`)};if(F)return e.jsx(m,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"50vh"},children:e.jsx(pe,{})});if(!["arcblock","ethereum","base"].includes(o?.paymentMethod?.type||""))return e.jsxs(m,{children:[!w&&e.jsx(R,{startIcon:e.jsx(N,{}),variant:"outlined",onClick:()=>B("/customer"),children:t("common.previous")}),e.jsx(ke,{children:t("customer.recharge.unsupported")})]});if(M)return e.jsxs(m,{children:[!w&&e.jsx(R,{startIcon:e.jsx(N,{}),variant:"outlined",onClick:()=>B("/customer"),children:t("common.previous")}),e.jsx(ge,{severity:"error",sx:{mt:2},children:M})]});const he=Ie(z?.token||"0",o?.decimal||0,6,!1),x=o?.paymentMethod?Pe(o.paymentMethod,y||""):void 0;return e.jsxs(_e,{children:[e.jsx(i,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center",position:"relative"},children:w?e.jsx(m,{}):e.jsx(R,{startIcon:e.jsx(N,{}),variant:"text",color:"inherit",onClick:()=>B("/customer"),sx:{color:"text.secondary"},children:t("common.previous")})}),e.jsxs(n,{variant:"h2",gutterBottom:!0,children:[o?.symbol," ",t("customer.recharge.title")]}),o&&e.jsxs(m,{ref:j,children:[e.jsxs(i,{sx:{maxWidth:"760px"},children:[e.jsxs(m,{sx:{mb:4},children:[e.jsx(Q,{elevation:0,children:e.jsxs(i,{direction:"row",spacing:2,sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(i,{spacing:.5,children:[e.jsx(n,{variant:"body2",sx:{color:"text.secondary"},children:t("customer.recharge.receiveAddress")}),e.jsx(n,{variant:"body1",sx:{wordBreak:"break-all",fontFamily:"monospace"},children:y||t("customer.balance.addressNotFound")})]}),o.logo&&e.jsx(fe,{src:o.logo,alt:o.name,sx:{width:{xs:30,sm:40},height:{xs:30,sm:40}}})]})}),e.jsx(Q,{elevation:0,onClick:()=>x&&window.open(x,"_blank"),sx:{color:"text.primary",borderRadius:1,transition:"all 0.2s ease-in-out",cursor:x?"pointer":"default",position:"relative","&:hover":x?{"& .arrow-icon":{opacity:1,transform:"translateX(0)"}}:void 0},children:e.jsxs(i,{direction:"row",sx:{alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(i,{children:[e.jsxs(n,{variant:"body1",color:"inherit",sx:{display:"flex",alignItems:"center",gap:1,color:"text.secondary"},children:[e.jsx(be,{color:"success",fontSize:"small"}),t("admin.customer.summary.balance")]}),e.jsxs(n,{variant:"h3",sx:{fontWeight:"bold",mt:1,color:"text.primary"},children:[he," ",o.symbol]})]}),x&&e.jsx(ye,{className:"arrow-icon",sx:{opacity:0,transform:"translateX(-10px)",transition:"all 0.2s ease-in-out",color:"inherit",fontSize:30}})]})})]}),e.jsx(i,{sx:{mb:3,backgroundColor:"background.default",borderRadius:"16px"},children:e.jsxs(p,{container:!0,spacing:2,children:[ne.map(({amount:r,label:l,multiplier:c})=>e.jsx(p,{size:{xs:6,sm:3},children:e.jsx(I,{variant:"outlined",sx:{height:"100%",display:"flex",flexDirection:"column",justifyContent:"center",transition:"all 0.2s",cursor:"pointer",borderRadius:"12px","&:hover":{transform:"translateY(-4px)",boxShadow:3},...a===r&&!d?{borderColor:"primary.main",borderWidth:2,backgroundColor:"primary.lighter"}:{}},children:e.jsxs(V,{onClick:()=>me(r),sx:{height:"100%",p:1.5,textAlign:"center"},children:[e.jsxs(n,{variant:"h6",align:"center",sx:{fontWeight:600,color:a===r&&!d?"primary.main":"text.primary"},children:[Te(r)," ",o.symbol]}),c>0&&l&&e.jsx(n,{variant:"caption",align:"center",sx:{color:"text.secondary"},children:l})]})})},r)),e.jsx(p,{size:{xs:6,sm:3},children:e.jsx(I,{variant:"outlined",sx:{height:"100%",display:"flex",flexDirection:"column",justifyContent:"center",transition:"all 0.2s",cursor:"pointer",borderRadius:"12px","&:hover":{transform:"translateY(-4px)",boxShadow:"0 4px 10px rgba(0,0,0,0.1)"},...d?{borderColor:"primary.main",borderWidth:2,backgroundColor:"primary.lighter"}:{}},children:e.jsx(V,{onClick:de,sx:{height:"100%",p:1},children:e.jsx(i,{direction:"row",spacing:1,sx:{justifyContent:"center",alignItems:"center"},children:e.jsx(n,{variant:"h6",align:"center",sx:{fontWeight:600,color:d?"primary.main":"text.primary"},children:t("customer.recharge.custom")||t("common.custom")})})})})})]})}),d&&e.jsxs(m,{sx:{mb:3},children:[e.jsx(je,{fullWidth:!0,label:t("customer.recharge.amount"),variant:"outlined",type:"text",value:a,error:!!f,helperText:f,onChange:le,inputRef:_,autoComplete:"off",slotProps:{input:{endAdornment:e.jsx(n,{children:o.symbol})},htmlInput:{min:0,max:K}}}),a&&Number(a)>0&&Number(h.amount)>0&&!f&&e.jsx(n,{variant:"body2",sx:{fontSize:12,color:"text.lighter",mt:1},children:t("common.estimatedDuration",{duration:S(Math.floor(Number(a)/Number(h.amount))<1?parseFloat((Number(a)/Number(h.amount)).toFixed(1)):Math.floor(Number(a)/Number(h.amount)),h.interval,{t})})})]}),e.jsx(R,{fullWidth:!0,size:"large",variant:"contained",color:"primary",onClick:ie,disabled:!a||parseFloat(a)<=0||!!f,sx:{mb:4,py:1.5,borderRadius:"8px",boxShadow:"0 4px 10px rgba(0,0,0,0.1)","&:hover":{boxShadow:"0 6px 15px rgba(0,0,0,0.15)",transform:"translateY(-2px)"},transition:"all 0.2s"},children:t("customer.recharge.submit")})]}),O.length>0&&e.jsxs(m,{sx:{mb:3},children:[e.jsx(n,{variant:"h4",gutterBottom:!0,children:t("customer.recharge.relatedSubscriptions")}),e.jsx(p,{container:!0,spacing:2,children:O.map(r=>e.jsx(p,{size:{xs:12,sm:6,md:4,lg:3},children:e.jsxs(i,{onClick:()=>ue(r.id),className:"base-card",sx:{height:"100%"},children:[e.jsx(i,{direction:"row",spacing:1.5,sx:{alignItems:"center",mb:1},children:e.jsx(n,{variant:"subtitle1",sx:{fontWeight:"medium",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"text.link",cursor:"pointer"},children:r.description||r.id})}),r.items&&r.items[0]&&o&&e.jsx(n,{variant:"body1",sx:{color:"text.secondary"},children:Ee(r.items[0].price,o,r.items[0].price?.product?.unit_label)})]})},r.id))})]}),e.jsx(ve,{sx:{mb:3}}),e.jsx(n,{variant:"h4",gutterBottom:!0,children:t("customer.recharge.history")}),e.jsx(Me,{currency_id:u,customer_id:b?.user?.did,recharge_address:y})]})]})}export{qe as default};
@@ -1 +1 @@
1
- import{j as r}from"./vendor-mui-BXZut9Pz.js";import{V as C,Y as x,P as j,Z as c}from"./vendor-blocklet-DcLR2Cyf.js";import{I as u,e as d,k as A}from"./index-BarN7DfU.js";import{A as w}from"./actions-BJDN6Op2.js";import{C as $}from"./click-boundary-CafubiPp.js";import{a as I}from"./vendor-react-BPknnnEA.js";const R=i=>d.get(`/api/invoices/${i}/return-stake`).then(s=>s.data);function q({data:i,variant:s="compact",onChange:y,mode:b="admin"}){const{t:e}=C(),l=I(),[t,n]=x({action:"",loading:!1}),g=["stake","stake_overdraft_protection"].includes(i.billing_reason),h=i.status==="paid",a=b==="admin",v=a&&g&&h&&i.paymentMethod?.type==="arcblock",{data:p={value:"0"},runAsync:k}=j(()=>v?R(i.id):Promise.resolve({value:"0"}),{manual:!0}),m=async()=>{try{if(n({loading:!0}),t.action==="return-stake"){const o=await d.post(`/api/invoices/${i.id}/return-stake`).then(S=>S.data);o.success?c.success(e("admin.invoice.returnStake.success")):c.error(o.error)}t.action==="retry-uncollectible"&&(await d.get("/api/invoices/retry-uncollectible",{params:{invoiceId:i.id}}).then(o=>o.data),c.success(e("admin.invoice.retryUncollectible.success"))),t.action==="void"&&(await d.post(`/api/invoices/${i.id}/void`).then(o=>o.data),c.success(e("admin.invoice.void.success"))),y(t.action)}catch(o){console.error(o),c.error(A(o))}finally{n({loading:!1,action:""})}},f=[a&&{label:e("admin.invoice.edit"),handler:()=>n({action:"edit"}),color:"primary",disabled:i.status!=="draft"},a&&{label:e("admin.invoice.duplicate"),handler:()=>n({action:"duplicate"}),color:"primary",disabled:i.status!=="draft",divider:!0},a&&i.status==="uncollectible"&&{label:e("admin.invoice.retryUncollectible.title"),handler:()=>n({action:"retry-uncollectible"}),color:"primary"},v&&p&&p.value!=="0"&&{label:e("admin.invoice.returnStake.title"),handler:()=>n({action:"return-stake"}),color:"primary",divider:!0},a&&!["paid","void","draft"].includes(i.status)&&{label:e("admin.invoice.void.title"),handler:()=>n({action:"void"}),color:"primary",divider:!0},{label:e("admin.customer.view"),handler:()=>{l(a?`/admin/customers/${i.customer_id}`:"/customer")},color:"primary"}].filter(Boolean);return s==="compact"&&f.push({label:e("admin.invoice.view"),handler:()=>{l(a?`/admin/billing/${i.id}`:`/customer/invoice/${i.id}`)},color:"primary"}),r.jsxs($,{children:[r.jsx(w,{variant:s,actions:f,onOpenCallback:k}),t.action==="retry-uncollectible"&&r.jsx(u,{onConfirm:m,onCancel:()=>n({action:""}),title:e("admin.invoice.retryUncollectible.title"),message:e("admin.invoice.retryUncollectible.tip"),loading:t.loading,color:"primary"}),t.action==="return-stake"&&r.jsx(u,{onConfirm:m,onCancel:()=>n({action:""}),title:e("admin.invoice.returnStake.title"),message:e("admin.invoice.returnStake.tip"),loading:t.loading}),t.action==="void"&&r.jsx(u,{onConfirm:m,onCancel:()=>n({action:""}),title:e("admin.invoice.void.title"),message:e("admin.invoice.void.tip"),loading:t.loading})]})}export{q as I};
1
+ import{j as r}from"./vendor-mui-BXZut9Pz.js";import{V as C,Y as x,P as j,Z as c}from"./vendor-blocklet-B67R14so.js";import{I as u,e as d,k as A}from"./index-B4yaPb7B.js";import{A as w}from"./actions-BEUwbsq1.js";import{C as $}from"./click-boundary-Bi28Y0Fq.js";import{a as I}from"./vendor-react-BPknnnEA.js";const R=i=>d.get(`/api/invoices/${i}/return-stake`).then(s=>s.data);function q({data:i,variant:s="compact",onChange:y,mode:b="admin"}){const{t:e}=C(),l=I(),[t,n]=x({action:"",loading:!1}),g=["stake","stake_overdraft_protection"].includes(i.billing_reason),h=i.status==="paid",a=b==="admin",v=a&&g&&h&&i.paymentMethod?.type==="arcblock",{data:p={value:"0"},runAsync:k}=j(()=>v?R(i.id):Promise.resolve({value:"0"}),{manual:!0}),m=async()=>{try{if(n({loading:!0}),t.action==="return-stake"){const o=await d.post(`/api/invoices/${i.id}/return-stake`).then(S=>S.data);o.success?c.success(e("admin.invoice.returnStake.success")):c.error(o.error)}t.action==="retry-uncollectible"&&(await d.get("/api/invoices/retry-uncollectible",{params:{invoiceId:i.id}}).then(o=>o.data),c.success(e("admin.invoice.retryUncollectible.success"))),t.action==="void"&&(await d.post(`/api/invoices/${i.id}/void`).then(o=>o.data),c.success(e("admin.invoice.void.success"))),y(t.action)}catch(o){console.error(o),c.error(A(o))}finally{n({loading:!1,action:""})}},f=[a&&{label:e("admin.invoice.edit"),handler:()=>n({action:"edit"}),color:"primary",disabled:i.status!=="draft"},a&&{label:e("admin.invoice.duplicate"),handler:()=>n({action:"duplicate"}),color:"primary",disabled:i.status!=="draft",divider:!0},a&&i.status==="uncollectible"&&{label:e("admin.invoice.retryUncollectible.title"),handler:()=>n({action:"retry-uncollectible"}),color:"primary"},v&&p&&p.value!=="0"&&{label:e("admin.invoice.returnStake.title"),handler:()=>n({action:"return-stake"}),color:"primary",divider:!0},a&&!["paid","void","draft"].includes(i.status)&&{label:e("admin.invoice.void.title"),handler:()=>n({action:"void"}),color:"primary",divider:!0},{label:e("admin.customer.view"),handler:()=>{l(a?`/admin/customers/${i.customer_id}`:"/customer")},color:"primary"}].filter(Boolean);return s==="compact"&&f.push({label:e("admin.invoice.view"),handler:()=>{l(a?`/admin/billing/${i.id}`:`/customer/invoice/${i.id}`)},color:"primary"}),r.jsxs($,{children:[r.jsx(w,{variant:s,actions:f,onOpenCallback:k}),t.action==="retry-uncollectible"&&r.jsx(u,{onConfirm:m,onCancel:()=>n({action:""}),title:e("admin.invoice.retryUncollectible.title"),message:e("admin.invoice.retryUncollectible.tip"),loading:t.loading,color:"primary"}),t.action==="return-stake"&&r.jsx(u,{onConfirm:m,onCancel:()=>n({action:""}),title:e("admin.invoice.returnStake.title"),message:e("admin.invoice.returnStake.tip"),loading:t.loading}),t.action==="void"&&r.jsx(u,{onConfirm:m,onCancel:()=>n({action:""}),title:e("admin.invoice.void.title"),message:e("admin.invoice.void.tip"),loading:t.loading})]})}export{q as I};
@@ -1 +1 @@
1
- import{j as n,a3 as w,x as h,w as j}from"./vendor-mui-BXZut9Pz.js";import{V as x,$ as k,Y as T,Z as c,_ as C,F as f}from"./vendor-blocklet-DcLR2Cyf.js";import{h as S,F as A,aX as F,I as v,e as g,k as b}from"./index-BarN7DfU.js";import{A as P}from"./actions-BJDN6Op2.js";import{C as $}from"./click-boundary-CafubiPp.js";import{A as L}from"./assign-0vMUDW_C.js";function R({data:r,loading:s,onSave:l,onCancel:a}){const{t:e}=x(),i=S({defaultValues:{name:r.name}}),{handleSubmit:m,reset:d}=i,p=()=>{m(async u=>{await l(u),d(),a(null)})()};return n.jsx(k,{open:!0,disableEscapeKeyDown:!0,fullWidth:!0,maxWidth:"sm",className:"base-dialog",onClose:()=>a(null),showCloseButton:!1,title:e("admin.pricingTable.rename"),actions:n.jsxs(w,{direction:"row",children:[n.jsx(h,{size:"small",sx:{mr:2},onClick:a,children:e("common.cancel")}),n.jsxs(h,{variant:"contained",color:"primary",size:"small",disabled:s,onClick:p,children:[s&&n.jsx(j,{size:"small"})," ",e("common.save")]})]}),children:n.jsx(A,{...i,children:n.jsx(F,{name:"name",rules:{required:!0},label:e("admin.pricingTable.name.label"),placeholder:e("admin.pricingTable.name.placeholder"),autoFocus:!0})})})}function V({data:r,variant:s="compact",onChange:l}){const{t:a}=x(),[e,i]=T({action:"",loading:!1}),m=async o=>{try{i({loading:!0}),await g.put(`/api/pricing-tables/${r.id}`,o).then(t=>t.data),c.success(a("common.saved")),l(e.action)}catch(t){console.error(t),c.error(b(t))}finally{i({loading:!1,action:""})}},d=async()=>{try{i({loading:!0}),await g.put(`/api/pricing-tables/${r.id}/archive`).then(o=>o.data),c.success(a("common.saved")),l(e.action)}catch(o){console.error(o),c.error(b(o))}finally{i({loading:!1,action:""})}},p=async()=>{try{i({loading:!0}),await g.delete(`/api/pricing-tables/${r.id}`).then(o=>o.data),c.success(a("common.removed")),l(e.action)}catch(o){console.error(o),c.error(b(o))}finally{i({loading:!1,action:""})}},u=()=>{C(f(window.blocklet.appUrl,window.blocklet.prefix,`/checkout/pricing-table/${r.id}`)),c.success(a("common.copied"))},y=()=>{window.open(f(window.blocklet.appUrl,window.blocklet.prefix,`/checkout/pricing-table/${r.id}`),"_blank")};return n.jsxs($,{children:[n.jsx(P,{variant:s,actions:[{label:a("admin.pricingTable.openLink"),handler:y,color:"primary"},{label:a("admin.pricingTable.copyLink"),handler:u,color:"primary"},{label:a("admin.pricingTable.rename"),handler:()=>i({action:"rename"}),color:"primary"},{label:a("admin.pricingTable.archive"),handler:()=>i({action:"archive"}),color:"primary"},{label:a("admin.pricingTable.remove"),handler:()=>i({action:"remove"}),color:"error",divider:!0},{label:a("admin.passport.assign"),handler:()=>i({action:"assign"}),color:"primary",disabled:!r.active}]}),e.action==="rename"&&n.jsx(R,{data:r,loading:e.loading,onSave:m,onCancel:()=>i({action:""})}),e.action==="assign"&&n.jsx(L,{id:r.id,onCancel:()=>i({action:""})}),e.action==="archive"&&n.jsx(v,{onConfirm:d,onCancel:()=>i({action:""}),title:a("admin.pricingTable.archive"),message:a("admin.pricingTable.archiveTip"),loading:e.loading}),e.action==="remove"&&n.jsx(v,{onConfirm:p,onCancel:()=>i({action:""}),title:a("admin.pricingTable.remove"),message:a("admin.pricingTable.removeTip"),loading:e.loading})]})}export{V as P};
1
+ import{j as n,a3 as w,x as h,w as j}from"./vendor-mui-BXZut9Pz.js";import{V as x,$ as k,Y as T,Z as c,_ as C,F as f}from"./vendor-blocklet-B67R14so.js";import{h as S,F as A,aX as F,I as v,e as g,k as b}from"./index-B4yaPb7B.js";import{A as P}from"./actions-BEUwbsq1.js";import{C as $}from"./click-boundary-Bi28Y0Fq.js";import{A as L}from"./assign-DKRfmN7W.js";function R({data:r,loading:s,onSave:l,onCancel:a}){const{t:e}=x(),i=S({defaultValues:{name:r.name}}),{handleSubmit:m,reset:d}=i,p=()=>{m(async u=>{await l(u),d(),a(null)})()};return n.jsx(k,{open:!0,disableEscapeKeyDown:!0,fullWidth:!0,maxWidth:"sm",className:"base-dialog",onClose:()=>a(null),showCloseButton:!1,title:e("admin.pricingTable.rename"),actions:n.jsxs(w,{direction:"row",children:[n.jsx(h,{size:"small",sx:{mr:2},onClick:a,children:e("common.cancel")}),n.jsxs(h,{variant:"contained",color:"primary",size:"small",disabled:s,onClick:p,children:[s&&n.jsx(j,{size:"small"})," ",e("common.save")]})]}),children:n.jsx(A,{...i,children:n.jsx(F,{name:"name",rules:{required:!0},label:e("admin.pricingTable.name.label"),placeholder:e("admin.pricingTable.name.placeholder"),autoFocus:!0})})})}function V({data:r,variant:s="compact",onChange:l}){const{t:a}=x(),[e,i]=T({action:"",loading:!1}),m=async o=>{try{i({loading:!0}),await g.put(`/api/pricing-tables/${r.id}`,o).then(t=>t.data),c.success(a("common.saved")),l(e.action)}catch(t){console.error(t),c.error(b(t))}finally{i({loading:!1,action:""})}},d=async()=>{try{i({loading:!0}),await g.put(`/api/pricing-tables/${r.id}/archive`).then(o=>o.data),c.success(a("common.saved")),l(e.action)}catch(o){console.error(o),c.error(b(o))}finally{i({loading:!1,action:""})}},p=async()=>{try{i({loading:!0}),await g.delete(`/api/pricing-tables/${r.id}`).then(o=>o.data),c.success(a("common.removed")),l(e.action)}catch(o){console.error(o),c.error(b(o))}finally{i({loading:!1,action:""})}},u=()=>{C(f(window.blocklet.appUrl,window.blocklet.prefix,`/checkout/pricing-table/${r.id}`)),c.success(a("common.copied"))},y=()=>{window.open(f(window.blocklet.appUrl,window.blocklet.prefix,`/checkout/pricing-table/${r.id}`),"_blank")};return n.jsxs($,{children:[n.jsx(P,{variant:s,actions:[{label:a("admin.pricingTable.openLink"),handler:y,color:"primary"},{label:a("admin.pricingTable.copyLink"),handler:u,color:"primary"},{label:a("admin.pricingTable.rename"),handler:()=>i({action:"rename"}),color:"primary"},{label:a("admin.pricingTable.archive"),handler:()=>i({action:"archive"}),color:"primary"},{label:a("admin.pricingTable.remove"),handler:()=>i({action:"remove"}),color:"error",divider:!0},{label:a("admin.passport.assign"),handler:()=>i({action:"assign"}),color:"primary",disabled:!r.active}]}),e.action==="rename"&&n.jsx(R,{data:r,loading:e.loading,onSave:m,onCancel:()=>i({action:""})}),e.action==="assign"&&n.jsx(L,{id:r.id,onCancel:()=>i({action:""})}),e.action==="archive"&&n.jsx(v,{onConfirm:d,onCancel:()=>i({action:""}),title:a("admin.pricingTable.archive"),message:a("admin.pricingTable.archiveTip"),loading:e.loading}),e.action==="remove"&&n.jsx(v,{onConfirm:p,onCancel:()=>i({action:""}),title:a("admin.pricingTable.remove"),message:a("admin.pricingTable.removeTip"),loading:e.loading})]})}export{V as P};
@@ -1 +1 @@
1
- import{r as a,j as e,aJ as v,ad as p,aH as d,a1 as k,x as u,c3 as x,I as C,c2 as y}from"./vendor-mui-BXZut9Pz.js";import{V as z}from"./vendor-blocklet-DcLR2Cyf.js";import{b4 as m}from"./index-BarN7DfU.js";function M(f){const s=Object.assign({variant:"compact",sx:{},onOpenCallback:null},f),{t:h}=z(),[o,i]=a.useState(null),j=!!o,b=a.useRef(null),[g,l]=a.useState(!1),t=n=>{if(m(n),b.current=n.currentTarget,s.onOpenCallback&&typeof s.onOpenCallback=="function"){const r=s.onOpenCallback();r instanceof Promise&&(l(!0),r.finally(()=>{l(!1)}))}i(n.currentTarget)},c=(n,r)=>{m(n),i(null),typeof r=="function"&&r()},O=()=>s.variant==="outlined"?e.jsx(u,{"aria-label":"actions",sx:{minWidth:0,padding:"5px",...s.sx},variant:"outlined",onClick:t,size:"small",children:e.jsx(x,{})}):s.variant==="compact"?e.jsx(C,{"aria-label":"actions",sx:s.sx,"aria-haspopup":"true",onClick:t,size:"small",children:e.jsx(x,{})}):e.jsxs(u,{sx:s.sx,onClick:t,size:"small",variant:"contained",color:"primary",children:[h("common.actions")," ",e.jsx(y,{fontSize:"small"})]});return e.jsxs(e.Fragment,{children:[O(),e.jsx(v,{anchorEl:o,open:j,onClose:c,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:s.actions.map(n=>g?e.jsx(p,{dense:!0,disabled:!0,children:e.jsx(d,{primary:e.jsx(k,{}),slotProps:{primary:{width:"56px"}}})},n.label):e.jsx(p,{divider:!!n.divider,dense:!!n.dense,disabled:!!n.disabled,onClick:r=>c(r,n.handler),children:e.jsx(d,{primary:n.label,slotProps:{primary:{color:n.color}}})},n.label))})]})}export{M as A};
1
+ import{r as a,j as e,aJ as v,ad as p,aH as d,a1 as k,x as u,c3 as x,I as C,c2 as y}from"./vendor-mui-BXZut9Pz.js";import{V as z}from"./vendor-blocklet-B67R14so.js";import{b4 as m}from"./index-B4yaPb7B.js";function M(f){const s=Object.assign({variant:"compact",sx:{},onOpenCallback:null},f),{t:h}=z(),[o,i]=a.useState(null),j=!!o,b=a.useRef(null),[g,l]=a.useState(!1),t=n=>{if(m(n),b.current=n.currentTarget,s.onOpenCallback&&typeof s.onOpenCallback=="function"){const r=s.onOpenCallback();r instanceof Promise&&(l(!0),r.finally(()=>{l(!1)}))}i(n.currentTarget)},c=(n,r)=>{m(n),i(null),typeof r=="function"&&r()},O=()=>s.variant==="outlined"?e.jsx(u,{"aria-label":"actions",sx:{minWidth:0,padding:"5px",...s.sx},variant:"outlined",onClick:t,size:"small",children:e.jsx(x,{})}):s.variant==="compact"?e.jsx(C,{"aria-label":"actions",sx:s.sx,"aria-haspopup":"true",onClick:t,size:"small",children:e.jsx(x,{})}):e.jsxs(u,{sx:s.sx,onClick:t,size:"small",variant:"contained",color:"primary",children:[h("common.actions")," ",e.jsx(y,{fontSize:"small"})]});return e.jsxs(e.Fragment,{children:[O(),e.jsx(v,{anchorEl:o,open:j,onClose:c,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:s.actions.map(n=>g?e.jsx(p,{dense:!0,disabled:!0,children:e.jsx(d,{primary:e.jsx(k,{}),slotProps:{primary:{width:"56px"}}})},n.label):e.jsx(p,{divider:!!n.divider,dense:!!n.dense,disabled:!!n.disabled,onClick:r=>c(r,n.handler),children:e.jsx(d,{primary:n.label,slotProps:{primary:{color:n.color}}})},n.label))})]})}export{M as A};
@@ -1 +1 @@
1
- import{j as n}from"./vendor-mui-BXZut9Pz.js";import{V as g,Y as y,Z as t}from"./vendor-blocklet-DcLR2Cyf.js";import{I as d,e as l,k as m}from"./index-BarN7DfU.js";import{l as x}from"./lodash-B4Ozcv0x.js";import{A as b}from"./actions-BJDN6Op2.js";import{C as j}from"./click-boundary-CafubiPp.js";import{A as C}from"./assign-0vMUDW_C.js";import{E as A}from"./edit-Bkj-OTJh.js";function D({data:e,variant:v="compact",onChange:s}){const p=e.locked||!x.isEmpty(e.prices)&&e.prices.some(a=>a.locked),{t:i}=g(),[r,o]=y({action:"",loading:!1}),h=async a=>{try{o({loading:!0}),await l.put(`/api/products/${e.id}`,a).then(c=>c.data),t.success(i("common.saved")),s(r.action)}catch(c){console.error(c),t.error(m(c))}finally{o({loading:!1,action:""})}},u=async()=>{try{o({loading:!0}),await l.put(`/api/products/${e.id}/archive`).then(a=>a.data),t.success(i("common.saved")),s(r.action)}catch(a){console.error(a),t.error(m(a))}finally{o({loading:!1,action:""})}},f=async()=>{try{o({loading:!0}),await l.delete(`/api/products/${e.id}`).then(a=>a.data),t.success(i("common.removed")),s(r.action)}catch(a){console.error(a),t.error(m(a))}finally{o({loading:!1,action:""})}};return n.jsxs(j,{children:[n.jsx(b,{variant:v,actions:[{label:i("admin.product.edit"),handler:()=>o({action:"edit"}),color:"primary",disabled:!e.active,divider:!0},e.active?{label:i("admin.product.archive"),handler:()=>o({action:"archive"}),color:"primary"}:{label:i("admin.product.unarchive"),handler:()=>o({action:"unarchive"}),color:"primary"},{label:i("admin.product.remove"),handler:()=>o({action:"remove"}),disabled:p,color:p?"text.disabled":"error",divider:!0},{label:i("admin.passport.assign"),handler:()=>o({action:"assign"}),color:"primary",disabled:!e.active}].filter(Boolean)}),r.action==="edit"&&n.jsx(A,{product:e,loading:r.loading,onSave:h,onCancel:()=>o({action:""})}),r.action==="archive"&&n.jsx(d,{onConfirm:u,onCancel:()=>o({action:""}),title:i("admin.product.archive"),message:i("admin.product.archiveTip"),loading:r.loading}),r.action==="unarchive"&&n.jsx(d,{onConfirm:u,onCancel:()=>o({action:""}),title:i("admin.product.unarchive"),message:i("admin.product.unarchiveTip"),loading:r.loading}),r.action==="remove"&&n.jsx(d,{onConfirm:f,onCancel:()=>o({action:""}),title:i("admin.product.remove"),message:i("admin.product.removeTip"),loading:r.loading}),r.action==="assign"&&n.jsx(C,{id:e.id,onCancel:()=>o({action:""})})]})}export{D as P};
1
+ import{j as n}from"./vendor-mui-BXZut9Pz.js";import{V as g,Y as y,Z as t}from"./vendor-blocklet-B67R14so.js";import{I as d,e as l,k as m}from"./index-B4yaPb7B.js";import{l as x}from"./lodash-B4Ozcv0x.js";import{A as b}from"./actions-BEUwbsq1.js";import{C as j}from"./click-boundary-Bi28Y0Fq.js";import{A as C}from"./assign-DKRfmN7W.js";import{E as A}from"./edit-DAU8AWzT.js";function D({data:e,variant:v="compact",onChange:s}){const p=e.locked||!x.isEmpty(e.prices)&&e.prices.some(a=>a.locked),{t:i}=g(),[r,o]=y({action:"",loading:!1}),h=async a=>{try{o({loading:!0}),await l.put(`/api/products/${e.id}`,a).then(c=>c.data),t.success(i("common.saved")),s(r.action)}catch(c){console.error(c),t.error(m(c))}finally{o({loading:!1,action:""})}},u=async()=>{try{o({loading:!0}),await l.put(`/api/products/${e.id}/archive`).then(a=>a.data),t.success(i("common.saved")),s(r.action)}catch(a){console.error(a),t.error(m(a))}finally{o({loading:!1,action:""})}},f=async()=>{try{o({loading:!0}),await l.delete(`/api/products/${e.id}`).then(a=>a.data),t.success(i("common.removed")),s(r.action)}catch(a){console.error(a),t.error(m(a))}finally{o({loading:!1,action:""})}};return n.jsxs(j,{children:[n.jsx(b,{variant:v,actions:[{label:i("admin.product.edit"),handler:()=>o({action:"edit"}),color:"primary",disabled:!e.active,divider:!0},e.active?{label:i("admin.product.archive"),handler:()=>o({action:"archive"}),color:"primary"}:{label:i("admin.product.unarchive"),handler:()=>o({action:"unarchive"}),color:"primary"},{label:i("admin.product.remove"),handler:()=>o({action:"remove"}),disabled:p,color:p?"text.disabled":"error",divider:!0},{label:i("admin.passport.assign"),handler:()=>o({action:"assign"}),color:"primary",disabled:!e.active}].filter(Boolean)}),r.action==="edit"&&n.jsx(A,{product:e,loading:r.loading,onSave:h,onCancel:()=>o({action:""})}),r.action==="archive"&&n.jsx(d,{onConfirm:u,onCancel:()=>o({action:""}),title:i("admin.product.archive"),message:i("admin.product.archiveTip"),loading:r.loading}),r.action==="unarchive"&&n.jsx(d,{onConfirm:u,onCancel:()=>o({action:""}),title:i("admin.product.unarchive"),message:i("admin.product.unarchiveTip"),loading:r.loading}),r.action==="remove"&&n.jsx(d,{onConfirm:f,onCancel:()=>o({action:""}),title:i("admin.product.remove"),message:i("admin.product.removeTip"),loading:r.loading}),r.action==="assign"&&n.jsx(C,{id:e.id,onCancel:()=>o({action:""})})]})}export{D as P};
@@ -1 +1 @@
1
- import{j as n,a3 as R,x as P,w as B}from"./vendor-mui-BXZut9Pz.js";import{V as E,H as j,$ as I,Z as o,Y as z,P as L,aa as C}from"./vendor-blocklet-DcLR2Cyf.js";import{h as V,F as H,I as w,e as m,b8 as _,k as y}from"./index-BarN7DfU.js";import{A as M}from"./actions-BJDN6Op2.js";import{l as S}from"./lodash-B4Ozcv0x.js";import{o as U}from"./util-DxXTXkeY.js";import{D as W,a as D}from"./form-cX026J4G.js";import{P as K}from"./product-select-ChEyoJqJ.js";import{a as O}from"./vendor-react-BPknnnEA.js";function Y({price:e,loading:s,onSave:v,onCancel:l,productType:g=""}){const{t:r}=E(),f=t=>S.isEmpty(t)?{}:t,d=V({mode:"onChange",defaultValues:{...e,unit_amount:j(e.unit_amount,e.currency?.decimal),model:U(e),metadata:f(e.metadata),recurring:e.recurring?{...e.recurring}:W.recurring,currency_options:S.cloneDeep(e.currency_options).map(t=>(t.unit_amount=j(t.unit_amount,t.currency?.decimal),t))}}),{handleSubmit:b,reset:h,formState:{errors:c}}=d,a=()=>{Object.keys(c).length>0||b(async t=>{if(t.metadata===void 0&&(t.metadata=d.getValues("metadata")),Number(t.quantity_available)>0&&Number(t.quantity_available)<Number(t.quantity_sold)){o.warning(r("admin.price.quantityAvailable.valid"));return}await v(t),h(),l(null)})()};return n.jsx(I,{open:!0,disableEscapeKeyDown:!0,fullWidth:!0,maxWidth:"sm",className:"base-dialog",onClose:()=>l(null),showCloseButton:!1,title:r("admin.price.edit"),actions:n.jsxs(R,{direction:"row",children:[n.jsx(P,{size:"small",sx:{mr:2},onClick:l,children:r("common.cancel")}),n.jsxs(P,{variant:"contained",color:"primary",size:"small",disabled:s,onClick:a,children:[s&&n.jsx(B,{size:"small"})," ",r("common.save")]})]}),children:n.jsx(H,{...d,children:n.jsx(K,{children:n.jsx(D,{productType:g||e.product?.type})})})})}const Z=async e=>(await m.get(`/api/payment-currencies/${e}/recharge-config`)).data;function ne({data:e,onChange:s,variant:v="compact",setAsDefault:l=!1,product:g=null}){const{t:r}=E(),f=O(),d=e.active,b=e.active,h=!e.locked&&!l,[c,a]=z({action:"",loading:!1}),t=async i=>{if(Number(i.quantity_available)>0&&Number(i.quantity_available)<Number(i.quantity_sold)){o.warning(r("admin.price.quantityAvailable.valid"));return}try{a({loading:!0}),await m.put(`/api/prices/${e.id}`,i).then(p=>p.data),o.success(r("common.saved")),_("price.updated"),s(c.action)}catch(p){throw console.error(p),o.error(y(p)),p}finally{a({loading:!1})}},k=async()=>{try{a({loading:!0}),await m.put(`/api/prices/${e.id}/archive`).then(i=>i.data),o.success(r("common.saved")),_("price.updated"),s(c.action)}catch(i){console.error(i),o.error(y(i))}finally{a({loading:!1,action:""})}},A=async()=>{try{a({loading:!0}),await m.delete(`/api/prices/${e.id}`).then(i=>i.data),o.success(r("common.removed")),_("price.deleted"),s(c.action)}catch(i){console.error(i),o.error(y(i))}finally{a({loading:!1,action:""})}},T=async()=>{try{a({loading:!0}),await m.put(`/api/products/${e.product_id}`,{default_price_id:e.id}).then(i=>i.data),o.success(r("common.saveAsDefaultPriceSuccess")),s(c.action)}catch(i){console.error(i),o.error(y(i))}finally{a({loading:!1,action:""})}},q=()=>{f(`/admin/products/links?price_id=${e.id}`)},$=()=>{f(`/admin/products/pricing-tables?price_id=${e.id}`)},u=e.metadata?.credit_config?.currency_id,{data:N}=L(()=>Z(u),{refreshDeps:[u],ready:!!u}),F=async()=>{try{a({loading:!0}),await m.put(`/api/payment-currencies/${u}/recharge-config`,{base_price_id:e.id}),o.success(r("admin.price.credit.saveSuccess")),s(c.action)}catch(i){console.error(i),o.error(y(i))}finally{a({loading:!1,action:""})}},x=[{label:r("admin.pricing"),handler:C,color:"text.primary",disabled:!0},{label:r("admin.price.edit"),handler:()=>a({action:"edit"}),color:d?"text.primary":"text.disabled",disabled:!d},{label:r("admin.price.archive"),handler:()=>a({action:"archive"}),color:b?"text.primary":"text.disabled",disabled:!b},{label:r("admin.price.remove"),handler:()=>a({action:"remove"}),color:h?"error.main":"text.disabled",disabled:!h,divider:!l},{label:r("admin.payments"),handler:C,color:"text.primary",disabled:!0},{label:r("admin.paymentLink.add"),handler:q,color:"primary"},{label:r("admin.pricingTable.add"),handler:$,color:"primary",disabled:!e.recurring}].filter(Boolean);if(l||x.splice(4,0,{label:r("admin.price.setAsDefault"),handler:T,color:"text.primary",disabled:!1,divider:!0}),u&&N?.recharge_config?.base_price_id!==e.id){const i=l?4:5;x.splice(i,0,{label:r("admin.price.credit.saveAsBasePrice"),handler:F,color:"text.primary",disabled:!1,divider:!1})}return n.jsxs(n.Fragment,{children:[n.jsx(M,{variant:v,actions:x}),c.action==="edit"&&n.jsx(Y,{price:e,onSave:t,onCancel:()=>a({action:""}),productType:g?.type}),c.action==="archive"&&n.jsx(w,{onConfirm:k,onCancel:()=>a({action:""}),title:r("admin.price.archive"),message:r("admin.price.archiveTip")}),c.action==="remove"&&n.jsx(w,{onConfirm:A,onCancel:()=>a({action:""}),title:r("admin.price.remove"),message:r("admin.price.removeTip")})]})}export{Y as E,ne as P};
1
+ import{j as n,a3 as R,x as P,w as B}from"./vendor-mui-BXZut9Pz.js";import{V as E,H as j,$ as I,Z as o,Y as z,P as L,aa as C}from"./vendor-blocklet-B67R14so.js";import{h as V,F as H,I as w,e as m,b8 as _,k as y}from"./index-B4yaPb7B.js";import{A as M}from"./actions-BEUwbsq1.js";import{l as S}from"./lodash-B4Ozcv0x.js";import{o as U}from"./util-B8B3fsMa.js";import{D as W,a as D}from"./form-AFzUvoFE.js";import{P as K}from"./product-select-_72p-5lF.js";import{a as O}from"./vendor-react-BPknnnEA.js";function Y({price:e,loading:s,onSave:v,onCancel:l,productType:g=""}){const{t:r}=E(),f=t=>S.isEmpty(t)?{}:t,d=V({mode:"onChange",defaultValues:{...e,unit_amount:j(e.unit_amount,e.currency?.decimal),model:U(e),metadata:f(e.metadata),recurring:e.recurring?{...e.recurring}:W.recurring,currency_options:S.cloneDeep(e.currency_options).map(t=>(t.unit_amount=j(t.unit_amount,t.currency?.decimal),t))}}),{handleSubmit:b,reset:h,formState:{errors:c}}=d,a=()=>{Object.keys(c).length>0||b(async t=>{if(t.metadata===void 0&&(t.metadata=d.getValues("metadata")),Number(t.quantity_available)>0&&Number(t.quantity_available)<Number(t.quantity_sold)){o.warning(r("admin.price.quantityAvailable.valid"));return}await v(t),h(),l(null)})()};return n.jsx(I,{open:!0,disableEscapeKeyDown:!0,fullWidth:!0,maxWidth:"sm",className:"base-dialog",onClose:()=>l(null),showCloseButton:!1,title:r("admin.price.edit"),actions:n.jsxs(R,{direction:"row",children:[n.jsx(P,{size:"small",sx:{mr:2},onClick:l,children:r("common.cancel")}),n.jsxs(P,{variant:"contained",color:"primary",size:"small",disabled:s,onClick:a,children:[s&&n.jsx(B,{size:"small"})," ",r("common.save")]})]}),children:n.jsx(H,{...d,children:n.jsx(K,{children:n.jsx(D,{productType:g||e.product?.type})})})})}const Z=async e=>(await m.get(`/api/payment-currencies/${e}/recharge-config`)).data;function ne({data:e,onChange:s,variant:v="compact",setAsDefault:l=!1,product:g=null}){const{t:r}=E(),f=O(),d=e.active,b=e.active,h=!e.locked&&!l,[c,a]=z({action:"",loading:!1}),t=async i=>{if(Number(i.quantity_available)>0&&Number(i.quantity_available)<Number(i.quantity_sold)){o.warning(r("admin.price.quantityAvailable.valid"));return}try{a({loading:!0}),await m.put(`/api/prices/${e.id}`,i).then(p=>p.data),o.success(r("common.saved")),_("price.updated"),s(c.action)}catch(p){throw console.error(p),o.error(y(p)),p}finally{a({loading:!1})}},k=async()=>{try{a({loading:!0}),await m.put(`/api/prices/${e.id}/archive`).then(i=>i.data),o.success(r("common.saved")),_("price.updated"),s(c.action)}catch(i){console.error(i),o.error(y(i))}finally{a({loading:!1,action:""})}},A=async()=>{try{a({loading:!0}),await m.delete(`/api/prices/${e.id}`).then(i=>i.data),o.success(r("common.removed")),_("price.deleted"),s(c.action)}catch(i){console.error(i),o.error(y(i))}finally{a({loading:!1,action:""})}},T=async()=>{try{a({loading:!0}),await m.put(`/api/products/${e.product_id}`,{default_price_id:e.id}).then(i=>i.data),o.success(r("common.saveAsDefaultPriceSuccess")),s(c.action)}catch(i){console.error(i),o.error(y(i))}finally{a({loading:!1,action:""})}},q=()=>{f(`/admin/products/links?price_id=${e.id}`)},$=()=>{f(`/admin/products/pricing-tables?price_id=${e.id}`)},u=e.metadata?.credit_config?.currency_id,{data:N}=L(()=>Z(u),{refreshDeps:[u],ready:!!u}),F=async()=>{try{a({loading:!0}),await m.put(`/api/payment-currencies/${u}/recharge-config`,{base_price_id:e.id}),o.success(r("admin.price.credit.saveSuccess")),s(c.action)}catch(i){console.error(i),o.error(y(i))}finally{a({loading:!1,action:""})}},x=[{label:r("admin.pricing"),handler:C,color:"text.primary",disabled:!0},{label:r("admin.price.edit"),handler:()=>a({action:"edit"}),color:d?"text.primary":"text.disabled",disabled:!d},{label:r("admin.price.archive"),handler:()=>a({action:"archive"}),color:b?"text.primary":"text.disabled",disabled:!b},{label:r("admin.price.remove"),handler:()=>a({action:"remove"}),color:h?"error.main":"text.disabled",disabled:!h,divider:!l},{label:r("admin.payments"),handler:C,color:"text.primary",disabled:!0},{label:r("admin.paymentLink.add"),handler:q,color:"primary"},{label:r("admin.pricingTable.add"),handler:$,color:"primary",disabled:!e.recurring}].filter(Boolean);if(l||x.splice(4,0,{label:r("admin.price.setAsDefault"),handler:T,color:"text.primary",disabled:!1,divider:!0}),u&&N?.recharge_config?.base_price_id!==e.id){const i=l?4:5;x.splice(i,0,{label:r("admin.price.credit.saveAsBasePrice"),handler:F,color:"text.primary",disabled:!1,divider:!1})}return n.jsxs(n.Fragment,{children:[n.jsx(M,{variant:v,actions:x}),c.action==="edit"&&n.jsx(Y,{price:e,onSave:t,onCancel:()=>a({action:""}),productType:g?.type}),c.action==="archive"&&n.jsx(w,{onConfirm:k,onCancel:()=>a({action:""}),title:r("admin.price.archive"),message:r("admin.price.archiveTip")}),c.action==="remove"&&n.jsx(w,{onConfirm:A,onCancel:()=>a({action:""}),title:r("admin.price.remove"),message:r("admin.price.removeTip")})]})}export{Y as E,ne as P};
@@ -1 +1 @@
1
- import{j as n}from"./vendor-mui-BXZut9Pz.js";import{V as g,Y as C,Z as o}from"./vendor-blocklet-DcLR2Cyf.js";import{I as f,e as v,k as x}from"./index-BarN7DfU.js";import{A as y}from"./actions-BJDN6Op2.js";import{C as h}from"./click-boundary-CafubiPp.js";import{a as j}from"./vendor-react-BPknnnEA.js";function E({data:t,variant:s="compact",onChange:p}){const{t:e}=g(),u=j(),[i,r]=C({action:"",loading:!1}),c=a=>async()=>{try{r({loading:!0}),a==="delete"?await v.delete(`/api/meters/${t.id}`):await v.put(`/api/meters/${t.id}/${a}`),a==="activate"?o.success(e("admin.meter.activated")):a==="deactivate"?o.success(e("admin.meter.deactivated")):a==="delete"&&o.success(e("admin.meter.deleted")),p(a)}catch(d){console.error(d),o.error(x(d))}finally{r({loading:!1,action:""})}},m=()=>{r({action:""})},l=[{label:t.status==="inactive"?e("admin.meter.activate"):e("admin.meter.deactivate"),handler:()=>r({action:t.status==="inactive"?"activate":"deactivate"}),color:t.status==="inactive"?"primary":"error"}];return s==="compact"&&l.push({label:e("admin.meter.view"),handler:()=>u(`/admin/billing/${t.id}`),color:"primary"}),n.jsxs(h,{children:[n.jsx(y,{variant:s,actions:l}),i.action==="activate"&&n.jsx(f,{onConfirm:c("activate"),onCancel:m,title:e("admin.meter.activate"),message:e("admin.meter.activateConfirm"),loading:i.loading,color:"primary"}),i.action==="deactivate"&&n.jsx(f,{onConfirm:c("deactivate"),onCancel:m,title:e("admin.meter.deactivate"),message:e("admin.meter.deactivateConfirm"),loading:i.loading,color:"warning"})]})}export{E as M};
1
+ import{j as n}from"./vendor-mui-BXZut9Pz.js";import{V as g,Y as C,Z as o}from"./vendor-blocklet-B67R14so.js";import{I as f,e as v,k as x}from"./index-B4yaPb7B.js";import{A as y}from"./actions-BEUwbsq1.js";import{C as h}from"./click-boundary-Bi28Y0Fq.js";import{a as j}from"./vendor-react-BPknnnEA.js";function E({data:t,variant:s="compact",onChange:p}){const{t:e}=g(),u=j(),[i,r]=C({action:"",loading:!1}),c=a=>async()=>{try{r({loading:!0}),a==="delete"?await v.delete(`/api/meters/${t.id}`):await v.put(`/api/meters/${t.id}/${a}`),a==="activate"?o.success(e("admin.meter.activated")):a==="deactivate"?o.success(e("admin.meter.deactivated")):a==="delete"&&o.success(e("admin.meter.deleted")),p(a)}catch(d){console.error(d),o.error(x(d))}finally{r({loading:!1,action:""})}},m=()=>{r({action:""})},l=[{label:t.status==="inactive"?e("admin.meter.activate"):e("admin.meter.deactivate"),handler:()=>r({action:t.status==="inactive"?"activate":"deactivate"}),color:t.status==="inactive"?"primary":"error"}];return s==="compact"&&l.push({label:e("admin.meter.view"),handler:()=>u(`/admin/billing/${t.id}`),color:"primary"}),n.jsxs(h,{children:[n.jsx(y,{variant:s,actions:l}),i.action==="activate"&&n.jsx(f,{onConfirm:c("activate"),onCancel:m,title:e("admin.meter.activate"),message:e("admin.meter.activateConfirm"),loading:i.loading,color:"primary"}),i.action==="deactivate"&&n.jsx(f,{onConfirm:c("deactivate"),onCancel:m,title:e("admin.meter.deactivate"),message:e("admin.meter.deactivateConfirm"),loading:i.loading,color:"warning"})]})}export{E as M};
@@ -1 +1 @@
1
- import{j as s}from"./vendor-mui-BXZut9Pz.js";import{V as f,Y as p,Z as l}from"./vendor-blocklet-DcLR2Cyf.js";import{I as u,e as y,k as g}from"./index-BarN7DfU.js";import{A as C}from"./actions-BJDN6Op2.js";import{C as h}from"./click-boundary-CafubiPp.js";import{a as b}from"./vendor-react-BPknnnEA.js";function A({data:a,variant:i="compact",onChange:d=()=>{}}){const{t:e}=f(),r=b(),[o,n]=p({action:"",loading:!1}),t=[{label:e("admin.customer.view"),handler:()=>r(`/admin/customers/${a.customer_id}`),color:"primary",disabled:!1}];i==="compact"&&t.push({label:e("admin.refund.view"),handler:()=>r(`/admin/payments/${a.id}`),color:"primary",disabled:!1}),["succeeded","canceled"].includes(a.status)||t.push({label:e("admin.paymentIntent.cancelRefund"),handler:()=>n({action:"cancel"}),color:"error",disabled:!1});const m=async()=>{try{n({loading:!0}),await y.post(`/api/refunds/${a?.id}/cancel`),l.success(e("admin.paymentIntent.refundCanceled")),d(o.action)}catch(c){console.error(c),l.error(g(c))}finally{n({loading:!1,action:""})}};return s.jsxs(h,{children:[s.jsx(C,{variant:i,actions:t}),o.action==="cancel"&&s.jsx(u,{onConfirm:m,onCancel:()=>n({action:""}),title:e("admin.paymentIntent.cancelRefund"),message:e("admin.paymentIntent.refundCanceledTip"),loading:o.loading})]})}export{A as R};
1
+ import{j as s}from"./vendor-mui-BXZut9Pz.js";import{V as f,Y as p,Z as l}from"./vendor-blocklet-B67R14so.js";import{I as u,e as y,k as g}from"./index-B4yaPb7B.js";import{A as C}from"./actions-BEUwbsq1.js";import{C as h}from"./click-boundary-Bi28Y0Fq.js";import{a as b}from"./vendor-react-BPknnnEA.js";function A({data:a,variant:i="compact",onChange:d=()=>{}}){const{t:e}=f(),r=b(),[o,n]=p({action:"",loading:!1}),t=[{label:e("admin.customer.view"),handler:()=>r(`/admin/customers/${a.customer_id}`),color:"primary",disabled:!1}];i==="compact"&&t.push({label:e("admin.refund.view"),handler:()=>r(`/admin/payments/${a.id}`),color:"primary",disabled:!1}),["succeeded","canceled"].includes(a.status)||t.push({label:e("admin.paymentIntent.cancelRefund"),handler:()=>n({action:"cancel"}),color:"error",disabled:!1});const m=async()=>{try{n({loading:!0}),await y.post(`/api/refunds/${a?.id}/cancel`),l.success(e("admin.paymentIntent.refundCanceled")),d(o.action)}catch(c){console.error(c),l.error(g(c))}finally{n({loading:!1,action:""})}};return s.jsxs(h,{children:[s.jsx(C,{variant:i,actions:t}),o.action==="cancel"&&s.jsx(u,{onConfirm:m,onCancel:()=>n({action:""}),title:e("admin.paymentIntent.cancelRefund"),message:e("admin.paymentIntent.refundCanceledTip"),loading:o.loading})]})}export{A as R};