cppay-sdk 0.0.2-beta.12 → 0.0.2-beta.18

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 @@
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}});
@@ -0,0 +1,216 @@
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
+ }));
59
+ }
60
+ async createOnetimePayment(e, t, n, r) {
61
+ let i = {
62
+ chain: e,
63
+ token: t,
64
+ order_no: n,
65
+ amount: r
66
+ }, o = await cppayRequest(this.apikey, {
67
+ url: "/api/payment/create",
68
+ method: "post",
69
+ data: i
70
+ });
71
+ return {
72
+ paymentId: o.payment_id,
73
+ paymentAmount: o.pay_amount,
74
+ receiveAddress: o.receive_address,
75
+ expireAt: o.expire_at
76
+ };
77
+ }
78
+ async createSubscriptionPayment(e, t, n, r, i) {
79
+ let o = {
80
+ chain: e,
81
+ token: t,
82
+ order_no: n,
83
+ amount_usd: r,
84
+ renewal_days: i
85
+ }, s = await cppayRequest(this.apikey, {
86
+ url: "/api/subscription/create",
87
+ method: "post",
88
+ data: o
89
+ });
90
+ return {
91
+ subscriptionId: s.subscription_id,
92
+ approveAmount: s.approved_amount,
93
+ spenderAddress: s.contract_address,
94
+ expireAt: s.expire_at
95
+ };
96
+ }
97
+ async createX402Payment() {
98
+ throw Error("Unsupported payment mode");
99
+ }
100
+ async checkOnetimePaymentStatus(e) {
101
+ let t = { payment_id: e }, n = await cppayRequest(this.apikey, {
102
+ url: "/api/payment/query",
103
+ params: t
104
+ });
105
+ return {
106
+ orderId: n.order_no,
107
+ paymentId: n.payment_id,
108
+ chain: n.chain,
109
+ token: n.token,
110
+ baseAmount: n.base_amount,
111
+ payAmount: n.pay_amount,
112
+ receiveAddress: n.receive_address,
113
+ expireAt: n.expire_at,
114
+ status: n.status
115
+ };
116
+ }
117
+ async checkSubcriptionPaymentStatus(e) {
118
+ let t = { subscription_id: e }, n = await cppayRequest(this.apikey, {
119
+ url: "/api/subscription/query",
120
+ params: t
121
+ });
122
+ return {
123
+ orderId: n.order_no,
124
+ subscriptionId: n.subscription_id,
125
+ chain: n.chain,
126
+ token: n.token,
127
+ approvedAddress: n.approved_contract_address,
128
+ txHash: n.approved_tx_hash,
129
+ approveAmount: n.approved_amount,
130
+ amountOfUsd: n.amount_usd,
131
+ expireAt: n.expire_at,
132
+ status: n.subscription_status
133
+ };
134
+ }
135
+ async getSubcriptionPayments(e) {
136
+ let t = { subscription_id: e }, n = await cppayRequest(this.apikey, {
137
+ url: "/api/subscription/payments",
138
+ params: t
139
+ });
140
+ return {
141
+ total: n.total,
142
+ payments: (n.payments ?? []).map((e) => ({
143
+ orderId: e.order_no,
144
+ subscriptionId: e.subscription_id,
145
+ chain: e.chain,
146
+ token: e.token,
147
+ txHash: e.tx_hash,
148
+ payAmount: e.pay_amount,
149
+ receiveAddress: e.receive_address,
150
+ status: e.status,
151
+ errorMessage: e.error_message
152
+ }))
153
+ };
154
+ }
155
+ async checkX402PaymentStatus() {
156
+ throw Error("Unsupported payment mode");
157
+ }
158
+ }, cppay_default = class {
159
+ api;
160
+ constructor(e) {
161
+ this.api = new CppayApi(e);
162
+ }
163
+ async getSupportedChains() {
164
+ let n = (await this.api.getSupportedChains()).reduce((n, r) => {
165
+ let i = n[r.chain] ?? {
166
+ chain: r.chain,
167
+ chainId: r.chainId,
168
+ tokens: [],
169
+ icon: CHAIN_ICONS[r.chain]
170
+ };
171
+ return i.tokens.push({
172
+ symbol: r.tokenSymbol,
173
+ decimals: r.tokenDecimals,
174
+ address: r.tokenAddress,
175
+ icon: TOKEN_ICONS[r.tokenSymbol]
176
+ }), n[r.chain] = i, n;
177
+ }, {});
178
+ return Object.values(n);
179
+ }
180
+ async createPayment(e, t) {
181
+ switch (e) {
182
+ case "one-time": return this.createOnetimePayment(t);
183
+ case "subscription": return this.createSubscriptionPayment(t);
184
+ }
185
+ }
186
+ async checkPaymentStatus(e, t) {
187
+ switch (e) {
188
+ case "one-time": return this.checkOnetimePaymentStatus(t);
189
+ case "subscription": return this.checkSubscriptionPaymentStatus(t);
190
+ }
191
+ }
192
+ async createOnetimePayment(e) {
193
+ let t = await this.api.createOnetimePayment(e.paymentChain, e.paymentToken, e.orderId, e.amount);
194
+ return {
195
+ ...e,
196
+ ...t
197
+ };
198
+ }
199
+ async createSubscriptionPayment(e) {
200
+ let t = await this.api.createSubscriptionPayment(e.paymentChain, e.paymentToken, e.orderId, e.amountOfUsd, e.intervalDays);
201
+ return {
202
+ ...e,
203
+ ...t
204
+ };
205
+ }
206
+ async checkOnetimePaymentStatus(e) {
207
+ return { ...await this.api.checkOnetimePaymentStatus(e.paymentId) };
208
+ }
209
+ async checkSubscriptionPaymentStatus(e) {
210
+ return { ...await this.api.checkSubcriptionPaymentStatus(e.subscriptionId) };
211
+ }
212
+ async getSubcriptionPayments(e) {
213
+ return { ...await this.api.getSubcriptionPayments(e.subscriptionId) };
214
+ }
215
+ };
216
+ export { CHAIN_ICONS as n, TOKEN_ICONS as r, cppay_default as t };
@@ -1,2 +1,2 @@
1
- ._cppay-fade-enter-active[data-v-de37a8de],._cppay-fade-leave-active[data-v-de37a8de]{transition:opacity .3s}._cppay-fade-enter-from[data-v-de37a8de],._cppay-fade-leave-to[data-v-de37a8de]{opacity:0}._cppay-fade-enter-active ._cppay-dialog[data-v-de37a8de]{animation:.3s _cppay-slideUp}
1
+ ._cppay-fade-enter-active[data-v-25169ecd],._cppay-fade-leave-active[data-v-25169ecd]{transition:opacity .3s}._cppay-fade-enter-from[data-v-25169ecd],._cppay-fade-leave-to[data-v-25169ecd]{opacity:0}._cppay-fade-enter-active ._cppay-dialog[data-v-25169ecd]{animation:.3s _cppay-slideUp}
2
2
  /*$vite$:1*/
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- const e=require(`./cppay-DUOs8RUI.cjs`);exports.CHAIN_ICONS=e.n,exports.Cppay=e.t,exports.TOKEN_ICONS=e.r;
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
@@ -10,16 +10,38 @@ export declare interface ChainInfo {
10
10
  }
11
11
 
12
12
  export declare class Cppay {
13
- private apikey;
13
+ private api;
14
14
  constructor(apikey: string);
15
15
  getSupportedChains(): Promise<ChainInfo[]>;
16
- createPayment(params: {
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: {
17
21
  paymentChain: string;
18
22
  paymentToken: string;
19
23
  orderId: string;
20
24
  amount: Numberic;
21
- }): Promise<PaymentInfo>;
22
- checkPaymentStatus(paymentId: string): Promise<PaymentOrder>;
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
+ }>;
23
45
  }
24
46
 
25
47
  export declare interface CppayResponse<R> {
@@ -30,7 +52,7 @@ export declare interface CppayResponse<R> {
30
52
 
31
53
  export declare type Numberic = `${number}.${number}` | `${number}`;
32
54
 
33
- export declare interface PaymentInfo {
55
+ export declare interface OnetimePaymentInfo {
34
56
  orderId: string;
35
57
  paymentId: string;
36
58
  paymentAmount: Numberic;
@@ -39,7 +61,7 @@ export declare interface PaymentInfo {
39
61
  receiveAddress: Address;
40
62
  }
41
63
 
42
- export declare interface PaymentOrder {
64
+ export declare interface OnetimePaymentOrderStatus {
43
65
  orderId: string;
44
66
  paymentId: string;
45
67
  chain: string;
@@ -51,8 +73,49 @@ export declare interface PaymentOrder {
51
73
  status: PaymentStatus;
52
74
  }
53
75
 
76
+ export declare type PaymentPlain = "one-time" | "subscription" | "x402";
77
+
54
78
  export declare type PaymentStatus = "pending" | "paid" | "expired" | "failed";
55
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;
115
+ }
116
+
117
+ export declare type SubscriptionPaymentStatus = "pending" | "approved" | "expired" | "failed";
118
+
56
119
  export declare const TOKEN_ICONS: Record<string, string>;
57
120
 
58
121
  export declare interface TokenInfo {
@@ -60,7 +123,6 @@ export declare interface TokenInfo {
60
123
  symbol: string;
61
124
  decimals: number;
62
125
  address: Address | "";
63
- receiveAddresses: Address[];
64
126
  }
65
127
 
66
128
  export { }
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-Co7VAb5Q.js";
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
- 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));const c=require(`./cppay-DUOs8RUI.cjs`),l=require(`./inject-style-Dz7JsQxo.cjs`);let u=require(`react`);u=s(u);let d=require(`react/jsx-runtime`);var f=({open:e,onClose:t,apiKey:n,orderId:r,amount:i,onSuccess:a,onError:o})=>{let s=(0,u.useMemo)(()=>new c.t(n),[n]),[l,f]=(0,u.useState)(`select`),[p,m]=(0,u.useState)(!1),[h,g]=(0,u.useState)([]),[_,v]=(0,u.useState)(``),[y,b]=(0,u.useState)(``),[x,S]=(0,u.useState)(null),C=(0,u.useMemo)(()=>h.find(e=>e.chain===_),[h,_]),w=(0,u.useMemo)(()=>C?.tokens||[],[C]),T=(0,u.useMemo)(()=>w.find(e=>e.symbol===y),[w,y]),E=(0,u.useMemo)(()=>y?(parseFloat(i)/1).toFixed(6):`0`,[i,y,1]),D=async()=>{try{m(!0);let e=await s.getSupportedChains();g(e),e.length>0&&v(e[0].chain)}catch(e){o?.(e)}finally{m(!1)}},O=async()=>{if(!(!_||!y))try{m(!0);let e=await s.createPayment({paymentChain:_,paymentToken:y,orderId:r,amount:E});S({paymentId:e.paymentId,paymentAmount:e.paymentAmount,receiveAddress:T?.receiveAddresses[0]||``}),f(`payment`)}catch(e){o?.(e)}finally{m(!1)}},k=async()=>{if(x)try{m(!0),await s.checkPaymentStatus(x.paymentId),a?.(x.paymentId),j()}catch(e){o?.(e)}finally{m(!1)}},A=async()=>{x?.receiveAddress&&await navigator.clipboard.writeText(x.receiveAddress)},j=()=>{t(),setTimeout(()=>{f(`select`),S(null)},300)};return(0,u.useEffect)(()=>{e&&h.length===0&&D()},[e]),(0,u.useEffect)(()=>{w.length>0&&b(w[0].symbol)},[w]),e?(0,d.jsx)(`div`,{className:`_cppay-overlay`,onClick:e=>e.target===e.currentTarget&&j(),children:(0,d.jsxs)(`div`,{className:`_cppay-dialog`,children:[(0,d.jsxs)(`div`,{className:`_cppay-header`,children:[(0,d.jsx)(`h2`,{className:`_cppay-title`,children:l===`select`?`选择支付方式`:`完成支付`}),(0,d.jsx)(`button`,{onClick:j,disabled:p,className:`_cppay-close-btn`,children:(0,d.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,d.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,d.jsx)(`div`,{className:`_cppay-content`,children:l===`select`?(0,d.jsxs)(`div`,{children:[(0,d.jsxs)(`div`,{className:`_cppay-section`,children:[(0,d.jsx)(`label`,{className:`_cppay-label`,children:`支付网络`}),(0,d.jsx)(`div`,{className:`_cppay-grid`,children:h.map(e=>(0,d.jsxs)(`button`,{onClick:()=>v(e.chain),className:`_cppay-select-btn ${_===e.chain?`_cppay-selected`:``}`,children:[e.icon&&(0,d.jsx)(`img`,{src:e.icon,alt:e.chain}),(0,d.jsx)(`span`,{children:e.chain})]},e.chain))})]}),(0,d.jsxs)(`div`,{className:`_cppay-section`,children:[(0,d.jsx)(`label`,{className:`_cppay-label`,children:`支付代币`}),(0,d.jsx)(`div`,{className:`_cppay-grid`,children:w.map(e=>(0,d.jsxs)(`button`,{onClick:()=>b(e.symbol),className:`_cppay-select-btn ${y===e.symbol?`_cppay-selected`:``}`,children:[e.icon&&(0,d.jsx)(`img`,{src:e.icon,alt:e.symbol}),(0,d.jsx)(`span`,{children:e.symbol})]},e.symbol))})]}),(0,d.jsx)(`div`,{className:`_cppay-section`,children:(0,d.jsx)(`div`,{className:`_cppay-price-box`,children:(0,d.jsxs)(`div`,{className:`_cppay-price-row`,children:[(0,d.jsx)(`span`,{className:`_cppay-price-label`,children:`支付金额`}),(0,d.jsxs)(`div`,{className:`_cppay-price-amount`,children:[(0,d.jsxs)(`div`,{className:`_cppay-price-main`,children:[E,` `,y]}),(0,d.jsxs)(`div`,{className:`_cppay-price-sub`,children:[`≈ $`,i]})]})]})})}),(0,d.jsx)(`div`,{className:`_cppay-section`,children:(0,d.jsx)(`button`,{onClick:O,disabled:!_||!y||p,className:`_cppay-btn _cppay-btn-primary`,children:p?`处理中...`:`继续支付`})})]}):x&&(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`_cppay-qr-container`,children:(0,d.jsx)(`div`,{className:`_cppay-qr-placeholder`,children:(0,d.jsx)(`span`,{children:`扫码支付`})})}),(0,d.jsxs)(`div`,{className:`_cppay-section`,children:[(0,d.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,d.jsx)(`div`,{className:`_cppay-info-label`,children:`支付金额`}),(0,d.jsxs)(`div`,{className:`_cppay-info-value`,children:[x.paymentAmount,` `,y]})]}),(0,d.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,d.jsx)(`div`,{className:`_cppay-info-label`,children:`支付地址`}),(0,d.jsxs)(`div`,{className:`_cppay-address-row`,children:[(0,d.jsx)(`code`,{children:x.receiveAddress}),(0,d.jsx)(`button`,{onClick:A,className:`_cppay-copy-btn`,title:`复制地址`,children:(0,d.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,d.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`})})})]})]})]}),(0,d.jsx)(`div`,{className:`_cppay-section`,children:(0,d.jsx)(`button`,{onClick:k,disabled:p,className:`_cppay-btn _cppay-btn-primary`,children:p?`检查支付状态...`:`我已完成支付`})}),(0,d.jsx)(`div`,{className:`_cppay-section`,children:(0,d.jsx)(`button`,{onClick:()=>f(`select`),disabled:p,className:`_cppay-btn _cppay-btn-secondary`,children:`更改支付方式`})})]})})]})}):null},p=u.default.memo(f);l.t(l.n),exports.PaymentDialog=p,exports.t=s;
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.default.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,15 +1,77 @@
1
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
+ }
2
30
 
3
31
  export declare const PaymentDialog: default_2.NamedExoticComponent<PaymentDialogProps>;
4
32
 
5
33
  declare interface PaymentDialogProps {
6
34
  open: boolean;
7
35
  onClose: () => void;
8
- apiKey: string;
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;
9
49
  orderId: string;
10
50
  amount: string;
11
- onSuccess?: (paymentId: string) => void;
51
+ intervalDays?: number;
52
+ onSuccess?: (order: SubscriptionPaymentOrderStatus | OnetimePaymentOrderStatus) => void;
12
53
  onError?: (error: Error) => void;
13
54
  }
14
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
+
15
77
  export { }