@100pay-hq/100pay.js 1.4.12 → 1.4.13
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 +173 -122
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -61,28 +61,28 @@ yarn add @100pay-hq/100pay.js
|
|
|
61
61
|
## Quick Start
|
|
62
62
|
|
|
63
63
|
```typescript
|
|
64
|
-
import { Pay100 } from
|
|
64
|
+
import { Pay100 } from "@100pay-hq/100pay.js";
|
|
65
65
|
|
|
66
66
|
// Initialize the 100Pay client
|
|
67
67
|
const client = new Pay100({
|
|
68
|
-
publicKey:
|
|
69
|
-
secretKey:
|
|
68
|
+
publicKey: "your_public_key",
|
|
69
|
+
secretKey: "your_secret_key", // Required for server-side operations
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
// Verify a transaction
|
|
73
73
|
async function verifyTransaction(transactionId) {
|
|
74
74
|
try {
|
|
75
75
|
const result = await client.verify(transactionId);
|
|
76
|
-
|
|
77
|
-
if (result.status ===
|
|
78
|
-
console.log(
|
|
76
|
+
|
|
77
|
+
if (result.status === "success") {
|
|
78
|
+
console.log("Transaction verified:", result.data);
|
|
79
79
|
return result.data;
|
|
80
80
|
} else {
|
|
81
|
-
console.error(
|
|
81
|
+
console.error("Verification failed:", result.message);
|
|
82
82
|
return null;
|
|
83
83
|
}
|
|
84
84
|
} catch (error) {
|
|
85
|
-
console.error(
|
|
85
|
+
console.error("Error:", error.message);
|
|
86
86
|
throw error;
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -94,9 +94,9 @@ async function verifyTransaction(transactionId) {
|
|
|
94
94
|
|
|
95
95
|
```typescript
|
|
96
96
|
const client = new Pay100({
|
|
97
|
-
publicKey: string,
|
|
98
|
-
secretKey
|
|
99
|
-
baseUrl
|
|
97
|
+
publicKey: string, // Your 100Pay public API key (required)
|
|
98
|
+
secretKey: string, // Your 100Pay secret API key (required for server-side operations)
|
|
99
|
+
baseUrl: string, // Optional custom API base URL (defaults to https://api.100pay.co)
|
|
100
100
|
});
|
|
101
101
|
```
|
|
102
102
|
|
|
@@ -109,8 +109,8 @@ const result = await client.verify(transactionId);
|
|
|
109
109
|
|
|
110
110
|
**Parameters:**
|
|
111
111
|
|
|
112
|
-
| Parameter
|
|
113
|
-
|
|
112
|
+
| Parameter | Type | Description |
|
|
113
|
+
| ------------- | ------ | ------------------------------------------ |
|
|
114
114
|
| transactionId | string | The unique ID of the transaction to verify |
|
|
115
115
|
|
|
116
116
|
**Returns:**
|
|
@@ -118,7 +118,7 @@ const result = await client.verify(transactionId);
|
|
|
118
118
|
```typescript
|
|
119
119
|
interface IVerifyResponse {
|
|
120
120
|
status: "success" | "error";
|
|
121
|
-
data
|
|
121
|
+
data?: ITransactionData | null;
|
|
122
122
|
message?: string;
|
|
123
123
|
}
|
|
124
124
|
```
|
|
@@ -128,8 +128,8 @@ interface IVerifyResponse {
|
|
|
128
128
|
```typescript
|
|
129
129
|
try {
|
|
130
130
|
const result = await client.verify("tx_123456789");
|
|
131
|
-
|
|
132
|
-
if (result.status ===
|
|
131
|
+
|
|
132
|
+
if (result.status === "success") {
|
|
133
133
|
// Payment is valid
|
|
134
134
|
const { amount, currency, status } = result.data;
|
|
135
135
|
// Process order fulfillment
|
|
@@ -159,12 +159,12 @@ const subaccount = await client.subaccounts.create({
|
|
|
159
159
|
owner: {
|
|
160
160
|
name: "Partner Store",
|
|
161
161
|
email: "partner@example.com",
|
|
162
|
-
phone: "+1234567890"
|
|
162
|
+
phone: "+1234567890",
|
|
163
163
|
},
|
|
164
164
|
metadata: {
|
|
165
165
|
storeId: "store-123",
|
|
166
|
-
region: "US"
|
|
167
|
-
}
|
|
166
|
+
region: "US",
|
|
167
|
+
},
|
|
168
168
|
});
|
|
169
169
|
```
|
|
170
170
|
|
|
@@ -172,12 +172,12 @@ const subaccount = await client.subaccounts.create({
|
|
|
172
172
|
|
|
173
173
|
```typescript
|
|
174
174
|
interface CreateSubAccountData {
|
|
175
|
-
symbols: string[];
|
|
176
|
-
networks: string[];
|
|
175
|
+
symbols: string[]; // List of supported cryptocurrencies
|
|
176
|
+
networks: string[]; // List of supported blockchain networks
|
|
177
177
|
owner: {
|
|
178
|
-
name: string;
|
|
179
|
-
email: string;
|
|
180
|
-
phone: string;
|
|
178
|
+
name: string; // Owner's name
|
|
179
|
+
email: string; // Owner's email
|
|
180
|
+
phone: string; // Owner's phone number
|
|
181
181
|
};
|
|
182
182
|
metadata: Record<string, unknown>; // Custom metadata for the subaccount
|
|
183
183
|
}
|
|
@@ -196,13 +196,13 @@ interface Account {
|
|
|
196
196
|
available: number | null;
|
|
197
197
|
locked: number | null;
|
|
198
198
|
};
|
|
199
|
-
accountType: string;
|
|
200
|
-
walletType: string;
|
|
201
|
-
status: string;
|
|
199
|
+
accountType: string; // e.g. "subaccount"
|
|
200
|
+
walletType: string; // e.g. "crypto"
|
|
201
|
+
status: string; // e.g. "active"
|
|
202
202
|
_id: string;
|
|
203
|
-
name: string;
|
|
204
|
-
symbol: string;
|
|
205
|
-
decimals: string;
|
|
203
|
+
name: string; // e.g. "Tether USDT"
|
|
204
|
+
symbol: string; // e.g. "USDT"
|
|
205
|
+
decimals: string; // e.g. "18"
|
|
206
206
|
account: AccountDetails;
|
|
207
207
|
contractAddress: string;
|
|
208
208
|
logo: string;
|
|
@@ -250,21 +250,21 @@ interface Crypto {
|
|
|
250
250
|
```typescript
|
|
251
251
|
try {
|
|
252
252
|
const result = await client.subaccounts.create({
|
|
253
|
-
symbols: ["USDT", "BTC"],
|
|
253
|
+
symbols: ["USDT", "BTC"],
|
|
254
254
|
networks: ["ETHEREUM"],
|
|
255
255
|
owner: {
|
|
256
256
|
name: "Merchant Store",
|
|
257
257
|
email: "merchant@example.com",
|
|
258
|
-
phone: "+1234567890"
|
|
258
|
+
phone: "+1234567890",
|
|
259
259
|
},
|
|
260
260
|
metadata: {
|
|
261
|
-
businessType: "ecommerce"
|
|
262
|
-
}
|
|
261
|
+
businessType: "ecommerce",
|
|
262
|
+
},
|
|
263
263
|
});
|
|
264
|
-
|
|
264
|
+
|
|
265
265
|
console.log(`Created ${result.accounts.length} accounts for the subaccount`);
|
|
266
266
|
// Store wallet addresses for each account
|
|
267
|
-
result.accounts.forEach(account => {
|
|
267
|
+
result.accounts.forEach((account) => {
|
|
268
268
|
console.log(`${account.symbol} wallet: ${account.account.address}`);
|
|
269
269
|
});
|
|
270
270
|
} catch (error) {
|
|
@@ -282,7 +282,7 @@ const conversion = await client.conversion.preview({
|
|
|
282
282
|
amount: 100,
|
|
283
283
|
from_symbol: "BTC",
|
|
284
284
|
to_symbol: "USDT",
|
|
285
|
-
appId: "your_app_id" // Optional
|
|
285
|
+
appId: "your_app_id", // Optional
|
|
286
286
|
});
|
|
287
287
|
```
|
|
288
288
|
|
|
@@ -290,14 +290,18 @@ const conversion = await client.conversion.preview({
|
|
|
290
290
|
|
|
291
291
|
```typescript
|
|
292
292
|
interface CurrencyConversionPayload {
|
|
293
|
-
amount: number;
|
|
294
|
-
from_symbol
|
|
295
|
-
to_symbol
|
|
296
|
-
|
|
297
|
-
|
|
293
|
+
amount: number; // Amount to convert
|
|
294
|
+
from_symbol?: string; // Source currency symbol (snake_case)
|
|
295
|
+
to_symbol?: string; // Target currency symbol (snake_case)
|
|
296
|
+
fromSymbol?: string; // Source currency symbol (camelCase) - for backward compatibility
|
|
297
|
+
toSymbol?: string; // Target currency symbol (camelCase) - for backward compatibility
|
|
298
|
+
appId?: string; // Optional application ID
|
|
299
|
+
mode?: string; // Optional conversion mode
|
|
298
300
|
}
|
|
299
301
|
```
|
|
300
302
|
|
|
303
|
+
> **Note:** You can use either `from_symbol`/`to_symbol` (snake_case) or `fromSymbol`/`toSymbol` (camelCase). The SDK supports both formats for backward compatibility.
|
|
304
|
+
|
|
301
305
|
**Returns:**
|
|
302
306
|
|
|
303
307
|
The preview may return a simple result or an enhanced response with more details:
|
|
@@ -331,13 +335,17 @@ try {
|
|
|
331
335
|
const preview = await client.conversion.preview({
|
|
332
336
|
amount: 0.5,
|
|
333
337
|
from_symbol: "BTC",
|
|
334
|
-
to_symbol: "USDT"
|
|
338
|
+
to_symbol: "USDT",
|
|
335
339
|
});
|
|
336
|
-
|
|
340
|
+
|
|
337
341
|
if ("convertedAmount" in preview) {
|
|
338
342
|
console.log(`You will receive: ${preview.convertedAmount} USDT`);
|
|
339
|
-
console.log(
|
|
340
|
-
|
|
343
|
+
console.log(
|
|
344
|
+
`Exchange rate: 1 BTC = ${preview.toRate / preview.fromRate} USDT`
|
|
345
|
+
);
|
|
346
|
+
console.log(
|
|
347
|
+
`Total fees: ${preview.feeInUSD} USD (${preview.feeInFromCurrency} BTC)`
|
|
348
|
+
);
|
|
341
349
|
} else {
|
|
342
350
|
// Handle enhanced response
|
|
343
351
|
console.log("Enhanced conversion preview:", preview);
|
|
@@ -355,21 +363,24 @@ Transfer assets between wallets and manage transfer operations:
|
|
|
355
363
|
// Execute an asset transfer
|
|
356
364
|
const transfer = await client.transfer.executeTransfer({
|
|
357
365
|
amount: 100,
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
//
|
|
366
|
+
symbol: "USDT", // Use 'symbol' not 'currency'
|
|
367
|
+
to: "0x1234567890abcdef...", // Use 'to' not 'recipientAddress'
|
|
368
|
+
transferType: "external", // Optional: "internal" or "external"
|
|
369
|
+
note: "Payment for services", // Optional note
|
|
361
370
|
});
|
|
362
371
|
|
|
363
372
|
// Get transfer history
|
|
364
373
|
const history = await client.transfer.getHistory({
|
|
365
374
|
page: 1,
|
|
366
|
-
limit: 10
|
|
375
|
+
limit: 10,
|
|
376
|
+
symbols: ["USDT"], // Optional filter by symbols
|
|
377
|
+
type: "debit", // Optional filter by type
|
|
367
378
|
});
|
|
368
379
|
|
|
369
380
|
// Calculate transfer fees
|
|
370
381
|
const fees = await client.transfer.calculateFee({
|
|
371
|
-
|
|
372
|
-
transferType: "
|
|
382
|
+
symbol: "USDT", // Use 'symbol' not 'currency'
|
|
383
|
+
transferType: "external", // Use "internal" or "external"
|
|
373
384
|
});
|
|
374
385
|
```
|
|
375
386
|
|
|
@@ -395,12 +406,12 @@ console.log(`${bankList.data.count} banks available`);
|
|
|
395
406
|
// Verify a bank account
|
|
396
407
|
const verification = await client.bankTransfer.verifyBank({
|
|
397
408
|
bankCode: "044",
|
|
398
|
-
accountNumber: "1234567890"
|
|
409
|
+
accountNumber: "1234567890",
|
|
399
410
|
});
|
|
400
411
|
|
|
401
412
|
if (verification.data.verified) {
|
|
402
413
|
console.log(`Account verified: ${verification.data.accountName}`);
|
|
403
|
-
|
|
414
|
+
|
|
404
415
|
// Execute bank transfer
|
|
405
416
|
const transfer = await client.bankTransfer.transfer({
|
|
406
417
|
beneficiaryBankCode: "044",
|
|
@@ -409,9 +420,9 @@ if (verification.data.verified) {
|
|
|
409
420
|
amount: 500, // Amount in Naira (NGN 500)
|
|
410
421
|
narration: "Payment for services",
|
|
411
422
|
paymentReference: `ref_${Date.now()}`,
|
|
412
|
-
saveBeneficiary: true
|
|
423
|
+
saveBeneficiary: true,
|
|
413
424
|
});
|
|
414
|
-
|
|
425
|
+
|
|
415
426
|
console.log(`Transfer initiated: ${transfer.data.transfer.sessionId}`);
|
|
416
427
|
}
|
|
417
428
|
```
|
|
@@ -452,7 +463,7 @@ interface IBank {
|
|
|
452
463
|
```typescript
|
|
453
464
|
const verification = await client.bankTransfer.verifyBank({
|
|
454
465
|
bankCode: "044",
|
|
455
|
-
accountNumber: "1234567890"
|
|
466
|
+
accountNumber: "1234567890",
|
|
456
467
|
});
|
|
457
468
|
```
|
|
458
469
|
|
|
@@ -460,7 +471,7 @@ const verification = await client.bankTransfer.verifyBank({
|
|
|
460
471
|
|
|
461
472
|
```typescript
|
|
462
473
|
interface IVerifyBankData {
|
|
463
|
-
bankCode: string;
|
|
474
|
+
bankCode: string; // Bank code from the bank list
|
|
464
475
|
accountNumber: string; // Account number to verify
|
|
465
476
|
}
|
|
466
477
|
```
|
|
@@ -491,7 +502,7 @@ const transfer = await client.bankTransfer.transfer({
|
|
|
491
502
|
amount: 50000,
|
|
492
503
|
narration: "Payment description",
|
|
493
504
|
paymentReference: "unique_ref_123",
|
|
494
|
-
saveBeneficiary: true
|
|
505
|
+
saveBeneficiary: true,
|
|
495
506
|
});
|
|
496
507
|
```
|
|
497
508
|
|
|
@@ -500,45 +511,52 @@ const transfer = await client.bankTransfer.transfer({
|
|
|
500
511
|
#### Get Authorization URL
|
|
501
512
|
|
|
502
513
|
```typescript
|
|
503
|
-
const authUrl = client.oauth.getAuthorizationUrl({
|
|
504
|
-
|
|
514
|
+
const authUrl = await client.oauth.getAuthorizationUrl({
|
|
515
|
+
client_id: "your_client_id",
|
|
516
|
+
redirect_uri: "https://yourapp.com/callback",
|
|
505
517
|
scope: "read_user_info read_app_info",
|
|
506
|
-
state: "some_random_state"
|
|
518
|
+
state: "some_random_state",
|
|
507
519
|
});
|
|
508
520
|
```
|
|
509
521
|
|
|
510
|
-
####
|
|
522
|
+
#### Exchange Code for Access Token
|
|
511
523
|
|
|
512
524
|
```typescript
|
|
513
|
-
const
|
|
525
|
+
const tokenResponse = await client.oauth.exchangeCodeForToken({
|
|
526
|
+
grant_type: "authorization_code",
|
|
514
527
|
code: "authorization_code",
|
|
515
|
-
|
|
528
|
+
client_id: "your_client_id",
|
|
529
|
+
client_secret: "your_client_secret",
|
|
530
|
+
redirect_uri: "https://yourapp.com/callback",
|
|
516
531
|
});
|
|
532
|
+
const tokenData = tokenResponse.data;
|
|
517
533
|
```
|
|
518
534
|
|
|
519
535
|
#### Get User Info
|
|
520
536
|
|
|
521
537
|
```typescript
|
|
522
|
-
const
|
|
538
|
+
const userInfoResponse = await client.oauth.getUserInfo(tokenData.access_token);
|
|
539
|
+
const userInfo = userInfoResponse.data;
|
|
523
540
|
```
|
|
524
541
|
|
|
525
542
|
#### Get App Info
|
|
526
543
|
|
|
527
544
|
```typescript
|
|
528
|
-
const
|
|
545
|
+
const appInfoResponse = await client.oauth.getAppInfo(tokenData.access_token);
|
|
546
|
+
const appInfo = appInfoResponse.data;
|
|
529
547
|
```
|
|
530
548
|
|
|
531
549
|
**Parameters:**
|
|
532
550
|
|
|
533
551
|
```typescript
|
|
534
552
|
interface IBankTransferData {
|
|
535
|
-
beneficiaryBankCode: string;
|
|
553
|
+
beneficiaryBankCode: string; // Recipient's bank code
|
|
536
554
|
beneficiaryAccountNumber: string; // Recipient's account number
|
|
537
|
-
beneficiaryAccountName: string;
|
|
538
|
-
amount: number;
|
|
539
|
-
narration: string;
|
|
540
|
-
paymentReference: string;
|
|
541
|
-
saveBeneficiary: boolean;
|
|
555
|
+
beneficiaryAccountName: string; // Recipient's account name
|
|
556
|
+
amount: number; // Amount in Naira
|
|
557
|
+
narration: string; // Transfer description
|
|
558
|
+
paymentReference: string; // Unique payment reference
|
|
559
|
+
saveBeneficiary: boolean; // Whether to save this beneficiary
|
|
542
560
|
}
|
|
543
561
|
```
|
|
544
562
|
|
|
@@ -569,23 +587,33 @@ The SDK provides methods for OAuth 2.0 authorization:
|
|
|
569
587
|
|
|
570
588
|
```typescript
|
|
571
589
|
// Get authorization URL
|
|
572
|
-
const authUrl = client.oauth.getAuthorizationUrl({
|
|
573
|
-
|
|
590
|
+
const authUrl = await client.oauth.getAuthorizationUrl({
|
|
591
|
+
client_id: "your_client_id",
|
|
592
|
+
redirect_uri: "https://yourapp.com/callback",
|
|
574
593
|
scope: "read_user_info read_app_info",
|
|
575
|
-
state: "some_random_state"
|
|
594
|
+
state: "some_random_state",
|
|
576
595
|
});
|
|
577
596
|
|
|
578
|
-
//
|
|
579
|
-
const
|
|
597
|
+
// Exchange code for access token
|
|
598
|
+
const tokenResponse = await client.oauth.exchangeCodeForToken({
|
|
599
|
+
grant_type: "authorization_code",
|
|
580
600
|
code: "authorization_code",
|
|
581
|
-
|
|
601
|
+
client_id: "your_client_id",
|
|
602
|
+
client_secret: "your_client_secret",
|
|
603
|
+
redirect_uri: "https://yourapp.com/callback",
|
|
582
604
|
});
|
|
583
605
|
|
|
584
606
|
// Get user info
|
|
585
|
-
const
|
|
607
|
+
const userInfoResponse = await client.oauth.getUserInfo(
|
|
608
|
+
tokenResponse.data.access_token
|
|
609
|
+
);
|
|
610
|
+
const userInfo = userInfoResponse.data;
|
|
586
611
|
|
|
587
612
|
// Get app info
|
|
588
|
-
const
|
|
613
|
+
const appInfoResponse = await client.oauth.getAppInfo(
|
|
614
|
+
tokenResponse.data.access_token
|
|
615
|
+
);
|
|
616
|
+
const appInfo = appInfoResponse.data;
|
|
589
617
|
```
|
|
590
618
|
|
|
591
619
|
### Generic API Requests
|
|
@@ -594,9 +622,9 @@ The SDK provides a generic `request` method for making any API call to the 100Pa
|
|
|
594
622
|
|
|
595
623
|
```typescript
|
|
596
624
|
const response = await client.request<ResponseType>(
|
|
597
|
-
method,
|
|
625
|
+
method, // 'GET', 'POST', 'PUT', or 'DELETE'
|
|
598
626
|
endpoint, // API endpoint path
|
|
599
|
-
data
|
|
627
|
+
data // Request payload
|
|
600
628
|
);
|
|
601
629
|
```
|
|
602
630
|
|
|
@@ -605,8 +633,8 @@ const response = await client.request<ResponseType>(
|
|
|
605
633
|
```typescript
|
|
606
634
|
// Get user app balance
|
|
607
635
|
const balance = await client.request<BalanceResponse>(
|
|
608
|
-
|
|
609
|
-
|
|
636
|
+
"GET",
|
|
637
|
+
"/api/v1/user-apps/:appId/wallet-balance/:symbol"
|
|
610
638
|
);
|
|
611
639
|
```
|
|
612
640
|
|
|
@@ -644,14 +672,25 @@ Client-side operations can use public key only, while server-side operations req
|
|
|
644
672
|
This package is built with TypeScript and includes full type definitions. The main types are exported for your convenience:
|
|
645
673
|
|
|
646
674
|
```typescript
|
|
647
|
-
import {
|
|
648
|
-
Pay100,
|
|
649
|
-
PaymentVerificationError,
|
|
675
|
+
import {
|
|
676
|
+
Pay100,
|
|
677
|
+
PaymentVerificationError,
|
|
678
|
+
ITransactionData,
|
|
679
|
+
IVerifyResponse,
|
|
650
680
|
CreateSubAccountData,
|
|
681
|
+
CreateSubAccountResponse,
|
|
651
682
|
CurrencyConversionPayload,
|
|
652
683
|
CurrencyConversionResult,
|
|
684
|
+
EnhancedConversionResponse,
|
|
653
685
|
Account,
|
|
654
686
|
AccountDetails,
|
|
687
|
+
ITransferAssetData,
|
|
688
|
+
ITransferAssetResponse,
|
|
689
|
+
ITransferHistoryParams,
|
|
690
|
+
ITransferHistoryResponse,
|
|
691
|
+
ITransferFeeParams,
|
|
692
|
+
ITransferFeeResponse,
|
|
693
|
+
ISupportedWalletResponse,
|
|
655
694
|
IBankListResponse,
|
|
656
695
|
IBankTransferData,
|
|
657
696
|
IBankTransferResponse,
|
|
@@ -660,8 +699,8 @@ import {
|
|
|
660
699
|
IOAuthApp,
|
|
661
700
|
ITokenData,
|
|
662
701
|
IUserInfo,
|
|
663
|
-
IAppInfo
|
|
664
|
-
} from
|
|
702
|
+
IAppInfo,
|
|
703
|
+
} from "@100pay-hq/100pay.js";
|
|
665
704
|
```
|
|
666
705
|
|
|
667
706
|
## Common Use Cases
|
|
@@ -681,16 +720,16 @@ const subaccount = await client.subaccounts.create({
|
|
|
681
720
|
owner: {
|
|
682
721
|
name: "Partner Name",
|
|
683
722
|
email: "partner@example.com",
|
|
684
|
-
phone: "+1234567890"
|
|
723
|
+
phone: "+1234567890",
|
|
685
724
|
},
|
|
686
725
|
metadata: {
|
|
687
|
-
partnerId: "partner-123"
|
|
688
|
-
}
|
|
726
|
+
partnerId: "partner-123",
|
|
727
|
+
},
|
|
689
728
|
});
|
|
690
729
|
|
|
691
730
|
// Save the subaccount information for future use
|
|
692
731
|
console.log(`Created subaccount with ${subaccount.accounts.length} wallets`);
|
|
693
|
-
subaccount.accounts.forEach(account => {
|
|
732
|
+
subaccount.accounts.forEach((account) => {
|
|
694
733
|
console.log(`${account.symbol} wallet: ${account.account.address}`);
|
|
695
734
|
});
|
|
696
735
|
```
|
|
@@ -702,14 +741,18 @@ subaccount.accounts.forEach(account => {
|
|
|
702
741
|
const preview = await client.conversion.preview({
|
|
703
742
|
amount: 1000,
|
|
704
743
|
from_symbol: "USDT",
|
|
705
|
-
to_symbol: "BTC"
|
|
744
|
+
to_symbol: "BTC",
|
|
706
745
|
});
|
|
707
746
|
|
|
708
747
|
// Show user the conversion details
|
|
709
748
|
if ("convertedAmount" in preview) {
|
|
710
749
|
console.log(`You will receive approximately ${preview.convertedAmount} BTC`);
|
|
711
|
-
console.log(
|
|
712
|
-
|
|
750
|
+
console.log(
|
|
751
|
+
`Exchange rate: 1 USDT = ${preview.toRate / preview.fromRate} BTC`
|
|
752
|
+
);
|
|
753
|
+
console.log(
|
|
754
|
+
`Fee: ${preview.feeInFromCurrency} USDT (${preview.feeInUSD} USD)`
|
|
755
|
+
);
|
|
713
756
|
} else {
|
|
714
757
|
// Handle enhanced response
|
|
715
758
|
console.log("Enhanced conversion preview:", preview);
|
|
@@ -725,23 +768,25 @@ async function performBankTransfer() {
|
|
|
725
768
|
// 1. Get available banks
|
|
726
769
|
const banks = await client.bankTransfer.getBankList();
|
|
727
770
|
console.log(`Available banks: ${banks.data.count}`);
|
|
728
|
-
|
|
771
|
+
|
|
729
772
|
// 2. Find the desired bank
|
|
730
|
-
const targetBank = banks.data.banks.find(bank =>
|
|
773
|
+
const targetBank = banks.data.banks.find((bank) =>
|
|
774
|
+
bank.name?.includes("Access")
|
|
775
|
+
);
|
|
731
776
|
if (!targetBank) throw new Error("Bank not found");
|
|
732
|
-
|
|
777
|
+
|
|
733
778
|
// 3. Verify the recipient's account
|
|
734
779
|
const verification = await client.bankTransfer.verifyBank({
|
|
735
780
|
bankCode: targetBank.bankCode!,
|
|
736
|
-
accountNumber: "1234567890"
|
|
781
|
+
accountNumber: "1234567890",
|
|
737
782
|
});
|
|
738
|
-
|
|
783
|
+
|
|
739
784
|
if (!verification.data.verified) {
|
|
740
785
|
throw new Error("Account verification failed");
|
|
741
786
|
}
|
|
742
|
-
|
|
787
|
+
|
|
743
788
|
console.log(`Account verified: ${verification.data.accountName}`);
|
|
744
|
-
|
|
789
|
+
|
|
745
790
|
// 4. Execute the transfer
|
|
746
791
|
const transfer = await client.bankTransfer.transfer({
|
|
747
792
|
beneficiaryBankCode: targetBank.bankCode!,
|
|
@@ -750,12 +795,11 @@ async function performBankTransfer() {
|
|
|
750
795
|
amount: 500, // NGN 500 in Naira
|
|
751
796
|
narration: "Payment for services rendered",
|
|
752
797
|
paymentReference: `PAY_${Date.now()}`,
|
|
753
|
-
saveBeneficiary: true
|
|
798
|
+
saveBeneficiary: true,
|
|
754
799
|
});
|
|
755
|
-
|
|
800
|
+
|
|
756
801
|
console.log(`Transfer successful: ${transfer.data.transfer.sessionId}`);
|
|
757
802
|
return transfer.data.transfer;
|
|
758
|
-
|
|
759
803
|
} catch (error) {
|
|
760
804
|
console.error(`Bank transfer failed: ${error.message}`);
|
|
761
805
|
throw error;
|
|
@@ -770,27 +814,34 @@ async function performBankTransfer() {
|
|
|
770
814
|
async function performOAuth() {
|
|
771
815
|
try {
|
|
772
816
|
// 1. Get authorization URL
|
|
773
|
-
const authUrl = client.oauth.getAuthorizationUrl({
|
|
774
|
-
|
|
817
|
+
const authUrl = await client.oauth.getAuthorizationUrl({
|
|
818
|
+
client_id: "your_client_id",
|
|
819
|
+
redirect_uri: "https://yourapp.com/callback",
|
|
775
820
|
scope: "read_user_info read_app_info",
|
|
776
|
-
state: "some_random_state"
|
|
821
|
+
state: "some_random_state",
|
|
777
822
|
});
|
|
778
823
|
console.log(`Authorization URL: ${authUrl}`);
|
|
779
|
-
|
|
780
|
-
// 2.
|
|
781
|
-
const
|
|
824
|
+
|
|
825
|
+
// 2. Exchange code for access token
|
|
826
|
+
const tokenResponse = await client.oauth.exchangeCodeForToken({
|
|
827
|
+
grant_type: "authorization_code",
|
|
782
828
|
code: "authorization_code",
|
|
783
|
-
|
|
829
|
+
client_id: "your_client_id",
|
|
830
|
+
client_secret: "your_client_secret",
|
|
831
|
+
redirect_uri: "https://yourapp.com/callback",
|
|
784
832
|
});
|
|
785
|
-
|
|
833
|
+
|
|
786
834
|
// 3. Get user info
|
|
787
|
-
const
|
|
788
|
-
|
|
789
|
-
|
|
835
|
+
const userInfoResponse = await client.oauth.getUserInfo(
|
|
836
|
+
tokenResponse.data.access_token
|
|
837
|
+
);
|
|
838
|
+
console.log(`User info:`, userInfoResponse.data);
|
|
839
|
+
|
|
790
840
|
// 4. Get app info
|
|
791
|
-
const
|
|
792
|
-
|
|
793
|
-
|
|
841
|
+
const appInfoResponse = await client.oauth.getAppInfo(
|
|
842
|
+
tokenResponse.data.access_token
|
|
843
|
+
);
|
|
844
|
+
console.log(`App info:`, appInfoResponse.data);
|
|
794
845
|
} catch (error) {
|
|
795
846
|
console.error(`OAuth workflow failed: ${error.message}`);
|
|
796
847
|
throw error;
|
|
@@ -835,7 +886,7 @@ interface BankTransferWebhook {
|
|
|
835
886
|
**Webhook Event Types:**
|
|
836
887
|
|
|
837
888
|
- `bank_transfer.debit` - Outgoing bank transfer initiated
|
|
838
|
-
- `bank_transfer.credit` - Incoming bank transfer received
|
|
889
|
+
- `bank_transfer.credit` - Incoming bank transfer received
|
|
839
890
|
- `wallet.deposit` - Wallet deposit received
|
|
840
891
|
- `wallet.deposit.internal` - Internal wallet deposit received
|
|
841
892
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@100pay-hq/100pay.js",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.13",
|
|
4
4
|
"description": "100Pay.js is the official Nodejs API wrapper SDK that lets you easily verify crypto payments, run bulk payout, transfer assets and many more.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|