@arcblock/payment-service 1.29.8 → 1.29.10

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 (184) hide show
  1. package/dist/cf.d.ts +31 -0
  2. package/dist/cf.js +79 -60
  3. package/dist/index.js +358 -87
  4. package/package.json +4 -4
  5. package/web/assets/{account-DETfFe4_.js → account-DrsnH5wP.js} +1 -1
  6. package/web/assets/{action-B_DQJlip.js → action-C2c0yWuW.js} +1 -1
  7. package/web/assets/{actions-Bt_jST94.js → actions--FNKSNIs.js} +1 -1
  8. package/web/assets/{actions-jxGAdGfb.js → actions-BEUwbsq1.js} +1 -1
  9. package/web/assets/{actions-D9MHLBFH.js → actions-C9AfME83.js} +1 -1
  10. package/web/assets/{actions-QPa-8lfB.js → actions-D2-s31n3.js} +1 -1
  11. package/web/assets/{actions-DJyfN5OU.js → actions-DXMceTgd.js} +1 -1
  12. package/web/assets/{actions-BtaoyTWt.js → actions-DeCPtfTK.js} +1 -1
  13. package/web/assets/{actions-BaDh4xWX.js → actions-DtNZGZWf.js} +1 -1
  14. package/web/assets/{actions-EPYeS5p4.js → actions-JHsqbHpB.js} +1 -1
  15. package/web/assets/{actions-BknL4OyZ.js → actions-izdZ2Mn4.js} +1 -1
  16. package/web/assets/{add-price-CD-utowo.js → add-price-TdXAR3NW.js} +1 -1
  17. package/web/assets/{admin-_nEB-lHn.js → admin-BpFv3eF5.js} +1 -1
  18. package/web/assets/{assign-CkV5Q2LP.js → assign-DKRfmN7W.js} +1 -1
  19. package/web/assets/{attempts-DySeqBYU.js → attempts-BfbYfiJa.js} +1 -1
  20. package/web/assets/browser-DF2vfpBa.js +1 -0
  21. package/web/assets/{change-payment-CPUCUEER.js → change-payment-j5UC8_h0.js} +1 -1
  22. package/web/assets/{change-plan-CxE-XfWc.js → change-plan-CtXvsIDw.js} +1 -1
  23. package/web/assets/{click-boundary-y8dVA_tr.js → click-boundary-Bi28Y0Fq.js} +1 -1
  24. package/web/assets/{connect-CC_l_f6Q.js → connect-CXek4LAE.js} +1 -1
  25. package/web/assets/{copyable-DpX04wZz.js → copyable-CprMHdhV.js} +1 -1
  26. package/web/assets/{create-Bs65p5Ne.js → create-B-Ubepl_.js} +1 -1
  27. package/web/assets/{create-tYebjhr9.js → create-BVt_sQ_7.js} +1 -1
  28. package/web/assets/{create-3SsWCAOC.js → create-BWviSWbC.js} +1 -1
  29. package/web/assets/{create-BkQAaSvD.js → create-C6jihslA.js} +1 -1
  30. package/web/assets/{create-BmcRybZ5.js → create-IaalYGmm.js} +1 -1
  31. package/web/assets/{create-kG09X9gl.js → create-jzl1m8ZK.js} +1 -1
  32. package/web/assets/{credit-grant-item-list-Bk27jIc7.js → credit-grant-item-list-DQcvdSRs.js} +1 -1
  33. package/web/assets/{credit-overview-DmMSEs14.js → credit-overview-CPId2vzk.js} +2 -2
  34. package/web/assets/{currency-restrictions-DYLv4YyW.js → currency-restrictions-Dsupz2ce.js} +1 -1
  35. package/web/assets/{currency-select-DGS-62-L.js → currency-select-C8j7QQMP.js} +1 -1
  36. package/web/assets/{dayjs-B9tvQIKg.js → dayjs-DUNWtvju.js} +1 -1
  37. package/web/assets/{description-Ym17DL48.js → description-BHxdy5I3.js} +1 -1
  38. package/web/assets/{detail-DPCTQLOx.js → detail-B17BN6kU.js} +1 -1
  39. package/web/assets/detail-BJ-hl5PK.js +10 -0
  40. package/web/assets/detail-BJEqTXDS.js +1 -0
  41. package/web/assets/{detail-DG4l2CqN.js → detail-BdC9VIc6.js} +1 -1
  42. package/web/assets/detail-BkRkrKyw.js +1 -0
  43. package/web/assets/{detail-DuWdZIyp.js → detail-BvcI9cB_.js} +1 -1
  44. package/web/assets/detail-C--ATvwm.js +24 -0
  45. package/web/assets/{detail-Cb9HBSMw.js → detail-CHJqYZ0W.js} +1 -1
  46. package/web/assets/detail-CfvKZ7IV.js +1 -0
  47. package/web/assets/{detail-K9EVY3r2.js → detail-CmIweOLE.js} +1 -1
  48. package/web/assets/{detail-CxYQYu_l.js → detail-D729Bgs6.js} +1 -1
  49. package/web/assets/detail-DD1YBtex.js +1 -0
  50. package/web/assets/detail-DOcm4Kqg.js +15 -0
  51. package/web/assets/{detail-Do9QO5L2.js → detail-DQj1mbhA.js} +1 -1
  52. package/web/assets/detail-DTXDMIR9.js +15 -0
  53. package/web/assets/{detail-DB56SG-k.js → detail-DUAJzKsu.js} +1 -1
  54. package/web/assets/detail-De8PyTyx.js +1 -0
  55. package/web/assets/{detail-CT9Unyrf.js → detail-DqfxOHky.js} +1 -1
  56. package/web/assets/{detail-cwHZbY62.js → detail-Dzt5tfyZ.js} +1 -1
  57. package/web/assets/{detail-D5KRrQDx.js → detail-H0dkKVyS.js} +1 -1
  58. package/web/assets/{detail-DuO_Jn5X.js → detail-MgdgGj5J.js} +1 -1
  59. package/web/assets/{detail-BJTcK7mx.js → detail-WAmPM6yq.js} +1 -1
  60. package/web/assets/{detail-Cr2wG4Th.js → detail-g6el9Fxj.js} +1 -1
  61. package/web/assets/did-Bqcz-NjH.js +1 -0
  62. package/web/assets/{drawer-form-Cl0T1Yyt.js → drawer-form-CQjNFFWk.js} +1 -1
  63. package/web/assets/{edit-3HUAnaXW.js → edit-DAU8AWzT.js} +1 -1
  64. package/web/assets/{editor-BF5I0siU.js → editor-vZvxDUTl.js} +1 -1
  65. package/web/assets/{embed-CsNqeCd0.js → embed-ClYNqZbf.js} +1 -1
  66. package/web/assets/{filter-toolbar-BydfQ-79.js → filter-toolbar-VvmMATj0.js} +1 -1
  67. package/web/assets/form-4_MzglPj.js +9 -0
  68. package/web/assets/{form-P4luyUpY.js → form-AFzUvoFE.js} +1 -1
  69. package/web/assets/{form-DSzMo9UD.js → form-Bro99BjK.js} +1 -1
  70. package/web/assets/{form-BGm5NPDn.js → form-CnrBCyTJ.js} +1 -1
  71. package/web/assets/form-Cuvruf4H.js +16 -0
  72. package/web/assets/{gas-Qf0SSUfS.js → gas-kw2KMH1u.js} +1 -1
  73. package/web/assets/{generateCategoricalChart-BaWwaXky.js → generateCategoricalChart-BCpuUeC_.js} +1 -1
  74. package/web/assets/{home-HbrLyxJL.js → home-ZNJREzbw.js} +1 -1
  75. package/web/assets/{index-BIoSdRvX.js → index-ASk8vU2H.js} +3 -3
  76. package/web/assets/{index-B1pTTyGZ.js → index-B4n6PvPu.js} +1 -1
  77. package/web/assets/{index-DgSc1Qy8.js → index-B4yaPb7B.js} +17 -17
  78. package/web/assets/{index-CI_EY4YS.js → index-BHwID_s4.js} +1 -1
  79. package/web/assets/index-BMcnd_jZ.js +1 -0
  80. package/web/assets/{index-9xBRL_33.js → index-BRmN8ViQ.js} +1 -1
  81. package/web/assets/index-BdbLl6St.js +1 -0
  82. package/web/assets/{index-Cw0ugaQL.js → index-BjKRyxNQ.js} +1 -1
  83. package/web/assets/index-BjLJQRKY.js +1 -0
  84. package/web/assets/index-BkNCPnTn.js +1 -0
  85. package/web/assets/index-BlAwTTmu.js +1 -0
  86. package/web/assets/{index-C0JaS08f.js → index-BtWfmATr.js} +1 -1
  87. package/web/assets/{index-DE2KzqXl.js → index-C-5n472s.js} +1 -1
  88. package/web/assets/{index-Br7_mvEw.js → index-C3AP4jq0.js} +1 -1
  89. package/web/assets/{index-2l22EYw9.js → index-C3Rh1SaB.js} +1 -1
  90. package/web/assets/index-CDyxbCzc.js +1 -0
  91. package/web/assets/{index-Dc954mDP.js → index-CH_k9MVv.js} +1 -1
  92. package/web/assets/{index-1y9kjPIr.js → index-CKPfOW6M.js} +1 -1
  93. package/web/assets/{index-Dr_MwbKt.js → index-CPFlZhA2.js} +1 -1
  94. package/web/assets/index-CPyGjEd3.js +49 -0
  95. package/web/assets/index-ChC-jsE2.js +1 -0
  96. package/web/assets/index-CiWvs3j9.js +1 -0
  97. package/web/assets/{index-BP53rZV9.js → index-D6gv9jHh.js} +1 -1
  98. package/web/assets/{index-CdkYrABk.js → index-D7pWd60Z.js} +1 -1
  99. package/web/assets/{index-fswPX_qe.js → index-DAen2-cr.js} +1 -1
  100. package/web/assets/{index-DPodCQ9c.js → index-DNobX-Tr.js} +1 -1
  101. package/web/assets/{index-Drav4oDH.js → index-DY-g0BPU.js} +2 -2
  102. package/web/assets/index-DZkpxY-C.js +1 -0
  103. package/web/assets/{index-BFML4-2u.js → index-Dh9agU9O.js} +1 -1
  104. package/web/assets/index-Dju8k6mq.js +1 -0
  105. package/web/assets/{index-fByZjxLy.js → index-DwDNPqjF.js} +1 -1
  106. package/web/assets/index-Dze0CpfQ.js +14 -0
  107. package/web/assets/{index-BMKZToMM.js → index-eDERHpkr.js} +2 -2
  108. package/web/assets/{index-SYTpMMMH.js → index-mgPU1lyd.js} +1 -1
  109. package/web/assets/{index-DZpJPE1Z.js → index-olGOY5KB.js} +1 -1
  110. package/web/assets/{index-Clbt8nRm.js → index-oy7LrXGT.js} +1 -1
  111. package/web/assets/index-x7sBb6oM.js +1 -0
  112. package/web/assets/{index.es-BWnfUzLb.js → index.es-C2Q6Owow.js} +1 -1
  113. package/web/assets/{info-card-C1yxhxJG.js → info-card-C9dRgztS.js} +1 -1
  114. package/web/assets/{info-metric-CNse3r66.js → info-metric-ukWq8INi.js} +1 -1
  115. package/web/assets/{info-row-DOK2whMn.js → info-row-CaPaNF4L.js} +1 -1
  116. package/web/assets/{info-row-group-BeUhWnnY.js → info-row-group-Cxo-4Gk5.js} +1 -1
  117. package/web/assets/{libphonenumber-CyphiuxQ.js → libphonenumber-CTvobi0D.js} +1 -1
  118. package/web/assets/{link-3eeclTeS.js → link-DsltSF2Q.js} +1 -1
  119. package/web/assets/{list-C521zE_7.js → list-B2b-s8wM.js} +1 -1
  120. package/web/assets/{list-CO0X4L3-.js → list-BzgF4i3i.js} +1 -1
  121. package/web/assets/{list-DnePqZ2K.js → list-Cd1O-aDi.js} +1 -1
  122. package/web/assets/{list-D1aevUOI.js → list-CvM46TsP.js} +2 -2
  123. package/web/assets/{list-jHj_5yy3.js → list-DtEjqlED.js} +1 -1
  124. package/web/assets/{list-D-I0msRW.js → list-O_uCSLFq.js} +2 -2
  125. package/web/assets/{list-1OG83xc4.js → list-YNWVqjwW.js} +1 -1
  126. package/web/assets/{list-CNmzJKIQ.js → list-ZaBapEXW.js} +1 -1
  127. package/web/assets/metadata-_hV0ZaVh.js +55 -0
  128. package/web/assets/{meter-event-lmNMgmIu.js → meter-event-CPVBpekF.js} +1 -1
  129. package/web/assets/{metrics-C7U41HWk.js → metrics-DVPdwpyf.js} +1 -1
  130. package/web/assets/{overview-Cs3-8n4e.js → overview-CGdVIJrJ.js} +1 -1
  131. package/web/assets/{overview-CH1HnSP-.js → overview-CN59I5Sc.js} +1 -1
  132. package/web/assets/{past-due-CGGRZmXY.js → past-due-C3PtU8uo.js} +1 -1
  133. package/web/assets/pay-XVdSNq__.js +4 -0
  134. package/web/assets/{payment-method-info-BsOBbA3m.js → payment-method-info-D_qR04xC.js} +2 -2
  135. package/web/assets/{preview-CjYh9dTg.js → preview-Bdtbh-xk.js} +1 -1
  136. package/web/assets/{preview-DjYRpRA8.js → preview-F3lma170.js} +1 -1
  137. package/web/assets/{pricing-table-edE6TJGX.js → pricing-table-Bt2WljzE.js} +1 -1
  138. package/web/assets/{pricing-table-C3Lkhq46.js → pricing-table-D9FGYBVa.js} +2 -2
  139. package/web/assets/{product-select-0ScZE2e8.js → product-select-_72p-5lF.js} +1 -1
  140. package/web/assets/{recharge-DcPtT8vt.js → recharge-CSlKshbU.js} +1 -1
  141. package/web/assets/{related-credit-grants-BygNGPfb.js → related-credit-grants-DnKdAit6.js} +22 -22
  142. package/web/assets/{safe-did-address-B0fFbUph.js → safe-did-address-CRTPYo34.js} +1 -1
  143. package/web/assets/{source-data-viewer-By_Utay-.js → source-data-viewer-D1GShrs5.js} +1 -1
  144. package/web/assets/{status-l6pD08fw.js → status-3Swm2gK5.js} +1 -1
  145. package/web/assets/subscription-BX00k6FU.js +1 -0
  146. package/web/assets/{subscription-Dq22e3D1.js → subscription-Bzeblscr.js} +1 -1
  147. package/web/assets/table-BN3WBnr3.js +1 -0
  148. package/web/assets/{tax-code-select-CWhIIiXi.js → tax-code-select-j2arPbaE.js} +1 -1
  149. package/web/assets/{tax-utils-DqNX34-r.js → tax-utils-B8J0Kfnz.js} +1 -1
  150. package/web/assets/{uploader-DRXDz_r0.js → uploader-BLdAbLR6.js} +1 -1
  151. package/web/assets/{usage-records-jjJMZ6DI.js → usage-records-BAwNs1y8.js} +1 -1
  152. package/web/assets/{util-mDHAL0lx.js → util-B8B3fsMa.js} +1 -1
  153. package/web/assets/{vendor-arcblock-ChFCRdyx.js → vendor-arcblock-D1drrE7q.js} +1 -1
  154. package/web/assets/{vendor-blocklet-D_i_QeSo.js → vendor-blocklet-B67R14so.js} +43 -43
  155. package/web/index.html +1 -1
  156. package/web/assets/browser-DSLTxXlL.js +0 -1
  157. package/web/assets/detail-15zxCbV9.js +0 -10
  158. package/web/assets/detail-ASPdMJoW.js +0 -1
  159. package/web/assets/detail-CIx9vkir.js +0 -1
  160. package/web/assets/detail-D5NbV29V.js +0 -1
  161. package/web/assets/detail-DE3OOC5M.js +0 -15
  162. package/web/assets/detail-DVVzYhdV.js +0 -1
  163. package/web/assets/detail-Dqc0OfCQ.js +0 -1
  164. package/web/assets/detail-OZeeKI69.js +0 -24
  165. package/web/assets/detail-uhlID8jD.js +0 -15
  166. package/web/assets/form-BXAuSawq.js +0 -9
  167. package/web/assets/form-CKfKLGXP.js +0 -16
  168. package/web/assets/index-0HK7CYm4.js +0 -1
  169. package/web/assets/index-BJ_E6bEO.js +0 -1
  170. package/web/assets/index-Bnyh4rlV.js +0 -1
  171. package/web/assets/index-BoQ7wf3O.js +0 -1
  172. package/web/assets/index-C68x-aau.js +0 -1
  173. package/web/assets/index-C8s2QKoe.js +0 -1
  174. package/web/assets/index-Cn7O-OP7.js +0 -49
  175. package/web/assets/index-DU39aG5u.js +0 -1
  176. package/web/assets/index-DtbqgSK4.js +0 -1
  177. package/web/assets/index-DuRu9NWB.js +0 -14
  178. package/web/assets/index-WMKOiUez.js +0 -1
  179. package/web/assets/index-dmHgoplS.js +0 -1
  180. package/web/assets/index-txVTkoDD.js +0 -1
  181. package/web/assets/metadata-CMSHcSXi.js +0 -55
  182. package/web/assets/pay-CSpHBUh_.js +0 -4
  183. package/web/assets/subscription-DcwhSOpa.js +0 -1
  184. package/web/assets/table-BRU4Enia.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/payment-service",
3
- "version": "1.29.8",
3
+ "version": "1.29.10",
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,9 +44,9 @@
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.8",
47
+ "@blocklet/payment-vendor": "1.29.10",
48
48
  "@blocklet/sdk": "^1.17.13-beta-20260613-094425-b81920c8",
49
- "@blocklet/xss": "^0.3.16",
49
+ "@blocklet/xss": "^0.15.4",
50
50
  "@hono/node-server": "^2.0.4",
51
51
  "@ocap/asset": "^1.30.24",
52
52
  "@ocap/client": "^1.30.24",
@@ -90,5 +90,5 @@
90
90
  "ts-jest": "^29.1.2",
91
91
  "typescript": "^5.4.3"
92
92
  },
93
- "gitHead": "547c0614f1f83abad80ea08452d2f5a9f4f5aa07"
93
+ "gitHead": "18c831f5dbdfb271a96640befb06f589adbeeab0"
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,ae as ke,G as X,F as q,Y as H,E as Ae}from"./vendor-blocklet-D_i_QeSo.js";import{a as Ne,u as Be,i as Ie,a4 as Pe,a8 as Te,f as Ee,e as J,k as K,l as Fe,G as De}from"./index-DgSc1Qy8.js";import{R as Me}from"./recharge-DcPtT8vt.js";import{g as B,M as Q}from"./util-mDHAL0lx.js";import{f as S}from"./dayjs-B9tvQIKg.js";import{u as We}from"./browser-DSLTxXlL.js";import"./table-BRU4Enia.js";import"./lodash-B4Ozcv0x.js";const _e=ee(i)(({theme:t})=>({marginBottom:t.spacing(3),gap:t.spacing(3),flexDirection:"column"})),Z=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 He(){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 J.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 q(c).mul(new q(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 J.get(`/api/customers/payer-token?currencyId=${u}&payerAddress=${y}`);c?.data&&se(c.data)}}else W(t("customer.balance.currency.notFound"))}catch(r){W(K(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(),H.success(t("customer.recharge.success")),Y()},onClose:()=>{k.close()},onError:r=>{H.error(K(r))}}))},le=r=>{const{value:l}=r.target;if(!o||!/^\d*\.?\d*$/.test(l)||l.startsWith(".")||Number(l)>Q)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(Z,{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(Z,{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:Q}}}),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{He 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,X as x,O as j,Y as c}from"./vendor-blocklet-D_i_QeSo.js";import{I as u,e as d,k as A}from"./index-DgSc1Qy8.js";import{A as w}from"./actions-jxGAdGfb.js";import{C as $}from"./click-boundary-y8dVA_tr.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 P({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{P 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,X as T,Y as c,_ as C,E as f}from"./vendor-blocklet-D_i_QeSo.js";import{h as S,F as A,aX as P,I as v,e as g,k as b}from"./index-DgSc1Qy8.js";import{A as $}from"./actions-jxGAdGfb.js";import{C as F}from"./click-boundary-y8dVA_tr.js";import{A as L}from"./assign-CkV5Q2LP.js";function E({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(P,{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(F,{children:[n.jsx($,{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(E,{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-D_i_QeSo.js";import{b4 as m}from"./index-DgSc1Qy8.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,X as y,Y as t}from"./vendor-blocklet-D_i_QeSo.js";import{I as d,e as l,k as m}from"./index-DgSc1Qy8.js";import{l as x}from"./lodash-B4Ozcv0x.js";import{A as b}from"./actions-jxGAdGfb.js";import{C as j}from"./click-boundary-y8dVA_tr.js";import{A as C}from"./assign-CkV5Q2LP.js";import{E as A}from"./edit-3HUAnaXW.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,G as j,$ as I,Y as o,X as z,O as L,a9 as C}from"./vendor-blocklet-D_i_QeSo.js";import{h as V,F as M,I as w,e as m,b8 as _,k as y}from"./index-DgSc1Qy8.js";import{A as O}from"./actions-jxGAdGfb.js";import{l as S}from"./lodash-B4Ozcv0x.js";import{o as U}from"./util-mDHAL0lx.js";import{D as W,a as D}from"./form-P4luyUpY.js";import{P as G}from"./product-select-0ScZE2e8.js";import{a as H}from"./vendor-react-BPknnnEA.js";function K({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(M,{...d,children:n.jsx(G,{children:n.jsx(D,{productType:g||e.product?.type})})})})}const X=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=H(),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(()=>X(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(O,{variant:v,actions:x}),c.action==="edit"&&n.jsx(K,{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{K 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,X as C,Y as o}from"./vendor-blocklet-D_i_QeSo.js";import{I as f,e as v,k as x}from"./index-DgSc1Qy8.js";import{A as y}from"./actions-jxGAdGfb.js";import{C as h}from"./click-boundary-y8dVA_tr.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,X as p,Y as l}from"./vendor-blocklet-D_i_QeSo.js";import{I as u,e as y,k as g}from"./index-DgSc1Qy8.js";import{A as C}from"./actions-jxGAdGfb.js";import{C as h}from"./click-boundary-y8dVA_tr.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};
@@ -1 +1 @@
1
- import{r as K,j as e,A as se,a3 as g,q as y,x as ne,a_ as $e,aX as D,a$ as M,a2 as Me,B as G,O as ce,ai as be,by as Ue,$ as te,bg as ae,bl as re,a1 as fe,aQ as Ve,w as qe,b4 as He,bH as Ge}from"./vendor-mui-BXZut9Pz.js";import{V as ie,O as W,$ as Ne,E as V,Y as v,G as B,F as T,ao as Ke,K as Xe,X as Ye,a5 as Qe,a6 as Je}from"./vendor-blocklet-D_i_QeSo.js";import{a as Fe,D as Ze,q as et,L as tt,e as S,k as U,l as ve,E as Te,j as Se,C as Pe,d as nt,h as Le,S as ot,G as at,F as rt,H as st,I as ct,O as it,i as _e}from"./index-DgSc1Qy8.js";import{C as lt}from"./currency-GstdXsJf.js";import{f as dt}from"./dayjs-B9tvQIKg.js";import{M as ge,a as ut,i as Ae}from"./util-mDHAL0lx.js";import{A as Ie}from"./actions-jxGAdGfb.js";import{u as mt}from"./subscription-Dq22e3D1.js";import{a as ht}from"./vendor-react-BPknnnEA.js";const pt=async t=>{const o=`/api/subscriptions/${t.subscriptionId}`;return(await S.get(t.authToken?V(o,`?authToken=${t.authToken}`):o)).data},xt=async t=>{const o=`/api/subscriptions/${t.subscriptionId}/recover-info`;return(await S.get(t.authToken?V(o,`?authToken=${t.authToken}`):o)).data},ft=async t=>{const o=`/api/subscriptions/${t.subscriptionId}/recover`;return(await S.put(t.authToken?V(o,`?authToken=${t.authToken}`):o)).data};function gt({subscriptionId:t,dialogProps:o={open:!0},onResumed:p=()=>{},successToast:d=!0,authToken:w=void 0}){const{t:x,locale:b}=ie(),{connect:a}=Fe(),[P,j]=K.useState(!1),[s,N]=K.useState(o.open||!1),{data:_,error:L,loading:q}=W(()=>xt({subscriptionId:t,authToken:w}),{ready:!!t}),c=Ze(),R=_?.needStake??!1,z=async()=>{try{const m=await pt({subscriptionId:t,authToken:w});d&&v.success(x("payment.customer.recover.success")),N(!1),p(m),j(!1)}catch(m){console.error("Failed to fetch updated subscription:",m),v.error(U(m)),j(!1)}},H=()=>{j(!0);try{a.open({locale:b,containerEl:void 0,saveConnect:!1,action:"re-stake",prefix:V(ve(),"/api/did"),useSocket:!c,extraParams:{subscriptionId:t},messages:{scan:x("common.connect.defaultScan"),title:x("payment.customer.recover.reStakeTitle"),confirm:x("common.connect.confirm")},onSuccess:z,onClose:()=>{a.close(),j(!1)},onError:m=>{v.error(U(m)),j(!1)}})}catch(m){v.error(U(m)),j(!1)}},h=async()=>{j(!0);try{const m=await ft({subscriptionId:t,authToken:w});if(m.needStake){H();return}const{subscription:$}=m;d&&v.success(x("payment.customer.recover.success")),N(!1),p($),j(!1)}catch(m){v.error(U(m)),j(!1)}},C=()=>{R?H():h()},A=()=>{N(!1),o.onClose?.()};return q?null:e.jsx(Ne,{PaperProps:{style:{minHeight:"auto"}},...o||{},open:s,title:o?.title||x("payment.customer.recover.title"),sx:{"& .MuiDialogContent-root":{pt:0}},onClose:A,children:L?e.jsx(se,{severity:"error",children:L.message}):e.jsxs(g,{sx:{gap:2},children:[e.jsx(y,{variant:"body2",sx:{color:"text.secondary"},children:x("payment.customer.recover.description",{date:et(Number(_?.subscription?.current_period_end||"0")*1e3)})}),R&&e.jsx(se,{severity:"warning",children:x("payment.customer.recover.stakeRequiredDescription")}),e.jsxs(g,{direction:"row",sx:{justifyContent:"flex-end",gap:2,mt:2},children:[e.jsx(ne,{variant:"outlined",color:"primary",onClick:A,children:x("common.cancel")}),e.jsx(tt,{variant:"contained",size:"small",loading:P,onClick:C,children:x("common.confirm")})]})]})})}function yt({data:t}){const{t:o}=ie(),{control:p}=Te();return e.jsxs(g,{direction:"column",spacing:1,sx:{alignItems:"flex-start"},children:[e.jsx(y,{children:t.status==="trialing"?o("payment.customer.cancel.trialDescription"):o("payment.customer.cancel.description",{date:Se(t.current_period_end*1e3)})}),e.jsx(Pe,{name:"cancel.feedback",control:p,render:({field:d})=>e.jsxs($e,{...d,sx:{ml:"5px !important"},children:[e.jsx(D,{value:"too_expensive",control:e.jsx(M,{checked:d.value==="too_expensive"}),label:o("payment.customer.cancel.feedback.too_expensive")}),e.jsx(D,{value:"missing_features",control:e.jsx(M,{checked:d.value==="missing_features"}),label:o("payment.customer.cancel.feedback.missing_features",{date:Se(new Date(t.current_period_end*1e3))})}),e.jsx(D,{value:"switched_service",control:e.jsx(M,{checked:d.value==="switched_service"}),label:o("payment.customer.cancel.feedback.switched_service")}),e.jsx(D,{value:"unused",control:e.jsx(M,{checked:d.value==="unused"}),label:o("payment.customer.cancel.feedback.unused")}),e.jsx(D,{value:"customer_service",control:e.jsx(M,{checked:d.value==="customer_service"}),label:o("payment.customer.cancel.feedback.customer_service")}),e.jsx(D,{value:"too_complex",control:e.jsx(M,{checked:d.value==="too_complex"}),label:o("payment.customer.cancel.feedback.too_complex")}),e.jsx(D,{value:"low_quality",control:e.jsx(M,{checked:d.value==="low_quality"}),label:o("payment.customer.cancel.feedback.low_quality")}),e.jsx(D,{value:"other",control:e.jsx(M,{checked:d.value==="other"}),label:o("payment.customer.cancel.feedback.other")})]})}),e.jsx(Pe,{name:"cancel.comment",control:p,rules:{maxLength:{value:200,message:o("common.maxLength",{len:200})}},render:({field:d})=>e.jsx(Me,{variant:"outlined",size:"small",fullWidth:!0,multiline:!0,minRows:2,maxRows:4,placeholder:o("payment.customer.cancel.comment"),...d,slotProps:{htmlInput:{maxLength:200}}})})]})}const bt=(t,o)=>S.get(`/api/subscriptions/${t}/cycle-amount`,{params:o}).then(p=>p.data);function De(t,...o){if(!o.length)return"0";const p=t?.decimal||18,d=o.reduce((w,x)=>{if(!x||typeof x!="string"||!/^-?\d*\.?\d*$/.test(x.trim()))return w;const b=x.trim();if(b===""||b==="-")return w;try{const a=Xe(b,p);return new T(w).add(new T(a))}catch{return w}},new T(0));return B(d.toString(),p)}function vt({value:t,loading:o,onSave:p,onCancel:d,open:w,stakingAddress:x="",payerAddress:b="",currency:a,subscription:P,initValues:j=null}){const{t:s,locale:N}=ie(),{isMobile:_}=nt(),[L,q]=K.useState(!1),[c,R]=K.useState([]),{data:z={amount:"0",gas:"0"},loading:H}=W(()=>bt(P.id,{overdraftProtection:!0}),{refreshDeps:[P.id],onSuccess:l=>{const k=(()=>{const{interval:u,interval_count:r}=P.pending_invoice_item_interval;switch(u){case"hour":return[{cycles:Math.ceil(24/r),label:"1 day"},{cycles:Math.ceil(168/r),label:"1 week"},{cycles:Math.ceil(720/r),label:"1 month"},{cycles:Math.ceil(2160/r),label:"3 months"},{cycles:Math.ceil(4320/r),label:"6 months"}];case"day":return[{cycles:Math.ceil(7/r),label:"1 week"},{cycles:Math.ceil(30/r),label:"1 month"},{cycles:Math.ceil(90/r),label:"3 months"},{cycles:Math.ceil(180/r),label:"6 months"},{cycles:Math.ceil(365/r),label:"1 year"}];default:return[{cycles:1,label:"1x"},{cycles:2,label:"2x"},{cycles:3,label:"6x"},{cycles:6,label:"6x"},{cycles:12,label:"12x"}]}})(),F=u=>B(new T(l.amount).mul(new T(u)).toString(),l?.currency?.decimal);R(k.map(({cycles:u,label:r})=>({amount:F(u),cycles:u,label:r})))}}),h=Le({defaultValues:{enabled:!!P.overdraft_protection?.enabled,return_stake:!1,amount:"0",...j||{}},mode:"onChange"}),C=h.watch("enabled"),A=h.watch("amount"),m=B(z.amount,a?.decimal),$=B(t.unused,a?.decimal),X=B(t.used,a?.decimal),f=B(new T(z.amount).sub(new T(t.unused)).toString(),a?.decimal),E=()=>{q(!0),h.setValue("amount",Number(f)<0?m:f)},le=()=>{h.handleSubmit(async l=>{await p(l)})()},Y=l=>{const{interval:k,interval_count:F}=P.pending_invoice_item_interval,u=l*F;return["hour","day","week","month","year"].includes(k)?s("common.estimatedDuration",{duration:dt(u,k,{t:s})}):s("customer.overdraftProtection.estimatedDuration",{duration:u,unit:s("customer.overdraftProtection.intervals").toLowerCase()})},de=()=>V(P.paymentMethod?.settings.arcblock?.explorer_host,"/stakes",x,"/tokens");Ke(()=>{h&&h.reset()});const Q=l=>{h.reset(),d(l)};return e.jsx(Ne,{open:w,onClose:Q,maxWidth:"sm",fullWidth:!0,className:"base-dialog",title:e.jsxs(g,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(y,{variant:"h6",component:"span",children:s("customer.overdraftProtection.setting")}),e.jsx(be,{href:"https://www.arcblock.io/content/blog/en/payment-kit-v117-sub-guard#listen-to-the-audio-overview",target:"_blank",rel:"noopener noreferrer",underline:"hover",sx:{display:"flex",alignItems:"center",gap:.5,fontSize:"14px",fontWeight:"normal",ml:1,color:"text.link","&:hover":{color:"primary.main"},..._?{fontSize:"12px"}:{}},children:e.jsx(ce,{title:s("customer.overdraftProtection.learnMore"),placement:"top",children:e.jsx(He,{fontSize:"small",sx:{fontSize:"16px",color:"text.secondary",cursor:"pointer","&:hover":{color:"primary.main"}}})})})]}),actions:e.jsxs(g,{direction:"row",spacing:2,children:[e.jsx(ne,{variant:"outlined",onClick:Q,children:s("common.cancel")}),e.jsxs(ne,{variant:"contained",color:"primary",disabled:o,onClick:le,children:[o&&e.jsx(qe,{size:20,sx:{mr:1}}),s("common.submit")]})]}),children:e.jsxs(g,{sx:{gap:2},children:[e.jsx(se,{severity:"info",children:t.used!=="0"&&!C?e.jsx(e.Fragment,{children:s("customer.overdraftProtection.disableConfirm")}):e.jsxs(G,{children:[s("customer.overdraftProtection.tip"),e.jsx(ce,{title:s("customer.overdraftProtection.ruleTip",{gas:B(z.gas,a?.decimal),symbol:a.symbol}),placement:"top",children:e.jsx(y,{variant:"body2",sx:{color:"text.link",cursor:"pointer",mt:1},children:s("customer.overdraftProtection.rule")})})]})}),e.jsxs(g,{spacing:2,direction:"row",sx:{alignItems:"center"},children:[e.jsx(y,{variant:"subtitle1",sx:{color:"text.secondary"},children:s("customer.overdraftProtection.title")}),e.jsx(D,{control:e.jsx(ot,{checked:C,onChange:l=>h.setValue("enabled",l.target.checked)}),label:""})]}),C?e.jsxs(g,{sx:{gap:1,mt:"-8px"},children:[b&&e.jsxs(g,{sx:_?{flexDirection:"column",gap:1}:{flexDirection:"row",alignItems:"center",gap:2},children:[e.jsx(y,{variant:"subtitle2",sx:{color:"text.secondary"},children:s("customer.overdraftProtection.payerAddress")}),e.jsx(y,{variant:"body2",sx:{wordBreak:"break-all",fontFamily:"monospace",fontWeight:"700"},children:b})]}),x&&e.jsxs(g,{sx:_?{flexDirection:"column",gap:1}:{flexDirection:"row",alignItems:"center",gap:2},children:[e.jsx(y,{variant:"subtitle2",sx:{color:"text.secondary"},children:s("customer.overdraftProtection.stakingAddress")}),e.jsxs(be,{href:de(),target:"_blank",rel:"noopener noreferrer",sx:{wordBreak:"break-all",fontFamily:"monospace",fontWeight:"700",textDecoration:"none",color:"text.link",display:"flex",flexWrap:"wrap",alignItems:"center",gap:1},children:[x,!_&&e.jsx(Ue,{fontSize:"small"})]})]}),e.jsx(y,{variant:"body2",sx:{color:"text.secondary"},children:Number(X)>0&&!t.enabled?s("customer.overdraftProtection.remainingNotEnough",{due:X,symbol:a.symbol,min:Number(f)<0?m:f,unused:$}):t.remaining==="0"?s("customer.overdraftProtection.noRemaining",{estimateAmount:m,symbol:a.symbol}):s("customer.overdraftProtection.remaining",{amount:$,symbol:a.symbol,estimateAmount:m})}),e.jsx(te,{container:!0,spacing:2,sx:{ml:-2,mt:-1},children:H?e.jsxs(e.Fragment,{children:[[1,2,3,4,5].map(l=>e.jsx(te,{size:{xs:6,sm:4},children:e.jsx(ae,{variant:"outlined",sx:{height:"100%"},children:e.jsx(re,{sx:{height:"100%",p:1},children:e.jsxs(g,{spacing:1,sx:{alignItems:"center"},children:[e.jsx(fe,{variant:"rectangular",width:80,height:32}),e.jsx(fe,{width:100})]})})})},l)),e.jsx(te,{size:{xs:6,sm:4},children:e.jsx(ae,{variant:"outlined",sx:{height:"100%"},children:e.jsx(re,{sx:{height:"100%",p:2},children:e.jsx(g,{spacing:1,sx:{alignItems:"center"},children:e.jsx(fe,{variant:"rectangular",width:80,height:24})})})})})]}):e.jsxs(e.Fragment,{children:[c.map(({amount:l,cycles:k})=>e.jsx(te,{size:{xs:6,sm:4},children:e.jsx(ae,{variant:"outlined",sx:{height:"100%",transition:"all 0.3s",cursor:"pointer","&:hover":{transform:"translateY(-4px)",boxShadow:3},...A===l&&!L?{borderColor:"primary.main",borderWidth:1}:{}},children:e.jsx(re,{onClick:()=>{h.setValue("amount",l),q(!1)},sx:{height:"100%",p:1},children:e.jsxs(g,{spacing:1,sx:{alignItems:"center"},children:[e.jsxs(y,{variant:"h6",sx:{fontWeight:600},children:[l," ",a.symbol]}),e.jsx(y,{variant:"caption",sx:{color:"text.secondary"},children:Y(k)})]})})})},l)),e.jsx(te,{size:{xs:6,sm:4},children:e.jsx(ae,{variant:"outlined",sx:{height:"100%",transition:"all 0.3s",cursor:"pointer","&:hover":{transform:"translateY(-4px)",boxShadow:3},...L?{borderColor:"primary.main",borderWidth:1}:{}},children:e.jsx(re,{onClick:E,sx:{height:"100%",p:2},children:e.jsx(g,{spacing:1,sx:{alignItems:"center"},children:e.jsx(y,{variant:"h6",sx:{fontWeight:600},children:s("common.custom")})})})})})]})}),L&&e.jsx(g,{spacing:2,sx:{mt:1},children:e.jsx(Ve,{fullWidth:!0,children:e.jsx(Me,{...h.register("amount",{required:!0,validate:l=>{const k=Number(f)<0?Number(m):Number(f);if(Number(l)<k)return s("customer.overdraftProtection.min",{min:k,symbol:a.symbol});if(Number(l)>ge)return s("common.maxAmount",{max:ge});const F=at(l.toString(),N,a?.maximum_precision||6);return F||!0}}),label:s("common.amount"),type:"number",error:!!h.formState.errors.amount,helperText:h.formState.errors.amount?.message,fullWidth:!0,variant:"outlined",slotProps:{input:{endAdornment:e.jsx(G,{sx:{ml:1,display:"flex",alignItems:"center"},children:e.jsx(lt,{logo:a.logo,name:a.symbol})})},htmlInput:{min:0,max:ge,step:Number(m)}}})})}),A&&Number(A)>0&&Number(m)>0&&!h.formState.errors.amount&&e.jsxs(y,{variant:"body2",sx:{fontSize:12,color:"text.lighter",mt:"8px !important"},children:[s("customer.overdraftProtection.total",{total:De(a,A,$),symbol:a.symbol}),Y(Math.floor(Number(De(a,A,$))/Number(m)))]})]}):Number($)>0&&e.jsxs(g,{direction:"row",sx:{alignItems:"flex-start",gap:2},children:[e.jsx(y,{variant:"subtitle2",sx:{color:"text.secondary",height:39,display:"flex",alignItems:"center",width:56},children:s("customer.overdraftProtection.stake")}),e.jsxs($e,{"aria-labelledby":"return-stake-group-label",value:h.watch("return_stake"),onChange:l=>h.setValue("return_stake",l.target.value==="true"),children:[e.jsx(D,{value:!1,control:e.jsx(M,{}),label:s("customer.overdraftProtection.keepStake")}),e.jsx(D,{value:!0,control:e.jsx(M,{color:"warning"}),label:s("customer.overdraftProtection.returnStake")})]})]})]})})}const jt=async t=>{try{return!!(await S.get(`/api/subscriptions/${t}/change-plan`)).data}catch{return!1}},kt=async t=>{try{const o=await S.get(`/api/subscriptions/${t}/summary`);return!Qe(o.data)&&Object.keys(o.data).length===1?Object.keys(o.data)[0]:""}catch{return""}},ye=t=>["active","trialing","past_due"].includes(t?.status)&&["arcblock","ethereum","base"].includes(t?.paymentMethod?.type)&&t.paymentCurrency?.type!=="credit";function wt({subscription:t,showExtra:o=!1,showRecharge:p=!1,showOverdraftProtection:d=!1,showDelegation:w=!1,showUnsubscribe:x=!0,onChange:b=void 0,actionProps:a={},mode:P="all-buttons",setUp:j=void 0,showBalanceInfo:s=!1,includeActions:N=null,excludeActions:_=null,forceShowDetailAction:L=!1,buttonSize:q="small"}){const{t:c,locale:R}=ie(),{reset:z,getValues:H}=Te(),h=ht(),{connect:C,session:A}=Fe(),[m,$]=K.useState(t),{checkUnpaidInvoices:X}=mt(t.id,!0),f=st(m,a??{}),E=i=>_&&_.length>0?!_.includes(i):N&&N.length>0?N.includes(i):!0,le=i=>{const I=i?.metadata?.credit_config?.schedule;return I?.enabled&&I?.delivery_mode==="schedule"},Y=(t.items||[]).some(i=>le(i.price)),{data:de=!1}=W(()=>jt(t.id),{ready:!!o&&ut(t)&&!Y}),{data:Q=""}=W(()=>kt(t.id),{ready:!!o}),{data:l={}}=W(()=>S.get(`/api/subscriptions/${t.id}/upcoming`).then(i=>i.data),{ready:E("recharge")&&!!(p&&ye(t))&&s}),{data:k={}}=W(()=>S.get(`/api/subscriptions/${t.id}/payer-token`).then(i=>i.data),{ready:E("recharge")&&!!(p&&ye(t))&&s}),F=l?.amount&&k?.token&&new T(k.token||"0").lt(new T(l.amount||"0")),[u,r]=Ye({action:"",subscription:"",loading:!1,openProtection:!1,protectionLoading:!1,protectionInitValues:null,batchPay:!1}),je=w&&["active","trialing","past_due"].includes(t?.status),ue=(typeof d=="boolean"&&d||typeof d=="object"&&d.show)&&t?.paymentMethod?.type==="arcblock"&&["active","trialing","past_due"].includes(t?.status)&&E("protection"),{data:me={sufficient:!0},refresh:Re}=W(()=>S.get(`/api/subscriptions/${t.id}/delegation`).then(i=>i.data),{ready:E("delegation")&&je,refreshDeps:[t.id,je]}),We=me&&typeof me=="object"&&!me.sufficient,{data:ke={enabled:!1,remaining:"0"},refresh:he}=W(()=>S.get(`/api/subscriptions/${t.id}/overdraft-protection`).then(i=>i.data),{ready:ue,refreshDeps:[t.id,ue]});K.useEffect(()=>{j&&j({openOverdraftProtection:i=>r({openProtection:!0,protectionInitValues:i})})},[j]);const ze=async()=>{try{if(await X()){r({action:""});return}r({loading:!0});const I=await S.put(`/api/subscriptions/${u.subscription}/cancel`,{at:"current_period_end",...H().cancel,cancel_from:"customer"}).then(J=>J.data);$(I),v.success(c("common.saved")),b&&b(u.action)}catch(i){console.error(i),v.error(U(i))}finally{r({loading:!1,action:"",subscription:""}),z()}},Ee=()=>{C.open({containerEl:void 0,saveConnect:!1,action:"delegation",locale:R,prefix:V(ve(),"/api/did"),extraParams:{subscriptionId:t.id,sessionUserDid:A.user.did},messages:{scan:c("common.connect.defaultScan"),title:c("customer.delegation.title"),confirm:c("common.connect.confirm")},onSuccess:()=>{C.close(),v.success(c("customer.delegation.success")),Re()},onClose:()=>{C.close()},onError:i=>{v.error(U(i))}})},Oe=async i=>{try{if(!i.enabled&&await X()){r({openProtection:!1});return}r({protectionLoading:!0});const I=await S.post(`/api/subscriptions/${t.id}/overdraft-protection`,i).then(pe=>pe.data),{open:J,amount:oe}=I;if(i.return_stake&&ke.remaining!=="0"){v.success(c("customer.overdraftProtection.applyRemainingSuccess")),r({openProtection:!1}),he(),d?.onChange?.(),b?.();return}J?C.open({containerEl:void 0,saveConnect:!1,locale:R,action:"overdraft-protection",prefix:V(ve(),"/api/did"),extraParams:{subscriptionId:t.id,amount:oe,sessionUserDid:A.user.did},messages:{scan:c("common.connect.defaultScan"),title:c("customer.overdraftProtection.title"),confirm:c("common.connect.confirm")},onSuccess:()=>{C.close(),t.overdraft_protection?.enabled?v.success(c("customer.overdraftProtection.settingSuccess")):v.success(c("customer.overdraftProtection.openSuccess")),r({openProtection:!1}),he(),d?.onChange?.(),b?.()},onClose:()=>{C.close(),r({protectionLoading:!1})}}):(v.success(c("customer.overdraftProtection.closeSuccess")),r({openProtection:!1}),he(),d?.onChange?.(),b?.())}catch(I){throw v.error(U(I)||c("customer.overdraftProtection.settingError")),I}finally{r({protectionLoading:!1})}},Be=()=>{const i=f?.action==="cancel"&&x,I=f&&(f?.action!=="cancel"||i),J=Ae(t)&&f?.action==="recover",oe=t.service_actions?.filter(n=>n?.type!=="notification")||[],Z=[{key:"delegation",show:w&&We,label:c("customer.delegation.btn"),tooltip:c("customer.delegation.title"),onClick:Ee,variant:a?.delegation?.variant||"outlined",color:a?.delegation?.color||"primary",primary:!0},{key:"protection",show:ue,label:c("customer.overdraftProtection.setting"),onClick:()=>r({openProtection:!0,protectionInitValues:null}),variant:a?.protection?.variant||"outlined",color:a?.protection?.color||"primary"},{key:"recharge",show:!!(p&&ye(t)),label:()=>{const n=e.jsxs(g,{direction:"row",spacing:.5,sx:{alignItems:"center"},children:[e.jsx(Ge,{fontSize:"small"}),c("customer.recharge.title")]});if(s&&t.paymentCurrency){const O=_e(k?.token||"0",t.paymentCurrency.decimal),ee=_e(l?.amount||"0",t.paymentCurrency.decimal);return e.jsx(ce,{title:e.jsxs(G,{children:[F&&e.jsx(se,{severity:"error",sx:{py:0,mb:1},children:c("admin.subscription.insufficientBalance")}),e.jsxs(g,{spacing:.5,children:[e.jsxs(G,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(y,{sx:{color:"text.secondary"},variant:"body2",children:c("admin.subscription.currentBalance")}),e.jsxs(y,{variant:"body2",children:[O," ",t.paymentCurrency.symbol]})]}),e.jsxs(G,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(y,{sx:{color:"text.secondary"},variant:"body2",children:c("admin.subscription.nextInvoiceAmount")}),e.jsxs(y,{variant:"body2",children:[ee," ",t.paymentCurrency.symbol]})]}),e.jsxs(G,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(y,{sx:{color:"text.secondary"},variant:"body2",children:c("admin.subscription.paymentAddress")}),e.jsx(Je,{did:k?.paymentAddress,responsive:!1,compact:!0,showAvatar:!1})]})]})]}),placement:"top",slotProps:{tooltip:{sx:{bgcolor:"background.paper",color:"text.primary",boxShadow:2,padding:"10px 16px",maxWidth:480,minWidth:350,wordBreak:"break-word"}}},children:n})}return n},labelText:c("customer.recharge.title"),onClick:n=>{n?.stopPropagation(),h(`/customer/subscription/${t.id}/recharge`)},variant:a?.recharge?.variant||"outlined",color:a?.recharge?.color||"primary",primary:!Ae(t),sx:F||k.token==="0"?{"&::before":{content:'""',backgroundColor:"error.main",borderRadius:"50%",position:"absolute",top:"3px",right:"-3px",width:"6px",height:"6px",zIndex:1},...a?.recharge?.sx||{}}:a?.recharge?.sx||{}},{key:"changePlan",show:de&&!Y,label:f?.text||c("payment.customer.changePlan.button"),onClick:n=>{n?.stopPropagation(),h(`/customer/subscription/${t.id}/change-plan`)},variant:a?.changePlan?.variant||"contained",color:a?.changePlan?.color||"primary",sx:a?.changePlan?.sx},{key:"batchPay",show:!!Q,label:f?.text||c("admin.subscription.batchPay.button"),onClick:n=>{n?.stopPropagation(),r({batchPay:!0})},variant:a?.batchPay?.variant||"outlined",color:a?.batchPay?.color||"error",sx:a?.batchPay?.sx,primary:!0},{key:"mainAction",show:!!(!Q&&I),label:f?.text||c(`payment.customer.${f?.action}.button`),onClick:n=>{n?.stopPropagation(),f?.action==="pastDue"?h(`/customer/invoice/past-due?subscription=${t.id}`):f?.action==="recover"&&!t.paymentMethodDetails?v.error(c("admin.subscription.bindPaymentMethodFirst")):r({action:f?.action,subscription:t.id})},variant:f?.variant||"outlined",color:f?.color||"primary",sx:f?.sx,divider:oe.length>0,primary:J},...oe.map(n=>({key:n.name,show:!0,label:n.text[R]||n.text.en||n.name,onClick:()=>window.open(n.link,"_blank"),variant:n?.variant||"contained",color:n?.color||"primary",component:be,href:n.link,target:"_blank",sx:{textDecoration:"none !important"}}))].filter(n=>n.show&&E(n.key)),we=n=>({label:n.labelText||(typeof n.label=="function"?n.label():n.label),handler:n.onClick,color:n.color,divider:n.divider}),xe=L&&e.jsx(ne,{className:"action-button",sx:a?.detail?.sx||{},variant:a?.detail?.variant||"outlined",color:a?.detail?.color||"primary",onClick:()=>h(`/customer/subscription/${t.id}`),children:c("customer.subscription.manage")},"detail"),Ce=n=>{const O=typeof n.label=="function"?n.label():n.label;return e.jsx(ne,{variant:n.variant,color:n.color,onClick:n.onClick,component:n.component,href:n.href,target:n.target,sx:n.sx,className:"action-button",size:q,children:n.tooltip?e.jsx(ce,{title:n.tooltip,children:e.jsx("span",{children:O})}):O},n.key)};if(P==="menu-only")return e.jsxs(e.Fragment,{children:[xe,Z.length>0&&e.jsx(Ie,{actions:Z.map(we),variant:"outlined",sx:a?.menu?.sx||{}})]});if(P==="primary-buttons"){const n=Z.filter(ee=>ee.primary),O=Z.filter(ee=>!ee.primary);return e.jsxs(e.Fragment,{children:[xe,n.map(Ce),O.length>0&&e.jsx(Ie,{actions:O.map(we),variant:"outlined",sx:a?.menu?.sx||{}})]})}return e.jsxs(e.Fragment,{children:[xe,Z.map(Ce)]})};return e.jsxs(g,{direction:"row",sx:{alignItems:"center",gap:1,flexWrap:"wrap"},children:[Be(),u.action==="cancel"&&u.subscription&&e.jsx(ct,{onConfirm:ze,onCancel:i=>{i.stopPropagation(),r({action:"",subscription:""})},title:c("payment.customer.cancel.title"),message:e.jsx(yt,{data:t}),loading:u.loading}),u.action==="recover"&&u.subscription&&e.jsx(gt,{subscriptionId:u.subscription,onResumed:i=>{r({action:"",subscription:""}),b?.(u.action),$(i)},dialogProps:{open:!0,onClose:()=>r({action:"",subscription:""})}}),u.openProtection&&e.jsx(vt,{value:ke,onSave:Oe,open:u.openProtection,payerAddress:t.overdraft_protection?.payment_details?.arcblock?.payer,stakingAddress:t.overdraft_protection?.payment_details?.arcblock?.staking?.address,currency:t.paymentCurrency,subscription:t,loading:u.protectionLoading,onCancel:()=>r({openProtection:!1}),initValues:u.protectionInitValues}),u.batchPay&&e.jsx(it,{subscriptionId:t.id,onPaid:()=>{r({batchPay:!1}),b?.("batch-pay")},detailLinkOptions:{enabled:!1},dialogProps:{open:u.batchPay,onClose:()=>r({batchPay:!1})}})]})}function Nt(t){const o=Object.assign({showExtra:!1,showRecharge:!1,showBalanceInfo:!1,showOverdraftProtection:!1,showDelegation:!1,onChange:null,actionProps:{},mode:"all-buttons",setUp:null,showUnsubscribe:!0,includeActions:null,excludeActions:null,forceShowDetailAction:!1,buttonSize:"small"},t),p=Le({defaultValues:{cancel:{at:"current_period_end",feedback:"unused",comment:""}}});return e.jsx(rt,{...p,children:e.jsx(wt,{...o})})}export{Nt as S};
1
+ import{r as Y,j as e,A as se,a3 as g,q as y,x as ne,a_ as $e,aX as D,a$ as M,a2 as Me,B as G,O as ce,ai as be,by as Ue,$ as te,bg as ae,bl as re,a1 as fe,aQ as Ve,w as qe,b4 as He,bH as Ge}from"./vendor-mui-BXZut9Pz.js";import{V as ie,P as W,$ as Ne,F as V,Z as v,H as O,G as L,ap as Ye,L as Ke,Y as Xe,a6 as Qe,a7 as Ze}from"./vendor-blocklet-B67R14so.js";import{a as Fe,D as Je,q as et,L as tt,e as S,k as U,l as ve,E as Le,j as Se,C as Pe,d as nt,h as Te,S as ot,G as at,F as rt,H as st,I as ct,O as it,i as _e}from"./index-B4yaPb7B.js";import{C as lt}from"./currency-GstdXsJf.js";import{f as dt}from"./dayjs-DUNWtvju.js";import{M as ge,a as ut,i as Ae}from"./util-B8B3fsMa.js";import{A as Ie}from"./actions-BEUwbsq1.js";import{u as mt}from"./subscription-Bzeblscr.js";import{a as ht}from"./vendor-react-BPknnnEA.js";const pt=async t=>{const o=`/api/subscriptions/${t.subscriptionId}`;return(await S.get(t.authToken?V(o,`?authToken=${t.authToken}`):o)).data},xt=async t=>{const o=`/api/subscriptions/${t.subscriptionId}/recover-info`;return(await S.get(t.authToken?V(o,`?authToken=${t.authToken}`):o)).data},ft=async t=>{const o=`/api/subscriptions/${t.subscriptionId}/recover`;return(await S.put(t.authToken?V(o,`?authToken=${t.authToken}`):o)).data};function gt({subscriptionId:t,dialogProps:o={open:!0},onResumed:p=()=>{},successToast:d=!0,authToken:w=void 0}){const{t:x,locale:b}=ie(),{connect:a}=Fe(),[P,j]=Y.useState(!1),[s,N]=Y.useState(o.open||!1),{data:_,error:T,loading:q}=W(()=>xt({subscriptionId:t,authToken:w}),{ready:!!t}),c=Je(),R=_?.needStake??!1,z=async()=>{try{const m=await pt({subscriptionId:t,authToken:w});d&&v.success(x("payment.customer.recover.success")),N(!1),p(m),j(!1)}catch(m){console.error("Failed to fetch updated subscription:",m),v.error(U(m)),j(!1)}},H=()=>{j(!0);try{a.open({locale:b,containerEl:void 0,saveConnect:!1,action:"re-stake",prefix:V(ve(),"/api/did"),useSocket:!c,extraParams:{subscriptionId:t},messages:{scan:x("common.connect.defaultScan"),title:x("payment.customer.recover.reStakeTitle"),confirm:x("common.connect.confirm")},onSuccess:z,onClose:()=>{a.close(),j(!1)},onError:m=>{v.error(U(m)),j(!1)}})}catch(m){v.error(U(m)),j(!1)}},h=async()=>{j(!0);try{const m=await ft({subscriptionId:t,authToken:w});if(m.needStake){H();return}const{subscription:$}=m;d&&v.success(x("payment.customer.recover.success")),N(!1),p($),j(!1)}catch(m){v.error(U(m)),j(!1)}},C=()=>{R?H():h()},A=()=>{N(!1),o.onClose?.()};return q?null:e.jsx(Ne,{PaperProps:{style:{minHeight:"auto"}},...o||{},open:s,title:o?.title||x("payment.customer.recover.title"),sx:{"& .MuiDialogContent-root":{pt:0}},onClose:A,children:T?e.jsx(se,{severity:"error",children:T.message}):e.jsxs(g,{sx:{gap:2},children:[e.jsx(y,{variant:"body2",sx:{color:"text.secondary"},children:x("payment.customer.recover.description",{date:et(Number(_?.subscription?.current_period_end||"0")*1e3)})}),R&&e.jsx(se,{severity:"warning",children:x("payment.customer.recover.stakeRequiredDescription")}),e.jsxs(g,{direction:"row",sx:{justifyContent:"flex-end",gap:2,mt:2},children:[e.jsx(ne,{variant:"outlined",color:"primary",onClick:A,children:x("common.cancel")}),e.jsx(tt,{variant:"contained",size:"small",loading:P,onClick:C,children:x("common.confirm")})]})]})})}function yt({data:t}){const{t:o}=ie(),{control:p}=Le();return e.jsxs(g,{direction:"column",spacing:1,sx:{alignItems:"flex-start"},children:[e.jsx(y,{children:t.status==="trialing"?o("payment.customer.cancel.trialDescription"):o("payment.customer.cancel.description",{date:Se(t.current_period_end*1e3)})}),e.jsx(Pe,{name:"cancel.feedback",control:p,render:({field:d})=>e.jsxs($e,{...d,sx:{ml:"5px !important"},children:[e.jsx(D,{value:"too_expensive",control:e.jsx(M,{checked:d.value==="too_expensive"}),label:o("payment.customer.cancel.feedback.too_expensive")}),e.jsx(D,{value:"missing_features",control:e.jsx(M,{checked:d.value==="missing_features"}),label:o("payment.customer.cancel.feedback.missing_features",{date:Se(new Date(t.current_period_end*1e3))})}),e.jsx(D,{value:"switched_service",control:e.jsx(M,{checked:d.value==="switched_service"}),label:o("payment.customer.cancel.feedback.switched_service")}),e.jsx(D,{value:"unused",control:e.jsx(M,{checked:d.value==="unused"}),label:o("payment.customer.cancel.feedback.unused")}),e.jsx(D,{value:"customer_service",control:e.jsx(M,{checked:d.value==="customer_service"}),label:o("payment.customer.cancel.feedback.customer_service")}),e.jsx(D,{value:"too_complex",control:e.jsx(M,{checked:d.value==="too_complex"}),label:o("payment.customer.cancel.feedback.too_complex")}),e.jsx(D,{value:"low_quality",control:e.jsx(M,{checked:d.value==="low_quality"}),label:o("payment.customer.cancel.feedback.low_quality")}),e.jsx(D,{value:"other",control:e.jsx(M,{checked:d.value==="other"}),label:o("payment.customer.cancel.feedback.other")})]})}),e.jsx(Pe,{name:"cancel.comment",control:p,rules:{maxLength:{value:200,message:o("common.maxLength",{len:200})}},render:({field:d})=>e.jsx(Me,{variant:"outlined",size:"small",fullWidth:!0,multiline:!0,minRows:2,maxRows:4,placeholder:o("payment.customer.cancel.comment"),...d,slotProps:{htmlInput:{maxLength:200}}})})]})}const bt=(t,o)=>S.get(`/api/subscriptions/${t}/cycle-amount`,{params:o}).then(p=>p.data);function De(t,...o){if(!o.length)return"0";const p=t?.decimal||18,d=o.reduce((w,x)=>{if(!x||typeof x!="string"||!/^-?\d*\.?\d*$/.test(x.trim()))return w;const b=x.trim();if(b===""||b==="-")return w;try{const a=Ke(b,p);return new L(w).add(new L(a))}catch{return w}},new L(0));return O(d.toString(),p)}function vt({value:t,loading:o,onSave:p,onCancel:d,open:w,stakingAddress:x="",payerAddress:b="",currency:a,subscription:P,initValues:j=null}){const{t:s,locale:N}=ie(),{isMobile:_}=nt(),[T,q]=Y.useState(!1),[c,R]=Y.useState([]),{data:z={amount:"0",gas:"0"},loading:H}=W(()=>bt(P.id,{overdraftProtection:!0}),{refreshDeps:[P.id],onSuccess:l=>{const k=(()=>{const{interval:u,interval_count:r}=P.pending_invoice_item_interval;switch(u){case"hour":return[{cycles:Math.ceil(24/r),label:"1 day"},{cycles:Math.ceil(168/r),label:"1 week"},{cycles:Math.ceil(720/r),label:"1 month"},{cycles:Math.ceil(2160/r),label:"3 months"},{cycles:Math.ceil(4320/r),label:"6 months"}];case"day":return[{cycles:Math.ceil(7/r),label:"1 week"},{cycles:Math.ceil(30/r),label:"1 month"},{cycles:Math.ceil(90/r),label:"3 months"},{cycles:Math.ceil(180/r),label:"6 months"},{cycles:Math.ceil(365/r),label:"1 year"}];default:return[{cycles:1,label:"1x"},{cycles:2,label:"2x"},{cycles:3,label:"6x"},{cycles:6,label:"6x"},{cycles:12,label:"12x"}]}})(),F=u=>O(new L(l.amount).mul(new L(u)).toString(),l?.currency?.decimal);R(k.map(({cycles:u,label:r})=>({amount:F(u),cycles:u,label:r})))}}),h=Te({defaultValues:{enabled:!!P.overdraft_protection?.enabled,return_stake:!1,amount:"0",...j||{}},mode:"onChange"}),C=h.watch("enabled"),A=h.watch("amount"),m=O(z.amount,a?.decimal),$=O(t.unused,a?.decimal),K=O(t.used,a?.decimal),f=O(new L(z.amount).sub(new L(t.unused)).toString(),a?.decimal),B=()=>{q(!0),h.setValue("amount",Number(f)<0?m:f)},le=()=>{h.handleSubmit(async l=>{await p(l)})()},X=l=>{const{interval:k,interval_count:F}=P.pending_invoice_item_interval,u=l*F;return["hour","day","week","month","year"].includes(k)?s("common.estimatedDuration",{duration:dt(u,k,{t:s})}):s("customer.overdraftProtection.estimatedDuration",{duration:u,unit:s("customer.overdraftProtection.intervals").toLowerCase()})},de=()=>V(P.paymentMethod?.settings.arcblock?.explorer_host,"/stakes",x,"/tokens");Ye(()=>{h&&h.reset()});const Q=l=>{h.reset(),d(l)};return e.jsx(Ne,{open:w,onClose:Q,maxWidth:"sm",fullWidth:!0,className:"base-dialog",title:e.jsxs(g,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(y,{variant:"h6",component:"span",children:s("customer.overdraftProtection.setting")}),e.jsx(be,{href:"https://www.arcblock.io/content/blog/en/payment-kit-v117-sub-guard#listen-to-the-audio-overview",target:"_blank",rel:"noopener noreferrer",underline:"hover",sx:{display:"flex",alignItems:"center",gap:.5,fontSize:"14px",fontWeight:"normal",ml:1,color:"text.link","&:hover":{color:"primary.main"},..._?{fontSize:"12px"}:{}},children:e.jsx(ce,{title:s("customer.overdraftProtection.learnMore"),placement:"top",children:e.jsx(He,{fontSize:"small",sx:{fontSize:"16px",color:"text.secondary",cursor:"pointer","&:hover":{color:"primary.main"}}})})})]}),actions:e.jsxs(g,{direction:"row",spacing:2,children:[e.jsx(ne,{variant:"outlined",onClick:Q,children:s("common.cancel")}),e.jsxs(ne,{variant:"contained",color:"primary",disabled:o,onClick:le,children:[o&&e.jsx(qe,{size:20,sx:{mr:1}}),s("common.submit")]})]}),children:e.jsxs(g,{sx:{gap:2},children:[e.jsx(se,{severity:"info",children:t.used!=="0"&&!C?e.jsx(e.Fragment,{children:s("customer.overdraftProtection.disableConfirm")}):e.jsxs(G,{children:[s("customer.overdraftProtection.tip"),e.jsx(ce,{title:s("customer.overdraftProtection.ruleTip",{gas:O(z.gas,a?.decimal),symbol:a.symbol}),placement:"top",children:e.jsx(y,{variant:"body2",sx:{color:"text.link",cursor:"pointer",mt:1},children:s("customer.overdraftProtection.rule")})})]})}),e.jsxs(g,{spacing:2,direction:"row",sx:{alignItems:"center"},children:[e.jsx(y,{variant:"subtitle1",sx:{color:"text.secondary"},children:s("customer.overdraftProtection.title")}),e.jsx(D,{control:e.jsx(ot,{checked:C,onChange:l=>h.setValue("enabled",l.target.checked)}),label:""})]}),C?e.jsxs(g,{sx:{gap:1,mt:"-8px"},children:[b&&e.jsxs(g,{sx:_?{flexDirection:"column",gap:1}:{flexDirection:"row",alignItems:"center",gap:2},children:[e.jsx(y,{variant:"subtitle2",sx:{color:"text.secondary"},children:s("customer.overdraftProtection.payerAddress")}),e.jsx(y,{variant:"body2",sx:{wordBreak:"break-all",fontFamily:"monospace",fontWeight:"700"},children:b})]}),x&&e.jsxs(g,{sx:_?{flexDirection:"column",gap:1}:{flexDirection:"row",alignItems:"center",gap:2},children:[e.jsx(y,{variant:"subtitle2",sx:{color:"text.secondary"},children:s("customer.overdraftProtection.stakingAddress")}),e.jsxs(be,{href:de(),target:"_blank",rel:"noopener noreferrer",sx:{wordBreak:"break-all",fontFamily:"monospace",fontWeight:"700",textDecoration:"none",color:"text.link",display:"flex",flexWrap:"wrap",alignItems:"center",gap:1},children:[x,!_&&e.jsx(Ue,{fontSize:"small"})]})]}),e.jsx(y,{variant:"body2",sx:{color:"text.secondary"},children:Number(K)>0&&!t.enabled?s("customer.overdraftProtection.remainingNotEnough",{due:K,symbol:a.symbol,min:Number(f)<0?m:f,unused:$}):t.remaining==="0"?s("customer.overdraftProtection.noRemaining",{estimateAmount:m,symbol:a.symbol}):s("customer.overdraftProtection.remaining",{amount:$,symbol:a.symbol,estimateAmount:m})}),e.jsx(te,{container:!0,spacing:2,sx:{ml:-2,mt:-1},children:H?e.jsxs(e.Fragment,{children:[[1,2,3,4,5].map(l=>e.jsx(te,{size:{xs:6,sm:4},children:e.jsx(ae,{variant:"outlined",sx:{height:"100%"},children:e.jsx(re,{sx:{height:"100%",p:1},children:e.jsxs(g,{spacing:1,sx:{alignItems:"center"},children:[e.jsx(fe,{variant:"rectangular",width:80,height:32}),e.jsx(fe,{width:100})]})})})},l)),e.jsx(te,{size:{xs:6,sm:4},children:e.jsx(ae,{variant:"outlined",sx:{height:"100%"},children:e.jsx(re,{sx:{height:"100%",p:2},children:e.jsx(g,{spacing:1,sx:{alignItems:"center"},children:e.jsx(fe,{variant:"rectangular",width:80,height:24})})})})})]}):e.jsxs(e.Fragment,{children:[c.map(({amount:l,cycles:k})=>e.jsx(te,{size:{xs:6,sm:4},children:e.jsx(ae,{variant:"outlined",sx:{height:"100%",transition:"all 0.3s",cursor:"pointer","&:hover":{transform:"translateY(-4px)",boxShadow:3},...A===l&&!T?{borderColor:"primary.main",borderWidth:1}:{}},children:e.jsx(re,{onClick:()=>{h.setValue("amount",l),q(!1)},sx:{height:"100%",p:1},children:e.jsxs(g,{spacing:1,sx:{alignItems:"center"},children:[e.jsxs(y,{variant:"h6",sx:{fontWeight:600},children:[l," ",a.symbol]}),e.jsx(y,{variant:"caption",sx:{color:"text.secondary"},children:X(k)})]})})})},l)),e.jsx(te,{size:{xs:6,sm:4},children:e.jsx(ae,{variant:"outlined",sx:{height:"100%",transition:"all 0.3s",cursor:"pointer","&:hover":{transform:"translateY(-4px)",boxShadow:3},...T?{borderColor:"primary.main",borderWidth:1}:{}},children:e.jsx(re,{onClick:B,sx:{height:"100%",p:2},children:e.jsx(g,{spacing:1,sx:{alignItems:"center"},children:e.jsx(y,{variant:"h6",sx:{fontWeight:600},children:s("common.custom")})})})})})]})}),T&&e.jsx(g,{spacing:2,sx:{mt:1},children:e.jsx(Ve,{fullWidth:!0,children:e.jsx(Me,{...h.register("amount",{required:!0,validate:l=>{const k=Number(f)<0?Number(m):Number(f);if(Number(l)<k)return s("customer.overdraftProtection.min",{min:k,symbol:a.symbol});if(Number(l)>ge)return s("common.maxAmount",{max:ge});const F=at(l.toString(),N,a?.maximum_precision||6);return F||!0}}),label:s("common.amount"),type:"number",error:!!h.formState.errors.amount,helperText:h.formState.errors.amount?.message,fullWidth:!0,variant:"outlined",slotProps:{input:{endAdornment:e.jsx(G,{sx:{ml:1,display:"flex",alignItems:"center"},children:e.jsx(lt,{logo:a.logo,name:a.symbol})})},htmlInput:{min:0,max:ge,step:Number(m)}}})})}),A&&Number(A)>0&&Number(m)>0&&!h.formState.errors.amount&&e.jsxs(y,{variant:"body2",sx:{fontSize:12,color:"text.lighter",mt:"8px !important"},children:[s("customer.overdraftProtection.total",{total:De(a,A,$),symbol:a.symbol}),X(Math.floor(Number(De(a,A,$))/Number(m)))]})]}):Number($)>0&&e.jsxs(g,{direction:"row",sx:{alignItems:"flex-start",gap:2},children:[e.jsx(y,{variant:"subtitle2",sx:{color:"text.secondary",height:39,display:"flex",alignItems:"center",width:56},children:s("customer.overdraftProtection.stake")}),e.jsxs($e,{"aria-labelledby":"return-stake-group-label",value:h.watch("return_stake"),onChange:l=>h.setValue("return_stake",l.target.value==="true"),children:[e.jsx(D,{value:!1,control:e.jsx(M,{}),label:s("customer.overdraftProtection.keepStake")}),e.jsx(D,{value:!0,control:e.jsx(M,{color:"warning"}),label:s("customer.overdraftProtection.returnStake")})]})]})]})})}const jt=async t=>{try{return!!(await S.get(`/api/subscriptions/${t}/change-plan`)).data}catch{return!1}},kt=async t=>{try{const o=await S.get(`/api/subscriptions/${t}/summary`);return!Qe(o.data)&&Object.keys(o.data).length===1?Object.keys(o.data)[0]:""}catch{return""}},ye=t=>["active","trialing","past_due"].includes(t?.status)&&["arcblock","ethereum","base"].includes(t?.paymentMethod?.type)&&t.paymentCurrency?.type!=="credit";function wt({subscription:t,showExtra:o=!1,showRecharge:p=!1,showOverdraftProtection:d=!1,showDelegation:w=!1,showUnsubscribe:x=!0,onChange:b=void 0,actionProps:a={},mode:P="all-buttons",setUp:j=void 0,showBalanceInfo:s=!1,includeActions:N=null,excludeActions:_=null,forceShowDetailAction:T=!1,buttonSize:q="small"}){const{t:c,locale:R}=ie(),{reset:z,getValues:H}=Le(),h=ht(),{connect:C,session:A}=Fe(),[m,$]=Y.useState(t),{checkUnpaidInvoices:K}=mt(t.id,!0),f=st(m,a??{}),B=i=>_&&_.length>0?!_.includes(i):N&&N.length>0?N.includes(i):!0,le=i=>{const I=i?.metadata?.credit_config?.schedule;return I?.enabled&&I?.delivery_mode==="schedule"},X=(t.items||[]).some(i=>le(i.price)),{data:de=!1}=W(()=>jt(t.id),{ready:!!o&&ut(t)&&!X}),{data:Q=""}=W(()=>kt(t.id),{ready:!!o}),{data:l={}}=W(()=>S.get(`/api/subscriptions/${t.id}/upcoming`).then(i=>i.data),{ready:B("recharge")&&!!(p&&ye(t))&&s}),{data:k={}}=W(()=>S.get(`/api/subscriptions/${t.id}/payer-token`).then(i=>i.data),{ready:B("recharge")&&!!(p&&ye(t))&&s}),F=l?.amount&&k?.token&&new L(k.token||"0").lt(new L(l.amount||"0")),[u,r]=Xe({action:"",subscription:"",loading:!1,openProtection:!1,protectionLoading:!1,protectionInitValues:null,batchPay:!1}),je=w&&["active","trialing","past_due"].includes(t?.status),ue=(typeof d=="boolean"&&d||typeof d=="object"&&d.show)&&t?.paymentMethod?.type==="arcblock"&&["active","trialing","past_due"].includes(t?.status)&&B("protection"),{data:me={sufficient:!0},refresh:Re}=W(()=>S.get(`/api/subscriptions/${t.id}/delegation`).then(i=>i.data),{ready:B("delegation")&&je,refreshDeps:[t.id,je]}),We=me&&typeof me=="object"&&!me.sufficient,{data:ke={enabled:!1,remaining:"0"},refresh:he}=W(()=>S.get(`/api/subscriptions/${t.id}/overdraft-protection`).then(i=>i.data),{ready:ue,refreshDeps:[t.id,ue]});Y.useEffect(()=>{j&&j({openOverdraftProtection:i=>r({openProtection:!0,protectionInitValues:i})})},[j]);const ze=async()=>{try{if(await K()){r({action:""});return}r({loading:!0});const I=await S.put(`/api/subscriptions/${u.subscription}/cancel`,{at:"current_period_end",...H().cancel,cancel_from:"customer"}).then(Z=>Z.data);$(I),v.success(c("common.saved")),b&&b(u.action)}catch(i){console.error(i),v.error(U(i))}finally{r({loading:!1,action:"",subscription:""}),z()}},Be=()=>{C.open({containerEl:void 0,saveConnect:!1,action:"delegation",locale:R,prefix:V(ve(),"/api/did"),extraParams:{subscriptionId:t.id,sessionUserDid:A.user.did},messages:{scan:c("common.connect.defaultScan"),title:c("customer.delegation.title"),confirm:c("common.connect.confirm")},onSuccess:()=>{C.close(),v.success(c("customer.delegation.success")),Re()},onClose:()=>{C.close()},onError:i=>{v.error(U(i))}})},Ee=async i=>{try{if(!i.enabled&&await K()){r({openProtection:!1});return}r({protectionLoading:!0});const I=await S.post(`/api/subscriptions/${t.id}/overdraft-protection`,i).then(pe=>pe.data),{open:Z,amount:oe}=I;if(i.return_stake&&ke.remaining!=="0"){v.success(c("customer.overdraftProtection.applyRemainingSuccess")),r({openProtection:!1}),he(),d?.onChange?.(),b?.();return}Z?C.open({containerEl:void 0,saveConnect:!1,locale:R,action:"overdraft-protection",prefix:V(ve(),"/api/did"),extraParams:{subscriptionId:t.id,amount:oe,sessionUserDid:A.user.did},messages:{scan:c("common.connect.defaultScan"),title:c("customer.overdraftProtection.title"),confirm:c("common.connect.confirm")},onSuccess:()=>{C.close(),t.overdraft_protection?.enabled?v.success(c("customer.overdraftProtection.settingSuccess")):v.success(c("customer.overdraftProtection.openSuccess")),r({openProtection:!1}),he(),d?.onChange?.(),b?.()},onClose:()=>{C.close(),r({protectionLoading:!1})}}):(v.success(c("customer.overdraftProtection.closeSuccess")),r({openProtection:!1}),he(),d?.onChange?.(),b?.())}catch(I){throw v.error(U(I)||c("customer.overdraftProtection.settingError")),I}finally{r({protectionLoading:!1})}},Oe=()=>{const i=f?.action==="cancel"&&x,I=f&&(f?.action!=="cancel"||i),Z=Ae(t)&&f?.action==="recover",oe=t.service_actions?.filter(n=>n?.type!=="notification")||[],J=[{key:"delegation",show:w&&We,label:c("customer.delegation.btn"),tooltip:c("customer.delegation.title"),onClick:Be,variant:a?.delegation?.variant||"outlined",color:a?.delegation?.color||"primary",primary:!0},{key:"protection",show:ue,label:c("customer.overdraftProtection.setting"),onClick:()=>r({openProtection:!0,protectionInitValues:null}),variant:a?.protection?.variant||"outlined",color:a?.protection?.color||"primary"},{key:"recharge",show:!!(p&&ye(t)),label:()=>{const n=e.jsxs(g,{direction:"row",spacing:.5,sx:{alignItems:"center"},children:[e.jsx(Ge,{fontSize:"small"}),c("customer.recharge.title")]});if(s&&t.paymentCurrency){const E=_e(k?.token||"0",t.paymentCurrency.decimal),ee=_e(l?.amount||"0",t.paymentCurrency.decimal);return e.jsx(ce,{title:e.jsxs(G,{children:[F&&e.jsx(se,{severity:"error",sx:{py:0,mb:1},children:c("admin.subscription.insufficientBalance")}),e.jsxs(g,{spacing:.5,children:[e.jsxs(G,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(y,{sx:{color:"text.secondary"},variant:"body2",children:c("admin.subscription.currentBalance")}),e.jsxs(y,{variant:"body2",children:[E," ",t.paymentCurrency.symbol]})]}),e.jsxs(G,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(y,{sx:{color:"text.secondary"},variant:"body2",children:c("admin.subscription.nextInvoiceAmount")}),e.jsxs(y,{variant:"body2",children:[ee," ",t.paymentCurrency.symbol]})]}),e.jsxs(G,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(y,{sx:{color:"text.secondary"},variant:"body2",children:c("admin.subscription.paymentAddress")}),e.jsx(Ze,{did:k?.paymentAddress,responsive:!1,compact:!0,showAvatar:!1})]})]})]}),placement:"top",slotProps:{tooltip:{sx:{bgcolor:"background.paper",color:"text.primary",boxShadow:2,padding:"10px 16px",maxWidth:480,minWidth:350,wordBreak:"break-word"}}},children:n})}return n},labelText:c("customer.recharge.title"),onClick:n=>{n?.stopPropagation(),h(`/customer/subscription/${t.id}/recharge`)},variant:a?.recharge?.variant||"outlined",color:a?.recharge?.color||"primary",primary:!Ae(t),sx:F||k.token==="0"?{"&::before":{content:'""',backgroundColor:"error.main",borderRadius:"50%",position:"absolute",top:"3px",right:"-3px",width:"6px",height:"6px",zIndex:1},...a?.recharge?.sx||{}}:a?.recharge?.sx||{}},{key:"changePlan",show:de&&!X,label:f?.text||c("payment.customer.changePlan.button"),onClick:n=>{n?.stopPropagation(),h(`/customer/subscription/${t.id}/change-plan`)},variant:a?.changePlan?.variant||"contained",color:a?.changePlan?.color||"primary",sx:a?.changePlan?.sx},{key:"batchPay",show:!!Q,label:f?.text||c("admin.subscription.batchPay.button"),onClick:n=>{n?.stopPropagation(),r({batchPay:!0})},variant:a?.batchPay?.variant||"outlined",color:a?.batchPay?.color||"error",sx:a?.batchPay?.sx,primary:!0},{key:"mainAction",show:!!(!Q&&I),label:f?.text||c(`payment.customer.${f?.action}.button`),onClick:n=>{n?.stopPropagation(),f?.action==="pastDue"?h(`/customer/invoice/past-due?subscription=${t.id}`):f?.action==="recover"&&!t.paymentMethodDetails?v.error(c("admin.subscription.bindPaymentMethodFirst")):r({action:f?.action,subscription:t.id})},variant:f?.variant||"outlined",color:f?.color||"primary",sx:f?.sx,divider:oe.length>0,primary:Z},...oe.map(n=>({key:n.name,show:!0,label:n.text[R]||n.text.en||n.name,onClick:()=>window.open(n.link,"_blank"),variant:n?.variant||"contained",color:n?.color||"primary",component:be,href:n.link,target:"_blank",sx:{textDecoration:"none !important"}}))].filter(n=>n.show&&B(n.key)),we=n=>({label:n.labelText||(typeof n.label=="function"?n.label():n.label),handler:n.onClick,color:n.color,divider:n.divider}),xe=T&&e.jsx(ne,{className:"action-button",sx:a?.detail?.sx||{},variant:a?.detail?.variant||"outlined",color:a?.detail?.color||"primary",onClick:()=>h(`/customer/subscription/${t.id}`),children:c("customer.subscription.manage")},"detail"),Ce=n=>{const E=typeof n.label=="function"?n.label():n.label;return e.jsx(ne,{variant:n.variant,color:n.color,onClick:n.onClick,component:n.component,href:n.href,target:n.target,sx:n.sx,className:"action-button",size:q,children:n.tooltip?e.jsx(ce,{title:n.tooltip,children:e.jsx("span",{children:E})}):E},n.key)};if(P==="menu-only")return e.jsxs(e.Fragment,{children:[xe,J.length>0&&e.jsx(Ie,{actions:J.map(we),variant:"outlined",sx:a?.menu?.sx||{}})]});if(P==="primary-buttons"){const n=J.filter(ee=>ee.primary),E=J.filter(ee=>!ee.primary);return e.jsxs(e.Fragment,{children:[xe,n.map(Ce),E.length>0&&e.jsx(Ie,{actions:E.map(we),variant:"outlined",sx:a?.menu?.sx||{}})]})}return e.jsxs(e.Fragment,{children:[xe,J.map(Ce)]})};return e.jsxs(g,{direction:"row",sx:{alignItems:"center",gap:1,flexWrap:"wrap"},children:[Oe(),u.action==="cancel"&&u.subscription&&e.jsx(ct,{onConfirm:ze,onCancel:i=>{i.stopPropagation(),r({action:"",subscription:""})},title:c("payment.customer.cancel.title"),message:e.jsx(yt,{data:t}),loading:u.loading}),u.action==="recover"&&u.subscription&&e.jsx(gt,{subscriptionId:u.subscription,onResumed:i=>{r({action:"",subscription:""}),b?.(u.action),$(i)},dialogProps:{open:!0,onClose:()=>r({action:"",subscription:""})}}),u.openProtection&&e.jsx(vt,{value:ke,onSave:Ee,open:u.openProtection,payerAddress:t.overdraft_protection?.payment_details?.arcblock?.payer,stakingAddress:t.overdraft_protection?.payment_details?.arcblock?.staking?.address,currency:t.paymentCurrency,subscription:t,loading:u.protectionLoading,onCancel:()=>r({openProtection:!1}),initValues:u.protectionInitValues}),u.batchPay&&e.jsx(it,{subscriptionId:t.id,onPaid:()=>{r({batchPay:!1}),b?.("batch-pay")},detailLinkOptions:{enabled:!1},dialogProps:{open:u.batchPay,onClose:()=>r({batchPay:!1})}})]})}function Nt(t){const o=Object.assign({showExtra:!1,showRecharge:!1,showBalanceInfo:!1,showOverdraftProtection:!1,showDelegation:!1,onChange:null,actionProps:{},mode:"all-buttons",setUp:null,showUnsubscribe:!0,includeActions:null,excludeActions:null,forceShowDetailAction:!1,buttonSize:"small"},t),p=Te({defaultValues:{cancel:{at:"current_period_end",feedback:"unused",comment:""}}});return e.jsx(rt,{...p,children:e.jsx(wt,{...o})})}export{Nt as S};
@@ -1 +1 @@
1
- import{j as e,r as R,a3 as S,a_ as P,aX as c,a$ as p,aQ as $,a2 as C,aZ as w,aR as N}from"./vendor-mui-BXZut9Pz.js";import{V as v,X as T,O as V,Y as y,G as E}from"./vendor-blocklet-D_i_QeSo.js";import{h as B,F as G,E as I,I as H,e as F,C as b,k as L,G as O}from"./index-DgSc1Qy8.js";import{A as W}from"./actions-jxGAdGfb.js";import{C as z}from"./click-boundary-y8dVA_tr.js";import{a as D}from"./vendor-react-BPknnnEA.js";function _(n,a,t=6){if(!n)return"0";const o=E(n,a),[s="0",u=""]=o.split(".");if(t<=0)return s;const m=u.substring(0,t).replace(/0+$/,"");return m?`${s}.${m}`:s}const U=n=>F.get(`/api/payment-intents/${n}/refundable-amount`).then(a=>a.data);function X({data:n,refundMaxAmount:a}){const{t,locale:o}=v(),{control:s,setValue:u,formState:{errors:m}}=I(),x=r=>{if(Number(r)<=0||Number(r)>Number(a))return t("admin.paymentIntent.refundForm.amountRange",{min:0,max:a,symbol:n.paymentCurrency.symbol});const l=O(r.toString(),o,n.paymentCurrency.maximum_precision||6);return l||!0};return e.jsxs(S,{direction:"column",spacing:1,sx:{alignItems:"flex-start",width:400},children:[e.jsx(b,{name:"refund.reason",control:s,render:({field:r})=>e.jsxs(P,{...r,sx:{ml:"5px !important"},children:[e.jsx(c,{value:"duplicate",control:e.jsx(p,{checked:r.value==="duplicate"}),label:t("admin.paymentIntent.refundForm.duplicate"),onClick:()=>u("refund.reason","duplicate")}),e.jsx(c,{value:"requested_by_customer",control:e.jsx(p,{checked:r.value==="requested_by_customer"}),label:t("admin.paymentIntent.refundForm.requestedByCustomer"),onClick:()=>u("refund.reason","requested_by_customer")}),e.jsx(c,{value:"requested_by_admin",control:e.jsx(p,{checked:r.value==="requested_by_admin"}),label:t("admin.paymentIntent.refundForm.requestedByAdmin"),onClick:()=>u("refund.reason","requested_by_admin")}),e.jsx(c,{value:"fraudulent",control:e.jsx(p,{checked:r.value==="fraudulent"}),label:t("admin.paymentIntent.refundForm.fraudulent"),onClick:()=>u("refund.reason","fraudulent")}),e.jsx(c,{value:"expired_uncaptured_charge",control:e.jsx(p,{checked:r.value==="expired_uncaptured_charge"}),label:t("admin.paymentIntent.refundForm.expiredUncapturedCharge"),onClick:()=>u("refund.reason","expired_uncaptured_charge")})]})}),e.jsxs($,{fullWidth:!0,component:"fieldset",variant:"outlined",children:[e.jsx(b,{name:"refund.amount",control:s,rules:{validate:x},render:({field:r})=>e.jsx(C,{...r,variant:"outlined",size:"small",type:"number",fullWidth:!0,placeholder:t("admin.paymentIntent.refundForm.amount"),error:!!m?.refund?.amount,helperText:m?.refund?.amount?.message,slotProps:{input:{endAdornment:e.jsx(w,{position:"end",children:n.paymentCurrency.symbol})}}})}),e.jsx(N,{children:t("admin.paymentIntent.refundForm.amountHelper",{min:0,max:a,symbol:n.paymentCurrency.symbol})})]}),e.jsx(b,{name:"refund.description",control:s,rules:{required:t("common.required"),validate:r=>r.trim()!==""||t("common.required")},render:({field:r})=>e.jsx(C,{...r,variant:"outlined",size:"small",fullWidth:!0,multiline:!0,minRows:2,maxRows:4,placeholder:t("admin.paymentIntent.refundForm.description"),error:!!m?.refund?.description,helperText:m?.refund?.description?.message,slotProps:{htmlInput:{maxLength:200}}})})]})}function M({data:n,variant:a="compact",onChange:t}){const{t:o}=v(),s=D(),{reset:u,getValues:m,setValue:x,handleSubmit:r}=I(),[l,f]=T({action:"",loading:!1}),[j,k]=R.useState("0"),A=n.payment_details?.arcblock?.type==="slash"&&n.paymentMethod?.type==="arcblock",{runAsync:h}=V(()=>A?Promise.resolve({amount:"0"}):U(n.id),{onSuccess:d=>{const i=_(d?.amount,n.paymentCurrency.decimal);k(i)},manual:!0}),q=async()=>{const{refund:d}=m();if(!d.amount||!d.reason||!d.description){y.warning(o("admin.paymentIntent.refundForm.required"));return}try{f({loading:!0}),await F.put(`/api/payment-intents/${n.id}/refund`,d).then(i=>i.data),y.success(o("admin.paymentIntent.refundSuccess")),t("refund"),h()}catch(i){console.error(i),y.error(L(i))}finally{f({loading:!1,action:""})}},g=[{label:o("admin.paymentIntent.refund"),handler:()=>{h().then(d=>{u();const i=_(d?.amount,n.paymentCurrency.decimal);if(Number(i)<=0){y.info(o("admin.paymentIntent.refundForm.empty"));return}x("refund.amount",i),f({action:"refund"})})},color:"primary",disabled:Number(j)<=0,divider:!0},{label:o("admin.customer.view"),handler:()=>s(`/admin/customers/${n.customer_id}`),color:"primary",disabled:!1}];return a==="compact"&&g.push({label:o("admin.paymentIntent.view"),handler:()=>s(`/admin/payments/${n.id}`),color:"primary",disabled:!1}),e.jsxs(z,{children:[e.jsx(W,{variant:a,actions:g,onOpenCallback:h}),l.action==="refund"&&e.jsx(H,{onConfirm:r(q),onCancel:()=>f({action:""}),title:o("admin.paymentIntent.refund"),message:e.jsx(X,{data:n,refundMaxAmount:j}),loading:l.loading})]})}function ne(n){const a=Object.assign({variant:"compact"},n),t=B({mode:"onChange",defaultValues:{refund:{reason:"requested_by_admin",description:""}}});return e.jsx(G,{...t,children:e.jsx(M,{...a})})}export{ne as P};
1
+ import{j as e,r as R,a3 as S,a_ as P,aX as c,a$ as p,aQ as $,a2 as C,aZ as w,aR as N}from"./vendor-mui-BXZut9Pz.js";import{V as v,Y as T,P as V,Z as y,H as E}from"./vendor-blocklet-B67R14so.js";import{h as H,F as B,E as I,I as L,e as F,C as b,k as W,G as z}from"./index-B4yaPb7B.js";import{A as D}from"./actions-BEUwbsq1.js";import{C as G}from"./click-boundary-Bi28Y0Fq.js";import{a as O}from"./vendor-react-BPknnnEA.js";function _(n,a,t=6){if(!n)return"0";const o=E(n,a),[s="0",u=""]=o.split(".");if(t<=0)return s;const m=u.substring(0,t).replace(/0+$/,"");return m?`${s}.${m}`:s}const U=n=>F.get(`/api/payment-intents/${n}/refundable-amount`).then(a=>a.data);function Z({data:n,refundMaxAmount:a}){const{t,locale:o}=v(),{control:s,setValue:u,formState:{errors:m}}=I(),x=r=>{if(Number(r)<=0||Number(r)>Number(a))return t("admin.paymentIntent.refundForm.amountRange",{min:0,max:a,symbol:n.paymentCurrency.symbol});const l=z(r.toString(),o,n.paymentCurrency.maximum_precision||6);return l||!0};return e.jsxs(S,{direction:"column",spacing:1,sx:{alignItems:"flex-start",width:400},children:[e.jsx(b,{name:"refund.reason",control:s,render:({field:r})=>e.jsxs(P,{...r,sx:{ml:"5px !important"},children:[e.jsx(c,{value:"duplicate",control:e.jsx(p,{checked:r.value==="duplicate"}),label:t("admin.paymentIntent.refundForm.duplicate"),onClick:()=>u("refund.reason","duplicate")}),e.jsx(c,{value:"requested_by_customer",control:e.jsx(p,{checked:r.value==="requested_by_customer"}),label:t("admin.paymentIntent.refundForm.requestedByCustomer"),onClick:()=>u("refund.reason","requested_by_customer")}),e.jsx(c,{value:"requested_by_admin",control:e.jsx(p,{checked:r.value==="requested_by_admin"}),label:t("admin.paymentIntent.refundForm.requestedByAdmin"),onClick:()=>u("refund.reason","requested_by_admin")}),e.jsx(c,{value:"fraudulent",control:e.jsx(p,{checked:r.value==="fraudulent"}),label:t("admin.paymentIntent.refundForm.fraudulent"),onClick:()=>u("refund.reason","fraudulent")}),e.jsx(c,{value:"expired_uncaptured_charge",control:e.jsx(p,{checked:r.value==="expired_uncaptured_charge"}),label:t("admin.paymentIntent.refundForm.expiredUncapturedCharge"),onClick:()=>u("refund.reason","expired_uncaptured_charge")})]})}),e.jsxs($,{fullWidth:!0,component:"fieldset",variant:"outlined",children:[e.jsx(b,{name:"refund.amount",control:s,rules:{validate:x},render:({field:r})=>e.jsx(C,{...r,variant:"outlined",size:"small",type:"number",fullWidth:!0,placeholder:t("admin.paymentIntent.refundForm.amount"),error:!!m?.refund?.amount,helperText:m?.refund?.amount?.message,slotProps:{input:{endAdornment:e.jsx(w,{position:"end",children:n.paymentCurrency.symbol})}}})}),e.jsx(N,{children:t("admin.paymentIntent.refundForm.amountHelper",{min:0,max:a,symbol:n.paymentCurrency.symbol})})]}),e.jsx(b,{name:"refund.description",control:s,rules:{required:t("common.required"),validate:r=>r.trim()!==""||t("common.required")},render:({field:r})=>e.jsx(C,{...r,variant:"outlined",size:"small",fullWidth:!0,multiline:!0,minRows:2,maxRows:4,placeholder:t("admin.paymentIntent.refundForm.description"),error:!!m?.refund?.description,helperText:m?.refund?.description?.message,slotProps:{htmlInput:{maxLength:200}}})})]})}function M({data:n,variant:a="compact",onChange:t}){const{t:o}=v(),s=O(),{reset:u,getValues:m,setValue:x,handleSubmit:r}=I(),[l,f]=T({action:"",loading:!1}),[j,k]=R.useState("0"),A=n.payment_details?.arcblock?.type==="slash"&&n.paymentMethod?.type==="arcblock",{runAsync:h}=V(()=>A?Promise.resolve({amount:"0"}):U(n.id),{onSuccess:d=>{const i=_(d?.amount,n.paymentCurrency.decimal);k(i)},manual:!0}),q=async()=>{const{refund:d}=m();if(!d.amount||!d.reason||!d.description){y.warning(o("admin.paymentIntent.refundForm.required"));return}try{f({loading:!0}),await F.put(`/api/payment-intents/${n.id}/refund`,d).then(i=>i.data),y.success(o("admin.paymentIntent.refundSuccess")),t("refund"),h()}catch(i){console.error(i),y.error(W(i))}finally{f({loading:!1,action:""})}},g=[{label:o("admin.paymentIntent.refund"),handler:()=>{h().then(d=>{u();const i=_(d?.amount,n.paymentCurrency.decimal);if(Number(i)<=0){y.info(o("admin.paymentIntent.refundForm.empty"));return}x("refund.amount",i),f({action:"refund"})})},color:"primary",disabled:Number(j)<=0,divider:!0},{label:o("admin.customer.view"),handler:()=>s(`/admin/customers/${n.customer_id}`),color:"primary",disabled:!1}];return a==="compact"&&g.push({label:o("admin.paymentIntent.view"),handler:()=>s(`/admin/payments/${n.id}`),color:"primary",disabled:!1}),e.jsxs(G,{children:[e.jsx(D,{variant:a,actions:g,onOpenCallback:h}),l.action==="refund"&&e.jsx(L,{onConfirm:r(q),onCancel:()=>f({action:""}),title:o("admin.paymentIntent.refund"),message:e.jsx(Z,{data:n,refundMaxAmount:j}),loading:l.loading})]})}function ne(n){const a=Object.assign({variant:"compact"},n),t=H({mode:"onChange",defaultValues:{refund:{reason:"requested_by_admin",description:""}}});return e.jsx(B,{...t,children:e.jsx(M,{...a})})}export{ne as P};
@@ -1 +1 @@
1
- import{j as t,a3 as P,x as b,w as x}from"./vendor-mui-BXZut9Pz.js";import{V as L,$ as C,X as j,Y as r,_ as S,E as f}from"./vendor-blocklet-D_i_QeSo.js";import{h as M,F as T,aX as $,I as y,e as m,k as c}from"./index-DgSc1Qy8.js";import{A}from"./actions-jxGAdGfb.js";import{C as E}from"./click-boundary-y8dVA_tr.js";import{A as F}from"./assign-CkV5Q2LP.js";function R({data:a,loading:d,onSave:l,onCancel:n}){const{t:o}=L(),e=M({defaultValues:{name:a.name}}),{handleSubmit:k,reset:u}=e,h=()=>{k(async g=>{await l(g),u(),n(null)})()};return t.jsx(C,{open:!0,disableEscapeKeyDown:!0,fullWidth:!0,maxWidth:"sm",className:"base-dialog",onClose:()=>n(null),showCloseButton:!1,title:o("admin.paymentLink.rename"),actions:t.jsxs(P,{direction:"row",children:[t.jsx(b,{size:"small",sx:{mr:2},onClick:n,children:o("common.cancel")}),t.jsxs(b,{variant:"contained",color:"primary",size:"small",disabled:d,onClick:h,children:[d&&t.jsx(x,{size:"small"})," ",o("common.save")]})]}),children:t.jsx(T,{...e,children:t.jsx($,{name:"name",rules:{required:!0},label:o("admin.paymentLink.name.label"),placeholder:o("admin.paymentLink.name.placeholder"),autoFocus:!0})})})}function W({data:a,variant:d="compact",onChange:l}){const{t:n}=L(),[o,e]=j({action:"",loading:!1}),k=async i=>{try{e({loading:!0}),await m.put(`/api/payment-links/${a.id}`,i).then(s=>s.data),r.success(n("common.saved")),l(o.action)}catch(s){console.error(s),r.error(c(s))}finally{e({loading:!1,action:""})}},u=async()=>{try{e({loading:!0}),await m.put(`/api/payment-links/${a.id}/archive`).then(i=>i.data),r.success(n("common.saved")),l(o.action)}catch(i){console.error(i),r.error(c(i))}finally{e({loading:!1,action:""})}},h=async()=>{try{e({loading:!0}),await m.delete(`/api/payment-links/${a.id}`).then(i=>i.data),r.success(n("common.removed")),l(o.action)}catch(i){console.error(i),r.error(c(i))}finally{e({loading:!1,action:""})}},g=async()=>{try{e({loading:!0}),await m.put(`/api/payment-links/${a.id}`,{allow_promotion_codes:!a.allow_promotion_codes}).then(i=>i.data),r.success(n("common.saved")),l(o.action)}catch(i){console.error(i),r.error(c(i))}finally{e({loading:!1,action:""})}},w=async()=>{const i=a.metadata||{},s=i.allow_skip_payment_method==="true";try{e({loading:!0}),await m.put(`/api/payment-links/${a.id}`,{metadata:{...i,allow_skip_payment_method:s?"false":"true"}}).then(p=>p.data),r.success(n("common.saved")),l(o.action)}catch(p){console.error(p),r.error(c(p))}finally{e({loading:!1,action:""})}},_=()=>{S(f(window.blocklet.appUrl,window.blocklet.prefix,`/checkout/pay/${a.id}`)),r.success(n("common.copied"))},v=()=>{window.open(f(window.blocklet.appUrl,window.blocklet.prefix,`/checkout/pay/${a.id}`))};return t.jsxs(E,{children:[t.jsx(A,{variant:d,actions:[{label:n("admin.paymentLink.openLink"),handler:v,color:"primary"},{label:n("admin.paymentLink.copyLink"),handler:_,color:"primary"},{label:n("admin.paymentLink.rename"),handler:()=>e({action:"rename"}),color:"primary"},{label:n("admin.paymentLink.archive"),handler:()=>e({action:"archive"}),color:"primary"},{label:n("admin.paymentLink.remove"),handler:()=>e({action:"remove"}),color:"error",divider:!0},{label:a.allow_promotion_codes?n("admin.paymentLink.disablePromotionCodes"):n("admin.paymentLink.enablePromotionCodes"),handler:()=>e({action:"togglePromotionCodes"}),color:"primary"},{label:a.metadata?.allow_skip_payment_method==="true"?n("admin.paymentLink.disableSkipPaymentMethod"):n("admin.paymentLink.enableSkipPaymentMethod"),handler:()=>e({action:"toggleSkipPaymentMethod"}),color:"primary"},{label:n("admin.passport.assign"),handler:()=>e({action:"assign"}),color:"primary",disabled:!a.active}]}),o.action==="rename"&&t.jsx(R,{data:a,loading:o.loading,onSave:k,onCancel:()=>e({action:""})}),o.action==="assign"&&t.jsx(F,{id:a.id,onCancel:()=>e({action:""})}),o.action==="archive"&&t.jsx(y,{onConfirm:u,onCancel:()=>e({action:""}),title:n("admin.paymentLink.archive"),message:n("admin.paymentLink.archiveTip"),loading:o.loading}),o.action==="remove"&&t.jsx(y,{onConfirm:h,onCancel:()=>e({action:""}),title:n("admin.paymentLink.remove"),message:n("admin.paymentLink.removeTip"),loading:o.loading}),o.action==="toggleSkipPaymentMethod"&&t.jsx(y,{onConfirm:w,onCancel:()=>e({action:""}),title:a.metadata?.allow_skip_payment_method==="true"?n("admin.paymentLink.disableSkipPaymentMethod"):n("admin.paymentLink.enableSkipPaymentMethod"),message:a.metadata?.allow_skip_payment_method==="true"?n("admin.paymentLink.disableSkipPaymentMethodTip"):n("admin.paymentLink.enableSkipPaymentMethodTip"),loading:o.loading}),o.action==="togglePromotionCodes"&&t.jsx(y,{onConfirm:g,onCancel:()=>e({action:""}),title:a.allow_promotion_codes?n("admin.paymentLink.disablePromotionCodes"):n("admin.paymentLink.enablePromotionCodes"),message:a.allow_promotion_codes?n("admin.paymentLink.disablePromotionCodesTip"):n("admin.paymentLink.enablePromotionCodesTip"),loading:o.loading})]})}export{W as P};
1
+ import{j as t,a3 as P,x as b,w as x}from"./vendor-mui-BXZut9Pz.js";import{V as L,$ as C,Y as j,Z as r,_ as S,F as f}from"./vendor-blocklet-B67R14so.js";import{h as M,F as T,aX as $,I as y,e as m,k as c}from"./index-B4yaPb7B.js";import{A}from"./actions-BEUwbsq1.js";import{C as F}from"./click-boundary-Bi28Y0Fq.js";import{A as E}from"./assign-DKRfmN7W.js";function R({data:a,loading:d,onSave:l,onCancel:n}){const{t:o}=L(),e=M({defaultValues:{name:a.name}}),{handleSubmit:k,reset:u}=e,h=()=>{k(async g=>{await l(g),u(),n(null)})()};return t.jsx(C,{open:!0,disableEscapeKeyDown:!0,fullWidth:!0,maxWidth:"sm",className:"base-dialog",onClose:()=>n(null),showCloseButton:!1,title:o("admin.paymentLink.rename"),actions:t.jsxs(P,{direction:"row",children:[t.jsx(b,{size:"small",sx:{mr:2},onClick:n,children:o("common.cancel")}),t.jsxs(b,{variant:"contained",color:"primary",size:"small",disabled:d,onClick:h,children:[d&&t.jsx(x,{size:"small"})," ",o("common.save")]})]}),children:t.jsx(T,{...e,children:t.jsx($,{name:"name",rules:{required:!0},label:o("admin.paymentLink.name.label"),placeholder:o("admin.paymentLink.name.placeholder"),autoFocus:!0})})})}function W({data:a,variant:d="compact",onChange:l}){const{t:n}=L(),[o,e]=j({action:"",loading:!1}),k=async i=>{try{e({loading:!0}),await m.put(`/api/payment-links/${a.id}`,i).then(s=>s.data),r.success(n("common.saved")),l(o.action)}catch(s){console.error(s),r.error(c(s))}finally{e({loading:!1,action:""})}},u=async()=>{try{e({loading:!0}),await m.put(`/api/payment-links/${a.id}/archive`).then(i=>i.data),r.success(n("common.saved")),l(o.action)}catch(i){console.error(i),r.error(c(i))}finally{e({loading:!1,action:""})}},h=async()=>{try{e({loading:!0}),await m.delete(`/api/payment-links/${a.id}`).then(i=>i.data),r.success(n("common.removed")),l(o.action)}catch(i){console.error(i),r.error(c(i))}finally{e({loading:!1,action:""})}},g=async()=>{try{e({loading:!0}),await m.put(`/api/payment-links/${a.id}`,{allow_promotion_codes:!a.allow_promotion_codes}).then(i=>i.data),r.success(n("common.saved")),l(o.action)}catch(i){console.error(i),r.error(c(i))}finally{e({loading:!1,action:""})}},w=async()=>{const i=a.metadata||{},s=i.allow_skip_payment_method==="true";try{e({loading:!0}),await m.put(`/api/payment-links/${a.id}`,{metadata:{...i,allow_skip_payment_method:s?"false":"true"}}).then(p=>p.data),r.success(n("common.saved")),l(o.action)}catch(p){console.error(p),r.error(c(p))}finally{e({loading:!1,action:""})}},_=()=>{S(f(window.blocklet.appUrl,window.blocklet.prefix,`/checkout/pay/${a.id}`)),r.success(n("common.copied"))},v=()=>{window.open(f(window.blocklet.appUrl,window.blocklet.prefix,`/checkout/pay/${a.id}`))};return t.jsxs(F,{children:[t.jsx(A,{variant:d,actions:[{label:n("admin.paymentLink.openLink"),handler:v,color:"primary"},{label:n("admin.paymentLink.copyLink"),handler:_,color:"primary"},{label:n("admin.paymentLink.rename"),handler:()=>e({action:"rename"}),color:"primary"},{label:n("admin.paymentLink.archive"),handler:()=>e({action:"archive"}),color:"primary"},{label:n("admin.paymentLink.remove"),handler:()=>e({action:"remove"}),color:"error",divider:!0},{label:a.allow_promotion_codes?n("admin.paymentLink.disablePromotionCodes"):n("admin.paymentLink.enablePromotionCodes"),handler:()=>e({action:"togglePromotionCodes"}),color:"primary"},{label:a.metadata?.allow_skip_payment_method==="true"?n("admin.paymentLink.disableSkipPaymentMethod"):n("admin.paymentLink.enableSkipPaymentMethod"),handler:()=>e({action:"toggleSkipPaymentMethod"}),color:"primary"},{label:n("admin.passport.assign"),handler:()=>e({action:"assign"}),color:"primary",disabled:!a.active}]}),o.action==="rename"&&t.jsx(R,{data:a,loading:o.loading,onSave:k,onCancel:()=>e({action:""})}),o.action==="assign"&&t.jsx(E,{id:a.id,onCancel:()=>e({action:""})}),o.action==="archive"&&t.jsx(y,{onConfirm:u,onCancel:()=>e({action:""}),title:n("admin.paymentLink.archive"),message:n("admin.paymentLink.archiveTip"),loading:o.loading}),o.action==="remove"&&t.jsx(y,{onConfirm:h,onCancel:()=>e({action:""}),title:n("admin.paymentLink.remove"),message:n("admin.paymentLink.removeTip"),loading:o.loading}),o.action==="toggleSkipPaymentMethod"&&t.jsx(y,{onConfirm:w,onCancel:()=>e({action:""}),title:a.metadata?.allow_skip_payment_method==="true"?n("admin.paymentLink.disableSkipPaymentMethod"):n("admin.paymentLink.enableSkipPaymentMethod"),message:a.metadata?.allow_skip_payment_method==="true"?n("admin.paymentLink.disableSkipPaymentMethodTip"):n("admin.paymentLink.enableSkipPaymentMethodTip"),loading:o.loading}),o.action==="togglePromotionCodes"&&t.jsx(y,{onConfirm:g,onCancel:()=>e({action:""}),title:a.allow_promotion_codes?n("admin.paymentLink.disablePromotionCodes"):n("admin.paymentLink.enablePromotionCodes"),message:a.allow_promotion_codes?n("admin.paymentLink.disablePromotionCodesTip"):n("admin.paymentLink.enablePromotionCodesTip"),loading:o.loading})]})}export{W as P};
@@ -1 +1 @@
1
- import{j as s,a3 as h,x as a,w as f}from"./vendor-mui-BXZut9Pz.js";import{V as j,$ as p}from"./vendor-blocklet-D_i_QeSo.js";import{a as P,h as b,F as y}from"./index-DgSc1Qy8.js";import{D as C,a as w}from"./form-P4luyUpY.js";import{P as F}from"./product-select-0ScZE2e8.js";function z({loading:o,onSave:i,onCancel:e,productType:n=""}){const{t:r}=j(),{settings:c}=P(),t=b({mode:"onChange",defaultValues:{...C,currency_id:c.baseCurrency.id}}),{handleSubmit:m,reset:l,formState:{errors:d}}=t,u=()=>{Object.keys(d).length>0||m(async x=>{await i(x),l(),e(null)})()};return s.jsx(p,{open:!0,disableEscapeKeyDown:!0,fullWidth:!0,maxWidth:"sm",className:"base-dialog",onClose:()=>e(null),showCloseButton:!1,title:r("admin.price.add"),actions:s.jsxs(h,{direction:"row",children:[s.jsx(a,{size:"small",sx:{mr:2},onClick:e,children:r("common.cancel")}),s.jsxs(a,{variant:"contained",color:"primary",size:"small",disabled:o,onClick:u,children:[o&&s.jsx(f,{size:"small"})," ",r("common.save")]})]}),children:s.jsx(y,{...t,children:s.jsx(F,{children:s.jsx(w,{productType:n})})})})}export{z as A};
1
+ import{j as s,a3 as h,x as a,w as f}from"./vendor-mui-BXZut9Pz.js";import{V as j,$ as p}from"./vendor-blocklet-B67R14so.js";import{a as P,h as b,F as y}from"./index-B4yaPb7B.js";import{D as C,a as w}from"./form-AFzUvoFE.js";import{P as F}from"./product-select-_72p-5lF.js";function z({loading:o,onSave:i,onCancel:e,productType:n=""}){const{t:r}=j(),{settings:c}=P(),t=b({mode:"onChange",defaultValues:{...C,currency_id:c.baseCurrency.id}}),{handleSubmit:m,reset:l,formState:{errors:d}}=t,u=()=>{Object.keys(d).length>0||m(async x=>{await i(x),l(),e(null)})()};return s.jsx(p,{open:!0,disableEscapeKeyDown:!0,fullWidth:!0,maxWidth:"sm",className:"base-dialog",onClose:()=>e(null),showCloseButton:!1,title:r("admin.price.add"),actions:s.jsxs(h,{direction:"row",children:[s.jsx(a,{size:"small",sx:{mr:2},onClick:e,children:r("common.cancel")}),s.jsxs(a,{variant:"contained",color:"primary",size:"small",disabled:o,onClick:u,children:[o&&s.jsx(f,{size:"small"})," ",r("common.save")]})]}),children:s.jsx(y,{...t,children:s.jsx(F,{children:s.jsx(w,{productType:n})})})})}export{z as A};
@@ -1,4 +1,4 @@
1
- import{r as i,j as e,B as d,w as s,bf as p}from"./vendor-mui-BXZut9Pz.js";import{aq as c}from"./vendor-blocklet-D_i_QeSo.js";import{u,P as g}from"./index-DgSc1Qy8.js";function n(){return e.jsx(d,{sx:{minHeight:"100vh",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(s,{})})}function l(){const o=window.blocklet;return!!(o&&o.appPid&&o.prefix)}const x=p(c)`
1
+ import{r as i,j as e,B as d,w as s,bf as p}from"./vendor-mui-BXZut9Pz.js";import{ar as c}from"./vendor-blocklet-B67R14so.js";import{u,P as g}from"./index-B4yaPb7B.js";function n(){return e.jsx(d,{sx:{minHeight:"100vh",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(s,{})})}function l(){const o=window.blocklet;return!!(o&&o.appPid&&o.prefix)}const x=p(c)`
2
2
  width: 100%;
3
3
  background-color: ${({theme:o})=>o.palette.background.default};
4
4
 
@@ -1 +1 @@
1
- import{r as m,j as s,A as f,w as h,B as j,q as p,aT as C,ad as y}from"./vendor-mui-BXZut9Pz.js";import{V as v,O as A,Y as d}from"./vendor-blocklet-D_i_QeSo.js";import{I as i,e as g}from"./index-DgSc1Qy8.js";const E=()=>g.get("/api/passports").then(a=>a.data);function T(a){const{t:e}=v(),{loading:u,error:c,data:r}=A(E),[n,l]=m.useState("");m.useEffect(()=>{r&&r.length&&!n&&l(r[0].name)},[r]);const o=async()=>{if(!n){d.error(e("admin.passport.assignError"));return}await g.put("/api/passports/assign",{name:n,id:a.id}),d.success(e("common.saved")),a.onCancel()};if(c)return s.jsx(i,{title:e("admin.passport.assign"),message:s.jsx(f,{severity:"error",children:c.message}),onConfirm:o,onCancel:a.onCancel,color:"primary"});if(u||!r)return s.jsx(i,{title:e("admin.passport.assign"),message:s.jsx(h,{}),onConfirm:o,onCancel:a.onCancel,color:"primary"});const x=t=>{l(t.target.value)};return s.jsx(i,{title:e("admin.passport.assign"),message:s.jsxs(j,{children:[s.jsx(p,{children:e("admin.passport.assignTip")}),s.jsx(C,{value:n,onChange:x,size:"small",children:r.map(t=>s.jsx(y,{value:t.name,children:s.jsx(p,{color:n?"text.primary":"text.secondary",children:t.title})},t.name))})]}),onConfirm:o,onCancel:a.onCancel,color:"primary"})}export{T as A};
1
+ import{r as m,j as s,A as f,w as h,B as j,q as p,aT as C,ad as y}from"./vendor-mui-BXZut9Pz.js";import{V as v,P as A,Z as d}from"./vendor-blocklet-B67R14so.js";import{I as i,e as g}from"./index-B4yaPb7B.js";const E=()=>g.get("/api/passports").then(a=>a.data);function S(a){const{t:e}=v(),{loading:u,error:c,data:r}=A(E),[n,l]=m.useState("");m.useEffect(()=>{r&&r.length&&!n&&l(r[0].name)},[r]);const o=async()=>{if(!n){d.error(e("admin.passport.assignError"));return}await g.put("/api/passports/assign",{name:n,id:a.id}),d.success(e("common.saved")),a.onCancel()};if(c)return s.jsx(i,{title:e("admin.passport.assign"),message:s.jsx(f,{severity:"error",children:c.message}),onConfirm:o,onCancel:a.onCancel,color:"primary"});if(u||!r)return s.jsx(i,{title:e("admin.passport.assign"),message:s.jsx(h,{}),onConfirm:o,onCancel:a.onCancel,color:"primary"});const x=t=>{l(t.target.value)};return s.jsx(i,{title:e("admin.passport.assign"),message:s.jsxs(j,{children:[s.jsx(p,{children:e("admin.passport.assignTip")}),s.jsx(C,{value:n,onChange:x,size:"small",children:r.map(t=>s.jsx(y,{value:t.name,children:s.jsx(p,{color:n?"text.primary":"text.secondary",children:t.title})},t.name))})]}),onConfirm:o,onCancel:a.onCancel,color:"primary"})}export{S as A};
@@ -1 +1 @@
1
- import{r as u,j as e,be as D,ab as M,a0 as P,q as l,w as B,$ as f,a8 as N,e as F,bN as H,a9 as T,af as _,aG as G,cE as J,cF as $,aH as Y,x as S,a3 as h,cG as U,B as v}from"./vendor-mui-BXZut9Pz.js";import{l as b}from"./vendor-arcblock-ChFCRdyx.js";import{V,ag as X,X as K,O as Q,Y as C}from"./vendor-blocklet-D_i_QeSo.js";import{e as O,j as Z,I as ee}from"./index-DgSc1Qy8.js";import{l as te}from"./lodash-B4Ozcv0x.js";import{v as se}from"./util-mDHAL0lx.js";import{I as ne}from"./info-card-C1yxhxJG.js";function k({requestInfo:r=void 0,request:o=void 0}){const[s,t]=u.useState(null),c=i=>{t(s?null:i.currentTarget)};return u.useEffect(()=>{const i=m=>{s&&!s.contains(m.target)&&!m.target.closest(".popper-content")&&t(null)},p=m=>{s&&!m.target?.closest(".popper-content")&&t(null)};return document.addEventListener("click",i),window.addEventListener("scroll",p,!0),()=>{document.removeEventListener("click",i),window.removeEventListener("scroll",p,!0)}},[s]),e.jsxs(e.Fragment,{children:[e.jsx(D,{fontSize:"small",onClick:i=>c(i),sx:{color:"text.secondary",opacity:.6,cursor:"pointer"}}),e.jsx(M,{open:!!s,anchorEl:s,placement:"right",sx:{zIndex:1e3,"@media (max-width: 600px)":{"& .MuiPaper-root":{width:"calc(100vw - 32px)",maxWidth:"none"}}},modifiers:[{name:"preventOverflow",options:{boundary:window,altAxis:!0,padding:16}},{name:"flip",options:{fallbackPlacements:["bottom"]}},{name:"matchWidth",enabled:!0,fn:({state:i})=>(window.innerWidth<=600&&(i.styles.popper={...i.styles.popper,width:"calc(100vw - 32px)",maxWidth:"none"}),i)}],children:e.jsx(P,{className:"popper-content",elevation:3,sx:{p:2,border:"1px solid",borderColor:"divider",maxWidth:360,"@media (max-width: 600px)":{maxWidth:"none",margin:"0 auto"}},children:r?e.jsxs(e.Fragment,{children:[e.jsx(l,{variant:"caption",sx:{color:"text.secondary",mb:1,display:"block"},children:"Requested by:"}),e.jsx(ne,{logo:r.avatar,name:r.email,description:r.did||o?.requested_by,size:40})]}):e.jsxs(l,{children:["Requested by: ",o?.requested_by||"system"]})})})]})}const re=(r={})=>{const o=new URLSearchParams;return Object.keys(r).forEach(s=>{o.set(s,String(r[s]))}),O.get(`/api/webhook-attempts?${o.toString()}`).then(s=>s.data)},oe=r=>{const o={};return r.forEach(s=>{const t=new Date(s.created_at).toLocaleDateString();o[t]||(o[t]=[]),o[t]?.push(s)}),o};function xe({event_id:r="",webhook_endpoint_id:o="",event:s=void 0}){const{t}=V(),{data:c,loadMore:i,loadingMore:p,loading:m,reload:L}=X(n=>{const d=n?Math.ceil(n.list.length/15)+1:1;return re({page:d,size:15,event_id:r,webhook_endpoint_id:o})},{reloadDeps:[r,o]}),q=c?.list||[],[a,w]=u.useState(null),[g,j]=K({retryEventId:""}),E=oe(q),{loading:y,run:A}=Q(n=>O.post(`/api/events/${n}/retry-webhooks`).then(x=>x.data),{manual:!0,onSuccess:n=>{C.success(n.message||t("admin.event.retryOptions.success")),L()},onError:n=>{C.error(n.response?.data?.error||t("admin.event.retryOptions.error"))}});u.useEffect(()=>{!a&&c?.list.length&&w(c.list[0])},[c?.list.length,a]);const R=n=>{w(n)},z=n=>{j({retryEventId:n})},W=()=>{g.retryEventId&&(A(g.retryEventId),j({retryEventId:""}))};if(m)return e.jsx(B,{});const I=c&&c.list.length<c.count;return e.jsxs(f,{container:!0,spacing:2.5,children:[e.jsx(f,{size:{xs:12,md:4},className:"attempt-list",children:te.isEmpty(Object.keys(E))?e.jsx(l,{sx:{color:"text.secondary"},children:t("admin.event.noAttempts")}):e.jsxs(e.Fragment,{children:[e.jsx(N,{sx:{maxHeight:"64vh",overflowY:"scroll"},children:Object.entries(E).map(([n,x])=>e.jsxs(F.Fragment,{children:[e.jsx(H,{children:n}),x.map(d=>e.jsxs(T,{component:_,onClick:()=>R(d),selected:a===d,secondaryAction:e.jsx(l,{sx:{color:"text.secondary"},children:Z(d.created_at,"HH:mm:ss A")}),children:[e.jsx(G,{children:se(d.response_status)===!1?e.jsx(J,{color:"error"}):e.jsx($,{color:"success"})}),e.jsx(Y,{primary:e.jsx(l,{sx:{color:"text.primary"},children:d.event.type})})]},d.id))]},n))}),I&&e.jsx(S,{variant:"text",type:"button",color:"inherit",onClick:i,disabled:p,children:t(p?"common.loading":"common.loadMore")}),!I&&e.jsx(l,{sx:{color:"text.secondary"},children:t("common.noMoreData")})]})}),e.jsxs(f,{size:{xs:12,md:8},children:[a&&e.jsxs(h,{direction:"column",spacing:2,sx:{pt:3,pl:3,borderLeft:"1px solid",borderColor:"divider"},children:[e.jsxs(h,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsx(l,{variant:"h6",children:r?a.endpoint.url:a.event.type}),e.jsx(S,{variant:"outlined",size:"small",startIcon:e.jsx(U,{}),onClick:()=>z(a.event_id),disabled:y,children:t(y?"admin.event.retrying":"admin.event.retry")})]}),g.retryEventId&&e.jsx(ee,{onConfirm:W,onCancel:()=>j({retryEventId:""}),title:t("admin.event.retryOptions.title"),message:t("admin.event.retryOptions.confirmMessage"),loading:y,color:"primary"}),e.jsxs(v,{children:[e.jsxs(l,{variant:"h6",children:[t("admin.event.response")," (",a.response_status,")"]}),e.jsx(b,{language:"json",children:JSON.stringify(a.response_body,null,2)})]}),e.jsxs(v,{children:[e.jsxs(h,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(l,{variant:"h6",children:t("admin.event.request")}),e.jsx(k,{requestInfo:a?.event?.requestInfo,request:a?.event.request})]}),e.jsx(b,{language:"json",children:JSON.stringify(a.event,null,2)})]})]}),c?.list.length===0&&s&&e.jsxs(v,{children:[e.jsxs(h,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(l,{variant:"h6",children:t("admin.event.eventData")}),e.jsx(k,{requestInfo:s.requestInfo,request:s.request})]}),e.jsx(b,{language:"json",children:JSON.stringify(s.data,null,2)})]})]})]})}export{xe as W};
1
+ import{r as u,j as e,be as D,ab as M,a0 as P,q as l,w as B,$ as f,a8 as N,e as F,bN as H,a9 as T,af as _,aG as G,cE as J,cF as $,aH as Y,x as S,a3 as h,cG as U,B as v}from"./vendor-mui-BXZut9Pz.js";import{l as b}from"./vendor-arcblock-D1drrE7q.js";import{V,ah as Z,Y as K,P as Q,Z as C}from"./vendor-blocklet-B67R14so.js";import{e as O,j as X,I as ee}from"./index-B4yaPb7B.js";import{l as te}from"./lodash-B4Ozcv0x.js";import{v as se}from"./util-B8B3fsMa.js";import{I as ne}from"./info-card-C9dRgztS.js";function k({requestInfo:r=void 0,request:o=void 0}){const[s,t]=u.useState(null),c=i=>{t(s?null:i.currentTarget)};return u.useEffect(()=>{const i=m=>{s&&!s.contains(m.target)&&!m.target.closest(".popper-content")&&t(null)},p=m=>{s&&!m.target?.closest(".popper-content")&&t(null)};return document.addEventListener("click",i),window.addEventListener("scroll",p,!0),()=>{document.removeEventListener("click",i),window.removeEventListener("scroll",p,!0)}},[s]),e.jsxs(e.Fragment,{children:[e.jsx(D,{fontSize:"small",onClick:i=>c(i),sx:{color:"text.secondary",opacity:.6,cursor:"pointer"}}),e.jsx(M,{open:!!s,anchorEl:s,placement:"right",sx:{zIndex:1e3,"@media (max-width: 600px)":{"& .MuiPaper-root":{width:"calc(100vw - 32px)",maxWidth:"none"}}},modifiers:[{name:"preventOverflow",options:{boundary:window,altAxis:!0,padding:16}},{name:"flip",options:{fallbackPlacements:["bottom"]}},{name:"matchWidth",enabled:!0,fn:({state:i})=>(window.innerWidth<=600&&(i.styles.popper={...i.styles.popper,width:"calc(100vw - 32px)",maxWidth:"none"}),i)}],children:e.jsx(P,{className:"popper-content",elevation:3,sx:{p:2,border:"1px solid",borderColor:"divider",maxWidth:360,"@media (max-width: 600px)":{maxWidth:"none",margin:"0 auto"}},children:r?e.jsxs(e.Fragment,{children:[e.jsx(l,{variant:"caption",sx:{color:"text.secondary",mb:1,display:"block"},children:"Requested by:"}),e.jsx(ne,{logo:r.avatar,name:r.email,description:r.did||o?.requested_by,size:40})]}):e.jsxs(l,{children:["Requested by: ",o?.requested_by||"system"]})})})]})}const re=(r={})=>{const o=new URLSearchParams;return Object.keys(r).forEach(s=>{o.set(s,String(r[s]))}),O.get(`/api/webhook-attempts?${o.toString()}`).then(s=>s.data)},oe=r=>{const o={};return r.forEach(s=>{const t=new Date(s.created_at).toLocaleDateString();o[t]||(o[t]=[]),o[t]?.push(s)}),o};function xe({event_id:r="",webhook_endpoint_id:o="",event:s=void 0}){const{t}=V(),{data:c,loadMore:i,loadingMore:p,loading:m,reload:L}=Z(n=>{const d=n?Math.ceil(n.list.length/15)+1:1;return re({page:d,size:15,event_id:r,webhook_endpoint_id:o})},{reloadDeps:[r,o]}),q=c?.list||[],[a,w]=u.useState(null),[g,j]=K({retryEventId:""}),E=oe(q),{loading:y,run:A}=Q(n=>O.post(`/api/events/${n}/retry-webhooks`).then(x=>x.data),{manual:!0,onSuccess:n=>{C.success(n.message||t("admin.event.retryOptions.success")),L()},onError:n=>{C.error(n.response?.data?.error||t("admin.event.retryOptions.error"))}});u.useEffect(()=>{!a&&c?.list.length&&w(c.list[0])},[c?.list.length,a]);const R=n=>{w(n)},z=n=>{j({retryEventId:n})},W=()=>{g.retryEventId&&(A(g.retryEventId),j({retryEventId:""}))};if(m)return e.jsx(B,{});const I=c&&c.list.length<c.count;return e.jsxs(f,{container:!0,spacing:2.5,children:[e.jsx(f,{size:{xs:12,md:4},className:"attempt-list",children:te.isEmpty(Object.keys(E))?e.jsx(l,{sx:{color:"text.secondary"},children:t("admin.event.noAttempts")}):e.jsxs(e.Fragment,{children:[e.jsx(N,{sx:{maxHeight:"64vh",overflowY:"scroll"},children:Object.entries(E).map(([n,x])=>e.jsxs(F.Fragment,{children:[e.jsx(H,{children:n}),x.map(d=>e.jsxs(T,{component:_,onClick:()=>R(d),selected:a===d,secondaryAction:e.jsx(l,{sx:{color:"text.secondary"},children:X(d.created_at,"HH:mm:ss A")}),children:[e.jsx(G,{children:se(d.response_status)===!1?e.jsx(J,{color:"error"}):e.jsx($,{color:"success"})}),e.jsx(Y,{primary:e.jsx(l,{sx:{color:"text.primary"},children:d.event.type})})]},d.id))]},n))}),I&&e.jsx(S,{variant:"text",type:"button",color:"inherit",onClick:i,disabled:p,children:t(p?"common.loading":"common.loadMore")}),!I&&e.jsx(l,{sx:{color:"text.secondary"},children:t("common.noMoreData")})]})}),e.jsxs(f,{size:{xs:12,md:8},children:[a&&e.jsxs(h,{direction:"column",spacing:2,sx:{pt:3,pl:3,borderLeft:"1px solid",borderColor:"divider"},children:[e.jsxs(h,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsx(l,{variant:"h6",children:r?a.endpoint.url:a.event.type}),e.jsx(S,{variant:"outlined",size:"small",startIcon:e.jsx(U,{}),onClick:()=>z(a.event_id),disabled:y,children:t(y?"admin.event.retrying":"admin.event.retry")})]}),g.retryEventId&&e.jsx(ee,{onConfirm:W,onCancel:()=>j({retryEventId:""}),title:t("admin.event.retryOptions.title"),message:t("admin.event.retryOptions.confirmMessage"),loading:y,color:"primary"}),e.jsxs(v,{children:[e.jsxs(l,{variant:"h6",children:[t("admin.event.response")," (",a.response_status,")"]}),e.jsx(b,{language:"json",children:JSON.stringify(a.response_body,null,2)})]}),e.jsxs(v,{children:[e.jsxs(h,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(l,{variant:"h6",children:t("admin.event.request")}),e.jsx(k,{requestInfo:a?.event?.requestInfo,request:a?.event.request})]}),e.jsx(b,{language:"json",children:JSON.stringify(a.event,null,2)})]})]}),c?.list.length===0&&s&&e.jsxs(v,{children:[e.jsxs(h,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(l,{variant:"h6",children:t("admin.event.eventData")}),e.jsx(k,{requestInfo:s.requestInfo,request:s.request})]}),e.jsx(b,{language:"json",children:JSON.stringify(s.data,null,2)})]})]})]})}export{xe as W};
@@ -0,0 +1 @@
1
+ import{a0 as r}from"./vendor-blocklet-B67R14so.js";function s(){return r().arcSphere}export{s as u};
@@ -1 +1 @@
1
- import{j as t,A as k,w as se,r as S,a3 as l,bv as ae,B as re,q as ie}from"./vendor-mui-BXZut9Pz.js";import{e as x,a as $,h as ce,R as oe,F as pe,E as de,U as le,V as me,W as ue,X as R,Y as U,Q as ye,Z as ge,C as he,_ as fe,$ as xe,L as _e,a0 as be,k as j,l as Ce,a1 as Se}from"./index-DgSc1Qy8.js";import{V as D,O as je,X as ve,Y as g,E as Pe}from"./vendor-blocklet-D_i_QeSo.js";import{e as Ie,a as we,b as ke}from"./vendor-react-BPknnnEA.js";import{S as A}from"./header-ivXuPt06.js";import{S as Fe}from"./description-Ym17DL48.js";import{g as Ee}from"./util-mDHAL0lx.js";import{u as Me,b as Ne}from"./subscription-Dq22e3D1.js";import{u as Re}from"./browser-DSLTxXlL.js";import"./lodash-B4Ozcv0x.js";const Ue=async e=>{const[i,r]=await Promise.all([x.get(`/api/subscriptions/${e}`).then(s=>s.data),x.get("/api/customers/me").then(s=>s.data)]);return{subscription:i,customer:r}},W={mode:"percent",percent:.5},Ae=e=>{if(!e||typeof e!="object")return W;const i=e.mode==="rate"?"rate":"percent",r=Number(e.percent),s=Number.isFinite(r)&&r>=0?r:W.percent,c=typeof e.min_acceptable_rate=="string"?e.min_acceptable_rate:void 0,d=typeof e.base_currency=="string"?e.base_currency:void 0,m=Number.isFinite(Number(e.updated_at_ms))?Number(e.updated_at_ms):void 0;return{mode:i,percent:s,...i==="rate"&&c?{min_acceptable_rate:c}:{},...d?{base_currency:d}:{},...m?{updated_at_ms:m}:{}}},We=async e=>{let i;return await Se(async()=>{const{data:r}=await x.get(`/api/subscriptions/${e}/change-payment`);if(r.setupIntent&&r.setupIntent.status==="requires_action"&&r.setupIntent.last_setup_error)throw new Error(r.setupIntent.last_setup_error.message);return i=r,r.setupIntent?.status==="succeeded"},{interval:2e3,timeout:180*1e3}),i};function $e({subscription:e,customer:i,onComplete:r}){const{t:s,locale:c}=D(),d=we(),[m]=ke(),{settings:u,connect:h}=$(),{checkUnpaidInvoices:V}=Me(e.id),{control:v,setValue:P,handleSubmit:B}=de(),O=Re(),[z,q]=S.useState(()=>Ae(e?.slippage_config)),[p,o]=ve({submitting:!1,paying:!1,paid:!1,stripePaying:!1,setupIntent:void 0,stripeContext:void 0,customer:i}),H=le(e.items),L=me(e.items[0]?.price).map(n=>n.currency_id),y=ue(u.paymentMethods).filter(n=>L.includes(n.id)),[I,T]=S.useState(y.findIndex(n=>n.id===e.currency_id)),_=R({control:v,name:"payment_currency"}),X=R({control:v,name:"payment_method"});S.useEffect(()=>{P("payment_method",y[I].method.id),P("payment_currency",y[I]?.id)},[I,y,P]);const b=u.paymentMethods.find(n=>n.id===X),F=_!==e.currency_id,Y=S.useMemo(()=>(e.items||[]).some(n=>{const a=n.upsell_price||n.price;return a&&a?.pricing_type==="dynamic"}),[e.items]),E=b?.type==="stripe",w=Y&&!E,{liveRateInfo:M,liveRateUnavailable:K}=Ne({subscriptionId:e.id,currencyId:_,enabled:w}),Q=async n=>{try{const a={...n,...n.base_currency?{}:{base_currency:M?.base_currency||"USD"}};await x.put(`/api/subscriptions/${e.id}/slippage`,{slippage_config:a}),q(a),g.success(s("common.saved"))}catch(a){console.error("Failed to update slippage",a),g.error(j(a))}},Z=async()=>{await r();const n=m.get("redirectUrl");n?window.location.href=n:d(`/customer/subscription/${e.id}`)},C=async()=>{try{await We(e.id),o({paid:!0,paying:!1}),g.success(s("payment.customer.changePayment.completed",{time:e.current_period_end})),await Z()}catch(n){g.error(j(n))}finally{o({paying:!1})}},G=async n=>{o({submitting:!0});try{const a=await x.post(`/api/subscriptions/${e.id}/change-payment`,n);o({setupIntent:a.data.setupIntent,stripeContext:a.data.stripeContext,submitting:!1}),["arcblock","ethereum","base"].includes(b.type)&&(o({paying:!0}),a.data.delegation?.sufficient?await C():h.open({locale:c,containerEl:void 0,action:"change-payment",prefix:Pe(Ce(),"/api/did"),saveConnect:!1,extraParams:{subscriptionId:e.id},messages:{scan:s("common.connect.defaultScan"),title:s("payment.customer.changePayment.title"),confirm:s("common.connect.confirm")},onSuccess:async()=>{h.close(),await C()},onClose:()=>{h.close(),o({submitting:!1,paying:!1})},onError:f=>{console.error(f),o({submitting:!1,paying:!1}),g.error(j(f))}})),["stripe"].includes(b.type)&&(a.data.setupIntent?.status==="succeeded"?await C():a.data.stripeContext?.status==="succeeded"?o({paying:!0}):o({stripePaying:!0}))}catch(a){console.error(a),g.error(j(a))}finally{o({submitting:!1})}},J=async()=>{e.overdraft_protection?.enabled&&await V()||B(G)()},ee=async()=>{o({stripePaying:!1,paying:!0}),await C()},te=()=>{o({stripePaying:!1})},N=U(u.paymentMethods,_);return t.jsxs(l,{direction:"column",spacing:4,sx:{maxWidth:"540px"},children:[t.jsx(l,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:O?t.jsx(re,{}):t.jsxs(l,{direction:"row",onClick:()=>Ee(`/customer/subscription/${e.id}`),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[t.jsx(ae,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),t.jsx(Fe,{subscription:e,variant:"h5"})]})}),t.jsx(k,{severity:"info",children:s("payment.customer.changePayment.limit")}),t.jsxs(l,{direction:"column",spacing:2,children:[t.jsx(A,{title:s("payment.customer.changePayment.review")}),t.jsx(ye,{items:e.items,currency:N,trialInDays:0,billingThreshold:0,showStaking:ge(b,N,!!e.billing_thresholds?.no_stake),liveRate:M,rateUnavailable:w&&K,slippageConfig:z,onSlippageChange:w?Q:void 0,isSubscription:!0,isStripePayment:E})]}),t.jsxs(l,{direction:"column",spacing:2,children:[t.jsx(A,{title:s("payment.customer.changePayment.select")}),t.jsx(he,{name:"payment_currency",control:v,render:({field:n})=>t.jsx(fe,{value:n.value,currencies:y,onChange:a=>{const f=y.findIndex(ne=>ne.id===a);f>=0&&T(f)}})}),e.paymentMethod.type!=="stripe"&&t.jsx(l,{direction:"column",className:"cko-payment-form",spacing:0,children:t.jsx(xe,{mode:"auto"})})]}),F&&t.jsxs(l,{className:"cko-payment-submit",children:[t.jsx(_e,{variant:"contained",color:"primary",size:"large",onClick:J,fullWidth:!0,loadingPosition:"end",disabled:!F||p.submitting||p.paying||p.stripePaying,loading:p.paying,children:p.paying?s("payment.checkout.processing"):s("payment.customer.changePayment.submit")}),t.jsx(ie,{sx:{mt:1,color:"text.secondary",fontSize:"0.7875rem",lineHeight:"0.9625rem",textAlign:"center"},children:s("payment.customer.changePayment.confirm",{payee:H,symbol:U(u.paymentMethods,_)?.symbol})})]}),p.stripePaying&&p.stripeContext&&t.jsx(be,{clientSecret:p.stripeContext.client_secret,intentType:p.stripeContext.intent_type,publicKey:p.stripeContext.publishable_key,customer:p.customer,mode:"setup",onConfirm:ee,onCancel:te,returnUrl:window.location.href.replace(/\/[^/]+$/,"")})]})}function De({subscription:e,customer:i,onComplete:r}){const{settings:s}=$(),c=e.currency_id,d=s.paymentMethods.find(u=>u.payment_currencies.some(h=>h.id===c))?.id,m=ce({defaultValues:{payment_method:d,payment_currency:c,billing_address:Object.assign({country:"",state:"",city:"",line1:"",line2:"",postal_code:""},i?.address||{},{country:oe(i?.address?.country||"")?i?.address?.country:"us"})}});return t.jsx(pe,{...m,children:t.jsx($e,{subscription:e,customer:i,onComplete:r})})}function Ke(){const{t:e}=D(),{id:i}=Ie(),{loading:r,error:s,data:c,runAsync:d}=je(()=>Ue(i));return s?t.jsx(k,{severity:"error",children:s.message}):r||!c?t.jsx(se,{}):c?t.jsx(De,{subscription:c.subscription,customer:c.customer,onComplete:d}):t.jsx(k,{severity:"error",children:e("payment.customer.changePlan.subscriptionNotFound")})}export{Ke as default};
1
+ import{j as t,A as k,w as se,r as S,a3 as l,bv as ae,B as re,q as ie}from"./vendor-mui-BXZut9Pz.js";import{e as x,a as $,h as ce,R as oe,F as pe,E as de,U as le,V as me,W as ue,X as R,Y as U,Q as ye,Z as ge,C as he,_ as fe,$ as xe,L as _e,a0 as be,k as j,l as Ce,a1 as Se}from"./index-B4yaPb7B.js";import{V as D,P as je,Y as Pe,Z as g,F as ve}from"./vendor-blocklet-B67R14so.js";import{e as Ie,a as we,b as ke}from"./vendor-react-BPknnnEA.js";import{S as A}from"./header-ivXuPt06.js";import{S as Fe}from"./description-BHxdy5I3.js";import{g as Me}from"./util-B8B3fsMa.js";import{u as Ee,b as Ne}from"./subscription-Bzeblscr.js";import{u as Re}from"./browser-DF2vfpBa.js";import"./lodash-B4Ozcv0x.js";const Ue=async e=>{const[i,r]=await Promise.all([x.get(`/api/subscriptions/${e}`).then(s=>s.data),x.get("/api/customers/me").then(s=>s.data)]);return{subscription:i,customer:r}},W={mode:"percent",percent:.5},Ae=e=>{if(!e||typeof e!="object")return W;const i=e.mode==="rate"?"rate":"percent",r=Number(e.percent),s=Number.isFinite(r)&&r>=0?r:W.percent,c=typeof e.min_acceptable_rate=="string"?e.min_acceptable_rate:void 0,d=typeof e.base_currency=="string"?e.base_currency:void 0,m=Number.isFinite(Number(e.updated_at_ms))?Number(e.updated_at_ms):void 0;return{mode:i,percent:s,...i==="rate"&&c?{min_acceptable_rate:c}:{},...d?{base_currency:d}:{},...m?{updated_at_ms:m}:{}}},We=async e=>{let i;return await Se(async()=>{const{data:r}=await x.get(`/api/subscriptions/${e}/change-payment`);if(r.setupIntent&&r.setupIntent.status==="requires_action"&&r.setupIntent.last_setup_error)throw new Error(r.setupIntent.last_setup_error.message);return i=r,r.setupIntent?.status==="succeeded"},{interval:2e3,timeout:180*1e3}),i};function $e({subscription:e,customer:i,onComplete:r}){const{t:s,locale:c}=D(),d=we(),[m]=ke(),{settings:u,connect:h}=$(),{checkUnpaidInvoices:V}=Ee(e.id),{control:P,setValue:v,handleSubmit:B}=de(),z=Re(),[O,q]=S.useState(()=>Ae(e?.slippage_config)),[p,o]=Pe({submitting:!1,paying:!1,paid:!1,stripePaying:!1,setupIntent:void 0,stripeContext:void 0,customer:i}),H=le(e.items),L=me(e.items[0]?.price).map(n=>n.currency_id),y=ue(u.paymentMethods).filter(n=>L.includes(n.id)),[I,T]=S.useState(y.findIndex(n=>n.id===e.currency_id)),_=R({control:P,name:"payment_currency"}),Y=R({control:P,name:"payment_method"});S.useEffect(()=>{v("payment_method",y[I].method.id),v("payment_currency",y[I]?.id)},[I,y,v]);const b=u.paymentMethods.find(n=>n.id===Y),F=_!==e.currency_id,Z=S.useMemo(()=>(e.items||[]).some(n=>{const a=n.upsell_price||n.price;return a&&a?.pricing_type==="dynamic"}),[e.items]),M=b?.type==="stripe",w=Z&&!M,{liveRateInfo:E,liveRateUnavailable:K}=Ne({subscriptionId:e.id,currencyId:_,enabled:w}),Q=async n=>{try{const a={...n,...n.base_currency?{}:{base_currency:E?.base_currency||"USD"}};await x.put(`/api/subscriptions/${e.id}/slippage`,{slippage_config:a}),q(a),g.success(s("common.saved"))}catch(a){console.error("Failed to update slippage",a),g.error(j(a))}},X=async()=>{await r();const n=m.get("redirectUrl");n?window.location.href=n:d(`/customer/subscription/${e.id}`)},C=async()=>{try{await We(e.id),o({paid:!0,paying:!1}),g.success(s("payment.customer.changePayment.completed",{time:e.current_period_end})),await X()}catch(n){g.error(j(n))}finally{o({paying:!1})}},G=async n=>{o({submitting:!0});try{const a=await x.post(`/api/subscriptions/${e.id}/change-payment`,n);o({setupIntent:a.data.setupIntent,stripeContext:a.data.stripeContext,submitting:!1}),["arcblock","ethereum","base"].includes(b.type)&&(o({paying:!0}),a.data.delegation?.sufficient?await C():h.open({locale:c,containerEl:void 0,action:"change-payment",prefix:ve(Ce(),"/api/did"),saveConnect:!1,extraParams:{subscriptionId:e.id},messages:{scan:s("common.connect.defaultScan"),title:s("payment.customer.changePayment.title"),confirm:s("common.connect.confirm")},onSuccess:async()=>{h.close(),await C()},onClose:()=>{h.close(),o({submitting:!1,paying:!1})},onError:f=>{console.error(f),o({submitting:!1,paying:!1}),g.error(j(f))}})),["stripe"].includes(b.type)&&(a.data.setupIntent?.status==="succeeded"?await C():a.data.stripeContext?.status==="succeeded"?o({paying:!0}):o({stripePaying:!0}))}catch(a){console.error(a),g.error(j(a))}finally{o({submitting:!1})}},J=async()=>{e.overdraft_protection?.enabled&&await V()||B(G)()},ee=async()=>{o({stripePaying:!1,paying:!0}),await C()},te=()=>{o({stripePaying:!1})},N=U(u.paymentMethods,_);return t.jsxs(l,{direction:"column",spacing:4,sx:{maxWidth:"540px"},children:[t.jsx(l,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:z?t.jsx(re,{}):t.jsxs(l,{direction:"row",onClick:()=>Me(`/customer/subscription/${e.id}`),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[t.jsx(ae,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),t.jsx(Fe,{subscription:e,variant:"h5"})]})}),t.jsx(k,{severity:"info",children:s("payment.customer.changePayment.limit")}),t.jsxs(l,{direction:"column",spacing:2,children:[t.jsx(A,{title:s("payment.customer.changePayment.review")}),t.jsx(ye,{items:e.items,currency:N,trialInDays:0,billingThreshold:0,showStaking:ge(b,N,!!e.billing_thresholds?.no_stake),liveRate:E,rateUnavailable:w&&K,slippageConfig:O,onSlippageChange:w?Q:void 0,isSubscription:!0,isStripePayment:M})]}),t.jsxs(l,{direction:"column",spacing:2,children:[t.jsx(A,{title:s("payment.customer.changePayment.select")}),t.jsx(he,{name:"payment_currency",control:P,render:({field:n})=>t.jsx(fe,{value:n.value,currencies:y,onChange:a=>{const f=y.findIndex(ne=>ne.id===a);f>=0&&T(f)}})}),e.paymentMethod.type!=="stripe"&&t.jsx(l,{direction:"column",className:"cko-payment-form",spacing:0,children:t.jsx(xe,{mode:"auto"})})]}),F&&t.jsxs(l,{className:"cko-payment-submit",children:[t.jsx(_e,{variant:"contained",color:"primary",size:"large",onClick:J,fullWidth:!0,loadingPosition:"end",disabled:!F||p.submitting||p.paying||p.stripePaying,loading:p.paying,children:p.paying?s("payment.checkout.processing"):s("payment.customer.changePayment.submit")}),t.jsx(ie,{sx:{mt:1,color:"text.secondary",fontSize:"0.7875rem",lineHeight:"0.9625rem",textAlign:"center"},children:s("payment.customer.changePayment.confirm",{payee:H,symbol:U(u.paymentMethods,_)?.symbol})})]}),p.stripePaying&&p.stripeContext&&t.jsx(be,{clientSecret:p.stripeContext.client_secret,intentType:p.stripeContext.intent_type,publicKey:p.stripeContext.publishable_key,customer:p.customer,mode:"setup",onConfirm:ee,onCancel:te,returnUrl:window.location.href.replace(/\/[^/]+$/,"")})]})}function De({subscription:e,customer:i,onComplete:r}){const{settings:s}=$(),c=e.currency_id,d=s.paymentMethods.find(u=>u.payment_currencies.some(h=>h.id===c))?.id,m=ce({defaultValues:{payment_method:d,payment_currency:c,billing_address:Object.assign({country:"",state:"",city:"",line1:"",line2:"",postal_code:""},i?.address||{},{country:oe(i?.address?.country||"")?i?.address?.country:"us"})}});return t.jsx(pe,{...m,children:t.jsx($e,{subscription:e,customer:i,onComplete:r})})}function Ke(){const{t:e}=D(),{id:i}=Ie(),{loading:r,error:s,data:c,runAsync:d}=je(()=>Ue(i));return s?t.jsx(k,{severity:"error",children:s.message}):r||!c?t.jsx(se,{}):c?t.jsx(De,{subscription:c.subscription,customer:c.customer,onComplete:d}):t.jsx(k,{severity:"error",children:e("payment.customer.changePlan.subscriptionNotFound")})}export{Ke as default};