cppay-sdk 0.0.2-beta.13 → 0.0.2-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cppay-ClXaSwp8.cjs +1 -0
- package/dist/{cppay-p8t6ic0x.js → cppay-DNvA2evq.js} +2 -4
- package/dist/cppay-sdk.css +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -1
- package/dist/inject-style-F1LzEPFL.cjs +1 -0
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +37 -2
- package/dist/react.js +193 -129
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.ts +6 -1
- package/dist/vue.js +164 -95
- package/package.json +12 -7
- package/dist/cppay-S6x6aDqU.cjs +0 -1
- package/dist/inject-style-Dz7JsQxo.cjs +0 -1
|
@@ -0,0 +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.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{apikey;constructor(e){this.apikey=e}async getSupportedChains(){return(await a(this.apikey,{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}))}async createOnetimePayment(e,t,n,r){let i={chain:e,token:t,order_no:n,amount:r},o=await a(this.apikey,{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.apikey,{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={payment_id:e},n=await a(this.apikey,{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={subscription_id:e},n=await a(this.apikey,{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.apikey,{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){this.api=new o(e)}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]}),n[r.chain]=i,n},{});return Object.values(n)}async createPayment(e,t){switch(e){case`one-time`:return this.createOnetimePayment(t);case`subscription`:return this.createSubscriptionPayment(t)}}async checkPaymentStatus(e,t){switch(e){case`one-time`: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.paymentId)}}async checkSubscriptionPaymentStatus(e){return{...await this.api.checkSubcriptionPaymentStatus(e.subscriptionId)}}async getSubcriptionPayments(e){return{...await this.api.getSubcriptionPayments(e.subscriptionId)}}},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}});
|
|
@@ -54,8 +54,7 @@ var BASE_URL = "http://192.168.0.162:8000", request = async (e, t, r) => {
|
|
|
54
54
|
chainId: e.chain_id,
|
|
55
55
|
tokenSymbol: e.token_symbol,
|
|
56
56
|
tokenDecimals: e.token_decimals,
|
|
57
|
-
tokenAddress: e.token_address
|
|
58
|
-
receiveAddresses: e.receive_addresses
|
|
57
|
+
tokenAddress: e.token_address
|
|
59
58
|
}));
|
|
60
59
|
}
|
|
61
60
|
async createOnetimePayment(e, t, n, r) {
|
|
@@ -140,7 +139,7 @@ var BASE_URL = "http://192.168.0.162:8000", request = async (e, t, r) => {
|
|
|
140
139
|
});
|
|
141
140
|
return {
|
|
142
141
|
total: n.total,
|
|
143
|
-
payments: n.payments.map((e) => ({
|
|
142
|
+
payments: (n.payments ?? []).map((e) => ({
|
|
144
143
|
orderId: e.order_no,
|
|
145
144
|
subscriptionId: e.subscription_id,
|
|
146
145
|
chain: e.chain,
|
|
@@ -173,7 +172,6 @@ var BASE_URL = "http://192.168.0.162:8000", request = async (e, t, r) => {
|
|
|
173
172
|
symbol: r.tokenSymbol,
|
|
174
173
|
decimals: r.tokenDecimals,
|
|
175
174
|
address: r.tokenAddress,
|
|
176
|
-
receiveAddresses: r.receiveAddresses,
|
|
177
175
|
icon: TOKEN_ICONS[r.tokenSymbol]
|
|
178
176
|
}), n[r.chain] = i, n;
|
|
179
177
|
}, {});
|
package/dist/cppay-sdk.css
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
._cppay-fade-enter-active[data-v-
|
|
1
|
+
._cppay-fade-enter-active[data-v-681ced40],._cppay-fade-leave-active[data-v-681ced40]{transition:opacity .3s}._cppay-fade-enter-from[data-v-681ced40],._cppay-fade-leave-to[data-v-681ced40]{opacity:0}._cppay-fade-enter-active ._cppay-dialog[data-v-681ced40]{animation:.3s _cppay-slideUp}
|
|
2
2
|
/*$vite$:1*/
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./cppay-
|
|
1
|
+
const e=require(`./cppay-ClXaSwp8.cjs`);exports.CHAIN_ICONS=e.n,exports.Cppay=e.t,exports.TOKEN_ICONS=e.r;
|
package/dist/index.d.ts
CHANGED
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-
|
|
1
|
+
import { n as CHAIN_ICONS, r as TOKEN_ICONS, t as cppay_default } from "./cppay-DNvA2evq.js";
|
|
2
2
|
export { CHAIN_ICONS, cppay_default as Cppay, TOKEN_ICONS };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n)),c=`._cppay-overlay{z-index:9999;background-color:#00000080;justify-content:center;align-items:center;padding:1rem;display:flex;position:fixed;inset:0}._cppay-dialog{background-color:#fff;border-radius:1.5rem;width:100%;max-width:28rem;overflow:hidden;box-shadow:0 20px 25px -5px #0000001a,0 10px 10px -5px #0000000a}._cppay-header{border-bottom:1px solid #e5e7eb;justify-content:space-between;align-items:center;padding:1.5rem;display:flex}._cppay-title{color:#111827;margin:0;font-size:1.25rem;font-weight:600}._cppay-close-btn{color:#9ca3af;cursor:pointer;background:0 0;border:none;padding:.25rem;transition:color .2s}._cppay-close-btn:hover:not(:disabled){color:#4b5563}._cppay-close-btn:disabled{opacity:.5;cursor:not-allowed}._cppay-close-btn svg{width:1.5rem;height:1.5rem}._cppay-content{padding:1.5rem}._cppay-section{margin-bottom:1.5rem}._cppay-section:last-child{margin-bottom:0}._cppay-label{color:#374151;margin-bottom:.5rem;font-size:.875rem;font-weight:500;display:block}._cppay-grid{grid-template-columns:repeat(2,1fr);gap:.75rem;display:grid}._cppay-select-btn{cursor:pointer;background:#fff;border:2px solid #e5e7eb;border-radius:.75rem;align-items:center;gap:.5rem;padding:.75rem;font-family:inherit;font-size:.875rem;transition:all .2s;display:flex}._cppay-select-btn:hover{border-color:#d1d5db}._cppay-select-btn._cppay-selected{background-color:#eff6ff;border-color:#2563eb}._cppay-select-btn img{border-radius:9999px;width:1.5rem;height:1.5rem}._cppay-select-btn span{font-weight:500}._cppay-price-box{background-color:#f9fafb;border-radius:1rem;padding:1rem}._cppay-price-row{justify-content:space-between;align-items:center;display:flex}._cppay-price-label{color:#4b5563;font-size:.875rem}._cppay-price-amount{text-align:right}._cppay-price-main{color:#111827;margin:0;font-size:1.25rem;font-weight:700}._cppay-price-sub{color:#6b7280;margin-top:.25rem;font-size:.875rem}._cppay-btn{cursor:pointer;border:none;border-radius:.75rem;width:100%;padding:.75rem;font-family:inherit;font-size:1rem;font-weight:500;transition:all .2s}._cppay-btn-primary{color:#fff;background-color:#2563eb}._cppay-btn-primary:hover:not(:disabled){background-color:#1d4ed8}._cppay-btn-primary:disabled{opacity:.5;cursor:not-allowed}._cppay-btn-secondary{color:#374151;background-color:#fff;border:1px solid #d1d5db}._cppay-btn-secondary:hover:not(:disabled){background-color:#f9fafb}._cppay-btn-secondary:disabled{opacity:.5;cursor:not-allowed}._cppay-qr-container{justify-content:center;margin-bottom:1.5rem;display:flex}._cppay-qr-placeholder{background-color:#f3f4f6;border-radius:1rem;justify-content:center;align-items:center;width:12rem;height:12rem;display:flex}._cppay-qr-placeholder span{color:#9ca3af;font-size:.875rem}._cppay-info-box{background-color:#f9fafb;border-radius:.75rem;margin-bottom:.75rem;padding:1rem}._cppay-info-box:last-child{margin-bottom:0}._cppay-info-label{color:#4b5563;margin-bottom:.25rem;font-size:.875rem}._cppay-info-value{color:#111827;font-size:1.25rem;font-weight:700}._cppay-address-row{align-items:center;gap:.5rem;display:flex}._cppay-address-row code{text-overflow:ellipsis;white-space:nowrap;color:#111827;background:0 0;flex:1;font-family:monospace;font-size:.75rem;overflow:hidden}._cppay-copy-btn{color:#2563eb;cursor:pointer;background:0 0;border:none;justify-content:center;align-items:center;padding:.25rem;transition:color .2s;display:flex}._cppay-copy-btn:hover{color:#1d4ed8}._cppay-copy-btn svg{width:1.25rem;height:1.25rem}@keyframes _cppay-fadeIn{0%{opacity:0}to{opacity:1}}@keyframes _cppay-slideUp{0%{opacity:0;transform:translateY(1.25rem)}to{opacity:1;transform:translateY(0)}}._cppay-overlay{animation:.3s _cppay-fadeIn}._cppay-dialog{animation:.3s _cppay-slideUp}@media (max-width:640px){._cppay-dialog{margin:.5rem}._cppay-header,._cppay-content{padding:1rem}}`;function l(e){if(typeof document>`u`||document.getElementById(`_cppay-payment-dialog-style`))return;let t=document.createElement(`style`);t.id=`_cppay-payment-dialog-style`,t.textContent=e,document.head.appendChild(t)}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return l}});
|
package/dist/react.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require(`./inject-style-F1LzEPFL.cjs`),t=require(`./cppay-ClXaSwp8.cjs`);let n=require(`qrcode`);n=e.r(n);let r=require(`rxjs`),i=require(`rxjs/operators`),a=require(`react`);a=e.r(a);let o=require(`react/jsx-runtime`);var s=({open:e,onClose:s,apikey:c,plain:l,orderId:u,amount:d,intervalDays:f,onExpired:p,onSuccess:m,onFailed:h,onError:g})=>{let _=(0,a.useMemo)(()=>new t.t(c),[c]),[v,y]=(0,a.useState)(`select`),[b,x]=(0,a.useState)(!1),[S,C]=(0,a.useState)([]),[w,T]=(0,a.useState)(``),[E,D]=(0,a.useState)(``),[O,k]=(0,a.useState)(``),A=(0,a.useRef)(null),j=(0,a.useMemo)(()=>S.find(e=>e.chain===w),[S,w]),M=(0,a.useMemo)(()=>j?.tokens||[],[j]);(0,a.useMemo)(()=>M.find(e=>e.symbol===E),[M,E]);let N=e=>[`USDT`,`USDC`,`BUSD`,`DAI`,`TUSD`,`USDD`,`FDUSD`].includes(e.toUpperCase())?2:6,P=(e,t)=>{let n=parseFloat(e);return isNaN(n)?`0`:n.toFixed(t).replace(/\.?0+$/,``)},F=(0,a.useMemo)(()=>{if(!E)return`0`;let e=N(E);return P((parseFloat(d)/1).toFixed(e),e)},[d,E,1]),I=async()=>{try{x(!0);let e=await _.getSupportedChains();C(e),e.length>0&&T(e[0].chain)}catch(e){g?.(e)}finally{x(!1)}},L=(0,a.useRef)(null),R=async()=>{if(!(!w||!E))try{x(!0);let e=``;l===`one-time`?(L.current=await _.createOnetimePayment({paymentChain:w,paymentToken:E,orderId:u,amount:F}),e=`${w.toLowerCase()}:${L.current.receiveAddress}?amount=${L.current.paymentAmount}`):l===`subscription`&&(L.current=await _.createSubscriptionPayment({paymentChain:w,paymentToken:E,orderId:u,amountOfUsd:F,intervalDays:f||30}),e=`${w.toLowerCase()}:${L.current.spenderAddress}?amount=${L.current.approveAmount}`),y(`payment`),k(await n.toDataURL(e,{width:200,margin:2,errorCorrectionLevel:`H`}))}catch(e){g?.(e)}finally{x(!1)}},z=async()=>{if(L.current)try{x(!0),l===`one-time`&&B(L.current.subscriptionId),l===`subscription`&&B(L.current.paymentId)}catch(e){console.error(`支付状态检查错误:`,e),g?.(e)}finally{x(!1)}},B=e=>{let t=()=>(0,r.defer)(()=>l===`subscription`?_.checkSubscriptionPaymentStatus({subscriptionId:e}):_.checkOnetimePaymentStatus({paymentId:e})).pipe((0,i.timeout)(15e3),(0,i.retry)({count:3,delay:2e3}));A.current?.unsubscribe(),A.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===`expired`&&p?.(e),e.status===`paid`&&(m?.(e),H()),e.status===`failed`&&h?.(e),e.status===`approved`&&(m?.(e),H())})).subscribe({error:e=>{console.error(`支付状态检查错误:`,e),g?.(e)}})},V=async()=>{if(!L.current)return;let e=l===`subscription`?L.current.spenderAddress:L.current.receiveAddress;e&&await navigator.clipboard.writeText(e)},H=()=>{s(),setTimeout(()=>{y(`select`),L.current=null},300)};return(0,a.useEffect)(()=>{e&&S.length===0&&I()},[e]),(0,a.useEffect)(()=>{M.length>0&&D(M[0].symbol)},[M]),(0,a.useEffect)(()=>()=>{A.current?.unsubscribe()},[]),e?(0,o.jsx)(`div`,{className:`_cppay-overlay`,onClick:e=>e.target===e.currentTarget&&H(),children:(0,o.jsxs)(`div`,{className:`_cppay-dialog`,children:[(0,o.jsxs)(`div`,{className:`_cppay-header`,children:[(0,o.jsx)(`h2`,{className:`_cppay-title`,children:v===`select`?`选择支付方式`:`完成支付`}),(0,o.jsx)(`button`,{onClick:H,disabled:b,className:`_cppay-close-btn`,children:(0,o.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,o.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,o.jsx)(`div`,{className:`_cppay-content`,children:v===`select`?(0,o.jsxs)(`div`,{children:[(0,o.jsxs)(`div`,{className:`_cppay-section`,children:[(0,o.jsx)(`label`,{className:`_cppay-label`,children:`支付网络`}),(0,o.jsx)(`div`,{className:`_cppay-grid`,children:S.map(e=>(0,o.jsxs)(`button`,{onClick:()=>T(e.chain),className:`_cppay-select-btn ${w===e.chain?`_cppay-selected`:``}`,children:[e.icon&&(0,o.jsx)(`img`,{src:e.icon,alt:e.chain}),(0,o.jsx)(`span`,{children:e.chain})]},e.chain))})]}),(0,o.jsxs)(`div`,{className:`_cppay-section`,children:[(0,o.jsx)(`label`,{className:`_cppay-label`,children:`支付代币`}),(0,o.jsx)(`div`,{className:`_cppay-grid`,children:M.map(e=>(0,o.jsxs)(`button`,{onClick:()=>D(e.symbol),className:`_cppay-select-btn ${E===e.symbol?`_cppay-selected`:``}`,children:[e.icon&&(0,o.jsx)(`img`,{src:e.icon,alt:e.symbol}),(0,o.jsx)(`span`,{children:e.symbol})]},e.symbol))})]}),(0,o.jsx)(`div`,{className:`_cppay-section`,children:(0,o.jsx)(`div`,{className:`_cppay-price-box`,children:(0,o.jsxs)(`div`,{className:`_cppay-price-row`,children:[(0,o.jsx)(`span`,{className:`_cppay-price-label`,children:`支付金额`}),(0,o.jsxs)(`div`,{className:`_cppay-price-amount`,children:[(0,o.jsxs)(`div`,{className:`_cppay-price-main`,children:[F,` `,E]}),(0,o.jsxs)(`div`,{className:`_cppay-price-sub`,children:[`≈ $`,d]})]})]})})}),(0,o.jsx)(`div`,{className:`_cppay-section`,children:(0,o.jsx)(`button`,{onClick:R,disabled:!w||!E||b,className:`_cppay-btn _cppay-btn-primary`,children:b?`处理中...`:`继续支付`})})]}):(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`div`,{className:`_cppay-qr-container`,children:(0,o.jsx)(`div`,{className:`_cppay-qr-code`,style:{background:`white`,padding:`16px`,borderRadius:`16px`},children:O&&(0,o.jsx)(`img`,{src:O,alt:`Payment QR Code`,style:{width:`200px`,height:`200px`}})})}),(0,o.jsxs)(`div`,{className:`_cppay-section`,children:[(0,o.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,o.jsx)(`div`,{className:`_cppay-info-label`,children:l===`subscription`?`授权金额`:`支付金额`}),(0,o.jsx)(`div`,{className:`_cppay-info-value`,children:l===`subscription`?`${P(L.current.approveAmount,N(E))} ${E}`:`${P(L.current.paymentAmount,N(E))} ${E}`})]}),(0,o.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,o.jsx)(`div`,{className:`_cppay-info-label`,children:l===`subscription`?`授权合约地址`:`支付地址`}),(0,o.jsxs)(`div`,{className:`_cppay-address-row`,children:[(0,o.jsx)(`code`,{children:l===`subscription`?L.current.spenderAddress:L.current.receiveAddress}),(0,o.jsx)(`button`,{onClick:V,className:`_cppay-copy-btn`,title:`复制地址`,children:(0,o.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,o.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z`})})})]})]}),l===`subscription`&&(0,o.jsxs)(`div`,{className:`_cppay-info-box`,style:{background:`#fff3cd`,borderColor:`#ffc107`},children:[(0,o.jsx)(`div`,{className:`_cppay-info-label`,style:{color:`#856404`},children:`📌 订阅说明`}),(0,o.jsx)(`div`,{className:`_cppay-info-value`,style:{fontSize:`12px`,color:`#856404`},children:`订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。`})]})]}),(0,o.jsx)(`div`,{className:`_cppay-section`,children:(0,o.jsx)(`button`,{onClick:z,disabled:b,className:`_cppay-btn _cppay-btn-primary`,children:b?`检查中...`:`我已完成支付`})}),(0,o.jsx)(`div`,{className:`_cppay-section`,children:(0,o.jsx)(`button`,{onClick:()=>y(`select`),disabled:b,className:`_cppay-btn _cppay-btn-secondary`,children:`更改支付方式`})})]})})]})}):null},c=a.default.memo(s),l=(0,a.createContext)(null);const u=({apikey:e,children:t})=>{let[n,r]=(0,a.useState)(!1),[i,s]=(0,a.useState)(null),u=(0,a.useCallback)(e=>{s(e),r(!0)},[]),d=(0,a.useCallback)(()=>{r(!1)},[]),f=(0,a.useCallback)(e=>{i?.onSuccess?.(e),r(!1)},[i]),p=(0,a.useCallback)(e=>{i?.onError?.(e)},[i]);return(0,o.jsxs)(l.Provider,{value:{showPayment:u},children:[t,i&&(0,o.jsx)(c,{open:n,onClose:d,apikey:e,plain:i.plain,orderId:i.orderId,amount:i.amount,intervalDays:i.intervalDays,onSuccess:f,onError:p})]})},d=()=>{let e=(0,a.useContext)(l);if(!e)throw Error(`useCppayPayment must be used within CppayProvider`);return e};e.t(e.n),exports.CppayProvider=u,exports.PaymentDialog=c,exports.useCppayPayment=d;
|
package/dist/react.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { default as default_2 } from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
|
+
declare type Address = `0x${string}`;
|
|
5
|
+
|
|
4
6
|
declare interface CppayContextValue {
|
|
5
7
|
showPayment: (options: PaymentOptions_2) => void;
|
|
6
8
|
}
|
|
@@ -12,6 +14,20 @@ declare interface CppayProviderProps {
|
|
|
12
14
|
children: ReactNode;
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
declare type Numberic = `${number}.${number}` | `${number}`;
|
|
18
|
+
|
|
19
|
+
declare interface OnetimePaymentOrderStatus {
|
|
20
|
+
orderId: string;
|
|
21
|
+
paymentId: string;
|
|
22
|
+
chain: string;
|
|
23
|
+
token: string;
|
|
24
|
+
baseAmount: Numberic;
|
|
25
|
+
payAmount: Numberic;
|
|
26
|
+
receiveAddress: Address;
|
|
27
|
+
expireAt: number;
|
|
28
|
+
status: PaymentStatus;
|
|
29
|
+
}
|
|
30
|
+
|
|
15
31
|
export declare const PaymentDialog: default_2.NamedExoticComponent<PaymentDialogProps>;
|
|
16
32
|
|
|
17
33
|
declare interface PaymentDialogProps {
|
|
@@ -22,7 +38,9 @@ declare interface PaymentDialogProps {
|
|
|
22
38
|
orderId: string;
|
|
23
39
|
amount: string;
|
|
24
40
|
intervalDays?: number;
|
|
25
|
-
onSuccess?: (
|
|
41
|
+
onSuccess?: (order: SubscriptionPaymentOrderStatus | OnetimePaymentOrderStatus) => void;
|
|
42
|
+
onExpired?: (order: SubscriptionPaymentOrderStatus | OnetimePaymentOrderStatus) => void;
|
|
43
|
+
onFailed?: (order: SubscriptionPaymentOrderStatus | OnetimePaymentOrderStatus) => void;
|
|
26
44
|
onError?: (error: Error) => void;
|
|
27
45
|
}
|
|
28
46
|
|
|
@@ -31,12 +49,29 @@ declare interface PaymentOptions_2 {
|
|
|
31
49
|
orderId: string;
|
|
32
50
|
amount: string;
|
|
33
51
|
intervalDays?: number;
|
|
34
|
-
onSuccess?: (
|
|
52
|
+
onSuccess?: (order: SubscriptionPaymentOrderStatus | OnetimePaymentOrderStatus) => void;
|
|
35
53
|
onError?: (error: Error) => void;
|
|
36
54
|
}
|
|
37
55
|
|
|
38
56
|
declare type PaymentPlain = "one-time" | "subscription" | "x402";
|
|
39
57
|
|
|
58
|
+
declare type PaymentStatus = "pending" | "paid" | "expired" | "failed";
|
|
59
|
+
|
|
60
|
+
declare interface SubscriptionPaymentOrderStatus {
|
|
61
|
+
orderId: string;
|
|
62
|
+
subscriptionId: string;
|
|
63
|
+
chain: string;
|
|
64
|
+
token: string;
|
|
65
|
+
approvedAddress: string;
|
|
66
|
+
txHash: string;
|
|
67
|
+
approveAmount: string;
|
|
68
|
+
amountOfUsd: string;
|
|
69
|
+
expireAt: number;
|
|
70
|
+
status: SubscriptionPaymentStatus;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare type SubscriptionPaymentStatus = "pending" | "approved" | "expired" | "failed";
|
|
74
|
+
|
|
40
75
|
export declare const useCppayPayment: () => CppayContextValue;
|
|
41
76
|
|
|
42
77
|
export { }
|
package/dist/react.js
CHANGED
|
@@ -1,79 +1,113 @@
|
|
|
1
|
-
import { t as cppay_default } from "./cppay-
|
|
1
|
+
import { t as cppay_default } from "./cppay-DNvA2evq.js";
|
|
2
2
|
import { n as payment_dialog_default, t as injectStyle } from "./inject-style-qX_0AjjE.js";
|
|
3
|
-
import
|
|
3
|
+
import * as QRCode from "qrcode";
|
|
4
|
+
import { EMPTY, defer, timer } from "rxjs";
|
|
5
|
+
import { expand, retry, switchMap, tap, timeout } from "rxjs/operators";
|
|
6
|
+
import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
4
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
var PaymentDialog_default = React.memo(({ open:
|
|
6
|
-
let
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
var PaymentDialog_default = React.memo(({ open: l, onClose: u, apikey: v, plain: y, orderId: b, amount: x, intervalDays: S, onExpired: C, onSuccess: w, onFailed: T, onError: E }) => {
|
|
9
|
+
let D = useMemo(() => new cppay_default(v), [v]), [O, k] = useState("select"), [A, j] = useState(!1), [M, N] = useState([]), [P, F] = useState(""), [I, L] = useState(""), [R, z] = useState(""), B = useRef(null), V = useMemo(() => M.find((t) => t.chain === P), [M, P]), H = useMemo(() => V?.tokens || [], [V]);
|
|
10
|
+
useMemo(() => H.find((t) => t.symbol === I), [H, I]);
|
|
11
|
+
let U = (t) => [
|
|
12
|
+
"USDT",
|
|
13
|
+
"USDC",
|
|
14
|
+
"BUSD",
|
|
15
|
+
"DAI",
|
|
16
|
+
"TUSD",
|
|
17
|
+
"USDD",
|
|
18
|
+
"FDUSD"
|
|
19
|
+
].includes(t.toUpperCase()) ? 2 : 6, W = (t, l) => {
|
|
20
|
+
let u = parseFloat(t);
|
|
21
|
+
return isNaN(u) ? "0" : u.toFixed(l).replace(/\.?0+$/, "");
|
|
22
|
+
}, G = useMemo(() => {
|
|
23
|
+
if (!I) return "0";
|
|
24
|
+
let t = U(I);
|
|
25
|
+
return W((parseFloat(x) / 1).toFixed(t), t);
|
|
26
|
+
}, [
|
|
27
|
+
x,
|
|
28
|
+
I,
|
|
9
29
|
1
|
|
10
|
-
]),
|
|
30
|
+
]), K = async () => {
|
|
11
31
|
try {
|
|
12
|
-
|
|
13
|
-
let t = await
|
|
14
|
-
|
|
32
|
+
j(!0);
|
|
33
|
+
let t = await D.getSupportedChains();
|
|
34
|
+
N(t), t.length > 0 && F(t[0].chain);
|
|
15
35
|
} catch (t) {
|
|
16
|
-
|
|
36
|
+
E?.(t);
|
|
17
37
|
} finally {
|
|
18
|
-
|
|
38
|
+
j(!1);
|
|
19
39
|
}
|
|
20
|
-
},
|
|
21
|
-
if (!(!
|
|
22
|
-
|
|
23
|
-
let t;
|
|
24
|
-
|
|
25
|
-
paymentChain:
|
|
26
|
-
paymentToken:
|
|
27
|
-
orderId:
|
|
28
|
-
amount:
|
|
29
|
-
}) :
|
|
30
|
-
paymentChain:
|
|
31
|
-
paymentToken:
|
|
32
|
-
orderId:
|
|
33
|
-
amountOfUsd:
|
|
34
|
-
intervalDays:
|
|
35
|
-
})),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
})
|
|
40
|
+
}, q = useRef(null), J = async () => {
|
|
41
|
+
if (!(!P || !I)) try {
|
|
42
|
+
j(!0);
|
|
43
|
+
let t = "";
|
|
44
|
+
y === "one-time" ? (q.current = await D.createOnetimePayment({
|
|
45
|
+
paymentChain: P,
|
|
46
|
+
paymentToken: I,
|
|
47
|
+
orderId: b,
|
|
48
|
+
amount: G
|
|
49
|
+
}), t = `${P.toLowerCase()}:${q.current.receiveAddress}?amount=${q.current.paymentAmount}`) : y === "subscription" && (q.current = await D.createSubscriptionPayment({
|
|
50
|
+
paymentChain: P,
|
|
51
|
+
paymentToken: I,
|
|
52
|
+
orderId: b,
|
|
53
|
+
amountOfUsd: G,
|
|
54
|
+
intervalDays: S || 30
|
|
55
|
+
}), t = `${P.toLowerCase()}:${q.current.spenderAddress}?amount=${q.current.approveAmount}`), k("payment"), z(await QRCode.toDataURL(t, {
|
|
56
|
+
width: 200,
|
|
57
|
+
margin: 2,
|
|
58
|
+
errorCorrectionLevel: "H"
|
|
59
|
+
}));
|
|
40
60
|
} catch (t) {
|
|
41
|
-
|
|
61
|
+
E?.(t);
|
|
42
62
|
} finally {
|
|
43
|
-
|
|
63
|
+
j(!1);
|
|
44
64
|
}
|
|
45
|
-
},
|
|
46
|
-
if (
|
|
47
|
-
|
|
65
|
+
}, Y = async () => {
|
|
66
|
+
if (q.current) try {
|
|
67
|
+
j(!0), y === "one-time" && X(q.current.subscriptionId), y === "subscription" && X(q.current.paymentId);
|
|
48
68
|
} catch (t) {
|
|
49
|
-
|
|
69
|
+
console.error("支付状态检查错误:", t), E?.(t);
|
|
50
70
|
} finally {
|
|
51
|
-
|
|
71
|
+
j(!1);
|
|
52
72
|
}
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
73
|
+
}, X = (t) => {
|
|
74
|
+
let l = () => defer(() => y === "subscription" ? D.checkSubscriptionPaymentStatus({ subscriptionId: t }) : D.checkOnetimePaymentStatus({ paymentId: t })).pipe(timeout(15e3), retry({
|
|
75
|
+
count: 3,
|
|
76
|
+
delay: 2e3
|
|
77
|
+
}));
|
|
78
|
+
B.current?.unsubscribe(), B.current = l().pipe(expand((t) => t.status === "pending" ? timer(2e3).pipe(switchMap(() => l())) : EMPTY), tap((t) => {
|
|
79
|
+
t.status === "expired" && C?.(t), t.status === "paid" && (w?.(t), Q()), t.status === "failed" && T?.(t), t.status === "approved" && (w?.(t), Q());
|
|
80
|
+
})).subscribe({ error: (t) => {
|
|
81
|
+
console.error("支付状态检查错误:", t), E?.(t);
|
|
82
|
+
} });
|
|
83
|
+
}, Z = async () => {
|
|
84
|
+
if (!q.current) return;
|
|
85
|
+
let t = y === "subscription" ? q.current.spenderAddress : q.current.receiveAddress;
|
|
86
|
+
t && await navigator.clipboard.writeText(t);
|
|
87
|
+
}, Q = () => {
|
|
88
|
+
u(), setTimeout(() => {
|
|
89
|
+
k("select"), q.current = null;
|
|
58
90
|
}, 300);
|
|
59
91
|
};
|
|
60
92
|
return useEffect(() => {
|
|
61
|
-
|
|
62
|
-
}, [
|
|
63
|
-
|
|
64
|
-
}, [
|
|
93
|
+
l && M.length === 0 && K();
|
|
94
|
+
}, [l]), useEffect(() => {
|
|
95
|
+
H.length > 0 && L(H[0].symbol);
|
|
96
|
+
}, [H]), useEffect(() => () => {
|
|
97
|
+
B.current?.unsubscribe();
|
|
98
|
+
}, []), l ? /* @__PURE__ */ jsx("div", {
|
|
65
99
|
className: "_cppay-overlay",
|
|
66
|
-
onClick: (t) => t.target === t.currentTarget &&
|
|
100
|
+
onClick: (t) => t.target === t.currentTarget && Q(),
|
|
67
101
|
children: /* @__PURE__ */ jsxs("div", {
|
|
68
102
|
className: "_cppay-dialog",
|
|
69
103
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
70
104
|
className: "_cppay-header",
|
|
71
105
|
children: [/* @__PURE__ */ jsx("h2", {
|
|
72
106
|
className: "_cppay-title",
|
|
73
|
-
children:
|
|
107
|
+
children: O === "select" ? "选择支付方式" : "完成支付"
|
|
74
108
|
}), /* @__PURE__ */ jsx("button", {
|
|
75
|
-
onClick:
|
|
76
|
-
disabled:
|
|
109
|
+
onClick: Q,
|
|
110
|
+
disabled: A,
|
|
77
111
|
className: "_cppay-close-btn",
|
|
78
112
|
children: /* @__PURE__ */ jsx("svg", {
|
|
79
113
|
fill: "none",
|
|
@@ -89,7 +123,7 @@ var PaymentDialog_default = React.memo(({ open: i, onClose: a, apikey: o, plain:
|
|
|
89
123
|
})]
|
|
90
124
|
}), /* @__PURE__ */ jsx("div", {
|
|
91
125
|
className: "_cppay-content",
|
|
92
|
-
children:
|
|
126
|
+
children: O === "select" ? /* @__PURE__ */ jsxs("div", { children: [
|
|
93
127
|
/* @__PURE__ */ jsxs("div", {
|
|
94
128
|
className: "_cppay-section",
|
|
95
129
|
children: [/* @__PURE__ */ jsx("label", {
|
|
@@ -97,9 +131,9 @@ var PaymentDialog_default = React.memo(({ open: i, onClose: a, apikey: o, plain:
|
|
|
97
131
|
children: "支付网络"
|
|
98
132
|
}), /* @__PURE__ */ jsx("div", {
|
|
99
133
|
className: "_cppay-grid",
|
|
100
|
-
children:
|
|
101
|
-
onClick: () =>
|
|
102
|
-
className: `_cppay-select-btn ${
|
|
134
|
+
children: M.map((t) => /* @__PURE__ */ jsxs("button", {
|
|
135
|
+
onClick: () => F(t.chain),
|
|
136
|
+
className: `_cppay-select-btn ${P === t.chain ? "_cppay-selected" : ""}`,
|
|
103
137
|
children: [t.icon && /* @__PURE__ */ jsx("img", {
|
|
104
138
|
src: t.icon,
|
|
105
139
|
alt: t.chain
|
|
@@ -114,9 +148,9 @@ var PaymentDialog_default = React.memo(({ open: i, onClose: a, apikey: o, plain:
|
|
|
114
148
|
children: "支付代币"
|
|
115
149
|
}), /* @__PURE__ */ jsx("div", {
|
|
116
150
|
className: "_cppay-grid",
|
|
117
|
-
children:
|
|
118
|
-
onClick: () =>
|
|
119
|
-
className: `_cppay-select-btn ${
|
|
151
|
+
children: H.map((t) => /* @__PURE__ */ jsxs("button", {
|
|
152
|
+
onClick: () => L(t.symbol),
|
|
153
|
+
className: `_cppay-select-btn ${I === t.symbol ? "_cppay-selected" : ""}`,
|
|
120
154
|
children: [t.icon && /* @__PURE__ */ jsx("img", {
|
|
121
155
|
src: t.icon,
|
|
122
156
|
alt: t.symbol
|
|
@@ -138,13 +172,13 @@ var PaymentDialog_default = React.memo(({ open: i, onClose: a, apikey: o, plain:
|
|
|
138
172
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
139
173
|
className: "_cppay-price-main",
|
|
140
174
|
children: [
|
|
141
|
-
|
|
175
|
+
G,
|
|
142
176
|
" ",
|
|
143
|
-
|
|
177
|
+
I
|
|
144
178
|
]
|
|
145
179
|
}), /* @__PURE__ */ jsxs("div", {
|
|
146
180
|
className: "_cppay-price-sub",
|
|
147
|
-
children: ["≈ $",
|
|
181
|
+
children: ["≈ $", x]
|
|
148
182
|
})]
|
|
149
183
|
})]
|
|
150
184
|
})
|
|
@@ -153,75 +187,105 @@ var PaymentDialog_default = React.memo(({ open: i, onClose: a, apikey: o, plain:
|
|
|
153
187
|
/* @__PURE__ */ jsx("div", {
|
|
154
188
|
className: "_cppay-section",
|
|
155
189
|
children: /* @__PURE__ */ jsx("button", {
|
|
156
|
-
onClick:
|
|
157
|
-
disabled: !
|
|
190
|
+
onClick: J,
|
|
191
|
+
disabled: !P || !I || A,
|
|
158
192
|
className: "_cppay-btn _cppay-btn-primary",
|
|
159
|
-
children:
|
|
193
|
+
children: A ? "处理中..." : "继续支付"
|
|
160
194
|
})
|
|
161
195
|
})
|
|
162
|
-
] }) :
|
|
196
|
+
] }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
163
197
|
/* @__PURE__ */ jsx("div", {
|
|
164
198
|
className: "_cppay-qr-container",
|
|
165
199
|
children: /* @__PURE__ */ jsx("div", {
|
|
166
|
-
className: "_cppay-qr-
|
|
167
|
-
|
|
200
|
+
className: "_cppay-qr-code",
|
|
201
|
+
style: {
|
|
202
|
+
background: "white",
|
|
203
|
+
padding: "16px",
|
|
204
|
+
borderRadius: "16px"
|
|
205
|
+
},
|
|
206
|
+
children: R && /* @__PURE__ */ jsx("img", {
|
|
207
|
+
src: R,
|
|
208
|
+
alt: "Payment QR Code",
|
|
209
|
+
style: {
|
|
210
|
+
width: "200px",
|
|
211
|
+
height: "200px"
|
|
212
|
+
}
|
|
213
|
+
})
|
|
168
214
|
})
|
|
169
215
|
}),
|
|
170
216
|
/* @__PURE__ */ jsxs("div", {
|
|
171
217
|
className: "_cppay-section",
|
|
172
|
-
children: [
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
d: "M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"
|
|
218
|
+
children: [
|
|
219
|
+
/* @__PURE__ */ jsxs("div", {
|
|
220
|
+
className: "_cppay-info-box",
|
|
221
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
222
|
+
className: "_cppay-info-label",
|
|
223
|
+
children: y === "subscription" ? "授权金额" : "支付金额"
|
|
224
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
225
|
+
className: "_cppay-info-value",
|
|
226
|
+
children: y === "subscription" ? `${W(q.current.approveAmount, U(I))} ${I}` : `${W(q.current.paymentAmount, U(I))} ${I}`
|
|
227
|
+
})]
|
|
228
|
+
}),
|
|
229
|
+
/* @__PURE__ */ jsxs("div", {
|
|
230
|
+
className: "_cppay-info-box",
|
|
231
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
232
|
+
className: "_cppay-info-label",
|
|
233
|
+
children: y === "subscription" ? "授权合约地址" : "支付地址"
|
|
234
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
235
|
+
className: "_cppay-address-row",
|
|
236
|
+
children: [/* @__PURE__ */ jsx("code", { children: y === "subscription" ? q.current.spenderAddress : q.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
|
|
237
|
+
onClick: Z,
|
|
238
|
+
className: "_cppay-copy-btn",
|
|
239
|
+
title: "复制地址",
|
|
240
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
241
|
+
fill: "none",
|
|
242
|
+
stroke: "currentColor",
|
|
243
|
+
viewBox: "0 0 24 24",
|
|
244
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
245
|
+
strokeLinecap: "round",
|
|
246
|
+
strokeLinejoin: "round",
|
|
247
|
+
strokeWidth: 2,
|
|
248
|
+
d: "M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"
|
|
249
|
+
})
|
|
205
250
|
})
|
|
206
|
-
})
|
|
251
|
+
})]
|
|
207
252
|
})]
|
|
208
|
-
})
|
|
209
|
-
|
|
253
|
+
}),
|
|
254
|
+
y === "subscription" && /* @__PURE__ */ jsxs("div", {
|
|
255
|
+
className: "_cppay-info-box",
|
|
256
|
+
style: {
|
|
257
|
+
background: "#fff3cd",
|
|
258
|
+
borderColor: "#ffc107"
|
|
259
|
+
},
|
|
260
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
261
|
+
className: "_cppay-info-label",
|
|
262
|
+
style: { color: "#856404" },
|
|
263
|
+
children: "📌 订阅说明"
|
|
264
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
265
|
+
className: "_cppay-info-value",
|
|
266
|
+
style: {
|
|
267
|
+
fontSize: "12px",
|
|
268
|
+
color: "#856404"
|
|
269
|
+
},
|
|
270
|
+
children: "订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。"
|
|
271
|
+
})]
|
|
272
|
+
})
|
|
273
|
+
]
|
|
210
274
|
}),
|
|
211
275
|
/* @__PURE__ */ jsx("div", {
|
|
212
276
|
className: "_cppay-section",
|
|
213
277
|
children: /* @__PURE__ */ jsx("button", {
|
|
214
|
-
onClick:
|
|
215
|
-
disabled:
|
|
278
|
+
onClick: Y,
|
|
279
|
+
disabled: A,
|
|
216
280
|
className: "_cppay-btn _cppay-btn-primary",
|
|
217
|
-
children:
|
|
281
|
+
children: A ? "检查中..." : "我已完成支付"
|
|
218
282
|
})
|
|
219
283
|
}),
|
|
220
284
|
/* @__PURE__ */ jsx("div", {
|
|
221
285
|
className: "_cppay-section",
|
|
222
286
|
children: /* @__PURE__ */ jsx("button", {
|
|
223
|
-
onClick: () =>
|
|
224
|
-
disabled:
|
|
287
|
+
onClick: () => k("select"),
|
|
288
|
+
disabled: A,
|
|
225
289
|
className: "_cppay-btn _cppay-btn-secondary",
|
|
226
290
|
children: "更改支付方式"
|
|
227
291
|
})
|
|
@@ -231,28 +295,28 @@ var PaymentDialog_default = React.memo(({ open: i, onClose: a, apikey: o, plain:
|
|
|
231
295
|
})
|
|
232
296
|
}) : null;
|
|
233
297
|
}), CppayContext = createContext(null);
|
|
234
|
-
const CppayProvider = ({ apikey: t, children:
|
|
235
|
-
let [
|
|
236
|
-
|
|
237
|
-
}, []),
|
|
238
|
-
|
|
239
|
-
}, []),
|
|
240
|
-
|
|
241
|
-
}, [
|
|
242
|
-
|
|
243
|
-
}, [
|
|
298
|
+
const CppayProvider = ({ apikey: t, children: l }) => {
|
|
299
|
+
let [u, d] = useState(!1), [f, p] = useState(null), m = useCallback((t) => {
|
|
300
|
+
p(t), d(!0);
|
|
301
|
+
}, []), h = useCallback(() => {
|
|
302
|
+
d(!1);
|
|
303
|
+
}, []), g = useCallback((t) => {
|
|
304
|
+
f?.onSuccess?.(t), d(!1);
|
|
305
|
+
}, [f]), _ = useCallback((t) => {
|
|
306
|
+
f?.onError?.(t);
|
|
307
|
+
}, [f]);
|
|
244
308
|
return /* @__PURE__ */ jsxs(CppayContext.Provider, {
|
|
245
|
-
value: { showPayment:
|
|
246
|
-
children: [
|
|
247
|
-
open:
|
|
248
|
-
onClose:
|
|
309
|
+
value: { showPayment: m },
|
|
310
|
+
children: [l, f && /* @__PURE__ */ jsx(PaymentDialog_default, {
|
|
311
|
+
open: u,
|
|
312
|
+
onClose: h,
|
|
249
313
|
apikey: t,
|
|
250
|
-
plain:
|
|
251
|
-
orderId:
|
|
252
|
-
amount:
|
|
253
|
-
intervalDays:
|
|
254
|
-
onSuccess:
|
|
255
|
-
onError:
|
|
314
|
+
plain: f.plain,
|
|
315
|
+
orderId: f.orderId,
|
|
316
|
+
amount: f.amount,
|
|
317
|
+
intervalDays: f.intervalDays,
|
|
318
|
+
onSuccess: g,
|
|
319
|
+
onError: _
|
|
256
320
|
})]
|
|
257
321
|
});
|
|
258
322
|
}, useCppayPayment = () => {
|
package/dist/vue.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./
|
|
1
|
+
const e=require(`./inject-style-F1LzEPFL.cjs`),t=require(`./cppay-ClXaSwp8.cjs`);let n=require(`vue`),r=require(`qrcode`);r=e.r(r);let i=require(`rxjs`),a=require(`rxjs/operators`);var o={class:`_cppay-dialog`},s={class:`_cppay-header`},c={class:`_cppay-title`},l=[`disabled`],u={class:`_cppay-content`},d={key:0},f={class:`_cppay-section`},p={class:`_cppay-grid`},m=[`onClick`],h=[`src`,`alt`],ee={class:`_cppay-section`},te={class:`_cppay-grid`},ne=[`onClick`],re=[`src`,`alt`],ie={class:`_cppay-section`},g={class:`_cppay-price-box`},_={class:`_cppay-price-row`},v={class:`_cppay-price-amount`},y={class:`_cppay-price-main`},b={class:`_cppay-price-sub`},x={class:`_cppay-section`},S=[`disabled`],C={key:1},w={class:`_cppay-qr-container`},T={class:`_cppay-qr-code`,style:{background:`white`,padding:`16px`,"border-radius":`16px`,display:`inline-block`}},E=[`src`],D={class:`_cppay-section`},O={class:`_cppay-info-box`},k={class:`_cppay-info-label`},A={class:`_cppay-info-value`},j={class:`_cppay-info-box`},M={class:`_cppay-info-label`},N={class:`_cppay-address-row`},P={key:0,class:`_cppay-info-box`,style:{background:`#fff3cd`,"border-color":`#ffc107`}},F={class:`_cppay-section`},I=[`disabled`],L={class:`_cppay-section`},ae=[`disabled`],R=(0,n.defineComponent)({__name:`PaymentDialog`,props:{modelValue:{type:Boolean},apikey:{},orderId:{},amount:{},plain:{default:`one-time`},intervalDays:{default:30}},emits:[`update:modelValue`,`success`,`error`],setup(e,{emit:R}){let z=e,B=R,V=new t.t(z.apikey),H=(0,n.ref)(`select`),U=(0,n.ref)(!1),W=(0,n.ref)([]),G=(0,n.ref)(``),K=(0,n.ref)(``),q=(0,n.ref)(null),J=(0,n.ref)(``),Y=(0,n.ref)(null),oe=(0,n.computed)(()=>W.value.find(e=>e.chain===G.value)),X=(0,n.computed)(()=>oe.value?.tokens||[]);(0,n.computed)(()=>X.value.find(e=>e.symbol===K.value));let se=(0,n.ref)(1),Z=(0,n.computed)(()=>K.value?(parseFloat(z.amount)/se.value).toFixed(6):`0`),Q=()=>{B(`update:modelValue`,!1),setTimeout(()=>{H.value=`select`,q.value=null},300)},ce=async()=>{try{U.value=!0,W.value=await V.getSupportedChains(),W.value.length>0&&(G.value=W.value[0].chain)}catch(e){B(`error`,e)}finally{U.value=!1}},le=async()=>{if(!(!G.value||!K.value))try{U.value=!0;let e;z.plain===`one-time`?e=await V.createPayment(`one-time`,{paymentChain:G.value,paymentToken:K.value,orderId:z.orderId,amount:Z.value}):z.plain===`subscription`&&(e=await V.createPayment(`subscription`,{paymentChain:G.value,paymentToken:K.value,orderId:z.orderId,amountOfUsd:Z.value,intervalDays:z.intervalDays||30})),q.value={paymentId:e.paymentId||e.subscriptionId,paymentAmount:e.paymentAmount||e.approveAmount,receiveAddress:e.receiveAddress||e.spenderAddress||``};let t=`${G.value.toLowerCase()}:${q.value.receiveAddress}?amount=${q.value.paymentAmount}`;J.value=await r.toDataURL(t,{width:200,margin:2,errorCorrectionLevel:`H`}),H.value=`payment`}catch(e){B(`error`,e)}finally{U.value=!1}},$=e=>{let t=()=>(0,i.defer)(()=>z.plain===`subscription`?V.checkSubscriptionPaymentStatus({subscriptionId:e}):V.checkOnetimePaymentStatus({paymentId:e})).pipe((0,a.timeout)(15e3),(0,a.retry)({count:3,delay:2e3}));Y.value?.unsubscribe(),Y.value=t().pipe((0,a.expand)(e=>e.status===`pending`?(0,i.timer)(2e3).pipe((0,a.switchMap)(()=>t())):i.EMPTY),(0,a.tap)(t=>{t.status===`expired`&&alert(`支付已过期`),t.status===`paid`&&(alert(`支付成功!`),B(`success`,e),Q()),t.status===`failed`&&alert(`支付失败`),t.status===`approved`&&(alert(`订阅成功!`),B(`success`,e),Q())})).subscribe({error:e=>{console.error(`支付状态检查错误:`,e),B(`error`,e)}})},ue=async()=>{if(q.value)try{U.value=!0,$(q.value.paymentId)}catch(e){B(`error`,e)}finally{U.value=!1}},de=async()=>{q.value?.receiveAddress&&(await navigator.clipboard.writeText(q.value.receiveAddress),alert(`地址已复制`))};return(0,n.watch)(()=>z.modelValue,e=>{e&&W.value.length===0&&ce()}),(0,n.watch)(G,()=>{X.value.length>0&&(K.value=X.value[0].symbol)}),(0,n.watch)(H,e=>{e===`payment`&&q.value&&$(q.value.paymentId)}),(0,n.onUnmounted)(()=>{Y.value?.unsubscribe()}),(t,r)=>((0,n.openBlock)(),(0,n.createBlock)(n.Teleport,{to:`body`},[(0,n.createVNode)(n.Transition,{name:`_cppay-fade`},{default:(0,n.withCtx)(()=>[e.modelValue?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:0,class:`_cppay-overlay`,onClick:(0,n.withModifiers)(Q,[`self`])},[(0,n.createElementVNode)(`div`,o,[(0,n.createElementVNode)(`div`,s,[(0,n.createElementVNode)(`h2`,c,(0,n.toDisplayString)(H.value===`select`?`选择支付方式`:`完成支付`),1),(0,n.createElementVNode)(`button`,{onClick:Q,class:`_cppay-close-btn`,disabled:U.value},[...r[1]||=[(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,l)]),(0,n.createElementVNode)(`div`,u,[H.value===`select`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,d,[(0,n.createElementVNode)(`div`,f,[r[2]||=(0,n.createElementVNode)(`label`,{class:`_cppay-label`},`支付网络`,-1),(0,n.createElementVNode)(`div`,p,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(W.value,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.chain,onClick:t=>G.value=e.chain,class:(0,n.normalizeClass)([`_cppay-select-btn`,G.value===e.chain?`_cppay-selected`:``])},[e.icon?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.chain},null,8,h)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.chain),1)],10,m))),128))])]),(0,n.createElementVNode)(`div`,ee,[r[3]||=(0,n.createElementVNode)(`label`,{class:`_cppay-label`},`支付代币`,-1),(0,n.createElementVNode)(`div`,te,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(X.value,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.symbol,onClick:t=>K.value=e.symbol,class:(0,n.normalizeClass)([`_cppay-select-btn`,K.value===e.symbol?`_cppay-selected`:``])},[e.icon?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.symbol},null,8,re)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.symbol),1)],10,ne))),128))])]),(0,n.createElementVNode)(`div`,ie,[(0,n.createElementVNode)(`div`,g,[(0,n.createElementVNode)(`div`,_,[r[4]||=(0,n.createElementVNode)(`span`,{class:`_cppay-price-label`},`支付金额`,-1),(0,n.createElementVNode)(`div`,v,[(0,n.createElementVNode)(`div`,y,(0,n.toDisplayString)(Z.value)+` `+(0,n.toDisplayString)(K.value),1),(0,n.createElementVNode)(`div`,b,`≈ $`+(0,n.toDisplayString)(e.amount),1)])])])]),(0,n.createElementVNode)(`div`,x,[(0,n.createElementVNode)(`button`,{onClick:le,disabled:!G.value||!K.value||U.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(U.value?`处理中...`:`继续支付`),9,S)])])):H.value===`payment`&&q.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,C,[(0,n.createElementVNode)(`div`,w,[(0,n.createElementVNode)(`div`,T,[J.value?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:J.value,alt:`QR Code`,style:{width:`200px`,height:`200px`}},null,8,E)):(0,n.createCommentVNode)(``,!0)])]),(0,n.createElementVNode)(`div`,D,[(0,n.createElementVNode)(`div`,O,[(0,n.createElementVNode)(`div`,k,(0,n.toDisplayString)(z.plain===`subscription`?`授权金额`:`支付金额`),1),(0,n.createElementVNode)(`div`,A,(0,n.toDisplayString)(q.value.paymentAmount)+` `+(0,n.toDisplayString)(K.value),1)]),(0,n.createElementVNode)(`div`,j,[(0,n.createElementVNode)(`div`,M,(0,n.toDisplayString)(z.plain===`subscription`?`授权合约地址`:`支付地址`),1),(0,n.createElementVNode)(`div`,N,[(0,n.createElementVNode)(`code`,null,(0,n.toDisplayString)(q.value.receiveAddress),1),(0,n.createElementVNode)(`button`,{onClick:de,class:`_cppay-copy-btn`,title:`复制地址`},[...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:`M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z`})],-1)]])])]),z.plain===`subscription`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,P,[...r[6]||=[(0,n.createElementVNode)(`div`,{class:`_cppay-info-label`,style:{color:`#856404`}},`📌 订阅说明`,-1),(0,n.createElementVNode)(`div`,{class:`_cppay-info-value`,style:{"font-size":`12px`,color:`#856404`}},` 订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。 `,-1)]])):(0,n.createCommentVNode)(``,!0)]),(0,n.createElementVNode)(`div`,F,[(0,n.createElementVNode)(`button`,{onClick:ue,disabled:U.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(U.value?`检查支付状态...`:`我已完成支付`),9,I)]),(0,n.createElementVNode)(`div`,L,[(0,n.createElementVNode)(`button`,{onClick:r[0]||=e=>H.value=`select`,disabled:U.value,class:`_cppay-btn _cppay-btn-secondary`},` 更改支付方式 `,8,ae)])])):(0,n.createCommentVNode)(``,!0)])])])):(0,n.createCommentVNode)(``,!0)]),_:1})]))}}),z=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},B=z(R,[[`__scopeId`,`data-v-681ced40`]]);e.t(e.n),exports.PaymentDialog=B;
|
package/dist/vue.d.ts
CHANGED
|
@@ -11,13 +11,18 @@ success: (paymentId: string) => any;
|
|
|
11
11
|
onError?: ((error: Error) => any) | undefined;
|
|
12
12
|
"onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
|
|
13
13
|
onSuccess?: ((paymentId: string) => any) | undefined;
|
|
14
|
-
}>, {
|
|
14
|
+
}>, {
|
|
15
|
+
intervalDays: number;
|
|
16
|
+
plain: "one-time" | "subscription";
|
|
17
|
+
}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
15
18
|
|
|
16
19
|
declare interface Props {
|
|
17
20
|
modelValue: boolean;
|
|
18
21
|
apikey: string;
|
|
19
22
|
orderId: string;
|
|
20
23
|
amount: string;
|
|
24
|
+
plain?: "one-time" | "subscription";
|
|
25
|
+
intervalDays?: number;
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
export { }
|
package/dist/vue.js
CHANGED
|
@@ -1,80 +1,128 @@
|
|
|
1
|
-
import { t as cppay_default } from "./cppay-
|
|
1
|
+
import { t as cppay_default } from "./cppay-DNvA2evq.js";
|
|
2
2
|
import { n as payment_dialog_default, t as injectStyle } from "./inject-style-qX_0AjjE.js";
|
|
3
|
-
import { Fragment, Teleport, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, openBlock, ref, renderList, toDisplayString, watch, withCtx, withModifiers } from "vue";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { Fragment, Teleport, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, onUnmounted, openBlock, ref, renderList, toDisplayString, watch, withCtx, withModifiers } from "vue";
|
|
4
|
+
import * as QRCode from "qrcode";
|
|
5
|
+
import { EMPTY, defer, timer } from "rxjs";
|
|
6
|
+
import { expand, retry, switchMap, tap, timeout } from "rxjs/operators";
|
|
7
|
+
var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-header" }, _hoisted_3 = { class: "_cppay-title" }, _hoisted_4 = ["disabled"], _hoisted_5 = { class: "_cppay-content" }, _hoisted_6 = { key: 0 }, _hoisted_7 = { class: "_cppay-section" }, _hoisted_8 = { class: "_cppay-grid" }, _hoisted_9 = ["onClick"], _hoisted_10 = ["src", "alt"], _hoisted_11 = { class: "_cppay-section" }, _hoisted_12 = { class: "_cppay-grid" }, _hoisted_13 = ["onClick"], _hoisted_14 = ["src", "alt"], _hoisted_15 = { class: "_cppay-section" }, _hoisted_16 = { class: "_cppay-price-box" }, _hoisted_17 = { class: "_cppay-price-row" }, _hoisted_18 = { class: "_cppay-price-amount" }, _hoisted_19 = { class: "_cppay-price-main" }, _hoisted_20 = { class: "_cppay-price-sub" }, _hoisted_21 = { class: "_cppay-section" }, _hoisted_22 = ["disabled"], _hoisted_23 = { key: 1 }, _hoisted_24 = { class: "_cppay-qr-container" }, _hoisted_25 = {
|
|
8
|
+
class: "_cppay-qr-code",
|
|
9
|
+
style: {
|
|
10
|
+
background: "white",
|
|
11
|
+
padding: "16px",
|
|
12
|
+
"border-radius": "16px",
|
|
13
|
+
display: "inline-block"
|
|
14
|
+
}
|
|
15
|
+
}, _hoisted_26 = ["src"], _hoisted_27 = { class: "_cppay-section" }, _hoisted_28 = { class: "_cppay-info-box" }, _hoisted_29 = { class: "_cppay-info-label" }, _hoisted_30 = { class: "_cppay-info-value" }, _hoisted_31 = { class: "_cppay-info-box" }, _hoisted_32 = { class: "_cppay-info-label" }, _hoisted_33 = { class: "_cppay-address-row" }, _hoisted_34 = {
|
|
16
|
+
key: 0,
|
|
17
|
+
class: "_cppay-info-box",
|
|
18
|
+
style: {
|
|
19
|
+
background: "#fff3cd",
|
|
20
|
+
"border-color": "#ffc107"
|
|
21
|
+
}
|
|
22
|
+
}, _hoisted_35 = { class: "_cppay-section" }, _hoisted_36 = ["disabled"], _hoisted_37 = { class: "_cppay-section" }, _hoisted_38 = ["disabled"], PaymentDialog_default = /* @__PURE__ */ ((e, A) => {
|
|
23
|
+
let j = e.__vccOpts || e;
|
|
24
|
+
for (let [e, M] of A) j[e] = M;
|
|
25
|
+
return j;
|
|
8
26
|
})(/* @__PURE__ */ defineComponent({
|
|
9
27
|
__name: "PaymentDialog",
|
|
10
28
|
props: {
|
|
11
29
|
modelValue: { type: Boolean },
|
|
12
30
|
apikey: {},
|
|
13
31
|
orderId: {},
|
|
14
|
-
amount: {}
|
|
32
|
+
amount: {},
|
|
33
|
+
plain: { default: "one-time" },
|
|
34
|
+
intervalDays: { default: 30 }
|
|
15
35
|
},
|
|
16
36
|
emits: [
|
|
17
37
|
"update:modelValue",
|
|
18
38
|
"success",
|
|
19
39
|
"error"
|
|
20
40
|
],
|
|
21
|
-
setup(
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
41
|
+
setup(A, { emit: j }) {
|
|
42
|
+
let N = A, P = j, F = new cppay_default(N.apikey), I = ref("select"), L = ref(!1), R = ref([]), z = ref(""), B = ref(""), V = ref(null), H = ref(""), U = ref(null), W = computed(() => R.value.find((e) => e.chain === z.value)), G = computed(() => W.value?.tokens || []);
|
|
43
|
+
computed(() => G.value.find((e) => e.symbol === B.value));
|
|
44
|
+
let K = ref(1), q = computed(() => B.value ? (parseFloat(N.amount) / K.value).toFixed(6) : "0"), J = () => {
|
|
45
|
+
P("update:modelValue", !1), setTimeout(() => {
|
|
46
|
+
I.value = "select", V.value = null;
|
|
25
47
|
}, 300);
|
|
26
|
-
},
|
|
48
|
+
}, Y = async () => {
|
|
27
49
|
try {
|
|
28
|
-
|
|
29
|
-
} catch (
|
|
30
|
-
|
|
50
|
+
L.value = !0, R.value = await F.getSupportedChains(), R.value.length > 0 && (z.value = R.value[0].chain);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
P("error", e);
|
|
31
53
|
} finally {
|
|
32
|
-
|
|
54
|
+
L.value = !1;
|
|
33
55
|
}
|
|
34
|
-
},
|
|
35
|
-
if (!(!
|
|
36
|
-
|
|
37
|
-
let
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
}, X = async () => {
|
|
57
|
+
if (!(!z.value || !B.value)) try {
|
|
58
|
+
L.value = !0;
|
|
59
|
+
let e;
|
|
60
|
+
N.plain === "one-time" ? e = await F.createPayment("one-time", {
|
|
61
|
+
paymentChain: z.value,
|
|
62
|
+
paymentToken: B.value,
|
|
63
|
+
orderId: N.orderId,
|
|
64
|
+
amount: q.value
|
|
65
|
+
}) : N.plain === "subscription" && (e = await F.createPayment("subscription", {
|
|
66
|
+
paymentChain: z.value,
|
|
67
|
+
paymentToken: B.value,
|
|
68
|
+
orderId: N.orderId,
|
|
69
|
+
amountOfUsd: q.value,
|
|
70
|
+
intervalDays: N.intervalDays || 30
|
|
71
|
+
})), V.value = {
|
|
72
|
+
paymentId: e.paymentId || e.subscriptionId,
|
|
73
|
+
paymentAmount: e.paymentAmount || e.approveAmount,
|
|
74
|
+
receiveAddress: e.receiveAddress || e.spenderAddress || ""
|
|
75
|
+
};
|
|
76
|
+
let A = `${z.value.toLowerCase()}:${V.value.receiveAddress}?amount=${V.value.paymentAmount}`;
|
|
77
|
+
H.value = await QRCode.toDataURL(A, {
|
|
78
|
+
width: 200,
|
|
79
|
+
margin: 2,
|
|
80
|
+
errorCorrectionLevel: "H"
|
|
81
|
+
}), I.value = "payment";
|
|
82
|
+
} catch (e) {
|
|
83
|
+
P("error", e);
|
|
50
84
|
} finally {
|
|
51
|
-
|
|
85
|
+
L.value = !1;
|
|
52
86
|
}
|
|
87
|
+
}, Z = (e) => {
|
|
88
|
+
let A = () => defer(() => N.plain === "subscription" ? F.checkSubscriptionPaymentStatus({ subscriptionId: e }) : F.checkOnetimePaymentStatus({ paymentId: e })).pipe(timeout(15e3), retry({
|
|
89
|
+
count: 3,
|
|
90
|
+
delay: 2e3
|
|
91
|
+
}));
|
|
92
|
+
U.value?.unsubscribe(), U.value = A().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => A())) : EMPTY), tap((A) => {
|
|
93
|
+
A.status === "expired" && alert("支付已过期"), A.status === "paid" && (alert("支付成功!"), P("success", e), J()), A.status === "failed" && alert("支付失败"), A.status === "approved" && (alert("订阅成功!"), P("success", e), J());
|
|
94
|
+
})).subscribe({ error: (e) => {
|
|
95
|
+
console.error("支付状态检查错误:", e), P("error", e);
|
|
96
|
+
} });
|
|
53
97
|
}, Q = async () => {
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
} catch (
|
|
57
|
-
|
|
98
|
+
if (V.value) try {
|
|
99
|
+
L.value = !0, Z(V.value.paymentId);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
P("error", e);
|
|
58
102
|
} finally {
|
|
59
|
-
|
|
103
|
+
L.value = !1;
|
|
60
104
|
}
|
|
61
105
|
}, $ = async () => {
|
|
62
|
-
|
|
106
|
+
V.value?.receiveAddress && (await navigator.clipboard.writeText(V.value.receiveAddress), alert("地址已复制"));
|
|
63
107
|
};
|
|
64
|
-
return watch(() =>
|
|
65
|
-
|
|
66
|
-
}), watch(
|
|
67
|
-
G.value.length > 0 && (
|
|
68
|
-
}), (
|
|
69
|
-
|
|
108
|
+
return watch(() => N.modelValue, (e) => {
|
|
109
|
+
e && R.value.length === 0 && Y();
|
|
110
|
+
}), watch(z, () => {
|
|
111
|
+
G.value.length > 0 && (B.value = G.value[0].symbol);
|
|
112
|
+
}), watch(I, (e) => {
|
|
113
|
+
e === "payment" && V.value && Z(V.value.paymentId);
|
|
114
|
+
}), onUnmounted(() => {
|
|
115
|
+
U.value?.unsubscribe();
|
|
116
|
+
}), (e, j) => (openBlock(), createBlock(Teleport, { to: "body" }, [createVNode(Transition, { name: "_cppay-fade" }, {
|
|
117
|
+
default: withCtx(() => [A.modelValue ? (openBlock(), createElementBlock("div", {
|
|
70
118
|
key: 0,
|
|
71
119
|
class: "_cppay-overlay",
|
|
72
|
-
onClick: withModifiers(
|
|
73
|
-
}, [createElementVNode("div", _hoisted_1, [createElementVNode("div", _hoisted_2, [createElementVNode("h2", _hoisted_3, toDisplayString(
|
|
74
|
-
onClick:
|
|
120
|
+
onClick: withModifiers(J, ["self"])
|
|
121
|
+
}, [createElementVNode("div", _hoisted_1, [createElementVNode("div", _hoisted_2, [createElementVNode("h2", _hoisted_3, toDisplayString(I.value === "select" ? "选择支付方式" : "完成支付"), 1), createElementVNode("button", {
|
|
122
|
+
onClick: J,
|
|
75
123
|
class: "_cppay-close-btn",
|
|
76
|
-
disabled:
|
|
77
|
-
}, [...
|
|
124
|
+
disabled: L.value
|
|
125
|
+
}, [...j[1] ||= [createElementVNode("svg", {
|
|
78
126
|
fill: "none",
|
|
79
127
|
stroke: "currentColor",
|
|
80
128
|
viewBox: "0 0 24 24"
|
|
@@ -83,61 +131,82 @@ var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-heade
|
|
|
83
131
|
"stroke-linejoin": "round",
|
|
84
132
|
"stroke-width": "2",
|
|
85
133
|
d: "M6 18L18 6M6 6l12 12"
|
|
86
|
-
})], -1)]], 8, _hoisted_4)]), createElementVNode("div", _hoisted_5, [
|
|
87
|
-
createElementVNode("div", _hoisted_7, [
|
|
88
|
-
key:
|
|
89
|
-
onClick: (
|
|
90
|
-
class: normalizeClass(["_cppay-select-btn",
|
|
91
|
-
}, [
|
|
134
|
+
})], -1)]], 8, _hoisted_4)]), createElementVNode("div", _hoisted_5, [I.value === "select" ? (openBlock(), createElementBlock("div", _hoisted_6, [
|
|
135
|
+
createElementVNode("div", _hoisted_7, [j[2] ||= createElementVNode("label", { class: "_cppay-label" }, "支付网络", -1), createElementVNode("div", _hoisted_8, [(openBlock(!0), createElementBlock(Fragment, null, renderList(R.value, (e) => (openBlock(), createElementBlock("button", {
|
|
136
|
+
key: e.chain,
|
|
137
|
+
onClick: (A) => z.value = e.chain,
|
|
138
|
+
class: normalizeClass(["_cppay-select-btn", z.value === e.chain ? "_cppay-selected" : ""])
|
|
139
|
+
}, [e.icon ? (openBlock(), createElementBlock("img", {
|
|
92
140
|
key: 0,
|
|
93
|
-
src:
|
|
94
|
-
alt:
|
|
95
|
-
}, null, 8, _hoisted_10)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(
|
|
96
|
-
createElementVNode("div", _hoisted_11, [
|
|
97
|
-
key:
|
|
98
|
-
onClick: (
|
|
99
|
-
class: normalizeClass(["_cppay-select-btn",
|
|
100
|
-
}, [
|
|
141
|
+
src: e.icon,
|
|
142
|
+
alt: e.chain
|
|
143
|
+
}, null, 8, _hoisted_10)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(e.chain), 1)], 10, _hoisted_9))), 128))])]),
|
|
144
|
+
createElementVNode("div", _hoisted_11, [j[3] ||= createElementVNode("label", { class: "_cppay-label" }, "支付代币", -1), createElementVNode("div", _hoisted_12, [(openBlock(!0), createElementBlock(Fragment, null, renderList(G.value, (e) => (openBlock(), createElementBlock("button", {
|
|
145
|
+
key: e.symbol,
|
|
146
|
+
onClick: (A) => B.value = e.symbol,
|
|
147
|
+
class: normalizeClass(["_cppay-select-btn", B.value === e.symbol ? "_cppay-selected" : ""])
|
|
148
|
+
}, [e.icon ? (openBlock(), createElementBlock("img", {
|
|
101
149
|
key: 0,
|
|
102
|
-
src:
|
|
103
|
-
alt:
|
|
104
|
-
}, null, 8, _hoisted_14)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(
|
|
105
|
-
createElementVNode("div", _hoisted_15, [createElementVNode("div", _hoisted_16, [createElementVNode("div", _hoisted_17, [
|
|
150
|
+
src: e.icon,
|
|
151
|
+
alt: e.symbol
|
|
152
|
+
}, null, 8, _hoisted_14)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(e.symbol), 1)], 10, _hoisted_13))), 128))])]),
|
|
153
|
+
createElementVNode("div", _hoisted_15, [createElementVNode("div", _hoisted_16, [createElementVNode("div", _hoisted_17, [j[4] ||= createElementVNode("span", { class: "_cppay-price-label" }, "支付金额", -1), createElementVNode("div", _hoisted_18, [createElementVNode("div", _hoisted_19, toDisplayString(q.value) + " " + toDisplayString(B.value), 1), createElementVNode("div", _hoisted_20, "≈ $" + toDisplayString(A.amount), 1)])])])]),
|
|
106
154
|
createElementVNode("div", _hoisted_21, [createElementVNode("button", {
|
|
107
|
-
onClick:
|
|
108
|
-
disabled: !
|
|
155
|
+
onClick: X,
|
|
156
|
+
disabled: !z.value || !B.value || L.value,
|
|
109
157
|
class: "_cppay-btn _cppay-btn-primary"
|
|
110
|
-
}, toDisplayString(
|
|
111
|
-
])) :
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
158
|
+
}, toDisplayString(L.value ? "处理中..." : "继续支付"), 9, _hoisted_22)])
|
|
159
|
+
])) : I.value === "payment" && V.value ? (openBlock(), createElementBlock("div", _hoisted_23, [
|
|
160
|
+
createElementVNode("div", _hoisted_24, [createElementVNode("div", _hoisted_25, [H.value ? (openBlock(), createElementBlock("img", {
|
|
161
|
+
key: 0,
|
|
162
|
+
src: H.value,
|
|
163
|
+
alt: "QR Code",
|
|
164
|
+
style: {
|
|
165
|
+
width: "200px",
|
|
166
|
+
height: "200px"
|
|
167
|
+
}
|
|
168
|
+
}, null, 8, _hoisted_26)) : createCommentVNode("", !0)])]),
|
|
169
|
+
createElementVNode("div", _hoisted_27, [
|
|
170
|
+
createElementVNode("div", _hoisted_28, [createElementVNode("div", _hoisted_29, toDisplayString(N.plain === "subscription" ? "授权金额" : "支付金额"), 1), createElementVNode("div", _hoisted_30, toDisplayString(V.value.paymentAmount) + " " + toDisplayString(B.value), 1)]),
|
|
171
|
+
createElementVNode("div", _hoisted_31, [createElementVNode("div", _hoisted_32, toDisplayString(N.plain === "subscription" ? "授权合约地址" : "支付地址"), 1), createElementVNode("div", _hoisted_33, [createElementVNode("code", null, toDisplayString(V.value.receiveAddress), 1), createElementVNode("button", {
|
|
172
|
+
onClick: $,
|
|
173
|
+
class: "_cppay-copy-btn",
|
|
174
|
+
title: "复制地址"
|
|
175
|
+
}, [...j[5] ||= [createElementVNode("svg", {
|
|
176
|
+
fill: "none",
|
|
177
|
+
stroke: "currentColor",
|
|
178
|
+
viewBox: "0 0 24 24"
|
|
179
|
+
}, [createElementVNode("path", {
|
|
180
|
+
"stroke-linecap": "round",
|
|
181
|
+
"stroke-linejoin": "round",
|
|
182
|
+
"stroke-width": "2",
|
|
183
|
+
d: "M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"
|
|
184
|
+
})], -1)]])])]),
|
|
185
|
+
N.plain === "subscription" ? (openBlock(), createElementBlock("div", _hoisted_34, [...j[6] ||= [createElementVNode("div", {
|
|
186
|
+
class: "_cppay-info-label",
|
|
187
|
+
style: { color: "#856404" }
|
|
188
|
+
}, "📌 订阅说明", -1), createElementVNode("div", {
|
|
189
|
+
class: "_cppay-info-value",
|
|
190
|
+
style: {
|
|
191
|
+
"font-size": "12px",
|
|
192
|
+
color: "#856404"
|
|
193
|
+
}
|
|
194
|
+
}, " 订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。 ", -1)]])) : createCommentVNode("", !0)
|
|
195
|
+
]),
|
|
196
|
+
createElementVNode("div", _hoisted_35, [createElementVNode("button", {
|
|
128
197
|
onClick: Q,
|
|
129
|
-
disabled:
|
|
198
|
+
disabled: L.value,
|
|
130
199
|
class: "_cppay-btn _cppay-btn-primary"
|
|
131
|
-
}, toDisplayString(
|
|
132
|
-
createElementVNode("div",
|
|
133
|
-
onClick:
|
|
134
|
-
disabled:
|
|
200
|
+
}, toDisplayString(L.value ? "检查支付状态..." : "我已完成支付"), 9, _hoisted_36)]),
|
|
201
|
+
createElementVNode("div", _hoisted_37, [createElementVNode("button", {
|
|
202
|
+
onClick: j[0] ||= (e) => I.value = "select",
|
|
203
|
+
disabled: L.value,
|
|
135
204
|
class: "_cppay-btn _cppay-btn-secondary"
|
|
136
|
-
}, " 更改支付方式 ", 8,
|
|
205
|
+
}, " 更改支付方式 ", 8, _hoisted_38)])
|
|
137
206
|
])) : createCommentVNode("", !0)])])])) : createCommentVNode("", !0)]),
|
|
138
207
|
_: 1
|
|
139
208
|
})]));
|
|
140
209
|
}
|
|
141
|
-
}), [["__scopeId", "data-v-
|
|
210
|
+
}), [["__scopeId", "data-v-681ced40"]]);
|
|
142
211
|
injectStyle(payment_dialog_default);
|
|
143
212
|
export { PaymentDialog_default as PaymentDialog };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cppay-sdk",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite",
|
|
@@ -33,23 +33,24 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"vue": "^3.0.0",
|
|
37
36
|
"react": ">=16.8.0",
|
|
38
|
-
"react-dom": ">=16.8.0"
|
|
37
|
+
"react-dom": ">=16.8.0",
|
|
38
|
+
"vue": "^3.0.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
41
|
-
"vue": {
|
|
42
|
-
"optional": true
|
|
43
|
-
},
|
|
44
41
|
"react": {
|
|
45
42
|
"optional": true
|
|
46
43
|
},
|
|
47
44
|
"react-dom": {
|
|
48
45
|
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"vue": {
|
|
48
|
+
"optional": true
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/node": "^25.0.8",
|
|
53
|
+
"@types/qrcode": "^1",
|
|
53
54
|
"@types/react": "^19",
|
|
54
55
|
"@types/react-dom": "^19",
|
|
55
56
|
"@vitejs/plugin-react": "^5.1.2",
|
|
@@ -70,5 +71,9 @@
|
|
|
70
71
|
"author": "",
|
|
71
72
|
"license": "MIT",
|
|
72
73
|
"repository": "",
|
|
73
|
-
"keywords": []
|
|
74
|
+
"keywords": [],
|
|
75
|
+
"dependencies": {
|
|
76
|
+
"qrcode": "^1.5.4",
|
|
77
|
+
"rxjs": "^7.8.2"
|
|
78
|
+
}
|
|
74
79
|
}
|
package/dist/cppay-S6x6aDqU.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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{apikey;constructor(e){this.apikey=e}async getSupportedChains(){return(await a(this.apikey,{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,receiveAddresses:e.receive_addresses}))}async createOnetimePayment(e,t,n,r){let i={chain:e,token:t,order_no:n,amount:r},o=await a(this.apikey,{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.apikey,{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={payment_id:e},n=await a(this.apikey,{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={subscription_id:e},n=await a(this.apikey,{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.apikey,{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){this.api=new o(e)}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,receiveAddresses:r.receiveAddresses,icon:t[r.tokenSymbol]}),n[r.chain]=i,n},{});return Object.values(n)}async createPayment(e,t){switch(e){case`one-time`:return this.createOnetimePayment(t);case`subscription`:return this.createSubscriptionPayment(t)}}async checkPaymentStatus(e,t){switch(e){case`one-time`: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.paymentId)}}async checkSubscriptionPaymentStatus(e){return{...await this.api.checkSubcriptionPaymentStatus(e.subscriptionId)}}async getSubcriptionPayments(e){return{...await this.api.getSubcriptionPayments(e.subscriptionId)}}},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 +0,0 @@
|
|
|
1
|
-
var e=`._cppay-overlay{z-index:9999;background-color:#00000080;justify-content:center;align-items:center;padding:1rem;display:flex;position:fixed;inset:0}._cppay-dialog{background-color:#fff;border-radius:1.5rem;width:100%;max-width:28rem;overflow:hidden;box-shadow:0 20px 25px -5px #0000001a,0 10px 10px -5px #0000000a}._cppay-header{border-bottom:1px solid #e5e7eb;justify-content:space-between;align-items:center;padding:1.5rem;display:flex}._cppay-title{color:#111827;margin:0;font-size:1.25rem;font-weight:600}._cppay-close-btn{color:#9ca3af;cursor:pointer;background:0 0;border:none;padding:.25rem;transition:color .2s}._cppay-close-btn:hover:not(:disabled){color:#4b5563}._cppay-close-btn:disabled{opacity:.5;cursor:not-allowed}._cppay-close-btn svg{width:1.5rem;height:1.5rem}._cppay-content{padding:1.5rem}._cppay-section{margin-bottom:1.5rem}._cppay-section:last-child{margin-bottom:0}._cppay-label{color:#374151;margin-bottom:.5rem;font-size:.875rem;font-weight:500;display:block}._cppay-grid{grid-template-columns:repeat(2,1fr);gap:.75rem;display:grid}._cppay-select-btn{cursor:pointer;background:#fff;border:2px solid #e5e7eb;border-radius:.75rem;align-items:center;gap:.5rem;padding:.75rem;font-family:inherit;font-size:.875rem;transition:all .2s;display:flex}._cppay-select-btn:hover{border-color:#d1d5db}._cppay-select-btn._cppay-selected{background-color:#eff6ff;border-color:#2563eb}._cppay-select-btn img{border-radius:9999px;width:1.5rem;height:1.5rem}._cppay-select-btn span{font-weight:500}._cppay-price-box{background-color:#f9fafb;border-radius:1rem;padding:1rem}._cppay-price-row{justify-content:space-between;align-items:center;display:flex}._cppay-price-label{color:#4b5563;font-size:.875rem}._cppay-price-amount{text-align:right}._cppay-price-main{color:#111827;margin:0;font-size:1.25rem;font-weight:700}._cppay-price-sub{color:#6b7280;margin-top:.25rem;font-size:.875rem}._cppay-btn{cursor:pointer;border:none;border-radius:.75rem;width:100%;padding:.75rem;font-family:inherit;font-size:1rem;font-weight:500;transition:all .2s}._cppay-btn-primary{color:#fff;background-color:#2563eb}._cppay-btn-primary:hover:not(:disabled){background-color:#1d4ed8}._cppay-btn-primary:disabled{opacity:.5;cursor:not-allowed}._cppay-btn-secondary{color:#374151;background-color:#fff;border:1px solid #d1d5db}._cppay-btn-secondary:hover:not(:disabled){background-color:#f9fafb}._cppay-btn-secondary:disabled{opacity:.5;cursor:not-allowed}._cppay-qr-container{justify-content:center;margin-bottom:1.5rem;display:flex}._cppay-qr-placeholder{background-color:#f3f4f6;border-radius:1rem;justify-content:center;align-items:center;width:12rem;height:12rem;display:flex}._cppay-qr-placeholder span{color:#9ca3af;font-size:.875rem}._cppay-info-box{background-color:#f9fafb;border-radius:.75rem;margin-bottom:.75rem;padding:1rem}._cppay-info-box:last-child{margin-bottom:0}._cppay-info-label{color:#4b5563;margin-bottom:.25rem;font-size:.875rem}._cppay-info-value{color:#111827;font-size:1.25rem;font-weight:700}._cppay-address-row{align-items:center;gap:.5rem;display:flex}._cppay-address-row code{text-overflow:ellipsis;white-space:nowrap;color:#111827;background:0 0;flex:1;font-family:monospace;font-size:.75rem;overflow:hidden}._cppay-copy-btn{color:#2563eb;cursor:pointer;background:0 0;border:none;justify-content:center;align-items:center;padding:.25rem;transition:color .2s;display:flex}._cppay-copy-btn:hover{color:#1d4ed8}._cppay-copy-btn svg{width:1.25rem;height:1.25rem}@keyframes _cppay-fadeIn{0%{opacity:0}to{opacity:1}}@keyframes _cppay-slideUp{0%{opacity:0;transform:translateY(1.25rem)}to{opacity:1;transform:translateY(0)}}._cppay-overlay{animation:.3s _cppay-fadeIn}._cppay-dialog{animation:.3s _cppay-slideUp}@media (max-width:640px){._cppay-dialog{margin:.5rem}._cppay-header,._cppay-content{padding:1rem}}`;function t(e){if(typeof document>`u`||document.getElementById(`_cppay-payment-dialog-style`))return;let t=document.createElement(`style`);t.id=`_cppay-payment-dialog-style`,t.textContent=e,document.head.appendChild(t)}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|