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.
- package/README.md +327 -182
- package/__tests__/session.test.ts +38 -0
- package/dist/lib/off_ramp/directCreateOrder.d.ts +12 -11
- package/dist/lib/off_ramp/directCreateOrder.js +6 -11
- package/dist/lib/on_ramp/createOrder.d.ts +10 -5
- package/dist/lib/on_ramp/createOrder.js +6 -12
- package/dist/lib/utility/session/initiate.d.ts +2 -1
- package/dist/lib/utility/session/initiate.js +5 -5
- package/dist/lib/utility/session/verify.d.ts +2 -3
- package/dist/lib/utility/session/verify.js +3 -3
- package/dist/lib/utility/transaction/getAllTransactions.d.ts +3 -5
- package/dist/lib/utility/transaction/getAllTransactions.js +4 -4
- package/dist/lib/utility/transaction/getTransaction.d.ts +8 -14
- package/dist/lib/utility/transaction/getTransaction.js +2 -2
- package/dist/sdk.d.ts +17 -16
- package/dist/sdk.js +25 -21
- package/dist/utils/api.js +2 -0
- package/dist/utils/enums.d.ts +5 -0
- package/dist/utils/enums.js +6 -0
- package/examples/README.md +141 -0
- package/examples/basic-offramp/.env.example +24 -0
- package/examples/basic-offramp/README.md +186 -0
- package/examples/basic-offramp/index.ts +117 -0
- package/examples/basic-offramp/package-lock.json +54 -0
- package/examples/basic-offramp/package.json +13 -0
- package/examples/basic-onramp/.env.example +24 -0
- package/examples/basic-onramp/README.md +161 -0
- package/examples/basic-onramp/index.ts +165 -0
- package/examples/basic-onramp/package-lock.json +46 -0
- package/examples/basic-onramp/package.json +13 -0
- package/examples/webhook-integration/.env.example +25 -0
- package/examples/webhook-integration/README.md +266 -0
- package/examples/webhook-integration/package-lock.json +798 -0
- package/examples/webhook-integration/package.json +15 -0
- package/examples/webhook-integration/server.js +184 -0
- package/lib/off_ramp/directCreateOrder.ts +22 -40
- package/lib/on_ramp/createOrder.ts +19 -20
- package/lib/utility/session/initiate.ts +8 -7
- package/lib/utility/session/verify.ts +5 -5
- package/lib/utility/transaction/getAllTransactions.ts +6 -8
- package/lib/utility/transaction/getTransaction.ts +10 -20
- package/package.json +2 -1
- package/sdk.ts +29 -22
- package/utils/api.ts +2 -0
- package/utils/enums.ts +18 -14
- package/__tests__/getTXPoolAddress.test.ts +0 -24
- package/lib/utility/deprecated/addWallet.ts +0 -33
- package/lib/utility/deprecated/getTXPoolAddress.ts +0 -22
- package/lib/utility/deprecated/getWallet.ts +0 -34
- 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(
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
276
|
+
import { createOfframpOrder, Currency } from 'paj_ramp';
|
|
259
277
|
|
|
260
|
-
const createOrder = await
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
347
|
+
## SDK Reference
|
|
348
|
+
|
|
349
|
+
### Complete On-Ramp Flow Example
|
|
328
350
|
|
|
329
351
|
```typescript
|
|
330
352
|
import {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
363
|
+
dotenv.config();
|
|
342
364
|
|
|
343
|
-
|
|
365
|
+
async function main() {
|
|
366
|
+
// Step 1: Initialize SDK
|
|
367
|
+
console.log('š Initializing PAJ Ramp SDK...');
|
|
368
|
+
initializeSDK(Environment.Local);
|
|
344
369
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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
|
-
|
|
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
|
-
|
|
427
|
-
|
|
428
|
-
The SDK provides comprehensive error handling:
|
|
519
|
+
### Complete Off-Ramp Flow Example
|
|
429
520
|
|
|
430
521
|
```typescript
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
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
|
-
|
|
533
|
+
dotenv.config();
|
|
441
534
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
535
|
+
async function main() {
|
|
536
|
+
// Step 1: Initialize SDK
|
|
537
|
+
console.log('š Initializing PAJ Ramp SDK...');
|
|
538
|
+
initializeSDK(Environment.Local);
|
|
445
539
|
|
|
446
|
-
|
|
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
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
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
|
-
'
|
|
474
|
-
|
|
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
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
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(
|
|
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
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
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
|
|
2
|
-
|
|
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
|
-
|
|
15
|
-
|
|
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 {};
|