cppay-sdk 0.0.2-beta.4 → 0.0.2-beta.40
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-Db8t1Cra.js +216 -0
- package/dist/cppay-DuOJqlpA.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +172 -7
- package/dist/index.js +1 -100
- package/dist/locales-BU7nq14n.js +118 -0
- package/dist/locales-ChrHW5Qd.cjs +1 -0
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +240 -1
- package/dist/react.js +757 -3
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.ts +193 -5
- package/dist/vue.js +609 -10
- package/package.json +46 -18
|
@@ -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
|
+
authorization;
|
|
48
|
+
constructor(e, t) {
|
|
49
|
+
this.authorization = e ? `ApiKey ${e}` : `OTT ${t}`;
|
|
50
|
+
}
|
|
51
|
+
async getSupportedChains() {
|
|
52
|
+
return (await cppayRequest(this.authorization, { 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, i) {
|
|
62
|
+
let o = {
|
|
63
|
+
chain: e,
|
|
64
|
+
token: t,
|
|
65
|
+
order_no: n,
|
|
66
|
+
amount: r,
|
|
67
|
+
remark: i
|
|
68
|
+
}, s = await cppayRequest(this.authorization, {
|
|
69
|
+
url: "/api/payment/create",
|
|
70
|
+
method: "post",
|
|
71
|
+
data: o
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
paymentId: s.payment_id,
|
|
75
|
+
paymentAmount: s.pay_amount,
|
|
76
|
+
receiveAddress: s.receive_address,
|
|
77
|
+
expireAt: s.expire_at
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
async createSubscriptionPayment(e, t, n, r, i) {
|
|
81
|
+
let o = {
|
|
82
|
+
chain: e,
|
|
83
|
+
token: t,
|
|
84
|
+
order_no: n,
|
|
85
|
+
amount_usd: r,
|
|
86
|
+
renewal_days: i
|
|
87
|
+
}, s = await cppayRequest(this.authorization, {
|
|
88
|
+
url: "/api/subscription/create",
|
|
89
|
+
method: "post",
|
|
90
|
+
data: o
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
subscriptionId: s.subscription_id,
|
|
94
|
+
approveAmount: s.approved_amount,
|
|
95
|
+
spenderAddress: s.contract_address,
|
|
96
|
+
expireAt: s.expire_at
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async createX402Payment() {
|
|
100
|
+
throw Error("Unsupported payment mode");
|
|
101
|
+
}
|
|
102
|
+
async checkOnetimePaymentStatus(e) {
|
|
103
|
+
let t = "orderId" in e ? { order_no: e.orderId } : { payment_id: e.paymentId }, n = await cppayRequest(this.authorization, {
|
|
104
|
+
url: "/api/payment/query",
|
|
105
|
+
params: t
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
orderId: n.order_no,
|
|
109
|
+
paymentId: n.payment_id,
|
|
110
|
+
chain: n.chain,
|
|
111
|
+
token: n.token,
|
|
112
|
+
baseAmount: n.base_amount,
|
|
113
|
+
payAmount: n.pay_amount,
|
|
114
|
+
receiveAddress: n.receive_address,
|
|
115
|
+
expireAt: n.expire_at,
|
|
116
|
+
status: n.status
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
async checkSubcriptionPaymentStatus(e) {
|
|
120
|
+
let t = "orderId" in e ? { order_no: e.orderId } : { subscription_id: e.subscriptionId }, n = await cppayRequest(this.authorization, {
|
|
121
|
+
url: "/api/subscription/query",
|
|
122
|
+
params: t
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
orderId: n.order_no,
|
|
126
|
+
subscriptionId: n.subscription_id,
|
|
127
|
+
chain: n.chain,
|
|
128
|
+
token: n.token,
|
|
129
|
+
approvedAddress: n.approved_contract_address,
|
|
130
|
+
txHash: n.approved_tx_hash,
|
|
131
|
+
approveAmount: n.approved_amount,
|
|
132
|
+
amountOfUsd: n.amount_usd,
|
|
133
|
+
expireAt: n.expire_at,
|
|
134
|
+
status: n.subscription_status
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
async getSubcriptionPayments(e) {
|
|
138
|
+
let t = { subscription_id: e }, n = await cppayRequest(this.authorization, {
|
|
139
|
+
url: "/api/subscription/payments",
|
|
140
|
+
params: t
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
total: n.total,
|
|
144
|
+
payments: (n.payments ?? []).map((e) => ({
|
|
145
|
+
orderId: e.order_no,
|
|
146
|
+
subscriptionId: e.subscription_id,
|
|
147
|
+
chain: e.chain,
|
|
148
|
+
token: e.token,
|
|
149
|
+
txHash: e.tx_hash,
|
|
150
|
+
payAmount: e.pay_amount,
|
|
151
|
+
receiveAddress: e.receive_address,
|
|
152
|
+
status: e.status,
|
|
153
|
+
errorMessage: e.error_message
|
|
154
|
+
}))
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
async checkX402PaymentStatus() {
|
|
158
|
+
throw Error("Unsupported payment mode");
|
|
159
|
+
}
|
|
160
|
+
}, cppay_default = class {
|
|
161
|
+
api;
|
|
162
|
+
constructor(e, t) {
|
|
163
|
+
this.api = new CppayApi(e, t);
|
|
164
|
+
}
|
|
165
|
+
async getSupportedChains() {
|
|
166
|
+
let n = (await this.api.getSupportedChains()).reduce((n, r) => {
|
|
167
|
+
let i = n[r.chain] ?? {
|
|
168
|
+
chain: r.chain,
|
|
169
|
+
chainId: r.chainId,
|
|
170
|
+
tokens: [],
|
|
171
|
+
icon: CHAIN_ICONS[r.chain]
|
|
172
|
+
};
|
|
173
|
+
return i.tokens.push({
|
|
174
|
+
symbol: r.tokenSymbol,
|
|
175
|
+
decimals: r.tokenDecimals,
|
|
176
|
+
address: r.tokenAddress,
|
|
177
|
+
icon: TOKEN_ICONS[r.tokenSymbol],
|
|
178
|
+
price: r.tokenPrice
|
|
179
|
+
}), n[r.chain] = i, n;
|
|
180
|
+
}, {});
|
|
181
|
+
return Object.values(n);
|
|
182
|
+
}
|
|
183
|
+
async createPayment(e, t) {
|
|
184
|
+
switch (e) {
|
|
185
|
+
case "instant": return this.createOnetimePayment(t);
|
|
186
|
+
case "subscription": return this.createSubscriptionPayment(t);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async checkPaymentStatus(e, t) {
|
|
190
|
+
switch (e) {
|
|
191
|
+
case "instant": return this.checkOnetimePaymentStatus(t);
|
|
192
|
+
case "subscription": return this.checkSubscriptionPaymentStatus(t);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async createOnetimePayment(e) {
|
|
196
|
+
let t = await this.api.createOnetimePayment(e.paymentChain, e.paymentToken, e.orderId, e.amount, e.remark);
|
|
197
|
+
return {
|
|
198
|
+
...e,
|
|
199
|
+
...t
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
async createSubscriptionPayment(e) {
|
|
203
|
+
let t = await this.api.createSubscriptionPayment(e.paymentChain, e.paymentToken, e.orderId, e.amountOfUsd, e.intervalDays);
|
|
204
|
+
return {
|
|
205
|
+
...e,
|
|
206
|
+
...t
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
async checkOnetimePaymentStatus(e) {
|
|
210
|
+
return { ...await this.api.checkOnetimePaymentStatus(e) };
|
|
211
|
+
}
|
|
212
|
+
async checkSubscriptionPaymentStatus(e) {
|
|
213
|
+
return { ...await this.api.checkSubcriptionPaymentStatus(e) };
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
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{authorization;constructor(e,t){this.authorization=e?`ApiKey ${e}`:`OTT ${t}`}async getSupportedChains(){return(await a(this.authorization,{url:`/api/payment/token`})).map(e=>({chain:e.chain,chainId:e.chain_id,tokenSymbol:e.token_symbol,tokenDecimals:e.token_decimals,tokenAddress:e.token_address,tokenPrice:e.token_price}))}async createOnetimePayment(e,t,n,r,i){let o={chain:e,token:t,order_no:n,amount:r,remark:i},s=await a(this.authorization,{url:`/api/payment/create`,method:`post`,data:o});return{paymentId:s.payment_id,paymentAmount:s.pay_amount,receiveAddress:s.receive_address,expireAt:s.expire_at}}async createSubscriptionPayment(e,t,n,r,i){let o={chain:e,token:t,order_no:n,amount_usd:r,renewal_days:i},s=await a(this.authorization,{url:`/api/subscription/create`,method:`post`,data:o});return{subscriptionId:s.subscription_id,approveAmount:s.approved_amount,spenderAddress:s.contract_address,expireAt:s.expire_at}}async createX402Payment(){throw Error(`Unsupported payment mode`)}async checkOnetimePaymentStatus(e){let t=`orderId`in e?{order_no:e.orderId}:{payment_id:e.paymentId},n=await a(this.authorization,{url:`/api/payment/query`,params:t});return{orderId:n.order_no,paymentId:n.payment_id,chain:n.chain,token:n.token,baseAmount:n.base_amount,payAmount:n.pay_amount,receiveAddress:n.receive_address,expireAt:n.expire_at,status:n.status}}async checkSubcriptionPaymentStatus(e){let t=`orderId`in e?{order_no:e.orderId}:{subscription_id:e.subscriptionId},n=await a(this.authorization,{url:`/api/subscription/query`,params:t});return{orderId:n.order_no,subscriptionId:n.subscription_id,chain:n.chain,token:n.token,approvedAddress:n.approved_contract_address,txHash:n.approved_tx_hash,approveAmount:n.approved_amount,amountOfUsd:n.amount_usd,expireAt:n.expire_at,status:n.subscription_status}}async getSubcriptionPayments(e){let t={subscription_id:e},n=await a(this.authorization,{url:`/api/subscription/payments`,params:t});return{total:n.total,payments:(n.payments??[]).map(e=>({orderId:e.order_no,subscriptionId:e.subscription_id,chain:e.chain,token:e.token,txHash:e.tx_hash,payAmount:e.pay_amount,receiveAddress:e.receive_address,status:e.status,errorMessage:e.error_message}))}}async checkX402PaymentStatus(){throw Error(`Unsupported payment mode`)}},s=class{api;constructor(e,t){this.api=new o(e,t)}async getSupportedChains(){let n=(await this.api.getSupportedChains()).reduce((n,r)=>{let i=n[r.chain]??{chain:r.chain,chainId:r.chainId,tokens:[],icon:e[r.chain]};return i.tokens.push({symbol:r.tokenSymbol,decimals:r.tokenDecimals,address:r.tokenAddress,icon:t[r.tokenSymbol],price:r.tokenPrice}),n[r.chain]=i,n},{});return Object.values(n)}async createPayment(e,t){switch(e){case`instant`:return this.createOnetimePayment(t);case`subscription`:return this.createSubscriptionPayment(t)}}async checkPaymentStatus(e,t){switch(e){case`instant`:return this.checkOnetimePaymentStatus(t);case`subscription`:return this.checkSubscriptionPaymentStatus(t)}}async createOnetimePayment(e){let t=await this.api.createOnetimePayment(e.paymentChain,e.paymentToken,e.orderId,e.amount,e.remark);return{...e,...t}}async createSubscriptionPayment(e){let t=await this.api.createSubscriptionPayment(e.paymentChain,e.paymentToken,e.orderId,e.amountOfUsd,e.intervalDays);return{...e,...t}}async checkOnetimePaymentStatus(e){return{...await this.api.checkOnetimePaymentStatus(e)}}async checkSubscriptionPaymentStatus(e){return{...await this.api.checkSubcriptionPaymentStatus(e)}}},c=s;Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return c}});
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=
|
|
1
|
+
const e=require(`./cppay-DuOJqlpA.cjs`);exports.CHAIN_ICONS=e.n,exports.Cppay=e.t,exports.TOKEN_ICONS=e.r;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,20 +5,116 @@ export declare const CHAIN_ICONS: Record<string, string>;
|
|
|
5
5
|
export declare interface ChainInfo {
|
|
6
6
|
icon?: string;
|
|
7
7
|
chain: string;
|
|
8
|
+
chainId: number;
|
|
8
9
|
tokens: TokenInfo[];
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export declare class Cppay {
|
|
12
|
-
|
|
13
|
-
constructor(apikey: string);
|
|
13
|
+
api: CppayApi;
|
|
14
|
+
constructor(apikey: string, ott?: undefined);
|
|
15
|
+
constructor(apikey: undefined, ott: string);
|
|
14
16
|
getSupportedChains(): Promise<ChainInfo[]>;
|
|
15
|
-
createPayment(params:
|
|
17
|
+
createPayment(plain: "instant", params: Parameters<Cppay["createOnetimePayment"]>[0]): Promise<OnetimePaymentInfo>;
|
|
18
|
+
createPayment(plain: "subscription", params: Parameters<Cppay["createSubscriptionPayment"]>[0]): Promise<SubscriptionPaymentInfo>;
|
|
19
|
+
checkPaymentStatus(plain: "instant", params: Parameters<Cppay["checkOnetimePaymentStatus"]>[0]): Promise<OnetimePaymentOrderStatus>;
|
|
20
|
+
checkPaymentStatus(plain: "subscription", params: Parameters<Cppay["checkSubscriptionPaymentStatus"]>[0]): Promise<SubscriptionPaymentOrderStatus>;
|
|
21
|
+
createOnetimePayment(params: {
|
|
16
22
|
paymentChain: string;
|
|
17
23
|
paymentToken: string;
|
|
18
24
|
orderId: string;
|
|
19
25
|
amount: Numberic;
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
remark?: string;
|
|
27
|
+
}): Promise<OnetimePaymentInfo>;
|
|
28
|
+
createSubscriptionPayment(params: {
|
|
29
|
+
paymentChain: string;
|
|
30
|
+
paymentToken: string;
|
|
31
|
+
orderId: string;
|
|
32
|
+
amountOfUsd: Numberic;
|
|
33
|
+
intervalDays: number;
|
|
34
|
+
}): Promise<SubscriptionPaymentInfo>;
|
|
35
|
+
checkOnetimePaymentStatus(params: {
|
|
36
|
+
orderId: string;
|
|
37
|
+
} | {
|
|
38
|
+
paymentId: string;
|
|
39
|
+
}): Promise<OnetimePaymentOrderStatus>;
|
|
40
|
+
checkSubscriptionPaymentStatus(params: {
|
|
41
|
+
orderId: string;
|
|
42
|
+
} | {
|
|
43
|
+
subscriptionId: string;
|
|
44
|
+
}): Promise<SubscriptionPaymentOrderStatus>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare class CppayApi {
|
|
48
|
+
private authorization;
|
|
49
|
+
constructor(apikey: string, ott?: undefined);
|
|
50
|
+
constructor(apikey: undefined, ott: string);
|
|
51
|
+
getSupportedChains(): Promise<{
|
|
52
|
+
chain: string;
|
|
53
|
+
chainId: number;
|
|
54
|
+
tokenSymbol: string;
|
|
55
|
+
tokenDecimals: number;
|
|
56
|
+
tokenAddress: `0x${string}`;
|
|
57
|
+
tokenPrice: Numberic;
|
|
58
|
+
}[]>;
|
|
59
|
+
createOnetimePayment(paymentChain: string, paymentToken: string, orderId: string, amount: Numberic, remark?: string): Promise<{
|
|
60
|
+
paymentId: string;
|
|
61
|
+
paymentAmount: Numberic;
|
|
62
|
+
receiveAddress: `0x${string}`;
|
|
63
|
+
expireAt: number;
|
|
64
|
+
}>;
|
|
65
|
+
createSubscriptionPayment(paymentChain: string, paymentToken: string, orderId: string, amountOfUsd: Numberic, intervalDays: number): Promise<{
|
|
66
|
+
subscriptionId: string;
|
|
67
|
+
approveAmount: Numberic;
|
|
68
|
+
spenderAddress: `0x${string}`;
|
|
69
|
+
expireAt: number;
|
|
70
|
+
}>;
|
|
71
|
+
createX402Payment(): Promise<void>;
|
|
72
|
+
checkOnetimePaymentStatus(_params: {
|
|
73
|
+
orderId: string;
|
|
74
|
+
} | {
|
|
75
|
+
paymentId: string;
|
|
76
|
+
}): Promise<{
|
|
77
|
+
orderId: string;
|
|
78
|
+
paymentId: string;
|
|
79
|
+
chain: string;
|
|
80
|
+
token: string;
|
|
81
|
+
baseAmount: Numberic;
|
|
82
|
+
payAmount: Numberic;
|
|
83
|
+
receiveAddress: `0x${string}`;
|
|
84
|
+
expireAt: number;
|
|
85
|
+
status: PaymentStatus;
|
|
86
|
+
}>;
|
|
87
|
+
checkSubcriptionPaymentStatus(_params: {
|
|
88
|
+
orderId: string;
|
|
89
|
+
} | {
|
|
90
|
+
subscriptionId: string;
|
|
91
|
+
}): Promise<{
|
|
92
|
+
orderId: string;
|
|
93
|
+
subscriptionId: string;
|
|
94
|
+
chain: string;
|
|
95
|
+
token: string;
|
|
96
|
+
approvedAddress: string;
|
|
97
|
+
txHash: string;
|
|
98
|
+
approveAmount: string;
|
|
99
|
+
amountOfUsd: string;
|
|
100
|
+
expireAt: number;
|
|
101
|
+
status: SubscriptionPaymentStatus;
|
|
102
|
+
}>;
|
|
103
|
+
getSubcriptionPayments(subscriptionId: string): Promise<{
|
|
104
|
+
total: number;
|
|
105
|
+
payments: {
|
|
106
|
+
orderId: string;
|
|
107
|
+
subscriptionId: string;
|
|
108
|
+
chain: string;
|
|
109
|
+
token: string;
|
|
110
|
+
txHash: string;
|
|
111
|
+
payAmount: Numberic;
|
|
112
|
+
receiveAddress: `0x${string}`;
|
|
113
|
+
status: PaymentStatus;
|
|
114
|
+
errorMessage: string;
|
|
115
|
+
}[];
|
|
116
|
+
}>;
|
|
117
|
+
checkX402PaymentStatus(): Promise<void>;
|
|
22
118
|
}
|
|
23
119
|
|
|
24
120
|
export declare interface CppayResponse<R> {
|
|
@@ -29,22 +125,91 @@ export declare interface CppayResponse<R> {
|
|
|
29
125
|
|
|
30
126
|
export declare type Numberic = `${number}.${number}` | `${number}`;
|
|
31
127
|
|
|
32
|
-
export declare interface
|
|
128
|
+
export declare interface OnetimePaymentInfo {
|
|
33
129
|
orderId: string;
|
|
34
130
|
paymentId: string;
|
|
35
131
|
paymentAmount: Numberic;
|
|
36
132
|
paymentChain: string;
|
|
37
133
|
paymentToken: string;
|
|
134
|
+
receiveAddress: Address;
|
|
135
|
+
expireAt: number;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export declare interface OnetimePaymentOrderStatus {
|
|
139
|
+
orderId: string;
|
|
140
|
+
paymentId: string;
|
|
141
|
+
chain: string;
|
|
142
|
+
token: string;
|
|
143
|
+
baseAmount: Numberic;
|
|
144
|
+
payAmount: Numberic;
|
|
145
|
+
receiveAddress: Address;
|
|
146
|
+
expireAt: number;
|
|
147
|
+
status: PaymentStatus;
|
|
38
148
|
}
|
|
39
149
|
|
|
150
|
+
export declare type PaymentPlain = "instant" | "subscription" | "x402";
|
|
151
|
+
|
|
152
|
+
export declare type PaymentStatus = "pending" | "paid" | "expired" | "failed";
|
|
153
|
+
|
|
154
|
+
export declare type PaymentStep = "select" | "payment" | "checking" | "success" | "failed" | "expired" | "error";
|
|
155
|
+
|
|
156
|
+
export declare interface SubscriptionPayment {
|
|
157
|
+
orderId: string;
|
|
158
|
+
subscriptionId: string;
|
|
159
|
+
chain: string;
|
|
160
|
+
token: string;
|
|
161
|
+
payAmount: Numberic;
|
|
162
|
+
txHash: string;
|
|
163
|
+
receiveAddress: Address;
|
|
164
|
+
status: PaymentStatus;
|
|
165
|
+
errorMessage: string;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export declare interface SubscriptionPaymentInfo {
|
|
169
|
+
subscriptionId: string;
|
|
170
|
+
approveAmount: Numberic;
|
|
171
|
+
spenderAddress: Address;
|
|
172
|
+
expireAt: number;
|
|
173
|
+
paymentChain: string;
|
|
174
|
+
paymentToken: string;
|
|
175
|
+
orderId: string;
|
|
176
|
+
amountOfUsd: Numberic;
|
|
177
|
+
intervalDays: number;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export declare interface SubscriptionPaymentOrderStatus {
|
|
181
|
+
orderId: string;
|
|
182
|
+
subscriptionId: string;
|
|
183
|
+
chain: string;
|
|
184
|
+
token: string;
|
|
185
|
+
approvedAddress: string;
|
|
186
|
+
txHash: string;
|
|
187
|
+
approveAmount: string;
|
|
188
|
+
amountOfUsd: string;
|
|
189
|
+
expireAt: number;
|
|
190
|
+
status: SubscriptionPaymentStatus;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export declare type SubscriptionPaymentStatus = "pending" | "approved" | "expired" | "failed";
|
|
194
|
+
|
|
40
195
|
export declare const TOKEN_ICONS: Record<string, string>;
|
|
41
196
|
|
|
42
197
|
export declare interface TokenInfo {
|
|
43
198
|
icon?: string;
|
|
44
199
|
symbol: string;
|
|
200
|
+
price: Numberic;
|
|
45
201
|
decimals: number;
|
|
46
202
|
address: Address | "";
|
|
47
|
-
receiveAddresses: Address[];
|
|
48
203
|
}
|
|
49
204
|
|
|
50
205
|
export { }
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
declare module "@vue/runtime-core" {
|
|
209
|
+
interface ComponentCustomProperties {
|
|
210
|
+
/** 显示支付对话框的全局方法 */
|
|
211
|
+
$showPayment: typeof showPayment;
|
|
212
|
+
/** 关闭支付对话框的全局方法 */
|
|
213
|
+
$closePayment: typeof closePayment;
|
|
214
|
+
}
|
|
215
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,101 +1,2 @@
|
|
|
1
|
-
|
|
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
|
-
tBNB: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png",
|
|
13
|
-
TRX: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png",
|
|
14
|
-
SOL: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png"
|
|
15
|
-
};
|
|
16
|
-
var BASE_URL = "http://192.168.0.162:8000", request = async (e, n, i) => {
|
|
17
|
-
let a = Object.assign({ timeout: 15e3 }, i), o = new AbortController(), s = setTimeout(() => o.abort(), a.timeout);
|
|
18
|
-
try {
|
|
19
|
-
let i = await fetch(new URL(e, BASE_URL), {
|
|
20
|
-
signal: o.signal,
|
|
21
|
-
...n
|
|
22
|
-
});
|
|
23
|
-
clearTimeout(s);
|
|
24
|
-
let a = i.headers.get("Content-Type") ?? "";
|
|
25
|
-
if (a.includes("json")) return await i.json();
|
|
26
|
-
try {
|
|
27
|
-
return await i.json();
|
|
28
|
-
} catch {
|
|
29
|
-
throw Error(`URL: ${e}, Unsupport Content Type: ${a}`);
|
|
30
|
-
}
|
|
31
|
-
} catch (n) {
|
|
32
|
-
throw clearTimeout(s), n instanceof DOMException && n.name === "AbortError" ? Error(`URL: ${e}, Request timeout after ${a.timeout}ms`) : n;
|
|
33
|
-
}
|
|
34
|
-
}, SUCCESS_CODE = 0;
|
|
35
|
-
const cppayRequest = async (e, n) => {
|
|
36
|
-
let r = await request(n.url, {
|
|
37
|
-
method: n.method ?? "get",
|
|
38
|
-
headers: {
|
|
39
|
-
Authorization: e,
|
|
40
|
-
...n.headers
|
|
41
|
-
},
|
|
42
|
-
body: JSON.stringify(n.data)
|
|
43
|
-
});
|
|
44
|
-
if (r.code !== SUCCESS_CODE) throw Error(`Request ${n.url} Failed. ${r.message}`);
|
|
45
|
-
return r.data;
|
|
46
|
-
}, sleep = (e = 1e3) => new Promise((n) => setTimeout(n, e));
|
|
47
|
-
var cppay_default = class {
|
|
48
|
-
apikey;
|
|
49
|
-
constructor(e) {
|
|
50
|
-
this.apikey = e;
|
|
51
|
-
}
|
|
52
|
-
async getSupportedChains() {
|
|
53
|
-
let r = (await cppayRequest(this.apikey, { url: "/api/payment/token" })).reduce((r, i) => {
|
|
54
|
-
let a = r[i.chain] ?? {
|
|
55
|
-
chain: i.chain,
|
|
56
|
-
tokens: [],
|
|
57
|
-
icon: CHAIN_ICONS[i.chain]
|
|
58
|
-
};
|
|
59
|
-
return a.tokens.push({
|
|
60
|
-
symbol: i.token_symbol,
|
|
61
|
-
decimals: i.token_decimals,
|
|
62
|
-
address: i.token_address,
|
|
63
|
-
receiveAddresses: i.receive_addresses,
|
|
64
|
-
icon: TOKEN_ICONS[i.token_symbol]
|
|
65
|
-
}), r[i.chain] = a, r;
|
|
66
|
-
}, {});
|
|
67
|
-
return Object.values(r);
|
|
68
|
-
}
|
|
69
|
-
async createPayment(e) {
|
|
70
|
-
let n = {
|
|
71
|
-
chain: e.paymentChain,
|
|
72
|
-
token: e.paymentToken,
|
|
73
|
-
order_no: e.orderId,
|
|
74
|
-
amount: e.amount
|
|
75
|
-
}, r = await cppayRequest(this.apikey, {
|
|
76
|
-
url: "/api/payment/create",
|
|
77
|
-
method: "post",
|
|
78
|
-
data: n
|
|
79
|
-
});
|
|
80
|
-
return {
|
|
81
|
-
orderId: e.orderId,
|
|
82
|
-
paymentId: r.payment_id,
|
|
83
|
-
paymentAmount: r.pay_amount,
|
|
84
|
-
paymentChain: e.paymentChain,
|
|
85
|
-
paymentToken: e.paymentToken
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
async checkPaymentStatus(e, n = 1e3) {
|
|
89
|
-
let r = 15;
|
|
90
|
-
for (; r--;) {
|
|
91
|
-
let r = { payment_id: e };
|
|
92
|
-
if ((await cppayRequest(this.apikey, {
|
|
93
|
-
url: "/api/payment/query",
|
|
94
|
-
data: r
|
|
95
|
-
})).status === "success") return;
|
|
96
|
-
await sleep(n);
|
|
97
|
-
}
|
|
98
|
-
throw Error(`Check Payment Status Timeout, PaymentId: ${e}`);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
1
|
+
import { n as CHAIN_ICONS, r as TOKEN_ICONS, t as cppay_default } from "./cppay-Db8t1Cra.js";
|
|
101
2
|
export { CHAIN_ICONS, cppay_default as Cppay, TOKEN_ICONS };
|