@coin-voyage/shared 0.0.1 → 0.0.2
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/api/config.d.ts +1 -0
- package/dist/api/config.js +3 -0
- package/dist/api/config.js.map +1 -0
- package/dist/api/fetcher.d.ts +7 -0
- package/{src/api/fetcher.ts → dist/api/fetcher.js} +10 -17
- package/dist/api/fetcher.js.map +1 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +4 -0
- package/dist/api/index.js.map +1 -0
- package/{src/api/pay-order.ts → dist/api/pay-order.d.ts} +114 -230
- package/dist/api/pay-order.js +238 -0
- package/dist/api/pay-order.js.map +1 -0
- package/dist/common/assert.d.ts +3 -0
- package/dist/common/assert.js +14 -0
- package/dist/common/assert.js.map +1 -0
- package/dist/common/chainExplorer.d.ts +2 -0
- package/dist/common/chainExplorer.js +26 -0
- package/dist/common/chainExplorer.js.map +1 -0
- package/dist/common/chains.d.ts +31 -0
- package/dist/common/chains.js +121 -0
- package/dist/common/chains.js.map +1 -0
- package/dist/common/currencies.d.ts +14 -0
- package/dist/common/currencies.js +31 -0
- package/dist/common/currencies.js.map +1 -0
- package/dist/common/debug.d.ts +1 -0
- package/dist/common/debug.js +11 -0
- package/dist/common/debug.js.map +1 -0
- package/dist/common/format.d.ts +1 -0
- package/dist/common/format.js +4 -0
- package/dist/common/format.js.map +1 -0
- package/dist/common/i18n/index.d.ts +6 -0
- package/dist/common/i18n/index.js +12 -0
- package/dist/common/i18n/index.js.map +1 -0
- package/dist/common/i18n/languages/en.d.ts +18 -0
- package/dist/common/i18n/languages/en.js +21 -0
- package/dist/common/i18n/languages/en.js.map +1 -0
- package/dist/common/i18n/languages/es.d.ts +2 -0
- package/dist/common/i18n/languages/es.js +21 -0
- package/dist/common/i18n/languages/es.js.map +1 -0
- package/dist/common/index.d.ts +12 -0
- package/dist/common/index.js +13 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/model.d.ts +22 -0
- package/dist/common/model.js +17 -0
- package/dist/common/model.js.map +1 -0
- package/{src/common/organization.ts → dist/common/organization.d.ts} +1 -2
- package/dist/common/organization.js +2 -0
- package/dist/common/organization.js.map +1 -0
- package/dist/common/pay.d.ts +284 -0
- package/dist/common/pay.js +82 -0
- package/dist/common/pay.js.map +1 -0
- package/dist/common/retryBackoff.d.ts +1 -0
- package/dist/common/retryBackoff.js +22 -0
- package/dist/common/retryBackoff.js.map +1 -0
- package/dist/common/time.d.ts +11 -0
- package/dist/common/time.js +62 -0
- package/dist/common/time.js.map +1 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/use-is-mobile.d.ts +1 -0
- package/dist/hooks/use-is-mobile.js +14 -0
- package/dist/hooks/use-is-mobile.js.map +1 -0
- package/dist/utils/account.d.ts +1 -0
- package/dist/utils/account.js +4 -0
- package/dist/utils/account.js.map +1 -0
- package/dist/utils/browser.d.ts +6 -0
- package/dist/utils/browser.js +22 -0
- package/dist/utils/browser.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/plurar.d.ts +1 -0
- package/dist/utils/plurar.js +7 -0
- package/dist/utils/plurar.js.map +1 -0
- package/package.json +6 -6
- package/src/api/config.ts +0 -2
- package/src/api/index.ts +0 -3
- package/src/common/assert.ts +0 -21
- package/src/common/chainExplorer.ts +0 -27
- package/src/common/chains.ts +0 -130
- package/src/common/currencies.ts +0 -42
- package/src/common/debug.ts +0 -11
- package/src/common/format.ts +0 -3
- package/src/common/i18n/index.ts +0 -18
- package/src/common/i18n/languages/en.ts +0 -38
- package/src/common/i18n/languages/es.ts +0 -38
- package/src/common/index.ts +0 -12
- package/src/common/model.ts +0 -43
- package/src/common/pay.ts +0 -194
- package/src/common/retryBackoff.ts +0 -24
- package/src/common/time.ts +0 -78
- package/src/hooks/use-is-mobile.ts +0 -16
- package/src/utils/account.ts +0 -3
- package/src/utils/browser.ts +0 -24
- package/src/utils/index.ts +0 -3
- package/src/utils/plurar.ts +0 -5
- /package/{src/hooks/index.ts → dist/hooks/index.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const API_URL = "https://dev-api.coinvoyage.io";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/api/config.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,+BAA+B,CAAA;AACtD,iDAAiD"}
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { API_URL } from "./config";
|
|
2
|
-
|
|
3
|
-
type FetchApiOptions = {
|
|
4
|
-
path: string;
|
|
5
|
-
options?: RequestInit;
|
|
6
|
-
throwOnFailure?: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export async function fetchApi<T>(opts: FetchApiOptions): Promise<T | undefined> {
|
|
2
|
+
export async function fetchApi(opts) {
|
|
10
3
|
try {
|
|
11
4
|
const response = await fetch(`${API_URL}/${opts.path}`, {
|
|
12
5
|
...opts.options,
|
|
@@ -18,21 +11,21 @@ export async function fetchApi<T>(opts: FetchApiOptions): Promise<T | undefined>
|
|
|
18
11
|
});
|
|
19
12
|
if (!response.ok) {
|
|
20
13
|
const text = await response.text();
|
|
21
|
-
console.error(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})
|
|
28
|
-
);
|
|
14
|
+
console.error(JSON.stringify({
|
|
15
|
+
path: opts.path,
|
|
16
|
+
status: response.status,
|
|
17
|
+
statusText: response.statusText,
|
|
18
|
+
details: text
|
|
19
|
+
}));
|
|
29
20
|
return;
|
|
30
21
|
}
|
|
31
22
|
return await response.json();
|
|
32
|
-
}
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
33
25
|
console.error(`path: ${opts.path}, message: ${error.message}`);
|
|
34
26
|
if (opts.throwOnFailure) {
|
|
35
27
|
throw error;
|
|
36
28
|
}
|
|
37
29
|
}
|
|
38
30
|
}
|
|
31
|
+
//# sourceMappingURL=fetcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetcher.js","sourceRoot":"","sources":["../../src/api/fetcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAQnC,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAI,IAAqB;IACnD,IAAI,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE;YACpD,GAAG,IAAI,CAAC,OAAO;YACf,OAAO,EAAE;gBACL,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO;gBACxB,cAAc,EAAE,kBAAkB;gBAClC,iBAAiB,EAAE,mBAAmB;aACzC;SACJ,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,OAAO,CAAC,KAAK,CACT,IAAI,CAAC,SAAS,CAAC;gBACX,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,OAAO,EAAE,IAAI;aAChB,CAAC,CACL,CAAC;YACF,OAAO;QACX,CAAC;QACD,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,OAAO,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,cAAc,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC/D,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA"}
|
|
@@ -1,67 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ChainId, ChainType, CurrencyAmount, CurrencyBase, CurrencyWithAmount, CurrencyWithBalance, PayOrder, PayOrderMetadata, PayOrderMode, PayOrderStatus, zDepositPayOrder, zPayOrderMetadata } from "../common/index";
|
|
3
|
-
import { fetchApi } from "./fetcher";
|
|
4
|
-
|
|
1
|
+
import { ChainId, ChainType, CurrencyAmount, CurrencyBase, CurrencyWithAmount, CurrencyWithBalance, PayOrder, PayOrderMetadata, PayOrderStatus } from "../common/index";
|
|
5
2
|
/**
|
|
6
3
|
* Fetches a PayOrder by its ID.
|
|
7
|
-
*
|
|
4
|
+
*
|
|
8
5
|
* Retrieves a PayOrder object from the API using the provided payOrderId.
|
|
9
6
|
* This function requires an API key for authentication.
|
|
10
|
-
*
|
|
7
|
+
*
|
|
11
8
|
* @param {string} payOrderId - The unique identifier of the PayOrder.
|
|
12
9
|
* @param {string} apiKey - The API key required for authentication.
|
|
13
10
|
* @returns {Promise<PayOrder | undefined>} - The PayOrder object if the request is successful.
|
|
14
|
-
*
|
|
11
|
+
*
|
|
15
12
|
* @example
|
|
16
13
|
* const apiKey = 'yourApiKey';
|
|
17
14
|
* const payOrder = await getPayOrder('123456', apiKey);
|
|
18
15
|
*/
|
|
19
|
-
export
|
|
20
|
-
return fetchApi<PayOrder>({
|
|
21
|
-
path: `pay-orders/${payOrderId}`,
|
|
22
|
-
options: {
|
|
23
|
-
headers: {
|
|
24
|
-
"X-API-KEY": apiKey
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
16
|
+
export declare function getPayOrder(payOrderId: string, apiKey: string): Promise<PayOrder | undefined>;
|
|
30
17
|
/** PayOrder parameters. The payOrder is created only after user taps pay. */
|
|
31
18
|
export interface DepositPayOrderParams {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Metadata to attach to the payOrder.
|
|
21
|
+
*/
|
|
22
|
+
metadata?: PayOrderMetadata;
|
|
23
|
+
/**
|
|
24
|
+
* Value in USD received from the Deposit.
|
|
25
|
+
*/
|
|
26
|
+
destination_value_usd?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Desired output token + chain.
|
|
29
|
+
*/
|
|
30
|
+
destination_currency: CurrencyBase;
|
|
31
|
+
/**
|
|
32
|
+
* Output amount to deposit.
|
|
33
|
+
*/
|
|
34
|
+
destination_amount?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Receiving address for the deposit.
|
|
37
|
+
*/
|
|
38
|
+
receiving_address: string;
|
|
52
39
|
}
|
|
53
|
-
|
|
54
40
|
/**
|
|
55
41
|
* Creates a `DEPOSIT` type PayOrder.
|
|
56
|
-
*
|
|
42
|
+
*
|
|
57
43
|
* Generates a PayOrder of type `DEPOSIT` with the provided parameters.
|
|
58
44
|
* This function ensures the request parameters are valid using a schema validation.
|
|
59
|
-
*
|
|
45
|
+
*
|
|
60
46
|
* @param {DepositPayOrderParams} createOrderParams - Parameters required to create a deposit PayOrder.
|
|
61
47
|
* @param {string} apiKey - The API key required for authentication.
|
|
62
48
|
* @param {boolean} [throwOnFailure] - Whether to throw an error if the request fails.
|
|
63
49
|
* @returns {Promise<PayOrder | undefined>} - The PayOrder object if the request is successful.
|
|
64
|
-
*
|
|
50
|
+
*
|
|
65
51
|
* @example
|
|
66
52
|
* const apiKey = 'yourApiKey';
|
|
67
53
|
* const depositOrderParams = {
|
|
@@ -71,76 +57,54 @@ export interface DepositPayOrderParams {
|
|
|
71
57
|
* };
|
|
72
58
|
* const depositPayOrder = await createDepositPayOrder(depositOrderParams, apiKey);
|
|
73
59
|
*/
|
|
74
|
-
export
|
|
75
|
-
const result = zDepositPayOrder.safeParse(createOrderParams);
|
|
76
|
-
if (!result.success) {
|
|
77
|
-
return
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return fetchApi<PayOrder>({
|
|
81
|
-
path: `pay-orders`, options: {
|
|
82
|
-
method: "POST",
|
|
83
|
-
body: JSON.stringify({
|
|
84
|
-
mode: PayOrderMode.DEPOSIT,
|
|
85
|
-
...createOrderParams
|
|
86
|
-
}),
|
|
87
|
-
headers: {
|
|
88
|
-
"X-API-KEY": apiKey
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
throwOnFailure: throwOnFailure
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
|
|
60
|
+
export declare function createDepositPayOrder(createOrderParams: DepositPayOrderParams, apiKey: string, throwOnFailure?: boolean): Promise<PayOrder | undefined>;
|
|
95
61
|
export type SalePayOrderParams = {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Metadata to attach to the payOrder.
|
|
64
|
+
*/
|
|
65
|
+
metadata?: PayOrderMetadata;
|
|
66
|
+
/**
|
|
67
|
+
* Expected value in USD to be received from the Sale.
|
|
68
|
+
*/
|
|
69
|
+
destination_value_usd: number;
|
|
70
|
+
/**
|
|
71
|
+
* Expected token on what chain to receive the value from the Sale.
|
|
72
|
+
*/
|
|
73
|
+
destination_currency?: CurrencyBase;
|
|
74
|
+
/**
|
|
75
|
+
* Expected receiving address to receive the value from the Sale.
|
|
76
|
+
*/
|
|
77
|
+
receiving_address?: string;
|
|
112
78
|
} | {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Metadata to attach to the payOrder.
|
|
81
|
+
*/
|
|
82
|
+
metadata?: PayOrderMetadata;
|
|
83
|
+
/**
|
|
84
|
+
* Expected token on what chain to receive the value from the Sale.
|
|
85
|
+
*/
|
|
86
|
+
destination_currency: CurrencyBase;
|
|
87
|
+
/**
|
|
88
|
+
* Expected amount to be received from the Sale.
|
|
89
|
+
*/
|
|
90
|
+
destination_amount: string;
|
|
91
|
+
/**
|
|
92
|
+
* Expected receiving address to receive the value from the Sale.
|
|
93
|
+
*/
|
|
94
|
+
receiving_address?: string;
|
|
95
|
+
};
|
|
132
96
|
/**
|
|
133
97
|
* Generates a `sale` type PayOrder.
|
|
134
|
-
*
|
|
98
|
+
*
|
|
135
99
|
* Creates a `sale` type PayOrder with a fixed valueOut `destination_value_usd`.
|
|
136
100
|
* This function should be executed
|
|
137
|
-
*
|
|
138
|
-
* and a SHA-512 hash signature of the concatenated API key, secret, and timestamp.
|
|
139
|
-
*
|
|
101
|
+
*
|
|
102
|
+
* and a SHA-512 hash signature of the concatenated API key, secret, and timestamp.
|
|
103
|
+
*
|
|
140
104
|
* @param {SalePayOrderParams} payOrderParams - destination_value_usd and metadata for this payOrder.
|
|
141
105
|
* @param {string} signature - signature generated by the `generateAuthorizationSignature` function.
|
|
142
106
|
* @returns {PayOrder | undefined} - A PayOrder object if the request was successful.
|
|
143
|
-
*
|
|
107
|
+
*
|
|
144
108
|
* @example
|
|
145
109
|
* const apiKey = 'yourApiKey';
|
|
146
110
|
* const apiSecret = 'yourApiSecret';
|
|
@@ -161,49 +125,23 @@ export type SalePayOrderParams = {
|
|
|
161
125
|
* ]
|
|
162
126
|
* }}, authSignature)
|
|
163
127
|
*/
|
|
164
|
-
export
|
|
165
|
-
try {
|
|
166
|
-
if (createOrderParams?.metadata) {
|
|
167
|
-
zPayOrderMetadata.parse(createOrderParams.metadata);
|
|
168
|
-
}
|
|
169
|
-
return fetchApi<PayOrder>({
|
|
170
|
-
path: `pay-orders`, options: {
|
|
171
|
-
method: "POST",
|
|
172
|
-
body: JSON.stringify({
|
|
173
|
-
mode: PayOrderMode.SALE,
|
|
174
|
-
...createOrderParams
|
|
175
|
-
}),
|
|
176
|
-
headers: {
|
|
177
|
-
"Authorization": signature
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
})
|
|
181
|
-
}
|
|
182
|
-
catch (err) {
|
|
183
|
-
if (err instanceof z.ZodError) {
|
|
184
|
-
throw new Error(err.errors.map(e => e.message).join(", "))
|
|
185
|
-
}
|
|
186
|
-
throw err
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
128
|
+
export declare function createSalePayOrder(createOrderParams: SalePayOrderParams, signature: string): Promise<PayOrder | undefined>;
|
|
190
129
|
export type PayOrderQuoteParams = {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
130
|
+
wallet_address: string;
|
|
131
|
+
chain_type: ChainType;
|
|
132
|
+
chain_id?: ChainId;
|
|
133
|
+
};
|
|
196
134
|
/**
|
|
197
135
|
* Generates a PayOrder Quote.
|
|
198
|
-
*
|
|
136
|
+
*
|
|
199
137
|
* Creates a PayOrder Quote for an existing PayOrder by providing wallet information and chain details.
|
|
200
138
|
* This function requires an API key for authentication.
|
|
201
|
-
*
|
|
139
|
+
*
|
|
202
140
|
* @param {string} orderId - The unique identifier of the PayOrder for which the quote is requested.
|
|
203
141
|
* @param {PayOrderQuoteParams} quoteParams - Contains `wallet_address`, `chain_type`, chain_id`.
|
|
204
142
|
* @param {string} apiKey - The API key for authorization.
|
|
205
143
|
* @returns {CurrencyWithBalance[] | undefined} - An array of PayTokens if the request was successful.
|
|
206
|
-
*
|
|
144
|
+
*
|
|
207
145
|
* @example
|
|
208
146
|
* const orderId = 'existingOrderId';
|
|
209
147
|
* const apiKey = 'yourApiKey';
|
|
@@ -212,66 +150,48 @@ export type PayOrderQuoteParams = {
|
|
|
212
150
|
* chain_type: ChainType.EVM,
|
|
213
151
|
* chain_id: 1 // Ethereum Mainnet
|
|
214
152
|
* };
|
|
215
|
-
*
|
|
153
|
+
*
|
|
216
154
|
* const payOrderQuote = await payOrderQuote(orderId, quoteParams, apiKey);
|
|
217
155
|
|
|
218
156
|
*/
|
|
219
|
-
export
|
|
220
|
-
return fetchApi<CurrencyWithBalance[]>({
|
|
221
|
-
path: `pay-orders/${orderId}/quote`, options: {
|
|
222
|
-
method: "POST",
|
|
223
|
-
body: JSON.stringify({
|
|
224
|
-
...quoteParams
|
|
225
|
-
}),
|
|
226
|
-
headers: {
|
|
227
|
-
"X-API-KEY": apiKey
|
|
228
|
-
},
|
|
229
|
-
}
|
|
230
|
-
})
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
157
|
+
export declare function payOrderQuote(orderId: string, quoteParams: PayOrderQuoteParams, apiKey: string): Promise<CurrencyWithBalance[] | undefined>;
|
|
234
158
|
export type PaymentDetailsParams = {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
159
|
+
payOrderId: string;
|
|
160
|
+
outTokenAddress?: string;
|
|
161
|
+
outChainId: ChainId;
|
|
162
|
+
refundAddress: string;
|
|
163
|
+
apiKey: string;
|
|
164
|
+
};
|
|
242
165
|
export type PaymentDetails = {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
destination_amount?: CurrencyAmount
|
|
255
|
-
}
|
|
256
|
-
|
|
166
|
+
payorder_id: string;
|
|
167
|
+
status: PayOrderStatus;
|
|
168
|
+
expires_at: Date;
|
|
169
|
+
refund_address: string;
|
|
170
|
+
deposit_address: string;
|
|
171
|
+
receiving_address?: string;
|
|
172
|
+
source_currency: CurrencyWithAmount;
|
|
173
|
+
source_amount: CurrencyAmount;
|
|
174
|
+
destination_currency?: CurrencyWithAmount;
|
|
175
|
+
destination_amount?: CurrencyAmount;
|
|
176
|
+
};
|
|
257
177
|
/**
|
|
258
178
|
* Retrieves payment details for a specific PayOrder.
|
|
259
|
-
*
|
|
260
|
-
* This function fetches payment details associated with a specific PayOrder ID.
|
|
261
|
-
* It allows specifying the token and blockchain network (via `outTokenAddress` and `outChainId`)
|
|
179
|
+
*
|
|
180
|
+
* This function fetches payment details associated with a specific PayOrder ID.
|
|
181
|
+
* It allows specifying the token and blockchain network (via `outTokenAddress` and `outChainId`)
|
|
262
182
|
* to retrieve source currency information, as well as a refund address for the transaction.
|
|
263
|
-
*
|
|
183
|
+
*
|
|
264
184
|
* The request is authenticated using the provided API key in the headers.
|
|
265
|
-
*
|
|
185
|
+
*
|
|
266
186
|
* @param {PaymentDetailsParams} params - Parameters to retrieve the payment details.
|
|
267
187
|
* @param {string} params.payOrderId - The unique identifier of the PayOrder for which payment details are fetched.
|
|
268
188
|
* @param {string} [params.outTokenAddress] - (Optional) The token address of the source currency.
|
|
269
189
|
* @param {ChainId} params.outChainId - The blockchain network ID where the token resides.
|
|
270
190
|
* @param {string} params.refundAddress - The address where funds will be refunded in case of a failed transaction.
|
|
271
191
|
* @param {string} params.apiKey - The API key used to authenticate the request.
|
|
272
|
-
*
|
|
192
|
+
*
|
|
273
193
|
* @returns {Promise<PaymentDetails | undefined>} - The payment details object if the request is successful.
|
|
274
|
-
*
|
|
194
|
+
*
|
|
275
195
|
* @example
|
|
276
196
|
* const paymentDetails = await payOrderPaymentDetails({
|
|
277
197
|
* payOrderId: '12345',
|
|
@@ -280,70 +200,34 @@ export type PaymentDetails = {
|
|
|
280
200
|
* refundAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
|
|
281
201
|
* apiKey: 'yourApiKey'
|
|
282
202
|
* });
|
|
283
|
-
*
|
|
203
|
+
*
|
|
284
204
|
* console.log(paymentDetails);
|
|
285
205
|
*/
|
|
286
|
-
export
|
|
287
|
-
payOrderId,
|
|
288
|
-
outTokenAddress,
|
|
289
|
-
outChainId,
|
|
290
|
-
refundAddress,
|
|
291
|
-
apiKey
|
|
292
|
-
}: PaymentDetailsParams): Promise<PaymentDetails | undefined> {
|
|
293
|
-
return fetchApi<PaymentDetails>({
|
|
294
|
-
path: `pay-orders/${payOrderId}/payment-details`, options: {
|
|
295
|
-
method: "POST",
|
|
296
|
-
body: JSON.stringify({
|
|
297
|
-
source_currency: {
|
|
298
|
-
address: outTokenAddress,
|
|
299
|
-
chain_id: outChainId
|
|
300
|
-
},
|
|
301
|
-
refund_address: refundAddress
|
|
302
|
-
}),
|
|
303
|
-
headers: {
|
|
304
|
-
"X-API-KEY": apiKey
|
|
305
|
-
},
|
|
306
|
-
}
|
|
307
|
-
})
|
|
308
|
-
}
|
|
309
|
-
|
|
206
|
+
export declare function payOrderPaymentDetails({ payOrderId, outTokenAddress, outChainId, refundAddress, apiKey }: PaymentDetailsParams): Promise<PaymentDetails | undefined>;
|
|
310
207
|
/**
|
|
311
208
|
* Processes a PayOrder transaction.
|
|
312
|
-
*
|
|
313
|
-
* This function triggers the processing of a PayOrder by providing the transaction hash
|
|
209
|
+
*
|
|
210
|
+
* This function triggers the processing of a PayOrder by providing the transaction hash
|
|
314
211
|
* that represents the payment on the blockchain. The request is authenticated using an API key.
|
|
315
|
-
*
|
|
212
|
+
*
|
|
316
213
|
* @param {Object} params - Parameters required to process the PayOrder.
|
|
317
214
|
* @param {string} params.payOrderId - The unique identifier of the PayOrder to be processed.
|
|
318
215
|
* @param {string} params.sourceTransactionHash - The transaction hash representing the payment on the blockchain.
|
|
319
216
|
* @param {string} params.apiKey - The API key used to authenticate the request.
|
|
320
|
-
*
|
|
217
|
+
*
|
|
321
218
|
* @returns {Promise<void>}
|
|
322
|
-
*
|
|
219
|
+
*
|
|
323
220
|
* @example
|
|
324
221
|
* const processedPayment = await processPayOrder({
|
|
325
222
|
* payOrderId: '12345',
|
|
326
223
|
* sourceTransactionHash: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
|
|
327
224
|
* apiKey: 'yourApiKey'
|
|
328
225
|
* });
|
|
329
|
-
*
|
|
226
|
+
*
|
|
330
227
|
* console.log(processedPayment);
|
|
331
228
|
*/
|
|
332
|
-
export
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}:
|
|
337
|
-
payOrderId: string
|
|
338
|
-
sourceTransactionHash: string
|
|
339
|
-
apiKey: string
|
|
340
|
-
}): Promise<void> {
|
|
341
|
-
return fetchApi<void>({
|
|
342
|
-
path: `pay-orders/${payOrderId}/process?tx_hash=${sourceTransactionHash}`, options: {
|
|
343
|
-
method: "GET",
|
|
344
|
-
headers: {
|
|
345
|
-
"X-API-KEY": apiKey
|
|
346
|
-
},
|
|
347
|
-
}
|
|
348
|
-
})
|
|
349
|
-
}
|
|
229
|
+
export declare function processPayOrder({ payOrderId, sourceTransactionHash, apiKey }: {
|
|
230
|
+
payOrderId: string;
|
|
231
|
+
sourceTransactionHash: string;
|
|
232
|
+
apiKey: string;
|
|
233
|
+
}): Promise<void>;
|