cppay-sdk 0.0.2-beta.12 → 0.0.2-beta.13
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-S6x6aDqU.cjs +1 -0
- package/dist/cppay-p8t6ic0x.js +218 -0
- package/dist/cppay-sdk.css +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +69 -6
- package/dist/index.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +28 -1
- package/dist/react.js +106 -71
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.ts +1 -1
- package/dist/vue.js +6 -6
- package/package.json +1 -1
- package/dist/cppay-Co7VAb5Q.js +0 -109
- package/dist/cppay-DUOs8RUI.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={Ethereum:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png`,BSC:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,"bsc-testnet":`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,Tron:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png`,Polygon:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/polygon/info/logo.png`,Solana:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png`},t={USDT:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png`,USDC:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png`,ETH:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png`,BNB:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,tBNB:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,TRX:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png`,SOL:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png`};var n=`http://192.168.0.162:8000`,r=async(e,t,r)=>{let i=Object.assign({timeout:15e3},r),a=new AbortController,o=setTimeout(()=>a.abort(),i.timeout);try{let r=await fetch(new URL(e,n),{signal:a.signal,...t});clearTimeout(o);let i=r.headers.get(`Content-Type`)??``;if(i.includes(`json`))return await r.json();try{return await r.json()}catch{throw Error(`URL: ${e}, Unsupport Content Type: ${i}`)}}catch(t){throw clearTimeout(o),t instanceof DOMException&&t.name===`AbortError`?Error(`URL: ${e}, Request timeout after ${i.timeout}ms`):t}},i=0,a=async(e,t)=>{let n=new URLSearchParams(t.params),a=await r(`${t.url}${n.size?`?${n.toString()}`:``}`,{method:t.method??`get`,headers:{Authorization:e,...t.headers},body:t.data?JSON.stringify(t.data):void 0});if(a.code!==i)throw Error(`Request ${t.url} Failed. ${a.message}`);return a.data},o=class{apikey;constructor(e){this.apikey=e}async getSupportedChains(){return(await a(this.apikey,{url:`/api/payment/token`})).map(e=>({chain:e.chain,chainId:e.chain_id,tokenSymbol:e.token_symbol,tokenDecimals:e.token_decimals,tokenAddress:e.token_address,receiveAddresses:e.receive_addresses}))}async createOnetimePayment(e,t,n,r){let i={chain:e,token:t,order_no:n,amount:r},o=await a(this.apikey,{url:`/api/payment/create`,method:`post`,data:i});return{paymentId:o.payment_id,paymentAmount:o.pay_amount,receiveAddress:o.receive_address,expireAt:o.expire_at}}async createSubscriptionPayment(e,t,n,r,i){let o={chain:e,token:t,order_no:n,amount_usd:r,renewal_days:i},s=await a(this.apikey,{url:`/api/subscription/create`,method:`post`,data:o});return{subscriptionId:s.subscription_id,approveAmount:s.approved_amount,spenderAddress:s.contract_address,expireAt:s.expire_at}}async createX402Payment(){throw Error(`Unsupported payment mode`)}async checkOnetimePaymentStatus(e){let t={payment_id:e},n=await a(this.apikey,{url:`/api/payment/query`,params:t});return{orderId:n.order_no,paymentId:n.payment_id,chain:n.chain,token:n.token,baseAmount:n.base_amount,payAmount:n.pay_amount,receiveAddress:n.receive_address,expireAt:n.expire_at,status:n.status}}async checkSubcriptionPaymentStatus(e){let t={subscription_id:e},n=await a(this.apikey,{url:`/api/subscription/query`,params:t});return{orderId:n.order_no,subscriptionId:n.subscription_id,chain:n.chain,token:n.token,approvedAddress:n.approved_contract_address,txHash:n.approved_tx_hash,approveAmount:n.approved_amount,amountOfUsd:n.amount_usd,expireAt:n.expire_at,status:n.subscription_status}}async getSubcriptionPayments(e){let t={subscription_id:e},n=await a(this.apikey,{url:`/api/subscription/payments`,params:t});return{total:n.total,payments:n.payments.map(e=>({orderId:e.order_no,subscriptionId:e.subscription_id,chain:e.chain,token:e.token,txHash:e.tx_hash,payAmount:e.pay_amount,receiveAddress:e.receive_address,status:e.status,errorMessage:e.error_message}))}}async checkX402PaymentStatus(){throw Error(`Unsupported payment mode`)}},s=class{api;constructor(e){this.api=new o(e)}async getSupportedChains(){let n=(await this.api.getSupportedChains()).reduce((n,r)=>{let i=n[r.chain]??{chain:r.chain,chainId:r.chainId,tokens:[],icon:e[r.chain]};return i.tokens.push({symbol:r.tokenSymbol,decimals:r.tokenDecimals,address:r.tokenAddress,receiveAddresses:r.receiveAddresses,icon:t[r.tokenSymbol]}),n[r.chain]=i,n},{});return Object.values(n)}async createPayment(e,t){switch(e){case`one-time`:return this.createOnetimePayment(t);case`subscription`:return this.createSubscriptionPayment(t)}}async checkPaymentStatus(e,t){switch(e){case`one-time`:return this.checkOnetimePaymentStatus(t);case`subscription`:return this.checkSubscriptionPaymentStatus(t)}}async createOnetimePayment(e){let t=await this.api.createOnetimePayment(e.paymentChain,e.paymentToken,e.orderId,e.amount);return{...e,...t}}async createSubscriptionPayment(e){let t=await this.api.createSubscriptionPayment(e.paymentChain,e.paymentToken,e.orderId,e.amountOfUsd,e.intervalDays);return{...e,...t}}async checkOnetimePaymentStatus(e){return{...await this.api.checkOnetimePaymentStatus(e.paymentId)}}async checkSubscriptionPaymentStatus(e){return{...await this.api.checkSubcriptionPaymentStatus(e.subscriptionId)}}async getSubcriptionPayments(e){return{...await this.api.getSubcriptionPayments(e.subscriptionId)}}},c=s;Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return c}});
|
|
@@ -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
|
+
receiveAddresses: e.receive_addresses
|
|
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
|
+
receiveAddresses: r.receiveAddresses,
|
|
177
|
+
icon: TOKEN_ICONS[r.tokenSymbol]
|
|
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 };
|
package/dist/cppay-sdk.css
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
._cppay-fade-enter-active[data-v-
|
|
1
|
+
._cppay-fade-enter-active[data-v-57d5d708],._cppay-fade-leave-active[data-v-57d5d708]{transition:opacity .3s}._cppay-fade-enter-from[data-v-57d5d708],._cppay-fade-leave-to[data-v-57d5d708]{opacity:0}._cppay-fade-enter-active ._cppay-dialog[data-v-57d5d708]{animation:.3s _cppay-slideUp}
|
|
2
2
|
/*$vite$:1*/
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./cppay-
|
|
1
|
+
const e=require(`./cppay-S6x6aDqU.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
|
|
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<
|
|
22
|
-
|
|
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
|
|
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
|
|
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 {
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as CHAIN_ICONS, r as TOKEN_ICONS, t as cppay_default } from "./cppay-
|
|
1
|
+
import { n as CHAIN_ICONS, r as TOKEN_ICONS, t as cppay_default } from "./cppay-p8t6ic0x.js";
|
|
2
2
|
export { CHAIN_ICONS, cppay_default as Cppay, TOKEN_ICONS };
|
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-
|
|
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-S6x6aDqU.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,plain:r,orderId:i,amount:a,intervalDays:o,onSuccess:s,onError:l})=>{let f=(0,u.useMemo)(()=>new c.t(n),[n]),[p,m]=(0,u.useState)(`select`),[h,g]=(0,u.useState)(!1),[_,v]=(0,u.useState)([]),[y,b]=(0,u.useState)(``),[x,S]=(0,u.useState)(``),[C,w]=(0,u.useState)(null),T=(0,u.useMemo)(()=>_.find(e=>e.chain===y),[_,y]),E=(0,u.useMemo)(()=>T?.tokens||[],[T]),D=(0,u.useMemo)(()=>E.find(e=>e.symbol===x),[E,x]),O=(0,u.useMemo)(()=>x?(parseFloat(a)/1).toFixed(6):`0`,[a,x,1]),k=async()=>{try{g(!0);let e=await f.getSupportedChains();v(e),e.length>0&&b(e[0].chain)}catch(e){l?.(e)}finally{g(!1)}},A=async()=>{if(!(!y||!x))try{g(!0);let e;r===`one-time`?e=await f.createPayment(`one-time`,{paymentChain:y,paymentToken:x,orderId:i,amount:O}):r===`subscription`&&(e=await f.createPayment(`subscription`,{paymentChain:y,paymentToken:x,orderId:i,amountOfUsd:O,intervalDays:o||30})),w({paymentId:e.paymentId||e.subscriptionId,paymentAmount:e.paymentAmount||e.approveAmount,receiveAddress:D?.receiveAddresses[0]||e.spenderAddress||``}),m(`payment`)}catch(e){l?.(e)}finally{g(!1)}},j=async()=>{if(C)try{g(!0),await f.checkPaymentStatus(`one-time`,C),s?.(C.paymentId),N()}catch(e){l?.(e)}finally{g(!1)}},M=async()=>{C?.receiveAddress&&await navigator.clipboard.writeText(C.receiveAddress)},N=()=>{t(),setTimeout(()=>{m(`select`),w(null)},300)};return(0,u.useEffect)(()=>{e&&_.length===0&&k()},[e]),(0,u.useEffect)(()=>{E.length>0&&S(E[0].symbol)},[E]),e?(0,d.jsx)(`div`,{className:`_cppay-overlay`,onClick:e=>e.target===e.currentTarget&&N(),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:p===`select`?`选择支付方式`:`完成支付`}),(0,d.jsx)(`button`,{onClick:N,disabled:h,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:p===`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:_.map(e=>(0,d.jsxs)(`button`,{onClick:()=>b(e.chain),className:`_cppay-select-btn ${y===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:E.map(e=>(0,d.jsxs)(`button`,{onClick:()=>S(e.symbol),className:`_cppay-select-btn ${x===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:[O,` `,x]}),(0,d.jsxs)(`div`,{className:`_cppay-price-sub`,children:[`≈ $`,a]})]})]})})}),(0,d.jsx)(`div`,{className:`_cppay-section`,children:(0,d.jsx)(`button`,{onClick:A,disabled:!y||!x||h,className:`_cppay-btn _cppay-btn-primary`,children:h?`处理中...`:`继续支付`})})]}):C&&(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:[C.paymentAmount,` `,x]})]}),(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:C.receiveAddress}),(0,d.jsx)(`button`,{onClick:M,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:j,disabled:h,className:`_cppay-btn _cppay-btn-primary`,children:h?`检查支付状态...`:`我已完成支付`})}),(0,d.jsx)(`div`,{className:`_cppay-section`,children:(0,d.jsx)(`button`,{onClick:()=>m(`select`),disabled:h,className:`_cppay-btn _cppay-btn-secondary`,children:`更改支付方式`})})]})})]})}):null},p=u.default.memo(f),m=(0,u.createContext)(null);const h=({apikey:e,children:t})=>{let[n,r]=(0,u.useState)(!1),[i,a]=(0,u.useState)(null),o=(0,u.useCallback)(e=>{a(e),r(!0)},[]),s=(0,u.useCallback)(()=>{r(!1)},[]),c=(0,u.useCallback)(e=>{i?.onSuccess?.(e),r(!1)},[i]),l=(0,u.useCallback)(e=>{i?.onError?.(e)},[i]);return(0,d.jsxs)(m.Provider,{value:{showPayment:o},children:[t,i&&(0,d.jsx)(p,{open:n,onClose:s,apikey:e,plain:i.plain,orderId:i.orderId,amount:i.amount,intervalDays:i.intervalDays,onSuccess:c,onError:l})]})},g=()=>{let e=(0,u.useContext)(m);if(!e)throw Error(`useCppayPayment must be used within CppayProvider`);return e};l.t(l.n),exports.CppayProvider=h,exports.PaymentDialog=p,exports.t=s,exports.useCppayPayment=g;
|
package/dist/react.d.ts
CHANGED
|
@@ -1,15 +1,42 @@
|
|
|
1
1
|
import { default as default_2 } from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
declare interface CppayContextValue {
|
|
5
|
+
showPayment: (options: PaymentOptions_2) => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export declare const CppayProvider: default_2.FC<CppayProviderProps>;
|
|
9
|
+
|
|
10
|
+
declare interface CppayProviderProps {
|
|
11
|
+
apikey: string;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}
|
|
2
14
|
|
|
3
15
|
export declare const PaymentDialog: default_2.NamedExoticComponent<PaymentDialogProps>;
|
|
4
16
|
|
|
5
17
|
declare interface PaymentDialogProps {
|
|
6
18
|
open: boolean;
|
|
7
19
|
onClose: () => void;
|
|
8
|
-
|
|
20
|
+
apikey: string;
|
|
21
|
+
plain: PaymentPlain;
|
|
9
22
|
orderId: string;
|
|
10
23
|
amount: string;
|
|
24
|
+
intervalDays?: number;
|
|
11
25
|
onSuccess?: (paymentId: string) => void;
|
|
12
26
|
onError?: (error: Error) => void;
|
|
13
27
|
}
|
|
14
28
|
|
|
29
|
+
declare interface PaymentOptions_2 {
|
|
30
|
+
plain: PaymentPlain;
|
|
31
|
+
orderId: string;
|
|
32
|
+
amount: string;
|
|
33
|
+
intervalDays?: number;
|
|
34
|
+
onSuccess?: (paymentId: string) => void;
|
|
35
|
+
onError?: (error: Error) => void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
declare type PaymentPlain = "one-time" | "subscription" | "x402";
|
|
39
|
+
|
|
40
|
+
export declare const useCppayPayment: () => CppayContextValue;
|
|
41
|
+
|
|
15
42
|
export { }
|
package/dist/react.js
CHANGED
|
@@ -1,73 +1,79 @@
|
|
|
1
|
-
import { t as cppay_default } from "./cppay-
|
|
1
|
+
import { t as cppay_default } from "./cppay-p8t6ic0x.js";
|
|
2
2
|
import { n as payment_dialog_default, t as injectStyle } from "./inject-style-qX_0AjjE.js";
|
|
3
|
-
import React, { useEffect, useMemo, useState } from "react";
|
|
3
|
+
import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
var PaymentDialog_default = React.memo(({ open:
|
|
6
|
-
let
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
var PaymentDialog_default = React.memo(({ open: i, onClose: a, apikey: o, plain: s, orderId: c, amount: l, intervalDays: f, onSuccess: p, onError: m }) => {
|
|
6
|
+
let h = useMemo(() => new cppay_default(o), [o]), [g, _] = useState("select"), [v, y] = useState(!1), [b, x] = useState([]), [S, C] = useState(""), [w, T] = useState(""), [E, D] = useState(null), O = useMemo(() => b.find((t) => t.chain === S), [b, S]), k = useMemo(() => O?.tokens || [], [O]), A = useMemo(() => k.find((t) => t.symbol === w), [k, w]), j = useMemo(() => w ? (parseFloat(l) / 1).toFixed(6) : "0", [
|
|
7
|
+
l,
|
|
8
|
+
w,
|
|
9
9
|
1
|
|
10
|
-
]),
|
|
10
|
+
]), M = async () => {
|
|
11
11
|
try {
|
|
12
|
-
|
|
13
|
-
let t = await
|
|
14
|
-
|
|
12
|
+
y(!0);
|
|
13
|
+
let t = await h.getSupportedChains();
|
|
14
|
+
x(t), t.length > 0 && C(t[0].chain);
|
|
15
15
|
} catch (t) {
|
|
16
|
-
|
|
16
|
+
m?.(t);
|
|
17
17
|
} finally {
|
|
18
|
-
|
|
18
|
+
y(!1);
|
|
19
19
|
}
|
|
20
|
-
},
|
|
21
|
-
if (!(!
|
|
22
|
-
|
|
23
|
-
let t
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
20
|
+
}, N = async () => {
|
|
21
|
+
if (!(!S || !w)) try {
|
|
22
|
+
y(!0);
|
|
23
|
+
let t;
|
|
24
|
+
s === "one-time" ? t = await h.createPayment("one-time", {
|
|
25
|
+
paymentChain: S,
|
|
26
|
+
paymentToken: w,
|
|
27
|
+
orderId: c,
|
|
28
|
+
amount: j
|
|
29
|
+
}) : s === "subscription" && (t = await h.createPayment("subscription", {
|
|
30
|
+
paymentChain: S,
|
|
31
|
+
paymentToken: w,
|
|
32
|
+
orderId: c,
|
|
33
|
+
amountOfUsd: j,
|
|
34
|
+
intervalDays: f || 30
|
|
35
|
+
})), D({
|
|
36
|
+
paymentId: t.paymentId || t.subscriptionId,
|
|
37
|
+
paymentAmount: t.paymentAmount || t.approveAmount,
|
|
38
|
+
receiveAddress: A?.receiveAddresses[0] || t.spenderAddress || ""
|
|
39
|
+
}), _("payment");
|
|
34
40
|
} catch (t) {
|
|
35
|
-
|
|
41
|
+
m?.(t);
|
|
36
42
|
} finally {
|
|
37
|
-
|
|
43
|
+
y(!1);
|
|
38
44
|
}
|
|
39
|
-
},
|
|
40
|
-
if (
|
|
41
|
-
|
|
45
|
+
}, P = async () => {
|
|
46
|
+
if (E) try {
|
|
47
|
+
y(!0), await h.checkPaymentStatus("one-time", E), p?.(E.paymentId), I();
|
|
42
48
|
} catch (t) {
|
|
43
|
-
|
|
49
|
+
m?.(t);
|
|
44
50
|
} finally {
|
|
45
|
-
|
|
51
|
+
y(!1);
|
|
46
52
|
}
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
}, F = async () => {
|
|
54
|
+
E?.receiveAddress && await navigator.clipboard.writeText(E.receiveAddress);
|
|
55
|
+
}, I = () => {
|
|
56
|
+
a(), setTimeout(() => {
|
|
57
|
+
_("select"), D(null);
|
|
52
58
|
}, 300);
|
|
53
59
|
};
|
|
54
60
|
return useEffect(() => {
|
|
55
|
-
|
|
56
|
-
}, [
|
|
57
|
-
|
|
58
|
-
}, [
|
|
61
|
+
i && b.length === 0 && M();
|
|
62
|
+
}, [i]), useEffect(() => {
|
|
63
|
+
k.length > 0 && T(k[0].symbol);
|
|
64
|
+
}, [k]), i ? /* @__PURE__ */ jsx("div", {
|
|
59
65
|
className: "_cppay-overlay",
|
|
60
|
-
onClick: (t) => t.target === t.currentTarget &&
|
|
66
|
+
onClick: (t) => t.target === t.currentTarget && I(),
|
|
61
67
|
children: /* @__PURE__ */ jsxs("div", {
|
|
62
68
|
className: "_cppay-dialog",
|
|
63
69
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
64
70
|
className: "_cppay-header",
|
|
65
71
|
children: [/* @__PURE__ */ jsx("h2", {
|
|
66
72
|
className: "_cppay-title",
|
|
67
|
-
children:
|
|
73
|
+
children: g === "select" ? "选择支付方式" : "完成支付"
|
|
68
74
|
}), /* @__PURE__ */ jsx("button", {
|
|
69
|
-
onClick:
|
|
70
|
-
disabled:
|
|
75
|
+
onClick: I,
|
|
76
|
+
disabled: v,
|
|
71
77
|
className: "_cppay-close-btn",
|
|
72
78
|
children: /* @__PURE__ */ jsx("svg", {
|
|
73
79
|
fill: "none",
|
|
@@ -83,7 +89,7 @@ var PaymentDialog_default = React.memo(({ open: o, onClose: s, apiKey: c, orderI
|
|
|
83
89
|
})]
|
|
84
90
|
}), /* @__PURE__ */ jsx("div", {
|
|
85
91
|
className: "_cppay-content",
|
|
86
|
-
children:
|
|
92
|
+
children: g === "select" ? /* @__PURE__ */ jsxs("div", { children: [
|
|
87
93
|
/* @__PURE__ */ jsxs("div", {
|
|
88
94
|
className: "_cppay-section",
|
|
89
95
|
children: [/* @__PURE__ */ jsx("label", {
|
|
@@ -91,9 +97,9 @@ var PaymentDialog_default = React.memo(({ open: o, onClose: s, apiKey: c, orderI
|
|
|
91
97
|
children: "支付网络"
|
|
92
98
|
}), /* @__PURE__ */ jsx("div", {
|
|
93
99
|
className: "_cppay-grid",
|
|
94
|
-
children:
|
|
95
|
-
onClick: () =>
|
|
96
|
-
className: `_cppay-select-btn ${
|
|
100
|
+
children: b.map((t) => /* @__PURE__ */ jsxs("button", {
|
|
101
|
+
onClick: () => C(t.chain),
|
|
102
|
+
className: `_cppay-select-btn ${S === t.chain ? "_cppay-selected" : ""}`,
|
|
97
103
|
children: [t.icon && /* @__PURE__ */ jsx("img", {
|
|
98
104
|
src: t.icon,
|
|
99
105
|
alt: t.chain
|
|
@@ -108,9 +114,9 @@ var PaymentDialog_default = React.memo(({ open: o, onClose: s, apiKey: c, orderI
|
|
|
108
114
|
children: "支付代币"
|
|
109
115
|
}), /* @__PURE__ */ jsx("div", {
|
|
110
116
|
className: "_cppay-grid",
|
|
111
|
-
children:
|
|
112
|
-
onClick: () =>
|
|
113
|
-
className: `_cppay-select-btn ${
|
|
117
|
+
children: k.map((t) => /* @__PURE__ */ jsxs("button", {
|
|
118
|
+
onClick: () => T(t.symbol),
|
|
119
|
+
className: `_cppay-select-btn ${w === t.symbol ? "_cppay-selected" : ""}`,
|
|
114
120
|
children: [t.icon && /* @__PURE__ */ jsx("img", {
|
|
115
121
|
src: t.icon,
|
|
116
122
|
alt: t.symbol
|
|
@@ -132,13 +138,13 @@ var PaymentDialog_default = React.memo(({ open: o, onClose: s, apiKey: c, orderI
|
|
|
132
138
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
133
139
|
className: "_cppay-price-main",
|
|
134
140
|
children: [
|
|
135
|
-
|
|
141
|
+
j,
|
|
136
142
|
" ",
|
|
137
|
-
|
|
143
|
+
w
|
|
138
144
|
]
|
|
139
145
|
}), /* @__PURE__ */ jsxs("div", {
|
|
140
146
|
className: "_cppay-price-sub",
|
|
141
|
-
children: ["≈ $",
|
|
147
|
+
children: ["≈ $", l]
|
|
142
148
|
})]
|
|
143
149
|
})]
|
|
144
150
|
})
|
|
@@ -147,13 +153,13 @@ var PaymentDialog_default = React.memo(({ open: o, onClose: s, apiKey: c, orderI
|
|
|
147
153
|
/* @__PURE__ */ jsx("div", {
|
|
148
154
|
className: "_cppay-section",
|
|
149
155
|
children: /* @__PURE__ */ jsx("button", {
|
|
150
|
-
onClick:
|
|
151
|
-
disabled: !
|
|
156
|
+
onClick: N,
|
|
157
|
+
disabled: !S || !w || v,
|
|
152
158
|
className: "_cppay-btn _cppay-btn-primary",
|
|
153
|
-
children:
|
|
159
|
+
children: v ? "处理中..." : "继续支付"
|
|
154
160
|
})
|
|
155
161
|
})
|
|
156
|
-
] }) :
|
|
162
|
+
] }) : E && /* @__PURE__ */ jsxs("div", { children: [
|
|
157
163
|
/* @__PURE__ */ jsx("div", {
|
|
158
164
|
className: "_cppay-qr-container",
|
|
159
165
|
children: /* @__PURE__ */ jsx("div", {
|
|
@@ -171,9 +177,9 @@ var PaymentDialog_default = React.memo(({ open: o, onClose: s, apiKey: c, orderI
|
|
|
171
177
|
}), /* @__PURE__ */ jsxs("div", {
|
|
172
178
|
className: "_cppay-info-value",
|
|
173
179
|
children: [
|
|
174
|
-
|
|
180
|
+
E.paymentAmount,
|
|
175
181
|
" ",
|
|
176
|
-
|
|
182
|
+
w
|
|
177
183
|
]
|
|
178
184
|
})]
|
|
179
185
|
}), /* @__PURE__ */ jsxs("div", {
|
|
@@ -183,8 +189,8 @@ var PaymentDialog_default = React.memo(({ open: o, onClose: s, apiKey: c, orderI
|
|
|
183
189
|
children: "支付地址"
|
|
184
190
|
}), /* @__PURE__ */ jsxs("div", {
|
|
185
191
|
className: "_cppay-address-row",
|
|
186
|
-
children: [/* @__PURE__ */ jsx("code", { children:
|
|
187
|
-
onClick:
|
|
192
|
+
children: [/* @__PURE__ */ jsx("code", { children: E.receiveAddress }), /* @__PURE__ */ jsx("button", {
|
|
193
|
+
onClick: F,
|
|
188
194
|
className: "_cppay-copy-btn",
|
|
189
195
|
title: "复制地址",
|
|
190
196
|
children: /* @__PURE__ */ jsx("svg", {
|
|
@@ -205,17 +211,17 @@ var PaymentDialog_default = React.memo(({ open: o, onClose: s, apiKey: c, orderI
|
|
|
205
211
|
/* @__PURE__ */ jsx("div", {
|
|
206
212
|
className: "_cppay-section",
|
|
207
213
|
children: /* @__PURE__ */ jsx("button", {
|
|
208
|
-
onClick:
|
|
209
|
-
disabled:
|
|
214
|
+
onClick: P,
|
|
215
|
+
disabled: v,
|
|
210
216
|
className: "_cppay-btn _cppay-btn-primary",
|
|
211
|
-
children:
|
|
217
|
+
children: v ? "检查支付状态..." : "我已完成支付"
|
|
212
218
|
})
|
|
213
219
|
}),
|
|
214
220
|
/* @__PURE__ */ jsx("div", {
|
|
215
221
|
className: "_cppay-section",
|
|
216
222
|
children: /* @__PURE__ */ jsx("button", {
|
|
217
|
-
onClick: () =>
|
|
218
|
-
disabled:
|
|
223
|
+
onClick: () => _("select"),
|
|
224
|
+
disabled: v,
|
|
219
225
|
className: "_cppay-btn _cppay-btn-secondary",
|
|
220
226
|
children: "更改支付方式"
|
|
221
227
|
})
|
|
@@ -224,6 +230,35 @@ var PaymentDialog_default = React.memo(({ open: o, onClose: s, apiKey: c, orderI
|
|
|
224
230
|
})]
|
|
225
231
|
})
|
|
226
232
|
}) : null;
|
|
227
|
-
});
|
|
233
|
+
}), CppayContext = createContext(null);
|
|
234
|
+
const CppayProvider = ({ apikey: t, children: i }) => {
|
|
235
|
+
let [a, o] = useState(!1), [s, l] = useState(null), u = useCallback((t) => {
|
|
236
|
+
l(t), o(!0);
|
|
237
|
+
}, []), d = useCallback(() => {
|
|
238
|
+
o(!1);
|
|
239
|
+
}, []), m = useCallback((t) => {
|
|
240
|
+
s?.onSuccess?.(t), o(!1);
|
|
241
|
+
}, [s]), h = useCallback((t) => {
|
|
242
|
+
s?.onError?.(t);
|
|
243
|
+
}, [s]);
|
|
244
|
+
return /* @__PURE__ */ jsxs(CppayContext.Provider, {
|
|
245
|
+
value: { showPayment: u },
|
|
246
|
+
children: [i, s && /* @__PURE__ */ jsx(PaymentDialog_default, {
|
|
247
|
+
open: a,
|
|
248
|
+
onClose: d,
|
|
249
|
+
apikey: t,
|
|
250
|
+
plain: s.plain,
|
|
251
|
+
orderId: s.orderId,
|
|
252
|
+
amount: s.amount,
|
|
253
|
+
intervalDays: s.intervalDays,
|
|
254
|
+
onSuccess: m,
|
|
255
|
+
onError: h
|
|
256
|
+
})]
|
|
257
|
+
});
|
|
258
|
+
}, useCppayPayment = () => {
|
|
259
|
+
let t = useContext(CppayContext);
|
|
260
|
+
if (!t) throw Error("useCppayPayment must be used within CppayProvider");
|
|
261
|
+
return t;
|
|
262
|
+
};
|
|
228
263
|
injectStyle(payment_dialog_default);
|
|
229
|
-
export { PaymentDialog_default as PaymentDialog };
|
|
264
|
+
export { CppayProvider, PaymentDialog_default as PaymentDialog, useCppayPayment };
|
package/dist/vue.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./cppay-
|
|
1
|
+
const e=require(`./cppay-S6x6aDqU.cjs`),t=require(`./inject-style-Dz7JsQxo.cjs`),n=require(`./react.cjs`);let r=require(`vue`);var i={class:`_cppay-dialog`},a={class:`_cppay-header`},o={class:`_cppay-title`},s=[`disabled`],c={class:`_cppay-content`},l={key:0},u={class:`_cppay-section`},d={class:`_cppay-grid`},f=[`onClick`],p=[`src`,`alt`],m={class:`_cppay-section`},h={class:`_cppay-grid`},g=[`onClick`],_=[`src`,`alt`],v={class:`_cppay-section`},y={class:`_cppay-price-box`},b={class:`_cppay-price-row`},x={class:`_cppay-price-amount`},S={class:`_cppay-price-main`},C={class:`_cppay-price-sub`},w={class:`_cppay-section`},T=[`disabled`],E={key:1},D={class:`_cppay-section`},O={class:`_cppay-info-box`},k={class:`_cppay-info-value`},A={class:`_cppay-info-box`},j={class:`_cppay-address-row`},M={class:`_cppay-section`},ee=[`disabled`],N={class:`_cppay-section`},P=[`disabled`],F=(0,r.defineComponent)({__name:`PaymentDialog`,props:{modelValue:{type:Boolean},apikey:{},orderId:{},amount:{}},emits:[`update:modelValue`,`success`,`error`],setup(t,{emit:n}){let F=t,I=n,L=new e.t(F.apikey),R=(0,r.ref)(`select`),z=(0,r.ref)(!1),B=(0,r.ref)([]),V=(0,r.ref)(``),H=(0,r.ref)(``),U=(0,r.ref)(null),W=(0,r.computed)(()=>B.value.find(e=>e.chain===V.value)),G=(0,r.computed)(()=>W.value?.tokens||[]),K=(0,r.computed)(()=>G.value.find(e=>e.symbol===H.value)),q=(0,r.ref)(1),J=(0,r.computed)(()=>H.value?(parseFloat(F.amount)/q.value).toFixed(6):`0`),Y=()=>{I(`update:modelValue`,!1),setTimeout(()=>{R.value=`select`,U.value=null},300)},X=async()=>{try{z.value=!0,B.value=await L.getSupportedChains(),B.value.length>0&&(V.value=B.value[0].chain)}catch(e){I(`error`,e)}finally{z.value=!1}},Z=async()=>{if(!(!V.value||!H.value))try{z.value=!0;let e=await L.createPayment(`one-time`,{paymentChain:V.value,paymentToken:H.value,orderId:F.orderId,amount:J.value});U.value={paymentId:e.paymentId,paymentAmount:e.paymentAmount,receiveAddress:K.value?.receiveAddresses[0]||``},R.value=`payment`}catch(e){I(`error`,e)}finally{z.value=!1}},Q=async()=>{if(U.value)try{z.value=!0,await L.checkPaymentStatus(`one-time`,U.value),I(`success`,U.value.paymentId),Y()}catch(e){I(`error`,e)}finally{z.value=!1}},$=async()=>{U.value?.receiveAddress&&await navigator.clipboard.writeText(U.value.receiveAddress)};return(0,r.watch)(()=>F.modelValue,e=>{e&&B.value.length===0&&X()}),(0,r.watch)(V,()=>{G.value.length>0&&(H.value=G.value[0].symbol)}),(e,n)=>((0,r.openBlock)(),(0,r.createBlock)(r.Teleport,{to:`body`},[(0,r.createVNode)(r.Transition,{name:`_cppay-fade`},{default:(0,r.withCtx)(()=>[t.modelValue?((0,r.openBlock)(),(0,r.createElementBlock)(`div`,{key:0,class:`_cppay-overlay`,onClick:(0,r.withModifiers)(Y,[`self`])},[(0,r.createElementVNode)(`div`,i,[(0,r.createElementVNode)(`div`,a,[(0,r.createElementVNode)(`h2`,o,(0,r.toDisplayString)(R.value===`select`?`选择支付方式`:`完成支付`),1),(0,r.createElementVNode)(`button`,{onClick:Y,class:`_cppay-close-btn`,disabled:z.value},[...n[1]||=[(0,r.createElementVNode)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`},[(0,r.createElementVNode)(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M6 18L18 6M6 6l12 12`})],-1)]],8,s)]),(0,r.createElementVNode)(`div`,c,[R.value===`select`?((0,r.openBlock)(),(0,r.createElementBlock)(`div`,l,[(0,r.createElementVNode)(`div`,u,[n[2]||=(0,r.createElementVNode)(`label`,{class:`_cppay-label`},`支付网络`,-1),(0,r.createElementVNode)(`div`,d,[((0,r.openBlock)(!0),(0,r.createElementBlock)(r.Fragment,null,(0,r.renderList)(B.value,e=>((0,r.openBlock)(),(0,r.createElementBlock)(`button`,{key:e.chain,onClick:t=>V.value=e.chain,class:(0,r.normalizeClass)([`_cppay-select-btn`,V.value===e.chain?`_cppay-selected`:``])},[e.icon?((0,r.openBlock)(),(0,r.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.chain},null,8,p)):(0,r.createCommentVNode)(``,!0),(0,r.createElementVNode)(`span`,null,(0,r.toDisplayString)(e.chain),1)],10,f))),128))])]),(0,r.createElementVNode)(`div`,m,[n[3]||=(0,r.createElementVNode)(`label`,{class:`_cppay-label`},`支付代币`,-1),(0,r.createElementVNode)(`div`,h,[((0,r.openBlock)(!0),(0,r.createElementBlock)(r.Fragment,null,(0,r.renderList)(G.value,e=>((0,r.openBlock)(),(0,r.createElementBlock)(`button`,{key:e.symbol,onClick:t=>H.value=e.symbol,class:(0,r.normalizeClass)([`_cppay-select-btn`,H.value===e.symbol?`_cppay-selected`:``])},[e.icon?((0,r.openBlock)(),(0,r.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.symbol},null,8,_)):(0,r.createCommentVNode)(``,!0),(0,r.createElementVNode)(`span`,null,(0,r.toDisplayString)(e.symbol),1)],10,g))),128))])]),(0,r.createElementVNode)(`div`,v,[(0,r.createElementVNode)(`div`,y,[(0,r.createElementVNode)(`div`,b,[n[4]||=(0,r.createElementVNode)(`span`,{class:`_cppay-price-label`},`支付金额`,-1),(0,r.createElementVNode)(`div`,x,[(0,r.createElementVNode)(`div`,S,(0,r.toDisplayString)(J.value)+` `+(0,r.toDisplayString)(H.value),1),(0,r.createElementVNode)(`div`,C,`≈ $`+(0,r.toDisplayString)(t.amount),1)])])])]),(0,r.createElementVNode)(`div`,w,[(0,r.createElementVNode)(`button`,{onClick:Z,disabled:!V.value||!H.value||z.value,class:`_cppay-btn _cppay-btn-primary`},(0,r.toDisplayString)(z.value?`处理中...`:`继续支付`),9,T)])])):R.value===`payment`&&U.value?((0,r.openBlock)(),(0,r.createElementBlock)(`div`,E,[n[8]||=(0,r.createElementVNode)(`div`,{class:`_cppay-qr-container`},[(0,r.createElementVNode)(`div`,{class:`_cppay-qr-placeholder`},[(0,r.createElementVNode)(`span`,null,`扫码支付`)])],-1),(0,r.createElementVNode)(`div`,D,[(0,r.createElementVNode)(`div`,O,[n[5]||=(0,r.createElementVNode)(`div`,{class:`_cppay-info-label`},`支付金额`,-1),(0,r.createElementVNode)(`div`,k,(0,r.toDisplayString)(U.value.paymentAmount)+` `+(0,r.toDisplayString)(H.value),1)]),(0,r.createElementVNode)(`div`,A,[n[7]||=(0,r.createElementVNode)(`div`,{class:`_cppay-info-label`},`支付地址`,-1),(0,r.createElementVNode)(`div`,j,[(0,r.createElementVNode)(`code`,null,(0,r.toDisplayString)(U.value.receiveAddress),1),(0,r.createElementVNode)(`button`,{onClick:$,class:`_cppay-copy-btn`,title:`复制地址`},[...n[6]||=[(0,r.createElementVNode)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`},[(0,r.createElementVNode)(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z`})],-1)]])])])]),(0,r.createElementVNode)(`div`,M,[(0,r.createElementVNode)(`button`,{onClick:Q,disabled:z.value,class:`_cppay-btn _cppay-btn-primary`},(0,r.toDisplayString)(z.value?`检查支付状态...`:`我已完成支付`),9,ee)]),(0,r.createElementVNode)(`div`,N,[(0,r.createElementVNode)(`button`,{onClick:n[0]||=e=>R.value=`select`,disabled:z.value,class:`_cppay-btn _cppay-btn-secondary`},` 更改支付方式 `,8,P)])])):(0,r.createCommentVNode)(``,!0)])])])):(0,r.createCommentVNode)(``,!0)]),_:1})]))}}),I=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},L=I(F,[[`__scopeId`,`data-v-57d5d708`]]);t.t(t.n),exports.PaymentDialog=L;
|
package/dist/vue.d.ts
CHANGED
package/dist/vue.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as cppay_default } from "./cppay-
|
|
1
|
+
import { t as cppay_default } from "./cppay-p8t6ic0x.js";
|
|
2
2
|
import { n as payment_dialog_default, t as injectStyle } from "./inject-style-qX_0AjjE.js";
|
|
3
3
|
import { Fragment, Teleport, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, openBlock, ref, renderList, toDisplayString, watch, withCtx, withModifiers } from "vue";
|
|
4
4
|
var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-header" }, _hoisted_3 = { class: "_cppay-title" }, _hoisted_4 = ["disabled"], _hoisted_5 = { class: "_cppay-content" }, _hoisted_6 = { key: 0 }, _hoisted_7 = { class: "_cppay-section" }, _hoisted_8 = { class: "_cppay-grid" }, _hoisted_9 = ["onClick"], _hoisted_10 = ["src", "alt"], _hoisted_11 = { class: "_cppay-section" }, _hoisted_12 = { class: "_cppay-grid" }, _hoisted_13 = ["onClick"], _hoisted_14 = ["src", "alt"], _hoisted_15 = { class: "_cppay-section" }, _hoisted_16 = { class: "_cppay-price-box" }, _hoisted_17 = { class: "_cppay-price-row" }, _hoisted_18 = { class: "_cppay-price-amount" }, _hoisted_19 = { class: "_cppay-price-main" }, _hoisted_20 = { class: "_cppay-price-sub" }, _hoisted_21 = { class: "_cppay-section" }, _hoisted_22 = ["disabled"], _hoisted_23 = { key: 1 }, _hoisted_24 = { class: "_cppay-section" }, _hoisted_25 = { class: "_cppay-info-box" }, _hoisted_26 = { class: "_cppay-info-value" }, _hoisted_27 = { class: "_cppay-info-box" }, _hoisted_28 = { class: "_cppay-address-row" }, _hoisted_29 = { class: "_cppay-section" }, _hoisted_30 = ["disabled"], _hoisted_31 = { class: "_cppay-section" }, _hoisted_32 = ["disabled"], PaymentDialog_default = /* @__PURE__ */ ((r, M) => {
|
|
@@ -9,7 +9,7 @@ var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-heade
|
|
|
9
9
|
__name: "PaymentDialog",
|
|
10
10
|
props: {
|
|
11
11
|
modelValue: { type: Boolean },
|
|
12
|
-
|
|
12
|
+
apikey: {},
|
|
13
13
|
orderId: {},
|
|
14
14
|
amount: {}
|
|
15
15
|
},
|
|
@@ -19,7 +19,7 @@ var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-heade
|
|
|
19
19
|
"error"
|
|
20
20
|
],
|
|
21
21
|
setup(M, { emit: N }) {
|
|
22
|
-
let F = M, I = N, L = new cppay_default(F.
|
|
22
|
+
let F = M, I = N, L = new cppay_default(F.apikey), R = ref("select"), z = ref(!1), B = ref([]), V = ref(""), H = ref(""), U = ref(null), W = computed(() => B.value.find((r) => r.chain === V.value)), G = computed(() => W.value?.tokens || []), K = computed(() => G.value.find((r) => r.symbol === H.value)), q = ref(1), J = computed(() => H.value ? (parseFloat(F.amount) / q.value).toFixed(6) : "0"), Y = () => {
|
|
23
23
|
I("update:modelValue", !1), setTimeout(() => {
|
|
24
24
|
R.value = "select", U.value = null;
|
|
25
25
|
}, 300);
|
|
@@ -34,7 +34,7 @@ var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-heade
|
|
|
34
34
|
}, Z = async () => {
|
|
35
35
|
if (!(!V.value || !H.value)) try {
|
|
36
36
|
z.value = !0;
|
|
37
|
-
let r = await L.createPayment({
|
|
37
|
+
let r = await L.createPayment("one-time", {
|
|
38
38
|
paymentChain: V.value,
|
|
39
39
|
paymentToken: H.value,
|
|
40
40
|
orderId: F.orderId,
|
|
@@ -52,7 +52,7 @@ var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-heade
|
|
|
52
52
|
}
|
|
53
53
|
}, Q = async () => {
|
|
54
54
|
if (U.value) try {
|
|
55
|
-
z.value = !0, await L.checkPaymentStatus(U.value
|
|
55
|
+
z.value = !0, await L.checkPaymentStatus("one-time", U.value), I("success", U.value.paymentId), Y();
|
|
56
56
|
} catch (r) {
|
|
57
57
|
I("error", r);
|
|
58
58
|
} finally {
|
|
@@ -138,6 +138,6 @@ var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-heade
|
|
|
138
138
|
_: 1
|
|
139
139
|
})]));
|
|
140
140
|
}
|
|
141
|
-
}), [["__scopeId", "data-v-
|
|
141
|
+
}), [["__scopeId", "data-v-57d5d708"]]);
|
|
142
142
|
injectStyle(payment_dialog_default);
|
|
143
143
|
export { PaymentDialog_default as PaymentDialog };
|
package/package.json
CHANGED
package/dist/cppay-Co7VAb5Q.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
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;
|
|
36
|
-
const cppayRequest = async (e, t) => {
|
|
37
|
-
let n = new URLSearchParams(t.params), a = await request(`${t.url}${n.size ? `?${n.toString()}` : ""}`, {
|
|
38
|
-
method: t.method ?? "get",
|
|
39
|
-
headers: {
|
|
40
|
-
Authorization: e,
|
|
41
|
-
...t.headers
|
|
42
|
-
},
|
|
43
|
-
body: t.data ? JSON.stringify(t.data) : void 0
|
|
44
|
-
});
|
|
45
|
-
if (a.code !== SUCCESS_CODE) throw Error(`Request ${t.url} Failed. ${a.message}`);
|
|
46
|
-
return a.data;
|
|
47
|
-
};
|
|
48
|
-
var cppay_default = class {
|
|
49
|
-
apikey;
|
|
50
|
-
constructor(e) {
|
|
51
|
-
this.apikey = e;
|
|
52
|
-
}
|
|
53
|
-
async getSupportedChains() {
|
|
54
|
-
let n = (await cppayRequest(this.apikey, { url: "/api/payment/token" })).reduce((n, r) => {
|
|
55
|
-
let i = n[r.chain] ?? {
|
|
56
|
-
chain: r.chain,
|
|
57
|
-
chainId: r.chain_id,
|
|
58
|
-
tokens: [],
|
|
59
|
-
icon: CHAIN_ICONS[r.chain]
|
|
60
|
-
};
|
|
61
|
-
return i.tokens.push({
|
|
62
|
-
symbol: r.token_symbol,
|
|
63
|
-
decimals: r.token_decimals,
|
|
64
|
-
address: r.token_address,
|
|
65
|
-
receiveAddresses: r.receive_addresses,
|
|
66
|
-
icon: TOKEN_ICONS[r.token_symbol]
|
|
67
|
-
}), n[r.chain] = i, n;
|
|
68
|
-
}, {});
|
|
69
|
-
return Object.values(n);
|
|
70
|
-
}
|
|
71
|
-
async createPayment(e) {
|
|
72
|
-
let t = {
|
|
73
|
-
chain: e.paymentChain,
|
|
74
|
-
token: e.paymentToken,
|
|
75
|
-
order_no: e.orderId,
|
|
76
|
-
amount: e.amount
|
|
77
|
-
}, n = await cppayRequest(this.apikey, {
|
|
78
|
-
url: "/api/payment/create",
|
|
79
|
-
method: "post",
|
|
80
|
-
data: t
|
|
81
|
-
});
|
|
82
|
-
return {
|
|
83
|
-
orderId: e.orderId,
|
|
84
|
-
paymentId: n.payment_id,
|
|
85
|
-
paymentAmount: n.pay_amount,
|
|
86
|
-
receiveAddress: n.receive_address,
|
|
87
|
-
paymentChain: e.paymentChain,
|
|
88
|
-
paymentToken: e.paymentToken
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
async checkPaymentStatus(e) {
|
|
92
|
-
let t = { payment_id: e }, n = await cppayRequest(this.apikey, {
|
|
93
|
-
url: "/api/payment/query",
|
|
94
|
-
params: t
|
|
95
|
-
});
|
|
96
|
-
return {
|
|
97
|
-
orderId: n.order_no,
|
|
98
|
-
paymentId: n.payment_id,
|
|
99
|
-
chain: n.chain,
|
|
100
|
-
token: n.token,
|
|
101
|
-
baseAmount: n.base_amount,
|
|
102
|
-
payAmount: n.pay_amount,
|
|
103
|
-
receiveAddress: n.receive_address,
|
|
104
|
-
expireAt: n.expire_at,
|
|
105
|
-
status: n.status
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
export { CHAIN_ICONS as n, TOKEN_ICONS as r, cppay_default as t };
|
package/dist/cppay-DUOs8RUI.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e={Ethereum:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png`,BSC:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,"bsc-testnet":`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,Tron:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png`,Polygon:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/polygon/info/logo.png`,Solana:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png`},t={USDT:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png`,USDC:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png`,ETH:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png`,BNB:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,tBNB:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,TRX:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png`,SOL:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png`};var n=`http://192.168.0.162:8000`,r=async(e,t,r)=>{let i=Object.assign({timeout:15e3},r),a=new AbortController,o=setTimeout(()=>a.abort(),i.timeout);try{let r=await fetch(new URL(e,n),{signal:a.signal,...t});clearTimeout(o);let i=r.headers.get(`Content-Type`)??``;if(i.includes(`json`))return await r.json();try{return await r.json()}catch{throw Error(`URL: ${e}, Unsupport Content Type: ${i}`)}}catch(t){throw clearTimeout(o),t instanceof DOMException&&t.name===`AbortError`?Error(`URL: ${e}, Request timeout after ${i.timeout}ms`):t}},i=0;const 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};var o=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,chainId:r.chain_id,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,receiveAddress:n.receive_address,paymentChain:e.paymentChain,paymentToken:e.paymentToken}}async checkPaymentStatus(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}}},s=o;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 s}});
|