@unifold/core 0.1.68-beta.0 → 0.1.68-beta.1
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/index.d.mts +410 -17
- package/dist/index.d.ts +410 -17
- package/dist/index.js +649 -196
- package/dist/index.mjs +626 -196
- package/package.json +11 -2
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __export(index_exports, {
|
|
|
27
27
|
IneligibilityReason: () => IneligibilityReason,
|
|
28
28
|
IntegrationProvider: () => IntegrationProvider,
|
|
29
29
|
SOLANA_USDC_ADDRESS: () => SOLANA_USDC_ADDRESS,
|
|
30
|
+
StripeApiResponseError: () => StripeApiResponseError,
|
|
30
31
|
WithdrawEventType: () => WithdrawEventType,
|
|
31
32
|
authenticateIntegrationOAuth: () => authenticateIntegrationOAuth,
|
|
32
33
|
buildHypercoreTransaction: () => buildHypercoreTransaction,
|
|
@@ -34,20 +35,25 @@ __export(index_exports, {
|
|
|
34
35
|
checkHypercoreActivation: () => checkHypercoreActivation,
|
|
35
36
|
confirmIntegrationTransfer: () => confirmIntegrationTransfer,
|
|
36
37
|
createCashAppSession: () => createCashAppSession,
|
|
38
|
+
createCoinbaseApplePaySession: () => createCoinbaseApplePaySession,
|
|
37
39
|
createDepositAddress: () => createDepositAddress,
|
|
38
40
|
createExchangeSession: () => createExchangeSession,
|
|
39
41
|
createIntegrationTransfer: () => createIntegrationTransfer,
|
|
40
42
|
createOnrampSession: () => createOnrampSession,
|
|
43
|
+
createOnrampVerificationSession: () => createOnrampVerificationSession,
|
|
44
|
+
exchangeOnrampVerificationToken: () => exchangeOnrampVerificationToken,
|
|
41
45
|
formatStablecoinAmount: () => formatStablecoinAmount,
|
|
42
46
|
generateKSUID: () => generateKSUID,
|
|
43
47
|
generatePrefixedKSUID: () => generatePrefixedKSUID,
|
|
44
48
|
getAddressBalance: () => getAddressBalance,
|
|
45
49
|
getAddressBalances: () => getAddressBalances,
|
|
46
50
|
getApiBaseUrl: () => getApiBaseUrl,
|
|
51
|
+
getApplePayProviders: () => getApplePayProviders,
|
|
47
52
|
getBankTransferProviders: () => getBankTransferProviders,
|
|
48
53
|
getCashAppLimits: () => getCashAppLimits,
|
|
49
54
|
getCashAppSessionStatus: () => getCashAppSessionStatus,
|
|
50
55
|
getChainName: () => getChainName,
|
|
56
|
+
getCoinbaseLegalAgreements: () => getCoinbaseLegalAgreements,
|
|
51
57
|
getDefaultOnrampToken: () => getDefaultOnrampToken,
|
|
52
58
|
getDepositAddress: () => getDepositAddress,
|
|
53
59
|
getDepositQuote: () => getDepositQuote,
|
|
@@ -63,6 +69,7 @@ __export(index_exports, {
|
|
|
63
69
|
getIpAddress: () => getIpAddress,
|
|
64
70
|
getOnrampQuotes: () => getOnrampQuotes,
|
|
65
71
|
getOnrampSessionStartUrl: () => getOnrampSessionStartUrl,
|
|
72
|
+
getOnrampVerificationSession: () => getOnrampVerificationSession,
|
|
66
73
|
getPreferredIconUrl: () => getPreferredIconUrl,
|
|
67
74
|
getProjectConfig: () => getProjectConfig,
|
|
68
75
|
getSupportedDepositTokens: () => getSupportedDepositTokens,
|
|
@@ -79,10 +86,26 @@ __export(index_exports, {
|
|
|
79
86
|
retrievePaymentIntent: () => retrievePaymentIntent,
|
|
80
87
|
revokeIntegrationToken: () => revokeIntegrationToken,
|
|
81
88
|
sendHypercoreTransaction: () => sendHypercoreTransaction,
|
|
89
|
+
sendOnrampVerificationOtp: () => sendOnrampVerificationOtp,
|
|
82
90
|
sendSolanaTransaction: () => sendSolanaTransaction,
|
|
83
91
|
setApiConfig: () => setApiConfig,
|
|
84
92
|
startIntegrationOAuth: () => startIntegrationOAuth,
|
|
93
|
+
stripeConfirmSession: () => stripeConfirmSession,
|
|
94
|
+
stripeCreateAuthIntent: () => stripeCreateAuthIntent,
|
|
95
|
+
stripeCreateSession: () => stripeCreateSession,
|
|
96
|
+
stripeExchangeTokens: () => stripeExchangeTokens,
|
|
97
|
+
stripeGetConfig: () => stripeGetConfig,
|
|
98
|
+
stripeGetCustomer: () => stripeGetCustomer,
|
|
99
|
+
stripeGetDefaultToken: () => stripeGetDefaultToken,
|
|
100
|
+
stripeGetQuotes: () => stripeGetQuotes,
|
|
101
|
+
stripeGetSession: () => stripeGetSession,
|
|
102
|
+
stripeGetTransactionLimits: () => stripeGetTransactionLimits,
|
|
103
|
+
stripeListPaymentTokens: () => stripeListPaymentTokens,
|
|
104
|
+
stripeListWallets: () => stripeListWallets,
|
|
105
|
+
stripeRefreshQuote: () => stripeRefreshQuote,
|
|
106
|
+
stripeRefreshToken: () => stripeRefreshToken,
|
|
85
107
|
useUserIp: () => useUserIp,
|
|
108
|
+
verifyOnrampVerificationOtp: () => verifyOnrampVerificationOtp,
|
|
86
109
|
verifyRecipientAddress: () => verifyRecipientAddress
|
|
87
110
|
});
|
|
88
111
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -217,18 +240,15 @@ async function createDepositAddress(overrides, publishableKey) {
|
|
|
217
240
|
async function getDepositAddress(params, publishableKey) {
|
|
218
241
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
219
242
|
validatePublishableKey(pk);
|
|
220
|
-
const response = await fetch(
|
|
221
|
-
|
|
222
|
-
{
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
body: JSON.stringify(params)
|
|
230
|
-
}
|
|
231
|
-
);
|
|
243
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/deposit_addresses/existing`, {
|
|
244
|
+
method: "POST",
|
|
245
|
+
headers: {
|
|
246
|
+
accept: "application/json",
|
|
247
|
+
"x-publishable-key": pk,
|
|
248
|
+
"Content-Type": "application/json"
|
|
249
|
+
},
|
|
250
|
+
body: JSON.stringify(params)
|
|
251
|
+
});
|
|
232
252
|
if (!response.ok) {
|
|
233
253
|
throw new Error(`Failed to get deposit addresses: ${response.statusText}`);
|
|
234
254
|
}
|
|
@@ -254,18 +274,15 @@ async function queryExecutions(externalUserId, publishableKey, actionType = "dep
|
|
|
254
274
|
external_user_id: externalUserId,
|
|
255
275
|
action_type: actionType
|
|
256
276
|
};
|
|
257
|
-
const response = await fetch(
|
|
258
|
-
|
|
259
|
-
{
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
body: JSON.stringify(body)
|
|
267
|
-
}
|
|
268
|
-
);
|
|
277
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/direct_executions/query`, {
|
|
278
|
+
method: "POST",
|
|
279
|
+
headers: {
|
|
280
|
+
accept: "application/json",
|
|
281
|
+
"x-publishable-key": pk,
|
|
282
|
+
"Content-Type": "application/json"
|
|
283
|
+
},
|
|
284
|
+
body: JSON.stringify(body)
|
|
285
|
+
});
|
|
269
286
|
if (!response.ok) {
|
|
270
287
|
throw new Error(`Failed to query executions: ${response.statusText}`);
|
|
271
288
|
}
|
|
@@ -274,18 +291,15 @@ async function queryExecutions(externalUserId, publishableKey, actionType = "dep
|
|
|
274
291
|
async function pollDirectExecutions(request, publishableKey) {
|
|
275
292
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
276
293
|
validatePublishableKey(pk);
|
|
277
|
-
const response = await fetch(
|
|
278
|
-
|
|
279
|
-
{
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
body: JSON.stringify(request)
|
|
287
|
-
}
|
|
288
|
-
);
|
|
294
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/direct_executions/poll`, {
|
|
295
|
+
method: "POST",
|
|
296
|
+
headers: {
|
|
297
|
+
accept: "application/json",
|
|
298
|
+
"x-publishable-key": pk,
|
|
299
|
+
"Content-Type": "application/json"
|
|
300
|
+
},
|
|
301
|
+
body: JSON.stringify(request)
|
|
302
|
+
});
|
|
289
303
|
if (!response.ok) {
|
|
290
304
|
throw new Error(`Failed to poll direct executions: ${response.statusText}`);
|
|
291
305
|
}
|
|
@@ -311,9 +325,7 @@ async function getSupportedDestinationTokens(publishableKey, options) {
|
|
|
311
325
|
}
|
|
312
326
|
});
|
|
313
327
|
if (!response.ok) {
|
|
314
|
-
throw new Error(
|
|
315
|
-
`Failed to fetch supported destination tokens: ${response.statusText}`
|
|
316
|
-
);
|
|
328
|
+
throw new Error(`Failed to fetch supported destination tokens: ${response.statusText}`);
|
|
317
329
|
}
|
|
318
330
|
return response.json();
|
|
319
331
|
}
|
|
@@ -342,9 +354,7 @@ async function getSupportedDepositTokens(publishableKey, options) {
|
|
|
342
354
|
}
|
|
343
355
|
});
|
|
344
356
|
if (!response.ok) {
|
|
345
|
-
throw new Error(
|
|
346
|
-
`Failed to fetch supported deposit tokens: ${response.statusText}`
|
|
347
|
-
);
|
|
357
|
+
throw new Error(`Failed to fetch supported deposit tokens: ${response.statusText}`);
|
|
348
358
|
}
|
|
349
359
|
return response.json();
|
|
350
360
|
}
|
|
@@ -356,16 +366,13 @@ async function getTokenMetadata(request, publishableKey) {
|
|
|
356
366
|
chainId: request.chain_id,
|
|
357
367
|
tokenAddress: request.token_address
|
|
358
368
|
});
|
|
359
|
-
const response = await fetch(
|
|
360
|
-
|
|
361
|
-
{
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
accept: "application/json",
|
|
365
|
-
"x-publishable-key": pk
|
|
366
|
-
}
|
|
369
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/tokens/token?${params.toString()}`, {
|
|
370
|
+
method: "GET",
|
|
371
|
+
headers: {
|
|
372
|
+
accept: "application/json",
|
|
373
|
+
"x-publishable-key": pk
|
|
367
374
|
}
|
|
368
|
-
);
|
|
375
|
+
});
|
|
369
376
|
if (!response.ok) {
|
|
370
377
|
throw new Error(`Failed to fetch token metadata: ${response.statusText}`);
|
|
371
378
|
}
|
|
@@ -384,16 +391,13 @@ function getPreferredIconUrl(iconUrls, preferredFormat = "svg") {
|
|
|
384
391
|
async function getFiatCurrencies(publishableKey) {
|
|
385
392
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
386
393
|
validatePublishableKey(pk);
|
|
387
|
-
const response = await fetch(
|
|
388
|
-
|
|
389
|
-
{
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
accept: "application/json",
|
|
393
|
-
"x-publishable-key": pk
|
|
394
|
-
}
|
|
394
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/onramps/fiat_currencies`, {
|
|
395
|
+
method: "GET",
|
|
396
|
+
headers: {
|
|
397
|
+
accept: "application/json",
|
|
398
|
+
"x-publishable-key": pk
|
|
395
399
|
}
|
|
396
|
-
);
|
|
400
|
+
});
|
|
397
401
|
if (!response.ok) {
|
|
398
402
|
throw new Error(`Failed to fetch fiat currencies: ${response.statusText}`);
|
|
399
403
|
}
|
|
@@ -402,18 +406,15 @@ async function getFiatCurrencies(publishableKey) {
|
|
|
402
406
|
async function getOnrampQuotes(request, publishableKey) {
|
|
403
407
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
404
408
|
validatePublishableKey(pk);
|
|
405
|
-
const response = await fetch(
|
|
406
|
-
|
|
407
|
-
{
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
body: JSON.stringify(request)
|
|
415
|
-
}
|
|
416
|
-
);
|
|
409
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/onramps/quotes`, {
|
|
410
|
+
method: "POST",
|
|
411
|
+
headers: {
|
|
412
|
+
accept: "application/json",
|
|
413
|
+
"x-publishable-key": pk,
|
|
414
|
+
"Content-Type": "application/json"
|
|
415
|
+
},
|
|
416
|
+
body: JSON.stringify(request)
|
|
417
|
+
});
|
|
417
418
|
if (!response.ok) {
|
|
418
419
|
throw new Error(`Failed to fetch onramp quotes: ${response.statusText}`);
|
|
419
420
|
}
|
|
@@ -422,18 +423,15 @@ async function getOnrampQuotes(request, publishableKey) {
|
|
|
422
423
|
async function createOnrampSession(request, publishableKey) {
|
|
423
424
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
424
425
|
validatePublishableKey(pk);
|
|
425
|
-
const response = await fetch(
|
|
426
|
-
|
|
427
|
-
{
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
body: JSON.stringify(request)
|
|
435
|
-
}
|
|
436
|
-
);
|
|
426
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/onramps/sessions`, {
|
|
427
|
+
method: "POST",
|
|
428
|
+
headers: {
|
|
429
|
+
accept: "application/json",
|
|
430
|
+
"x-publishable-key": pk,
|
|
431
|
+
"Content-Type": "application/json"
|
|
432
|
+
},
|
|
433
|
+
body: JSON.stringify(request)
|
|
434
|
+
});
|
|
437
435
|
if (!response.ok) {
|
|
438
436
|
throw new Error(`Failed to create onramp session: ${response.statusText}`);
|
|
439
437
|
}
|
|
@@ -456,9 +454,23 @@ async function getBankTransferProviders(publishableKey, options = {}) {
|
|
|
456
454
|
}
|
|
457
455
|
});
|
|
458
456
|
if (!response.ok) {
|
|
459
|
-
throw new Error(
|
|
460
|
-
|
|
461
|
-
|
|
457
|
+
throw new Error(`Failed to fetch bank-transfer providers: ${response.statusText}`);
|
|
458
|
+
}
|
|
459
|
+
return response.json();
|
|
460
|
+
}
|
|
461
|
+
async function getApplePayProviders(publishableKey) {
|
|
462
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
463
|
+
validatePublishableKey(pk);
|
|
464
|
+
const url = `${API_BASE_URL}/v1/public/onramps/apple_pay/providers`;
|
|
465
|
+
const response = await fetch(url, {
|
|
466
|
+
method: "GET",
|
|
467
|
+
headers: {
|
|
468
|
+
accept: "application/json",
|
|
469
|
+
"x-publishable-key": pk
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
if (!response.ok) {
|
|
473
|
+
throw new Error(`Failed to fetch Apple Pay providers: ${response.statusText}`);
|
|
462
474
|
}
|
|
463
475
|
return response.json();
|
|
464
476
|
}
|
|
@@ -531,10 +543,18 @@ function getChainName(chains, chainType, chainId) {
|
|
|
531
543
|
if (!chainType) return chainId || "Unknown";
|
|
532
544
|
return chainType.charAt(0).toUpperCase() + chainType.slice(1);
|
|
533
545
|
}
|
|
534
|
-
async function getProjectConfig(publishableKey) {
|
|
546
|
+
async function getProjectConfig(publishableKey, options) {
|
|
535
547
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
536
548
|
validatePublishableKey(pk);
|
|
537
|
-
const
|
|
549
|
+
const params = new URLSearchParams();
|
|
550
|
+
if (options?.countryCode) {
|
|
551
|
+
params.set("country_code", options.countryCode);
|
|
552
|
+
}
|
|
553
|
+
if (options?.subdivisionCode) {
|
|
554
|
+
params.set("subdivision_code", options.subdivisionCode);
|
|
555
|
+
}
|
|
556
|
+
const queryString = params.toString();
|
|
557
|
+
const url = `${API_BASE_URL}/v1/public/projects/config${queryString ? `?${queryString}` : ""}`;
|
|
538
558
|
const response = await fetch(url, {
|
|
539
559
|
method: "GET",
|
|
540
560
|
headers: {
|
|
@@ -556,9 +576,7 @@ async function getIpAddress() {
|
|
|
556
576
|
}
|
|
557
577
|
});
|
|
558
578
|
if (!response.ok) {
|
|
559
|
-
throw new Error(
|
|
560
|
-
`Failed to fetch IP address information: ${response.statusText}`
|
|
561
|
-
);
|
|
579
|
+
throw new Error(`Failed to fetch IP address information: ${response.statusText}`);
|
|
562
580
|
}
|
|
563
581
|
return response.json();
|
|
564
582
|
}
|
|
@@ -660,31 +678,24 @@ async function verifyRecipientAddress(request, publishableKey) {
|
|
|
660
678
|
body: JSON.stringify(request)
|
|
661
679
|
});
|
|
662
680
|
if (!response.ok) {
|
|
663
|
-
throw new Error(
|
|
664
|
-
`Failed to verify recipient address: ${response.statusText}`
|
|
665
|
-
);
|
|
681
|
+
throw new Error(`Failed to verify recipient address: ${response.statusText}`);
|
|
666
682
|
}
|
|
667
683
|
return response.json();
|
|
668
684
|
}
|
|
669
685
|
async function checkHypercoreActivation(request, publishableKey) {
|
|
670
686
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
671
687
|
validatePublishableKey(pk);
|
|
672
|
-
const response = await fetch(
|
|
673
|
-
|
|
674
|
-
{
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
body: JSON.stringify(request)
|
|
682
|
-
}
|
|
683
|
-
);
|
|
688
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/addresses/hypercore/activation`, {
|
|
689
|
+
method: "POST",
|
|
690
|
+
headers: {
|
|
691
|
+
accept: "application/json",
|
|
692
|
+
"x-publishable-key": pk,
|
|
693
|
+
"Content-Type": "application/json"
|
|
694
|
+
},
|
|
695
|
+
body: JSON.stringify(request)
|
|
696
|
+
});
|
|
684
697
|
if (!response.ok) {
|
|
685
|
-
throw new Error(
|
|
686
|
-
`HyperCore activation check failed: ${response.statusText}`
|
|
687
|
-
);
|
|
698
|
+
throw new Error(`HyperCore activation check failed: ${response.statusText}`);
|
|
688
699
|
}
|
|
689
700
|
return response.json();
|
|
690
701
|
}
|
|
@@ -692,7 +703,8 @@ async function getExchanges(query, publishableKey) {
|
|
|
692
703
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
693
704
|
validatePublishableKey(pk);
|
|
694
705
|
const params = new URLSearchParams();
|
|
695
|
-
if (query?.destination_currency)
|
|
706
|
+
if (query?.destination_currency)
|
|
707
|
+
params.append("destination_currency", query.destination_currency);
|
|
696
708
|
if (query?.destination_network) params.append("destination_network", query.destination_network);
|
|
697
709
|
const queryString = params.toString();
|
|
698
710
|
const url = `${API_BASE_URL}/v1/public/onramps/exchanges${queryString ? `?${queryString}` : ""}`;
|
|
@@ -712,18 +724,15 @@ async function getExchanges(query, publishableKey) {
|
|
|
712
724
|
async function createExchangeSession(request, publishableKey) {
|
|
713
725
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
714
726
|
validatePublishableKey(pk);
|
|
715
|
-
const response = await fetch(
|
|
716
|
-
|
|
717
|
-
{
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
body: JSON.stringify(request)
|
|
725
|
-
}
|
|
726
|
-
);
|
|
727
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/onramps/exchanges/sessions`, {
|
|
728
|
+
method: "POST",
|
|
729
|
+
headers: {
|
|
730
|
+
accept: "application/json",
|
|
731
|
+
"x-publishable-key": pk,
|
|
732
|
+
"Content-Type": "application/json"
|
|
733
|
+
},
|
|
734
|
+
body: JSON.stringify(request)
|
|
735
|
+
});
|
|
727
736
|
if (!response.ok) {
|
|
728
737
|
throw new Error(`Failed to create exchange session: ${response.statusText}`);
|
|
729
738
|
}
|
|
@@ -876,15 +885,18 @@ async function confirmIntegrationTransfer(transferId, accessToken, mfaCode, publ
|
|
|
876
885
|
validatePublishableKey(pk);
|
|
877
886
|
const body = { access_token: accessToken };
|
|
878
887
|
if (mfaCode) body.mfa_code = mfaCode;
|
|
879
|
-
const response = await fetch(
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
+
const response = await fetch(
|
|
889
|
+
`${API_BASE_URL}/v1/public/integrations/transfers/${transferId}/confirm`,
|
|
890
|
+
{
|
|
891
|
+
method: "POST",
|
|
892
|
+
headers: {
|
|
893
|
+
accept: "application/json",
|
|
894
|
+
"x-publishable-key": pk,
|
|
895
|
+
"Content-Type": "application/json"
|
|
896
|
+
},
|
|
897
|
+
body: JSON.stringify(body)
|
|
898
|
+
}
|
|
899
|
+
);
|
|
888
900
|
if (!response.ok) {
|
|
889
901
|
const err = await response.json().catch(() => ({ message: response.statusText }));
|
|
890
902
|
throw new Error(`Failed to confirm transfer: ${err.message || response.statusText}`);
|
|
@@ -923,9 +935,7 @@ async function buildSolanaTransaction(request, publishableKey) {
|
|
|
923
935
|
});
|
|
924
936
|
if (!response.ok) {
|
|
925
937
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
926
|
-
throw new Error(
|
|
927
|
-
`Failed to build Solana transaction: ${error.message || response.statusText}`
|
|
928
|
-
);
|
|
938
|
+
throw new Error(`Failed to build Solana transaction: ${error.message || response.statusText}`);
|
|
929
939
|
}
|
|
930
940
|
return response.json();
|
|
931
941
|
}
|
|
@@ -943,50 +953,40 @@ async function sendSolanaTransaction(request, publishableKey) {
|
|
|
943
953
|
});
|
|
944
954
|
if (!response.ok) {
|
|
945
955
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
946
|
-
throw new Error(
|
|
947
|
-
`Failed to send Solana transaction: ${error.message || response.statusText}`
|
|
948
|
-
);
|
|
956
|
+
throw new Error(`Failed to send Solana transaction: ${error.message || response.statusText}`);
|
|
949
957
|
}
|
|
950
958
|
return response.json();
|
|
951
959
|
}
|
|
952
960
|
async function retrievePaymentIntent(clientSecret, publishableKey) {
|
|
953
961
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
954
962
|
validatePublishableKey(pk);
|
|
955
|
-
const response = await fetch(
|
|
956
|
-
|
|
957
|
-
{
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
body: JSON.stringify({ client_secret: clientSecret })
|
|
965
|
-
}
|
|
966
|
-
);
|
|
963
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/payment_intents/retrieve`, {
|
|
964
|
+
method: "POST",
|
|
965
|
+
headers: {
|
|
966
|
+
accept: "application/json",
|
|
967
|
+
"x-publishable-key": pk,
|
|
968
|
+
"Content-Type": "application/json"
|
|
969
|
+
},
|
|
970
|
+
body: JSON.stringify({ client_secret: clientSecret })
|
|
971
|
+
});
|
|
967
972
|
if (!response.ok) {
|
|
968
973
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
969
|
-
throw new Error(
|
|
970
|
-
`Failed to retrieve payment intent: ${error.message || response.statusText}`
|
|
971
|
-
);
|
|
974
|
+
throw new Error(`Failed to retrieve payment intent: ${error.message || response.statusText}`);
|
|
972
975
|
}
|
|
973
976
|
return response.json();
|
|
974
977
|
}
|
|
975
978
|
async function listPaymentIntentExecutions(clientSecret, publishableKey) {
|
|
976
979
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
977
980
|
validatePublishableKey(pk);
|
|
978
|
-
const response = await fetch(
|
|
979
|
-
|
|
980
|
-
{
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
body: JSON.stringify({ client_secret: clientSecret })
|
|
988
|
-
}
|
|
989
|
-
);
|
|
981
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/payment_intents/executions`, {
|
|
982
|
+
method: "POST",
|
|
983
|
+
headers: {
|
|
984
|
+
accept: "application/json",
|
|
985
|
+
"x-publishable-key": pk,
|
|
986
|
+
"Content-Type": "application/json"
|
|
987
|
+
},
|
|
988
|
+
body: JSON.stringify({ client_secret: clientSecret })
|
|
989
|
+
});
|
|
990
990
|
if (!response.ok) {
|
|
991
991
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
992
992
|
throw new Error(
|
|
@@ -1009,9 +1009,7 @@ async function getDepositQuote(request, publishableKey) {
|
|
|
1009
1009
|
});
|
|
1010
1010
|
if (!response.ok) {
|
|
1011
1011
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1012
|
-
throw new Error(
|
|
1013
|
-
`Failed to get deposit quote: ${error.message || response.statusText}`
|
|
1014
|
-
);
|
|
1012
|
+
throw new Error(`Failed to get deposit quote: ${error.message || response.statusText}`);
|
|
1015
1013
|
}
|
|
1016
1014
|
const json = await response.json();
|
|
1017
1015
|
return json.data;
|
|
@@ -1019,18 +1017,15 @@ async function getDepositQuote(request, publishableKey) {
|
|
|
1019
1017
|
async function buildHypercoreTransaction(request, publishableKey) {
|
|
1020
1018
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1021
1019
|
validatePublishableKey(pk);
|
|
1022
|
-
const response = await fetch(
|
|
1023
|
-
|
|
1024
|
-
{
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
body: JSON.stringify(request)
|
|
1032
|
-
}
|
|
1033
|
-
);
|
|
1020
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/transactions/hypercore/build`, {
|
|
1021
|
+
method: "POST",
|
|
1022
|
+
headers: {
|
|
1023
|
+
accept: "application/json",
|
|
1024
|
+
"x-publishable-key": pk,
|
|
1025
|
+
"Content-Type": "application/json"
|
|
1026
|
+
},
|
|
1027
|
+
body: JSON.stringify(request)
|
|
1028
|
+
});
|
|
1034
1029
|
if (!response.ok) {
|
|
1035
1030
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1036
1031
|
throw new Error(
|
|
@@ -1054,40 +1049,60 @@ async function getCashAppLimits(currency = "usd", publishableKey) {
|
|
|
1054
1049
|
);
|
|
1055
1050
|
if (!response.ok) {
|
|
1056
1051
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1057
|
-
throw new Error(
|
|
1058
|
-
`Failed to get Cash App limits: ${error.message || response.statusText}`
|
|
1059
|
-
);
|
|
1052
|
+
throw new Error(`Failed to get Cash App limits: ${error.message || response.statusText}`);
|
|
1060
1053
|
}
|
|
1061
1054
|
return response.json();
|
|
1062
1055
|
}
|
|
1063
1056
|
async function createCashAppSession(request, publishableKey) {
|
|
1057
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1058
|
+
validatePublishableKey(pk);
|
|
1059
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/onramps/cashapp/sessions`, {
|
|
1060
|
+
method: "POST",
|
|
1061
|
+
headers: {
|
|
1062
|
+
accept: "application/json",
|
|
1063
|
+
"x-publishable-key": pk,
|
|
1064
|
+
"Content-Type": "application/json"
|
|
1065
|
+
},
|
|
1066
|
+
body: JSON.stringify(request)
|
|
1067
|
+
});
|
|
1068
|
+
if (!response.ok) {
|
|
1069
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1070
|
+
throw new Error(`Failed to create Cash App session: ${error.message || response.statusText}`);
|
|
1071
|
+
}
|
|
1072
|
+
return response.json();
|
|
1073
|
+
}
|
|
1074
|
+
async function getCashAppSessionStatus(externalId, publishableKey) {
|
|
1064
1075
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1065
1076
|
validatePublishableKey(pk);
|
|
1066
1077
|
const response = await fetch(
|
|
1067
|
-
`${API_BASE_URL}/v1/public/onramps/cashapp/sessions`,
|
|
1078
|
+
`${API_BASE_URL}/v1/public/onramps/cashapp/sessions/${encodeURIComponent(externalId)}/status`,
|
|
1068
1079
|
{
|
|
1069
|
-
method: "
|
|
1080
|
+
method: "GET",
|
|
1070
1081
|
headers: {
|
|
1071
1082
|
accept: "application/json",
|
|
1072
|
-
"x-publishable-key": pk
|
|
1073
|
-
|
|
1074
|
-
},
|
|
1075
|
-
body: JSON.stringify(request)
|
|
1083
|
+
"x-publishable-key": pk
|
|
1084
|
+
}
|
|
1076
1085
|
}
|
|
1077
1086
|
);
|
|
1078
1087
|
if (!response.ok) {
|
|
1079
1088
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1080
1089
|
throw new Error(
|
|
1081
|
-
`Failed to
|
|
1090
|
+
`Failed to get Cash App session status: ${error.message || response.statusText}`
|
|
1082
1091
|
);
|
|
1083
1092
|
}
|
|
1084
1093
|
return response.json();
|
|
1085
1094
|
}
|
|
1086
|
-
async function
|
|
1095
|
+
async function stripeGetDefaultToken(params, publishableKey) {
|
|
1087
1096
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1088
1097
|
validatePublishableKey(pk);
|
|
1098
|
+
const query = new URLSearchParams({
|
|
1099
|
+
token_address: params.tokenAddress,
|
|
1100
|
+
chain_id: params.chainId,
|
|
1101
|
+
chain_type: params.chainType
|
|
1102
|
+
});
|
|
1103
|
+
if (params.countryCode) query.append("country_code", params.countryCode);
|
|
1089
1104
|
const response = await fetch(
|
|
1090
|
-
`${API_BASE_URL}/
|
|
1105
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/default_token?${query.toString()}`,
|
|
1091
1106
|
{
|
|
1092
1107
|
method: "GET",
|
|
1093
1108
|
headers: {
|
|
@@ -1096,29 +1111,317 @@ async function getCashAppSessionStatus(externalId, publishableKey) {
|
|
|
1096
1111
|
}
|
|
1097
1112
|
}
|
|
1098
1113
|
);
|
|
1114
|
+
if (!response.ok) {
|
|
1115
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1116
|
+
throwStripeError("Failed to get Stripe default token", response, error);
|
|
1117
|
+
}
|
|
1118
|
+
return response.json();
|
|
1119
|
+
}
|
|
1120
|
+
var HEADLESS_STRIPE_BASE = "/v1/public/onramps/headless/stripe";
|
|
1121
|
+
var StripeApiResponseError = class extends Error {
|
|
1122
|
+
constructor(message, statusCode, stripeCode, errorType) {
|
|
1123
|
+
super(message);
|
|
1124
|
+
this.statusCode = statusCode;
|
|
1125
|
+
this.stripeCode = stripeCode;
|
|
1126
|
+
this.errorType = errorType;
|
|
1127
|
+
this.name = "StripeApiResponseError";
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
function throwStripeError(prefix, response, error) {
|
|
1131
|
+
const stripeError = error.details?.stripe_error;
|
|
1132
|
+
const detailMessage = stripeError?.message || error.message || response.statusText;
|
|
1133
|
+
throw new StripeApiResponseError(
|
|
1134
|
+
`${prefix}: ${detailMessage}`,
|
|
1135
|
+
response.status,
|
|
1136
|
+
stripeError?.code,
|
|
1137
|
+
error.error_type
|
|
1138
|
+
);
|
|
1139
|
+
}
|
|
1140
|
+
async function stripeGetConfig(publishableKey) {
|
|
1141
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1142
|
+
validatePublishableKey(pk);
|
|
1143
|
+
const response = await fetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/config`, {
|
|
1144
|
+
method: "GET",
|
|
1145
|
+
headers: {
|
|
1146
|
+
accept: "application/json",
|
|
1147
|
+
"x-publishable-key": pk
|
|
1148
|
+
}
|
|
1149
|
+
});
|
|
1150
|
+
if (!response.ok) {
|
|
1151
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1152
|
+
throwStripeError("Failed to get Stripe config", response, error);
|
|
1153
|
+
}
|
|
1154
|
+
return response.json();
|
|
1155
|
+
}
|
|
1156
|
+
async function stripeCreateAuthIntent(email, publishableKey) {
|
|
1157
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1158
|
+
validatePublishableKey(pk);
|
|
1159
|
+
const response = await fetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/oauth/start`, {
|
|
1160
|
+
method: "POST",
|
|
1161
|
+
headers: {
|
|
1162
|
+
accept: "application/json",
|
|
1163
|
+
"x-publishable-key": pk,
|
|
1164
|
+
"Content-Type": "application/json"
|
|
1165
|
+
},
|
|
1166
|
+
body: JSON.stringify({ email })
|
|
1167
|
+
});
|
|
1168
|
+
if (!response.ok) {
|
|
1169
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1170
|
+
throwStripeError("Failed to create Stripe auth intent", response, error);
|
|
1171
|
+
}
|
|
1172
|
+
return response.json();
|
|
1173
|
+
}
|
|
1174
|
+
async function stripeExchangeTokens(authIntentId, publishableKey) {
|
|
1175
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1176
|
+
validatePublishableKey(pk);
|
|
1177
|
+
const response = await fetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/oauth/token`, {
|
|
1178
|
+
method: "POST",
|
|
1179
|
+
headers: {
|
|
1180
|
+
accept: "application/json",
|
|
1181
|
+
"x-publishable-key": pk,
|
|
1182
|
+
"Content-Type": "application/json"
|
|
1183
|
+
},
|
|
1184
|
+
body: JSON.stringify({ auth_intent_id: authIntentId })
|
|
1185
|
+
});
|
|
1186
|
+
if (!response.ok) {
|
|
1187
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1188
|
+
throwStripeError("Failed to exchange Stripe tokens", response, error);
|
|
1189
|
+
}
|
|
1190
|
+
return response.json();
|
|
1191
|
+
}
|
|
1192
|
+
async function stripeRefreshToken(refreshToken, publishableKey) {
|
|
1193
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1194
|
+
validatePublishableKey(pk);
|
|
1195
|
+
const response = await fetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/oauth/token/refresh`, {
|
|
1196
|
+
method: "POST",
|
|
1197
|
+
headers: {
|
|
1198
|
+
accept: "application/json",
|
|
1199
|
+
"x-publishable-key": pk,
|
|
1200
|
+
"Content-Type": "application/json"
|
|
1201
|
+
},
|
|
1202
|
+
body: JSON.stringify({ refresh_token: refreshToken })
|
|
1203
|
+
});
|
|
1204
|
+
if (!response.ok) {
|
|
1205
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1206
|
+
throwStripeError("Failed to refresh Stripe token", response, error);
|
|
1207
|
+
}
|
|
1208
|
+
return response.json();
|
|
1209
|
+
}
|
|
1210
|
+
async function stripeGetCustomer(customerId, oauthToken, publishableKey) {
|
|
1211
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1212
|
+
validatePublishableKey(pk);
|
|
1213
|
+
const response = await fetch(
|
|
1214
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/customers/${encodeURIComponent(customerId)}`,
|
|
1215
|
+
{
|
|
1216
|
+
method: "GET",
|
|
1217
|
+
headers: {
|
|
1218
|
+
accept: "application/json",
|
|
1219
|
+
"x-publishable-key": pk,
|
|
1220
|
+
"x-stripe-oauth-token": oauthToken
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
);
|
|
1224
|
+
if (!response.ok) {
|
|
1225
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1226
|
+
throwStripeError("Failed to get Stripe customer", response, error);
|
|
1227
|
+
}
|
|
1228
|
+
return response.json();
|
|
1229
|
+
}
|
|
1230
|
+
async function stripeListWallets(customerId, oauthToken, publishableKey) {
|
|
1231
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1232
|
+
validatePublishableKey(pk);
|
|
1233
|
+
const response = await fetch(
|
|
1234
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/customers/${encodeURIComponent(customerId)}/wallet_addresses`,
|
|
1235
|
+
{
|
|
1236
|
+
method: "GET",
|
|
1237
|
+
headers: {
|
|
1238
|
+
accept: "application/json",
|
|
1239
|
+
"x-publishable-key": pk,
|
|
1240
|
+
"x-stripe-oauth-token": oauthToken
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
);
|
|
1244
|
+
if (!response.ok) {
|
|
1245
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1246
|
+
throwStripeError("Failed to list Stripe wallets", response, error);
|
|
1247
|
+
}
|
|
1248
|
+
return response.json();
|
|
1249
|
+
}
|
|
1250
|
+
async function stripeListPaymentTokens(customerId, oauthToken, publishableKey) {
|
|
1251
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1252
|
+
validatePublishableKey(pk);
|
|
1253
|
+
const response = await fetch(
|
|
1254
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/customers/${encodeURIComponent(customerId)}/payment_tokens`,
|
|
1255
|
+
{
|
|
1256
|
+
method: "GET",
|
|
1257
|
+
headers: {
|
|
1258
|
+
accept: "application/json",
|
|
1259
|
+
"x-publishable-key": pk,
|
|
1260
|
+
"x-stripe-oauth-token": oauthToken
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
);
|
|
1099
1264
|
if (!response.ok) {
|
|
1100
1265
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1101
1266
|
throw new Error(
|
|
1102
|
-
`Failed to
|
|
1267
|
+
`Failed to list Stripe payment tokens: ${error.message || response.statusText}`
|
|
1103
1268
|
);
|
|
1104
1269
|
}
|
|
1105
1270
|
return response.json();
|
|
1106
1271
|
}
|
|
1107
|
-
async function
|
|
1272
|
+
async function stripeCreateSession(request, oauthToken, publishableKey) {
|
|
1273
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1274
|
+
validatePublishableKey(pk);
|
|
1275
|
+
const response = await fetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/sessions`, {
|
|
1276
|
+
method: "POST",
|
|
1277
|
+
headers: {
|
|
1278
|
+
accept: "application/json",
|
|
1279
|
+
"x-publishable-key": pk,
|
|
1280
|
+
"x-stripe-oauth-token": oauthToken,
|
|
1281
|
+
"Content-Type": "application/json"
|
|
1282
|
+
},
|
|
1283
|
+
body: JSON.stringify({
|
|
1284
|
+
crypto_customer_id: request.cryptoCustomerId,
|
|
1285
|
+
payment_token: request.paymentToken,
|
|
1286
|
+
source_amount: request.sourceAmount,
|
|
1287
|
+
source_currency: request.sourceCurrency,
|
|
1288
|
+
destination_currency: request.destinationCurrency,
|
|
1289
|
+
destination_network: request.destinationNetwork,
|
|
1290
|
+
wallet_address: request.walletAddress
|
|
1291
|
+
})
|
|
1292
|
+
});
|
|
1293
|
+
if (!response.ok) {
|
|
1294
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1295
|
+
throwStripeError("Failed to create Stripe session", response, error);
|
|
1296
|
+
}
|
|
1297
|
+
return response.json();
|
|
1298
|
+
}
|
|
1299
|
+
async function stripeConfirmSession(sessionId, oauthToken, request, publishableKey) {
|
|
1108
1300
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1109
1301
|
validatePublishableKey(pk);
|
|
1110
1302
|
const response = await fetch(
|
|
1111
|
-
`${API_BASE_URL}/
|
|
1303
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/sessions/${encodeURIComponent(sessionId)}/confirm`,
|
|
1112
1304
|
{
|
|
1113
1305
|
method: "POST",
|
|
1114
1306
|
headers: {
|
|
1115
1307
|
accept: "application/json",
|
|
1116
1308
|
"x-publishable-key": pk,
|
|
1309
|
+
"x-stripe-oauth-token": oauthToken,
|
|
1117
1310
|
"Content-Type": "application/json"
|
|
1118
1311
|
},
|
|
1119
|
-
body: JSON.stringify(request)
|
|
1312
|
+
body: JSON.stringify(request?.mandateData ? { mandate_data: request.mandateData } : {})
|
|
1313
|
+
}
|
|
1314
|
+
);
|
|
1315
|
+
if (!response.ok) {
|
|
1316
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1317
|
+
throwStripeError("Failed to confirm Stripe session", response, error);
|
|
1318
|
+
}
|
|
1319
|
+
return response.json();
|
|
1320
|
+
}
|
|
1321
|
+
async function stripeRefreshQuote(sessionId, oauthToken, publishableKey) {
|
|
1322
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1323
|
+
validatePublishableKey(pk);
|
|
1324
|
+
const response = await fetch(
|
|
1325
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/sessions/${encodeURIComponent(sessionId)}/quote/refresh`,
|
|
1326
|
+
{
|
|
1327
|
+
method: "POST",
|
|
1328
|
+
headers: {
|
|
1329
|
+
accept: "application/json",
|
|
1330
|
+
"x-publishable-key": pk,
|
|
1331
|
+
"x-stripe-oauth-token": oauthToken
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
);
|
|
1335
|
+
if (!response.ok) {
|
|
1336
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1337
|
+
throwStripeError("Failed to refresh Stripe quote", response, error);
|
|
1338
|
+
}
|
|
1339
|
+
return response.json();
|
|
1340
|
+
}
|
|
1341
|
+
async function stripeGetSession(sessionId, oauthToken, publishableKey) {
|
|
1342
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1343
|
+
validatePublishableKey(pk);
|
|
1344
|
+
const response = await fetch(
|
|
1345
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/sessions/${encodeURIComponent(sessionId)}`,
|
|
1346
|
+
{
|
|
1347
|
+
method: "GET",
|
|
1348
|
+
headers: {
|
|
1349
|
+
accept: "application/json",
|
|
1350
|
+
"x-publishable-key": pk,
|
|
1351
|
+
"x-stripe-oauth-token": oauthToken
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
);
|
|
1355
|
+
if (!response.ok) {
|
|
1356
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1357
|
+
throwStripeError("Failed to get Stripe session", response, error);
|
|
1358
|
+
}
|
|
1359
|
+
return response.json();
|
|
1360
|
+
}
|
|
1361
|
+
async function stripeGetQuotes(request, oauthToken, publishableKey) {
|
|
1362
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1363
|
+
validatePublishableKey(pk);
|
|
1364
|
+
const headers = {
|
|
1365
|
+
accept: "application/json",
|
|
1366
|
+
"x-publishable-key": pk,
|
|
1367
|
+
"Content-Type": "application/json"
|
|
1368
|
+
};
|
|
1369
|
+
if (oauthToken) headers["x-stripe-oauth-token"] = oauthToken;
|
|
1370
|
+
const response = await fetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/quotes`, {
|
|
1371
|
+
method: "POST",
|
|
1372
|
+
headers,
|
|
1373
|
+
body: JSON.stringify({
|
|
1374
|
+
source_amount: request.sourceAmount,
|
|
1375
|
+
source_currency: request.sourceCurrency,
|
|
1376
|
+
destination_currency: request.destinationCurrency,
|
|
1377
|
+
destination_network: request.destinationNetwork
|
|
1378
|
+
})
|
|
1379
|
+
});
|
|
1380
|
+
if (!response.ok) {
|
|
1381
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1382
|
+
throwStripeError("Failed to get Stripe quotes", response, error);
|
|
1383
|
+
}
|
|
1384
|
+
return response.json();
|
|
1385
|
+
}
|
|
1386
|
+
async function stripeGetTransactionLimits(params, oauthToken, publishableKey) {
|
|
1387
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1388
|
+
validatePublishableKey(pk);
|
|
1389
|
+
const query = new URLSearchParams({
|
|
1390
|
+
crypto_customer_id: params.cryptoCustomerId,
|
|
1391
|
+
destination_network: params.destinationNetwork,
|
|
1392
|
+
wallet_address: params.walletAddress
|
|
1393
|
+
});
|
|
1394
|
+
if (params.destinationTag) query.append("destination_tag", params.destinationTag);
|
|
1395
|
+
if (params.refresh) query.append("refresh", "true");
|
|
1396
|
+
const response = await fetch(
|
|
1397
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/transaction_limits?${query.toString()}`,
|
|
1398
|
+
{
|
|
1399
|
+
method: "GET",
|
|
1400
|
+
headers: {
|
|
1401
|
+
accept: "application/json",
|
|
1402
|
+
"x-publishable-key": pk,
|
|
1403
|
+
"x-stripe-oauth-token": oauthToken
|
|
1404
|
+
}
|
|
1120
1405
|
}
|
|
1121
1406
|
);
|
|
1407
|
+
if (!response.ok) {
|
|
1408
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1409
|
+
throwStripeError("Failed to get Stripe transaction limits", response, error);
|
|
1410
|
+
}
|
|
1411
|
+
return response.json();
|
|
1412
|
+
}
|
|
1413
|
+
async function sendHypercoreTransaction(request, publishableKey) {
|
|
1414
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1415
|
+
validatePublishableKey(pk);
|
|
1416
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/transactions/hypercore/send`, {
|
|
1417
|
+
method: "POST",
|
|
1418
|
+
headers: {
|
|
1419
|
+
accept: "application/json",
|
|
1420
|
+
"x-publishable-key": pk,
|
|
1421
|
+
"Content-Type": "application/json"
|
|
1422
|
+
},
|
|
1423
|
+
body: JSON.stringify(request)
|
|
1424
|
+
});
|
|
1122
1425
|
if (!response.ok) {
|
|
1123
1426
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1124
1427
|
throw new Error(
|
|
@@ -1127,6 +1430,133 @@ async function sendHypercoreTransaction(request, publishableKey) {
|
|
|
1127
1430
|
}
|
|
1128
1431
|
return response.json();
|
|
1129
1432
|
}
|
|
1433
|
+
async function getCoinbaseLegalAgreements(publishableKey) {
|
|
1434
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1435
|
+
validatePublishableKey(pk);
|
|
1436
|
+
const response = await fetch(
|
|
1437
|
+
`${API_BASE_URL}/v1/public/onramps/headless/coinbase/legal_agreements`,
|
|
1438
|
+
{
|
|
1439
|
+
method: "GET",
|
|
1440
|
+
headers: { accept: "application/json", "x-publishable-key": pk }
|
|
1441
|
+
}
|
|
1442
|
+
);
|
|
1443
|
+
if (!response.ok) {
|
|
1444
|
+
throw new Error(`Failed to fetch Coinbase legal agreements: ${response.statusText}`);
|
|
1445
|
+
}
|
|
1446
|
+
return response.json();
|
|
1447
|
+
}
|
|
1448
|
+
var VERIFICATION_BASE = "/v1/public/onramps/verification_sessions";
|
|
1449
|
+
async function jsonOrThrow(response, label) {
|
|
1450
|
+
if (!response.ok) {
|
|
1451
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1452
|
+
const body = error;
|
|
1453
|
+
const tag = body.error_type ? ` [${body.error_type}]` : "";
|
|
1454
|
+
throw new Error(`${label}${tag}: ${body.message || response.statusText}`);
|
|
1455
|
+
}
|
|
1456
|
+
return response.json();
|
|
1457
|
+
}
|
|
1458
|
+
async function createOnrampVerificationSession(request, publishableKey) {
|
|
1459
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1460
|
+
validatePublishableKey(pk);
|
|
1461
|
+
const response = await fetch(`${API_BASE_URL}${VERIFICATION_BASE}`, {
|
|
1462
|
+
method: "POST",
|
|
1463
|
+
headers: {
|
|
1464
|
+
accept: "application/json",
|
|
1465
|
+
"x-publishable-key": pk,
|
|
1466
|
+
"Content-Type": "application/json"
|
|
1467
|
+
},
|
|
1468
|
+
body: JSON.stringify(request)
|
|
1469
|
+
});
|
|
1470
|
+
return jsonOrThrow(response, "Failed to create verification session");
|
|
1471
|
+
}
|
|
1472
|
+
async function postVerificationAction(id, factor, action, body, publishableKey) {
|
|
1473
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1474
|
+
validatePublishableKey(pk);
|
|
1475
|
+
const response = await fetch(
|
|
1476
|
+
`${API_BASE_URL}${VERIFICATION_BASE}/${encodeURIComponent(id)}/${factor}/${action}`,
|
|
1477
|
+
{
|
|
1478
|
+
method: "POST",
|
|
1479
|
+
headers: {
|
|
1480
|
+
accept: "application/json",
|
|
1481
|
+
"x-publishable-key": pk,
|
|
1482
|
+
"Content-Type": "application/json"
|
|
1483
|
+
},
|
|
1484
|
+
body: JSON.stringify(body)
|
|
1485
|
+
}
|
|
1486
|
+
);
|
|
1487
|
+
return jsonOrThrow(response, `Failed to ${action} ${factor} OTP`);
|
|
1488
|
+
}
|
|
1489
|
+
async function sendOnrampVerificationOtp(id, factor, clientSecret, publishableKey) {
|
|
1490
|
+
return postVerificationAction(
|
|
1491
|
+
id,
|
|
1492
|
+
factor,
|
|
1493
|
+
"send",
|
|
1494
|
+
{ client_secret: clientSecret },
|
|
1495
|
+
publishableKey
|
|
1496
|
+
);
|
|
1497
|
+
}
|
|
1498
|
+
async function verifyOnrampVerificationOtp(id, factor, clientSecret, code, publishableKey) {
|
|
1499
|
+
return postVerificationAction(
|
|
1500
|
+
id,
|
|
1501
|
+
factor,
|
|
1502
|
+
"verify",
|
|
1503
|
+
{ client_secret: clientSecret, code },
|
|
1504
|
+
publishableKey
|
|
1505
|
+
);
|
|
1506
|
+
}
|
|
1507
|
+
async function exchangeOnrampVerificationToken(id, clientSecret, publishableKey) {
|
|
1508
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1509
|
+
validatePublishableKey(pk);
|
|
1510
|
+
const response = await fetch(
|
|
1511
|
+
`${API_BASE_URL}${VERIFICATION_BASE}/${encodeURIComponent(id)}/token`,
|
|
1512
|
+
{
|
|
1513
|
+
method: "POST",
|
|
1514
|
+
headers: {
|
|
1515
|
+
accept: "application/json",
|
|
1516
|
+
"x-publishable-key": pk,
|
|
1517
|
+
"Content-Type": "application/json"
|
|
1518
|
+
},
|
|
1519
|
+
body: JSON.stringify({ client_secret: clientSecret })
|
|
1520
|
+
}
|
|
1521
|
+
);
|
|
1522
|
+
return jsonOrThrow(
|
|
1523
|
+
response,
|
|
1524
|
+
"Failed to exchange verification token"
|
|
1525
|
+
);
|
|
1526
|
+
}
|
|
1527
|
+
async function getOnrampVerificationSession(id, clientSecret, publishableKey) {
|
|
1528
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1529
|
+
validatePublishableKey(pk);
|
|
1530
|
+
const url = new URL(`${API_BASE_URL}${VERIFICATION_BASE}/${encodeURIComponent(id)}`);
|
|
1531
|
+
url.searchParams.set("client_secret", clientSecret);
|
|
1532
|
+
const response = await fetch(url.toString(), {
|
|
1533
|
+
method: "GET",
|
|
1534
|
+
headers: { accept: "application/json", "x-publishable-key": pk }
|
|
1535
|
+
});
|
|
1536
|
+
return jsonOrThrow(response, "Failed to fetch verification session");
|
|
1537
|
+
}
|
|
1538
|
+
async function createCoinbaseApplePaySession(request, onrampToken, publishableKey, signal) {
|
|
1539
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1540
|
+
validatePublishableKey(pk);
|
|
1541
|
+
const response = await fetch(
|
|
1542
|
+
`${API_BASE_URL}/v1/public/onramps/headless/coinbase/apple_pay/sessions`,
|
|
1543
|
+
{
|
|
1544
|
+
method: "POST",
|
|
1545
|
+
headers: {
|
|
1546
|
+
accept: "application/json",
|
|
1547
|
+
"x-publishable-key": pk,
|
|
1548
|
+
"Content-Type": "application/json",
|
|
1549
|
+
"x-onramp-token": onrampToken
|
|
1550
|
+
},
|
|
1551
|
+
body: JSON.stringify(request),
|
|
1552
|
+
signal
|
|
1553
|
+
}
|
|
1554
|
+
);
|
|
1555
|
+
return jsonOrThrow(
|
|
1556
|
+
response,
|
|
1557
|
+
"Failed to create Apple Pay session"
|
|
1558
|
+
);
|
|
1559
|
+
}
|
|
1130
1560
|
|
|
1131
1561
|
// src/lib/events.ts
|
|
1132
1562
|
var DepositEventType = /* @__PURE__ */ ((DepositEventType2) => {
|
|
@@ -1283,6 +1713,7 @@ var i18n = en_default;
|
|
|
1283
1713
|
IneligibilityReason,
|
|
1284
1714
|
IntegrationProvider,
|
|
1285
1715
|
SOLANA_USDC_ADDRESS,
|
|
1716
|
+
StripeApiResponseError,
|
|
1286
1717
|
WithdrawEventType,
|
|
1287
1718
|
authenticateIntegrationOAuth,
|
|
1288
1719
|
buildHypercoreTransaction,
|
|
@@ -1290,20 +1721,25 @@ var i18n = en_default;
|
|
|
1290
1721
|
checkHypercoreActivation,
|
|
1291
1722
|
confirmIntegrationTransfer,
|
|
1292
1723
|
createCashAppSession,
|
|
1724
|
+
createCoinbaseApplePaySession,
|
|
1293
1725
|
createDepositAddress,
|
|
1294
1726
|
createExchangeSession,
|
|
1295
1727
|
createIntegrationTransfer,
|
|
1296
1728
|
createOnrampSession,
|
|
1729
|
+
createOnrampVerificationSession,
|
|
1730
|
+
exchangeOnrampVerificationToken,
|
|
1297
1731
|
formatStablecoinAmount,
|
|
1298
1732
|
generateKSUID,
|
|
1299
1733
|
generatePrefixedKSUID,
|
|
1300
1734
|
getAddressBalance,
|
|
1301
1735
|
getAddressBalances,
|
|
1302
1736
|
getApiBaseUrl,
|
|
1737
|
+
getApplePayProviders,
|
|
1303
1738
|
getBankTransferProviders,
|
|
1304
1739
|
getCashAppLimits,
|
|
1305
1740
|
getCashAppSessionStatus,
|
|
1306
1741
|
getChainName,
|
|
1742
|
+
getCoinbaseLegalAgreements,
|
|
1307
1743
|
getDefaultOnrampToken,
|
|
1308
1744
|
getDepositAddress,
|
|
1309
1745
|
getDepositQuote,
|
|
@@ -1319,6 +1755,7 @@ var i18n = en_default;
|
|
|
1319
1755
|
getIpAddress,
|
|
1320
1756
|
getOnrampQuotes,
|
|
1321
1757
|
getOnrampSessionStartUrl,
|
|
1758
|
+
getOnrampVerificationSession,
|
|
1322
1759
|
getPreferredIconUrl,
|
|
1323
1760
|
getProjectConfig,
|
|
1324
1761
|
getSupportedDepositTokens,
|
|
@@ -1335,9 +1772,25 @@ var i18n = en_default;
|
|
|
1335
1772
|
retrievePaymentIntent,
|
|
1336
1773
|
revokeIntegrationToken,
|
|
1337
1774
|
sendHypercoreTransaction,
|
|
1775
|
+
sendOnrampVerificationOtp,
|
|
1338
1776
|
sendSolanaTransaction,
|
|
1339
1777
|
setApiConfig,
|
|
1340
1778
|
startIntegrationOAuth,
|
|
1779
|
+
stripeConfirmSession,
|
|
1780
|
+
stripeCreateAuthIntent,
|
|
1781
|
+
stripeCreateSession,
|
|
1782
|
+
stripeExchangeTokens,
|
|
1783
|
+
stripeGetConfig,
|
|
1784
|
+
stripeGetCustomer,
|
|
1785
|
+
stripeGetDefaultToken,
|
|
1786
|
+
stripeGetQuotes,
|
|
1787
|
+
stripeGetSession,
|
|
1788
|
+
stripeGetTransactionLimits,
|
|
1789
|
+
stripeListPaymentTokens,
|
|
1790
|
+
stripeListWallets,
|
|
1791
|
+
stripeRefreshQuote,
|
|
1792
|
+
stripeRefreshToken,
|
|
1341
1793
|
useUserIp,
|
|
1794
|
+
verifyOnrampVerificationOtp,
|
|
1342
1795
|
verifyRecipientAddress
|
|
1343
1796
|
});
|