carbon-baas-sdk 1.0.0
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 +236 -0
- package/dist/accounts.d.ts +7 -0
- package/dist/banks.d.ts +8 -0
- package/dist/customers.d.ts +18 -0
- package/dist/index.cjs.js +20394 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.esm.js +20376 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.umd.js +20386 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/payouts.d.ts +18 -0
- package/dist/transactions.d.ts +2 -0
- package/dist/util.d.ts +1 -0
- package/dist/webhook.d.ts +8 -0
- package/example/index.js +48 -0
- package/example/test-mcp.ts +74 -0
- package/jest.config.js +8 -0
- package/package.json +34 -0
- package/rollup.config.mjs +34 -0
- package/src/accounts.ts +26 -0
- package/src/banks.ts +44 -0
- package/src/customers.ts +47 -0
- package/src/index.ts +34 -0
- package/src/payouts.ts +36 -0
- package/src/transactions.ts +22 -0
- package/src/util.ts +9 -0
- package/src/webhook.ts +94 -0
- package/tests/customers.test.ts +88 -0
- package/tests/webhook.test.ts +91 -0
- package/tsconfig.json +115 -0
package/README.md
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# Carbon Business API SDK
|
|
2
|
+
|
|
3
|
+
This SDK provides a simple interface to interact with the Carbon Business API, allowing developers to integrate Carbon's financial services into their applications.
|
|
4
|
+
|
|
5
|
+
## API Documentation
|
|
6
|
+
[](https://documenter.getpostman.com/view/33237778/2sA2rFRzKS#37cff604-7f17-448f-afe4-2a456f8ad23a)
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install carbon-baas-sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Configuration
|
|
15
|
+
|
|
16
|
+
Initialize the SDK with your API key and mode (live or sandbox):
|
|
17
|
+
|
|
18
|
+
### CommonJS
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
const carbon = require('carbon-baas-sdk');
|
|
22
|
+
|
|
23
|
+
carbon.initialize('your_api_key_here', 'sandbox');
|
|
24
|
+
|
|
25
|
+
// Create an account
|
|
26
|
+
carbon.createAccount('customer_id', 'static')
|
|
27
|
+
.then(response => console.log(response))
|
|
28
|
+
.catch(error => console.error(error));
|
|
29
|
+
|
|
30
|
+
// Fetch an account
|
|
31
|
+
carbon.fetchAccount('account_number')
|
|
32
|
+
.then(response => console.log(response))
|
|
33
|
+
.catch(error => console.error(error));
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### ES Modules
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
import { initialize, createAccount, fetchAccount } from 'carbon-baas-sdk';
|
|
40
|
+
|
|
41
|
+
initialize('your_api_key_here', 'sandbox');
|
|
42
|
+
|
|
43
|
+
// Create an account
|
|
44
|
+
const account = await createAccount('customer_id', 'static');
|
|
45
|
+
console.log(account);
|
|
46
|
+
|
|
47
|
+
// Fetch an account
|
|
48
|
+
const accountDetails = await fetchAccount('account_number');
|
|
49
|
+
console.log(accountDetails);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
import { initialize } from 'carbon-baas-sdk';
|
|
54
|
+
|
|
55
|
+
initialize('your_api_key_here', 'sandbox');
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## API Reference
|
|
59
|
+
|
|
60
|
+
### Authentication
|
|
61
|
+
```javascript
|
|
62
|
+
initialize(apiKey: string, mode: 'live' | 'sandbox')
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Accounts
|
|
66
|
+
```javascript
|
|
67
|
+
createAccount(accountData: CreateAccountRequest)
|
|
68
|
+
// accountData: { customer_id: string, account_type: string }
|
|
69
|
+
|
|
70
|
+
fetchAccount(accountNumber: string)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Customers
|
|
74
|
+
```javascript
|
|
75
|
+
createCustomer(customerData: CreateCustomerRequest)
|
|
76
|
+
// customerData: {
|
|
77
|
+
// first_name: string;
|
|
78
|
+
// last_name: string;
|
|
79
|
+
// email: string;
|
|
80
|
+
// phone: string;
|
|
81
|
+
// dob: string;
|
|
82
|
+
// gender: string;
|
|
83
|
+
// street: string;
|
|
84
|
+
// city: string;
|
|
85
|
+
// state: string;
|
|
86
|
+
// country: string;
|
|
87
|
+
// bvn: string;
|
|
88
|
+
// nin: string;
|
|
89
|
+
// }
|
|
90
|
+
|
|
91
|
+
fetchCustomer(customerId: string)
|
|
92
|
+
|
|
93
|
+
fetchCustomers(page?: number, limit?: number)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Transactions
|
|
97
|
+
```javascript
|
|
98
|
+
verifyTransaction(accountNumber: string, reference: string)
|
|
99
|
+
|
|
100
|
+
fetchTransactions(accountNumber: string, page?: number, limit?: number)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Payouts
|
|
104
|
+
```javascript
|
|
105
|
+
initiatePayout(payoutData: InitiatePayoutRequest)
|
|
106
|
+
// payoutData: {
|
|
107
|
+
// amount: number;
|
|
108
|
+
// source: { account_number: string };
|
|
109
|
+
// beneficiary: {
|
|
110
|
+
// bank_code: string;
|
|
111
|
+
// bank_name: string;
|
|
112
|
+
// account_number: string;
|
|
113
|
+
// account_name: string;
|
|
114
|
+
// };
|
|
115
|
+
// reference: string;
|
|
116
|
+
// meta_data: object;
|
|
117
|
+
// remark: string;
|
|
118
|
+
// }
|
|
119
|
+
|
|
120
|
+
fetchPayout(payoutId: string)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Banks
|
|
124
|
+
```javascript
|
|
125
|
+
fetchBanks()
|
|
126
|
+
|
|
127
|
+
resolveAccount(accountData: ResolveAccountRequest)
|
|
128
|
+
// accountData: { account_number: string, bank_code: string }
|
|
129
|
+
|
|
130
|
+
fetchBanksUptime()
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Webhooks
|
|
134
|
+
```javascript
|
|
135
|
+
fetchWebhook()
|
|
136
|
+
|
|
137
|
+
updateWebhook(data: UpdateWebhookRequest)
|
|
138
|
+
// data: { url: string }
|
|
139
|
+
|
|
140
|
+
fetchWebhookHistory(page?: number, limit?: number)
|
|
141
|
+
|
|
142
|
+
resendWebhookEvent(eventId: string)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Example Usage
|
|
146
|
+
|
|
147
|
+
### Managing Accounts
|
|
148
|
+
```javascript
|
|
149
|
+
import { createAccount, fetchAccount } from 'carbon-baas-sdk';
|
|
150
|
+
|
|
151
|
+
// Create an account
|
|
152
|
+
const newAccount = await createAccount({
|
|
153
|
+
customer_id: 'customer_123',
|
|
154
|
+
account_type: 'static'
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// Fetch account details
|
|
158
|
+
const accountDetails = await fetchAccount('1234567890');
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Managing Customers
|
|
162
|
+
```javascript
|
|
163
|
+
import { createCustomer, fetchCustomer } from 'carbon-baas-sdk';
|
|
164
|
+
|
|
165
|
+
// Create a customer
|
|
166
|
+
const customerData = {
|
|
167
|
+
first_name: 'John',
|
|
168
|
+
last_name: 'Doe',
|
|
169
|
+
email: 'john.doe@example.com',
|
|
170
|
+
phone: '2348012345678',
|
|
171
|
+
dob: '1990-01-01',
|
|
172
|
+
gender: 'male',
|
|
173
|
+
street: '123 Main St',
|
|
174
|
+
city: 'Lagos',
|
|
175
|
+
state: 'Lagos',
|
|
176
|
+
country: 'Nigeria',
|
|
177
|
+
bvn: '12345678901',
|
|
178
|
+
nin: '12345678901'
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const newCustomer = await createCustomer(customerData);
|
|
182
|
+
|
|
183
|
+
// Fetch customer details
|
|
184
|
+
const customerDetails = await fetchCustomer('customer_id');
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Managing Webhooks
|
|
188
|
+
```javascript
|
|
189
|
+
import { updateWebhook, fetchWebhookHistory } from 'carbon-baas-sdk';
|
|
190
|
+
|
|
191
|
+
// Update webhook URL
|
|
192
|
+
const webhook = await updateWebhook({
|
|
193
|
+
url: 'https://your-webhook-endpoint.com/webhook'
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Fetch webhook history
|
|
197
|
+
const history = await fetchWebhookHistory(1, 10);
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Bank Operations
|
|
201
|
+
```javascript
|
|
202
|
+
import { fetchBanks, resolveAccount, fetchBanksUptime } from 'carbon-baas-sdk';
|
|
203
|
+
|
|
204
|
+
// Fetch all banks
|
|
205
|
+
const banks = await fetchBanks();
|
|
206
|
+
|
|
207
|
+
// Resolve account
|
|
208
|
+
const accountDetails = await resolveAccount({
|
|
209
|
+
account_number: '1234567890',
|
|
210
|
+
bank_code: '058'
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Check banks uptime
|
|
214
|
+
const uptime = await fetchBanksUptime();
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Error Handling
|
|
218
|
+
|
|
219
|
+
The SDK uses a consistent error handling pattern. All API calls return a response object that includes status and error information when applicable:
|
|
220
|
+
|
|
221
|
+
```javascript
|
|
222
|
+
try {
|
|
223
|
+
const result = await createCustomer(customerData);
|
|
224
|
+
if (result.status === 'failed') {
|
|
225
|
+
console.error('API Error:', result.message, result.errors);
|
|
226
|
+
} else {
|
|
227
|
+
console.log('Success:', result.data);
|
|
228
|
+
}
|
|
229
|
+
} catch (error) {
|
|
230
|
+
console.error('Request failed:', error);
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## License
|
|
235
|
+
|
|
236
|
+
This project is licensed under the MIT License.
|
package/dist/banks.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface ResolveAccountRequest {
|
|
2
|
+
account_number: string;
|
|
3
|
+
bank_code: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function fetchBanks(): Promise<any>;
|
|
6
|
+
export declare function resolveAccount(accountData: ResolveAccountRequest): Promise<any>;
|
|
7
|
+
export declare function fetchBanksUptime(): Promise<any>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface CreateCustomerRequest {
|
|
2
|
+
first_name: string;
|
|
3
|
+
last_name: string;
|
|
4
|
+
email: string;
|
|
5
|
+
phone: string;
|
|
6
|
+
dob: string;
|
|
7
|
+
gender: string;
|
|
8
|
+
street: string;
|
|
9
|
+
city: string;
|
|
10
|
+
state: string;
|
|
11
|
+
country: string;
|
|
12
|
+
bvn: string;
|
|
13
|
+
nin: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function createCustomer(customerData: CreateCustomerRequest): Promise<any>;
|
|
16
|
+
export declare function fetchCustomer(customerId: string): Promise<any>;
|
|
17
|
+
export declare function fetchCustomers(page?: number, limit?: number): Promise<any>;
|
|
18
|
+
export {};
|