cppay-sdk 0.0.2-beta.9 → 0.0.2

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.
package/dist/vue.cjs CHANGED
@@ -1 +1 @@
1
- const e=require(`./cppay-D9NSpEr9.cjs`),t=require(`./inject-style-Dz7JsQxo.cjs`),n=require(`./react.cjs`);let r=require(`vue`);var i={class:`_cppay-dialog`},a={class:`_cppay-header`},o={class:`_cppay-title`},s=[`disabled`],c={class:`_cppay-content`},l={key:0},u={class:`_cppay-section`},d={class:`_cppay-grid`},f=[`onClick`],p=[`src`,`alt`],m={class:`_cppay-section`},h={class:`_cppay-grid`},g=[`onClick`],_=[`src`,`alt`],v={class:`_cppay-section`},y={class:`_cppay-price-box`},b={class:`_cppay-price-row`},x={class:`_cppay-price-amount`},S={class:`_cppay-price-main`},C={class:`_cppay-price-sub`},w={class:`_cppay-section`},T=[`disabled`],E={key:1},D={class:`_cppay-section`},O={class:`_cppay-info-box`},k={class:`_cppay-info-value`},A={class:`_cppay-info-box`},j={class:`_cppay-address-row`},M={class:`_cppay-section`},ee=[`disabled`],N={class:`_cppay-section`},P=[`disabled`],F=(0,r.defineComponent)({__name:`PaymentDialog`,props:{modelValue:{type:Boolean},apiKey:{},orderId:{},amount:{}},emits:[`update:modelValue`,`success`,`error`],setup(t,{emit:n}){let F=t,I=n,L=new e.t(F.apiKey),R=(0,r.ref)(`select`),z=(0,r.ref)(!1),B=(0,r.ref)([]),V=(0,r.ref)(``),H=(0,r.ref)(``),U=(0,r.ref)(null),W=(0,r.computed)(()=>B.value.find(e=>e.chain===V.value)),G=(0,r.computed)(()=>W.value?.tokens||[]),K=(0,r.computed)(()=>G.value.find(e=>e.symbol===H.value)),q=(0,r.ref)(1),J=(0,r.computed)(()=>H.value?(parseFloat(F.amount)/q.value).toFixed(6):`0`),Y=()=>{I(`update:modelValue`,!1),setTimeout(()=>{R.value=`select`,U.value=null},300)},X=async()=>{try{z.value=!0,B.value=await L.getSupportedChains(),B.value.length>0&&(V.value=B.value[0].chain)}catch(e){I(`error`,e)}finally{z.value=!1}},Z=async()=>{if(!(!V.value||!H.value))try{z.value=!0;let e=await L.createPayment({paymentChain:V.value,paymentToken:H.value,orderId:F.orderId,amount:J.value});U.value={paymentId:e.paymentId,paymentAmount:e.paymentAmount,receiveAddress:K.value?.receiveAddresses[0]||``},R.value=`payment`}catch(e){I(`error`,e)}finally{z.value=!1}},Q=async()=>{if(U.value)try{z.value=!0,await L.checkPaymentStatus(U.value.paymentId),I(`success`,U.value.paymentId),Y()}catch(e){I(`error`,e)}finally{z.value=!1}},$=async()=>{U.value?.receiveAddress&&await navigator.clipboard.writeText(U.value.receiveAddress)};return(0,r.watch)(()=>F.modelValue,e=>{e&&B.value.length===0&&X()}),(0,r.watch)(V,()=>{G.value.length>0&&(H.value=G.value[0].symbol)}),(e,n)=>((0,r.openBlock)(),(0,r.createBlock)(r.Teleport,{to:`body`},[(0,r.createVNode)(r.Transition,{name:`_cppay-fade`},{default:(0,r.withCtx)(()=>[t.modelValue?((0,r.openBlock)(),(0,r.createElementBlock)(`div`,{key:0,class:`_cppay-overlay`,onClick:(0,r.withModifiers)(Y,[`self`])},[(0,r.createElementVNode)(`div`,i,[(0,r.createElementVNode)(`div`,a,[(0,r.createElementVNode)(`h2`,o,(0,r.toDisplayString)(R.value===`select`?`选择支付方式`:`完成支付`),1),(0,r.createElementVNode)(`button`,{onClick:Y,class:`_cppay-close-btn`,disabled:z.value},[...n[1]||=[(0,r.createElementVNode)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`},[(0,r.createElementVNode)(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M6 18L18 6M6 6l12 12`})],-1)]],8,s)]),(0,r.createElementVNode)(`div`,c,[R.value===`select`?((0,r.openBlock)(),(0,r.createElementBlock)(`div`,l,[(0,r.createElementVNode)(`div`,u,[n[2]||=(0,r.createElementVNode)(`label`,{class:`_cppay-label`},`支付网络`,-1),(0,r.createElementVNode)(`div`,d,[((0,r.openBlock)(!0),(0,r.createElementBlock)(r.Fragment,null,(0,r.renderList)(B.value,e=>((0,r.openBlock)(),(0,r.createElementBlock)(`button`,{key:e.chain,onClick:t=>V.value=e.chain,class:(0,r.normalizeClass)([`_cppay-select-btn`,V.value===e.chain?`_cppay-selected`:``])},[e.icon?((0,r.openBlock)(),(0,r.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.chain},null,8,p)):(0,r.createCommentVNode)(``,!0),(0,r.createElementVNode)(`span`,null,(0,r.toDisplayString)(e.chain),1)],10,f))),128))])]),(0,r.createElementVNode)(`div`,m,[n[3]||=(0,r.createElementVNode)(`label`,{class:`_cppay-label`},`支付代币`,-1),(0,r.createElementVNode)(`div`,h,[((0,r.openBlock)(!0),(0,r.createElementBlock)(r.Fragment,null,(0,r.renderList)(G.value,e=>((0,r.openBlock)(),(0,r.createElementBlock)(`button`,{key:e.symbol,onClick:t=>H.value=e.symbol,class:(0,r.normalizeClass)([`_cppay-select-btn`,H.value===e.symbol?`_cppay-selected`:``])},[e.icon?((0,r.openBlock)(),(0,r.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.symbol},null,8,_)):(0,r.createCommentVNode)(``,!0),(0,r.createElementVNode)(`span`,null,(0,r.toDisplayString)(e.symbol),1)],10,g))),128))])]),(0,r.createElementVNode)(`div`,v,[(0,r.createElementVNode)(`div`,y,[(0,r.createElementVNode)(`div`,b,[n[4]||=(0,r.createElementVNode)(`span`,{class:`_cppay-price-label`},`支付金额`,-1),(0,r.createElementVNode)(`div`,x,[(0,r.createElementVNode)(`div`,S,(0,r.toDisplayString)(J.value)+` `+(0,r.toDisplayString)(H.value),1),(0,r.createElementVNode)(`div`,C,`≈ $`+(0,r.toDisplayString)(t.amount),1)])])])]),(0,r.createElementVNode)(`div`,w,[(0,r.createElementVNode)(`button`,{onClick:Z,disabled:!V.value||!H.value||z.value,class:`_cppay-btn _cppay-btn-primary`},(0,r.toDisplayString)(z.value?`处理中...`:`继续支付`),9,T)])])):R.value===`payment`&&U.value?((0,r.openBlock)(),(0,r.createElementBlock)(`div`,E,[n[8]||=(0,r.createElementVNode)(`div`,{class:`_cppay-qr-container`},[(0,r.createElementVNode)(`div`,{class:`_cppay-qr-placeholder`},[(0,r.createElementVNode)(`span`,null,`扫码支付`)])],-1),(0,r.createElementVNode)(`div`,D,[(0,r.createElementVNode)(`div`,O,[n[5]||=(0,r.createElementVNode)(`div`,{class:`_cppay-info-label`},`支付金额`,-1),(0,r.createElementVNode)(`div`,k,(0,r.toDisplayString)(U.value.paymentAmount)+` `+(0,r.toDisplayString)(H.value),1)]),(0,r.createElementVNode)(`div`,A,[n[7]||=(0,r.createElementVNode)(`div`,{class:`_cppay-info-label`},`支付地址`,-1),(0,r.createElementVNode)(`div`,j,[(0,r.createElementVNode)(`code`,null,(0,r.toDisplayString)(U.value.receiveAddress),1),(0,r.createElementVNode)(`button`,{onClick:$,class:`_cppay-copy-btn`,title:`复制地址`},[...n[6]||=[(0,r.createElementVNode)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`},[(0,r.createElementVNode)(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z`})],-1)]])])])]),(0,r.createElementVNode)(`div`,M,[(0,r.createElementVNode)(`button`,{onClick:Q,disabled:z.value,class:`_cppay-btn _cppay-btn-primary`},(0,r.toDisplayString)(z.value?`检查支付状态...`:`我已完成支付`),9,ee)]),(0,r.createElementVNode)(`div`,N,[(0,r.createElementVNode)(`button`,{onClick:n[0]||=e=>R.value=`select`,disabled:z.value,class:`_cppay-btn _cppay-btn-secondary`},` 更改支付方式 `,8,P)])])):(0,r.createCommentVNode)(``,!0)])])])):(0,r.createCommentVNode)(``,!0)]),_:1})]))}}),I=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},L=I(F,[[`__scopeId`,`data-v-de37a8de`]]);t.t(t.n),exports.PaymentDialog=L;
1
+ const e=require(`./locales-BWWyDdfj.cjs`),t=require(`./cppay-DuOJqlpA.cjs`);let n=require(`vue`),r=require(`qrcode`);r=e.i(r);let i=require(`rxjs`),a=require(`rxjs/operators`),o=require(`viem`),s=require(`viem/chains`),c=require(`@reown/appkit`),l=require(`@reown/appkit-adapter-ethers`);var u={class:`_cppay-content`},d={class:`_cppay-state-container`},ee={class:`_cppay-state-title _cppay-state-title-success`},te={key:0,class:`_cppay-state-hash-container`},ne={class:`_cppay-state-label`},re={class:`_cppay-hash-row`},ie={class:`_cppay-state-hash`},ae=[`title`],oe={key:1,class:`_cppay-success-details`},se={class:`_cppay-detail-item`},ce={class:`_cppay-detail-label`},le={class:`_cppay-detail-value`},ue={class:`_cppay-detail-item`},de={class:`_cppay-detail-label`},fe={class:`_cppay-detail-value`},pe={class:`_cppay-detail-item`},me={class:`_cppay-detail-label`},he={class:`_cppay-detail-value`},ge={class:`_cppay-detail-item`},_e={class:`_cppay-detail-label`},ve={class:`_cppay-detail-value`},ye={key:0,class:`_cppay-detail-item`},be={class:`_cppay-detail-label`},xe={class:`_cppay-detail-value`},Se={class:`_cppay-detail-item`},Ce={class:`_cppay-detail-label`},we={class:`_cppay-detail-value _cppay-detail-id`},Te={class:`_cppay-state-container`},Ee={class:`_cppay-state-title _cppay-state-title-expired`},De={class:`_cppay-state-message`},Oe=[`disabled`],ke={class:`_cppay-state-container`},Ae={class:`_cppay-state-title _cppay-state-title-error`},je={class:`_cppay-state-message`},Me=[`disabled`],Ne={class:`_cppay-state-container`},Pe={class:`_cppay-state-title _cppay-state-title-failed`},Fe={class:`_cppay-state-message`},Ie=[`disabled`],Le={key:4},Re={class:`_cppay-section`},ze={class:`_cppay-label`},f={class:`_cppay-grid`},p=[`onClick`],m=[`src`,`alt`],Be={class:`_cppay-section`},Ve={class:`_cppay-label`},He={class:`_cppay-grid`},Ue=[`onClick`],We=[`src`,`alt`],Ge={class:`_cppay-section`},Ke={class:`_cppay-price-box`},qe={class:`_cppay-price-row`},Je={class:`_cppay-price-label`},Ye={class:`_cppay-price-amount`},Xe={class:`_cppay-price-main`},Ze={class:`_cppay-price-sub`},Qe={class:`_cppay-section`},$e={class:`_cppay-error-tooltip`},et={key:0,class:`_cppay-error-tooltip-full`},tt=[`disabled`],nt={key:5},rt={class:`_cppay-qr-container`},it={class:`_cppay-qr-code`},at=[`src`],ot={class:`_cppay-section`},st={key:0,class:`_cppay-info-box`},ct={class:`_cppay-info-flex-container`},lt={class:`_cppay-info-flex-child`},ut={class:`_cppay-info-label`},dt={class:`_cppay-info-value _cppay-info-value-flex`},ft={key:0},pt={class:`_cppay-info-box`},mt={class:`_cppay-info-flex-child`},ht={class:`_cppay-info-label _cppay-info-label-flex`},gt={key:0,class:`_cppay-countdown`},_t={class:`_cppay-address-row`},vt={key:0},yt=[`title`],bt={key:0,class:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},xt={key:1,class:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`currentColor`},St={key:1,class:`_cppay-info-box _cppay-subscription-box`},Ct={class:`_cppay-info-label _cppay-subscription-label`},wt={class:`_cppay-info-value _cppay-subscription-message`},Tt={class:`_cppay-error-tooltip`},Et={key:0,class:`_cppay-error-tooltip-full`},Dt={key:1,class:`_cppay-section`},Ot=[`disabled`],kt=[`disabled`],At=[`disabled`,`title`],jt={class:`_cppay-wallet-address-text`},Mt={class:`_cppay-section`},Nt=[`disabled`],Pt={class:`_cppay-section`},Ft=[`disabled`],h=(0,n.defineComponent)({__name:`PaymentContent`,props:{apikey:{},ott:{},orderId:{},amount:{},plain:{},intervalDays:{},remark:{},slots:{},locale:{}},emits:[`update:paymentStep`,`success`,`expired`,`failed`,`error`],setup(h,{emit:g}){let _=h,v=g,y=(0,n.computed)(()=>e.t(_.locale)),b=(0,n.computed)(()=>new t.t(_.apikey,_.ott)),x=(0,n.ref)(`select`),S=(0,n.ref)(!1),C=(0,n.computed)(()=>x.value===`checking`),w=(0,n.ref)(),T=(0,n.ref)([]),E=(0,n.ref)(),D=(0,n.ref)(),O=(0,n.ref)(),k=(0,n.ref)(),A=(0,n.ref)(!1),j=(0,n.ref)(),M=(0,n.ref)(``),N=(0,n.ref)(!1),P=(0,n.ref)(!1),F=(0,n.shallowRef)(null),I=(0,n.ref)(null),L=(0,n.ref)(null),R=(0,n.ref)(null),z=(0,n.ref)(``),It=()=>{typeof window<`u`&&!F.value&&(F.value=(0,c.createAppKit)({debug:!1,enableNetworkSwitch:!1,adapters:[new l.EthersAdapter],projectId:`8d2e1854d3f1782e45aa15fbd8938894`,allowUnsupportedChain:!0,networks:[s.mainnet,s.bsc,s.polygon,s.arbitrum,s.optimism,s.base],metadata:{name:`Cppay`,description:`Cppay Payment Gateway`,url:window.location.origin,icons:[`https://cppay.com/icon.png`]},features:{analytics:!1}}),k.value=F.value.getAddress(),j.value=F.value.getProvider(`eip155`),F.value.subscribeAccount(e=>{e.isConnected?k.value=e.address:(k.value=void 0,j.value=void 0)}),F.value.subscribeProviders(e=>{j.value=e?.eip155}))};(0,n.watch)(x,e=>{v(`update:paymentStep`,e)});let B=async()=>{try{A.value=!0,w.value=void 0,F.value&&await F.value.open()}catch(e){w.value=e instanceof Error?e.message:y.value.walletConnectionFailed,v(`error`,e)}finally{A.value=!1}},V=(0,n.computed)(()=>T.value.find(e=>e.chain===E.value)),H=(0,n.computed)(()=>V.value?.tokens||[]),U=(0,n.computed)(()=>H.value.find(e=>e.symbol===D.value)),W=e=>[`USDT`,`USDC`,`BUSD`,`DAI`,`TUSD`,`USDD`,`FDUSD`].includes(e.toUpperCase())?2:6,G=(e,t)=>{let n=parseFloat(e);return isNaN(n)?`0`:n.toFixed(t).replace(/\.?0+$/,``)},Lt=e=>{if(e<=0)return y.value.expired;let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=e%60,i=e=>e.toString().padStart(2,`0`);return t>0?`${t}:${i(n)}:${i(r)}`:`${n}:${i(r)}`},K=e=>{L.value&&clearInterval(L.value);let t=()=>{if(x.value===`checking`){q();return}let t=e-Math.floor(Date.now()/1e3);M.value=Lt(t),t<=0&&q()};t(),L.value=setInterval(t,1e3)},q=()=>{L.value&&=(clearInterval(L.value),null)},J=(0,n.computed)(()=>{if(!D.value||!U.value)return`0`;let e=parseFloat(U.value.price);if(isNaN(e)||e===0)return`0`;let t=W(D.value);return G((parseFloat(_.amount)/e).toFixed(t),t)}),Rt=async()=>{try{S.value=!0,w.value=void 0,T.value=await b.value.getSupportedChains(),T.value.length>0&&(E.value=T.value[0].chain)}catch(e){w.value=e instanceof Error?e.message:y.value.loadPaymentNetworkFailed,v(`error`,e)}finally{S.value=!1}},Y=async e=>{if(j.value)try{await j.value.request({method:`wallet_switchEthereumChain`,params:[{chainId:`0x${e.toString(16)}`}]})}catch(e){throw e.code===4902?Error(y.value.pleaseAddNetwork):e}},zt=async()=>{if(!(!k.value||!j.value||!R.value||!U.value||!V.value))try{S.value=!0;let e=R.value;await Y(V.value.chainId);let t=(0,o.createWalletClient)({account:k.value,transport:(0,o.custom)(j.value)});if(U.value.address){let n=await t.writeContract({address:U.value.address,abi:[{name:`transfer`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`to`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`transfer`,args:[e.receiveAddress,(0,o.parseUnits)(e.paymentAmount,U.value.decimals)],chain:null});console.log(`转账交易哈希:`,n),z.value=n}else{let n=await t.sendTransaction({to:e.receiveAddress,value:(0,o.parseUnits)(e.paymentAmount,U.value.decimals),chain:null});console.log(`转账交易哈希:`,n),z.value=n}S.value=!1,x.value=`checking`,Z({paymentId:e.paymentId})}catch(e){console.error(`钱包支付失败:`,e),w.value=e instanceof Error?e.message:y.value.walletPaymentFailed,v(`error`,e),S.value=!1}},Bt=async()=>{if(!(!k.value||!j.value||!R.value||!U.value||!V.value))try{let e=R.value;await Y(V.value.chainId);let t=(0,o.createWalletClient)({account:k.value,transport:(0,o.custom)(j.value)});if(!U.value.address)throw Error(y.value.subscriptionDoesNotSupportNative);let n=await t.writeContract({address:U.value.address,abi:[{name:`approve`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`spender`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`approve`,args:[e.spenderAddress,(0,o.parseUnits)(e.approveAmount,U.value.decimals)],chain:null});console.log(`授权交易哈希:`,n),z.value=n,S.value=!1,x.value=`checking`,Z({subscriptionId:e.subscriptionId})}catch(e){console.error(`钱包授权失败:`,e),w.value=e instanceof Error?e.message:y.value.walletPaymentFailed,v(`error`,e),S.value=!1}},Vt=async()=>{if(!k.value){w.value=y.value.pleaseConnectWallet,v(`error`,Error(y.value.pleaseConnectWallet));return}_.plain===`instant`?await zt():_.plain===`subscription`&&await Bt()},Ht=async()=>{if(!(!E.value||!D.value))try{w.value=void 0;let e=``;if(_.plain===`instant`)R.value=await b.value.createOnetimePayment({paymentChain:E.value,paymentToken:D.value,orderId:_.orderId,amount:J.value,remark:_.remark}),e=`${E.value.toLowerCase()}:${R.value.receiveAddress}?amount=${R.value.paymentAmount}`,K(R.value.expireAt),Q(R.value.paymentId,`instant`);else if(_.plain===`subscription`){if(!_.intervalDays)throw Error(`Invalid Renewal Days: ${_.intervalDays??``}`);R.value=await b.value.createSubscriptionPayment({paymentChain:E.value,paymentToken:D.value,orderId:_.orderId,amountOfUsd:J.value,intervalDays:_.intervalDays}),e=`${E.value.toLowerCase()}:${R.value.spenderAddress}?amount=${R.value.approveAmount}`,K(R.value.expireAt),Q(R.value.subscriptionId,`subscription`)}x.value=`payment`,O.value=await r.toDataURL(e,{width:200,margin:2,errorCorrectionLevel:`H`})}catch(e){w.value=e instanceof Error?e.message:y.value.createPaymentFailed,v(`error`,e)}},X=()=>{R.value&&(w.value=void 0,x.value=`checking`,_.plain===`instant`?Z({paymentId:R.value.paymentId}):_.plain===`subscription`&&Z({subscriptionId:R.value.subscriptionId}))},Z=e=>{I.value?.unsubscribe();let t=()=>(0,i.defer)(()=>_.plain===`subscription`?b.value.checkSubscriptionPaymentStatus(e):b.value.checkOnetimePaymentStatus(e)).pipe((0,a.timeout)(15e3),(0,a.retry)({delay:2e3}));I.value=t().pipe((0,a.expand)(e=>e.status===`pending`?(0,i.timer)(2e3).pipe((0,a.switchMap)(()=>t())):i.EMPTY),(0,a.tap)(e=>{if(!R.value&&_.plain===`instant`){let t=e;R.value={paymentId:t.paymentId,orderId:t.orderId,paymentChain:t.chain,paymentToken:t.token,paymentAmount:t.payAmount,receiveAddress:t.receiveAddress,expireAt:t.expireAt},E.value=t.chain,D.value=t.token,K(t.expireAt);let n=`${t.chain.toLowerCase()}:${t.receiveAddress}?amount=${t.payAmount}`;r.toDataURL(n,{width:200,margin:2,errorCorrectionLevel:`H`}).then(e=>{O.value=e,x.value=`payment`}).catch(e=>{console.error(`生成二维码失败:`,e),x.value=`select`})}if(!R.value&&_.plain===`subscription`){let t=e;R.value={subscriptionId:t.subscriptionId,orderId:t.orderId,paymentChain:t.chain,paymentToken:t.token,approveAmount:t.approveAmount,spenderAddress:t.approvedAddress,expireAt:t.expireAt,intervalDays:0,amountOfUsd:t.amountOfUsd},E.value=t.chain,D.value=t.token,K(t.expireAt);let n=`${t.chain.toLowerCase()}:${t.approvedAddress}?amount=${t.approveAmount}`;r.toDataURL(n,{width:200,margin:2,errorCorrectionLevel:`H`}).then(e=>{O.value=e,x.value=`payment`}).catch(e=>{console.error(`生成二维码失败:`,e),x.value=`select`})}(e.status===`paid`||e.status===`approved`)&&(x.value=`success`,$(),v(`success`,e)),e.status===`expired`&&(x.value=`expired`,$(),v(`expired`,e)),e.status===`failed`&&(x.value=`failed`,$(),v(`failed`,e))})).subscribe({error:e=>{if(R.value){let t=e instanceof Error?e.message:y.value.checkPaymentStatusFailed;x.value=`error`,w.value=t,$(),v(`error`,e)}},complete:()=>{I.value?.unsubscribe()}})},Ut=async()=>{if(!R.value)return;let e=_.plain===`subscription`?R.value.spenderAddress:R.value.receiveAddress;if(e)try{await navigator.clipboard.writeText(e),N.value=!0,setTimeout(()=>{N.value=!1},2e3)}catch(e){console.error(`复制失败:`,e)}};(0,n.watch)(H,e=>{e.length>0&&(D.value=e[0].symbol)}),(0,n.onMounted)(()=>{It(),T.value.length||Rt(),Gt()}),(0,n.onUnmounted)(()=>{I.value?.unsubscribe(),q()});let Wt=async()=>{if(z.value)try{await navigator.clipboard.writeText(z.value);let e=N.value;N.value=!0,setTimeout(()=>{N.value=e},2e3)}catch(e){console.error(`复制失败:`,e)}},Q=(e,t)=>{if(!_.ott||typeof window>`u`)return;let n=new URL(window.location.href),r=t===`subscription`?`subscriptionId`:`paymentId`;n.searchParams.set(r,e),window.history.replaceState({},``,n.toString())},$=()=>{if(typeof window>`u`)return;let e=new URL(window.location.href);e.searchParams.delete(`paymentId`),e.searchParams.delete(`subscriptionId`),window.history.replaceState({},``,e.toString())},Gt=async()=>{if(typeof window>`u`)return;let e=new URL(window.location.href);if(_.plain===`instant`){let t=e.searchParams.get(`paymentId`);t&&(x.value=`payment`,Z({paymentId:t}))}if(_.plain===`subscription`){let t=e.searchParams.get(`subscriptionId`);t&&(x.value=`payment`,Z({subscriptionId:t}))}};return(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`div`,u,[x.value===`success`?(0,n.renderSlot)(e.$slots,`success`,{key:0},()=>[(0,n.createElementVNode)(`div`,d,[t[9]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-success-bg`},[(0,n.createElementVNode)(`div`,{class:`_cppay-state-success-icon`},`✓`)],-1),(0,n.createElementVNode)(`h3`,ee,(0,n.toDisplayString)(h.plain===`subscription`?y.value.authorizationSuccess:y.value.paymentSuccess),1),z.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,te,[(0,n.createElementVNode)(`div`,ne,(0,n.toDisplayString)(y.value.transactionHash),1),(0,n.createElementVNode)(`div`,re,[(0,n.createElementVNode)(`code`,ie,(0,n.toDisplayString)(z.value),1),(0,n.createElementVNode)(`button`,{onClick:Wt,class:`_cppay-state-copy-btn`,title:y.value.copyAddress},[...t[8]||=[(0,n.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},[(0,n.createElementVNode)(`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`}),(0,n.createElementVNode)(`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,ry:`1`})],-1)]],8,ae)])])):(0,n.createCommentVNode)(``,!0),R.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,oe,[(0,n.createElementVNode)(`div`,se,[(0,n.createElementVNode)(`span`,ce,(0,n.toDisplayString)(y.value.orderId),1),(0,n.createElementVNode)(`span`,le,(0,n.toDisplayString)(R.value.orderId),1)]),(0,n.createElementVNode)(`div`,ue,[(0,n.createElementVNode)(`span`,de,(0,n.toDisplayString)(h.plain===`subscription`?y.value.authorizationAmount:y.value.paymentAmount),1),(0,n.createElementVNode)(`span`,fe,(0,n.toDisplayString)(h.plain===`subscription`?`${G(R.value.approveAmount,W(D.value))} ${D.value}`:`${G(R.value.paymentAmount,W(D.value))} ${D.value}`),1)]),(0,n.createElementVNode)(`div`,pe,[(0,n.createElementVNode)(`span`,me,(0,n.toDisplayString)(y.value.paymentNetwork),1),(0,n.createElementVNode)(`span`,he,(0,n.toDisplayString)(R.value.paymentChain),1)]),(0,n.createElementVNode)(`div`,ge,[(0,n.createElementVNode)(`span`,_e,(0,n.toDisplayString)(y.value.paymentToken),1),(0,n.createElementVNode)(`span`,ve,(0,n.toDisplayString)(R.value.paymentToken),1)]),h.plain===`subscription`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,ye,[(0,n.createElementVNode)(`span`,be,(0,n.toDisplayString)(y.value.renewalInterval),1),(0,n.createElementVNode)(`span`,xe,(0,n.toDisplayString)(R.value.intervalDays)+` `+(0,n.toDisplayString)(y.value.days),1)])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,Se,[(0,n.createElementVNode)(`span`,Ce,(0,n.toDisplayString)(h.plain===`subscription`?y.value.subscriptionId:y.value.paymentId),1),(0,n.createElementVNode)(`span`,we,(0,n.toDisplayString)(h.plain===`subscription`?R.value.subscriptionId:R.value.paymentId),1)])])):(0,n.createCommentVNode)(``,!0)])]):x.value===`expired`?(0,n.renderSlot)(e.$slots,`expired`,{key:1},()=>[(0,n.createElementVNode)(`div`,Te,[t[10]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-expired-bg`},[(0,n.createElementVNode)(`div`,{class:`_cppay-state-expired-icon`},`⏰`)],-1),(0,n.createElementVNode)(`h3`,Ee,(0,n.toDisplayString)(y.value.paymentExpired),1),(0,n.createElementVNode)(`p`,De,(0,n.toDisplayString)(y.value.pleaseInitiatePaymentAgain),1),(0,n.createElementVNode)(`button`,{onClick:t[0]||=()=>{x.value=`select`,$()},disabled:S.value||C.value,class:`_cppay-btn _cppay-btn-primary _cppay-state-btn`},(0,n.toDisplayString)(y.value.returnButton),9,Oe)])]):x.value===`error`?(0,n.renderSlot)(e.$slots,`error`,{key:2},()=>[(0,n.createElementVNode)(`div`,ke,[t[11]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-error-bg`},[(0,n.createElementVNode)(`div`,{class:`_cppay-state-error-icon`},`!`)],-1),(0,n.createElementVNode)(`h3`,Ae,(0,n.toDisplayString)(w.value||y.value.error),1),(0,n.createElementVNode)(`p`,je,(0,n.toDisplayString)(y.value.checkStatusFailed),1),(0,n.createElementVNode)(`button`,{onClick:t[1]||=()=>{x.value=`select`,$()},disabled:S.value||C.value,class:`_cppay-btn _cppay-btn-primary _cppay-state-btn`},(0,n.toDisplayString)(y.value.returnButton),9,Me)])]):x.value===`failed`?(0,n.renderSlot)(e.$slots,`failed`,{key:3},()=>[(0,n.createElementVNode)(`div`,Ne,[t[12]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-failed-bg`},[(0,n.createElementVNode)(`div`,{class:`_cppay-state-failed-icon`},`✕`)],-1),(0,n.createElementVNode)(`h3`,Pe,(0,n.toDisplayString)(y.value.paymentFailed),1),(0,n.createElementVNode)(`p`,Fe,(0,n.toDisplayString)(y.value.pleaseInitiatePaymentAgain),1),(0,n.createElementVNode)(`button`,{onClick:t[2]||=()=>{x.value=`select`,$()},disabled:S.value||C.value,class:`_cppay-btn _cppay-btn-primary _cppay-state-btn`},(0,n.toDisplayString)(y.value.returnButton),9,Ie)])]):x.value===`select`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Le,[(0,n.renderSlot)(e.$slots,`choose-top`),(0,n.createElementVNode)(`div`,Re,[(0,n.createElementVNode)(`label`,ze,(0,n.toDisplayString)(y.value.paymentNetwork),1),(0,n.createElementVNode)(`div`,f,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(T.value,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.chain,onClick:t=>E.value=e.chain,class:(0,n.normalizeClass)([`_cppay-select-btn`,{"_cppay-selected":E.value===e.chain}])},[e.icon?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.chain},null,8,m)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.chain),1)],10,p))),128))])]),(0,n.createElementVNode)(`div`,Be,[(0,n.createElementVNode)(`label`,Ve,(0,n.toDisplayString)(y.value.paymentToken),1),(0,n.createElementVNode)(`div`,He,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(H.value,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.symbol,onClick:t=>D.value=e.symbol,class:(0,n.normalizeClass)([`_cppay-select-btn`,{"_cppay-selected":D.value===e.symbol}])},[e.icon?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.symbol},null,8,We)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.symbol),1)],10,Ue))),128))])]),(0,n.renderSlot)(e.$slots,`choose-bottom`),(0,n.createElementVNode)(`div`,Ge,[(0,n.createElementVNode)(`div`,Ke,[(0,n.createElementVNode)(`div`,qe,[(0,n.createElementVNode)(`span`,Je,(0,n.toDisplayString)(y.value.paymentAmount),1),(0,n.createElementVNode)(`div`,Ye,[(0,n.createElementVNode)(`div`,Xe,(0,n.toDisplayString)(J.value??`-`)+` `+(0,n.toDisplayString)(D.value??``),1),(0,n.createElementVNode)(`div`,Ze,`≈ $`+(0,n.toDisplayString)(h.amount),1)])])])]),(0,n.createElementVNode)(`div`,Qe,[w.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:0,class:`_cppay-error-tooltip-wrapper`,onMouseenter:t[3]||=e=>P.value=!0,onMouseleave:t[4]||=e=>P.value=!1},[(0,n.createElementVNode)(`div`,$e,[t[13]||=(0,n.createElementVNode)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`},[(0,n.createElementVNode)(`path`,{"fill-rule":`evenodd`,d:`M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z`,"clip-rule":`evenodd`})],-1),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(w.value),1)]),P.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,et,(0,n.toDisplayString)(w.value),1)):(0,n.createCommentVNode)(``,!0)],32)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`button`,{onClick:Ht,disabled:!E.value||!D.value||S.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(S.value?y.value.processing:y.value.continuePayment),9,tt)])])):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,nt,[(0,n.createElementVNode)(`div`,rt,[(0,n.createElementVNode)(`div`,it,[O.value?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:O.value,alt:`Payment QR Code`,class:`_cppay-qr-image`},null,8,at)):(0,n.createCommentVNode)(``,!0)])]),(0,n.createElementVNode)(`div`,ot,[U.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,st,[(0,n.createElementVNode)(`div`,ct,[(0,n.createElementVNode)(`div`,lt,[(0,n.createElementVNode)(`div`,ut,(0,n.toDisplayString)(h.plain===`subscription`?y.value.authorizationAmount:y.value.paymentAmount),1),(0,n.createElementVNode)(`div`,dt,[R.value?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,ft,(0,n.toDisplayString)(h.plain===`subscription`?`${G(R.value.approveAmount,W(U.value.symbol))} ${U.value.symbol}`:`${G(R.value.paymentAmount,W(U.value.symbol))} ${U.value.symbol}`),1)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,`≈ $`+(0,n.toDisplayString)(h.amount),1)])])])])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,pt,[(0,n.createElementVNode)(`div`,mt,[(0,n.createElementVNode)(`div`,ht,[(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(h.plain===`subscription`?y.value.authorizationContractAddress:y.value.paymentAddress),1),M.value?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,gt,`⏰ `+(0,n.toDisplayString)(M.value),1)):(0,n.createCommentVNode)(``,!0)]),(0,n.createElementVNode)(`div`,_t,[R.value?((0,n.openBlock)(),(0,n.createElementBlock)(`code`,vt,(0,n.toDisplayString)(h.plain===`subscription`?R.value.spenderAddress:R.value.receiveAddress),1)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`button`,{onClick:Ut,class:(0,n.normalizeClass)([`_cppay-copy-btn`,{"_cppay-copy-success":N.value}]),title:N.value?y.value.copied:y.value.copyAddress},[N.value?((0,n.openBlock)(),(0,n.createElementBlock)(`svg`,xt,[...t[15]||=[(0,n.createElementVNode)(`path`,{d:`M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z`},null,-1)]])):((0,n.openBlock)(),(0,n.createElementBlock)(`svg`,bt,[...t[14]||=[(0,n.createElementVNode)(`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`},null,-1),(0,n.createElementVNode)(`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,ry:`1`},null,-1)]]))],10,yt)])])]),h.plain===`subscription`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,St,[(0,n.createElementVNode)(`div`,Ct,(0,n.toDisplayString)(y.value.subscriptionNotice),1),(0,n.createElementVNode)(`div`,wt,(0,n.toDisplayString)(y.value.subscriptionNoticeMessage),1)])):(0,n.createCommentVNode)(``,!0)]),w.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:0,class:`_cppay-error-tooltip-wrapper`,onMouseenter:t[5]||=e=>P.value=!0,onMouseleave:t[6]||=e=>P.value=!1},[(0,n.createElementVNode)(`div`,Tt,[t[16]||=(0,n.createElementVNode)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`},[(0,n.createElementVNode)(`path`,{"fill-rule":`evenodd`,d:`M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z`,"clip-rule":`evenodd`})],-1),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(w.value),1)]),P.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Et,(0,n.toDisplayString)(w.value),1)):(0,n.createCommentVNode)(``,!0)],32)):(0,n.createCommentVNode)(``,!0),C.value?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Dt,[k.value?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:1},[(0,n.createElementVNode)(`button`,{onClick:Vt,disabled:S.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(S.value?h.plain===`subscription`?y.value.authorizing:y.value.processing:(h.plain,y.value.walletPay)),9,kt),(0,n.createElementVNode)(`button`,{onClick:B,disabled:S.value,class:`_cppay-btn _cppay-wallet-address-btn`,title:y.value.clickToModifyWallet},[(0,n.createElementVNode)(`span`,jt,(0,n.toDisplayString)(k.value.slice(0,10))+`...`+(0,n.toDisplayString)(k.value.slice(-4)),1),t[17]||=(0,n.createElementVNode)(`svg`,{class:`_cppay-wallet-arrow`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},[(0,n.createElementVNode)(`polyline`,{points:`6 9 12 15 18 9`})],-1)],8,At)],64)):((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:0,onClick:B,disabled:A.value,class:`_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn`},[(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(A.value?y.value.processing:y.value.connectWallet),1)],8,Ot))])),(0,n.createElementVNode)(`div`,Mt,[(0,n.createElementVNode)(`button`,{onClick:X,disabled:C.value,class:`_cppay-btn _cppay-btn-primary`},[C.value?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:0},[t[18]||=(0,n.createElementVNode)(`svg`,{class:`_cppay-spinner`,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`},[(0,n.createElementVNode)(`circle`,{cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,"stroke-width":`3`,"stroke-opacity":`0.25`}),(0,n.createElementVNode)(`path`,{d:`M12 2a10 10 0 0 1 10 10`,stroke:`currentColor`,"stroke-width":`3`,"stroke-linecap":`round`})],-1),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(y.value.checking),1)],64)):((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:1},[(0,n.createTextVNode)((0,n.toDisplayString)(y.value.completedPayment),1)],64))],8,Nt)]),t[19]||=(0,n.createElementVNode)(`hr`,{class:`_cppay-divider`},null,-1),(0,n.createElementVNode)(`div`,Pt,[(0,n.createElementVNode)(`button`,{onClick:t[7]||=()=>{x.value=`select`,$()},disabled:S.value||C.value,class:`_cppay-btn _cppay-btn-text`},(0,n.toDisplayString)(y.value.changePaymentMethod),9,Ft)])]))]))}}),g=h,_={class:`_cppay-dialog`},v={class:`_cppay-header`},y={class:`_cppay-title`},b=[`disabled`],x=(0,n.defineComponent)({__name:`PaymentDialog`,props:{modelValue:{type:Boolean},ott:{},apikey:{},orderId:{},amount:{},plain:{},intervalDays:{},locale:{}},emits:[`update:modelValue`,`success`,`expired`,`failed`,`error`],setup(t,{emit:r}){let i=t,a=r,o=(0,n.computed)(()=>e.t(i.locale)),s=(0,n.ref)(`select`),c=(0,n.computed)(()=>s.value!==`checking`);(0,n.watch)(()=>i.modelValue,e=>{e||(s.value=`select`)});let l=e=>{s.value=e};(0,n.onMounted)(()=>{let e=e=>{e.key===`Escape`&&i.modelValue&&!c.value&&u()};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}});let u=()=>{c.value&&a(`update:modelValue`,!1)},d=()=>{switch(s.value){case`success`:return o.value.paymentResult;case`expired`:return o.value.paymentExpired;case`failed`:return o.value.paymentFailed;case`error`:return o.value.error;case`payment`:return o.value.completePayment;default:return o.value.selectPaymentMethod}};return(e,r)=>t.modelValue?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:0,class:`_cppay-overlay`,onClick:r[4]||=e=>e.target===e.currentTarget&&u()},[(0,n.createElementVNode)(`div`,_,[(0,n.createElementVNode)(`div`,v,[(0,n.createElementVNode)(`h2`,y,(0,n.toDisplayString)(d()),1),(0,n.createElementVNode)(`button`,{onClick:u,disabled:!c.value,class:`_cppay-close-btn`},[...r[5]||=[(0,n.createElementVNode)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`},[(0,n.createElementVNode)(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M6 18L18 6M6 6l12 12`})],-1)]],8,b)]),t.modelValue?((0,n.openBlock)(),(0,n.createBlock)(g,{key:0,apikey:t.apikey,ott:t.ott,orderId:t.orderId,amount:t.amount,plain:t.plain,intervalDays:t.intervalDays,locale:t.locale,"onUpdate:paymentStep":l,onSuccess:r[0]||=e=>a(`success`,e),onExpired:r[1]||=e=>a(`expired`,e),onFailed:r[2]||=e=>a(`failed`,e),onError:r[3]||=e=>a(`error`,e)},{"choose-top":(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`choose-top`)]),"choose-bottom":(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`choose-bottom`)]),success:(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`success`)]),failed:(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`failed`)]),error:(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`error`)]),expired:(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`expired`)]),_:3},8,[`apikey`,`ott`,`orderId`,`amount`,`plain`,`intervalDays`,`locale`])):(0,n.createCommentVNode)(``,!0)])])):(0,n.createCommentVNode)(``,!0)}}),S=x,C=(0,n.ref)({open:!1,options:null});const w=e=>{C.value.options=e,C.value.open=!0},T=()=>{C.value.open=!1};var E=()=>{C.value.open=!1},D=e=>{C.value.options?.onSuccess?.(e)},O=e=>{C.value.options?.onExpired?.(e)},k=e=>{C.value.options?.onFailed?.(e)},A=e=>{C.value.options?.onError?.(e)};const j={install(e){e.config.globalProperties.$showPayment=w,e.config.globalProperties.$closePayment=T;let t=document.createElement(`div`);document.body.appendChild(t),(0,n.createApp)({setup(){return()=>C.value.options?(0,n.h)(S,{modelValue:C.value.open,"onUpdate:modelValue":e=>{C.value.open=e,e||E()},...C.value.options,onSuccess:D,onExpired:O,onFailed:k,onError:A}):null}}).mount(t)}},M=()=>({showPayment:w,closePayment:T});e.n(e.r),exports.CppayPlugin=j,exports.PaymentContent=g,exports.PaymentDialog=S,exports.showPayment=w,exports.useCppayPayment=M;
package/dist/vue.d.ts CHANGED
@@ -1,23 +1,196 @@
1
- import { ComponentOptionsMixin } from 'vue';
2
- import { ComponentProvideOptions } from 'vue';
3
- import { DefineComponent } from 'vue';
4
- import { PublicProps } from 'vue';
1
+ import { ComponentOptionsMixin } from '../../vue/dist/vue.esm-bundler.js';
2
+ import { ComponentProvideOptions } from '../../vue/dist/vue.esm-bundler.js';
3
+ import { DefineComponent } from '../../vue/dist/vue.esm-bundler.js';
4
+ import { Plugin as Plugin_2 } from '../../vue/dist/vue.esm-bundler.js';
5
+ import { PublicProps } from '../../vue/dist/vue.esm-bundler.js';
5
6
 
6
- export declare const PaymentDialog: DefineComponent<Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {} & {
7
+ declare const __VLS_component: DefineComponent<PaymentDialogProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {} & {
8
+ success: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
9
+ failed: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
10
+ expired: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
7
11
  error: (error: Error) => any;
8
12
  "update:modelValue": (value: boolean) => any;
9
- success: (paymentId: string) => any;
10
- }, string, PublicProps, Readonly<Props> & Readonly<{
13
+ }, string, PublicProps, Readonly<PaymentDialogProps> & Readonly<{
14
+ onSuccess?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
15
+ onFailed?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
16
+ onExpired?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
11
17
  onError?: ((error: Error) => any) | undefined;
12
18
  "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
13
- onSuccess?: ((paymentId: string) => any) | undefined;
14
19
  }>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
15
20
 
16
- declare interface Props {
21
+ declare const __VLS_component_2: DefineComponent<Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {} & {
22
+ success: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
23
+ failed: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
24
+ expired: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
25
+ error: (error: Error) => any;
26
+ "update:paymentStep": (value: PaymentStep) => any;
27
+ }, string, PublicProps, Readonly<Props> & Readonly<{
28
+ onSuccess?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
29
+ onFailed?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
30
+ onExpired?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
31
+ onError?: ((error: Error) => any) | undefined;
32
+ "onUpdate:paymentStep"?: ((value: PaymentStep) => any) | undefined;
33
+ }>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
34
+
35
+ declare function __VLS_template(): {
36
+ attrs: Partial<{}>;
37
+ slots: {
38
+ 'choose-top'?(_: {}): any;
39
+ 'choose-bottom'?(_: {}): any;
40
+ success?(_: {}): any;
41
+ failed?(_: {}): any;
42
+ error?(_: {}): any;
43
+ expired?(_: {}): any;
44
+ };
45
+ refs: {};
46
+ rootEl: any;
47
+ };
48
+
49
+ declare function __VLS_template_2(): {
50
+ attrs: Partial<{}>;
51
+ slots: {
52
+ success?(_: {}): any;
53
+ expired?(_: {}): any;
54
+ error?(_: {}): any;
55
+ failed?(_: {}): any;
56
+ 'choose-top'?(_: {}): any;
57
+ 'choose-bottom'?(_: {}): any;
58
+ };
59
+ refs: {};
60
+ rootEl: HTMLDivElement;
61
+ };
62
+
63
+ declare type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
64
+
65
+ declare type __VLS_TemplateResult_2 = ReturnType<typeof __VLS_template_2>;
66
+
67
+ declare type __VLS_WithTemplateSlots<T, S> = T & {
68
+ new (): {
69
+ $slots: S;
70
+ };
71
+ };
72
+
73
+ declare type __VLS_WithTemplateSlots_2<T, S> = T & {
74
+ new (): {
75
+ $slots: S;
76
+ };
77
+ };
78
+
79
+ declare type Address = `0x${string}`;
80
+
81
+ export declare const CppayPlugin: Plugin_2;
82
+
83
+ export declare type Locale = "zh-CN" | "en-US";
84
+
85
+ declare type Numberic = `${number}.${number}` | `${number}`;
86
+
87
+ declare interface OnetimePaymentOrderStatus {
88
+ orderId: string;
89
+ paymentId: string;
90
+ chain: string;
91
+ token: string;
92
+ baseAmount: Numberic;
93
+ payAmount: Numberic;
94
+ receiveAddress: Address;
95
+ expireAt: number;
96
+ status: PaymentStatus;
97
+ }
98
+
99
+ export declare const PaymentContent: __VLS_WithTemplateSlots_2<typeof __VLS_component_2, __VLS_TemplateResult_2["slots"]>;
100
+
101
+ export declare const PaymentDialog: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
102
+
103
+ declare interface PaymentDialogProps {
17
104
  modelValue: boolean;
18
- apiKey: string;
105
+ ott?: string;
106
+ apikey?: string;
107
+ orderId: string;
108
+ amount: string;
109
+ plain: PaymentPlain;
110
+ intervalDays?: number;
111
+ locale?: Locale;
112
+ }
113
+
114
+ /**
115
+ * 支付选项配置
116
+ */
117
+ declare type PaymentOptions_2 = Omit<PaymentDialogProps, "modelValue"> & {
118
+ /** 支付成功回调 */
119
+ onSuccess?: (order: SubscriptionPaymentOrderStatus | OnetimePaymentOrderStatus) => void;
120
+ /** 支付错误回调 */
121
+ onError?: (error: Error) => void;
122
+ /** 支付过期回调 */
123
+ onExpired?: (order: SubscriptionPaymentOrderStatus | OnetimePaymentOrderStatus) => void;
124
+ /** 支付失败回调 */
125
+ onFailed?: (order: SubscriptionPaymentOrderStatus | OnetimePaymentOrderStatus) => void;
126
+ };
127
+
128
+ declare type PaymentPlain = "instant" | "subscription" | "x402";
129
+
130
+ declare type PaymentStatus = "pending" | "paid" | "expired" | "failed";
131
+
132
+ declare type PaymentStep = "select" | "payment" | "checking" | "success" | "failed" | "expired" | "error";
133
+
134
+ declare interface Props {
135
+ /** API Key */
136
+ apikey?: string;
137
+ /** One-Time Token */
138
+ ott?: string;
139
+ /** 订单 ID */
19
140
  orderId: string;
141
+ /** 支付金额(USD) */
20
142
  amount: string;
143
+ /** 支付类型 */
144
+ plain: PaymentPlain;
145
+ /** 订阅间隔天数 */
146
+ intervalDays?: number;
147
+ /** 备注信息 */
148
+ remark?: string;
149
+ /** 插槽 */
150
+ slots?: any;
151
+ /** 语言设置 */
152
+ locale?: Locale;
21
153
  }
22
154
 
155
+ /**
156
+ * 显示支付对话框
157
+ */
158
+ export declare const showPayment: (options: PaymentOptions_2) => void;
159
+
160
+ declare interface SubscriptionPaymentOrderStatus {
161
+ orderId: string;
162
+ subscriptionId: string;
163
+ chain: string;
164
+ token: string;
165
+ approvedAddress: string;
166
+ txHash: string;
167
+ approveAmount: string;
168
+ amountOfUsd: string;
169
+ expireAt: number;
170
+ status: SubscriptionPaymentStatus;
171
+ }
172
+
173
+ declare type SubscriptionPaymentStatus = "pending" | "approved" | "expired" | "failed";
174
+
175
+ /**
176
+ * 使用 CPPay 支付钩子(Vue Composable)
177
+ * @throws {Error} 如果在 CppayPlugin 安装之前使用会抛出错误
178
+ */
179
+ export declare const useCppayPayment: () => {
180
+ /** 显示支付对话框 */
181
+ showPayment: (options: PaymentOptions_2) => void;
182
+ /** 关闭支付对话框 */
183
+ closePayment: () => void;
184
+ };
185
+
23
186
  export { }
187
+
188
+
189
+ declare module "@vue/runtime-core" {
190
+ interface ComponentCustomProperties {
191
+ /** 显示支付对话框的全局方法 */
192
+ $showPayment: typeof showPayment;
193
+ /** 关闭支付对话框的全局方法 */
194
+ $closePayment: typeof closePayment;
195
+ }
196
+ }