cppay-sdk 0.0.2-beta.37 → 0.0.2-beta.39

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.
@@ -1 +1 @@
1
- const e={Ethereum:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png`,BSC:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,"bsc-testnet":`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,Tron:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png`,Polygon:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/polygon/info/logo.png`,Solana:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png`},t={USDT:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png`,USDC:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png`,ETH:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png`,BNB:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,tBNB:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,TRX:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png`,SOL:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png`};var n=`http://192.168.0.163:8000`,r=async(e,t,r)=>{let i=Object.assign({timeout:15e3},r),a=new AbortController,o=setTimeout(()=>a.abort(),i.timeout);try{let r=await fetch(new URL(e,n),{signal:a.signal,...t});clearTimeout(o);let i=r.headers.get(`Content-Type`)??``;if(i.includes(`json`))return await r.json();try{return await r.json()}catch{throw Error(`URL: ${e}, Unsupport Content Type: ${i}`)}}catch(t){throw clearTimeout(o),t instanceof DOMException&&t.name===`AbortError`?Error(`URL: ${e}, Request timeout after ${i.timeout}ms`):t}},i=0,a=async(e,t)=>{let n=new URLSearchParams(t.params),a=await r(`${t.url}${n.size?`?${n.toString()}`:``}`,{method:t.method??`get`,headers:{Authorization:e,...t.headers},body:t.data?JSON.stringify(t.data):void 0});if(a.code!==i)throw Error(`Request ${t.url} Failed. ${a.message}`);return a.data},o=class{authorization;constructor(e,t){this.authorization=e?`ApiKey ${e}`:`OTT ${t}`}async getSupportedChains(){return(await a(this.authorization,{url:`/api/payment/token`})).map(e=>({chain:e.chain,chainId:e.chain_id,tokenSymbol:e.token_symbol,tokenDecimals:e.token_decimals,tokenAddress:e.token_address,tokenPrice:e.token_price}))}async createOnetimePayment(e,t,n,r){let i={chain:e,token:t,order_no:n,amount:r},o=await a(this.authorization,{url:`/api/payment/create`,method:`post`,data:i});return{paymentId:o.payment_id,paymentAmount:o.pay_amount,receiveAddress:o.receive_address,expireAt:o.expire_at}}async createSubscriptionPayment(e,t,n,r,i){let o={chain:e,token:t,order_no:n,amount_usd:r,renewal_days:i},s=await a(this.authorization,{url:`/api/subscription/create`,method:`post`,data:o});return{subscriptionId:s.subscription_id,approveAmount:s.approved_amount,spenderAddress:s.contract_address,expireAt:s.expire_at}}async createX402Payment(){throw Error(`Unsupported payment mode`)}async checkOnetimePaymentStatus(e){let t=`orderId`in e?{order_no:e.orderId}:{payment_id:e.paymentId},n=await a(this.authorization,{url:`/api/payment/query`,params:t});return{orderId:n.order_no,paymentId:n.payment_id,chain:n.chain,token:n.token,baseAmount:n.base_amount,payAmount:n.pay_amount,receiveAddress:n.receive_address,expireAt:n.expire_at,status:n.status}}async checkSubcriptionPaymentStatus(e){let t=`orderId`in e?{order_no:e.orderId}:{subscription_id:e.subscriptionId},n=await a(this.authorization,{url:`/api/subscription/query`,params:t});return{orderId:n.order_no,subscriptionId:n.subscription_id,chain:n.chain,token:n.token,approvedAddress:n.approved_contract_address,txHash:n.approved_tx_hash,approveAmount:n.approved_amount,amountOfUsd:n.amount_usd,expireAt:n.expire_at,status:n.subscription_status}}async getSubcriptionPayments(e){let t={subscription_id:e},n=await a(this.authorization,{url:`/api/subscription/payments`,params:t});return{total:n.total,payments:(n.payments??[]).map(e=>({orderId:e.order_no,subscriptionId:e.subscription_id,chain:e.chain,token:e.token,txHash:e.tx_hash,payAmount:e.pay_amount,receiveAddress:e.receive_address,status:e.status,errorMessage:e.error_message}))}}async checkX402PaymentStatus(){throw Error(`Unsupported payment mode`)}},s=class{api;constructor(e,t){this.api=new o(e,t)}async getSupportedChains(){let n=(await this.api.getSupportedChains()).reduce((n,r)=>{let i=n[r.chain]??{chain:r.chain,chainId:r.chainId,tokens:[],icon:e[r.chain]};return i.tokens.push({symbol:r.tokenSymbol,decimals:r.tokenDecimals,address:r.tokenAddress,icon:t[r.tokenSymbol],price:r.tokenPrice}),n[r.chain]=i,n},{});return Object.values(n)}async createPayment(e,t){switch(e){case`instant`:return this.createOnetimePayment(t);case`subscription`:return this.createSubscriptionPayment(t)}}async checkPaymentStatus(e,t){switch(e){case`instant`:return this.checkOnetimePaymentStatus(t);case`subscription`:return this.checkSubscriptionPaymentStatus(t)}}async createOnetimePayment(e){let t=await this.api.createOnetimePayment(e.paymentChain,e.paymentToken,e.orderId,e.amount);return{...e,...t}}async createSubscriptionPayment(e){let t=await this.api.createSubscriptionPayment(e.paymentChain,e.paymentToken,e.orderId,e.amountOfUsd,e.intervalDays);return{...e,...t}}async checkOnetimePaymentStatus(e){return{...await this.api.checkOnetimePaymentStatus(e)}}async checkSubscriptionPaymentStatus(e){return{...await this.api.checkSubcriptionPaymentStatus(e)}}},c=s;Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return c}});
1
+ const e={Ethereum:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png`,BSC:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,"bsc-testnet":`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,Tron:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png`,Polygon:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/polygon/info/logo.png`,Solana:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png`},t={USDT:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png`,USDC:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png`,ETH:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png`,BNB:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,tBNB:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,TRX:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png`,SOL:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png`};var n=`http://192.168.0.162:8000`,r=async(e,t,r)=>{let i=Object.assign({timeout:15e3},r),a=new AbortController,o=setTimeout(()=>a.abort(),i.timeout);try{let r=await fetch(new URL(e,n),{signal:a.signal,...t});clearTimeout(o);let i=r.headers.get(`Content-Type`)??``;if(i.includes(`json`))return await r.json();try{return await r.json()}catch{throw Error(`URL: ${e}, Unsupport Content Type: ${i}`)}}catch(t){throw clearTimeout(o),t instanceof DOMException&&t.name===`AbortError`?Error(`URL: ${e}, Request timeout after ${i.timeout}ms`):t}},i=0,a=async(e,t)=>{let n=new URLSearchParams(t.params),a=await r(`${t.url}${n.size?`?${n.toString()}`:``}`,{method:t.method??`get`,headers:{Authorization:e,...t.headers},body:t.data?JSON.stringify(t.data):void 0});if(a.code!==i)throw Error(`Request ${t.url} Failed. ${a.message}`);return a.data},o=class{authorization;constructor(e,t){this.authorization=e?`ApiKey ${e}`:`OTT ${t}`}async getSupportedChains(){return(await a(this.authorization,{url:`/api/payment/token`})).map(e=>({chain:e.chain,chainId:e.chain_id,tokenSymbol:e.token_symbol,tokenDecimals:e.token_decimals,tokenAddress:e.token_address,tokenPrice:e.token_price}))}async createOnetimePayment(e,t,n,r){let i={chain:e,token:t,order_no:n,amount:r},o=await a(this.authorization,{url:`/api/payment/create`,method:`post`,data:i});return{paymentId:o.payment_id,paymentAmount:o.pay_amount,receiveAddress:o.receive_address,expireAt:o.expire_at}}async createSubscriptionPayment(e,t,n,r,i){let o={chain:e,token:t,order_no:n,amount_usd:r,renewal_days:i},s=await a(this.authorization,{url:`/api/subscription/create`,method:`post`,data:o});return{subscriptionId:s.subscription_id,approveAmount:s.approved_amount,spenderAddress:s.contract_address,expireAt:s.expire_at}}async createX402Payment(){throw Error(`Unsupported payment mode`)}async checkOnetimePaymentStatus(e){let t=`orderId`in e?{order_no:e.orderId}:{payment_id:e.paymentId},n=await a(this.authorization,{url:`/api/payment/query`,params:t});return{orderId:n.order_no,paymentId:n.payment_id,chain:n.chain,token:n.token,baseAmount:n.base_amount,payAmount:n.pay_amount,receiveAddress:n.receive_address,expireAt:n.expire_at,status:n.status}}async checkSubcriptionPaymentStatus(e){let t=`orderId`in e?{order_no:e.orderId}:{subscription_id:e.subscriptionId},n=await a(this.authorization,{url:`/api/subscription/query`,params:t});return{orderId:n.order_no,subscriptionId:n.subscription_id,chain:n.chain,token:n.token,approvedAddress:n.approved_contract_address,txHash:n.approved_tx_hash,approveAmount:n.approved_amount,amountOfUsd:n.amount_usd,expireAt:n.expire_at,status:n.subscription_status}}async getSubcriptionPayments(e){let t={subscription_id:e},n=await a(this.authorization,{url:`/api/subscription/payments`,params:t});return{total:n.total,payments:(n.payments??[]).map(e=>({orderId:e.order_no,subscriptionId:e.subscription_id,chain:e.chain,token:e.token,txHash:e.tx_hash,payAmount:e.pay_amount,receiveAddress:e.receive_address,status:e.status,errorMessage:e.error_message}))}}async checkX402PaymentStatus(){throw Error(`Unsupported payment mode`)}},s=class{api;constructor(e,t){this.api=new o(e,t)}async getSupportedChains(){let n=(await this.api.getSupportedChains()).reduce((n,r)=>{let i=n[r.chain]??{chain:r.chain,chainId:r.chainId,tokens:[],icon:e[r.chain]};return i.tokens.push({symbol:r.tokenSymbol,decimals:r.tokenDecimals,address:r.tokenAddress,icon:t[r.tokenSymbol],price:r.tokenPrice}),n[r.chain]=i,n},{});return Object.values(n)}async createPayment(e,t){switch(e){case`instant`:return this.createOnetimePayment(t);case`subscription`:return this.createSubscriptionPayment(t)}}async checkPaymentStatus(e,t){switch(e){case`instant`:return this.checkOnetimePaymentStatus(t);case`subscription`:return this.checkSubscriptionPaymentStatus(t)}}async createOnetimePayment(e){let t=await this.api.createOnetimePayment(e.paymentChain,e.paymentToken,e.orderId,e.amount);return{...e,...t}}async createSubscriptionPayment(e){let t=await this.api.createSubscriptionPayment(e.paymentChain,e.paymentToken,e.orderId,e.amountOfUsd,e.intervalDays);return{...e,...t}}async checkOnetimePaymentStatus(e){return{...await this.api.checkOnetimePaymentStatus(e)}}async checkSubscriptionPaymentStatus(e){return{...await this.api.checkSubcriptionPaymentStatus(e)}}},c=s;Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return c}});
@@ -14,7 +14,7 @@ const CHAIN_ICONS = {
14
14
  TRX: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png",
15
15
  SOL: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png"
16
16
  };
17
- var BASE_URL = "http://192.168.0.163:8000", request = async (e, t, r) => {
17
+ var BASE_URL = "http://192.168.0.162:8000", request = async (e, t, r) => {
18
18
  let i = Object.assign({ timeout: 15e3 }, r), a = new AbortController(), o = setTimeout(() => a.abort(), i.timeout);
19
19
  try {
20
20
  let r = await fetch(new URL(e, BASE_URL), {
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- const e=require(`./cppay-B52ulQGn.cjs`);exports.CHAIN_ICONS=e.n,exports.Cppay=e.t,exports.TOKEN_ICONS=e.r;
1
+ const e=require(`./cppay-UdGae-e8.cjs`);exports.CHAIN_ICONS=e.n,exports.Cppay=e.t,exports.TOKEN_ICONS=e.r;
package/dist/index.d.ts CHANGED
@@ -150,6 +150,8 @@ export declare type PaymentPlain = "instant" | "subscription" | "x402";
150
150
 
151
151
  export declare type PaymentStatus = "pending" | "paid" | "expired" | "failed";
152
152
 
153
+ export declare type PaymentStep = "select" | "payment" | "checking" | "success" | "failed" | "expired" | "error";
154
+
153
155
  export declare interface SubscriptionPayment {
154
156
  orderId: string;
155
157
  subscriptionId: string;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as CHAIN_ICONS, r as TOKEN_ICONS, t as cppay_default } from "./cppay-J9nBy01A.js";
1
+ import { n as CHAIN_ICONS, r as TOKEN_ICONS, t as cppay_default } from "./cppay-jU20-wmK.js";
2
2
  export { CHAIN_ICONS, cppay_default as Cppay, TOKEN_ICONS };
package/dist/react.cjs CHANGED
@@ -1 +1 @@
1
- const e=require(`./locales-DfK0OLJI.cjs`),t=require(`./cppay-B52ulQGn.cjs`);let n=require(`qrcode`);n=e.i(n);let r=require(`rxjs`),i=require(`rxjs/operators`),a=require(`viem`),o=require(`viem/chains`),s=require(`@reown/appkit`),c=require(`@reown/appkit-adapter-ethers`),l=require(`react`);l=e.i(l);let u=require(`react/jsx-runtime`);var d=({apikey:d,ott:f,plain:p,orderId:m,amount:h,intervalDays:g,locale:_,onSuccess:v,onExpired:y,onFailed:b,onError:x,Slots:S,onPaymentStepChange:ee})=>{let C=(0,l.useMemo)(()=>new t.t(d,f),[d,f]),w=(0,l.useMemo)(()=>e.t(_),[_]),[T,E]=(0,l.useState)(`select`),D=(0,l.useMemo)(()=>T===`checking`,[T]),[O,k]=(0,l.useState)(!1),[A,j]=(0,l.useState)(),[M,te]=(0,l.useState)([]),[N,P]=(0,l.useState)(),[F,ne]=(0,l.useState)(),[re,ie]=(0,l.useState)(),[I,L]=(0,l.useState)(),[ae,oe]=(0,l.useState)(!1),[R,z]=(0,l.useState)(),[se,ce]=(0,l.useState)(``),[B,le]=(0,l.useState)(!1),[ue,V]=(0,l.useState)(!1),H=(0,l.useRef)(null),U=(0,l.useRef)(null),W=(0,l.useRef)(null),G=(0,l.useRef)(null);(0,l.useEffect)(()=>{typeof window<`u`&&!H.current&&(H.current=(0,s.createAppKit)({debug:!1,enableNetworkSwitch:!1,adapters:[new c.EthersAdapter],projectId:`8d2e1854d3f1782e45aa15fbd8938894`,allowUnsupportedChain:!0,networks:[o.mainnet,o.bsc,o.polygon,o.arbitrum,o.optimism,o.base],metadata:{name:`Cppay`,description:`Cppay Payment Gateway`,url:window.location.origin,icons:[`https://cppay.com/icon.png`]},features:{analytics:!1}}),L(H.current.getAddress()),z(H.current.getProvider(`eip155`)),H.current.subscribeAccount(e=>{e.isConnected?L(e.address):(L(void 0),z(void 0))}),H.current.subscribeProviders(e=>{let t=e?.eip155;z(t)}))},[]),(0,l.useEffect)(()=>{ee?.(T)},[T]);let de=async()=>{try{oe(!0),j(void 0),H.current&&await H.current.open()}catch(e){console.error(`钱包连接失败:`,e),j(e instanceof Error?e.message:w.walletConnectionFailed),x?.(e)}finally{oe(!1)}},K=(0,l.useMemo)(()=>M.find(e=>e.chain===N),[M,N]),q=(0,l.useMemo)(()=>K?.tokens||[],[K]),J=(0,l.useMemo)(()=>q.find(e=>e.symbol===F),[q,F]),Y=e=>[`USDT`,`USDC`,`BUSD`,`DAI`,`TUSD`,`USDD`,`FDUSD`].includes(e.toUpperCase())?2:6,X=(e,t)=>{let n=parseFloat(e);return isNaN(n)?`0`:n.toFixed(t).replace(/\.?0+$/,``)},fe=e=>{if(e<=0)return w.expired;let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=e%60;return t>0?`${t}${w.hours}${n}${w.minutes}${r}${w.seconds}`:`${n}${w.minutes}${r}${w.seconds}`},pe=e=>{W.current&&clearInterval(W.current);let t=()=>{if(T===`checking`){Z();return}let t=e-Math.floor(Date.now()/1e3);ce(fe(t)),t<=0&&(E(`expired`),Z())};t(),W.current=setInterval(t,1e3)},Z=()=>{W.current&&=(clearInterval(W.current),null)},Q=(0,l.useMemo)(()=>{if(!F||!J)return`0`;let e=parseFloat(J.price);if(isNaN(e)||e===0)return`0`;let t=Y(F);return X((parseFloat(h)/e).toFixed(t),t)},[h,F,J]),me=async()=>{try{k(!0),j(void 0);let e=await C.getSupportedChains();te(e),e.length>0&&P(e[0].chain)}catch(e){j(e instanceof Error?e.message:w.loadPaymentNetworkFailed),x?.(e)}finally{k(!1)}},he=async e=>{if(R)try{await R.request({method:`wallet_switchEthereumChain`,params:[{chainId:`0x${e.toString(16)}`}]})}catch(e){throw e.code===4902?Error(w.pleaseAddNetwork):e}},ge=async()=>{if(!(!I||!R||!G.current||!J||!K))try{k(!0);let e=G.current;await he(K.chainId);let t=(0,a.createWalletClient)({account:I,transport:(0,a.custom)(R)});if(J.address){let n=await t.writeContract({address:J.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,a.parseUnits)(e.paymentAmount,J.decimals)],chain:null});console.log(`转账交易哈希:`,n)}else{let n=await t.sendTransaction({to:e.receiveAddress,value:(0,a.parseUnits)(e.paymentAmount,J.decimals),chain:null});console.log(`转账交易哈希:`,n)}k(!1),E(`checking`)}catch(e){console.error(`钱包支付失败:`,e),j(e instanceof Error?e.message:w.walletPaymentFailed),x?.(e),k(!1)}},_e=async()=>{if(!(!I||!R||!G.current||!J||!K))try{k(!0);let e=G.current;await he(K.chainId);let t=(0,a.createWalletClient)({account:I,transport:(0,a.custom)(R)});if(!J.address)throw Error(w.subscriptionDoesNotSupportNative);let n=await t.writeContract({address:J.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,a.parseUnits)(e.approveAmount,J.decimals)],chain:null});console.log(`授权交易哈希:`,n),k(!1),E(`checking`)}catch(e){console.error(`钱包授权失败:`,e),j(e instanceof Error?e.message:w.walletPaymentFailed),x?.(e),k(!1)}},ve=async()=>{if(!I){let e=w.pleaseConnectWallet;j(e),x?.(Error(e));return}p===`instant`?await ge():p===`subscription`&&await _e()},ye=async()=>{if(!(!N||!F))try{k(!0),j(void 0);let e=``;p===`instant`?(G.current=await C.createOnetimePayment({paymentChain:N,paymentToken:F,orderId:m,amount:Q}),e=`${N.toLowerCase()}:${G.current.receiveAddress}?amount=${G.current.paymentAmount}`,pe(G.current.expireAt),$({paymentId:G.current.paymentId})):p===`subscription`&&(G.current=await C.createSubscriptionPayment({paymentChain:N,paymentToken:F,orderId:m,amountOfUsd:Q,intervalDays:g||30}),e=`${N.toLowerCase()}:${G.current.spenderAddress}?amount=${G.current.approveAmount}`,pe(G.current.expireAt),$({subscriptionId:G.current.subscriptionId})),E(`payment`),ie(await n.toDataURL(e,{width:200,margin:2,errorCorrectionLevel:`H`}))}catch(e){j(e instanceof Error?e.message:w.createPaymentFailed),x?.(e)}finally{k(!1)}},be=()=>{G.current&&(E(`checking`),j(void 0))},$=e=>{U.current?.unsubscribe();let t=()=>(0,r.defer)(()=>p===`subscription`?C.checkSubscriptionPaymentStatus(e):C.checkOnetimePaymentStatus(e)).pipe((0,i.timeout)(15e3),(0,i.retry)({delay:2e3}));U.current=t().pipe((0,i.expand)(e=>e.status===`pending`?(0,r.timer)(2e3).pipe((0,i.switchMap)(()=>t())):r.EMPTY),(0,i.tap)(e=>{(e.status===`paid`||e.status===`approved`)&&(E(`success`),v?.(e)),e.status===`expired`&&(E(`expired`),y?.(e)),e.status===`failed`&&(E(`failed`),b?.(e))})).subscribe({error:e=>{if(G.current){let t=e instanceof Error?e.message:w.checkPaymentStatusFailed;E(`error`),j(t),x?.(e)}},complete:()=>{U.current?.unsubscribe()}})};return(0,l.useEffect)(()=>{M.length===0&&me()},[]),(0,l.useEffect)(()=>{q.length>0&&ne(q[0].symbol)},[q]),(0,l.useEffect)(()=>(m&&$({orderId:m}),()=>{U.current?.unsubscribe(),Z()}),[m]),(0,u.jsx)(`div`,{className:`_cppay-content`,children:T===`success`?(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`✅`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:p===`subscription`?w.authorizationSuccess:w.paymentSuccess}),(0,u.jsx)(`p`,{className:`_cppay-state-message`,children:p===`subscription`?w.subscriptionActivated:w.transactionCompleted})]}):T===`expired`?(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`⏰`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:w.paymentExpired}),(0,u.jsx)(`button`,{onClick:()=>E(`select`),disabled:O||D,className:`_cppay-btn _cppay-btn-text`,children:w.returnButton})]}):T===`error`?(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`❌`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:A||w.error})]}):T===`failed`?(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`❌`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:w.paymentFailed})]}):T===`select`?(0,u.jsxs)(`div`,{children:[S?.ChooseTop,(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[(0,u.jsx)(`label`,{className:`_cppay-label`,children:w.paymentNetwork}),(0,u.jsx)(`div`,{className:`_cppay-grid`,children:M.map(e=>(0,u.jsxs)(`button`,{onClick:()=>P(e.chain),className:`_cppay-select-btn ${N===e.chain?`_cppay-selected`:``}`,children:[e.icon&&(0,u.jsx)(`img`,{src:e.icon,alt:e.chain}),(0,u.jsx)(`span`,{children:e.chain})]},e.chain))})]}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[(0,u.jsx)(`label`,{className:`_cppay-label`,children:w.paymentToken}),(0,u.jsx)(`div`,{className:`_cppay-grid`,children:q.map(e=>(0,u.jsxs)(`button`,{onClick:()=>ne(e.symbol),className:`_cppay-select-btn ${F===e.symbol?`_cppay-selected`:``}`,children:[e.icon&&(0,u.jsx)(`img`,{src:e.icon,alt:e.symbol}),(0,u.jsx)(`span`,{children:e.symbol})]},e.symbol))})]}),S?.ChooseBottom,(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`div`,{className:`_cppay-price-box`,children:(0,u.jsxs)(`div`,{className:`_cppay-price-row`,children:[(0,u.jsx)(`span`,{className:`_cppay-price-label`,children:w.paymentAmount}),(0,u.jsxs)(`div`,{className:`_cppay-price-amount`,children:[(0,u.jsxs)(`div`,{className:`_cppay-price-main`,children:[Q??`-`,` `,F??``]}),(0,u.jsxs)(`div`,{className:`_cppay-price-sub`,children:[`≈ $`,h]})]})]})})}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[A&&(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip-wrapper`,onMouseEnter:()=>V(!0),onMouseLeave:()=>V(!1),children:[(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip`,children:[(0,u.jsx)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,u.jsx)(`path`,{fillRule:`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`,clipRule:`evenodd`})}),(0,u.jsx)(`span`,{children:A})]}),ue&&(0,u.jsx)(`div`,{className:`_cppay-error-tooltip-full`,children:A})]}),(0,u.jsx)(`button`,{onClick:ye,disabled:!N||!F||O,className:`_cppay-btn _cppay-btn-primary`,children:O?w.processing:w.continuePayment})]})]}):(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`_cppay-qr-container`,children:(0,u.jsx)(`div`,{className:`_cppay-qr-code`,children:re&&(0,u.jsx)(`img`,{src:re,alt:`Payment QR Code`,className:`_cppay-qr-image`})})}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[J&&(0,u.jsx)(`div`,{className:`_cppay-info-box`,children:(0,u.jsx)(`div`,{className:`_cppay-info-flex-container`,children:(0,u.jsxs)(`div`,{className:`_cppay-info-flex-child`,children:[(0,u.jsx)(`div`,{className:`_cppay-info-label`,children:p===`subscription`?w.authorizationAmount:w.paymentAmount}),(0,u.jsxs)(`div`,{className:`_cppay-info-value _cppay-info-value-flex`,children:[(0,u.jsx)(`span`,{children:p===`subscription`?`${X(G.current.approveAmount,Y(J.symbol))} ${J.symbol}`:`${X(G.current.paymentAmount,Y(J.symbol))} ${J.symbol}`}),(0,u.jsxs)(`span`,{children:[`≈ $`,h]})]})]})})}),(0,u.jsx)(`div`,{className:`_cppay-info-box`,children:(0,u.jsxs)(`div`,{className:`_cppay-info-flex-child`,children:[(0,u.jsxs)(`div`,{className:`_cppay-info-label _cppay-info-label-flex`,children:[(0,u.jsx)(`span`,{children:p===`subscription`?w.authorizationContractAddress:w.paymentAddress}),se&&(0,u.jsxs)(`span`,{className:`_cppay-countdown`,children:[`⏰ `,se]})]}),(0,u.jsxs)(`div`,{className:`_cppay-address-row`,children:[(0,u.jsx)(`code`,{children:p===`subscription`?G.current.spenderAddress:G.current.receiveAddress}),(0,u.jsx)(`button`,{onClick:async()=>{if(!G.current)return;let e=p===`subscription`?G.current.spenderAddress:G.current.receiveAddress;if(e)try{await navigator.clipboard.writeText(e),le(!0),setTimeout(()=>{le(!1)},2e3)}catch(e){console.error(`复制失败:`,e)}},className:`_cppay-copy-btn ${B?`_cppay-copy-success`:``}`,title:B?w.copied:w.copyAddress,children:B?(0,u.jsx)(`svg`,{className:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,u.jsx)(`path`,{d:`M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z`})}):(0,u.jsxs)(`svg`,{className:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,u.jsx)(`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,u.jsx)(`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,ry:`1`})]})})]})]})}),p===`subscription`&&(0,u.jsxs)(`div`,{className:`_cppay-info-box _cppay-subscription-box`,children:[(0,u.jsx)(`div`,{className:`_cppay-info-label _cppay-subscription-label`,children:w.subscriptionNotice}),(0,u.jsx)(`div`,{className:`_cppay-info-value _cppay-subscription-message`,children:w.subscriptionNoticeMessage})]})]}),A&&(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip-wrapper`,onMouseEnter:()=>V(!0),onMouseLeave:()=>V(!1),children:[(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip`,children:[(0,u.jsx)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,u.jsx)(`path`,{fillRule:`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`,clipRule:`evenodd`})}),(0,u.jsx)(`span`,{children:A})]}),ue&&(0,u.jsx)(`div`,{className:`_cppay-error-tooltip-full`,children:A})]}),!D&&(0,u.jsx)(`div`,{className:`_cppay-section`,children:I?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`button`,{onClick:ve,disabled:O,className:`_cppay-btn _cppay-btn-primary`,children:O?p===`subscription`?w.authorizing:w.processing:p===`subscription`?`💳 ${w.connectWallet}`:`💳 ${w.walletPay}`}),(0,u.jsxs)(`button`,{onClick:de,disabled:O,className:`_cppay-btn _cppay-wallet-address-btn`,title:w.clickToModifyWallet,children:[(0,u.jsxs)(`span`,{className:`_cppay-wallet-address-text`,children:[I.slice(0,10),`...`,I.slice(-4)]}),(0,u.jsx)(`svg`,{className:`_cppay-wallet-arrow`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,u.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})]})]}):(0,u.jsx)(`button`,{onClick:de,disabled:ae,className:`_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn`,children:(0,u.jsx)(`span`,{children:ae?w.processing:`💳 ${w.connectWallet}`})})}),(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`button`,{onClick:be,disabled:D,className:`_cppay-btn _cppay-btn-primary`,children:D?w.checking:w.completedPayment})}),(0,u.jsx)(`hr`,{className:`_cppay-divider`}),(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`button`,{onClick:()=>E(`select`),disabled:O||D,className:`_cppay-btn _cppay-btn-text`,children:w.changePaymentMethod})})]})})},f=d,p=({open:t,onClose:n,ott:r,apikey:i,plain:a,orderId:o,amount:s,intervalDays:c,locale:d,onExpired:p,onSuccess:m,onFailed:h,onError:g,Slots:_})=>{let[v,y]=(0,l.useState)(`select`),b=(0,l.useMemo)(()=>v!==`checking`,[v]);(0,l.useEffect)(()=>{t||y(`select`)},[t]),(0,l.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&b&&x()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,b]);let x=()=>{b&&n()},S=(0,l.useMemo)(()=>e.t(d),[d]);return t?(0,u.jsx)(`div`,{className:`_cppay-overlay`,onClick:e=>e.target===e.currentTarget&&x(),children:(0,u.jsxs)(`div`,{className:`_cppay-dialog`,children:[(0,u.jsxs)(`div`,{className:`_cppay-header`,children:[(0,u.jsx)(`h2`,{className:`_cppay-title`,children:(()=>{switch(v){case`success`:return S.paymentResult;case`expired`:return S.paymentExpired;case`failed`:return S.paymentFailed;case`error`:return S.error;case`payment`:case`checking`:return S.completePayment;default:return S.selectPaymentMethod}})()}),(0,u.jsx)(`button`,{onClick:x,disabled:!b,className:`_cppay-close-btn`,children:(0,u.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,u.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,u.jsx)(f,{apikey:i,ott:r,plain:a,orderId:o,amount:s,intervalDays:c,locale:d,onSuccess:m,onExpired:p,onFailed:h,onError:g,Slots:_,onPaymentStepChange:y})]})}):null},m=p,h=(0,l.createContext)(null);const g=({apikey:e,children:t})=>{let[n,r]=(0,l.useState)(!1),[i,a]=(0,l.useState)(null),o=(0,l.useCallback)(e=>{a(e),r(!0)},[]),s=(0,l.useCallback)(()=>{r(!1)},[]),c=(0,l.useCallback)(()=>{r(!1)},[]),d=(0,l.useCallback)(e=>{i?.onSuccess?.(e),setTimeout(()=>r(!1),1e3)},[i]),f=(0,l.useCallback)(e=>{i?.onExpired?.(e)},[i]),p=(0,l.useCallback)(e=>{i?.onFailed?.(e)},[i]),g=(0,l.useCallback)(e=>{i?.onError?.(e)},[i]);return(0,l.useEffect)(()=>{if(!n)return;let e=e=>{e.key===`Escape`&&c()};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[n,c]),(0,u.jsxs)(h.Provider,{value:{showPayment:o,closePayment:s},children:[t,i&&(0,u.jsx)(m,{open:n,onClose:c,apikey:e,plain:i.plain,orderId:i.orderId,amount:i.amount,intervalDays:i.intervalDays,onSuccess:d,onExpired:f,onFailed:p,onError:g})]})},_=()=>{let e=(0,l.useContext)(h);if(!e)throw Error(`useCppayPayment must be used within CppayProvider`);return e};e.n(e.r),exports.CppayProvider=g,exports.PaymentContent=f,exports.PaymentDialog=m,exports.useCppayPayment=_;
1
+ const e=require(`./locales-DfK0OLJI.cjs`),t=require(`./cppay-UdGae-e8.cjs`);let n=require(`qrcode`);n=e.i(n);let r=require(`rxjs`),i=require(`rxjs/operators`),a=require(`viem`),o=require(`viem/chains`),s=require(`@reown/appkit`),c=require(`@reown/appkit-adapter-ethers`),l=require(`react`);l=e.i(l);let u=require(`react/jsx-runtime`);var d=({apikey:d,ott:f,plain:p,orderId:m,amount:h,intervalDays:g,locale:_,onSuccess:v,onExpired:y,onFailed:b,onError:x,Slots:S,onPaymentStepChange:ee})=>{let C=(0,l.useMemo)(()=>new t.t(d,f),[d,f]),w=(0,l.useMemo)(()=>e.t(_),[_]),[T,E]=(0,l.useState)(`select`),D=(0,l.useMemo)(()=>T===`checking`,[T]),[O,k]=(0,l.useState)(!1),[A,j]=(0,l.useState)(),[M,te]=(0,l.useState)([]),[N,P]=(0,l.useState)(),[F,ne]=(0,l.useState)(),[re,ie]=(0,l.useState)(),[I,L]=(0,l.useState)(),[ae,oe]=(0,l.useState)(!1),[R,z]=(0,l.useState)(),[se,ce]=(0,l.useState)(``),[B,le]=(0,l.useState)(!1),[ue,V]=(0,l.useState)(!1),H=(0,l.useRef)(null),U=(0,l.useRef)(null),W=(0,l.useRef)(null),G=(0,l.useRef)(null);(0,l.useEffect)(()=>{typeof window<`u`&&!H.current&&(H.current=(0,s.createAppKit)({debug:!1,enableNetworkSwitch:!1,adapters:[new c.EthersAdapter],projectId:`8d2e1854d3f1782e45aa15fbd8938894`,allowUnsupportedChain:!0,networks:[o.mainnet,o.bsc,o.polygon,o.arbitrum,o.optimism,o.base],metadata:{name:`Cppay`,description:`Cppay Payment Gateway`,url:window.location.origin,icons:[`https://cppay.com/icon.png`]},features:{analytics:!1}}),L(H.current.getAddress()),z(H.current.getProvider(`eip155`)),H.current.subscribeAccount(e=>{e.isConnected?L(e.address):(L(void 0),z(void 0))}),H.current.subscribeProviders(e=>{let t=e?.eip155;z(t)}))},[]),(0,l.useEffect)(()=>{ee?.(T)},[T]);let de=async()=>{try{oe(!0),j(void 0),H.current&&await H.current.open()}catch(e){console.error(`钱包连接失败:`,e),j(e instanceof Error?e.message:w.walletConnectionFailed),x?.(e)}finally{oe(!1)}},K=(0,l.useMemo)(()=>M.find(e=>e.chain===N),[M,N]),q=(0,l.useMemo)(()=>K?.tokens||[],[K]),J=(0,l.useMemo)(()=>q.find(e=>e.symbol===F),[q,F]),Y=e=>[`USDT`,`USDC`,`BUSD`,`DAI`,`TUSD`,`USDD`,`FDUSD`].includes(e.toUpperCase())?2:6,X=(e,t)=>{let n=parseFloat(e);return isNaN(n)?`0`:n.toFixed(t).replace(/\.?0+$/,``)},fe=e=>{if(e<=0)return w.expired;let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=e%60;return t>0?`${t}${w.hours}${n}${w.minutes}${r}${w.seconds}`:`${n}${w.minutes}${r}${w.seconds}`},pe=e=>{W.current&&clearInterval(W.current);let t=()=>{if(T===`checking`){Z();return}let t=e-Math.floor(Date.now()/1e3);ce(fe(t)),t<=0&&(E(`expired`),Z())};t(),W.current=setInterval(t,1e3)},Z=()=>{W.current&&=(clearInterval(W.current),null)},Q=(0,l.useMemo)(()=>{if(!F||!J)return`0`;let e=parseFloat(J.price);if(isNaN(e)||e===0)return`0`;let t=Y(F);return X((parseFloat(h)/e).toFixed(t),t)},[h,F,J]),me=async()=>{try{k(!0),j(void 0);let e=await C.getSupportedChains();te(e),e.length>0&&P(e[0].chain)}catch(e){j(e instanceof Error?e.message:w.loadPaymentNetworkFailed),x?.(e)}finally{k(!1)}},he=async e=>{if(R)try{await R.request({method:`wallet_switchEthereumChain`,params:[{chainId:`0x${e.toString(16)}`}]})}catch(e){throw e.code===4902?Error(w.pleaseAddNetwork):e}},ge=async()=>{if(!(!I||!R||!G.current||!J||!K))try{k(!0);let e=G.current;await he(K.chainId);let t=(0,a.createWalletClient)({account:I,transport:(0,a.custom)(R)});if(J.address){let n=await t.writeContract({address:J.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,a.parseUnits)(e.paymentAmount,J.decimals)],chain:null});console.log(`转账交易哈希:`,n)}else{let n=await t.sendTransaction({to:e.receiveAddress,value:(0,a.parseUnits)(e.paymentAmount,J.decimals),chain:null});console.log(`转账交易哈希:`,n)}k(!1),E(`checking`)}catch(e){console.error(`钱包支付失败:`,e),j(e instanceof Error?e.message:w.walletPaymentFailed),x?.(e),k(!1)}},_e=async()=>{if(!(!I||!R||!G.current||!J||!K))try{k(!0);let e=G.current;await he(K.chainId);let t=(0,a.createWalletClient)({account:I,transport:(0,a.custom)(R)});if(!J.address)throw Error(w.subscriptionDoesNotSupportNative);let n=await t.writeContract({address:J.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,a.parseUnits)(e.approveAmount,J.decimals)],chain:null});console.log(`授权交易哈希:`,n),k(!1),E(`checking`)}catch(e){console.error(`钱包授权失败:`,e),j(e instanceof Error?e.message:w.walletPaymentFailed),x?.(e),k(!1)}},ve=async()=>{if(!I){let e=w.pleaseConnectWallet;j(e),x?.(Error(e));return}p===`instant`?await ge():p===`subscription`&&await _e()},ye=async()=>{if(!(!N||!F))try{k(!0),j(void 0);let e=``;p===`instant`?(G.current=await C.createOnetimePayment({paymentChain:N,paymentToken:F,orderId:m,amount:Q}),e=`${N.toLowerCase()}:${G.current.receiveAddress}?amount=${G.current.paymentAmount}`,pe(G.current.expireAt),$({paymentId:G.current.paymentId})):p===`subscription`&&(G.current=await C.createSubscriptionPayment({paymentChain:N,paymentToken:F,orderId:m,amountOfUsd:Q,intervalDays:g||30}),e=`${N.toLowerCase()}:${G.current.spenderAddress}?amount=${G.current.approveAmount}`,pe(G.current.expireAt),$({subscriptionId:G.current.subscriptionId})),E(`payment`),ie(await n.toDataURL(e,{width:200,margin:2,errorCorrectionLevel:`H`}))}catch(e){j(e instanceof Error?e.message:w.createPaymentFailed),x?.(e)}finally{k(!1)}},be=()=>{G.current&&(E(`checking`),j(void 0))},$=e=>{U.current?.unsubscribe();let t=()=>(0,r.defer)(()=>p===`subscription`?C.checkSubscriptionPaymentStatus(e):C.checkOnetimePaymentStatus(e)).pipe((0,i.timeout)(15e3),(0,i.retry)({delay:2e3}));U.current=t().pipe((0,i.expand)(e=>e.status===`pending`?(0,r.timer)(2e3).pipe((0,i.switchMap)(()=>t())):r.EMPTY),(0,i.tap)(e=>{(e.status===`paid`||e.status===`approved`)&&(E(`success`),v?.(e)),e.status===`expired`&&(E(`expired`),y?.(e)),e.status===`failed`&&(E(`failed`),b?.(e))})).subscribe({error:e=>{if(G.current){let t=e instanceof Error?e.message:w.checkPaymentStatusFailed;E(`error`),j(t),x?.(e)}},complete:()=>{U.current?.unsubscribe()}})};return(0,l.useEffect)(()=>{M.length===0&&me()},[]),(0,l.useEffect)(()=>{q.length>0&&ne(q[0].symbol)},[q]),(0,l.useEffect)(()=>(m&&$({orderId:m}),()=>{U.current?.unsubscribe(),Z()}),[m]),(0,u.jsx)(`div`,{className:`_cppay-content`,children:T===`success`?S?.Success?(0,u.jsx)(S.Success,{paymentInfo:G.current}):(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`✅`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:p===`subscription`?w.authorizationSuccess:w.paymentSuccess}),(0,u.jsx)(`p`,{className:`_cppay-state-message`,children:p===`subscription`?w.subscriptionActivated:w.transactionCompleted})]}):T===`expired`?S?.Expired?(0,u.jsx)(S.Expired,{paymentInfo:G.current}):(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`⏰`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:w.paymentExpired}),(0,u.jsx)(`button`,{onClick:()=>E(`select`),disabled:O||D,className:`_cppay-btn _cppay-btn-text`,children:w.returnButton})]}):T===`error`?S?.Error?(0,u.jsx)(S.Error,{paymentInfo:G.current}):(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`❌`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:A||w.error})]}):T===`failed`?S?.Failed?(0,u.jsx)(S.Failed,{paymentInfo:G.current}):(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`❌`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:w.paymentFailed})]}):T===`select`?(0,u.jsxs)(`div`,{children:[S?.ChooseTop,(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[(0,u.jsx)(`label`,{className:`_cppay-label`,children:w.paymentNetwork}),(0,u.jsx)(`div`,{className:`_cppay-grid`,children:M.map(e=>(0,u.jsxs)(`button`,{onClick:()=>P(e.chain),className:`_cppay-select-btn ${N===e.chain?`_cppay-selected`:``}`,children:[e.icon&&(0,u.jsx)(`img`,{src:e.icon,alt:e.chain}),(0,u.jsx)(`span`,{children:e.chain})]},e.chain))})]}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[(0,u.jsx)(`label`,{className:`_cppay-label`,children:w.paymentToken}),(0,u.jsx)(`div`,{className:`_cppay-grid`,children:q.map(e=>(0,u.jsxs)(`button`,{onClick:()=>ne(e.symbol),className:`_cppay-select-btn ${F===e.symbol?`_cppay-selected`:``}`,children:[e.icon&&(0,u.jsx)(`img`,{src:e.icon,alt:e.symbol}),(0,u.jsx)(`span`,{children:e.symbol})]},e.symbol))})]}),S?.ChooseBottom,(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`div`,{className:`_cppay-price-box`,children:(0,u.jsxs)(`div`,{className:`_cppay-price-row`,children:[(0,u.jsx)(`span`,{className:`_cppay-price-label`,children:w.paymentAmount}),(0,u.jsxs)(`div`,{className:`_cppay-price-amount`,children:[(0,u.jsxs)(`div`,{className:`_cppay-price-main`,children:[Q??`-`,` `,F??``]}),(0,u.jsxs)(`div`,{className:`_cppay-price-sub`,children:[`≈ $`,h]})]})]})})}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[A&&(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip-wrapper`,onMouseEnter:()=>V(!0),onMouseLeave:()=>V(!1),children:[(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip`,children:[(0,u.jsx)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,u.jsx)(`path`,{fillRule:`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`,clipRule:`evenodd`})}),(0,u.jsx)(`span`,{children:A})]}),ue&&(0,u.jsx)(`div`,{className:`_cppay-error-tooltip-full`,children:A})]}),(0,u.jsx)(`button`,{onClick:ye,disabled:!N||!F||O,className:`_cppay-btn _cppay-btn-primary`,children:O?w.processing:w.continuePayment})]})]}):(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`_cppay-qr-container`,children:(0,u.jsx)(`div`,{className:`_cppay-qr-code`,children:re&&(0,u.jsx)(`img`,{src:re,alt:`Payment QR Code`,className:`_cppay-qr-image`})})}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[J&&(0,u.jsx)(`div`,{className:`_cppay-info-box`,children:(0,u.jsx)(`div`,{className:`_cppay-info-flex-container`,children:(0,u.jsxs)(`div`,{className:`_cppay-info-flex-child`,children:[(0,u.jsx)(`div`,{className:`_cppay-info-label`,children:p===`subscription`?w.authorizationAmount:w.paymentAmount}),(0,u.jsxs)(`div`,{className:`_cppay-info-value _cppay-info-value-flex`,children:[(0,u.jsx)(`span`,{children:p===`subscription`?`${X(G.current.approveAmount,Y(J.symbol))} ${J.symbol}`:`${X(G.current.paymentAmount,Y(J.symbol))} ${J.symbol}`}),(0,u.jsxs)(`span`,{children:[`≈ $`,h]})]})]})})}),(0,u.jsx)(`div`,{className:`_cppay-info-box`,children:(0,u.jsxs)(`div`,{className:`_cppay-info-flex-child`,children:[(0,u.jsxs)(`div`,{className:`_cppay-info-label _cppay-info-label-flex`,children:[(0,u.jsx)(`span`,{children:p===`subscription`?w.authorizationContractAddress:w.paymentAddress}),se&&(0,u.jsxs)(`span`,{className:`_cppay-countdown`,children:[`⏰ `,se]})]}),(0,u.jsxs)(`div`,{className:`_cppay-address-row`,children:[(0,u.jsx)(`code`,{children:p===`subscription`?G.current.spenderAddress:G.current.receiveAddress}),(0,u.jsx)(`button`,{onClick:async()=>{if(!G.current)return;let e=p===`subscription`?G.current.spenderAddress:G.current.receiveAddress;if(e)try{await navigator.clipboard.writeText(e),le(!0),setTimeout(()=>{le(!1)},2e3)}catch(e){console.error(`复制失败:`,e)}},className:`_cppay-copy-btn ${B?`_cppay-copy-success`:``}`,title:B?w.copied:w.copyAddress,children:B?(0,u.jsx)(`svg`,{className:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,u.jsx)(`path`,{d:`M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z`})}):(0,u.jsxs)(`svg`,{className:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,u.jsx)(`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,u.jsx)(`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,ry:`1`})]})})]})]})}),p===`subscription`&&(0,u.jsxs)(`div`,{className:`_cppay-info-box _cppay-subscription-box`,children:[(0,u.jsx)(`div`,{className:`_cppay-info-label _cppay-subscription-label`,children:w.subscriptionNotice}),(0,u.jsx)(`div`,{className:`_cppay-info-value _cppay-subscription-message`,children:w.subscriptionNoticeMessage})]})]}),A&&(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip-wrapper`,onMouseEnter:()=>V(!0),onMouseLeave:()=>V(!1),children:[(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip`,children:[(0,u.jsx)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,u.jsx)(`path`,{fillRule:`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`,clipRule:`evenodd`})}),(0,u.jsx)(`span`,{children:A})]}),ue&&(0,u.jsx)(`div`,{className:`_cppay-error-tooltip-full`,children:A})]}),!D&&(0,u.jsx)(`div`,{className:`_cppay-section`,children:I?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`button`,{onClick:ve,disabled:O,className:`_cppay-btn _cppay-btn-primary`,children:O?p===`subscription`?w.authorizing:w.processing:p===`subscription`?`💳 ${w.connectWallet}`:`💳 ${w.walletPay}`}),(0,u.jsxs)(`button`,{onClick:de,disabled:O,className:`_cppay-btn _cppay-wallet-address-btn`,title:w.clickToModifyWallet,children:[(0,u.jsxs)(`span`,{className:`_cppay-wallet-address-text`,children:[I.slice(0,10),`...`,I.slice(-4)]}),(0,u.jsx)(`svg`,{className:`_cppay-wallet-arrow`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,u.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})]})]}):(0,u.jsx)(`button`,{onClick:de,disabled:ae,className:`_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn`,children:(0,u.jsx)(`span`,{children:ae?w.processing:`💳 ${w.connectWallet}`})})}),(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`button`,{onClick:be,disabled:D,className:`_cppay-btn _cppay-btn-primary`,children:D?w.checking:w.completedPayment})}),(0,u.jsx)(`hr`,{className:`_cppay-divider`}),(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`button`,{onClick:()=>E(`select`),disabled:O||D,className:`_cppay-btn _cppay-btn-text`,children:w.changePaymentMethod})})]})})},f=d,p=({open:t,onClose:n,ott:r,apikey:i,plain:a,orderId:o,amount:s,intervalDays:c,locale:d,onExpired:p,onSuccess:m,onFailed:h,onError:g,Slots:_})=>{let[v,y]=(0,l.useState)(`select`),b=(0,l.useMemo)(()=>v!==`checking`,[v]);(0,l.useEffect)(()=>{t||y(`select`)},[t]),(0,l.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&b&&x()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,b]);let x=()=>{b&&n()},S=(0,l.useMemo)(()=>e.t(d),[d]);return t?(0,u.jsx)(`div`,{className:`_cppay-overlay`,onClick:e=>e.target===e.currentTarget&&x(),children:(0,u.jsxs)(`div`,{className:`_cppay-dialog`,children:[(0,u.jsxs)(`div`,{className:`_cppay-header`,children:[(0,u.jsx)(`h2`,{className:`_cppay-title`,children:(()=>{switch(v){case`success`:return S.paymentResult;case`expired`:return S.paymentExpired;case`failed`:return S.paymentFailed;case`error`:return S.error;case`payment`:case`checking`:return S.completePayment;default:return S.selectPaymentMethod}})()}),(0,u.jsx)(`button`,{onClick:x,disabled:!b,className:`_cppay-close-btn`,children:(0,u.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,u.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,u.jsx)(f,{apikey:i,ott:r,plain:a,orderId:o,amount:s,intervalDays:c,locale:d,onSuccess:m,onExpired:p,onFailed:h,onError:g,Slots:_,onPaymentStepChange:y})]})}):null},m=p,h=(0,l.createContext)(null);const g=({apikey:e,children:t})=>{let[n,r]=(0,l.useState)(!1),[i,a]=(0,l.useState)(null),o=(0,l.useCallback)(e=>{a(e),r(!0)},[]),s=(0,l.useCallback)(()=>{r(!1)},[]),c=(0,l.useCallback)(()=>{r(!1)},[]),d=(0,l.useCallback)(e=>{i?.onSuccess?.(e),setTimeout(()=>r(!1),1e3)},[i]),f=(0,l.useCallback)(e=>{i?.onExpired?.(e)},[i]),p=(0,l.useCallback)(e=>{i?.onFailed?.(e)},[i]),g=(0,l.useCallback)(e=>{i?.onError?.(e)},[i]);return(0,l.useEffect)(()=>{if(!n)return;let e=e=>{e.key===`Escape`&&c()};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[n,c]),(0,u.jsxs)(h.Provider,{value:{showPayment:o,closePayment:s},children:[t,i&&(0,u.jsx)(m,{open:n,onClose:c,apikey:e,plain:i.plain,orderId:i.orderId,amount:i.amount,intervalDays:i.intervalDays,onSuccess:d,onExpired:f,onFailed:p,onError:g})]})},_=()=>{let e=(0,l.useContext)(h);if(!e)throw Error(`useCppayPayment must be used within CppayProvider`);return e};e.n(e.r),exports.CppayProvider=g,exports.PaymentContent=f,exports.PaymentDialog=m,exports.useCppayPayment=_;
package/dist/react.d.ts CHANGED
@@ -29,6 +29,16 @@ export declare type Locale = "zh-CN" | "en-US";
29
29
 
30
30
  declare type Numberic = `${number}.${number}` | `${number}`;
31
31
 
32
+ declare interface OnetimePaymentInfo {
33
+ orderId: string;
34
+ paymentId: string;
35
+ paymentAmount: Numberic;
36
+ paymentChain: string;
37
+ paymentToken: string;
38
+ receiveAddress: Address;
39
+ expireAt: number;
40
+ }
41
+
32
42
  declare interface OnetimePaymentOrderStatus {
33
43
  orderId: string;
34
44
  paymentId: string;
@@ -87,6 +97,18 @@ declare interface PaymentContentProps {
87
97
  Slots?: Partial<{
88
98
  ChooseTop: default_2.ReactNode;
89
99
  ChooseBottom: default_2.ReactNode;
100
+ Success: default_2.FC<{
101
+ paymentInfo: OnetimePaymentInfo | SubscriptionPaymentInfo;
102
+ }>;
103
+ Expired: default_2.FC<{
104
+ paymentInfo: OnetimePaymentInfo | SubscriptionPaymentInfo;
105
+ }>;
106
+ Failed: default_2.FC<{
107
+ paymentInfo: OnetimePaymentInfo | SubscriptionPaymentInfo;
108
+ }>;
109
+ Error: default_2.FC<{
110
+ paymentInfo: OnetimePaymentInfo | SubscriptionPaymentInfo;
111
+ }>;
90
112
  }>;
91
113
  /** 支付步骤状态变化回调 */
92
114
  onPaymentStepChange?: (step: PaymentStep) => void;
@@ -150,6 +172,18 @@ declare interface PaymentDialogProps {
150
172
  Slots?: Partial<{
151
173
  ChooseTop: default_2.ReactNode;
152
174
  ChooseBottom: default_2.ReactNode;
175
+ Success: default_2.FC<{
176
+ paymentInfo: OnetimePaymentInfo | SubscriptionPaymentInfo;
177
+ }>;
178
+ Expired: default_2.FC<{
179
+ paymentInfo: OnetimePaymentInfo | SubscriptionPaymentInfo;
180
+ }>;
181
+ Failed: default_2.FC<{
182
+ paymentInfo: OnetimePaymentInfo | SubscriptionPaymentInfo;
183
+ }>;
184
+ Error: default_2.FC<{
185
+ paymentInfo: OnetimePaymentInfo | SubscriptionPaymentInfo;
186
+ }>;
153
187
  }>;
154
188
  }
155
189
 
@@ -181,6 +215,18 @@ declare type PaymentStatus = "pending" | "paid" | "expired" | "failed";
181
215
 
182
216
  declare type PaymentStep = "select" | "payment" | "checking" | "success" | "failed" | "expired" | "error";
183
217
 
218
+ declare interface SubscriptionPaymentInfo {
219
+ subscriptionId: string;
220
+ approveAmount: Numberic;
221
+ spenderAddress: Address;
222
+ expireAt: number;
223
+ paymentChain: string;
224
+ paymentToken: string;
225
+ orderId: string;
226
+ amountOfUsd: Numberic;
227
+ intervalDays: number;
228
+ }
229
+
184
230
  declare interface SubscriptionPaymentOrderStatus {
185
231
  orderId: string;
186
232
  subscriptionId: string;
package/dist/react.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as cppay_default } from "./cppay-J9nBy01A.js";
1
+ import { t as cppay_default } from "./cppay-jU20-wmK.js";
2
2
  import { n as injectStyle, r as payment_dialog_default, t as getLocaleMessages } from "./locales-De6oJnka.js";
3
3
  import * as QRCode from "qrcode";
4
4
  import { EMPTY, defer, timer } from "rxjs";
@@ -9,10 +9,10 @@ import { createAppKit } from "@reown/appkit";
9
9
  import { EthersAdapter } from "@reown/appkit-adapter-ethers";
10
10
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
11
11
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12
- var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount: h, intervalDays: ve, locale: g, onSuccess: ye, onExpired: be, onFailed: xe, onError: _, Slots: Se, onPaymentStepChange: Ce }) => {
13
- let v = useMemo(() => new cppay_default(t, n), [t, n]), y = useMemo(() => getLocaleMessages(g), [g]), [b, x] = useState("select"), S = useMemo(() => b === "checking", [b]), [C, w] = useState(!1), [T, E] = useState(), [D, we] = useState([]), [O, k] = useState(), [A, j] = useState(), [M, Te] = useState(), [N, P] = useState(), [F, I] = useState(!1), [L, R] = useState(), [z, Ee] = useState(""), [B, De] = useState(!1), [Oe, V] = useState(!1), H = useRef(null), U = useRef(null), W = useRef(null), G = useRef(null);
12
+ var PaymentContent_default = ({ apikey: t, ott: n, plain: f, orderId: p, amount: m, intervalDays: ye, locale: h, onSuccess: be, onExpired: xe, onFailed: Se, onError: g, Slots: _, onPaymentStepChange: Ce }) => {
13
+ let v = useMemo(() => new cppay_default(t, n), [t, n]), y = useMemo(() => getLocaleMessages(h), [h]), [b, x] = useState("select"), S = useMemo(() => b === "checking", [b]), [C, w] = useState(!1), [T, E] = useState(), [D, we] = useState([]), [O, k] = useState(), [A, j] = useState(), [M, Te] = useState(), [N, P] = useState(), [F, I] = useState(!1), [L, R] = useState(), [Ee, De] = useState(""), [z, Oe] = useState(!1), [ke, B] = useState(!1), V = useRef(null), H = useRef(null), U = useRef(null), W = useRef(null);
14
14
  useEffect(() => {
15
- typeof window < "u" && !H.current && (H.current = createAppKit({
15
+ typeof window < "u" && !V.current && (V.current = createAppKit({
16
16
  debug: !1,
17
17
  enableNetworkSwitch: !1,
18
18
  adapters: [new EthersAdapter()],
@@ -33,24 +33,24 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
33
33
  icons: ["https://cppay.com/icon.png"]
34
34
  },
35
35
  features: { analytics: !1 }
36
- }), P(H.current.getAddress()), R(H.current.getProvider("eip155")), H.current.subscribeAccount((e) => {
36
+ }), P(V.current.getAddress()), R(V.current.getProvider("eip155")), V.current.subscribeAccount((e) => {
37
37
  e.isConnected ? P(e.address) : (P(void 0), R(void 0));
38
- }), H.current.subscribeProviders((e) => {
38
+ }), V.current.subscribeProviders((e) => {
39
39
  let t = e?.eip155;
40
40
  R(t);
41
41
  }));
42
42
  }, []), useEffect(() => {
43
43
  Ce?.(b);
44
44
  }, [b]);
45
- let ke = async () => {
45
+ let Ae = async () => {
46
46
  try {
47
- I(!0), E(void 0), H.current && await H.current.open();
47
+ I(!0), E(void 0), V.current && await V.current.open();
48
48
  } catch (e) {
49
- console.error("钱包连接失败:", e), E(e instanceof Error ? e.message : y.walletConnectionFailed), _?.(e);
49
+ console.error("钱包连接失败:", e), E(e instanceof Error ? e.message : y.walletConnectionFailed), g?.(e);
50
50
  } finally {
51
51
  I(!1);
52
52
  }
53
- }, K = useMemo(() => D.find((e) => e.chain === O), [D, O]), q = useMemo(() => K?.tokens || [], [K]), J = useMemo(() => q.find((e) => e.symbol === A), [q, A]), Y = (e) => [
53
+ }, G = useMemo(() => D.find((e) => e.chain === O), [D, O]), K = useMemo(() => G?.tokens || [], [G]), q = useMemo(() => K.find((e) => e.symbol === A), [K, A]), J = (e) => [
54
54
  "USDT",
55
55
  "USDC",
56
56
  "BUSD",
@@ -58,47 +58,47 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
58
58
  "TUSD",
59
59
  "USDD",
60
60
  "FDUSD"
61
- ].includes(e.toUpperCase()) ? 2 : 6, X = (e, t) => {
61
+ ].includes(e.toUpperCase()) ? 2 : 6, Y = (e, t) => {
62
62
  let n = parseFloat(e);
63
63
  return isNaN(n) ? "0" : n.toFixed(t).replace(/\.?0+$/, "");
64
- }, Ae = (e) => {
64
+ }, je = (e) => {
65
65
  if (e <= 0) return y.expired;
66
66
  let t = Math.floor(e / 3600), n = Math.floor(e % 3600 / 60), r = e % 60;
67
67
  return t > 0 ? `${t}${y.hours}${n}${y.minutes}${r}${y.seconds}` : `${n}${y.minutes}${r}${y.seconds}`;
68
- }, je = (e) => {
69
- W.current && clearInterval(W.current);
68
+ }, Me = (e) => {
69
+ U.current && clearInterval(U.current);
70
70
  let t = () => {
71
71
  if (b === "checking") {
72
- Z();
72
+ X();
73
73
  return;
74
74
  }
75
75
  let t = e - Math.floor(Date.now() / 1e3);
76
- Ee(Ae(t)), t <= 0 && (x("expired"), Z());
76
+ De(je(t)), t <= 0 && (x("expired"), X());
77
77
  };
78
- t(), W.current = setInterval(t, 1e3);
79
- }, Z = () => {
80
- W.current &&= (clearInterval(W.current), null);
81
- }, Q = useMemo(() => {
82
- if (!A || !J) return "0";
83
- let e = parseFloat(J.price);
78
+ t(), U.current = setInterval(t, 1e3);
79
+ }, X = () => {
80
+ U.current &&= (clearInterval(U.current), null);
81
+ }, Z = useMemo(() => {
82
+ if (!A || !q) return "0";
83
+ let e = parseFloat(q.price);
84
84
  if (isNaN(e) || e === 0) return "0";
85
- let t = Y(A);
86
- return X((parseFloat(h) / e).toFixed(t), t);
85
+ let t = J(A);
86
+ return Y((parseFloat(m) / e).toFixed(t), t);
87
87
  }, [
88
- h,
88
+ m,
89
89
  A,
90
- J
91
- ]), Me = async () => {
90
+ q
91
+ ]), Ne = async () => {
92
92
  try {
93
93
  w(!0), E(void 0);
94
94
  let e = await v.getSupportedChains();
95
95
  we(e), e.length > 0 && k(e[0].chain);
96
96
  } catch (e) {
97
- E(e instanceof Error ? e.message : y.loadPaymentNetworkFailed), _?.(e);
97
+ E(e instanceof Error ? e.message : y.loadPaymentNetworkFailed), g?.(e);
98
98
  } finally {
99
99
  w(!1);
100
100
  }
101
- }, Ne = async (e) => {
101
+ }, Q = async (e) => {
102
102
  if (L) try {
103
103
  await L.request({
104
104
  method: "wallet_switchEthereumChain",
@@ -108,17 +108,17 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
108
108
  throw e.code === 4902 ? Error(y.pleaseAddNetwork) : e;
109
109
  }
110
110
  }, Pe = async () => {
111
- if (!(!N || !L || !G.current || !J || !K)) try {
111
+ if (!(!N || !L || !W.current || !q || !G)) try {
112
112
  w(!0);
113
- let e = G.current;
114
- await Ne(K.chainId);
113
+ let e = W.current;
114
+ await Q(G.chainId);
115
115
  let t = createWalletClient({
116
116
  account: N,
117
117
  transport: custom(L)
118
118
  });
119
- if (J.address) {
119
+ if (q.address) {
120
120
  let n = await t.writeContract({
121
- address: J.address,
121
+ address: q.address,
122
122
  abi: [{
123
123
  name: "transfer",
124
124
  type: "function",
@@ -133,34 +133,34 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
133
133
  outputs: [{ type: "bool" }]
134
134
  }],
135
135
  functionName: "transfer",
136
- args: [e.receiveAddress, parseUnits(e.paymentAmount, J.decimals)],
136
+ args: [e.receiveAddress, parseUnits(e.paymentAmount, q.decimals)],
137
137
  chain: null
138
138
  });
139
139
  console.log("转账交易哈希:", n);
140
140
  } else {
141
141
  let n = await t.sendTransaction({
142
142
  to: e.receiveAddress,
143
- value: parseUnits(e.paymentAmount, J.decimals),
143
+ value: parseUnits(e.paymentAmount, q.decimals),
144
144
  chain: null
145
145
  });
146
146
  console.log("转账交易哈希:", n);
147
147
  }
148
148
  w(!1), x("checking");
149
149
  } catch (e) {
150
- console.error("钱包支付失败:", e), E(e instanceof Error ? e.message : y.walletPaymentFailed), _?.(e), w(!1);
150
+ console.error("钱包支付失败:", e), E(e instanceof Error ? e.message : y.walletPaymentFailed), g?.(e), w(!1);
151
151
  }
152
152
  }, Fe = async () => {
153
- if (!(!N || !L || !G.current || !J || !K)) try {
153
+ if (!(!N || !L || !W.current || !q || !G)) try {
154
154
  w(!0);
155
- let e = G.current;
156
- await Ne(K.chainId);
155
+ let e = W.current;
156
+ await Q(G.chainId);
157
157
  let t = createWalletClient({
158
158
  account: N,
159
159
  transport: custom(L)
160
160
  });
161
- if (!J.address) throw Error(y.subscriptionDoesNotSupportNative);
161
+ if (!q.address) throw Error(y.subscriptionDoesNotSupportNative);
162
162
  let n = await t.writeContract({
163
- address: J.address,
163
+ address: q.address,
164
164
  abi: [{
165
165
  name: "approve",
166
166
  type: "function",
@@ -175,73 +175,73 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
175
175
  outputs: [{ type: "bool" }]
176
176
  }],
177
177
  functionName: "approve",
178
- args: [e.spenderAddress, parseUnits(e.approveAmount, J.decimals)],
178
+ args: [e.spenderAddress, parseUnits(e.approveAmount, q.decimals)],
179
179
  chain: null
180
180
  });
181
181
  console.log("授权交易哈希:", n), w(!1), x("checking");
182
182
  } catch (e) {
183
- console.error("钱包授权失败:", e), E(e instanceof Error ? e.message : y.walletPaymentFailed), _?.(e), w(!1);
183
+ console.error("钱包授权失败:", e), E(e instanceof Error ? e.message : y.walletPaymentFailed), g?.(e), w(!1);
184
184
  }
185
185
  }, Ie = async () => {
186
186
  if (!N) {
187
187
  let e = y.pleaseConnectWallet;
188
- E(e), _?.(Error(e));
188
+ E(e), g?.(Error(e));
189
189
  return;
190
190
  }
191
- p === "instant" ? await Pe() : p === "subscription" && await Fe();
191
+ f === "instant" ? await Pe() : f === "subscription" && await Fe();
192
192
  }, Le = async () => {
193
193
  if (!(!O || !A)) try {
194
194
  w(!0), E(void 0);
195
195
  let e = "";
196
- p === "instant" ? (G.current = await v.createOnetimePayment({
196
+ f === "instant" ? (W.current = await v.createOnetimePayment({
197
197
  paymentChain: O,
198
198
  paymentToken: A,
199
- orderId: m,
200
- amount: Q
201
- }), e = `${O.toLowerCase()}:${G.current.receiveAddress}?amount=${G.current.paymentAmount}`, je(G.current.expireAt), $({ paymentId: G.current.paymentId })) : p === "subscription" && (G.current = await v.createSubscriptionPayment({
199
+ orderId: p,
200
+ amount: Z
201
+ }), e = `${O.toLowerCase()}:${W.current.receiveAddress}?amount=${W.current.paymentAmount}`, Me(W.current.expireAt), $({ paymentId: W.current.paymentId })) : f === "subscription" && (W.current = await v.createSubscriptionPayment({
202
202
  paymentChain: O,
203
203
  paymentToken: A,
204
- orderId: m,
205
- amountOfUsd: Q,
206
- intervalDays: ve || 30
207
- }), e = `${O.toLowerCase()}:${G.current.spenderAddress}?amount=${G.current.approveAmount}`, je(G.current.expireAt), $({ subscriptionId: G.current.subscriptionId })), x("payment"), Te(await QRCode.toDataURL(e, {
204
+ orderId: p,
205
+ amountOfUsd: Z,
206
+ intervalDays: ye || 30
207
+ }), e = `${O.toLowerCase()}:${W.current.spenderAddress}?amount=${W.current.approveAmount}`, Me(W.current.expireAt), $({ subscriptionId: W.current.subscriptionId })), x("payment"), Te(await QRCode.toDataURL(e, {
208
208
  width: 200,
209
209
  margin: 2,
210
210
  errorCorrectionLevel: "H"
211
211
  }));
212
212
  } catch (e) {
213
- E(e instanceof Error ? e.message : y.createPaymentFailed), _?.(e);
213
+ E(e instanceof Error ? e.message : y.createPaymentFailed), g?.(e);
214
214
  } finally {
215
215
  w(!1);
216
216
  }
217
217
  }, Re = () => {
218
- G.current && (x("checking"), E(void 0));
218
+ W.current && (x("checking"), E(void 0));
219
219
  }, $ = (e) => {
220
- U.current?.unsubscribe();
221
- let t = () => defer(() => p === "subscription" ? v.checkSubscriptionPaymentStatus(e) : v.checkOnetimePaymentStatus(e)).pipe(timeout(15e3), retry({ delay: 2e3 }));
222
- U.current = t().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => t())) : EMPTY), tap((e) => {
223
- (e.status === "paid" || e.status === "approved") && (x("success"), ye?.(e)), e.status === "expired" && (x("expired"), be?.(e)), e.status === "failed" && (x("failed"), xe?.(e));
220
+ H.current?.unsubscribe();
221
+ let t = () => defer(() => f === "subscription" ? v.checkSubscriptionPaymentStatus(e) : v.checkOnetimePaymentStatus(e)).pipe(timeout(15e3), retry({ delay: 2e3 }));
222
+ H.current = t().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => t())) : EMPTY), tap((e) => {
223
+ (e.status === "paid" || e.status === "approved") && (x("success"), be?.(e)), e.status === "expired" && (x("expired"), xe?.(e)), e.status === "failed" && (x("failed"), Se?.(e));
224
224
  })).subscribe({
225
225
  error: (e) => {
226
- if (G.current) {
226
+ if (W.current) {
227
227
  let t = e instanceof Error ? e.message : y.checkPaymentStatusFailed;
228
- x("error"), E(t), _?.(e);
228
+ x("error"), E(t), g?.(e);
229
229
  }
230
230
  },
231
231
  complete: () => {
232
- U.current?.unsubscribe();
232
+ H.current?.unsubscribe();
233
233
  }
234
234
  });
235
235
  };
236
236
  return useEffect(() => {
237
- D.length === 0 && Me();
237
+ D.length === 0 && Ne();
238
238
  }, []), useEffect(() => {
239
- q.length > 0 && j(q[0].symbol);
240
- }, [q]), useEffect(() => (m && $({ orderId: m }), () => {
241
- U.current?.unsubscribe(), Z();
242
- }), [m]), /* @__PURE__ */ jsx("div", {
239
+ K.length > 0 && j(K[0].symbol);
240
+ }, [K]), useEffect(() => (p && $({ orderId: p }), () => {
241
+ H.current?.unsubscribe(), X();
242
+ }), [p]), /* @__PURE__ */ jsx("div", {
243
243
  className: "_cppay-content",
244
- children: b === "success" ? /* @__PURE__ */ jsxs("div", {
244
+ children: b === "success" ? _?.Success ? /* @__PURE__ */ jsx(_.Success, { paymentInfo: W.current }) : /* @__PURE__ */ jsxs("div", {
245
245
  className: "_cppay-state-container",
246
246
  children: [
247
247
  /* @__PURE__ */ jsx("div", {
@@ -250,14 +250,14 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
250
250
  }),
251
251
  /* @__PURE__ */ jsx("h3", {
252
252
  className: "_cppay-state-title",
253
- children: p === "subscription" ? y.authorizationSuccess : y.paymentSuccess
253
+ children: f === "subscription" ? y.authorizationSuccess : y.paymentSuccess
254
254
  }),
255
255
  /* @__PURE__ */ jsx("p", {
256
256
  className: "_cppay-state-message",
257
- children: p === "subscription" ? y.subscriptionActivated : y.transactionCompleted
257
+ children: f === "subscription" ? y.subscriptionActivated : y.transactionCompleted
258
258
  })
259
259
  ]
260
- }) : b === "expired" ? /* @__PURE__ */ jsxs("div", {
260
+ }) : b === "expired" ? _?.Expired ? /* @__PURE__ */ jsx(_.Expired, { paymentInfo: W.current }) : /* @__PURE__ */ jsxs("div", {
261
261
  className: "_cppay-state-container",
262
262
  children: [
263
263
  /* @__PURE__ */ jsx("div", {
@@ -275,7 +275,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
275
275
  children: y.returnButton
276
276
  })
277
277
  ]
278
- }) : b === "error" ? /* @__PURE__ */ jsxs("div", {
278
+ }) : b === "error" ? _?.Error ? /* @__PURE__ */ jsx(_.Error, { paymentInfo: W.current }) : /* @__PURE__ */ jsxs("div", {
279
279
  className: "_cppay-state-container",
280
280
  children: [/* @__PURE__ */ jsx("div", {
281
281
  className: "_cppay-state-icon",
@@ -284,7 +284,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
284
284
  className: "_cppay-state-title",
285
285
  children: T || y.error
286
286
  })]
287
- }) : b === "failed" ? /* @__PURE__ */ jsxs("div", {
287
+ }) : b === "failed" ? _?.Failed ? /* @__PURE__ */ jsx(_.Failed, { paymentInfo: W.current }) : /* @__PURE__ */ jsxs("div", {
288
288
  className: "_cppay-state-container",
289
289
  children: [/* @__PURE__ */ jsx("div", {
290
290
  className: "_cppay-state-icon",
@@ -294,7 +294,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
294
294
  children: y.paymentFailed
295
295
  })]
296
296
  }) : b === "select" ? /* @__PURE__ */ jsxs("div", { children: [
297
- Se?.ChooseTop,
297
+ _?.ChooseTop,
298
298
  /* @__PURE__ */ jsxs("div", {
299
299
  className: "_cppay-section",
300
300
  children: [/* @__PURE__ */ jsx("label", {
@@ -319,7 +319,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
319
319
  children: y.paymentToken
320
320
  }), /* @__PURE__ */ jsx("div", {
321
321
  className: "_cppay-grid",
322
- children: q.map((e) => /* @__PURE__ */ jsxs("button", {
322
+ children: K.map((e) => /* @__PURE__ */ jsxs("button", {
323
323
  onClick: () => j(e.symbol),
324
324
  className: `_cppay-select-btn ${A === e.symbol ? "_cppay-selected" : ""}`,
325
325
  children: [e.icon && /* @__PURE__ */ jsx("img", {
@@ -329,7 +329,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
329
329
  }, e.symbol))
330
330
  })]
331
331
  }),
332
- Se?.ChooseBottom,
332
+ _?.ChooseBottom,
333
333
  /* @__PURE__ */ jsx("div", {
334
334
  className: "_cppay-section",
335
335
  children: /* @__PURE__ */ jsx("div", {
@@ -344,13 +344,13 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
344
344
  children: [/* @__PURE__ */ jsxs("div", {
345
345
  className: "_cppay-price-main",
346
346
  children: [
347
- Q ?? "-",
347
+ Z ?? "-",
348
348
  " ",
349
349
  A ?? ""
350
350
  ]
351
351
  }), /* @__PURE__ */ jsxs("div", {
352
352
  className: "_cppay-price-sub",
353
- children: ["≈ $", h]
353
+ children: ["≈ $", m]
354
354
  })]
355
355
  })]
356
356
  })
@@ -360,8 +360,8 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
360
360
  className: "_cppay-section",
361
361
  children: [T && /* @__PURE__ */ jsxs("div", {
362
362
  className: "_cppay-error-tooltip-wrapper",
363
- onMouseEnter: () => V(!0),
364
- onMouseLeave: () => V(!1),
363
+ onMouseEnter: () => B(!0),
364
+ onMouseLeave: () => B(!1),
365
365
  children: [/* @__PURE__ */ jsxs("div", {
366
366
  className: "_cppay-error-tooltip",
367
367
  children: [/* @__PURE__ */ jsx("svg", {
@@ -373,7 +373,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
373
373
  clipRule: "evenodd"
374
374
  })
375
375
  }), /* @__PURE__ */ jsx("span", { children: T })]
376
- }), Oe && /* @__PURE__ */ jsx("div", {
376
+ }), ke && /* @__PURE__ */ jsx("div", {
377
377
  className: "_cppay-error-tooltip-full",
378
378
  children: T
379
379
  })]
@@ -399,7 +399,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
399
399
  /* @__PURE__ */ jsxs("div", {
400
400
  className: "_cppay-section",
401
401
  children: [
402
- J && /* @__PURE__ */ jsx("div", {
402
+ q && /* @__PURE__ */ jsx("div", {
403
403
  className: "_cppay-info-box",
404
404
  children: /* @__PURE__ */ jsx("div", {
405
405
  className: "_cppay-info-flex-container",
@@ -407,10 +407,10 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
407
407
  className: "_cppay-info-flex-child",
408
408
  children: [/* @__PURE__ */ jsx("div", {
409
409
  className: "_cppay-info-label",
410
- children: p === "subscription" ? y.authorizationAmount : y.paymentAmount
410
+ children: f === "subscription" ? y.authorizationAmount : y.paymentAmount
411
411
  }), /* @__PURE__ */ jsxs("div", {
412
412
  className: "_cppay-info-value _cppay-info-value-flex",
413
- children: [/* @__PURE__ */ jsx("span", { children: p === "subscription" ? `${X(G.current.approveAmount, Y(J.symbol))} ${J.symbol}` : `${X(G.current.paymentAmount, Y(J.symbol))} ${J.symbol}` }), /* @__PURE__ */ jsxs("span", { children: ["≈ $", h] })]
413
+ children: [/* @__PURE__ */ jsx("span", { children: f === "subscription" ? `${Y(W.current.approveAmount, J(q.symbol))} ${q.symbol}` : `${Y(W.current.paymentAmount, J(q.symbol))} ${q.symbol}` }), /* @__PURE__ */ jsxs("span", { children: ["≈ $", m] })]
414
414
  })]
415
415
  })
416
416
  })
@@ -421,27 +421,27 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
421
421
  className: "_cppay-info-flex-child",
422
422
  children: [/* @__PURE__ */ jsxs("div", {
423
423
  className: "_cppay-info-label _cppay-info-label-flex",
424
- children: [/* @__PURE__ */ jsx("span", { children: p === "subscription" ? y.authorizationContractAddress : y.paymentAddress }), z && /* @__PURE__ */ jsxs("span", {
424
+ children: [/* @__PURE__ */ jsx("span", { children: f === "subscription" ? y.authorizationContractAddress : y.paymentAddress }), Ee && /* @__PURE__ */ jsxs("span", {
425
425
  className: "_cppay-countdown",
426
- children: ["⏰ ", z]
426
+ children: ["⏰ ", Ee]
427
427
  })]
428
428
  }), /* @__PURE__ */ jsxs("div", {
429
429
  className: "_cppay-address-row",
430
- children: [/* @__PURE__ */ jsx("code", { children: p === "subscription" ? G.current.spenderAddress : G.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
430
+ children: [/* @__PURE__ */ jsx("code", { children: f === "subscription" ? W.current.spenderAddress : W.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
431
431
  onClick: async () => {
432
- if (!G.current) return;
433
- let e = p === "subscription" ? G.current.spenderAddress : G.current.receiveAddress;
432
+ if (!W.current) return;
433
+ let e = f === "subscription" ? W.current.spenderAddress : W.current.receiveAddress;
434
434
  if (e) try {
435
- await navigator.clipboard.writeText(e), De(!0), setTimeout(() => {
436
- De(!1);
435
+ await navigator.clipboard.writeText(e), Oe(!0), setTimeout(() => {
436
+ Oe(!1);
437
437
  }, 2e3);
438
438
  } catch (e) {
439
439
  console.error("复制失败:", e);
440
440
  }
441
441
  },
442
- className: `_cppay-copy-btn ${B ? "_cppay-copy-success" : ""}`,
443
- title: B ? y.copied : y.copyAddress,
444
- children: B ? /* @__PURE__ */ jsx("svg", {
442
+ className: `_cppay-copy-btn ${z ? "_cppay-copy-success" : ""}`,
443
+ title: z ? y.copied : y.copyAddress,
444
+ children: z ? /* @__PURE__ */ jsx("svg", {
445
445
  className: "_cppay-copy-icon",
446
446
  viewBox: "0 0 24 24",
447
447
  fill: "currentColor",
@@ -465,7 +465,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
465
465
  })]
466
466
  })
467
467
  }),
468
- p === "subscription" && /* @__PURE__ */ jsxs("div", {
468
+ f === "subscription" && /* @__PURE__ */ jsxs("div", {
469
469
  className: "_cppay-info-box _cppay-subscription-box",
470
470
  children: [/* @__PURE__ */ jsx("div", {
471
471
  className: "_cppay-info-label _cppay-subscription-label",
@@ -479,8 +479,8 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
479
479
  }),
480
480
  T && /* @__PURE__ */ jsxs("div", {
481
481
  className: "_cppay-error-tooltip-wrapper",
482
- onMouseEnter: () => V(!0),
483
- onMouseLeave: () => V(!1),
482
+ onMouseEnter: () => B(!0),
483
+ onMouseLeave: () => B(!1),
484
484
  children: [/* @__PURE__ */ jsxs("div", {
485
485
  className: "_cppay-error-tooltip",
486
486
  children: [/* @__PURE__ */ jsx("svg", {
@@ -492,7 +492,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
492
492
  clipRule: "evenodd"
493
493
  })
494
494
  }), /* @__PURE__ */ jsx("span", { children: T })]
495
- }), Oe && /* @__PURE__ */ jsx("div", {
495
+ }), ke && /* @__PURE__ */ jsx("div", {
496
496
  className: "_cppay-error-tooltip-full",
497
497
  children: T
498
498
  })]
@@ -503,9 +503,9 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
503
503
  onClick: Ie,
504
504
  disabled: C,
505
505
  className: "_cppay-btn _cppay-btn-primary",
506
- children: C ? p === "subscription" ? y.authorizing : y.processing : p === "subscription" ? `💳 ${y.connectWallet}` : `💳 ${y.walletPay}`
506
+ children: C ? f === "subscription" ? y.authorizing : y.processing : f === "subscription" ? `💳 ${y.connectWallet}` : `💳 ${y.walletPay}`
507
507
  }), /* @__PURE__ */ jsxs("button", {
508
- onClick: ke,
508
+ onClick: Ae,
509
509
  disabled: C,
510
510
  className: "_cppay-btn _cppay-wallet-address-btn",
511
511
  title: y.clickToModifyWallet,
@@ -525,7 +525,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
525
525
  children: /* @__PURE__ */ jsx("polyline", { points: "6 9 12 15 18 9" })
526
526
  })]
527
527
  })] }) : /* @__PURE__ */ jsx("button", {
528
- onClick: ke,
528
+ onClick: Ae,
529
529
  disabled: F,
530
530
  className: "_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn",
531
531
  children: /* @__PURE__ */ jsx("span", { children: F ? y.processing : `💳 ${y.connectWallet}` })
@@ -553,22 +553,22 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
553
553
  ] })
554
554
  });
555
555
  }, PaymentDialog_default = ({ open: e, onClose: t, ott: n, apikey: i, plain: de, orderId: fe, amount: pe, intervalDays: a, locale: o, onExpired: me, onSuccess: he, onFailed: s, onError: ge, Slots: _e }) => {
556
- let [c, l] = useState("select"), u = useMemo(() => c !== "checking", [c]);
556
+ let [c, ve] = useState("select"), l = useMemo(() => c !== "checking", [c]);
557
557
  useEffect(() => {
558
- e || l("select");
558
+ e || ve("select");
559
559
  }, [e]), useEffect(() => {
560
560
  if (!e) return;
561
561
  let t = (e) => {
562
- e.key === "Escape" && u && d();
562
+ e.key === "Escape" && l && u();
563
563
  };
564
564
  return window.addEventListener("keydown", t), () => window.removeEventListener("keydown", t);
565
- }, [e, u]);
566
- let d = () => {
567
- u && t();
568
- }, f = useMemo(() => getLocaleMessages(o), [o]);
565
+ }, [e, l]);
566
+ let u = () => {
567
+ l && t();
568
+ }, d = useMemo(() => getLocaleMessages(o), [o]);
569
569
  return e ? /* @__PURE__ */ jsx("div", {
570
570
  className: "_cppay-overlay",
571
- onClick: (e) => e.target === e.currentTarget && d(),
571
+ onClick: (e) => e.target === e.currentTarget && u(),
572
572
  children: /* @__PURE__ */ jsxs("div", {
573
573
  className: "_cppay-dialog",
574
574
  children: [/* @__PURE__ */ jsxs("div", {
@@ -577,18 +577,18 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
577
577
  className: "_cppay-title",
578
578
  children: (() => {
579
579
  switch (c) {
580
- case "success": return f.paymentResult;
581
- case "expired": return f.paymentExpired;
582
- case "failed": return f.paymentFailed;
583
- case "error": return f.error;
580
+ case "success": return d.paymentResult;
581
+ case "expired": return d.paymentExpired;
582
+ case "failed": return d.paymentFailed;
583
+ case "error": return d.error;
584
584
  case "payment":
585
- case "checking": return f.completePayment;
586
- default: return f.selectPaymentMethod;
585
+ case "checking": return d.completePayment;
586
+ default: return d.selectPaymentMethod;
587
587
  }
588
588
  })()
589
589
  }), /* @__PURE__ */ jsx("button", {
590
- onClick: d,
591
- disabled: !u,
590
+ onClick: u,
591
+ disabled: !l,
592
592
  className: "_cppay-close-btn",
593
593
  children: /* @__PURE__ */ jsx("svg", {
594
594
  fill: "none",
@@ -615,7 +615,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: p, orderId: m, amount:
615
615
  onFailed: s,
616
616
  onError: ge,
617
617
  Slots: _e,
618
- onPaymentStepChange: l
618
+ onPaymentStepChange: ve
619
619
  })]
620
620
  })
621
621
  }) : null;
package/dist/vue.cjs CHANGED
@@ -1 +1 @@
1
- const e=require(`./locales-DfK0OLJI.cjs`),t=require(`./cppay-B52ulQGn.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={key:0,class:`_cppay-state-container`},ee={class:`_cppay-state-title`},te={class:`_cppay-state-message`},ne={key:1,class:`_cppay-state-container`},re={class:`_cppay-state-title`},f=[`disabled`],ie={key:2,class:`_cppay-state-container`},ae={class:`_cppay-state-title`},oe={key:3,class:`_cppay-state-container`},se={class:`_cppay-state-title`},ce={key:4},le={class:`_cppay-section`},ue={class:`_cppay-label`},de={class:`_cppay-grid`},fe=[`onClick`],pe=[`src`,`alt`],me={class:`_cppay-section`},he={class:`_cppay-label`},ge={class:`_cppay-grid`},_e=[`onClick`],ve=[`src`,`alt`],ye={class:`_cppay-section`},be={class:`_cppay-price-box`},xe={class:`_cppay-price-row`},Se={class:`_cppay-price-label`},Ce={class:`_cppay-price-amount`},we={class:`_cppay-price-main`},Te={class:`_cppay-price-sub`},Ee={class:`_cppay-section`},De={class:`_cppay-error-tooltip`},Oe={key:0,class:`_cppay-error-tooltip-full`},ke=[`disabled`],Ae={key:5},je={class:`_cppay-qr-container`},Me={class:`_cppay-qr-code`},Ne=[`src`],Pe={class:`_cppay-section`},Fe={key:0,class:`_cppay-info-box`},p={class:`_cppay-info-flex-container`},m={class:`_cppay-info-flex-child`},h={class:`_cppay-info-label`},g={class:`_cppay-info-value _cppay-info-value-flex`},_={key:0},v={class:`_cppay-info-box`},Ie={class:`_cppay-info-flex-child`},Le={class:`_cppay-info-label _cppay-info-label-flex`},Re={key:0,class:`_cppay-countdown`},ze={class:`_cppay-address-row`},Be={key:0},Ve=[`title`],He={key:0,class:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},Ue={key:1,class:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`currentColor`},We={key:1,class:`_cppay-info-box _cppay-subscription-box`},Ge={class:`_cppay-info-label _cppay-subscription-label`},Ke={class:`_cppay-info-value _cppay-subscription-message`},qe={class:`_cppay-error-tooltip`},Je={key:0,class:`_cppay-error-tooltip-full`},Ye={key:1,class:`_cppay-section`},Xe=[`disabled`],Ze=[`disabled`],Qe=[`disabled`,`title`],$e={class:`_cppay-wallet-address-text`},et={class:`_cppay-section`},tt=[`disabled`],nt={class:`_cppay-section`},rt=[`disabled`],y=(0,n.defineComponent)({__name:`PaymentContent`,props:{apikey:{},orderId:{},amount:{},plain:{},intervalDays:{},slots:{},locale:{}},emits:[`update:paymentStep`,`success`,`expired`,`failed`,`error`],setup(y,{emit:b}){let x=y,S=b,C=(0,n.computed)(()=>e.t(x.locale)),w=new t.t(x.apikey),T=(0,n.ref)(`select`),E=(0,n.ref)(!1),D=(0,n.computed)(()=>T.value===`checking`),O=(0,n.ref)(),k=(0,n.ref)([]),A=(0,n.ref)(),j=(0,n.ref)(),M=(0,n.ref)(),N=(0,n.ref)(),P=(0,n.ref)(!1),F=(0,n.ref)(),I=(0,n.ref)(``),L=(0,n.ref)(!1),R=(0,n.ref)(!1),z=(0,n.shallowRef)(null),B=(0,n.ref)(null),V=(0,n.ref)(null),H=(0,n.ref)(null),it=()=>{typeof window<`u`&&!z.value&&(z.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}}),N.value=z.value.getAddress(),F.value=z.value.getProvider(`eip155`),z.value.subscribeAccount(e=>{e.isConnected?N.value=e.address:(N.value=void 0,F.value=void 0)}),z.value.subscribeProviders(e=>{F.value=e?.eip155}))};(0,n.watch)(T,e=>{S(`update:paymentStep`,e)});let U=async()=>{try{P.value=!0,O.value=void 0,z.value&&await z.value.open()}catch(e){O.value=e instanceof Error?e.message:C.value.walletConnectionFailed,S(`error`,e)}finally{P.value=!1}},W=(0,n.computed)(()=>k.value.find(e=>e.chain===A.value)),G=(0,n.computed)(()=>W.value?.tokens||[]),K=(0,n.computed)(()=>G.value.find(e=>e.symbol===j.value)),q=e=>[`USDT`,`USDC`,`BUSD`,`DAI`,`TUSD`,`USDD`,`FDUSD`].includes(e.toUpperCase())?2:6,J=(e,t)=>{let n=parseFloat(e);return isNaN(n)?`0`:n.toFixed(t).replace(/\.?0+$/,``)},at=e=>{if(e<=0)return C.value.expired;let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=e%60;return t>0?`${t}${C.value.hours}${n}${C.value.minutes}${r}${C.value.seconds}`:`${n}${C.value.minutes}${r}${C.value.seconds}`},Y=e=>{V.value&&clearInterval(V.value);let t=()=>{if(T.value===`checking`){X();return}let t=e-Math.floor(Date.now()/1e3);I.value=at(t),t<=0&&(T.value=`expired`,X())};t(),V.value=setInterval(t,1e3)},X=()=>{V.value&&=(clearInterval(V.value),null)},Z=(0,n.computed)(()=>{if(!j.value||!K.value)return`0`;let e=parseFloat(K.value.price);if(isNaN(e)||e===0)return`0`;let t=q(j.value);return J((parseFloat(x.amount)/e).toFixed(t),t)}),ot=async()=>{try{E.value=!0,O.value=void 0,k.value=await w.getSupportedChains(),k.value.length>0&&(A.value=k.value[0].chain)}catch(e){O.value=e instanceof Error?e.message:C.value.loadPaymentNetworkFailed,S(`error`,e)}finally{E.value=!1}},Q=async e=>{if(F.value)try{await F.value.request({method:`wallet_switchEthereumChain`,params:[{chainId:`0x${e.toString(16)}`}]})}catch(e){throw e.code===4902?Error(C.value.pleaseAddNetwork):e}},st=async()=>{if(!(!N.value||!F.value||!H.value||!K.value||!W.value))try{E.value=!0;let e=H.value;await Q(W.value.chainId);let t=(0,o.createWalletClient)({account:N.value,transport:(0,o.custom)(F.value)});if(K.value.address){let n=await t.writeContract({address:K.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,K.value.decimals)],chain:null});console.log(`转账交易哈希:`,n)}else{let n=await t.sendTransaction({to:e.receiveAddress,value:(0,o.parseUnits)(e.paymentAmount,K.value.decimals),chain:null});console.log(`转账交易哈希:`,n)}E.value=!1,T.value=`checking`}catch(e){console.error(`钱包支付失败:`,e),O.value=e instanceof Error?e.message:C.value.walletPaymentFailed,S(`error`,e),E.value=!1}},ct=async()=>{if(!(!N.value||!F.value||!H.value||!K.value||!W.value))try{let e=H.value;await Q(W.value.chainId);let t=(0,o.createWalletClient)({account:N.value,transport:(0,o.custom)(F.value)});if(!K.value.address)throw Error(C.value.subscriptionDoesNotSupportNative);let n=await t.writeContract({address:K.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,K.value.decimals)],chain:null});console.log(`授权交易哈希:`,n),E.value=!1,T.value=`checking`}catch(e){console.error(`钱包授权失败:`,e),O.value=e instanceof Error?e.message:C.value.walletPaymentFailed,S(`error`,e),E.value=!1}},lt=async()=>{if(!N.value){O.value=C.value.pleaseConnectWallet,S(`error`,Error(C.value.pleaseConnectWallet));return}x.plain===`instant`?await st():x.plain===`subscription`&&await ct()},ut=async()=>{if(!(!A.value||!j.value))try{O.value=void 0;let e=``;x.plain===`instant`?(H.value=await w.createOnetimePayment({paymentChain:A.value,paymentToken:j.value,orderId:x.orderId,amount:Z.value}),e=`${A.value.toLowerCase()}:${H.value.receiveAddress}?amount=${H.value.paymentAmount}`,Y(H.value.expireAt),$({paymentId:H.value.paymentId})):x.plain===`subscription`&&(H.value=await w.createSubscriptionPayment({paymentChain:A.value,paymentToken:j.value,orderId:x.orderId,amountOfUsd:Z.value,intervalDays:x.intervalDays||30}),e=`${A.value.toLowerCase()}:${H.value.spenderAddress}?amount=${H.value.approveAmount}`,Y(H.value.expireAt),$({subscriptionId:H.value.subscriptionId})),T.value=`payment`,M.value=await r.toDataURL(e,{width:200,margin:2,errorCorrectionLevel:`H`})}catch(e){O.value=e instanceof Error?e.message:C.value.createPaymentFailed,S(`error`,e)}},dt=()=>{H.value&&(O.value=void 0,T.value=`checking`)},$=e=>{B.value?.unsubscribe();let t=()=>(0,i.defer)(()=>x.plain===`subscription`?w.checkSubscriptionPaymentStatus(e):w.checkOnetimePaymentStatus(e)).pipe((0,a.timeout)(15e3),(0,a.retry)({delay:2e3}));B.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=>{(e.status===`paid`||e.status===`approved`)&&(T.value=`success`,S(`success`,e)),e.status===`expired`&&(T.value=`expired`,S(`expired`,e)),e.status===`failed`&&(T.value=`failed`,S(`failed`,e))})).subscribe({error:e=>{if(H.value){let t=e instanceof Error?e.message:C.value.checkPaymentStatusFailed;T.value=`error`,O.value=t,S(`error`,e)}},complete:()=>{B.value?.unsubscribe()}})},ft=async()=>{if(!H.value)return;let e=x.plain===`subscription`?H.value.spenderAddress:H.value.receiveAddress;if(e)try{await navigator.clipboard.writeText(e),L.value=!0,setTimeout(()=>{L.value=!1},2e3)}catch(e){console.error(`复制失败:`,e)}};return(0,n.watch)(G,e=>{e.length>0&&(j.value=e[0].symbol)}),(0,n.onMounted)(()=>{it(),k.value.length||ot(),x.orderId&&$({orderId:x.orderId})}),(0,n.onUnmounted)(()=>{B.value?.unsubscribe(),X()}),(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`div`,u,[T.value===`success`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,d,[t[6]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-icon`},`✅`,-1),(0,n.createElementVNode)(`h3`,ee,(0,n.toDisplayString)(y.plain===`subscription`?C.value.authorizationSuccess:C.value.paymentSuccess),1),(0,n.createElementVNode)(`p`,te,(0,n.toDisplayString)(y.plain===`subscription`?C.value.subscriptionActivated:C.value.transactionCompleted),1)])):T.value===`expired`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,ne,[t[7]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-icon`},`⏰`,-1),(0,n.createElementVNode)(`h3`,re,(0,n.toDisplayString)(C.value.paymentExpired),1),(0,n.createElementVNode)(`button`,{onClick:t[0]||=e=>T.value=`select`,disabled:E.value||D.value,class:`_cppay-btn _cppay-btn-text`},(0,n.toDisplayString)(C.value.returnButton),9,f)])):T.value===`error`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,ie,[t[8]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-icon`},`❌`,-1),(0,n.createElementVNode)(`h3`,ae,(0,n.toDisplayString)(C.value.checking),1)])):T.value===`failed`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,oe,[t[9]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-icon`},`❌`,-1),(0,n.createElementVNode)(`h3`,se,(0,n.toDisplayString)(C.value.paymentFailed),1)])):T.value===`select`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,ce,[(0,n.renderSlot)(e.$slots,`choose-top`),(0,n.createElementVNode)(`div`,le,[(0,n.createElementVNode)(`label`,ue,(0,n.toDisplayString)(C.value.paymentNetwork),1),(0,n.createElementVNode)(`div`,de,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(k.value,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.chain,onClick:t=>A.value=e.chain,class:(0,n.normalizeClass)([`_cppay-select-btn`,{"_cppay-selected":A.value===e.chain}])},[e.icon?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.chain},null,8,pe)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.chain),1)],10,fe))),128))])]),(0,n.createElementVNode)(`div`,me,[(0,n.createElementVNode)(`label`,he,(0,n.toDisplayString)(C.value.paymentToken),1),(0,n.createElementVNode)(`div`,ge,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(G.value,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.symbol,onClick:t=>j.value=e.symbol,class:(0,n.normalizeClass)([`_cppay-select-btn`,{"_cppay-selected":j.value===e.symbol}])},[e.icon?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.symbol},null,8,ve)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.symbol),1)],10,_e))),128))])]),(0,n.renderSlot)(e.$slots,`choose-bottom`),(0,n.createElementVNode)(`div`,ye,[(0,n.createElementVNode)(`div`,be,[(0,n.createElementVNode)(`div`,xe,[(0,n.createElementVNode)(`span`,Se,(0,n.toDisplayString)(C.value.paymentAmount),1),(0,n.createElementVNode)(`div`,Ce,[(0,n.createElementVNode)(`div`,we,(0,n.toDisplayString)(Z.value??`-`)+` `+(0,n.toDisplayString)(j.value??``),1),(0,n.createElementVNode)(`div`,Te,`≈ $`+(0,n.toDisplayString)(y.amount),1)])])])]),(0,n.createElementVNode)(`div`,Ee,[O.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:0,class:`_cppay-error-tooltip-wrapper`,onMouseenter:t[1]||=e=>R.value=!0,onMouseleave:t[2]||=e=>R.value=!1},[(0,n.createElementVNode)(`div`,De,[t[10]||=(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)(O.value),1)]),R.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Oe,(0,n.toDisplayString)(O.value),1)):(0,n.createCommentVNode)(``,!0)],32)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`button`,{onClick:ut,disabled:!A.value||!j.value||E.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(E.value?C.value.processing:C.value.continuePayment),9,ke)])])):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Ae,[(0,n.createElementVNode)(`div`,je,[(0,n.createElementVNode)(`div`,Me,[M.value?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:M.value,alt:`Payment QR Code`,class:`_cppay-qr-image`},null,8,Ne)):(0,n.createCommentVNode)(``,!0)])]),(0,n.createElementVNode)(`div`,Pe,[K.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Fe,[(0,n.createElementVNode)(`div`,p,[(0,n.createElementVNode)(`div`,m,[(0,n.createElementVNode)(`div`,h,(0,n.toDisplayString)(y.plain===`subscription`?C.value.authorizationAmount:C.value.paymentAmount),1),(0,n.createElementVNode)(`div`,g,[H.value?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,_,(0,n.toDisplayString)(y.plain===`subscription`?`${J(H.value.approveAmount,q(K.value.symbol))} ${K.value.symbol}`:`${J(H.value.paymentAmount,q(K.value.symbol))} ${K.value.symbol}`),1)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,`≈ $`+(0,n.toDisplayString)(y.amount),1)])])])])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,v,[(0,n.createElementVNode)(`div`,Ie,[(0,n.createElementVNode)(`div`,Le,[(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(y.plain===`subscription`?C.value.authorizationContractAddress:C.value.paymentAddress),1),I.value?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,Re,`⏰ `+(0,n.toDisplayString)(I.value),1)):(0,n.createCommentVNode)(``,!0)]),(0,n.createElementVNode)(`div`,ze,[H.value?((0,n.openBlock)(),(0,n.createElementBlock)(`code`,Be,(0,n.toDisplayString)(y.plain===`subscription`?H.value.spenderAddress:H.value.receiveAddress),1)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`button`,{onClick:ft,class:(0,n.normalizeClass)([`_cppay-copy-btn`,{"_cppay-copy-success":L.value}]),title:L.value?C.value.copied:C.value.copyAddress},[L.value?((0,n.openBlock)(),(0,n.createElementBlock)(`svg`,Ue,[...t[12]||=[(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`,He,[...t[11]||=[(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,Ve)])])]),y.plain===`subscription`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,We,[(0,n.createElementVNode)(`div`,Ge,(0,n.toDisplayString)(C.value.subscriptionNotice),1),(0,n.createElementVNode)(`div`,Ke,(0,n.toDisplayString)(C.value.subscriptionNoticeMessage),1)])):(0,n.createCommentVNode)(``,!0)]),O.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:0,class:`_cppay-error-tooltip-wrapper`,onMouseenter:t[3]||=e=>R.value=!0,onMouseleave:t[4]||=e=>R.value=!1},[(0,n.createElementVNode)(`div`,qe,[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)(O.value),1)]),R.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Je,(0,n.toDisplayString)(O.value),1)):(0,n.createCommentVNode)(``,!0)],32)):(0,n.createCommentVNode)(``,!0),D.value?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Ye,[N.value?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:1},[(0,n.createElementVNode)(`button`,{onClick:lt,disabled:E.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(E.value?y.plain===`subscription`?C.value.authorizing:C.value.processing:(y.plain,C.value.walletPay)),9,Ze),(0,n.createElementVNode)(`button`,{onClick:U,disabled:E.value,class:`_cppay-btn _cppay-wallet-address-btn`,title:C.value.clickToModifyWallet},[(0,n.createElementVNode)(`span`,$e,(0,n.toDisplayString)(N.value.slice(0,10))+`...`+(0,n.toDisplayString)(N.value.slice(-4)),1),t[14]||=(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,Qe)],64)):((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:0,onClick:U,disabled:P.value,class:`_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn`},[(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(P.value?C.value.processing:C.value.connectWallet),1)],8,Xe))])),(0,n.createElementVNode)(`div`,et,[(0,n.createElementVNode)(`button`,{onClick:dt,disabled:D.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(D.value?C.value.checking:C.value.completedPayment),9,tt)]),t[15]||=(0,n.createElementVNode)(`hr`,{class:`_cppay-divider`},null,-1),(0,n.createElementVNode)(`div`,nt,[(0,n.createElementVNode)(`button`,{onClick:t[5]||=e=>T.value=`select`,disabled:E.value||D.value,class:`_cppay-btn _cppay-btn-text`},(0,n.toDisplayString)(C.value.changePaymentMethod),9,rt)])]))]))}}),b=y,x={class:`_cppay-dialog`},S={class:`_cppay-header`},C={class:`_cppay-title`},w=[`disabled`],T=(0,n.defineComponent)({__name:`PaymentDialog`,props:{modelValue:{type:Boolean},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`,x,[(0,n.createElementVNode)(`div`,S,[(0,n.createElementVNode)(`h2`,C,(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,w)]),t.modelValue?((0,n.openBlock)(),(0,n.createBlock)(b,{key:0,apikey:t.apikey,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`)]),_:3},8,[`apikey`,`orderId`,`amount`,`plain`,`intervalDays`,`locale`])):(0,n.createCommentVNode)(``,!0)])])):(0,n.createCommentVNode)(``,!0)}}),E=T,D=(0,n.ref)({apikey:``,open:!1,options:null});const O=e=>{D.value.options=e,D.value.open=!0},k=()=>{D.value.open=!1};var A=()=>{D.value.open=!1},j=e=>{D.value.options?.onSuccess?.(e),setTimeout(()=>{D.value.open=!1},1e3)},M=e=>{D.value.options?.onExpired?.(e)},N=e=>{D.value.options?.onFailed?.(e)},P=e=>{D.value.options?.onError?.(e)};const F={install(e,t){if(!t?.apikey)throw Error(`Cppay plugin requires an apikey`);D.value.apikey=t.apikey,e.config.globalProperties.$showPayment=O,e.config.globalProperties.$closePayment=k;let r=e=>{e.key===`Escape`&&D.value.open&&A()},i=document.createElement(`div`);document.body.appendChild(i),(0,n.createApp)({setup(){return()=>D.value.options?(0,n.h)(E,{modelValue:D.value.open,"onUpdate:modelValue":e=>{D.value.open=e,e||A()},apikey:D.value.apikey,plain:D.value.options.plain,orderId:D.value.options.orderId,amount:D.value.options.amount,intervalDays:D.value.options.intervalDays,onSuccess:j,onExpired:M,onFailed:N,onError:P}):null}}).mount(i),D.value.open&&document.addEventListener(`keydown`,r),e.config.globalProperties.$watchEffect?.(()=>{D.value.open?document.addEventListener(`keydown`,r):document.removeEventListener(`keydown`,r)})}},I=()=>{if(!D.value.apikey)throw Error(`useCppayPayment must be used after installing CppayPlugin`);return{showPayment:O,closePayment:k}};e.n(e.r),exports.CppayPlugin=F,exports.PaymentContent=b,exports.PaymentDialog=E,exports.showPayment=O,exports.useCppayPayment=I;
1
+ const e=require(`./locales-DfK0OLJI.cjs`),t=require(`./cppay-UdGae-e8.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`},te={class:`_cppay-state-message`},ne={class:`_cppay-state-container`},re={class:`_cppay-state-title`},f=[`disabled`],ie={class:`_cppay-state-container`},ae={class:`_cppay-state-title`},oe={class:`_cppay-state-container`},se={class:`_cppay-state-title`},ce={key:4},le={class:`_cppay-section`},ue={class:`_cppay-label`},de={class:`_cppay-grid`},fe=[`onClick`],pe=[`src`,`alt`],me={class:`_cppay-section`},he={class:`_cppay-label`},ge={class:`_cppay-grid`},_e=[`onClick`],ve=[`src`,`alt`],ye={class:`_cppay-section`},be={class:`_cppay-price-box`},xe={class:`_cppay-price-row`},Se={class:`_cppay-price-label`},Ce={class:`_cppay-price-amount`},we={class:`_cppay-price-main`},Te={class:`_cppay-price-sub`},Ee={class:`_cppay-section`},De={class:`_cppay-error-tooltip`},Oe={key:0,class:`_cppay-error-tooltip-full`},ke=[`disabled`],Ae={key:5},je={class:`_cppay-qr-container`},Me={class:`_cppay-qr-code`},Ne=[`src`],Pe={class:`_cppay-section`},Fe={key:0,class:`_cppay-info-box`},p={class:`_cppay-info-flex-container`},m={class:`_cppay-info-flex-child`},h={class:`_cppay-info-label`},g={class:`_cppay-info-value _cppay-info-value-flex`},_={key:0},v={class:`_cppay-info-box`},Ie={class:`_cppay-info-flex-child`},Le={class:`_cppay-info-label _cppay-info-label-flex`},Re={key:0,class:`_cppay-countdown`},ze={class:`_cppay-address-row`},Be={key:0},Ve=[`title`],He={key:0,class:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},Ue={key:1,class:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`currentColor`},We={key:1,class:`_cppay-info-box _cppay-subscription-box`},Ge={class:`_cppay-info-label _cppay-subscription-label`},Ke={class:`_cppay-info-value _cppay-subscription-message`},qe={class:`_cppay-error-tooltip`},Je={key:0,class:`_cppay-error-tooltip-full`},Ye={key:1,class:`_cppay-section`},Xe=[`disabled`],Ze=[`disabled`],Qe=[`disabled`,`title`],$e={class:`_cppay-wallet-address-text`},et={class:`_cppay-section`},tt=[`disabled`],nt={class:`_cppay-section`},rt=[`disabled`],y=(0,n.defineComponent)({__name:`PaymentContent`,props:{apikey:{},ott:{},orderId:{},amount:{},plain:{},intervalDays:{},slots:{},locale:{}},emits:[`update:paymentStep`,`success`,`expired`,`failed`,`error`],setup(y,{emit:b}){let x=y,S=b,C=(0,n.computed)(()=>e.t(x.locale)),w=(0,n.computed)(()=>new t.t(x.apikey,x.ott)),T=(0,n.ref)(`select`),E=(0,n.ref)(!1),D=(0,n.computed)(()=>T.value===`checking`),O=(0,n.ref)(),k=(0,n.ref)([]),A=(0,n.ref)(),j=(0,n.ref)(),M=(0,n.ref)(),N=(0,n.ref)(),P=(0,n.ref)(!1),F=(0,n.ref)(),I=(0,n.ref)(``),L=(0,n.ref)(!1),R=(0,n.ref)(!1),z=(0,n.shallowRef)(null),B=(0,n.ref)(null),V=(0,n.ref)(null),H=(0,n.ref)(null),it=()=>{typeof window<`u`&&!z.value&&(z.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}}),N.value=z.value.getAddress(),F.value=z.value.getProvider(`eip155`),z.value.subscribeAccount(e=>{e.isConnected?N.value=e.address:(N.value=void 0,F.value=void 0)}),z.value.subscribeProviders(e=>{F.value=e?.eip155}))};(0,n.watch)(T,e=>{S(`update:paymentStep`,e)});let U=async()=>{try{P.value=!0,O.value=void 0,z.value&&await z.value.open()}catch(e){O.value=e instanceof Error?e.message:C.value.walletConnectionFailed,S(`error`,e)}finally{P.value=!1}},W=(0,n.computed)(()=>k.value.find(e=>e.chain===A.value)),G=(0,n.computed)(()=>W.value?.tokens||[]),K=(0,n.computed)(()=>G.value.find(e=>e.symbol===j.value)),q=e=>[`USDT`,`USDC`,`BUSD`,`DAI`,`TUSD`,`USDD`,`FDUSD`].includes(e.toUpperCase())?2:6,J=(e,t)=>{let n=parseFloat(e);return isNaN(n)?`0`:n.toFixed(t).replace(/\.?0+$/,``)},at=e=>{if(e<=0)return C.value.expired;let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=e%60;return t>0?`${t}${C.value.hours}${n}${C.value.minutes}${r}${C.value.seconds}`:`${n}${C.value.minutes}${r}${C.value.seconds}`},Y=e=>{V.value&&clearInterval(V.value);let t=()=>{if(T.value===`checking`){X();return}let t=e-Math.floor(Date.now()/1e3);I.value=at(t),t<=0&&(T.value=`expired`,X())};t(),V.value=setInterval(t,1e3)},X=()=>{V.value&&=(clearInterval(V.value),null)},Z=(0,n.computed)(()=>{if(!j.value||!K.value)return`0`;let e=parseFloat(K.value.price);if(isNaN(e)||e===0)return`0`;let t=q(j.value);return J((parseFloat(x.amount)/e).toFixed(t),t)}),ot=async()=>{try{E.value=!0,O.value=void 0,k.value=await w.value.getSupportedChains(),k.value.length>0&&(A.value=k.value[0].chain)}catch(e){O.value=e instanceof Error?e.message:C.value.loadPaymentNetworkFailed,S(`error`,e)}finally{E.value=!1}},Q=async e=>{if(F.value)try{await F.value.request({method:`wallet_switchEthereumChain`,params:[{chainId:`0x${e.toString(16)}`}]})}catch(e){throw e.code===4902?Error(C.value.pleaseAddNetwork):e}},st=async()=>{if(!(!N.value||!F.value||!H.value||!K.value||!W.value))try{E.value=!0;let e=H.value;await Q(W.value.chainId);let t=(0,o.createWalletClient)({account:N.value,transport:(0,o.custom)(F.value)});if(K.value.address){let n=await t.writeContract({address:K.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,K.value.decimals)],chain:null});console.log(`转账交易哈希:`,n)}else{let n=await t.sendTransaction({to:e.receiveAddress,value:(0,o.parseUnits)(e.paymentAmount,K.value.decimals),chain:null});console.log(`转账交易哈希:`,n)}E.value=!1,T.value=`checking`}catch(e){console.error(`钱包支付失败:`,e),O.value=e instanceof Error?e.message:C.value.walletPaymentFailed,S(`error`,e),E.value=!1}},ct=async()=>{if(!(!N.value||!F.value||!H.value||!K.value||!W.value))try{let e=H.value;await Q(W.value.chainId);let t=(0,o.createWalletClient)({account:N.value,transport:(0,o.custom)(F.value)});if(!K.value.address)throw Error(C.value.subscriptionDoesNotSupportNative);let n=await t.writeContract({address:K.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,K.value.decimals)],chain:null});console.log(`授权交易哈希:`,n),E.value=!1,T.value=`checking`}catch(e){console.error(`钱包授权失败:`,e),O.value=e instanceof Error?e.message:C.value.walletPaymentFailed,S(`error`,e),E.value=!1}},lt=async()=>{if(!N.value){O.value=C.value.pleaseConnectWallet,S(`error`,Error(C.value.pleaseConnectWallet));return}x.plain===`instant`?await st():x.plain===`subscription`&&await ct()},ut=async()=>{if(!(!A.value||!j.value))try{O.value=void 0;let e=``;x.plain===`instant`?(H.value=await w.value.createOnetimePayment({paymentChain:A.value,paymentToken:j.value,orderId:x.orderId,amount:Z.value}),e=`${A.value.toLowerCase()}:${H.value.receiveAddress}?amount=${H.value.paymentAmount}`,Y(H.value.expireAt),$({paymentId:H.value.paymentId})):x.plain===`subscription`&&(H.value=await w.value.createSubscriptionPayment({paymentChain:A.value,paymentToken:j.value,orderId:x.orderId,amountOfUsd:Z.value,intervalDays:x.intervalDays||30}),e=`${A.value.toLowerCase()}:${H.value.spenderAddress}?amount=${H.value.approveAmount}`,Y(H.value.expireAt),$({subscriptionId:H.value.subscriptionId})),T.value=`payment`,M.value=await r.toDataURL(e,{width:200,margin:2,errorCorrectionLevel:`H`})}catch(e){O.value=e instanceof Error?e.message:C.value.createPaymentFailed,S(`error`,e)}},dt=()=>{H.value&&(O.value=void 0,T.value=`checking`)},$=e=>{B.value?.unsubscribe();let t=()=>(0,i.defer)(()=>x.plain===`subscription`?w.value.checkSubscriptionPaymentStatus(e):w.value.checkOnetimePaymentStatus(e)).pipe((0,a.timeout)(15e3),(0,a.retry)({delay:2e3}));B.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=>{(e.status===`paid`||e.status===`approved`)&&(T.value=`success`,S(`success`,e)),e.status===`expired`&&(T.value=`expired`,S(`expired`,e)),e.status===`failed`&&(T.value=`failed`,S(`failed`,e))})).subscribe({error:e=>{if(H.value){let t=e instanceof Error?e.message:C.value.checkPaymentStatusFailed;T.value=`error`,O.value=t,S(`error`,e)}},complete:()=>{B.value?.unsubscribe()}})},ft=async()=>{if(!H.value)return;let e=x.plain===`subscription`?H.value.spenderAddress:H.value.receiveAddress;if(e)try{await navigator.clipboard.writeText(e),L.value=!0,setTimeout(()=>{L.value=!1},2e3)}catch(e){console.error(`复制失败:`,e)}};return(0,n.watch)(G,e=>{e.length>0&&(j.value=e[0].symbol)}),(0,n.onMounted)(()=>{it(),k.value.length||ot(),x.orderId&&$({orderId:x.orderId})}),(0,n.onUnmounted)(()=>{B.value?.unsubscribe(),X()}),(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`div`,u,[T.value===`success`?(0,n.renderSlot)(e.$slots,`success`,{key:0},()=>[(0,n.createElementVNode)(`div`,d,[t[6]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-icon`},`✅`,-1),(0,n.createElementVNode)(`h3`,ee,(0,n.toDisplayString)(y.plain===`subscription`?C.value.authorizationSuccess:C.value.paymentSuccess),1),(0,n.createElementVNode)(`p`,te,(0,n.toDisplayString)(y.plain===`subscription`?C.value.subscriptionActivated:C.value.transactionCompleted),1)])]):T.value===`expired`?(0,n.renderSlot)(e.$slots,`expired`,{key:1},()=>[(0,n.createElementVNode)(`div`,ne,[t[7]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-icon`},`⏰`,-1),(0,n.createElementVNode)(`h3`,re,(0,n.toDisplayString)(C.value.paymentExpired),1),(0,n.createElementVNode)(`button`,{onClick:t[0]||=e=>T.value=`select`,disabled:E.value||D.value,class:`_cppay-btn _cppay-btn-text`},(0,n.toDisplayString)(C.value.returnButton),9,f)])]):T.value===`error`?(0,n.renderSlot)(e.$slots,`error`,{key:2},()=>[(0,n.createElementVNode)(`div`,ie,[t[8]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-icon`},`❌`,-1),(0,n.createElementVNode)(`h3`,ae,(0,n.toDisplayString)(C.value.checking),1)])]):T.value===`failed`?(0,n.renderSlot)(e.$slots,`failed`,{key:3},()=>[(0,n.createElementVNode)(`div`,oe,[t[9]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-icon`},`❌`,-1),(0,n.createElementVNode)(`h3`,se,(0,n.toDisplayString)(C.value.paymentFailed),1)])]):T.value===`select`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,ce,[(0,n.renderSlot)(e.$slots,`choose-top`),(0,n.createElementVNode)(`div`,le,[(0,n.createElementVNode)(`label`,ue,(0,n.toDisplayString)(C.value.paymentNetwork),1),(0,n.createElementVNode)(`div`,de,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(k.value,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.chain,onClick:t=>A.value=e.chain,class:(0,n.normalizeClass)([`_cppay-select-btn`,{"_cppay-selected":A.value===e.chain}])},[e.icon?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.chain},null,8,pe)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.chain),1)],10,fe))),128))])]),(0,n.createElementVNode)(`div`,me,[(0,n.createElementVNode)(`label`,he,(0,n.toDisplayString)(C.value.paymentToken),1),(0,n.createElementVNode)(`div`,ge,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(G.value,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.symbol,onClick:t=>j.value=e.symbol,class:(0,n.normalizeClass)([`_cppay-select-btn`,{"_cppay-selected":j.value===e.symbol}])},[e.icon?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.symbol},null,8,ve)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.symbol),1)],10,_e))),128))])]),(0,n.renderSlot)(e.$slots,`choose-bottom`),(0,n.createElementVNode)(`div`,ye,[(0,n.createElementVNode)(`div`,be,[(0,n.createElementVNode)(`div`,xe,[(0,n.createElementVNode)(`span`,Se,(0,n.toDisplayString)(C.value.paymentAmount),1),(0,n.createElementVNode)(`div`,Ce,[(0,n.createElementVNode)(`div`,we,(0,n.toDisplayString)(Z.value??`-`)+` `+(0,n.toDisplayString)(j.value??``),1),(0,n.createElementVNode)(`div`,Te,`≈ $`+(0,n.toDisplayString)(y.amount),1)])])])]),(0,n.createElementVNode)(`div`,Ee,[O.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:0,class:`_cppay-error-tooltip-wrapper`,onMouseenter:t[1]||=e=>R.value=!0,onMouseleave:t[2]||=e=>R.value=!1},[(0,n.createElementVNode)(`div`,De,[t[10]||=(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)(O.value),1)]),R.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Oe,(0,n.toDisplayString)(O.value),1)):(0,n.createCommentVNode)(``,!0)],32)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`button`,{onClick:ut,disabled:!A.value||!j.value||E.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(E.value?C.value.processing:C.value.continuePayment),9,ke)])])):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Ae,[(0,n.createElementVNode)(`div`,je,[(0,n.createElementVNode)(`div`,Me,[M.value?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:M.value,alt:`Payment QR Code`,class:`_cppay-qr-image`},null,8,Ne)):(0,n.createCommentVNode)(``,!0)])]),(0,n.createElementVNode)(`div`,Pe,[K.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Fe,[(0,n.createElementVNode)(`div`,p,[(0,n.createElementVNode)(`div`,m,[(0,n.createElementVNode)(`div`,h,(0,n.toDisplayString)(y.plain===`subscription`?C.value.authorizationAmount:C.value.paymentAmount),1),(0,n.createElementVNode)(`div`,g,[H.value?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,_,(0,n.toDisplayString)(y.plain===`subscription`?`${J(H.value.approveAmount,q(K.value.symbol))} ${K.value.symbol}`:`${J(H.value.paymentAmount,q(K.value.symbol))} ${K.value.symbol}`),1)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,`≈ $`+(0,n.toDisplayString)(y.amount),1)])])])])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,v,[(0,n.createElementVNode)(`div`,Ie,[(0,n.createElementVNode)(`div`,Le,[(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(y.plain===`subscription`?C.value.authorizationContractAddress:C.value.paymentAddress),1),I.value?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,Re,`⏰ `+(0,n.toDisplayString)(I.value),1)):(0,n.createCommentVNode)(``,!0)]),(0,n.createElementVNode)(`div`,ze,[H.value?((0,n.openBlock)(),(0,n.createElementBlock)(`code`,Be,(0,n.toDisplayString)(y.plain===`subscription`?H.value.spenderAddress:H.value.receiveAddress),1)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`button`,{onClick:ft,class:(0,n.normalizeClass)([`_cppay-copy-btn`,{"_cppay-copy-success":L.value}]),title:L.value?C.value.copied:C.value.copyAddress},[L.value?((0,n.openBlock)(),(0,n.createElementBlock)(`svg`,Ue,[...t[12]||=[(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`,He,[...t[11]||=[(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,Ve)])])]),y.plain===`subscription`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,We,[(0,n.createElementVNode)(`div`,Ge,(0,n.toDisplayString)(C.value.subscriptionNotice),1),(0,n.createElementVNode)(`div`,Ke,(0,n.toDisplayString)(C.value.subscriptionNoticeMessage),1)])):(0,n.createCommentVNode)(``,!0)]),O.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:0,class:`_cppay-error-tooltip-wrapper`,onMouseenter:t[3]||=e=>R.value=!0,onMouseleave:t[4]||=e=>R.value=!1},[(0,n.createElementVNode)(`div`,qe,[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)(O.value),1)]),R.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Je,(0,n.toDisplayString)(O.value),1)):(0,n.createCommentVNode)(``,!0)],32)):(0,n.createCommentVNode)(``,!0),D.value?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Ye,[N.value?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:1},[(0,n.createElementVNode)(`button`,{onClick:lt,disabled:E.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(E.value?y.plain===`subscription`?C.value.authorizing:C.value.processing:(y.plain,C.value.walletPay)),9,Ze),(0,n.createElementVNode)(`button`,{onClick:U,disabled:E.value,class:`_cppay-btn _cppay-wallet-address-btn`,title:C.value.clickToModifyWallet},[(0,n.createElementVNode)(`span`,$e,(0,n.toDisplayString)(N.value.slice(0,10))+`...`+(0,n.toDisplayString)(N.value.slice(-4)),1),t[14]||=(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,Qe)],64)):((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:0,onClick:U,disabled:P.value,class:`_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn`},[(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(P.value?C.value.processing:C.value.connectWallet),1)],8,Xe))])),(0,n.createElementVNode)(`div`,et,[(0,n.createElementVNode)(`button`,{onClick:dt,disabled:D.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(D.value?C.value.checking:C.value.completedPayment),9,tt)]),t[15]||=(0,n.createElementVNode)(`hr`,{class:`_cppay-divider`},null,-1),(0,n.createElementVNode)(`div`,nt,[(0,n.createElementVNode)(`button`,{onClick:t[5]||=e=>T.value=`select`,disabled:E.value||D.value,class:`_cppay-btn _cppay-btn-text`},(0,n.toDisplayString)(C.value.changePaymentMethod),9,rt)])]))]))}}),b=y,x={class:`_cppay-dialog`},S={class:`_cppay-header`},C={class:`_cppay-title`},w=[`disabled`],T=(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`,x,[(0,n.createElementVNode)(`div`,S,[(0,n.createElementVNode)(`h2`,C,(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,w)]),t.modelValue?((0,n.openBlock)(),(0,n.createBlock)(b,{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)}}),E=T,D=(0,n.ref)({apikey:``,open:!1,options:null});const O=e=>{D.value.options=e,D.value.open=!0},k=()=>{D.value.open=!1};var A=()=>{D.value.open=!1},j=e=>{D.value.options?.onSuccess?.(e),setTimeout(()=>{D.value.open=!1},1e3)},M=e=>{D.value.options?.onExpired?.(e)},N=e=>{D.value.options?.onFailed?.(e)},P=e=>{D.value.options?.onError?.(e)};const F={install(e,t){if(!t?.apikey)throw Error(`Cppay plugin requires an apikey`);D.value.apikey=t.apikey,e.config.globalProperties.$showPayment=O,e.config.globalProperties.$closePayment=k;let r=e=>{e.key===`Escape`&&D.value.open&&A()},i=document.createElement(`div`);document.body.appendChild(i),(0,n.createApp)({setup(){return()=>D.value.options?(0,n.h)(E,{modelValue:D.value.open,"onUpdate:modelValue":e=>{D.value.open=e,e||A()},apikey:D.value.apikey,plain:D.value.options.plain,orderId:D.value.options.orderId,amount:D.value.options.amount,intervalDays:D.value.options.intervalDays,onSuccess:j,onExpired:M,onFailed:N,onError:P}):null}}).mount(i),D.value.open&&document.addEventListener(`keydown`,r),e.config.globalProperties.$watchEffect?.(()=>{D.value.open?document.addEventListener(`keydown`,r):document.removeEventListener(`keydown`,r)})}},I=()=>{if(!D.value.apikey)throw Error(`useCppayPayment must be used after installing CppayPlugin`);return{showPayment:O,closePayment:k}};e.n(e.r),exports.CppayPlugin=F,exports.PaymentContent=b,exports.PaymentDialog=E,exports.showPayment=O,exports.useCppayPayment=I;
package/dist/vue.d.ts CHANGED
@@ -5,30 +5,30 @@ import { Plugin as Plugin_2 } from '../../vue/dist/vue.esm-bundler.js';
5
5
  import { PublicProps } from '../../vue/dist/vue.esm-bundler.js';
6
6
 
7
7
  declare const __VLS_component: DefineComponent<Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {} & {
8
- expired: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
8
+ success: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
9
9
  failed: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
10
+ expired: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
10
11
  error: (error: Error) => any;
11
- success: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
12
12
  "update:modelValue": (value: boolean) => any;
13
13
  }, string, PublicProps, Readonly<Props> & Readonly<{
14
- onExpired?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
14
+ onSuccess?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
15
15
  onFailed?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
16
+ onExpired?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
16
17
  onError?: ((error: Error) => any) | undefined;
17
- onSuccess?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
18
18
  "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
19
19
  }>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
20
20
 
21
21
  declare const __VLS_component_2: DefineComponent<Props_2, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {} & {
22
- expired: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
22
+ success: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
23
23
  failed: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
24
+ expired: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
24
25
  error: (error: Error) => any;
25
- success: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
26
26
  "update:paymentStep": (value: PaymentStep) => any;
27
27
  }, string, PublicProps, Readonly<Props_2> & Readonly<{
28
- onExpired?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
28
+ onSuccess?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
29
29
  onFailed?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
30
+ onExpired?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
30
31
  onError?: ((error: Error) => any) | undefined;
31
- onSuccess?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
32
32
  "onUpdate:paymentStep"?: ((value: PaymentStep) => any) | undefined;
33
33
  }>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
34
34
 
@@ -37,6 +37,10 @@ declare function __VLS_template(): {
37
37
  slots: {
38
38
  'choose-top'?(_: {}): any;
39
39
  'choose-bottom'?(_: {}): any;
40
+ success?(_: {}): any;
41
+ failed?(_: {}): any;
42
+ error?(_: {}): any;
43
+ expired?(_: {}): any;
40
44
  };
41
45
  refs: {};
42
46
  rootEl: any;
@@ -45,6 +49,10 @@ declare function __VLS_template(): {
45
49
  declare function __VLS_template_2(): {
46
50
  attrs: Partial<{}>;
47
51
  slots: {
52
+ success?(_: {}): any;
53
+ expired?(_: {}): any;
54
+ error?(_: {}): any;
55
+ failed?(_: {}): any;
48
56
  'choose-top'?(_: {}): any;
49
57
  'choose-bottom'?(_: {}): any;
50
58
  };
@@ -122,7 +130,8 @@ declare type PaymentStep = "select" | "payment" | "checking" | "success" | "fail
122
130
 
123
131
  declare interface Props {
124
132
  modelValue: boolean;
125
- apikey: string;
133
+ ott?: string;
134
+ apikey?: string;
126
135
  orderId: string;
127
136
  amount: string;
128
137
  plain: PaymentPlain;
@@ -132,7 +141,9 @@ declare interface Props {
132
141
 
133
142
  declare interface Props_2 {
134
143
  /** API Key */
135
- apikey: string;
144
+ apikey?: string;
145
+ /** One-Time Token */
146
+ ott?: string;
136
147
  /** 订单 ID */
137
148
  orderId: string;
138
149
  /** 支付金额(USD) */
package/dist/vue.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as cppay_default } from "./cppay-J9nBy01A.js";
1
+ import { t as cppay_default } from "./cppay-jU20-wmK.js";
2
2
  import { n as injectStyle, r as payment_dialog_default, t as getLocaleMessages } from "./locales-De6oJnka.js";
3
3
  import { Fragment, computed, createApp, createBlock, createCommentVNode, createElementBlock, createElementVNode, defineComponent, h, normalizeClass, onMounted, onUnmounted, openBlock, ref, renderList, renderSlot, shallowRef, toDisplayString, watch, withCtx } from "vue";
4
4
  import * as QRCode from "qrcode";
@@ -8,19 +8,7 @@ import { createWalletClient, custom, parseUnits } from "viem";
8
8
  import { arbitrum, base, bsc, mainnet, optimism, polygon } from "viem/chains";
9
9
  import { createAppKit } from "@reown/appkit";
10
10
  import { EthersAdapter } from "@reown/appkit-adapter-ethers";
11
- var _hoisted_1$1 = { class: "_cppay-content" }, _hoisted_2$1 = {
12
- key: 0,
13
- class: "_cppay-state-container"
14
- }, _hoisted_3$1 = { class: "_cppay-state-title" }, _hoisted_4$1 = { class: "_cppay-state-message" }, _hoisted_5 = {
15
- key: 1,
16
- class: "_cppay-state-container"
17
- }, _hoisted_6 = { class: "_cppay-state-title" }, _hoisted_7 = ["disabled"], _hoisted_8 = {
18
- key: 2,
19
- class: "_cppay-state-container"
20
- }, _hoisted_9 = { class: "_cppay-state-title" }, _hoisted_10 = {
21
- key: 3,
22
- class: "_cppay-state-container"
23
- }, _hoisted_11 = { class: "_cppay-state-title" }, _hoisted_12 = { key: 4 }, _hoisted_13 = { class: "_cppay-section" }, _hoisted_14 = { class: "_cppay-label" }, _hoisted_15 = { class: "_cppay-grid" }, _hoisted_16 = ["onClick"], _hoisted_17 = ["src", "alt"], _hoisted_18 = { class: "_cppay-section" }, _hoisted_19 = { class: "_cppay-label" }, _hoisted_20 = { class: "_cppay-grid" }, _hoisted_21 = ["onClick"], _hoisted_22 = ["src", "alt"], _hoisted_23 = { class: "_cppay-section" }, _hoisted_24 = { class: "_cppay-price-box" }, _hoisted_25 = { class: "_cppay-price-row" }, _hoisted_26 = { class: "_cppay-price-label" }, _hoisted_27 = { class: "_cppay-price-amount" }, _hoisted_28 = { class: "_cppay-price-main" }, _hoisted_29 = { class: "_cppay-price-sub" }, _hoisted_30 = { class: "_cppay-section" }, _hoisted_31 = { class: "_cppay-error-tooltip" }, _hoisted_32 = {
11
+ var _hoisted_1$1 = { class: "_cppay-content" }, _hoisted_2$1 = { class: "_cppay-state-container" }, _hoisted_3$1 = { class: "_cppay-state-title" }, _hoisted_4$1 = { class: "_cppay-state-message" }, _hoisted_5 = { class: "_cppay-state-container" }, _hoisted_6 = { class: "_cppay-state-title" }, _hoisted_7 = ["disabled"], _hoisted_8 = { class: "_cppay-state-container" }, _hoisted_9 = { class: "_cppay-state-title" }, _hoisted_10 = { class: "_cppay-state-container" }, _hoisted_11 = { class: "_cppay-state-title" }, _hoisted_12 = { key: 4 }, _hoisted_13 = { class: "_cppay-section" }, _hoisted_14 = { class: "_cppay-label" }, _hoisted_15 = { class: "_cppay-grid" }, _hoisted_16 = ["onClick"], _hoisted_17 = ["src", "alt"], _hoisted_18 = { class: "_cppay-section" }, _hoisted_19 = { class: "_cppay-label" }, _hoisted_20 = { class: "_cppay-grid" }, _hoisted_21 = ["onClick"], _hoisted_22 = ["src", "alt"], _hoisted_23 = { class: "_cppay-section" }, _hoisted_24 = { class: "_cppay-price-box" }, _hoisted_25 = { class: "_cppay-price-row" }, _hoisted_26 = { class: "_cppay-price-label" }, _hoisted_27 = { class: "_cppay-price-amount" }, _hoisted_28 = { class: "_cppay-price-main" }, _hoisted_29 = { class: "_cppay-price-sub" }, _hoisted_30 = { class: "_cppay-section" }, _hoisted_31 = { class: "_cppay-error-tooltip" }, _hoisted_32 = {
24
12
  key: 0,
25
13
  class: "_cppay-error-tooltip-full"
26
14
  }, _hoisted_33 = ["disabled"], _hoisted_34 = { key: 5 }, _hoisted_35 = { class: "_cppay-qr-container" }, _hoisted_36 = { class: "_cppay-qr-code" }, _hoisted_37 = ["src"], _hoisted_38 = { class: "_cppay-section" }, _hoisted_39 = {
@@ -54,6 +42,7 @@ var _hoisted_1$1 = { class: "_cppay-content" }, _hoisted_2$1 = {
54
42
  __name: "PaymentContent",
55
43
  props: {
56
44
  apikey: {},
45
+ ott: {},
57
46
  orderId: {},
58
47
  amount: {},
59
48
  plain: {},
@@ -69,7 +58,7 @@ var _hoisted_1$1 = { class: "_cppay-content" }, _hoisted_2$1 = {
69
58
  "error"
70
59
  ],
71
60
  setup(i, { emit: a }) {
72
- let c = i, l = a, u = computed(() => getLocaleMessages(c.locale)), d = new cppay_default(c.apikey), g = ref("select"), _ = ref(!1), v = computed(() => g.value === "checking"), y = ref(), b = ref([]), x = ref(), S = ref(), C = ref(), w = ref(), T = ref(!1), E = ref(), D = ref(""), O = ref(!1), k = ref(!1), A = shallowRef(null), j = ref(null), M = ref(null), N = ref(null), P = () => {
61
+ let c = i, l = a, u = computed(() => getLocaleMessages(c.locale)), d = computed(() => new cppay_default(c.apikey, c.ott)), g = ref("select"), _ = ref(!1), v = computed(() => g.value === "checking"), y = ref(), b = ref([]), x = ref(), S = ref(), C = ref(), w = ref(), T = ref(!1), E = ref(), D = ref(""), O = ref(!1), k = ref(!1), A = shallowRef(null), j = ref(null), M = ref(null), N = ref(null), P = () => {
73
62
  typeof window < "u" && !A.value && (A.value = createAppKit({
74
63
  debug: !1,
75
64
  enableNetworkSwitch: !1,
@@ -144,7 +133,7 @@ var _hoisted_1$1 = { class: "_cppay-content" }, _hoisted_2$1 = {
144
133
  return B((parseFloat(c.amount) / e).toFixed(i), i);
145
134
  }), G = async () => {
146
135
  try {
147
- _.value = !0, y.value = void 0, b.value = await d.getSupportedChains(), b.value.length > 0 && (x.value = b.value[0].chain);
136
+ _.value = !0, y.value = void 0, b.value = await d.value.getSupportedChains(), b.value.length > 0 && (x.value = b.value[0].chain);
148
137
  } catch (e) {
149
138
  y.value = e instanceof Error ? e.message : u.value.loadPaymentNetworkFailed, l("error", e);
150
139
  } finally {
@@ -243,12 +232,12 @@ var _hoisted_1$1 = { class: "_cppay-content" }, _hoisted_2$1 = {
243
232
  if (!(!x.value || !S.value)) try {
244
233
  y.value = void 0;
245
234
  let e = "";
246
- c.plain === "instant" ? (N.value = await d.createOnetimePayment({
235
+ c.plain === "instant" ? (N.value = await d.value.createOnetimePayment({
247
236
  paymentChain: x.value,
248
237
  paymentToken: S.value,
249
238
  orderId: c.orderId,
250
239
  amount: W.value
251
- }), e = `${x.value.toLowerCase()}:${N.value.receiveAddress}?amount=${N.value.paymentAmount}`, H(N.value.expireAt), Q({ paymentId: N.value.paymentId })) : c.plain === "subscription" && (N.value = await d.createSubscriptionPayment({
240
+ }), e = `${x.value.toLowerCase()}:${N.value.receiveAddress}?amount=${N.value.paymentAmount}`, H(N.value.expireAt), Q({ paymentId: N.value.paymentId })) : c.plain === "subscription" && (N.value = await d.value.createSubscriptionPayment({
252
241
  paymentChain: x.value,
253
242
  paymentToken: S.value,
254
243
  orderId: c.orderId,
@@ -266,7 +255,7 @@ var _hoisted_1$1 = { class: "_cppay-content" }, _hoisted_2$1 = {
266
255
  N.value && (y.value = void 0, g.value = "checking");
267
256
  }, Q = (e) => {
268
257
  j.value?.unsubscribe();
269
- let i = () => defer(() => c.plain === "subscription" ? d.checkSubscriptionPaymentStatus(e) : d.checkOnetimePaymentStatus(e)).pipe(timeout(15e3), retry({ delay: 2e3 }));
258
+ let i = () => defer(() => c.plain === "subscription" ? d.value.checkSubscriptionPaymentStatus(e) : d.value.checkOnetimePaymentStatus(e)).pipe(timeout(15e3), retry({ delay: 2e3 }));
270
259
  j.value = i().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => i())) : EMPTY), tap((e) => {
271
260
  (e.status === "paid" || e.status === "approved") && (g.value = "success", l("success", e)), e.status === "expired" && (g.value = "expired", l("expired", e)), e.status === "failed" && (g.value = "failed", l("failed", e));
272
261
  })).subscribe({
@@ -297,11 +286,11 @@ var _hoisted_1$1 = { class: "_cppay-content" }, _hoisted_2$1 = {
297
286
  P(), b.value.length || G(), c.orderId && Q({ orderId: c.orderId });
298
287
  }), onUnmounted(() => {
299
288
  j.value?.unsubscribe(), U();
300
- }), (e, a) => (openBlock(), createElementBlock("div", _hoisted_1$1, [g.value === "success" ? (openBlock(), createElementBlock("div", _hoisted_2$1, [
289
+ }), (e, a) => (openBlock(), createElementBlock("div", _hoisted_1$1, [g.value === "success" ? renderSlot(e.$slots, "success", { key: 0 }, () => [createElementVNode("div", _hoisted_2$1, [
301
290
  a[6] ||= createElementVNode("div", { class: "_cppay-state-icon" }, "✅", -1),
302
291
  createElementVNode("h3", _hoisted_3$1, toDisplayString(i.plain === "subscription" ? u.value.authorizationSuccess : u.value.paymentSuccess), 1),
303
292
  createElementVNode("p", _hoisted_4$1, toDisplayString(i.plain === "subscription" ? u.value.subscriptionActivated : u.value.transactionCompleted), 1)
304
- ])) : g.value === "expired" ? (openBlock(), createElementBlock("div", _hoisted_5, [
293
+ ])]) : g.value === "expired" ? renderSlot(e.$slots, "expired", { key: 1 }, () => [createElementVNode("div", _hoisted_5, [
305
294
  a[7] ||= createElementVNode("div", { class: "_cppay-state-icon" }, "⏰", -1),
306
295
  createElementVNode("h3", _hoisted_6, toDisplayString(u.value.paymentExpired), 1),
307
296
  createElementVNode("button", {
@@ -309,7 +298,7 @@ var _hoisted_1$1 = { class: "_cppay-content" }, _hoisted_2$1 = {
309
298
  disabled: _.value || v.value,
310
299
  class: "_cppay-btn _cppay-btn-text"
311
300
  }, toDisplayString(u.value.returnButton), 9, _hoisted_7)
312
- ])) : g.value === "error" ? (openBlock(), createElementBlock("div", _hoisted_8, [a[8] ||= createElementVNode("div", { class: "_cppay-state-icon" }, "❌", -1), createElementVNode("h3", _hoisted_9, toDisplayString(u.value.checking), 1)])) : g.value === "failed" ? (openBlock(), createElementBlock("div", _hoisted_10, [a[9] ||= createElementVNode("div", { class: "_cppay-state-icon" }, "❌", -1), createElementVNode("h3", _hoisted_11, toDisplayString(u.value.paymentFailed), 1)])) : g.value === "select" ? (openBlock(), createElementBlock("div", _hoisted_12, [
301
+ ])]) : g.value === "error" ? renderSlot(e.$slots, "error", { key: 2 }, () => [createElementVNode("div", _hoisted_8, [a[8] ||= createElementVNode("div", { class: "_cppay-state-icon" }, "❌", -1), createElementVNode("h3", _hoisted_9, toDisplayString(u.value.checking), 1)])]) : g.value === "failed" ? renderSlot(e.$slots, "failed", { key: 3 }, () => [createElementVNode("div", _hoisted_10, [a[9] ||= createElementVNode("div", { class: "_cppay-state-icon" }, "❌", -1), createElementVNode("h3", _hoisted_11, toDisplayString(u.value.paymentFailed), 1)])]) : g.value === "select" ? (openBlock(), createElementBlock("div", _hoisted_12, [
313
302
  renderSlot(e.$slots, "choose-top"),
314
303
  createElementVNode("div", _hoisted_13, [createElementVNode("label", _hoisted_14, toDisplayString(u.value.paymentNetwork), 1), createElementVNode("div", _hoisted_15, [(openBlock(!0), createElementBlock(Fragment, null, renderList(b.value, (e) => (openBlock(), createElementBlock("button", {
315
304
  key: e.chain,
@@ -422,6 +411,7 @@ var _hoisted_1$1 = { class: "_cppay-content" }, _hoisted_2$1 = {
422
411
  __name: "PaymentDialog",
423
412
  props: {
424
413
  modelValue: { type: Boolean },
414
+ ott: {},
425
415
  apikey: {},
426
416
  orderId: {},
427
417
  amount: {},
@@ -484,6 +474,7 @@ var _hoisted_1$1 = { class: "_cppay-content" }, _hoisted_2$1 = {
484
474
  })], -1)]], 8, _hoisted_4)]), e.modelValue ? (openBlock(), createBlock(PaymentContent_default, {
485
475
  key: 0,
486
476
  apikey: e.apikey,
477
+ ott: e.ott,
487
478
  orderId: e.orderId,
488
479
  amount: e.amount,
489
480
  plain: e.plain,
@@ -497,9 +488,14 @@ var _hoisted_1$1 = { class: "_cppay-content" }, _hoisted_2$1 = {
497
488
  }, {
498
489
  "choose-top": withCtx(() => [renderSlot(i.$slots, "choose-top")]),
499
490
  "choose-bottom": withCtx(() => [renderSlot(i.$slots, "choose-bottom")]),
491
+ success: withCtx(() => [renderSlot(i.$slots, "success")]),
492
+ failed: withCtx(() => [renderSlot(i.$slots, "failed")]),
493
+ error: withCtx(() => [renderSlot(i.$slots, "error")]),
494
+ expired: withCtx(() => [renderSlot(i.$slots, "expired")]),
500
495
  _: 3
501
496
  }, 8, [
502
497
  "apikey",
498
+ "ott",
503
499
  "orderId",
504
500
  "amount",
505
501
  "plain",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cppay-sdk",
3
- "version": "0.0.2-beta.37",
3
+ "version": "0.0.2-beta.39",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",