@ton-pay/api 0.2.0-beta.1 → 0.2.0
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/README.md +10 -10
- package/dist/index.d.mts +17 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.js +27 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,28 +22,28 @@ import {
|
|
|
22
22
|
verifySignature,
|
|
23
23
|
TON,
|
|
24
24
|
USDT,
|
|
25
|
-
} from
|
|
25
|
+
} from '@ton-pay/api';
|
|
26
26
|
|
|
27
27
|
// Create a TON Pay transfer
|
|
28
28
|
const transfer = await createTonPayTransfer(
|
|
29
29
|
{
|
|
30
30
|
amount: 10.5,
|
|
31
31
|
asset: TON,
|
|
32
|
-
recipientAddr:
|
|
33
|
-
senderAddr:
|
|
34
|
-
commentToSender:
|
|
35
|
-
commentToRecipient:
|
|
32
|
+
recipientAddr: 'EQC...', // Optional if API key is provided
|
|
33
|
+
senderAddr: 'EQC...',
|
|
34
|
+
commentToSender: 'Payment for order #123',
|
|
35
|
+
commentToRecipient: 'Thank you!',
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
|
-
chain:
|
|
39
|
-
apiKey:
|
|
40
|
-
}
|
|
38
|
+
chain: 'mainnet',
|
|
39
|
+
apiKey: 'your-api-key',
|
|
40
|
+
},
|
|
41
41
|
);
|
|
42
42
|
|
|
43
43
|
// Get transfer status by reference
|
|
44
44
|
const transferInfo = await getTonPayTransferByReference(transfer.reference, {
|
|
45
|
-
chain:
|
|
46
|
-
apiKey:
|
|
45
|
+
chain: 'mainnet',
|
|
46
|
+
apiKey: 'your-api-key',
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
// Verify webhook signature
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type Chain =
|
|
1
|
+
type Chain = 'mainnet' | 'testnet';
|
|
2
2
|
|
|
3
3
|
type APIOptions = {
|
|
4
4
|
chain?: Chain;
|
|
@@ -152,6 +152,18 @@ type CheckMoonpayLimitsResponse = MoonpayAmountLimits;
|
|
|
152
152
|
*/
|
|
153
153
|
declare const checkMoonpayLimits: (params: CheckMoonpayLimitsParams, options?: APIOptions) => Promise<CheckMoonpayLimitsResponse>;
|
|
154
154
|
|
|
155
|
+
type CheckMoonpayAvailabilityParams = {
|
|
156
|
+
asset: string;
|
|
157
|
+
ipAddress?: string;
|
|
158
|
+
};
|
|
159
|
+
type CheckMoonpayAvailabilityResponse = {
|
|
160
|
+
geo: MoonpayGeoResult;
|
|
161
|
+
limits: MoonpayAmountLimits;
|
|
162
|
+
currencyCode: string;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
declare const checkMoonpayAvailability: (params: CheckMoonpayAvailabilityParams, options?: APIOptions) => Promise<CheckMoonpayAvailabilityResponse>;
|
|
166
|
+
|
|
155
167
|
/**
|
|
156
168
|
* @param amount - the amount of the transfer in human readable format
|
|
157
169
|
* @param rawAmount - the amount of the transfer in base units
|
|
@@ -226,7 +238,7 @@ type GetTonPayTransferByReferenceParams = {
|
|
|
226
238
|
* - `transfer.completed` - Transfer completed (check `data.status` for success/failed)
|
|
227
239
|
* - `transfer.refunded` - Transfer was refunded (Coming Soon)
|
|
228
240
|
*/
|
|
229
|
-
type WebhookEventType =
|
|
241
|
+
type WebhookEventType = 'transfer.completed' | 'transfer.refunded';
|
|
230
242
|
|
|
231
243
|
/**
|
|
232
244
|
* Base webhook payload structure
|
|
@@ -243,7 +255,7 @@ interface BaseWebhookPayload {
|
|
|
243
255
|
* Check `data.status` field to determine if transfer was "success" or "failed".
|
|
244
256
|
*/
|
|
245
257
|
interface TransferCompletedWebhookPayload extends BaseWebhookPayload {
|
|
246
|
-
event:
|
|
258
|
+
event: 'transfer.completed';
|
|
247
259
|
data: CompletedTonPayTransferInfo;
|
|
248
260
|
}
|
|
249
261
|
/**
|
|
@@ -253,7 +265,7 @@ interface TransferCompletedWebhookPayload extends BaseWebhookPayload {
|
|
|
253
265
|
* Coming Soon - Sent when a transfer is refunded
|
|
254
266
|
*/
|
|
255
267
|
interface TransferRefundedWebhookPayload extends BaseWebhookPayload {
|
|
256
|
-
event:
|
|
268
|
+
event: 'transfer.refunded';
|
|
257
269
|
data: unknown;
|
|
258
270
|
}
|
|
259
271
|
/**
|
|
@@ -305,4 +317,4 @@ declare const TON = "TON";
|
|
|
305
317
|
*/
|
|
306
318
|
declare function verifySignature(payload: string | object, signature: string, apiSecret: string): boolean;
|
|
307
319
|
|
|
308
|
-
export { type APIOptions, type Chain, type CheckMoonpayGeoParams, type CheckMoonpayGeoResponse, type CheckMoonpayLimitsParams, type CheckMoonpayLimitsResponse, type CompletedTonPayTransferInfo, type CreateMoonpayTransferParams, type CreateMoonpayTransferResponse, type CreateTonPayTransferParams, type CreateTonPayTransferResponse, type GetTonPayTransferByBodyHashParams, type GetTonPayTransferByReferenceParams, type MoonpayAmountLimits, type MoonpayGeoResult, TON, type TransferCompletedWebhookPayload, type TransferRefundedWebhookPayload, USDT, type WebhookEventType, type WebhookPayload, checkMoonpayGeo, checkMoonpayLimits, createMoonpayTransfer, createTonPayTransfer, getTonPayTransferByBodyHash, getTonPayTransferByReference, verifySignature };
|
|
320
|
+
export { type APIOptions, type Chain, type CheckMoonpayAvailabilityParams, type CheckMoonpayAvailabilityResponse, type CheckMoonpayGeoParams, type CheckMoonpayGeoResponse, type CheckMoonpayLimitsParams, type CheckMoonpayLimitsResponse, type CompletedTonPayTransferInfo, type CreateMoonpayTransferParams, type CreateMoonpayTransferResponse, type CreateTonPayTransferParams, type CreateTonPayTransferResponse, type GetTonPayTransferByBodyHashParams, type GetTonPayTransferByReferenceParams, type MoonpayAmountLimits, type MoonpayGeoResult, TON, type TransferCompletedWebhookPayload, type TransferRefundedWebhookPayload, USDT, type WebhookEventType, type WebhookPayload, checkMoonpayAvailability, checkMoonpayGeo, checkMoonpayLimits, createMoonpayTransfer, createTonPayTransfer, getTonPayTransferByBodyHash, getTonPayTransferByReference, verifySignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type Chain =
|
|
1
|
+
type Chain = 'mainnet' | 'testnet';
|
|
2
2
|
|
|
3
3
|
type APIOptions = {
|
|
4
4
|
chain?: Chain;
|
|
@@ -152,6 +152,18 @@ type CheckMoonpayLimitsResponse = MoonpayAmountLimits;
|
|
|
152
152
|
*/
|
|
153
153
|
declare const checkMoonpayLimits: (params: CheckMoonpayLimitsParams, options?: APIOptions) => Promise<CheckMoonpayLimitsResponse>;
|
|
154
154
|
|
|
155
|
+
type CheckMoonpayAvailabilityParams = {
|
|
156
|
+
asset: string;
|
|
157
|
+
ipAddress?: string;
|
|
158
|
+
};
|
|
159
|
+
type CheckMoonpayAvailabilityResponse = {
|
|
160
|
+
geo: MoonpayGeoResult;
|
|
161
|
+
limits: MoonpayAmountLimits;
|
|
162
|
+
currencyCode: string;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
declare const checkMoonpayAvailability: (params: CheckMoonpayAvailabilityParams, options?: APIOptions) => Promise<CheckMoonpayAvailabilityResponse>;
|
|
166
|
+
|
|
155
167
|
/**
|
|
156
168
|
* @param amount - the amount of the transfer in human readable format
|
|
157
169
|
* @param rawAmount - the amount of the transfer in base units
|
|
@@ -226,7 +238,7 @@ type GetTonPayTransferByReferenceParams = {
|
|
|
226
238
|
* - `transfer.completed` - Transfer completed (check `data.status` for success/failed)
|
|
227
239
|
* - `transfer.refunded` - Transfer was refunded (Coming Soon)
|
|
228
240
|
*/
|
|
229
|
-
type WebhookEventType =
|
|
241
|
+
type WebhookEventType = 'transfer.completed' | 'transfer.refunded';
|
|
230
242
|
|
|
231
243
|
/**
|
|
232
244
|
* Base webhook payload structure
|
|
@@ -243,7 +255,7 @@ interface BaseWebhookPayload {
|
|
|
243
255
|
* Check `data.status` field to determine if transfer was "success" or "failed".
|
|
244
256
|
*/
|
|
245
257
|
interface TransferCompletedWebhookPayload extends BaseWebhookPayload {
|
|
246
|
-
event:
|
|
258
|
+
event: 'transfer.completed';
|
|
247
259
|
data: CompletedTonPayTransferInfo;
|
|
248
260
|
}
|
|
249
261
|
/**
|
|
@@ -253,7 +265,7 @@ interface TransferCompletedWebhookPayload extends BaseWebhookPayload {
|
|
|
253
265
|
* Coming Soon - Sent when a transfer is refunded
|
|
254
266
|
*/
|
|
255
267
|
interface TransferRefundedWebhookPayload extends BaseWebhookPayload {
|
|
256
|
-
event:
|
|
268
|
+
event: 'transfer.refunded';
|
|
257
269
|
data: unknown;
|
|
258
270
|
}
|
|
259
271
|
/**
|
|
@@ -305,4 +317,4 @@ declare const TON = "TON";
|
|
|
305
317
|
*/
|
|
306
318
|
declare function verifySignature(payload: string | object, signature: string, apiSecret: string): boolean;
|
|
307
319
|
|
|
308
|
-
export { type APIOptions, type Chain, type CheckMoonpayGeoParams, type CheckMoonpayGeoResponse, type CheckMoonpayLimitsParams, type CheckMoonpayLimitsResponse, type CompletedTonPayTransferInfo, type CreateMoonpayTransferParams, type CreateMoonpayTransferResponse, type CreateTonPayTransferParams, type CreateTonPayTransferResponse, type GetTonPayTransferByBodyHashParams, type GetTonPayTransferByReferenceParams, type MoonpayAmountLimits, type MoonpayGeoResult, TON, type TransferCompletedWebhookPayload, type TransferRefundedWebhookPayload, USDT, type WebhookEventType, type WebhookPayload, checkMoonpayGeo, checkMoonpayLimits, createMoonpayTransfer, createTonPayTransfer, getTonPayTransferByBodyHash, getTonPayTransferByReference, verifySignature };
|
|
320
|
+
export { type APIOptions, type Chain, type CheckMoonpayAvailabilityParams, type CheckMoonpayAvailabilityResponse, type CheckMoonpayGeoParams, type CheckMoonpayGeoResponse, type CheckMoonpayLimitsParams, type CheckMoonpayLimitsResponse, type CompletedTonPayTransferInfo, type CreateMoonpayTransferParams, type CreateMoonpayTransferResponse, type CreateTonPayTransferParams, type CreateTonPayTransferResponse, type GetTonPayTransferByBodyHashParams, type GetTonPayTransferByReferenceParams, type MoonpayAmountLimits, type MoonpayGeoResult, TON, type TransferCompletedWebhookPayload, type TransferRefundedWebhookPayload, USDT, type WebhookEventType, type WebhookPayload, checkMoonpayAvailability, checkMoonpayGeo, checkMoonpayLimits, createMoonpayTransfer, createTonPayTransfer, getTonPayTransferByBodyHash, getTonPayTransferByReference, verifySignature };
|
package/dist/index.js
CHANGED
|
@@ -6625,8 +6625,8 @@ var require_crypto_js = __commonJS({
|
|
|
6625
6625
|
});
|
|
6626
6626
|
|
|
6627
6627
|
// src/common/const.ts
|
|
6628
|
-
var BASE_URL = "https://
|
|
6629
|
-
var TESTNET_BASE_URL = "https://testnet.
|
|
6628
|
+
var BASE_URL = "https://pay.ton.org";
|
|
6629
|
+
var TESTNET_BASE_URL = "https://testnet.pay.ton.org";
|
|
6630
6630
|
|
|
6631
6631
|
// src/common/get-base-url.ts
|
|
6632
6632
|
var getBaseUrl = (chain) => {
|
|
@@ -6734,9 +6734,30 @@ var checkMoonpayLimits = async (params, options) => {
|
|
|
6734
6734
|
return response.json();
|
|
6735
6735
|
};
|
|
6736
6736
|
|
|
6737
|
+
// src/check-moonpay-availability/check-moonpay-availability.ts
|
|
6738
|
+
var checkMoonpayAvailability = async (params, options) => {
|
|
6739
|
+
const baseUrl = getBaseUrl(_optionalChain([options, 'optionalAccess', _8 => _8.chain]));
|
|
6740
|
+
const headers = {
|
|
6741
|
+
"Content-Type": "application/json",
|
|
6742
|
+
..._optionalChain([options, 'optionalAccess', _9 => _9.apiKey]) ? { "x-api-key": options.apiKey } : {}
|
|
6743
|
+
};
|
|
6744
|
+
const response = await fetch(`${baseUrl}/api/external/moonpay/check`, {
|
|
6745
|
+
method: "POST",
|
|
6746
|
+
body: JSON.stringify(params),
|
|
6747
|
+
headers
|
|
6748
|
+
});
|
|
6749
|
+
if (!response.ok) {
|
|
6750
|
+
const errorText = await response.text();
|
|
6751
|
+
throw new Error(`Failed to check MoonPay availability: ${errorText}`, {
|
|
6752
|
+
cause: response.statusText
|
|
6753
|
+
});
|
|
6754
|
+
}
|
|
6755
|
+
return response.json();
|
|
6756
|
+
};
|
|
6757
|
+
|
|
6737
6758
|
// src/get-ton-pay-transfer/get-ton-pay-transfer-by-body-hash.ts
|
|
6738
6759
|
var getTonPayTransferByBodyHash = async (bodyHash, options) => {
|
|
6739
|
-
const baseUrl = getBaseUrl(_optionalChain([options, 'optionalAccess',
|
|
6760
|
+
const baseUrl = getBaseUrl(_optionalChain([options, 'optionalAccess', _10 => _10.chain]));
|
|
6740
6761
|
const response = await fetch(
|
|
6741
6762
|
`${baseUrl}/api/merchant/v1/transfer?bodyHash=${bodyHash}`,
|
|
6742
6763
|
{
|
|
@@ -6753,7 +6774,7 @@ var getTonPayTransferByBodyHash = async (bodyHash, options) => {
|
|
|
6753
6774
|
|
|
6754
6775
|
// src/get-ton-pay-transfer/get-ton-pay-transfer-by-reference.ts
|
|
6755
6776
|
var getTonPayTransferByReference = async (reference, options) => {
|
|
6756
|
-
const baseUrl = getBaseUrl(_optionalChain([options, 'optionalAccess',
|
|
6777
|
+
const baseUrl = getBaseUrl(_optionalChain([options, 'optionalAccess', _11 => _11.chain]));
|
|
6757
6778
|
const response = await fetch(
|
|
6758
6779
|
`${baseUrl}/api/merchant/v1/transfer?reference=${reference}`,
|
|
6759
6780
|
{
|
|
@@ -6790,7 +6811,8 @@ function verifySignature(payload, signature, apiSecret) {
|
|
|
6790
6811
|
|
|
6791
6812
|
|
|
6792
6813
|
|
|
6793
|
-
|
|
6814
|
+
|
|
6815
|
+
exports.TON = TON; exports.USDT = USDT; exports.checkMoonpayAvailability = checkMoonpayAvailability; exports.checkMoonpayGeo = checkMoonpayGeo; exports.checkMoonpayLimits = checkMoonpayLimits; exports.createMoonpayTransfer = createMoonpayTransfer; exports.createTonPayTransfer = createTonPayTransfer; exports.getTonPayTransferByBodyHash = getTonPayTransferByBodyHash; exports.getTonPayTransferByReference = getTonPayTransferByReference; exports.verifySignature = verifySignature;
|
|
6794
6816
|
/*! Bundled license information:
|
|
6795
6817
|
|
|
6796
6818
|
crypto-js/ripemd160.js:
|