@metamask-previews/ramps-controller 29.0.0-preview-7410208d2 → 29.0.0-preview-e53b41ba2
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/CHANGELOG.md +0 -11
- package/dist/RampsController-method-action-types.d.ts +0 -12
- package/dist/RampsController-method-action-types.d.ts.map +1 -1
- package/dist/RampsController-method-action-types.js.map +1 -1
- package/dist/RampsController.d.ts +1 -23
- package/dist/RampsController.d.ts.map +1 -1
- package/dist/RampsController.js +7 -100
- package/dist/RampsController.js.map +1 -1
- package/dist/TransakService.d.ts +5 -18
- package/dist/TransakService.d.ts.map +1 -1
- package/dist/TransakService.js +114 -293
- package/dist/TransakService.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/rampsErrorCodes.d.ts +0 -1
- package/dist/rampsErrorCodes.d.ts.map +1 -1
- package/dist/rampsErrorCodes.js +0 -1
- package/dist/rampsErrorCodes.js.map +1 -1
- package/package.json +3 -4
package/dist/TransakService.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HttpError } from '@metamask/controller-utils';
|
|
3
|
-
import { any, array, boolean, nullable, number, optional, record, string, type as looseObject, } from '@metamask/superstruct';
|
|
1
|
+
import { createServicePolicy, HttpError } from '@metamask/controller-utils';
|
|
4
2
|
import packageJson from '../package.json';
|
|
5
3
|
import { addRampsClientIdentityParams } from './client-identity.js';
|
|
6
4
|
import { RAMPS_SDK_VERSION } from './RampsService.js';
|
|
@@ -161,131 +159,13 @@ export class TransakApiError extends HttpError {
|
|
|
161
159
|
this.apiMessage = apiMessage;
|
|
162
160
|
}
|
|
163
161
|
}
|
|
164
|
-
// === RESPONSE STRUCTS ===
|
|
165
|
-
/**
|
|
166
|
-
* The structs below are intentionally lenient: they require only the fields
|
|
167
|
-
* the service itself depends on, check the type of any other field that is
|
|
168
|
-
* present, and ignore extra fields the APIs return. The APIs omit fields for
|
|
169
|
-
* incomplete profiles and sparse responses, and responses were not validated
|
|
170
|
-
* before, so a missing field must not fail a call.
|
|
171
|
-
*/
|
|
172
|
-
const TransakPaymentDetailsStruct = array(looseObject({
|
|
173
|
-
fiatCurrency: string(),
|
|
174
|
-
paymentMethod: string(),
|
|
175
|
-
fields: array(looseObject({ name: string(), id: string(), value: string() })),
|
|
176
|
-
}));
|
|
177
|
-
const SendUserOtpResponseStruct = looseObject({
|
|
178
|
-
isTncAccepted: boolean(),
|
|
179
|
-
stateToken: string(),
|
|
180
|
-
email: string(),
|
|
181
|
-
expiresIn: number(),
|
|
182
|
-
});
|
|
183
|
-
const VerifyUserOtpResponseStruct = looseObject({
|
|
184
|
-
accessToken: string(),
|
|
185
|
-
ttl: number(),
|
|
186
|
-
created: string(),
|
|
187
|
-
});
|
|
188
|
-
const UserDetailsStruct = looseObject({
|
|
189
|
-
id: optional(string()),
|
|
190
|
-
firstName: optional(string()),
|
|
191
|
-
lastName: optional(string()),
|
|
192
|
-
email: optional(string()),
|
|
193
|
-
mobileNumber: optional(string()),
|
|
194
|
-
status: optional(string()),
|
|
195
|
-
dob: optional(string()),
|
|
196
|
-
kyc: optional(looseObject({
|
|
197
|
-
status: optional(string()),
|
|
198
|
-
type: optional(string()),
|
|
199
|
-
userId: optional(string()),
|
|
200
|
-
workFlowRunId: optional(string()),
|
|
201
|
-
})),
|
|
202
|
-
address: optional(looseObject({
|
|
203
|
-
addressLine1: optional(string()),
|
|
204
|
-
addressLine2: optional(string()),
|
|
205
|
-
state: optional(string()),
|
|
206
|
-
city: optional(string()),
|
|
207
|
-
postCode: optional(string()),
|
|
208
|
-
country: optional(string()),
|
|
209
|
-
countryCode: optional(string()),
|
|
210
|
-
})),
|
|
211
|
-
createdAt: optional(string()),
|
|
212
|
-
});
|
|
213
|
-
const BuyQuoteStruct = looseObject({
|
|
214
|
-
quoteId: string(),
|
|
215
|
-
conversionPrice: optional(number()),
|
|
216
|
-
marketConversionPrice: optional(number()),
|
|
217
|
-
slippage: optional(number()),
|
|
218
|
-
fiatCurrency: optional(string()),
|
|
219
|
-
cryptoCurrency: optional(string()),
|
|
220
|
-
paymentMethod: optional(string()),
|
|
221
|
-
fiatAmount: optional(number()),
|
|
222
|
-
cryptoAmount: optional(number()),
|
|
223
|
-
isBuyOrSell: optional(string()),
|
|
224
|
-
network: optional(string()),
|
|
225
|
-
feeDecimal: optional(number()),
|
|
226
|
-
totalFee: optional(number()),
|
|
227
|
-
feeBreakdown: optional(array(record(string(), any()))),
|
|
228
|
-
nonce: optional(number()),
|
|
229
|
-
cryptoLiquidityProvider: optional(string()),
|
|
230
|
-
notes: optional(array(record(string(), any()))),
|
|
231
|
-
});
|
|
232
|
-
const KycRequirementStruct = looseObject({
|
|
233
|
-
status: string(),
|
|
234
|
-
kycType: string(),
|
|
235
|
-
isAllowedToPlaceOrder: boolean(),
|
|
236
|
-
});
|
|
237
|
-
const AdditionalRequirementsStruct = looseObject({
|
|
238
|
-
formsRequired: array(looseObject({ type: string(), metadata: optional(any()) })),
|
|
239
|
-
});
|
|
240
|
-
const TransakOrderStruct = looseObject({
|
|
241
|
-
orderId: string(),
|
|
242
|
-
walletAddress: string(),
|
|
243
|
-
paymentDetails: optional(nullable(TransakPaymentDetailsStruct)),
|
|
244
|
-
});
|
|
245
|
-
const TransakOrderPaymentDetailsStruct = looseObject({
|
|
246
|
-
paymentDetails: optional(nullable(TransakPaymentDetailsStruct)),
|
|
247
|
-
});
|
|
248
|
-
const ActiveOrdersStruct = array(looseObject({ orderId: string(), status: string() }));
|
|
249
|
-
const DepositOrderStruct = looseObject({
|
|
250
|
-
providerOrderId: string(),
|
|
251
|
-
status: string(),
|
|
252
|
-
});
|
|
253
|
-
const UserLimitsStruct = looseObject({
|
|
254
|
-
limits: looseObject({ '1': number(), '30': number(), '365': number() }),
|
|
255
|
-
spent: looseObject({ '1': number(), '30': number(), '365': number() }),
|
|
256
|
-
remaining: looseObject({ '1': number(), '30': number(), '365': number() }),
|
|
257
|
-
exceeded: looseObject({ '1': boolean(), '30': boolean(), '365': boolean() }),
|
|
258
|
-
shortage: optional(record(string(), number())),
|
|
259
|
-
});
|
|
260
|
-
const OttStruct = looseObject({ ott: string() });
|
|
261
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
262
|
-
const TranslationStruct = looseObject({
|
|
263
|
-
region: optional(string()),
|
|
264
|
-
paymentMethod: optional(string()),
|
|
265
|
-
cryptoCurrency: string(),
|
|
266
|
-
network: string(),
|
|
267
|
-
fiatCurrency: string(),
|
|
268
|
-
});
|
|
269
|
-
const IdProofStatusStruct = looseObject({
|
|
270
|
-
status: string(),
|
|
271
|
-
kycType: string(),
|
|
272
|
-
randomLogIdentifier: optional(string()),
|
|
273
|
-
});
|
|
274
|
-
const PaymentConfirmationStruct = looseObject({ success: boolean() });
|
|
275
|
-
const WidgetUrlResponseStruct = looseObject({ widgetUrl: string() });
|
|
276
|
-
/**
|
|
277
|
-
* Wraps a struct in the `{ data }` envelope the Transak API gateway uses.
|
|
278
|
-
*
|
|
279
|
-
* @param dataStruct - The struct for the `data` property.
|
|
280
|
-
* @returns The envelope struct.
|
|
281
|
-
*/
|
|
282
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
283
|
-
function envelope(dataStruct) {
|
|
284
|
-
return looseObject({ data: dataStruct });
|
|
285
|
-
}
|
|
286
162
|
// === SERVICE DEFINITION ===
|
|
287
|
-
export class TransakService
|
|
163
|
+
export class TransakService {
|
|
164
|
+
name;
|
|
165
|
+
#messenger;
|
|
288
166
|
#fetch;
|
|
167
|
+
#policy;
|
|
168
|
+
#noRetryPolicy;
|
|
289
169
|
#environment;
|
|
290
170
|
#context;
|
|
291
171
|
#orderRetryDelayMs;
|
|
@@ -304,9 +184,15 @@ export class TransakService extends BaseDataService {
|
|
|
304
184
|
*/
|
|
305
185
|
#referrerDomain;
|
|
306
186
|
#clientIdentity;
|
|
307
|
-
constructor({ messenger, environment = TransakEnvironment.Staging, context, fetch: fetchFunction, apiKey, policyOptions, orderRetryDelayMs = 2000, rampsApiBaseUrlOverride, referrerDomain = TRANSAK_REFERRER_DOMAIN, clientProduct, clientVersion, }) {
|
|
308
|
-
|
|
187
|
+
constructor({ messenger, environment = TransakEnvironment.Staging, context, fetch: fetchFunction, apiKey, policyOptions = {}, orderRetryDelayMs = 2000, rampsApiBaseUrlOverride, referrerDomain = TRANSAK_REFERRER_DOMAIN, clientProduct, clientVersion, }) {
|
|
188
|
+
this.name = serviceName;
|
|
189
|
+
this.#messenger = messenger;
|
|
309
190
|
this.#fetch = fetchFunction;
|
|
191
|
+
this.#policy = createServicePolicy(policyOptions);
|
|
192
|
+
this.#noRetryPolicy = createServicePolicy({
|
|
193
|
+
...policyOptions,
|
|
194
|
+
maxRetries: 0,
|
|
195
|
+
});
|
|
310
196
|
this.#environment = environment;
|
|
311
197
|
this.#context = context;
|
|
312
198
|
this.#apiKey = apiKey ?? null;
|
|
@@ -317,7 +203,7 @@ export class TransakService extends BaseDataService {
|
|
|
317
203
|
clientProduct,
|
|
318
204
|
clientVersion,
|
|
319
205
|
};
|
|
320
|
-
this
|
|
206
|
+
this.#messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
321
207
|
}
|
|
322
208
|
setApiKey(apiKey) {
|
|
323
209
|
this.#apiKey = apiKey;
|
|
@@ -384,21 +270,7 @@ export class TransakService extends BaseDataService {
|
|
|
384
270
|
}
|
|
385
271
|
throw new TransakApiError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'${errorBody ? `: ${errorBody}` : ''}`, errorCode, apiMessage);
|
|
386
272
|
}
|
|
387
|
-
|
|
388
|
-
* Identifies the current login session without exposing the access token,
|
|
389
|
-
* so reads made under different sessions never share a request.
|
|
390
|
-
*
|
|
391
|
-
* @returns The access token creation time in milliseconds, or `null` when
|
|
392
|
-
* logged out.
|
|
393
|
-
*/
|
|
394
|
-
#getSessionId() {
|
|
395
|
-
return this.#accessToken
|
|
396
|
-
? new Date(this.#accessToken.created).getTime()
|
|
397
|
-
: null;
|
|
398
|
-
}
|
|
399
|
-
async #transakGet(queryName, path,
|
|
400
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
401
|
-
dataStruct, params) {
|
|
273
|
+
async #transakGet(path, params) {
|
|
402
274
|
const baseUrl = getTransakApiBaseUrl(this.#environment);
|
|
403
275
|
const url = new URL(path, baseUrl);
|
|
404
276
|
if (params) {
|
|
@@ -410,98 +282,59 @@ export class TransakService extends BaseDataService {
|
|
|
410
282
|
}
|
|
411
283
|
const apiKey = this.#ensureApiKey();
|
|
412
284
|
url.searchParams.set('apiKey', apiKey);
|
|
413
|
-
const response =
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
gcTime: 0,
|
|
424
|
-
responseStruct: envelope(dataStruct),
|
|
425
|
-
queryFn: async () => {
|
|
426
|
-
const fetchResponse = await this.#fetch(url.toString(), {
|
|
427
|
-
method: 'GET',
|
|
428
|
-
headers: this.#getHeaders(),
|
|
429
|
-
});
|
|
430
|
-
if (!fetchResponse.ok) {
|
|
431
|
-
await this.#throwTransakApiError(fetchResponse, url);
|
|
432
|
-
}
|
|
433
|
-
return (await fetchResponse.json());
|
|
434
|
-
},
|
|
435
|
-
}));
|
|
285
|
+
const response = await this.#policy.execute(async () => {
|
|
286
|
+
const fetchResponse = await this.#fetch(url.toString(), {
|
|
287
|
+
method: 'GET',
|
|
288
|
+
headers: this.#getHeaders(),
|
|
289
|
+
});
|
|
290
|
+
if (!fetchResponse.ok) {
|
|
291
|
+
await this.#throwTransakApiError(fetchResponse, url);
|
|
292
|
+
}
|
|
293
|
+
return fetchResponse.json();
|
|
294
|
+
});
|
|
436
295
|
return response.data;
|
|
437
296
|
}
|
|
438
|
-
|
|
439
|
-
* Sends a request that changes server side data. Mutations are never
|
|
440
|
-
* retried, and the mutation key holds only the method name, as keys appear
|
|
441
|
-
* in the names of published `cacheUpdated` events.
|
|
442
|
-
*
|
|
443
|
-
* @param options - The options.
|
|
444
|
-
* @param options.mutationName - The name of the public method.
|
|
445
|
-
* @param options.url - The request URL.
|
|
446
|
-
* @param options.init - The request method, headers and body.
|
|
447
|
-
* @param options.responseStruct - The struct for the response body. When
|
|
448
|
-
* omitted, the response body is ignored.
|
|
449
|
-
* @returns The validated response body, or `null` if it was ignored.
|
|
450
|
-
*/
|
|
451
|
-
async #sendMutation({ mutationName, url, init, responseStruct, }) {
|
|
452
|
-
return (await this.executeMutation({
|
|
453
|
-
mutationKey: [`${this.name}:${mutationName}`],
|
|
454
|
-
// Some responses carry credentials (`verifyUserOtp` returns the access
|
|
455
|
-
// token), so do not keep finished mutations in the cache.
|
|
456
|
-
gcTime: 0,
|
|
457
|
-
responseStruct,
|
|
458
|
-
mutationFn: async () => {
|
|
459
|
-
const fetchResponse = await this.#fetch(url.toString(), init);
|
|
460
|
-
if (!fetchResponse.ok) {
|
|
461
|
-
await this.#throwTransakApiError(fetchResponse, url);
|
|
462
|
-
}
|
|
463
|
-
return responseStruct ? (await fetchResponse.json()) : null;
|
|
464
|
-
},
|
|
465
|
-
}));
|
|
466
|
-
}
|
|
467
|
-
async #transakPost(mutationName, path,
|
|
468
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
469
|
-
dataStruct, body) {
|
|
297
|
+
async #transakPost(path, body, options = {}) {
|
|
470
298
|
const apiKey = this.#ensureApiKey();
|
|
471
299
|
const baseUrl = getTransakApiBaseUrl(this.#environment);
|
|
472
300
|
const url = new URL(path, baseUrl);
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
301
|
+
const requestBody = {
|
|
302
|
+
...(body ?? {}),
|
|
303
|
+
apiKey,
|
|
304
|
+
};
|
|
305
|
+
const policy = options.policy ?? this.#policy;
|
|
306
|
+
const response = await policy.execute(async () => {
|
|
307
|
+
const fetchResponse = await this.#fetch(url.toString(), {
|
|
477
308
|
method: 'POST',
|
|
478
309
|
headers: this.#getHeaders(),
|
|
479
|
-
body: JSON.stringify(
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
|
|
310
|
+
body: JSON.stringify(requestBody),
|
|
311
|
+
});
|
|
312
|
+
if (!fetchResponse.ok) {
|
|
313
|
+
await this.#throwTransakApiError(fetchResponse, url);
|
|
314
|
+
}
|
|
315
|
+
return fetchResponse.json();
|
|
316
|
+
});
|
|
483
317
|
return response.data;
|
|
484
318
|
}
|
|
485
|
-
async #transakPatch(
|
|
486
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
487
|
-
dataStruct, body) {
|
|
319
|
+
async #transakPatch(path, body) {
|
|
488
320
|
const apiKey = this.#ensureApiKey();
|
|
489
321
|
const baseUrl = getTransakApiBaseUrl(this.#environment);
|
|
490
322
|
const url = new URL(path, baseUrl);
|
|
491
323
|
url.searchParams.set('apiKey', apiKey);
|
|
492
|
-
const response =
|
|
493
|
-
|
|
494
|
-
url,
|
|
495
|
-
init: {
|
|
324
|
+
const response = await this.#policy.execute(async () => {
|
|
325
|
+
const fetchResponse = await this.#fetch(url.toString(), {
|
|
496
326
|
method: 'PATCH',
|
|
497
327
|
headers: this.#getHeaders(),
|
|
498
328
|
body: JSON.stringify(body),
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
|
|
329
|
+
});
|
|
330
|
+
if (!fetchResponse.ok) {
|
|
331
|
+
await this.#throwTransakApiError(fetchResponse, url);
|
|
332
|
+
}
|
|
333
|
+
return fetchResponse.json();
|
|
334
|
+
});
|
|
502
335
|
return response.data;
|
|
503
336
|
}
|
|
504
|
-
async #transakDelete(
|
|
337
|
+
async #transakDelete(path, params) {
|
|
505
338
|
const apiKey = this.#ensureApiKey();
|
|
506
339
|
const baseUrl = getTransakApiBaseUrl(this.#environment);
|
|
507
340
|
const url = new URL(path, baseUrl);
|
|
@@ -513,10 +346,14 @@ export class TransakService extends BaseDataService {
|
|
|
513
346
|
}
|
|
514
347
|
}
|
|
515
348
|
}
|
|
516
|
-
await this.#
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
349
|
+
await this.#policy.execute(async () => {
|
|
350
|
+
const fetchResponse = await this.#fetch(url.toString(), {
|
|
351
|
+
method: 'DELETE',
|
|
352
|
+
headers: this.#getHeaders(),
|
|
353
|
+
});
|
|
354
|
+
if (!fetchResponse.ok) {
|
|
355
|
+
await this.#throwTransakApiError(fetchResponse, url);
|
|
356
|
+
}
|
|
520
357
|
});
|
|
521
358
|
}
|
|
522
359
|
/**
|
|
@@ -543,9 +380,7 @@ export class TransakService extends BaseDataService {
|
|
|
543
380
|
// client product / version.
|
|
544
381
|
addRampsClientIdentityParams(url, this.#clientIdentity);
|
|
545
382
|
}
|
|
546
|
-
async #ordersApiGet(
|
|
547
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
548
|
-
dataStruct, params) {
|
|
383
|
+
async #ordersApiGet(path, params) {
|
|
549
384
|
const baseUrl = this.#getRampsApiBaseUrl();
|
|
550
385
|
const providerPath = getRampsProviderPath(this.#environment);
|
|
551
386
|
const url = new URL(`${providerPath}${path}`, baseUrl);
|
|
@@ -561,36 +396,29 @@ export class TransakService extends BaseDataService {
|
|
|
561
396
|
}
|
|
562
397
|
}
|
|
563
398
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
throw new HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
|
|
576
|
-
}
|
|
577
|
-
return (await fetchResponse.json());
|
|
578
|
-
},
|
|
579
|
-
}));
|
|
399
|
+
const response = await this.#policy.execute(async () => {
|
|
400
|
+
const fetchResponse = await this.#fetch(url.toString(), {
|
|
401
|
+
method: 'GET',
|
|
402
|
+
headers: { Accept: 'application/json' },
|
|
403
|
+
});
|
|
404
|
+
if (!fetchResponse.ok) {
|
|
405
|
+
throw new HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
|
|
406
|
+
}
|
|
407
|
+
return fetchResponse.json();
|
|
408
|
+
});
|
|
409
|
+
return response;
|
|
580
410
|
}
|
|
581
411
|
// === PUBLIC API METHODS ===
|
|
582
412
|
async sendUserOtp(email) {
|
|
583
|
-
const result = await this.#transakPost('
|
|
584
|
-
email,
|
|
585
|
-
});
|
|
413
|
+
const result = await this.#transakPost('/api/v2/auth/login', { email });
|
|
586
414
|
return result;
|
|
587
415
|
}
|
|
588
416
|
async verifyUserOtp(email, verificationCode, stateToken) {
|
|
589
|
-
const responseData = await this.#transakPost('
|
|
417
|
+
const responseData = await this.#transakPost('/api/v2/auth/verify', {
|
|
590
418
|
email,
|
|
591
419
|
otp: verificationCode,
|
|
592
420
|
stateToken,
|
|
593
|
-
});
|
|
421
|
+
}, { policy: this.#noRetryPolicy });
|
|
594
422
|
const accessToken = {
|
|
595
423
|
accessToken: responseData.accessToken,
|
|
596
424
|
ttl: responseData.ttl,
|
|
@@ -602,7 +430,7 @@ export class TransakService extends BaseDataService {
|
|
|
602
430
|
async logout() {
|
|
603
431
|
this.#ensureAccessToken();
|
|
604
432
|
try {
|
|
605
|
-
const result = await this.#transakPost('
|
|
433
|
+
const result = await this.#transakPost('/api/v1/auth/logout');
|
|
606
434
|
this.clearAccessToken();
|
|
607
435
|
return result;
|
|
608
436
|
}
|
|
@@ -616,7 +444,7 @@ export class TransakService extends BaseDataService {
|
|
|
616
444
|
}
|
|
617
445
|
async getUserDetails() {
|
|
618
446
|
this.#ensureAccessToken();
|
|
619
|
-
return this.#transakGet('
|
|
447
|
+
return this.#transakGet('/api/v2/user/');
|
|
620
448
|
}
|
|
621
449
|
async getBuyQuote(genericFiatCurrency, genericCryptoCurrency, genericNetwork, genericPaymentMethod, fiatAmount, isFeeExcludedFromFiat = true) {
|
|
622
450
|
const normalizedPaymentMethod = normalizePaymentMethodForTranslation(genericPaymentMethod || undefined);
|
|
@@ -640,7 +468,7 @@ export class TransakService extends BaseDataService {
|
|
|
640
468
|
if (translation.paymentMethod) {
|
|
641
469
|
params.paymentMethod = translation.paymentMethod;
|
|
642
470
|
}
|
|
643
|
-
const quote = await this.#transakGet('
|
|
471
|
+
const quote = await this.#transakGet('/api/v2/lookup/quotes', params);
|
|
644
472
|
return {
|
|
645
473
|
...quote,
|
|
646
474
|
requestedAssetId: genericCryptoCurrency,
|
|
@@ -649,14 +477,14 @@ export class TransakService extends BaseDataService {
|
|
|
649
477
|
}
|
|
650
478
|
async getKycRequirement(quoteId) {
|
|
651
479
|
this.#ensureAccessToken();
|
|
652
|
-
const result = await this.#transakGet('
|
|
480
|
+
const result = await this.#transakGet('/api/v2/kyc/requirement', {
|
|
653
481
|
'metadata[quoteId]': quoteId,
|
|
654
482
|
});
|
|
655
483
|
return result;
|
|
656
484
|
}
|
|
657
485
|
async getAdditionalRequirements(quoteId) {
|
|
658
486
|
this.#ensureAccessToken();
|
|
659
|
-
return this.#transakGet('
|
|
487
|
+
return this.#transakGet('/api/v2/kyc/additional-requirements', { 'metadata[quoteId]': quoteId });
|
|
660
488
|
}
|
|
661
489
|
async createOrder(quoteId, walletAddress, paymentMethodId) {
|
|
662
490
|
this.#ensureAccessToken();
|
|
@@ -666,7 +494,7 @@ export class TransakService extends BaseDataService {
|
|
|
666
494
|
});
|
|
667
495
|
const paymentInstrumentId = translation.paymentMethod ?? normalizedPaymentMethod;
|
|
668
496
|
try {
|
|
669
|
-
const transakOrder = await this.#transakPost('
|
|
497
|
+
const transakOrder = await this.#transakPost('/api/v2/orders', {
|
|
670
498
|
quoteId,
|
|
671
499
|
walletAddress,
|
|
672
500
|
paymentInstrumentId,
|
|
@@ -680,7 +508,7 @@ export class TransakService extends BaseDataService {
|
|
|
680
508
|
error.errorCode === TRANSAK_ERROR_CODES.ORDER_EXISTS) {
|
|
681
509
|
await this.cancelAllActiveOrders();
|
|
682
510
|
await new Promise((resolve) => setTimeout(resolve, this.#orderRetryDelayMs));
|
|
683
|
-
const retryOrder = await this.#transakPost('
|
|
511
|
+
const retryOrder = await this.#transakPost('/api/v2/orders', {
|
|
684
512
|
quoteId,
|
|
685
513
|
walletAddress,
|
|
686
514
|
paymentInstrumentId,
|
|
@@ -700,7 +528,7 @@ export class TransakService extends BaseDataService {
|
|
|
700
528
|
depositOrderId = TransakOrderIdTransformer.transakOrderIdToDepositOrderId(orderId, this.#environment);
|
|
701
529
|
}
|
|
702
530
|
const transakOrderId = TransakOrderIdTransformer.extractTransakOrderId(depositOrderId);
|
|
703
|
-
const order = await this.#ordersApiGet(
|
|
531
|
+
const order = await this.#ordersApiGet(`/orders/${transakOrderId}`, { wallet });
|
|
704
532
|
const orderWithId = {
|
|
705
533
|
...order,
|
|
706
534
|
id: depositOrderId,
|
|
@@ -711,7 +539,7 @@ export class TransakService extends BaseDataService {
|
|
|
711
539
|
}
|
|
712
540
|
if (this.#accessToken?.accessToken) {
|
|
713
541
|
try {
|
|
714
|
-
const transakOrder = await this.#transakGet(
|
|
542
|
+
const transakOrder = await this.#transakGet(`/api/v2/orders/${transakOrderId}`);
|
|
715
543
|
return { ...orderWithId, paymentDetails: transakOrder.paymentDetails };
|
|
716
544
|
}
|
|
717
545
|
catch {
|
|
@@ -733,7 +561,7 @@ export class TransakService extends BaseDataService {
|
|
|
733
561
|
if (translation.paymentMethod) {
|
|
734
562
|
params.paymentCategory = translation.paymentMethod;
|
|
735
563
|
}
|
|
736
|
-
return this.#transakGet('
|
|
564
|
+
return this.#transakGet('/api/v2/orders/user-limit', params);
|
|
737
565
|
}
|
|
738
566
|
/**
|
|
739
567
|
* @deprecated Use {@link createWidgetUrl} instead. The OTT flow requires the
|
|
@@ -742,7 +570,7 @@ export class TransakService extends BaseDataService {
|
|
|
742
570
|
*/
|
|
743
571
|
async requestOtt() {
|
|
744
572
|
this.#ensureAccessToken();
|
|
745
|
-
const result = await this.#transakPost('
|
|
573
|
+
const result = await this.#transakPost('/api/v2/auth/request-ott');
|
|
746
574
|
return result;
|
|
747
575
|
}
|
|
748
576
|
/**
|
|
@@ -798,7 +626,7 @@ export class TransakService extends BaseDataService {
|
|
|
798
626
|
*/
|
|
799
627
|
async createWidgetUrl(quote, walletAddress, extraParams) {
|
|
800
628
|
this.#ensureAccessToken();
|
|
801
|
-
const bearerToken = await this
|
|
629
|
+
const bearerToken = await this.#messenger.call('AuthenticationController:getBearerToken');
|
|
802
630
|
const baseUrl = this.#getRampsApiBaseUrl();
|
|
803
631
|
const providerPath = getRampsProviderPath(this.#environment);
|
|
804
632
|
const url = new URL(`${providerPath}/widget-url`, baseUrl);
|
|
@@ -825,32 +653,32 @@ export class TransakService extends BaseDataService {
|
|
|
825
653
|
if (this.#accessToken?.accessToken) {
|
|
826
654
|
headers['x-transak-access-token'] = this.#accessToken.accessToken;
|
|
827
655
|
}
|
|
828
|
-
const response =
|
|
829
|
-
|
|
830
|
-
url,
|
|
831
|
-
init: {
|
|
656
|
+
const response = await this.#policy.execute(async () => {
|
|
657
|
+
const fetchResponse = await this.#fetch(url.toString(), {
|
|
832
658
|
method: 'POST',
|
|
833
659
|
headers,
|
|
834
660
|
body: JSON.stringify({ widgetParams }),
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
|
|
661
|
+
});
|
|
662
|
+
if (!fetchResponse.ok) {
|
|
663
|
+
await this.#throwTransakApiError(fetchResponse, url);
|
|
664
|
+
}
|
|
665
|
+
return fetchResponse.json();
|
|
666
|
+
});
|
|
838
667
|
return response.widgetUrl;
|
|
839
668
|
}
|
|
840
669
|
async submitPurposeOfUsageForm(purpose) {
|
|
841
670
|
this.#ensureAccessToken();
|
|
842
|
-
await this.#transakPost('
|
|
671
|
+
await this.#transakPost('/api/v2/kyc/purpose-of-usage', {
|
|
672
|
+
purposeList: purpose,
|
|
673
|
+
});
|
|
843
674
|
}
|
|
844
675
|
async patchUser(data) {
|
|
845
676
|
this.#ensureAccessToken();
|
|
846
|
-
return this.#transakPatch('
|
|
677
|
+
return this.#transakPatch('/api/v2/kyc/user', data);
|
|
847
678
|
}
|
|
848
679
|
async submitSsnDetails(ssn, quoteId) {
|
|
849
680
|
this.#ensureAccessToken();
|
|
850
|
-
return this.#transakPost('
|
|
851
|
-
ssn,
|
|
852
|
-
quoteId,
|
|
853
|
-
});
|
|
681
|
+
return this.#transakPost('/api/v2/kyc/ssn', { ssn, quoteId });
|
|
854
682
|
}
|
|
855
683
|
async confirmPayment(orderId, paymentMethodId) {
|
|
856
684
|
this.#ensureAccessToken();
|
|
@@ -859,7 +687,7 @@ export class TransakService extends BaseDataService {
|
|
|
859
687
|
paymentMethod: normalizedPaymentMethod,
|
|
860
688
|
});
|
|
861
689
|
const transakOrderId = TransakOrderIdTransformer.extractTransakOrderId(orderId);
|
|
862
|
-
return this.#transakPost('
|
|
690
|
+
return this.#transakPost('/api/v2/orders/payment-confirmation', {
|
|
863
691
|
orderId: transakOrderId,
|
|
864
692
|
paymentMethod: translation.paymentMethod ?? normalizedPaymentMethod,
|
|
865
693
|
});
|
|
@@ -874,38 +702,31 @@ export class TransakService extends BaseDataService {
|
|
|
874
702
|
...translationRequest,
|
|
875
703
|
paymentMethod: normalizePaymentMethodForTranslation(translationRequest.paymentMethod),
|
|
876
704
|
};
|
|
877
|
-
const params = {};
|
|
878
705
|
for (const [key, value] of Object.entries(normalizedRequest)) {
|
|
879
706
|
if (value !== undefined) {
|
|
880
707
|
url.searchParams.set(key, value);
|
|
881
|
-
params[key] = value;
|
|
882
708
|
}
|
|
883
709
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
throw new HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
|
|
896
|
-
}
|
|
897
|
-
return (await fetchResponse.json());
|
|
898
|
-
},
|
|
899
|
-
}));
|
|
710
|
+
const response = await this.#policy.execute(async () => {
|
|
711
|
+
const fetchResponse = await this.#fetch(url.toString(), {
|
|
712
|
+
method: 'GET',
|
|
713
|
+
headers: { Accept: 'application/json' },
|
|
714
|
+
});
|
|
715
|
+
if (!fetchResponse.ok) {
|
|
716
|
+
throw new HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
|
|
717
|
+
}
|
|
718
|
+
return fetchResponse.json();
|
|
719
|
+
});
|
|
720
|
+
return response;
|
|
900
721
|
}
|
|
901
722
|
async getIdProofStatus(workFlowRunId) {
|
|
902
723
|
this.#ensureAccessToken();
|
|
903
|
-
return this.#transakGet('
|
|
724
|
+
return this.#transakGet('/api/v2/kyc/id-proof-status', { workFlowRunId });
|
|
904
725
|
}
|
|
905
726
|
async cancelOrder(depositOrderId) {
|
|
906
727
|
this.#ensureAccessToken();
|
|
907
728
|
const transakOrderId = TransakOrderIdTransformer.extractTransakOrderId(depositOrderId);
|
|
908
|
-
await this.#transakDelete(
|
|
729
|
+
await this.#transakDelete(`/api/v2/orders/${transakOrderId}`, {
|
|
909
730
|
cancelReason: 'Creating new order',
|
|
910
731
|
});
|
|
911
732
|
}
|
|
@@ -926,7 +747,7 @@ export class TransakService extends BaseDataService {
|
|
|
926
747
|
}
|
|
927
748
|
async getActiveOrders() {
|
|
928
749
|
this.#ensureAccessToken();
|
|
929
|
-
return this.#transakGet('
|
|
750
|
+
return this.#transakGet('/api/v2/active-orders');
|
|
930
751
|
}
|
|
931
752
|
}
|
|
932
753
|
//# sourceMappingURL=TransakService.js.map
|