cppay-sdk 0.0.2-beta.2 → 0.0.2-beta.21

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.
@@ -0,0 +1,218 @@
1
+ const CHAIN_ICONS = {
2
+ Ethereum: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png",
3
+ BSC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png",
4
+ "bsc-testnet": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png",
5
+ Tron: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png",
6
+ Polygon: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/polygon/info/logo.png",
7
+ Solana: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png"
8
+ }, TOKEN_ICONS = {
9
+ USDT: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png",
10
+ USDC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
11
+ ETH: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png",
12
+ BNB: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png",
13
+ tBNB: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png",
14
+ TRX: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png",
15
+ SOL: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png"
16
+ };
17
+ var BASE_URL = "http://192.168.0.162:8000", request = async (e, t, r) => {
18
+ let i = Object.assign({ timeout: 15e3 }, r), a = new AbortController(), o = setTimeout(() => a.abort(), i.timeout);
19
+ try {
20
+ let r = await fetch(new URL(e, BASE_URL), {
21
+ signal: a.signal,
22
+ ...t
23
+ });
24
+ clearTimeout(o);
25
+ let i = r.headers.get("Content-Type") ?? "";
26
+ if (i.includes("json")) return await r.json();
27
+ try {
28
+ return await r.json();
29
+ } catch {
30
+ throw Error(`URL: ${e}, Unsupport Content Type: ${i}`);
31
+ }
32
+ } catch (t) {
33
+ throw clearTimeout(o), t instanceof DOMException && t.name === "AbortError" ? Error(`URL: ${e}, Request timeout after ${i.timeout}ms`) : t;
34
+ }
35
+ }, SUCCESS_CODE = 0, cppayRequest = async (e, t) => {
36
+ let n = new URLSearchParams(t.params), a = await request(`${t.url}${n.size ? `?${n.toString()}` : ""}`, {
37
+ method: t.method ?? "get",
38
+ headers: {
39
+ Authorization: e,
40
+ ...t.headers
41
+ },
42
+ body: t.data ? JSON.stringify(t.data) : void 0
43
+ });
44
+ if (a.code !== SUCCESS_CODE) throw Error(`Request ${t.url} Failed. ${a.message}`);
45
+ return a.data;
46
+ }, CppayApi = class {
47
+ apikey;
48
+ constructor(e) {
49
+ this.apikey = e;
50
+ }
51
+ async getSupportedChains() {
52
+ return (await cppayRequest(this.apikey, { url: "/api/payment/token" })).map((e) => ({
53
+ chain: e.chain,
54
+ chainId: e.chain_id,
55
+ tokenSymbol: e.token_symbol,
56
+ tokenDecimals: e.token_decimals,
57
+ tokenAddress: e.token_address,
58
+ tokenPrice: e.token_price
59
+ }));
60
+ }
61
+ async createOnetimePayment(e, t, n, r) {
62
+ let i = {
63
+ chain: e,
64
+ token: t,
65
+ order_no: n,
66
+ amount: r
67
+ }, o = await cppayRequest(this.apikey, {
68
+ url: "/api/payment/create",
69
+ method: "post",
70
+ data: i
71
+ });
72
+ return {
73
+ paymentId: o.payment_id,
74
+ paymentAmount: o.pay_amount,
75
+ receiveAddress: o.receive_address,
76
+ expireAt: o.expire_at
77
+ };
78
+ }
79
+ async createSubscriptionPayment(e, t, n, r, i) {
80
+ let o = {
81
+ chain: e,
82
+ token: t,
83
+ order_no: n,
84
+ amount_usd: r,
85
+ renewal_days: i
86
+ }, s = await cppayRequest(this.apikey, {
87
+ url: "/api/subscription/create",
88
+ method: "post",
89
+ data: o
90
+ });
91
+ return {
92
+ subscriptionId: s.subscription_id,
93
+ approveAmount: s.approved_amount,
94
+ spenderAddress: s.contract_address,
95
+ expireAt: s.expire_at
96
+ };
97
+ }
98
+ async createX402Payment() {
99
+ throw Error("Unsupported payment mode");
100
+ }
101
+ async checkOnetimePaymentStatus(e) {
102
+ let t = { payment_id: e }, n = await cppayRequest(this.apikey, {
103
+ url: "/api/payment/query",
104
+ params: t
105
+ });
106
+ return {
107
+ orderId: n.order_no,
108
+ paymentId: n.payment_id,
109
+ chain: n.chain,
110
+ token: n.token,
111
+ baseAmount: n.base_amount,
112
+ payAmount: n.pay_amount,
113
+ receiveAddress: n.receive_address,
114
+ expireAt: n.expire_at,
115
+ status: n.status
116
+ };
117
+ }
118
+ async checkSubcriptionPaymentStatus(e) {
119
+ let t = { subscription_id: e }, n = await cppayRequest(this.apikey, {
120
+ url: "/api/subscription/query",
121
+ params: t
122
+ });
123
+ return {
124
+ orderId: n.order_no,
125
+ subscriptionId: n.subscription_id,
126
+ chain: n.chain,
127
+ token: n.token,
128
+ approvedAddress: n.approved_contract_address,
129
+ txHash: n.approved_tx_hash,
130
+ approveAmount: n.approved_amount,
131
+ amountOfUsd: n.amount_usd,
132
+ expireAt: n.expire_at,
133
+ status: n.subscription_status
134
+ };
135
+ }
136
+ async getSubcriptionPayments(e) {
137
+ let t = { subscription_id: e }, n = await cppayRequest(this.apikey, {
138
+ url: "/api/subscription/payments",
139
+ params: t
140
+ });
141
+ return {
142
+ total: n.total,
143
+ payments: (n.payments ?? []).map((e) => ({
144
+ orderId: e.order_no,
145
+ subscriptionId: e.subscription_id,
146
+ chain: e.chain,
147
+ token: e.token,
148
+ txHash: e.tx_hash,
149
+ payAmount: e.pay_amount,
150
+ receiveAddress: e.receive_address,
151
+ status: e.status,
152
+ errorMessage: e.error_message
153
+ }))
154
+ };
155
+ }
156
+ async checkX402PaymentStatus() {
157
+ throw Error("Unsupported payment mode");
158
+ }
159
+ }, cppay_default = class {
160
+ api;
161
+ constructor(e) {
162
+ this.api = new CppayApi(e);
163
+ }
164
+ async getSupportedChains() {
165
+ let n = (await this.api.getSupportedChains()).reduce((n, r) => {
166
+ let i = n[r.chain] ?? {
167
+ chain: r.chain,
168
+ chainId: r.chainId,
169
+ tokens: [],
170
+ icon: CHAIN_ICONS[r.chain]
171
+ };
172
+ return i.tokens.push({
173
+ symbol: r.tokenSymbol,
174
+ decimals: r.tokenDecimals,
175
+ address: r.tokenAddress,
176
+ icon: TOKEN_ICONS[r.tokenSymbol],
177
+ price: r.tokenPrice
178
+ }), n[r.chain] = i, n;
179
+ }, {});
180
+ return Object.values(n);
181
+ }
182
+ async createPayment(e, t) {
183
+ switch (e) {
184
+ case "one-time": return this.createOnetimePayment(t);
185
+ case "subscription": return this.createSubscriptionPayment(t);
186
+ }
187
+ }
188
+ async checkPaymentStatus(e, t) {
189
+ switch (e) {
190
+ case "one-time": return this.checkOnetimePaymentStatus(t);
191
+ case "subscription": return this.checkSubscriptionPaymentStatus(t);
192
+ }
193
+ }
194
+ async createOnetimePayment(e) {
195
+ let t = await this.api.createOnetimePayment(e.paymentChain, e.paymentToken, e.orderId, e.amount);
196
+ return {
197
+ ...e,
198
+ ...t
199
+ };
200
+ }
201
+ async createSubscriptionPayment(e) {
202
+ let t = await this.api.createSubscriptionPayment(e.paymentChain, e.paymentToken, e.orderId, e.amountOfUsd, e.intervalDays);
203
+ return {
204
+ ...e,
205
+ ...t
206
+ };
207
+ }
208
+ async checkOnetimePaymentStatus(e) {
209
+ return { ...await this.api.checkOnetimePaymentStatus(e.paymentId) };
210
+ }
211
+ async checkSubscriptionPaymentStatus(e) {
212
+ return { ...await this.api.checkSubcriptionPaymentStatus(e.subscriptionId) };
213
+ }
214
+ async getSubcriptionPayments(e) {
215
+ return { ...await this.api.getSubcriptionPayments(e.subscriptionId) };
216
+ }
217
+ };
218
+ export { CHAIN_ICONS as n, TOKEN_ICONS as r, cppay_default as t };
@@ -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,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.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],price:r.tokenPrice}),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}});
@@ -0,0 +1,2 @@
1
+ ._cppay-fade-enter-active[data-v-1a5fedf2],._cppay-fade-leave-active[data-v-1a5fedf2]{transition:opacity .3s}._cppay-fade-enter-from[data-v-1a5fedf2],._cppay-fade-leave-to[data-v-1a5fedf2]{opacity:0}._cppay-fade-enter-active ._cppay-dialog[data-v-1a5fedf2]{animation:.3s _cppay-slideUp}
2
+ /*$vite$:1*/
package/dist/index.cjs CHANGED
@@ -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`,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`,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;const a=async(e,t)=>{let n=await r(t.url,{method:t.method??`get`,headers:{Authorization:e,...t.headers},body:JSON.stringify(t.data)});if(n.code!==i)throw Error(`Request ${t.url} Failed. ${n.message}`);return n.data},o=(e=1e3)=>new Promise(t=>setTimeout(t,e));var s=class{apikey;constructor(e){this.apikey=e}async getSupportedChains(){let n=(await a(this.apikey,{url:`/api/payment/token`})).reduce((n,r)=>{let i=n[r.chain]??{chain:r.chain,tokens:[],icon:e[r.chain]};return i.tokens.push({symbol:r.token_symbol,decimals:r.token_decimals,address:r.token_address,receiveAddresses:r.receive_addresses,icon:t[r.token_symbol]}),n[r.chain]=i,n},{});return Object.values(n)}async createPayment(e){let t={chain:e.paymentChain,token:e.paymentToken,order_no:e.orderId,amount:e.amount},n=await a(this.apikey,{url:`/api/payment/create`,method:`post`,data:t});return{orderId:e.orderId,paymentId:n.payment_id,paymentAmount:n.pay_amount,paymentChain:e.paymentChain,paymentToken:e.paymentToken}}async checkPaymentStatus(e,t=1e3){let n=15;for(;n--;){let n={payment_id:e};if((await a(this.apikey,{url:`/api/payment/query`,data:n})).status===`success`)return;await o(t)}throw Error(`Check Payment Status Timeout, PaymentId: ${e}`)}},c=s;exports.CHAIN_ICONS=e,exports.Cppay=c,exports.TOKEN_ICONS=t;
1
+ const e=require(`./cppay-DnxPUyM2.cjs`);exports.CHAIN_ICONS=e.n,exports.Cppay=e.t,exports.TOKEN_ICONS=e.r;
package/dist/index.d.ts CHANGED
@@ -1,26 +1,47 @@
1
1
  export declare type Address = `0x${string}`;
2
2
 
3
- export declare type Chain = "Ethereum" | "BSC" | "Tron" | "Polygon" | "Solana";
4
-
5
- export declare const CHAIN_ICONS: Record<Chain, string>;
3
+ export declare const CHAIN_ICONS: Record<string, string>;
6
4
 
7
5
  export declare interface ChainInfo {
8
6
  icon?: string;
9
- chain: Chain;
7
+ chain: string;
8
+ chainId: number;
10
9
  tokens: TokenInfo[];
11
10
  }
12
11
 
13
12
  export declare class Cppay {
14
- private apikey;
13
+ private api;
15
14
  constructor(apikey: string);
16
15
  getSupportedChains(): Promise<ChainInfo[]>;
17
- createPayment(params: {
18
- paymentChain: Chain;
19
- paymentToken: Token;
16
+ createPayment(plain: "one-time", params: Parameters<Cppay["createOnetimePayment"]>[0]): Promise<OnetimePaymentInfo>;
17
+ createPayment(plain: "subscription", params: Parameters<Cppay["createSubscriptionPayment"]>[0]): Promise<SubscriptionPaymentInfo>;
18
+ checkPaymentStatus(plain: "one-time", params: Parameters<Cppay["checkOnetimePaymentStatus"]>[0]): Promise<OnetimePaymentOrderStatus>;
19
+ checkPaymentStatus(plain: "subscription", params: Parameters<Cppay["checkSubscriptionPaymentStatus"]>[0]): Promise<SubscriptionPaymentOrderStatus>;
20
+ createOnetimePayment(params: {
21
+ paymentChain: string;
22
+ paymentToken: string;
20
23
  orderId: string;
21
24
  amount: Numberic;
22
- }): Promise<PaymentInfo>;
23
- checkPaymentStatus(paymentId: string, interval?: number): Promise<void>;
25
+ }): Promise<OnetimePaymentInfo>;
26
+ createSubscriptionPayment(params: {
27
+ paymentChain: string;
28
+ paymentToken: string;
29
+ orderId: string;
30
+ amountOfUsd: Numberic;
31
+ intervalDays: number;
32
+ }): Promise<SubscriptionPaymentInfo>;
33
+ checkOnetimePaymentStatus(params: {
34
+ paymentId: string;
35
+ }): Promise<OnetimePaymentOrderStatus>;
36
+ checkSubscriptionPaymentStatus(params: {
37
+ subscriptionId: string;
38
+ }): Promise<SubscriptionPaymentOrderStatus>;
39
+ getSubcriptionPayments(params: {
40
+ subscriptionId: string;
41
+ }): Promise<{
42
+ total: number;
43
+ payments: SubscriptionPayment[];
44
+ }>;
24
45
  }
25
46
 
26
47
  export declare interface CppayResponse<R> {
@@ -31,24 +52,85 @@ export declare interface CppayResponse<R> {
31
52
 
32
53
  export declare type Numberic = `${number}.${number}` | `${number}`;
33
54
 
34
- export declare interface PaymentInfo {
55
+ export declare interface OnetimePaymentInfo {
35
56
  orderId: string;
36
57
  paymentId: string;
37
58
  paymentAmount: Numberic;
38
- paymentChain: Chain;
39
- paymentToken: Token;
59
+ paymentChain: string;
60
+ paymentToken: string;
61
+ receiveAddress: Address;
62
+ }
63
+
64
+ export declare interface OnetimePaymentOrderStatus {
65
+ orderId: string;
66
+ paymentId: string;
67
+ chain: string;
68
+ token: string;
69
+ baseAmount: Numberic;
70
+ payAmount: Numberic;
71
+ receiveAddress: Address;
72
+ expireAt: number;
73
+ status: PaymentStatus;
74
+ }
75
+
76
+ export declare type PaymentPlain = "one-time" | "subscription" | "x402";
77
+
78
+ export declare type PaymentStatus = "pending" | "paid" | "expired" | "failed";
79
+
80
+ export declare interface SubscriptionPayment {
81
+ orderId: string;
82
+ subscriptionId: string;
83
+ chain: string;
84
+ token: string;
85
+ payAmount: Numberic;
86
+ txHash: string;
87
+ receiveAddress: Address;
88
+ status: PaymentStatus;
89
+ errorMessage: string;
90
+ }
91
+
92
+ export declare interface SubscriptionPaymentInfo {
93
+ subscriptionId: string;
94
+ approveAmount: Numberic;
95
+ spenderAddress: Address;
96
+ expireAt: number;
97
+ paymentChain: string;
98
+ paymentToken: string;
99
+ orderId: string;
100
+ amountOfUsd: Numberic;
101
+ intervalDays: number;
102
+ }
103
+
104
+ export declare interface SubscriptionPaymentOrderStatus {
105
+ orderId: string;
106
+ subscriptionId: string;
107
+ chain: string;
108
+ token: string;
109
+ approvedAddress: string;
110
+ txHash: string;
111
+ approveAmount: string;
112
+ amountOfUsd: string;
113
+ expireAt: number;
114
+ status: SubscriptionPaymentStatus;
40
115
  }
41
116
 
42
- export declare type Token = "USDT" | "USDC" | "ETH" | "BNB" | "TRX" | "SOL";
117
+ export declare type SubscriptionPaymentStatus = "pending" | "approved" | "expired" | "failed";
43
118
 
44
- export declare const TOKEN_ICONS: Record<Token, string>;
119
+ export declare const TOKEN_ICONS: Record<string, string>;
45
120
 
46
121
  export declare interface TokenInfo {
47
122
  icon?: string;
48
- symbol: Token;
123
+ symbol: string;
124
+ price: Numberic;
49
125
  decimals: number;
50
126
  address: Address | "";
51
- receiveAddresses: Address[];
52
127
  }
53
128
 
54
129
  export { }
130
+
131
+
132
+ declare module "@vue/runtime-core" {
133
+ interface ComponentCustomProperties {
134
+ $showPayment: typeof showPayment;
135
+ }
136
+ }
package/dist/index.js CHANGED
@@ -1,100 +1,2 @@
1
- const CHAIN_ICONS = {
2
- Ethereum: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png",
3
- BSC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png",
4
- Tron: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png",
5
- Polygon: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/polygon/info/logo.png",
6
- Solana: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png"
7
- }, TOKEN_ICONS = {
8
- USDT: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png",
9
- USDC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
10
- ETH: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png",
11
- BNB: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png",
12
- TRX: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png",
13
- SOL: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png"
14
- };
15
- var BASE_URL = "http://192.168.0.162:8000", request = async (e, n, i) => {
16
- let a = Object.assign({ timeout: 15e3 }, i), o = new AbortController(), s = setTimeout(() => o.abort(), a.timeout);
17
- try {
18
- let i = await fetch(new URL(e, BASE_URL), {
19
- signal: o.signal,
20
- ...n
21
- });
22
- clearTimeout(s);
23
- let a = i.headers.get("Content-Type") ?? "";
24
- if (a.includes("json")) return await i.json();
25
- try {
26
- return await i.json();
27
- } catch {
28
- throw Error(`URL: ${e}, Unsupport Content Type: ${a}`);
29
- }
30
- } catch (n) {
31
- throw clearTimeout(s), n instanceof DOMException && n.name === "AbortError" ? Error(`URL: ${e}, Request timeout after ${a.timeout}ms`) : n;
32
- }
33
- }, SUCCESS_CODE = 0;
34
- const cppayRequest = async (e, n) => {
35
- let r = await request(n.url, {
36
- method: n.method ?? "get",
37
- headers: {
38
- Authorization: e,
39
- ...n.headers
40
- },
41
- body: JSON.stringify(n.data)
42
- });
43
- if (r.code !== SUCCESS_CODE) throw Error(`Request ${n.url} Failed. ${r.message}`);
44
- return r.data;
45
- }, sleep = (e = 1e3) => new Promise((n) => setTimeout(n, e));
46
- var cppay_default = class {
47
- apikey;
48
- constructor(e) {
49
- this.apikey = e;
50
- }
51
- async getSupportedChains() {
52
- let r = (await cppayRequest(this.apikey, { url: "/api/payment/token" })).reduce((r, i) => {
53
- let a = r[i.chain] ?? {
54
- chain: i.chain,
55
- tokens: [],
56
- icon: CHAIN_ICONS[i.chain]
57
- };
58
- return a.tokens.push({
59
- symbol: i.token_symbol,
60
- decimals: i.token_decimals,
61
- address: i.token_address,
62
- receiveAddresses: i.receive_addresses,
63
- icon: TOKEN_ICONS[i.token_symbol]
64
- }), r[i.chain] = a, r;
65
- }, {});
66
- return Object.values(r);
67
- }
68
- async createPayment(e) {
69
- let n = {
70
- chain: e.paymentChain,
71
- token: e.paymentToken,
72
- order_no: e.orderId,
73
- amount: e.amount
74
- }, r = await cppayRequest(this.apikey, {
75
- url: "/api/payment/create",
76
- method: "post",
77
- data: n
78
- });
79
- return {
80
- orderId: e.orderId,
81
- paymentId: r.payment_id,
82
- paymentAmount: r.pay_amount,
83
- paymentChain: e.paymentChain,
84
- paymentToken: e.paymentToken
85
- };
86
- }
87
- async checkPaymentStatus(e, n = 1e3) {
88
- let r = 15;
89
- for (; r--;) {
90
- let r = { payment_id: e };
91
- if ((await cppayRequest(this.apikey, {
92
- url: "/api/payment/query",
93
- data: r
94
- })).status === "success") return;
95
- await sleep(n);
96
- }
97
- throw Error(`Check Payment Status Timeout, PaymentId: ${e}`);
98
- }
99
- };
1
+ import { n as CHAIN_ICONS, r as TOKEN_ICONS, t as cppay_default } from "./cppay-BcCDwXlg.js";
100
2
  export { CHAIN_ICONS, cppay_default as Cppay, TOKEN_ICONS };
package/dist/react.cjs ADDED
@@ -0,0 +1 @@
1
+ const e=require(`./walletconnect-B_n5YF-h.cjs`),t=require(`./cppay-DnxPUyM2.cjs`);let n=require(`rxjs`),r=require(`rxjs/operators`),i=require(`viem`),a=require(`viem/chains`),o=require(`@walletconnect/ethereum-provider`);o=e.o(o);let s=require(`react`);s=e.o(s);let c=require(`react/jsx-runtime`);var l=e.o(e.r(),1),u=({open:u,onClose:d,apikey:f,plain:p,orderId:m,amount:h,intervalDays:g,onExpired:_,onSuccess:v,onFailed:y,onError:b})=>{let x=(0,s.useMemo)(()=>new t.t(f),[f]),[S,C]=(0,s.useState)(`select`),[w,T]=(0,s.useState)(!1),[E,D]=(0,s.useState)([]),[O,k]=(0,s.useState)(``),[A,j]=(0,s.useState)(``),[M,N]=(0,s.useState)(``),[P,F]=(0,s.useState)(``),[I,L]=(0,s.useState)(!1),[R,z]=(0,s.useState)(null),B=(0,s.useRef)(null),V=(0,s.useRef)(null),H=(0,s.useMemo)(()=>E.find(e=>e.chain===O),[E,O]),U=(0,s.useMemo)(()=>H?.tokens||[],[H]),W=(0,s.useMemo)(()=>U.find(e=>e.symbol===A),[U,A]),G=e=>[`USDT`,`USDC`,`BUSD`,`DAI`,`TUSD`,`USDD`,`FDUSD`].includes(e.toUpperCase())?2:6,K=e=>({ETH:a.mainnet,BSC:a.bsc,Polygon:a.polygon,Arbitrum:a.arbitrum,Optimism:a.optimism,Base:a.base})[e]||a.mainnet,q=(e,t)=>{let n=parseFloat(e);return isNaN(n)?`0`:n.toFixed(t).replace(/\.?0+$/,``)},J=(0,s.useMemo)(()=>{if(!A||!W)return`0`;let e=parseFloat(W.price);if(isNaN(e)||e===0)return`0`;let t=G(A);return q((parseFloat(h)/e).toFixed(t),t)},[h,A,W]),ee=async()=>{try{T(!0);let e=await x.getSupportedChains();D(e),e.length>0&&k(e[0].chain)}catch(e){b?.(e)}finally{T(!1)}},Y=async e=>{try{if(L(!0),e===`metamask`){if(typeof window<`u`&&window.ethereum?.isMetaMask){let e=await window.ethereum.request({method:`eth_requestAccounts`});if(e&&e.length>0){F(e[0]),z(`metamask`);return}}throw Error(`请安装 MetaMask 扩展`)}if(e===`walletconnect`){let e=await o.default.init({projectId:`8d2e1854d3f1782e45aa15fbd8938894`,chains:[1],showQrModal:!0,optionalChains:[56,137,42161,10,8453],methods:[`eth_sendTransaction`,`eth_signTransaction`,`eth_sign`,`personal_sign`,`eth_signTypedData`],events:[`chainChanged`,`accountsChanged`],metadata:{name:`Cppay`,description:`Cppay Payment Gateway`,url:typeof window<`u`?window.location.origin:`https://cppay.com`,icons:[`https://cppay.com/icon.png`]},rpcMap:{1:`https://ethereum.publicnode.com`,56:`https://bsc-dataseed.binance.org`,137:`https://polygon-rpc.com`,42161:`https://arb1.arbitrum.io/rpc`,10:`https://mainnet.optimism.io`,8453:`https://mainnet.base.org`}});await e.enable();let t=await e.request({method:`eth_accounts`});t&&t.length>0&&(F(t[0]),z(`walletconnect`),B.current=e)}}catch(e){console.error(`钱包连接失败:`,e),b?.(e)}finally{L(!1)}},X=async e=>{let t;if(t=R===`walletconnect`?B.current:window.ethereum,t)try{await t.request({method:`wallet_switchEthereumChain`,params:[{chainId:`0x${e.toString(16)}`}]})}catch(e){throw e.code===4902?Error(`请在钱包中添加该网络`):e}},te=async()=>{if(!(!P||!Z.current||!W))try{T(!0);let e=Z.current,t=K(O);await X(H.chainId);let n=(0,i.createWalletClient)({account:P,chain:t,transport:(0,i.custom)(R===`walletconnect`?B.current:window.ethereum)});if(W.address){let t=await n.writeContract({address:W.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,i.parseUnits)(e.paymentAmount,W.decimals)],chain:null});console.log(`转账交易哈希:`,t)}else{let t=await n.sendTransaction({to:e.receiveAddress,value:(0,i.parseUnits)(e.paymentAmount,W.decimals),chain:null});console.log(`转账交易哈希:`,t)}Q(e.paymentId)}catch(e){console.error(`钱包支付失败:`,e),b?.(e)}finally{T(!1)}},ne=async()=>{if(!(!P||!Z.current||!W))try{T(!0);let e=Z.current,t=K(O);await X(H.chainId);let n=(0,i.createWalletClient)({account:P,chain:t,transport:(0,i.custom)(R===`walletconnect`?B.current:window.ethereum)});if(!W.address)throw Error(`订阅支付不支持原生代币`);let r=await n.writeContract({address:W.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,i.parseUnits)(e.approveAmount,W.decimals)],chain:null});console.log(`授权交易哈希:`,r),Q(e.subscriptionId)}catch(e){console.error(`钱包授权失败:`,e),b?.(e)}finally{T(!1)}},re=async()=>{if(!P){b?.(Error(`请先连接钱包`));return}p===`one-time`?await te():p===`subscription`&&await ne()},Z=(0,s.useRef)(null),ie=async()=>{if(!(!O||!A))try{T(!0);let e=``;p===`one-time`?(Z.current=await x.createOnetimePayment({paymentChain:O,paymentToken:A,orderId:m,amount:J}),e=`${O.toLowerCase()}:${Z.current.receiveAddress}?amount=${Z.current.paymentAmount}`):p===`subscription`&&(Z.current=await x.createSubscriptionPayment({paymentChain:O,paymentToken:A,orderId:m,amountOfUsd:J,intervalDays:g||30}),e=`${O.toLowerCase()}:${Z.current.spenderAddress}?amount=${Z.current.approveAmount}`),C(`payment`),N(await l.toDataURL(e,{width:200,margin:2,errorCorrectionLevel:`H`}))}catch(e){b?.(e)}finally{T(!1)}},ae=async()=>{if(Z.current)try{T(!0),p===`one-time`?Q(Z.current.paymentId):p===`subscription`&&Q(Z.current.subscriptionId)}catch(e){console.error(`支付状态检查错误:`,e),b?.(e),T(!1)}},Q=e=>{let t=()=>(0,n.defer)(()=>p===`subscription`?x.checkSubscriptionPaymentStatus({subscriptionId:e}):x.checkOnetimePaymentStatus({paymentId:e})).pipe((0,r.timeout)(15e3),(0,r.retry)({count:3,delay:2e3}));V.current?.unsubscribe(),V.current=t().pipe((0,r.expand)(e=>e.status===`pending`?(0,n.timer)(2e3).pipe((0,r.switchMap)(()=>t())):n.EMPTY),(0,r.tap)(e=>{e.status===`expired`&&(T(!1),_?.(e)),e.status===`paid`&&(T(!1),C(`success`),v?.(e)),e.status===`failed`&&(T(!1),y?.(e)),e.status===`approved`&&(T(!1),C(`success`),v?.(e))})).subscribe({error:e=>{console.error(`支付状态检查错误:`,e),T(!1),b?.(e)}})},oe=async()=>{if(!Z.current)return;let e=p===`subscription`?Z.current.spenderAddress:Z.current.receiveAddress;e&&await navigator.clipboard.writeText(e)},$=()=>{w||(d(),setTimeout(()=>{C(`select`),Z.current=null},300))};return(0,s.useEffect)(()=>{u&&E.length===0&&ee()},[u]),(0,s.useEffect)(()=>{U.length>0&&j(U[0].symbol)},[U]),(0,s.useEffect)(()=>()=>{V.current?.unsubscribe()},[]),u?(0,c.jsx)(`div`,{className:`_cppay-overlay`,onClick:e=>e.target===e.currentTarget&&!w&&$(),children:(0,c.jsxs)(`div`,{className:`_cppay-dialog`,children:[(0,c.jsxs)(`div`,{className:`_cppay-header`,children:[(0,c.jsx)(`h2`,{className:`_cppay-title`,children:S===`select`?`选择支付方式`:`完成支付`}),(0,c.jsx)(`button`,{onClick:$,disabled:w,className:`_cppay-close-btn`,children:(0,c.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,c.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,c.jsx)(`div`,{className:`_cppay-content`,children:S===`success`?(0,c.jsxs)(`div`,{style:{textAlign:`center`,padding:`2rem 0`},children:[(0,c.jsx)(`div`,{style:{fontSize:`64px`,marginBottom:`1rem`},children:`✅`}),(0,c.jsx)(`h3`,{style:{fontSize:`1.5rem`,fontWeight:600,color:`#10b981`,margin:`0 0 0.5rem 0`},children:p===`subscription`?`授权成功!`:`支付成功!`}),(0,c.jsx)(`p`,{style:{color:`#6b7280`,margin:0},children:p===`subscription`?`订阅已激活`:`交易已完成`})]}):S===`select`?(0,c.jsxs)(`div`,{children:[(0,c.jsxs)(`div`,{className:`_cppay-section`,children:[(0,c.jsx)(`label`,{className:`_cppay-label`,children:`支付网络`}),(0,c.jsx)(`div`,{className:`_cppay-grid`,children:E.map(e=>(0,c.jsxs)(`button`,{onClick:()=>k(e.chain),className:`_cppay-select-btn ${O===e.chain?`_cppay-selected`:``}`,children:[e.icon&&(0,c.jsx)(`img`,{src:e.icon,alt:e.chain}),(0,c.jsx)(`span`,{children:e.chain})]},e.chain))})]}),(0,c.jsxs)(`div`,{className:`_cppay-section`,children:[(0,c.jsx)(`label`,{className:`_cppay-label`,children:`支付代币`}),(0,c.jsx)(`div`,{className:`_cppay-grid`,children:U.map(e=>(0,c.jsxs)(`button`,{onClick:()=>j(e.symbol),className:`_cppay-select-btn ${A===e.symbol?`_cppay-selected`:``}`,children:[e.icon&&(0,c.jsx)(`img`,{src:e.icon,alt:e.symbol}),(0,c.jsx)(`span`,{children:e.symbol})]},e.symbol))})]}),(0,c.jsx)(`div`,{className:`_cppay-section`,children:(0,c.jsx)(`div`,{className:`_cppay-price-box`,children:(0,c.jsxs)(`div`,{className:`_cppay-price-row`,children:[(0,c.jsx)(`span`,{className:`_cppay-price-label`,children:`支付金额`}),(0,c.jsxs)(`div`,{className:`_cppay-price-amount`,children:[(0,c.jsxs)(`div`,{className:`_cppay-price-main`,children:[J,` `,A]}),(0,c.jsxs)(`div`,{className:`_cppay-price-sub`,children:[`≈ $`,h]})]})]})})}),(0,c.jsx)(`div`,{className:`_cppay-section`,children:(0,c.jsx)(`button`,{onClick:ie,disabled:!O||!A||w,className:`_cppay-btn _cppay-btn-primary`,children:w?`处理中...`:`继续支付`})})]}):(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`div`,{className:`_cppay-qr-container`,children:(0,c.jsx)(`div`,{className:`_cppay-qr-code`,children:M&&(0,c.jsx)(`img`,{src:M,alt:`Payment QR Code`,style:{width:`160px`,height:`160px`,display:`block`}})})}),(0,c.jsxs)(`div`,{className:`_cppay-section`,children:[(0,c.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,c.jsx)(`div`,{className:`_cppay-info-label`,children:p===`subscription`?`授权金额`:`支付金额`}),(0,c.jsx)(`div`,{className:`_cppay-info-value`,children:p===`subscription`?`${q(Z.current.approveAmount,G(A))} ${A}`:`${q(Z.current.paymentAmount,G(A))} ${A}`})]}),(0,c.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,c.jsx)(`div`,{className:`_cppay-info-label`,children:p===`subscription`?`授权合约地址`:`支付地址`}),(0,c.jsxs)(`div`,{className:`_cppay-address-row`,children:[(0,c.jsx)(`code`,{children:p===`subscription`?Z.current.spenderAddress:Z.current.receiveAddress}),(0,c.jsx)(`button`,{onClick:oe,className:`_cppay-copy-btn`,title:`复制地址`,children:(0,c.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,c.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`})})})]})]}),p===`subscription`&&(0,c.jsxs)(`div`,{className:`_cppay-info-box`,style:{background:`#fff3cd`,borderColor:`#ffc107`},children:[(0,c.jsx)(`div`,{className:`_cppay-info-label`,style:{color:`#856404`},children:`📌 订阅说明`}),(0,c.jsx)(`div`,{className:`_cppay-info-value`,style:{fontSize:`12px`,color:`#856404`},children:`订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。`})]})]}),(0,c.jsx)(`div`,{className:`_cppay-section`,children:P?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(`button`,{onClick:re,disabled:w,className:`_cppay-btn _cppay-btn-primary`,children:w?p===`subscription`?`授权中...`:`支付中...`:p===`subscription`?`💳 钱包授权`:`💳 钱包支付`}),(0,c.jsxs)(`div`,{style:{textAlign:`center`,marginTop:`8px`,fontSize:`12px`,color:`#666`},children:[`已连接: `,P.slice(0,6),`...`,P.slice(-4)]})]}):(0,c.jsxs)(`div`,{style:{display:`flex`,flexDirection:`row`,gap:`0.5rem`,justifyContent:`center`},children:[(0,c.jsxs)(`button`,{onClick:()=>Y(`metamask`),disabled:I,className:`_cppay-btn _cppay-btn-secondary`,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`0.5rem`,padding:`0.5rem 1rem`,fontSize:`14px`,flex:`1`},children:[(0,c.jsx)(`img`,{src:e.n,alt:`MetaMask`,style:{width:`20px`,height:`20px`}}),(0,c.jsx)(`span`,{children:`MetaMask`})]}),(0,c.jsxs)(`button`,{onClick:()=>Y(`walletconnect`),disabled:I,className:`_cppay-btn _cppay-btn-secondary`,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`0.5rem`,padding:`0.5rem 1rem`,fontSize:`14px`,flex:`1`},children:[(0,c.jsx)(`img`,{src:e.t,alt:`WalletConnect`,style:{width:`20px`,height:`20px`}}),(0,c.jsx)(`span`,{children:`WalletConnect`})]})]})}),(0,c.jsx)(`div`,{className:`_cppay-section`,children:(0,c.jsx)(`button`,{onClick:ae,disabled:w,className:`_cppay-btn _cppay-btn-primary`,children:w?`检查中...`:`我已完成支付`})}),(0,c.jsx)(`div`,{className:`_cppay-section`,children:(0,c.jsx)(`button`,{onClick:()=>C(`select`),disabled:w,className:`_cppay-btn _cppay-btn-text`,children:`更改支付方式`})})]})})]})}):null},d=s.default.memo(u),f=(0,s.createContext)(null);const p=({apikey:e,children:t})=>{let[n,r]=(0,s.useState)(!1),[i,a]=(0,s.useState)(null),o=(0,s.useCallback)(e=>{a(e),r(!0)},[]),l=(0,s.useCallback)(()=>{r(!1)},[]),u=(0,s.useCallback)(e=>{i?.onSuccess?.(e),r(!1)},[i]),p=(0,s.useCallback)(e=>{i?.onError?.(e)},[i]);return(0,c.jsxs)(f.Provider,{value:{showPayment:o},children:[t,i&&(0,c.jsx)(d,{open:n,onClose:l,apikey:e,plain:i.plain,orderId:i.orderId,amount:i.amount,intervalDays:i.intervalDays,onSuccess:u,onError:p})]})},m=()=>{let e=(0,s.useContext)(f);if(!e)throw Error(`useCppayPayment must be used within CppayProvider`);return e};e.i(e.a),exports.CppayProvider=p,exports.PaymentDialog=d,exports.useCppayPayment=m;
@@ -0,0 +1,84 @@
1
+ import { default as default_2 } from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ declare type Address = `0x${string}`;
5
+
6
+ declare interface CppayContextValue {
7
+ showPayment: (options: PaymentOptions_2) => void;
8
+ }
9
+
10
+ export declare const CppayProvider: default_2.FC<CppayProviderProps>;
11
+
12
+ declare interface CppayProviderProps {
13
+ apikey: string;
14
+ children: ReactNode;
15
+ }
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
+
31
+ export declare const PaymentDialog: default_2.NamedExoticComponent<PaymentDialogProps>;
32
+
33
+ declare interface PaymentDialogProps {
34
+ open: boolean;
35
+ onClose: () => void;
36
+ apikey: string;
37
+ plain: PaymentPlain;
38
+ orderId: string;
39
+ amount: string;
40
+ intervalDays?: number;
41
+ onSuccess?: (order: SubscriptionPaymentOrderStatus | OnetimePaymentOrderStatus) => void;
42
+ onExpired?: (order: SubscriptionPaymentOrderStatus | OnetimePaymentOrderStatus) => void;
43
+ onFailed?: (order: SubscriptionPaymentOrderStatus | OnetimePaymentOrderStatus) => void;
44
+ onError?: (error: Error) => void;
45
+ }
46
+
47
+ declare interface PaymentOptions_2 {
48
+ plain: PaymentPlain;
49
+ orderId: string;
50
+ amount: string;
51
+ intervalDays?: number;
52
+ onSuccess?: (order: SubscriptionPaymentOrderStatus | OnetimePaymentOrderStatus) => void;
53
+ onError?: (error: Error) => void;
54
+ }
55
+
56
+ declare type PaymentPlain = "one-time" | "subscription" | "x402";
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
+
75
+ export declare const useCppayPayment: () => CppayContextValue;
76
+
77
+ export { }
78
+
79
+
80
+ declare module "@vue/runtime-core" {
81
+ interface ComponentCustomProperties {
82
+ $showPayment: typeof showPayment;
83
+ }
84
+ }