carbon-baas-sdk 1.0.3 → 1.0.5
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 +91 -17
- package/dist/accounts.d.ts +13 -2
- package/dist/config.d.ts +5 -0
- package/dist/customers.d.ts +1 -1
- package/dist/index.cjs.js +1268 -697
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.esm.js +1267 -698
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +1270 -700
- package/dist/index.umd.js.map +1 -1
- package/dist/payouts.d.ts +1 -0
- package/example/index.js +36 -3
- package/package.json +3 -3
- package/src/accounts.ts +24 -2
- package/src/config.ts +15 -0
- package/src/customers.ts +1 -1
- package/src/index.ts +8 -4
- package/src/payouts.ts +8 -0
- package/tests/accounts.test.ts +196 -0
package/README.md
CHANGED
|
@@ -22,8 +22,12 @@ const carbon = require('carbon-baas-sdk');
|
|
|
22
22
|
|
|
23
23
|
carbon.initialize('your_api_key_here', 'sandbox');
|
|
24
24
|
|
|
25
|
-
// Create an account
|
|
26
|
-
carbon.createAccount(
|
|
25
|
+
// Create an account for a third-party customer
|
|
26
|
+
carbon.createAccount({
|
|
27
|
+
account_type: 'static',
|
|
28
|
+
third_party: true,
|
|
29
|
+
customer_id: 'customer_123'
|
|
30
|
+
})
|
|
27
31
|
.then(response => console.log(response))
|
|
28
32
|
.catch(error => console.error(error));
|
|
29
33
|
|
|
@@ -31,26 +35,44 @@ carbon.createAccount('customer_id', 'static')
|
|
|
31
35
|
carbon.fetchAccount('account_number')
|
|
32
36
|
.then(response => console.log(response))
|
|
33
37
|
.catch(error => console.error(error));
|
|
38
|
+
|
|
39
|
+
// Fetch all accounts with pagination
|
|
40
|
+
carbon.fetchAccounts(1, 10) // page 1, limit 10
|
|
41
|
+
.then(response => console.log(response))
|
|
42
|
+
.catch(error => console.error(error));
|
|
43
|
+
|
|
44
|
+
// Fetch account balance
|
|
45
|
+
carbon.fetchAccountBalance('account_number')
|
|
46
|
+
.then(response => console.log(response))
|
|
47
|
+
.catch(error => console.error(error));
|
|
34
48
|
```
|
|
35
49
|
|
|
36
50
|
### ES Modules
|
|
37
51
|
|
|
38
52
|
```javascript
|
|
39
|
-
import { initialize, createAccount, fetchAccount } from 'carbon-baas-sdk';
|
|
53
|
+
import { initialize, createAccount, fetchAccount, fetchAccounts, fetchAccountBalance } from 'carbon-baas-sdk';
|
|
40
54
|
|
|
41
55
|
initialize('your_api_key_here', 'sandbox');
|
|
42
56
|
|
|
43
|
-
// Create an account
|
|
44
|
-
const account = await createAccount(
|
|
57
|
+
// Create an account for a third-party customer
|
|
58
|
+
const account = await createAccount({
|
|
59
|
+
account_type: 'static',
|
|
60
|
+
third_party: true,
|
|
61
|
+
customer_id: 'customer_123'
|
|
62
|
+
});
|
|
45
63
|
console.log(account);
|
|
46
64
|
|
|
47
65
|
// Fetch an account
|
|
48
66
|
const accountDetails = await fetchAccount('account_number');
|
|
49
67
|
console.log(accountDetails);
|
|
50
68
|
|
|
51
|
-
//Fetch accounts
|
|
52
|
-
const accounts = await fetchAccounts(page
|
|
69
|
+
// Fetch accounts
|
|
70
|
+
const accounts = await fetchAccounts(1, 10); // page 1, limit 10
|
|
53
71
|
console.log(accounts);
|
|
72
|
+
|
|
73
|
+
// Fetch account balance
|
|
74
|
+
const balance = await fetchAccountBalance('account_number');
|
|
75
|
+
console.log(balance);
|
|
54
76
|
```
|
|
55
77
|
|
|
56
78
|
```javascript
|
|
@@ -69,9 +91,18 @@ initialize(apiKey: string, mode: 'live' | 'sandbox')
|
|
|
69
91
|
### Accounts
|
|
70
92
|
```javascript
|
|
71
93
|
createAccount(accountData: CreateAccountRequest)
|
|
72
|
-
// accountData: {
|
|
94
|
+
// accountData: {
|
|
95
|
+
// account_type: "static", // Must always be "static"
|
|
96
|
+
// third_party?: boolean, // true for third-party customer, false for own business sub-account (defaults to true)
|
|
97
|
+
// customer_id?: string, // Required if third_party is true
|
|
98
|
+
// account_name?: string // Required if third_party is false
|
|
99
|
+
// }
|
|
73
100
|
|
|
74
101
|
fetchAccount(accountNumber: string)
|
|
102
|
+
|
|
103
|
+
fetchAccounts(page?: number, limit?: number)
|
|
104
|
+
|
|
105
|
+
fetchAccountBalance(accountNumber: string)
|
|
75
106
|
```
|
|
76
107
|
|
|
77
108
|
### Customers
|
|
@@ -122,6 +153,8 @@ initiatePayout(payoutData: InitiatePayoutRequest)
|
|
|
122
153
|
// }
|
|
123
154
|
|
|
124
155
|
fetchPayout(payoutId: string)
|
|
156
|
+
|
|
157
|
+
fetchPayoutsWithPendingApprovals(includeExpired?: boolean)
|
|
125
158
|
```
|
|
126
159
|
|
|
127
160
|
### Banks
|
|
@@ -136,10 +169,6 @@ fetchBanksUptime()
|
|
|
136
169
|
|
|
137
170
|
### Webhooks
|
|
138
171
|
```javascript
|
|
139
|
-
fetchWebhook()
|
|
140
|
-
|
|
141
|
-
updateWebhook(data: UpdateWebhookRequest)
|
|
142
|
-
// data: { url: string }
|
|
143
172
|
|
|
144
173
|
fetchWebhookHistory(page?: number, limit?: number)
|
|
145
174
|
|
|
@@ -150,16 +179,30 @@ resendWebhookEvent(eventId: string)
|
|
|
150
179
|
|
|
151
180
|
### Managing Accounts
|
|
152
181
|
```javascript
|
|
153
|
-
import { createAccount, fetchAccount } from 'carbon-baas-sdk';
|
|
182
|
+
import { createAccount, fetchAccount, fetchAccounts, fetchAccountBalance } from 'carbon-baas-sdk';
|
|
154
183
|
|
|
155
|
-
// Create an account
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
184
|
+
// Create an account for a third-party customer
|
|
185
|
+
const newCustomerAccount = await createAccount({
|
|
186
|
+
account_type: 'static',
|
|
187
|
+
third_party: true,
|
|
188
|
+
customer_id: 'customer_123'
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// Create a sub-account for your own business (for collections)
|
|
192
|
+
const newSubAccount = await createAccount({
|
|
193
|
+
account_type: 'static',
|
|
194
|
+
third_party: false,
|
|
195
|
+
account_name: 'Collections'
|
|
159
196
|
});
|
|
160
197
|
|
|
161
198
|
// Fetch account details
|
|
162
199
|
const accountDetails = await fetchAccount('1234567890');
|
|
200
|
+
|
|
201
|
+
// Fetch account balance
|
|
202
|
+
const balance = await fetchAccountBalance('1234567890');
|
|
203
|
+
|
|
204
|
+
// Fetch all accounts (with pagination)
|
|
205
|
+
const accounts = await fetchAccounts(1, 20); // page 1, 20 items per page
|
|
163
206
|
```
|
|
164
207
|
|
|
165
208
|
### Managing Customers
|
|
@@ -188,6 +231,37 @@ const newCustomer = await createCustomer(customerData);
|
|
|
188
231
|
const customerDetails = await fetchCustomer('customer_id');
|
|
189
232
|
```
|
|
190
233
|
|
|
234
|
+
### Managing Payouts
|
|
235
|
+
```javascript
|
|
236
|
+
import { initiatePayout, fetchPayout, fetchPayoutsWithPendingApprovals } from 'carbon-baas-sdk';
|
|
237
|
+
|
|
238
|
+
// Initiate a payout
|
|
239
|
+
const payoutData = {
|
|
240
|
+
amount: 1000,
|
|
241
|
+
source: { account_number: '1234567890' },
|
|
242
|
+
beneficiary: {
|
|
243
|
+
bank_code: '058',
|
|
244
|
+
bank_name: 'GTB',
|
|
245
|
+
account_number: '0987654321',
|
|
246
|
+
account_name: 'John Doe'
|
|
247
|
+
},
|
|
248
|
+
reference: 'payout_ref_123',
|
|
249
|
+
meta_data: { description: 'Payment for services' },
|
|
250
|
+
remark: 'Service payment'
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const payout = await initiatePayout(payoutData);
|
|
254
|
+
|
|
255
|
+
// Fetch payout details
|
|
256
|
+
const payoutDetails = await fetchPayout('payout_id');
|
|
257
|
+
|
|
258
|
+
// Fetch payouts with pending approvals
|
|
259
|
+
const pendingPayouts = await fetchPayoutsWithPendingApprovals();
|
|
260
|
+
|
|
261
|
+
// Fetch payouts with pending approvals including expired ones
|
|
262
|
+
const allPendingPayouts = await fetchPayoutsWithPendingApprovals(true);
|
|
263
|
+
```
|
|
264
|
+
|
|
191
265
|
### Managing Webhooks
|
|
192
266
|
```javascript
|
|
193
267
|
import { resendWebhookEvent, fetchWebhookHistory } from 'carbon-baas-sdk';
|
package/dist/accounts.d.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
interface CreateAccountRequest {
|
|
2
|
-
|
|
3
|
-
account_type:
|
|
2
|
+
/** Must always be "static". */
|
|
3
|
+
account_type: "static";
|
|
4
|
+
/**
|
|
5
|
+
* Set to true when creating an account for a third-party customer (business use).
|
|
6
|
+
* Set to false when creating a sub-account for your own business (collections).
|
|
7
|
+
* Defaults to true if not provided.
|
|
8
|
+
*/
|
|
9
|
+
third_party?: boolean;
|
|
10
|
+
/** Required if third_party is true. The customer to associate the account with. */
|
|
11
|
+
customer_id?: string;
|
|
12
|
+
/** Required if third_party is false. The sub-account name (e.g."SUBACCOUNT" -> BUSINESS NAME - SUBACCOUNT). */
|
|
13
|
+
account_name?: string;
|
|
4
14
|
}
|
|
5
15
|
export declare function createAccount(accountData: CreateAccountRequest): Promise<any>;
|
|
6
16
|
export declare function fetchAccount(accountNumber: string): Promise<any>;
|
|
7
17
|
export declare function fetchAccounts(page?: number, limit?: number): Promise<any>;
|
|
18
|
+
export declare function fetchAccountBalance(accountNumber: string): Promise<any>;
|
|
8
19
|
export {};
|
package/dist/config.d.ts
ADDED
package/dist/customers.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ interface CreateCustomerRequest {
|
|
|
10
10
|
state: string;
|
|
11
11
|
country: string;
|
|
12
12
|
bvn: string;
|
|
13
|
-
nin
|
|
13
|
+
nin?: string;
|
|
14
14
|
}
|
|
15
15
|
export declare function createCustomer(customerData: CreateCustomerRequest): Promise<any>;
|
|
16
16
|
export declare function fetchCustomer(customerId: string): Promise<any>;
|