paj_ramp 1.3.2 → 1.4.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.
Files changed (50) hide show
  1. package/README.md +327 -182
  2. package/__tests__/session.test.ts +38 -0
  3. package/dist/lib/off_ramp/directCreateOrder.d.ts +12 -11
  4. package/dist/lib/off_ramp/directCreateOrder.js +6 -11
  5. package/dist/lib/on_ramp/createOrder.d.ts +10 -5
  6. package/dist/lib/on_ramp/createOrder.js +6 -12
  7. package/dist/lib/utility/session/initiate.d.ts +2 -1
  8. package/dist/lib/utility/session/initiate.js +5 -5
  9. package/dist/lib/utility/session/verify.d.ts +2 -3
  10. package/dist/lib/utility/session/verify.js +3 -3
  11. package/dist/lib/utility/transaction/getAllTransactions.d.ts +3 -5
  12. package/dist/lib/utility/transaction/getAllTransactions.js +4 -4
  13. package/dist/lib/utility/transaction/getTransaction.d.ts +8 -14
  14. package/dist/lib/utility/transaction/getTransaction.js +2 -2
  15. package/dist/sdk.d.ts +17 -16
  16. package/dist/sdk.js +25 -21
  17. package/dist/utils/api.js +2 -0
  18. package/dist/utils/enums.d.ts +5 -0
  19. package/dist/utils/enums.js +6 -0
  20. package/examples/README.md +141 -0
  21. package/examples/basic-offramp/.env.example +24 -0
  22. package/examples/basic-offramp/README.md +186 -0
  23. package/examples/basic-offramp/index.ts +117 -0
  24. package/examples/basic-offramp/package-lock.json +54 -0
  25. package/examples/basic-offramp/package.json +13 -0
  26. package/examples/basic-onramp/.env.example +24 -0
  27. package/examples/basic-onramp/README.md +161 -0
  28. package/examples/basic-onramp/index.ts +165 -0
  29. package/examples/basic-onramp/package-lock.json +46 -0
  30. package/examples/basic-onramp/package.json +13 -0
  31. package/examples/webhook-integration/.env.example +25 -0
  32. package/examples/webhook-integration/README.md +266 -0
  33. package/examples/webhook-integration/package-lock.json +798 -0
  34. package/examples/webhook-integration/package.json +15 -0
  35. package/examples/webhook-integration/server.js +184 -0
  36. package/lib/off_ramp/directCreateOrder.ts +22 -40
  37. package/lib/on_ramp/createOrder.ts +19 -20
  38. package/lib/utility/session/initiate.ts +8 -7
  39. package/lib/utility/session/verify.ts +5 -5
  40. package/lib/utility/transaction/getAllTransactions.ts +6 -8
  41. package/lib/utility/transaction/getTransaction.ts +10 -20
  42. package/package.json +2 -1
  43. package/sdk.ts +29 -22
  44. package/utils/api.ts +2 -0
  45. package/utils/enums.ts +18 -14
  46. package/__tests__/getTXPoolAddress.test.ts +0 -24
  47. package/lib/utility/deprecated/addWallet.ts +0 -33
  48. package/lib/utility/deprecated/getTXPoolAddress.ts +0 -22
  49. package/lib/utility/deprecated/getWallet.ts +0 -34
  50. package/lib/utility/deprecated/switchWalletBankAccount.ts +0 -25
package/README.md CHANGED
@@ -17,10 +17,10 @@ yarn add paj_ramp
17
17
  ### Initialize SDK (select environment: "staging" | "production")
18
18
 
19
19
  ```typescript
20
- import { initializeSDK } from 'paj_ramp';
20
+ import { initializeSDK, Environment } from 'paj_ramp';
21
21
 
22
22
  // Selects the environment you want to work with
23
- initializeSDK('staging'); // or production
23
+ initializeSDK(Environment.Production); // or Environment.Staging
24
24
  ```
25
25
 
26
26
  ### Initiate Session
@@ -66,6 +66,24 @@ token: string
66
66
  } */
67
67
  ```
68
68
 
69
+ ## šŸ“š Examples
70
+
71
+ Check out our [examples directory](./examples) for complete, runnable examples:
72
+
73
+ - **[Basic Onramp](./examples/basic-onramp)** - Simple onramp transaction flow showing how users can buy crypto with fiat
74
+ - **[Basic Offramp](./examples/basic-offramp)** - Simple offramp transaction flow showing how users can sell crypto for fiat
75
+ - **[Webhook Integration](./examples/webhook-integration)** - Express server with webhook handling for real-time order updates
76
+
77
+ Each example includes its own README with detailed setup instructions. Perfect for understanding how to integrate PAJ Ramp into your application!
78
+
79
+ ```bash
80
+ cd examples/basic-onramp
81
+ npm install
82
+ cp .env.example .env
83
+ # Edit .env with your credentials
84
+ npm start
85
+ ```
86
+
69
87
  ## Utility Endpoints
70
88
 
71
89
  ### Handle Rate:
@@ -216,7 +234,7 @@ amount: number;
216
234
  usdcAmount: number;
217
235
  fiatAmount: number;
218
236
  sender: string;
219
- receipiant: string;
237
+ receipient: string;
220
238
  rate: number;
221
239
  status: TransactionStatus;
222
240
  transactionType: TransactionType;
@@ -242,7 +260,7 @@ amount: number;
242
260
  usdcAmount: number;
243
261
  fiatAmount: number;
244
262
  sender: string;
245
- receipiant: string;
263
+ receipint: string;
246
264
  rate: number;
247
265
  status: TransactionStatus;
248
266
  transactionType: TransactionType;
@@ -255,31 +273,31 @@ createdAt: string | Date;
255
273
  ### Usage Example
256
274
 
257
275
  ```typescript
258
- import { offRampCreateOrder } from 'paj_ramp';
276
+ import { createOfframpOrder, Currency } from 'paj_ramp';
259
277
 
260
- const createOrder = await offRampCreateOrder(
261
- 'token',
262
- 'bank_id',
263
- 'account_number',
264
- 'NGN', // Currency
265
- 10000, // amount
266
- 'token_mint_address'
267
- 'webhook_url'
278
+ const createOrder = await createOfframpOrder(
279
+ {
280
+ bank: 'bank_id',
281
+ accountNumber: 'account_number',
282
+ currency: 'NGN' as Currency, // Currency
283
+ amount: 10000, // amount
284
+ mint: 'token_mint_address',
285
+ webhookURL: 'webhook_url', // https://your-domain.com/webhook
286
+ },
287
+ 'token'
268
288
  );
269
289
  /* Response: {
270
290
  id: string,
271
291
  address: string,
272
- signature?: string,
273
292
  mint: string,
274
293
  currency: Currency,
275
294
  amount: number,
276
- usdcAmount: number,
277
295
  fiatAmount: number,
278
296
  sender: string,
279
- receipiant: string,
280
297
  rate: number,
281
298
  status: TransactionStatus,
282
299
  transactionType: TransactionType
300
+ createdAt: string
283
301
  }*/
284
302
  ```
285
303
 
@@ -288,17 +306,19 @@ transactionType: TransactionType
288
306
  ### Usage Example
289
307
 
290
308
  ```typescript
291
- import { createOrder } from 'paj_ramp';
292
-
293
- const order = await createOrder({
294
- fiatAmount: 10000,
295
- currency: 'NGN',
296
- recipient: 'wallet_address_here',
297
- mint: 'token_mint_address_here',
298
- chain: 'SOLANA', //ethereum, polygon, etc
299
- webhookURL: 'your_webhook_url',
300
- token: 'token_from_verification',
301
- });
309
+ import { createOrder, Currency } from 'paj_ramp';
310
+
311
+ const order = await createOrder(
312
+ {
313
+ fiatAmount: 10000,
314
+ currency: 'NGN' as Currency,
315
+ recipient: 'wallet_address_here',
316
+ mint: 'token_mint_address_here',
317
+ chain: 'SOLANA', //ethereum, polygon, etc
318
+ webhookURL: 'your_webhook_url', // https://your-domain.com/webhook
319
+ },
320
+ 'token_from_verification'
321
+ );
302
322
  // Response: { id: string, accountNumber: string, accountName: string, fiatAmount: number, bank: string }
303
323
  ```
304
324
 
@@ -317,194 +337,319 @@ const order = await createOrder({
317
337
  usdcAmount: number;
318
338
  fiatAmount: number;
319
339
  sender: string;
320
- receipiant: string;
340
+ receipient: string;
321
341
  rate: number;
322
342
  status: TransactionStatus; // eg. INIT, PAID, COMPLETED
323
343
  transactionType: TransactionType; // ON_RAMP or OFF_RAMP
324
344
  }
325
345
  ```
326
346
 
327
- ## Other types
347
+ ## SDK Reference
348
+
349
+ ### Complete On-Ramp Flow Example
328
350
 
329
351
  ```typescript
330
352
  import {
331
- // Chain, // SOLANA, etc
332
- TransactionStatus, // INIT, etc
333
- TransactionType, // ON_RAMP, etc
334
- Currency, // NGN
353
+ initializeSDK,
354
+ initiate,
355
+ verify,
356
+ createOnrampOrder,
357
+ getTransaction,
358
+ getAllTransactions,
359
+ Environment,
335
360
  } from 'paj_ramp';
336
- ```
337
-
338
- <!--
339
- ## Quick Start
361
+ import dotenv from 'dotenv';
340
362
 
341
- ### Real-time Order Observation
363
+ dotenv.config();
342
364
 
343
- The SDK provides Socket.IO functionality to observe onramp orders in real-time:
365
+ async function main() {
366
+ // Step 1: Initialize SDK
367
+ console.log('šŸš€ Initializing PAJ Ramp SDK...');
368
+ initializeSDK(Environment.Local);
344
369
 
345
- ```typescript
346
- import { observeOrder } from 'paj_ramp';
347
-
348
- // Using observeOrder function
349
- const observer = observeOrder({
350
- orderId: 'your_order_id',
351
- onOrderUpdate: data => {
352
- console.log('Order update:', data);
353
- // Handle status changes: pending, processing, completed, failed, cancelled
354
- },
355
- onError: error => {
356
- console.error('Socket error:', error);
357
- },
358
- });
370
+ const email = process.env.USER_EMAIL!;
371
+ const apiKey = process.env.BUSINESS_API_KEY!;
372
+ const fiatAmount = parseInt(process.env.FIAT_AMOUNT!);
373
+ const currency = process.env.CURRENCY!;
374
+ const recipient = process.env.WALLET_ADDRESS!;
375
+ const mint = process.env.TOKEN_MINT!;
376
+ const webhookURL = process.env.WEBHOOK_URL!;
359
377
 
360
- await observer.connect();
361
- ```
378
+ try {
379
+ // Step 2: Initiate session
380
+ console.log('\nšŸ“§ Initiating session...');
381
+ console.log('Email:', email);
382
+ console.log('API Key:', apiKey);
383
+ const initiated = await initiate(email, apiKey);
384
+ console.log('āœ… OTP sent to:', initiated.email || initiated.phone);
385
+
386
+ // In a real application, you would wait for the user to receive and enter the OTP
387
+ // For this example, we assume you have the OTP from your email
388
+ console.log(
389
+ '\nā³ Please check your email for the OTP and add it to your .env file'
390
+ );
391
+
392
+ const otp = process.env.OTP;
393
+ if (!otp) {
394
+ console.error(
395
+ 'āŒ OTP not found in .env file. Please add OTP=your_otp to .env'
396
+ );
397
+ process.exit(1);
398
+ }
362
399
 
363
- ### Order Update Data Structure
400
+ // Step 3: Verify session
401
+ console.log('\nšŸ” Verifying session with OTP...');
402
+ const verified = await verify(
403
+ email,
404
+ otp,
405
+ {
406
+ uuid: 'example-device-uuid-' + Date.now(),
407
+ device: 'Desktop',
408
+ os: 'MacOS',
409
+ browser: 'Chrome',
410
+ },
411
+ apiKey
412
+ );
413
+ console.log('āœ… Session verified successfully!');
414
+ console.log(
415
+ 'Token (first 20 chars):',
416
+ verified.token.substring(0, 20) + '...'
417
+ );
418
+
419
+ const sessionToken = verified.token;
420
+
421
+ // Step 4: Create onramp order
422
+ console.log('\nšŸ’° Creating onramp order...');
423
+ const order = await createOnrampOrder(
424
+ {
425
+ fiatAmount,
426
+ currency,
427
+ recipient,
428
+ mint,
429
+ chain: 'SOLANA',
430
+ webhookURL,
431
+ },
432
+ sessionToken
433
+ );
434
+
435
+ console.log('\nāœ… Order created successfully!');
436
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
437
+ console.log('šŸ“‹ Order Details:');
438
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
439
+ console.log('Order ID:', order.id);
440
+ console.log('Account Number:', order.accountNumber);
441
+ console.log('Account Name:', order.accountName);
442
+ console.log(
443
+ 'Fiat Amount (to send):',
444
+ order.fiatAmount,
445
+ process.env.CURRENCY
446
+ );
447
+ console.log('Token Amount (to receive):', order.amount);
448
+ console.log('Bank:', order.bank);
449
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
450
+
451
+ // Step 5: Fetch the transaction details
452
+ console.log('\nšŸ” Fetching transaction details...');
453
+ const transaction = await getTransaction(sessionToken, order.id);
454
+
455
+ console.log('\nāœ… Transaction fetched successfully!');
456
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
457
+ console.log('šŸ“‹ Transaction Details:');
458
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
459
+ console.log('Transaction ID:', transaction.id);
460
+ console.log('Status:', transaction.status);
461
+ console.log('Type:', transaction.transactionType);
462
+ console.log('Mint:', transaction.mint);
463
+ console.log('Currency:', transaction.currency);
464
+ console.log('Token Amount:', transaction.amount);
465
+ console.log('USDC Amount:', transaction.usdcAmount);
466
+ console.log('Fiat Amount:', transaction.fiatAmount);
467
+ console.log('Rate:', transaction.rate);
468
+ console.log('Recipient:', transaction.recipient);
469
+ console.log('Created At:', transaction.createdAt);
470
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
471
+
472
+ // Step 6: Fetch all transactions
473
+ console.log('\nšŸ“œ Fetching all transactions...');
474
+ const allTransactions = await getAllTransactions(sessionToken);
475
+
476
+ console.log(`\nāœ… Found ${allTransactions.length} transaction(s)!\n`);
477
+
478
+ if (allTransactions.length > 0) {
479
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
480
+ console.log('šŸ“‹ All Transactions:');
481
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
482
+
483
+ allTransactions.forEach((tx, index) => {
484
+ console.log(`\n${index + 1}. Transaction ID: ${tx.id}`);
485
+ console.log(` Status: ${tx.status}`);
486
+ console.log(` Type: ${tx.transactionType}`);
487
+ console.log(` Amount: ${tx.amount} (${tx.currency})`);
488
+ console.log(` Fiat: ${tx.fiatAmount}`);
489
+ console.log(` Created: ${tx.createdAt}`);
490
+ });
491
+
492
+ console.log('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
493
+ }
364
494
 
365
- ```typescript
366
- interface OnRampOrderUpdate {
367
- id: string;
368
- fiatAmount: string;
369
- currency: string;
370
- recipient: string; // wallet address
371
- mint: string; // token address
372
- chain: Chain; // enum: 'solana', 'ethereum', 'polygon'
373
- status: OnRampStatus; // enum: 'pending', 'processing', 'completed', 'failed', 'cancelled'
495
+ console.log('\nšŸ“ Next Steps:');
496
+ console.log(
497
+ '1. Transfer',
498
+ order.fiatAmount,
499
+ process.env.CURRENCY,
500
+ 'to the account number above'
501
+ );
502
+ console.log('2. Your webhook will receive status updates');
503
+ console.log('3. Once payment is confirmed, you will receive tokens');
504
+ } catch (error) {
505
+ console.error(
506
+ '\nāŒ Error:',
507
+ error instanceof Error ? error.message : String(error)
508
+ );
509
+ if (error && typeof error === 'object' && 'response' in error) {
510
+ console.error('Response data:', (error as any).response.data);
511
+ }
512
+ process.exit(1);
513
+ }
374
514
  }
375
- ```
376
-
377
- ### Socket Events
378
-
379
- The SDK listens for these Socket.IO events:
380
-
381
- - **ORDER_UPDATE**: Real-time order status updates
382
- - **ERROR**: Error messages from the server
383
-
384
- ## API Reference
385
-
386
- ### observeOrder(options)
387
515
 
388
- Creates an order observer.
389
-
390
- **Parameters:**
391
-
392
- - `options.orderId` (string, required): The order ID to observe
393
- - `options.onOrderUpdate` (function, optional): Callback for order updates
394
- - `options.onError` (function, optional): Callback for errors
395
- - `options.onConnect` (function, optional): Callback when connected
396
- - `options.onDisconnect` (function, optional): Callback when disconnected
397
- - `options.onConnectionStatusChange` (function, optional): Callback for connection status changes
398
-
399
- **Returns:**
400
-
401
- - `socket`: The Socket.IO instance
402
- - `isConnected()`: Function to check connection status
403
- - `connect()`: Function to connect to the socket
404
- - `disconnect()`: Function to disconnect from the socket
405
-
406
- **Example:**
407
-
408
- ```typescript
409
- import { observeOrder } from 'paj_ramp';
410
-
411
- const observer = observeOrder({
412
- orderId: 'your_order_id',
413
- onOrderUpdate: data => console.log(data),
414
- });
415
-
416
- // Connect manually
417
- await observer.connect();
418
-
419
- // Check connection status
420
- console.log('Connected:', observer.isConnected());
421
-
422
- // Disconnect manually: you could use setTimeout to keep the socket alive for a certain amount of time before you disconnect
423
- observer.disconnect();
516
+ main();
424
517
  ```
425
518
 
426
- ## Error Handling
427
-
428
- The SDK provides comprehensive error handling:
519
+ ### Complete Off-Ramp Flow Example
429
520
 
430
521
  ```typescript
431
- const observer = observeOrder({
432
- orderId: 'your_order_id',
433
- onError: error => {
434
- // Handle connection errors, order not found, etc.
435
- console.error('Socket error:', error);
436
- },
437
- });
438
- ```
522
+ import {
523
+ initializeSDK,
524
+ initiate,
525
+ verify,
526
+ getBanks,
527
+ createOfframpOrder,
528
+ Currency,
529
+ Environment,
530
+ } from 'paj_ramp';
531
+ import dotenv from 'dotenv';
439
532
 
440
- Common error messages:
533
+ dotenv.config();
441
534
 
442
- - `"Order not found: {orderId}"`
443
- - `"Connection failed"`
444
- - `"Socket timeout"`
535
+ async function main() {
536
+ // Step 1: Initialize SDK
537
+ console.log('šŸš€ Initializing PAJ Ramp SDK...');
538
+ initializeSDK(Environment.Local);
445
539
 
446
- ### Usage Example
540
+ const email = process.env.USER_EMAIL!;
541
+ const apiKey = process.env.BUSINESS_API_KEY!;
542
+ const accountNumber = process.env.ACCOUNT_NUMBER!;
543
+ const bankId = process.env.BANK_ID!;
544
+ const currency = process.env.CURRENCY! as Currency;
545
+ const mint = process.env.TOKEN_MINT!;
546
+ const webhookURL = process.env.WEBHOOK_URL!;
447
547
 
448
- ```typescript
449
- import { observeOrder, createOrder } from 'paj_ramp';
450
-
451
- async function example(orderId) {
452
- console.log('Observe Order');
453
-
454
- const observer = observeOrder({
455
- orderId,
456
- onOrderUpdate: data => {
457
- console.log('Order update received:', data);
458
- console.log('Status:', data.status);
459
- console.log('Amount:', data.amount);
460
- console.log('Currency:', data.currency);
461
- },
462
- onError: error => {
463
- console.error('Socket error:', error);
464
- },
465
- onConnect: () => {
466
- console.log('Connected to order socket');
467
- },
468
- onDisconnect: () => {
469
- console.log('Disconnected from order socket');
470
- },
471
- onConnectionStatusChange: connected => {
548
+ try {
549
+ // Step 2: Initiate session
550
+ console.log('\nšŸ“§ Initiating session...');
551
+ const initiated = await initiate(email, apiKey);
552
+ console.log('āœ… OTP sent to:', initiated.email || initiated.phone);
553
+
554
+ const otp = process.env.OTP;
555
+ if (!otp) {
556
+ console.error(
557
+ 'āŒ OTP not found in .env file. Please add OTP=your_otp to .env'
558
+ );
559
+ process.exit(1);
560
+ }
561
+
562
+ // Step 3: Verify session
563
+ console.log('\nšŸ” Verifying session with OTP...');
564
+ const verified = await verify(
565
+ email,
566
+ otp,
567
+ {
568
+ uuid: 'example-device-uuid-' + Date.now(),
569
+ device: 'Desktop',
570
+ os: 'MacOS',
571
+ browser: 'Chrome',
572
+ },
573
+ apiKey
574
+ );
575
+ console.log('āœ… Session verified successfully!');
576
+
577
+ const sessionToken = verified.token;
578
+
579
+ // Step 4: Get available banks
580
+ console.log('\nšŸ¦ Fetching available banks...');
581
+ const banks = await getBanks(sessionToken);
582
+ console.log(`āœ… Found ${banks.length} banks`);
583
+ if (banks.length > 0) {
472
584
  console.log(
473
- 'Connection status changed:',
474
- connected ? 'Connected' : 'Disconnected'
585
+ 'First few banks:',
586
+ banks
587
+ .slice(0, 3)
588
+ .map(b => b.name)
589
+ .join(', ')
475
590
  );
476
- },
477
- });
591
+ }
478
592
 
479
- try {
480
- await observer.connect();
481
- console.log('Successfully connected to order observer');
482
-
483
- // Keep the connection alive for 1 minute
484
- setTimeout(() => {
485
- console.log('Disconnecting after 1 minute...');
486
- observer.disconnect();
487
- }, 1 * 60 * 1000);
593
+ // Step 7: Create offramp order
594
+ console.log('\nšŸ’ø Creating offramp order...');
595
+ const order = await createOfframpOrder(
596
+ {
597
+ token: verified.token,
598
+ bank: bankId,
599
+ accountNumber,
600
+ currency,
601
+ amount: parseInt(process.env.TOKEN_AMOUNT || '1'),
602
+ mint,
603
+ webhookURL,
604
+ },
605
+ sessionToken
606
+ );
607
+
608
+ console.log('\nāœ… Offramp order created successfully!');
609
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
610
+ console.log('šŸ“‹ Order Details:');
611
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
612
+ console.log('Order ID:', order.id);
613
+ console.log('Address:', order.address);
614
+ console.log('Mint:', order.mint);
615
+ console.log('Token Amount (to pay):', order.amount);
616
+ console.log('Fiat Amount (to receive):', order.fiatAmount);
617
+ console.log('Rate:', order.rate);
618
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
619
+
620
+ console.log('\nšŸ“ Next Steps:');
621
+ console.log('1. Send', order.amount, 'tokens to address:', order.address);
622
+ console.log('2. Your webhook will receive status updates');
623
+ console.log(
624
+ '3. Once tokens are received and confirmed, fiat will be sent to your bank account'
625
+ );
488
626
  } catch (error) {
489
- console.error('Failed to connect:', error);
627
+ console.error(
628
+ '\nāŒ Error:',
629
+ error instanceof Error ? error.message : String(error)
630
+ );
631
+ if (error && typeof error === 'object' && 'response' in error) {
632
+ console.error('Response data:', (error as any).response.data);
633
+ }
634
+ process.exit(1);
490
635
  }
491
636
  }
492
637
 
493
- const order = await createOrder({
494
- fiatAmount: 10000,
495
- currency: 'NGN',
496
- recipient: 'your_wallet_address',
497
- mint: 'your_token_mint_address',
498
- chain: 'SOLANA',
499
- webhookURL: 'webhook_url',
500
- token: token_from_verification,
501
- });
502
-
503
- await example(order.id);
504
- // Response: { id: string, fiatAmount: string, currency: string, , recipient: string, mint: string, chain: Chain, amount: number, status: OnRampStatus }
505
- ``` -->
506
-
507
- ---
638
+ main();
639
+ ```
640
+
641
+ ## Other types
642
+
643
+ ```typescript
644
+ import {
645
+ // Chain, // SOLANA, etc
646
+ TransactionStatus, // INIT, etc
647
+ TransactionType, // ON_RAMP, etc
648
+ Currency, // NGN
649
+ Environment,
650
+ RateType,
651
+ } from 'paj_ramp';
652
+ ```
508
653
 
509
654
  ## License
510
655
 
@@ -0,0 +1,38 @@
1
+ import { initiate } from "../lib/utility/session/initiate";
2
+ import { deviceSignatureType, verify } from "../lib/utility/session/verify";
3
+ import * as api from "../utils/api";
4
+
5
+ describe("Session", () => {
6
+ const mockEmail = "matthew.chukwuemeka@gmail.com";
7
+ const ApiKey = "ApiKey";
8
+
9
+ afterEach(() => {
10
+ jest.restoreAllMocks();
11
+ });
12
+
13
+ it("should return session when API call succeeds", async () => {
14
+ jest.spyOn(api, "get").mockResolvedValue({ email: mockEmail });
15
+
16
+ const result = await initiate(mockEmail, ApiKey);
17
+ expect(result).toEqual({ email: mockEmail });
18
+ });
19
+
20
+ it("should throw an error when API call fails", async () => {
21
+ const error = new Error("API Failure");
22
+ jest.spyOn(api, "get").mockRejectedValue(error);
23
+
24
+ await expect(initiate(mockEmail, ApiKey)).rejects.toThrow("API Failure");
25
+ });
26
+
27
+ it("Should verify session when API call succeeds", async () => {
28
+ jest.spyOn(api, "get").mockResolvedValue({ email: mockEmail });
29
+
30
+ const device: deviceSignatureType = {
31
+ uuid: "uuid",
32
+ device: "device",
33
+ os: "os",
34
+ };
35
+ const result = await verify(mockEmail, "OTP", device, ApiKey);
36
+ expect(result).toEqual({ email: mockEmail });
37
+ });
38
+ });
@@ -1,19 +1,20 @@
1
- import { Currency, TransactionStatus, TransactionType } from '../../utils/enums.js';
2
- type offRampCreateOrderResponse = {
1
+ import { Currency } from "../../utils/enums.js";
2
+ interface CreateOfframpOrder {
3
+ bank: string;
4
+ accountNumber: string;
5
+ currency: Currency;
6
+ amount: number;
7
+ mint: string;
8
+ webhookURL: string;
9
+ }
10
+ export interface OfframpOrder {
3
11
  id: string;
4
12
  address: string;
5
- signature?: string;
6
13
  mint: string;
7
14
  currency: Currency;
8
15
  amount: number;
9
- usdcAmount: number;
10
16
  fiatAmount: number;
11
- sender: string;
12
- receipiant: string;
13
17
  rate: number;
14
- status: TransactionStatus;
15
- transactionType: TransactionType;
16
- createdAt: string;
17
- };
18
- export declare const offRampCreateOrder: (token: string, bank: string, accountNumber: string, currency: string, amount: number, mint: string, webhookURL: string) => Promise<offRampCreateOrderResponse>;
18
+ }
19
+ export declare const createOfframpOrder: (order: CreateOfframpOrder, sessionToken: string) => Promise<OfframpOrder>;
19
20
  export {};