@maxkabechani/mtn-momo-sdk 0.1.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/LICENSE +21 -0
- package/README.md +187 -0
- package/lib/cjs/auth.d.ts +17 -0
- package/lib/cjs/auth.d.ts.map +1 -0
- package/lib/cjs/auth.js +86 -0
- package/lib/cjs/auth.js.map +1 -0
- package/lib/cjs/cli.d.ts +3 -0
- package/lib/cjs/cli.d.ts.map +1 -0
- package/lib/cjs/cli.js +66 -0
- package/lib/cjs/cli.js.map +1 -0
- package/lib/cjs/client.d.ts +7 -0
- package/lib/cjs/client.d.ts.map +1 -0
- package/lib/cjs/client.js +67 -0
- package/lib/cjs/client.js.map +1 -0
- package/lib/cjs/collections.d.ts +176 -0
- package/lib/cjs/collections.d.ts.map +1 -0
- package/lib/cjs/collections.js +219 -0
- package/lib/cjs/collections.js.map +1 -0
- package/lib/cjs/common.d.ts +299 -0
- package/lib/cjs/common.d.ts.map +1 -0
- package/lib/cjs/common.js +41 -0
- package/lib/cjs/common.js.map +1 -0
- package/lib/cjs/disbursements.d.ts +190 -0
- package/lib/cjs/disbursements.d.ts.map +1 -0
- package/lib/cjs/disbursements.js +268 -0
- package/lib/cjs/disbursements.js.map +1 -0
- package/lib/cjs/errors.d.ts +67 -0
- package/lib/cjs/errors.d.ts.map +1 -0
- package/lib/cjs/errors.js +207 -0
- package/lib/cjs/errors.js.map +1 -0
- package/lib/cjs/index.d.ts +24 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/index.js +87 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/remittance.d.ts +59 -0
- package/lib/cjs/remittance.d.ts.map +1 -0
- package/lib/cjs/remittance.js +145 -0
- package/lib/cjs/remittance.js.map +1 -0
- package/lib/cjs/users.d.ts +22 -0
- package/lib/cjs/users.d.ts.map +1 -0
- package/lib/cjs/users.js +42 -0
- package/lib/cjs/users.js.map +1 -0
- package/lib/cjs/validate.d.ts +14 -0
- package/lib/cjs/validate.d.ts.map +1 -0
- package/lib/cjs/validate.js +111 -0
- package/lib/cjs/validate.js.map +1 -0
- package/lib/esm/auth.d.ts +17 -0
- package/lib/esm/auth.d.ts.map +1 -0
- package/lib/esm/auth.js +78 -0
- package/lib/esm/auth.js.map +1 -0
- package/lib/esm/cli.d.ts +3 -0
- package/lib/esm/cli.d.ts.map +1 -0
- package/lib/esm/cli.js +31 -0
- package/lib/esm/cli.js.map +1 -0
- package/lib/esm/client.d.ts +7 -0
- package/lib/esm/client.d.ts.map +1 -0
- package/lib/esm/client.js +29 -0
- package/lib/esm/client.js.map +1 -0
- package/lib/esm/collections.d.ts +176 -0
- package/lib/esm/collections.d.ts.map +1 -0
- package/lib/esm/collections.js +216 -0
- package/lib/esm/collections.js.map +1 -0
- package/lib/esm/common.d.ts +299 -0
- package/lib/esm/common.d.ts.map +1 -0
- package/lib/esm/common.js +38 -0
- package/lib/esm/common.js.map +1 -0
- package/lib/esm/disbursements.d.ts +190 -0
- package/lib/esm/disbursements.d.ts.map +1 -0
- package/lib/esm/disbursements.js +265 -0
- package/lib/esm/disbursements.js.map +1 -0
- package/lib/esm/errors.d.ts +67 -0
- package/lib/esm/errors.d.ts.map +1 -0
- package/lib/esm/errors.js +182 -0
- package/lib/esm/errors.js.map +1 -0
- package/lib/esm/index.d.ts +24 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +63 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/remittance.d.ts +59 -0
- package/lib/esm/remittance.d.ts.map +1 -0
- package/lib/esm/remittance.js +142 -0
- package/lib/esm/remittance.js.map +1 -0
- package/lib/esm/users.d.ts +22 -0
- package/lib/esm/users.d.ts.map +1 -0
- package/lib/esm/users.js +39 -0
- package/lib/esm/users.js.map +1 -0
- package/lib/esm/validate.d.ts +14 -0
- package/lib/esm/validate.d.ts.map +1 -0
- package/lib/esm/validate.js +100 -0
- package/lib/esm/validate.js.map +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Max Kabechani
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# MTN MoMo Node SDK (@maxkabechani/mtn-momo-sdk)
|
|
2
|
+
|
|
3
|
+
TypeScript-first MTN Mobile Money client for Node.js. Fully compatible with official MoMo API v1.0 and v2.0.
|
|
4
|
+
|
|
5
|
+
This SDK provides a type-safe, developer-friendly interface for integrating MTN Mobile Money into your applications. It supports **Collections**, **Disbursements**, and **Remittance** products.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Coexistence of V1 & V2**: Use stable V1 endpoints by default or opt-in to latest V2 features (e.g., `depositV2`).
|
|
12
|
+
- **Comprehensive Coverage**: Supporting everything from simple transfers to biometric consent (BC Authorize).
|
|
13
|
+
- **TypeScript First**: Full type definitions for all requests and responses.
|
|
14
|
+
- **Bun & Node.js**: Optimized for modern runtimes.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @maxkabechani/mtn-momo-sdk
|
|
22
|
+
# or
|
|
23
|
+
bun add @maxkabechani/mtn-momo-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Quick Start (Sandbox)
|
|
29
|
+
|
|
30
|
+
### 1. Initialize the Client
|
|
31
|
+
```ts
|
|
32
|
+
import { create, Environment } from "@maxkabechani/mtn-momo-sdk";
|
|
33
|
+
|
|
34
|
+
const momo = create({
|
|
35
|
+
callbackHost: "yourdomain.com", // Used for callback validation
|
|
36
|
+
environment: Environment.SANDBOX,
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 2. Configure a Product
|
|
41
|
+
Each product (Collections, Disbursements, Remittance) is initialized separately:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
const collections = momo.Collections({
|
|
45
|
+
primaryKey: "your_collections_primary_key",
|
|
46
|
+
userId: "your_user_id",
|
|
47
|
+
userSecret: "your_user_secret",
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 3. Generate Sandbox Credentials
|
|
52
|
+
If you don't have a `userId` and `userSecret` yet, you can generate them using our CLI tool:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npx momo-sandbox --host yourdomain.com --primary-key YOUR_PRIMARY_KEY
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## API Reference
|
|
61
|
+
|
|
62
|
+
### Collections
|
|
63
|
+
Manage incoming payments and withdrawals.
|
|
64
|
+
|
|
65
|
+
#### `requestToPay(request: PaymentRequest)`
|
|
66
|
+
Requests a payment from a consumer.
|
|
67
|
+
- **Arguments**:
|
|
68
|
+
- `amount`: `string` (e.g., "100.00")
|
|
69
|
+
- `currency`: `string` (e.g., "EUR")
|
|
70
|
+
- `externalId`: `string` (Optional, for reconciliation)
|
|
71
|
+
- `payer`: `{ partyIdType: 'MSISDN' | 'EMAIL' | 'PARTY_CODE', partyId: string }`
|
|
72
|
+
- `payerMessage`: `string` (Optional, shown in payer history)
|
|
73
|
+
- `payeeNote`: `string` (Optional, shown in your history)
|
|
74
|
+
- `callbackUrl`: `string` (Optional, overrides global callback host)
|
|
75
|
+
|
|
76
|
+
#### `getTransaction(referenceId: string)`
|
|
77
|
+
Retrieves status of a payment request. Returns a `Payment` object with `status` (`PENDING`, `SUCCESSFUL`, `FAILED`).
|
|
78
|
+
|
|
79
|
+
#### `getBalance()`
|
|
80
|
+
Returns `{ availableBalance: string, currency: string }`.
|
|
81
|
+
|
|
82
|
+
#### `requestToWithdrawV2(request: WithdrawalRequest)`
|
|
83
|
+
Initiates a withdrawal from a payer account using V2 specs.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
### Disbursements
|
|
88
|
+
Manage payouts, deposits, and refunds.
|
|
89
|
+
|
|
90
|
+
#### `transfer(request: TransferRequest)`
|
|
91
|
+
Transfers money from your account to a payee.
|
|
92
|
+
- **Arguments**:
|
|
93
|
+
- `amount`, `currency`, `externalId`: Same as Collections.
|
|
94
|
+
- `payee`: `{ partyIdType: 'MSISDN' | 'EMAIL' | 'PARTY_CODE', partyId: string }`
|
|
95
|
+
- `payerMessage`, `payeeNote`, `callbackUrl`: Same as Collections.
|
|
96
|
+
|
|
97
|
+
#### `depositV2(request: DepositRequest)`
|
|
98
|
+
Deposits money into a payee account using V2 specs.
|
|
99
|
+
|
|
100
|
+
#### `refundV2(request: RefundRequest)`
|
|
101
|
+
Refunds a previous transaction.
|
|
102
|
+
- **Arguments**:
|
|
103
|
+
- `amount`, `currency`, `externalId`, `payerMessage`, `payeeNote`
|
|
104
|
+
- `referenceIdToRefund`: `string` (The original transaction ID)
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
### Remittance
|
|
109
|
+
Manage cross-border transfers.
|
|
110
|
+
|
|
111
|
+
#### `transfer(request: CashTransferRequest)`
|
|
112
|
+
- **Additional Arguments**:
|
|
113
|
+
- `originatingCountry`: `string` (ISO code)
|
|
114
|
+
- `originalAmount`: `string`
|
|
115
|
+
- `originalCurrency`: `string`
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Going Live (Production)
|
|
120
|
+
|
|
121
|
+
Transitioning from Sandbox to Production requires a few changes:
|
|
122
|
+
|
|
123
|
+
1. **Environment Flag**:
|
|
124
|
+
Change `Environment.SANDBOX` to `Environment.PRODUCTION`.
|
|
125
|
+
```ts
|
|
126
|
+
const momo = create({
|
|
127
|
+
callbackHost: "production-api.yoursite.com",
|
|
128
|
+
environment: Environment.PRODUCTION,
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
2. **Production Credentials**:
|
|
133
|
+
- Get your **Primary Key** from the [MTN MoMo Developer Portal](https://momodeveloper.mtn.com/).
|
|
134
|
+
- Obtain your production **User ID** and **User Secret** through the official onboarding process in your specific region.
|
|
135
|
+
|
|
136
|
+
3. **Endpoints**:
|
|
137
|
+
The SDK handles the URL switch automatically when `Environment.PRODUCTION` is set.
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Environment Variables
|
|
142
|
+
|
|
143
|
+
For security, it is highly recommended to store your credentials in environment variables (e.g., using `dotenv`):
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
# Collections
|
|
147
|
+
COLLECTIONS_PRIMARY_KEY=your_key
|
|
148
|
+
COLLECTIONS_USER_ID=your_id
|
|
149
|
+
COLLECTIONS_USER_SECRET=your_secret
|
|
150
|
+
|
|
151
|
+
# Disbursements
|
|
152
|
+
DISBURSEMENTS_PRIMARY_KEY=your_key
|
|
153
|
+
DISBURSEMENTS_USER_ID=your_id
|
|
154
|
+
DISBURSEMENTS_USER_SECRET=your_secret
|
|
155
|
+
|
|
156
|
+
# Remittance
|
|
157
|
+
REMITTANCE_PRIMARY_KEY=your_key
|
|
158
|
+
REMITTANCE_USER_ID=your_id
|
|
159
|
+
REMITTANCE_USER_SECRET=your_secret
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Usage in your application:
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import "dotenv/config";
|
|
166
|
+
|
|
167
|
+
const collections = momo.Collections({
|
|
168
|
+
primaryKey: process.env.COLLECTIONS_PRIMARY_KEY!,
|
|
169
|
+
userId: process.env.COLLECTIONS_USER_ID!,
|
|
170
|
+
userSecret: process.env.COLLECTIONS_USER_SECRET!,
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Development & Testing
|
|
177
|
+
|
|
178
|
+
We use [Bun](https://bun.sh) for efficient development.
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
bun install
|
|
182
|
+
bun run test # Run unit tests
|
|
183
|
+
bun run build # Build for production (ESM/CJS)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## License
|
|
187
|
+
ISC
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AxiosInstance } from "axios";
|
|
2
|
+
import type { AccessToken, Config, UserConfig } from "./common";
|
|
3
|
+
export type TokenRefresher = () => Promise<string>;
|
|
4
|
+
export interface AuthorizerOptions {
|
|
5
|
+
grant_type?: string;
|
|
6
|
+
refresh_token?: string;
|
|
7
|
+
}
|
|
8
|
+
export type Authorizer = (config: Config, options?: AuthorizerOptions, client?: AxiosInstance) => Promise<AccessToken & {
|
|
9
|
+
refresh_token?: string;
|
|
10
|
+
refresh_token_expired_in?: number;
|
|
11
|
+
}>;
|
|
12
|
+
export declare function createTokenRefresher(authorize: Authorizer, config: Config): TokenRefresher;
|
|
13
|
+
export declare const authorizeCollections: Authorizer;
|
|
14
|
+
export declare const authorizeDisbursements: Authorizer;
|
|
15
|
+
export declare const authorizeRemittance: Authorizer;
|
|
16
|
+
export declare function createBasicAuthToken(config: UserConfig): string;
|
|
17
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEhE,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;AAEnD,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,UAAU,GAAG,CACvB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,iBAAiB,EAC3B,MAAM,CAAC,EAAE,aAAa,KACnB,OAAO,CAAC,WAAW,GAAG;IAAE,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,wBAAwB,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAS1F,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,MAAM,GACb,cAAc,CAmChB;AASD,eAAO,MAAM,oBAAoB,EAAE,UAalC,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,UAapC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,UAajC,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAI/D"}
|
package/lib/cjs/auth.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.authorizeRemittance = exports.authorizeDisbursements = exports.authorizeCollections = void 0;
|
|
4
|
+
exports.createTokenRefresher = createTokenRefresher;
|
|
5
|
+
exports.createBasicAuthToken = createBasicAuthToken;
|
|
6
|
+
const client_1 = require("./client");
|
|
7
|
+
function createTokenRefresher(authorize, config) {
|
|
8
|
+
let credentials;
|
|
9
|
+
return () => {
|
|
10
|
+
if (isExpired(credentials)) {
|
|
11
|
+
const isRefreshTokenValid = credentials?.refreshToken && !isRefreshExpired(credentials);
|
|
12
|
+
const options = isRefreshTokenValid
|
|
13
|
+
? { grant_type: 'refresh_token', refresh_token: credentials.refreshToken }
|
|
14
|
+
: { grant_type: 'client_credentials' };
|
|
15
|
+
return authorize(config, options)
|
|
16
|
+
.then((tokenData) => {
|
|
17
|
+
const { access_token, expires_in, refresh_token, refresh_token_expired_in } = tokenData;
|
|
18
|
+
const expires = Date.now() + expires_in * 1000 - 60000;
|
|
19
|
+
let refreshExpires;
|
|
20
|
+
if (refresh_token_expired_in) {
|
|
21
|
+
refreshExpires = Date.now() + refresh_token_expired_in * 1000 - 60000;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
accessToken: access_token,
|
|
25
|
+
expires,
|
|
26
|
+
refreshToken: refresh_token,
|
|
27
|
+
refreshExpires,
|
|
28
|
+
};
|
|
29
|
+
})
|
|
30
|
+
.then((freshCredentials) => {
|
|
31
|
+
credentials = freshCredentials;
|
|
32
|
+
return credentials.accessToken;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return Promise.resolve(credentials.accessToken);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function isRefreshExpired(credentials) {
|
|
39
|
+
if (!credentials || !credentials.refreshExpires) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return Date.now() > credentials.refreshExpires;
|
|
43
|
+
}
|
|
44
|
+
const authorizeCollections = function (config, options, client = (0, client_1.createClient)(config)) {
|
|
45
|
+
const basicAuthToken = createBasicAuthToken(config);
|
|
46
|
+
return client
|
|
47
|
+
.post("/collection/token/", null, {
|
|
48
|
+
headers: {
|
|
49
|
+
Authorization: `Basic ${basicAuthToken}`,
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
.then((response) => response.data);
|
|
53
|
+
};
|
|
54
|
+
exports.authorizeCollections = authorizeCollections;
|
|
55
|
+
const authorizeDisbursements = function (config, options, client = (0, client_1.createClient)(config)) {
|
|
56
|
+
const basicAuthToken = createBasicAuthToken(config);
|
|
57
|
+
return client
|
|
58
|
+
.post("/disbursement/token/", null, {
|
|
59
|
+
headers: {
|
|
60
|
+
Authorization: `Basic ${basicAuthToken}`,
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
.then((response) => response.data);
|
|
64
|
+
};
|
|
65
|
+
exports.authorizeDisbursements = authorizeDisbursements;
|
|
66
|
+
const authorizeRemittance = function (config, options, client = (0, client_1.createClient)(config)) {
|
|
67
|
+
const basicAuthToken = createBasicAuthToken(config);
|
|
68
|
+
return client
|
|
69
|
+
.post("/remittance/token/", null, {
|
|
70
|
+
headers: {
|
|
71
|
+
Authorization: `Basic ${basicAuthToken}`,
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
.then((response) => response.data);
|
|
75
|
+
};
|
|
76
|
+
exports.authorizeRemittance = authorizeRemittance;
|
|
77
|
+
function createBasicAuthToken(config) {
|
|
78
|
+
return Buffer.from(`${config.userId}:${config.userSecret}`).toString("base64");
|
|
79
|
+
}
|
|
80
|
+
function isExpired(credentials) {
|
|
81
|
+
if (!credentials || !credentials.expires) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
return Date.now() > credentials.expires;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/auth.ts"],"names":[],"mappings":";;;AA0BA,oDAsCC;AAsDD,oDAIC;AAxHD,qCAAwC;AAwBxC,SAAgB,oBAAoB,CAClC,SAAqB,EACrB,MAAc;IAEd,IAAI,WAA6B,CAAC;IAClC,OAAO,GAAG,EAAE;QACV,IAAI,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC;YAC3B,MAAM,mBAAmB,GAAG,WAAW,EAAE,YAAY,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;YAExF,MAAM,OAAO,GAAsB,mBAAmB;gBACpD,CAAC,CAAC,EAAE,UAAU,EAAE,eAAe,EAAE,aAAa,EAAE,WAAW,CAAC,YAAY,EAAE;gBAC1E,CAAC,CAAC,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC;YAEzC,OAAO,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC;iBAC9B,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE;gBAClB,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,wBAAwB,EAAE,GAAG,SAAS,CAAC;gBACxF,MAAM,OAAO,GAAW,IAAI,CAAC,GAAG,EAAE,GAAG,UAAU,GAAG,IAAI,GAAG,KAAK,CAAC;gBAE/D,IAAI,cAAkC,CAAC;gBACvC,IAAI,wBAAwB,EAAE,CAAC;oBAC7B,cAAc,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,wBAAwB,GAAG,IAAI,GAAG,KAAK,CAAC;gBACxE,CAAC;gBAED,OAAO;oBACL,WAAW,EAAE,YAAY;oBACzB,OAAO;oBACP,YAAY,EAAE,aAAa;oBAC3B,cAAc;iBACf,CAAC;YACJ,CAAC,CAAC;iBACD,IAAI,CAAC,CAAC,gBAAgB,EAAE,EAAE;gBACzB,WA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K,MAAM,mBAAmB,GAAe,UAC7C,MAAc,EACd,OAA2B,EAC3B,SAAwB,IAAA,qBAAY,EAAC,MAAM,CAAC;IAE5C,MAAM,cAAc,GAAW,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC5D,OAAO,MAAM;SACV,IAAI,CAAC,oBAAoB,EAAE,IAAI,EAAE;QAChC,OAAO,EAAE;YACP,aAAa,EAAE,SAAS,cAAc,EAAE;SACzC;KACF,CAAC;SACD,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC,CAAC;AAbW,QAAA,mBAAmB,uBAa9B;AAEF,SAAgB,oBAAoB,CAAC,MAAkB;IACrD,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,QAAQ,CAClE,QAAQ,CACT,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,WAA6B;IAC9C,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,OAAO,CAAC;AAC1C,CAAC"}
|
package/lib/cjs/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":""}
|
package/lib/cjs/cli.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
const commander_1 = require("commander");
|
|
38
|
+
const momo = __importStar(require("./index"));
|
|
39
|
+
const version = process.env.npm_package_version || "0.0.0";
|
|
40
|
+
commander_1.program
|
|
41
|
+
.version(version)
|
|
42
|
+
.description("Create sandbox credentials")
|
|
43
|
+
.option("-x, --host <n>", "Your webhook host")
|
|
44
|
+
.option("-p, --primary-key <n>", "Primary Key")
|
|
45
|
+
.parse(process.argv);
|
|
46
|
+
const options = commander_1.program.opts();
|
|
47
|
+
if (!options.host || !options.primaryKey) {
|
|
48
|
+
commander_1.program.help({ error: true });
|
|
49
|
+
}
|
|
50
|
+
const stringify = (obj) => JSON.stringify(obj, null, 2);
|
|
51
|
+
const { Users } = momo.create({ callbackHost: options.host });
|
|
52
|
+
const users = Users({ primaryKey: options.primaryKey });
|
|
53
|
+
users
|
|
54
|
+
.create(options.host)
|
|
55
|
+
.then((userId) => {
|
|
56
|
+
return users.login(userId).then((credentials) => {
|
|
57
|
+
console.log("Momo Sandbox Credentials", stringify({
|
|
58
|
+
userSecret: credentials.apiKey,
|
|
59
|
+
userId,
|
|
60
|
+
}));
|
|
61
|
+
});
|
|
62
|
+
})
|
|
63
|
+
.catch((error) => {
|
|
64
|
+
console.log(error);
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAAoC;AAEpC,8CAAgC;AAIhC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC;AAE3D,mBAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,4BAA4B,CAAC;KACzC,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC;KAC7C,MAAM,CAAC,uBAAuB,EAAE,aAAa,CAAC;KAC9C,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvB,MAAM,OAAO,GAAG,mBAAO,CAAC,IAAI,EAA0C,CAAC;AAEvE,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;IACzC,mBAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,SAAS,GAAG,CAAC,GAAoB,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAEzE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AAE9D,MAAM,KAAK,GAAG,KAAK,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;AAExD,KAAK;KACF,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;KACpB,IAAI,CAAC,CAAC,MAAc,EAAE,EAAE;IACvB,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,WAAwB,EAAE,EAAE;QAC3D,OAAO,CAAC,GAAG,CACT,0BAA0B,EAC1B,SAAS,CAAC;YACR,UAAU,EAAE,WAAW,CAAC,MAAM;YAC9B,MAAM;SACP,CAAC,CACH,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;KACD,KAAK,CAAC,CAAC,KAAmB,EAAE,EAAE;IAC7B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACrB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AxiosInstance } from "axios";
|
|
2
|
+
import type { TokenRefresher } from "./auth";
|
|
3
|
+
import type { GlobalConfig, SubscriptionConfig } from "./common";
|
|
4
|
+
export declare function createClient(config: SubscriptionConfig & GlobalConfig, client?: AxiosInstance): AxiosInstance;
|
|
5
|
+
export declare function createAuthClient(refresh: TokenRefresher, client: AxiosInstance): AxiosInstance;
|
|
6
|
+
export declare function withErrorHandling(client: AxiosInstance): AxiosInstance;
|
|
7
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAA8B,MAAM,OAAO,CAAC;AAIvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEjE,wBAAgB,YAAY,CAC1B,MAAM,EAAE,kBAAkB,GAAG,YAAY,EACzC,MAAM,GAAE,aAA8B,GACrC,aAAa,CAUf;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,aAAa,GACpB,aAAa,CAiBf;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAOtE"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createClient = createClient;
|
|
37
|
+
exports.createAuthClient = createAuthClient;
|
|
38
|
+
exports.withErrorHandling = withErrorHandling;
|
|
39
|
+
const axios_1 = __importStar(require("axios"));
|
|
40
|
+
const errors_1 = require("./errors");
|
|
41
|
+
function createClient(config, client = axios_1.default.create()) {
|
|
42
|
+
if (config.baseUrl) {
|
|
43
|
+
client.defaults.baseURL = config.baseUrl;
|
|
44
|
+
}
|
|
45
|
+
client.defaults.headers.common["Ocp-Apim-Subscription-Key"] =
|
|
46
|
+
config.primaryKey;
|
|
47
|
+
client.defaults.headers.common["X-Target-Environment"] =
|
|
48
|
+
config.environment || "sandbox";
|
|
49
|
+
return withErrorHandling(client);
|
|
50
|
+
}
|
|
51
|
+
function createAuthClient(refresh, client) {
|
|
52
|
+
client.interceptors.request.use(async (request) => {
|
|
53
|
+
const accessToken = await refresh();
|
|
54
|
+
const headers = request.headers instanceof axios_1.AxiosHeaders
|
|
55
|
+
? request.headers
|
|
56
|
+
: axios_1.AxiosHeaders.from(request.headers);
|
|
57
|
+
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
58
|
+
request.headers = headers;
|
|
59
|
+
return request;
|
|
60
|
+
});
|
|
61
|
+
return client;
|
|
62
|
+
}
|
|
63
|
+
function withErrorHandling(client) {
|
|
64
|
+
client.interceptors.response.use((response) => response, (error) => Promise.reject((0, errors_1.handleError)(error)));
|
|
65
|
+
return client;
|
|
66
|
+
}
|
|
67
|
+
//# sourceM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SAAgB,iBAAiB,CAAC,MAAqB;IACrD,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAC9B,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,EACtB,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAA,oBAAW,EAAC,KAAK,CAAC,CAAC,CAC9C,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type { AxiosInstance } from "axios";
|
|
2
|
+
import { type Balance, type BasicUserInfo, type BcAuthorizeRequest, type BcAuthorizeResponse, type Config, type DeliveryNotification, FailureReason, type Party, PartyIdType, TransactionStatus, type Withdrawal, type WithdrawalRequest } from "./common";
|
|
3
|
+
export interface PaymentRequest {
|
|
4
|
+
/**
|
|
5
|
+
* Amount that will be debited from the payer account
|
|
6
|
+
*/
|
|
7
|
+
amount: string;
|
|
8
|
+
/**
|
|
9
|
+
* ISO4217 Currency
|
|
10
|
+
*/
|
|
11
|
+
currency: string;
|
|
12
|
+
/**
|
|
13
|
+
* External id is used as a reference to the transaction.
|
|
14
|
+
* External id is used for reconciliation.
|
|
15
|
+
* The external id will be included in transaction history report.
|
|
16
|
+
* External id is not required to be unique.
|
|
17
|
+
*/
|
|
18
|
+
externalId?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Party identifies a account holder in the wallet platform.
|
|
21
|
+
* Party consists of two parameters, type and partyId.
|
|
22
|
+
* Each type have its own validation of the partyId
|
|
23
|
+
* - MSISDN - Mobile Number validated according to ITU-T E.164. Validated with IsMSISDN
|
|
24
|
+
* - EMAIL - Validated to be a valid e-mail format. Validated with IsEmail
|
|
25
|
+
* - PARTY_CODE - UUID of the party. Validated with IsUuid
|
|
26
|
+
*/
|
|
27
|
+
payer: Party;
|
|
28
|
+
/**
|
|
29
|
+
* Message that will be written in the payer transaction history message field.
|
|
30
|
+
*/
|
|
31
|
+
payerMessage?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Message that will be written in the payee transaction history note field.
|
|
34
|
+
*/
|
|
35
|
+
payeeNote?: string;
|
|
36
|
+
/**
|
|
37
|
+
* URL to the server where the callback should be sent.
|
|
38
|
+
*/
|
|
39
|
+
callbackUrl?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface Payment {
|
|
42
|
+
/**
|
|
43
|
+
* Financial transactionIdd from mobile money manager.
|
|
44
|
+
* Used to connect to the specific financial transaction made in the account
|
|
45
|
+
*/
|
|
46
|
+
financialTransactionId: string;
|
|
47
|
+
/**
|
|
48
|
+
* External id provided in the creation of the requestToPay transaction
|
|
49
|
+
*/
|
|
50
|
+
externalId: string;
|
|
51
|
+
/**
|
|
52
|
+
* Amount that will be debited from the payer account.
|
|
53
|
+
*/
|
|
54
|
+
amount: string;
|
|
55
|
+
/**
|
|
56
|
+
* ISO4217 Currency
|
|
57
|
+
*/
|
|
58
|
+
currency: string;
|
|
59
|
+
/**
|
|
60
|
+
* Party identifies a account holder in the wallet platform.
|
|
61
|
+
* Party consists of two parameters, type and partyId.
|
|
62
|
+
* Each type have its own validation of the partyId
|
|
63
|
+
* - MSISDN - Mobile Number validated according to ITU-T E.164. Validated with IsMSISDN
|
|
64
|
+
* - EMAIL - Validated to be a valid e-mail format. Validated with IsEmail
|
|
65
|
+
* - PARTY_CODE - UUID of the party. Validated with IsUuid
|
|
66
|
+
*/
|
|
67
|
+
payer: Party;
|
|
68
|
+
/**
|
|
69
|
+
* Message that will be written in the payer transaction history message field.
|
|
70
|
+
*/
|
|
71
|
+
payerMessage: string;
|
|
72
|
+
/**
|
|
73
|
+
* Message that will be written in the payee transaction history note field.
|
|
74
|
+
*/
|
|
75
|
+
payeeNote: string;
|
|
76
|
+
reason?: FailureReason;
|
|
77
|
+
status: TransactionStatus;
|
|
78
|
+
}
|
|
79
|
+
export default class Collections {
|
|
80
|
+
private client;
|
|
81
|
+
private config;
|
|
82
|
+
constructor(client: AxiosInstance, config: Config);
|
|
83
|
+
/**
|
|
84
|
+
* This method is used to request a payment from a consumer (Payer).
|
|
85
|
+
* The payer will be asked to authorize the payment. The transaction will
|
|
86
|
+
* be executed once the payer has authorized the payment.
|
|
87
|
+
* The requesttopay will be in status PENDING until the transaction
|
|
88
|
+
* is authorized or declined by the payer or it is timed out by the system.
|
|
89
|
+
* Status of the transaction can be validated by using `getTransation`
|
|
90
|
+
*
|
|
91
|
+
* @param paymentRequest
|
|
92
|
+
*/
|
|
93
|
+
requestToPay({ callbackUrl, ...paymentRequest }: PaymentRequest): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* This method is used to retrieve transaction information. You can invoke it
|
|
96
|
+
* at intervals until your transaction fails or succeeds.
|
|
97
|
+
*
|
|
98
|
+
* If the transaction has failed, it will throw an appropriate error. The error will be a subclass
|
|
99
|
+
* of `MtnMoMoError`. Check [`src/error.ts`](https://github.com/maxkabechani/mtn-momo-sdk/blob/master/src/errors.ts)
|
|
100
|
+
* for the various errors that can be thrown
|
|
101
|
+
*
|
|
102
|
+
* @param referenceId the value returned from `requestToPay`
|
|
103
|
+
*/
|
|
104
|
+
getTransaction(referenceId: string): Promise<Payment>;
|
|
105
|
+
/**
|
|
106
|
+
* Get the balance of the account.
|
|
107
|
+
*/
|
|
108
|
+
getBalance(): Promise<Balance>;
|
|
109
|
+
/**
|
|
110
|
+
* This method is used to check if an account holder is registered and active in the system.
|
|
111
|
+
*
|
|
112
|
+
* @param id Specifies the type of the party ID. Allowed values [msisdn, email, party_code].
|
|
113
|
+
* accountHolderId should explicitly be in small letters.
|
|
114
|
+
*
|
|
115
|
+
* @param type The party number. Validated according to the party ID type (case Sensitive).
|
|
116
|
+
* msisdn - Mobile Number validated according to ITU-T E.164. Validated with IsMSISDN
|
|
117
|
+
* email - Validated to be a valid e-mail format. Validated with IsEmail
|
|
118
|
+
* party_code - UUID of the party. Validated with IsUuid
|
|
119
|
+
*/
|
|
120
|
+
isPayerActive(id: string, type?: PartyIdType): Promise<boolean>;
|
|
121
|
+
/**
|
|
122
|
+
* This method is used to request a withdrawal from a payer account (V1).
|
|
123
|
+
* The payer will be asked to authorize the withdrawal.
|
|
124
|
+
*
|
|
125
|
+
* @param withdrawalRequest The withdrawal request details
|
|
126
|
+
* @returns A promise that resolves to the withdrawal reference ID
|
|
127
|
+
*/
|
|
128
|
+
requestToWithdraw(withdrawalRequest: WithdrawalRequest): Promise<string>;
|
|
129
|
+
/**
|
|
130
|
+
* This method is used to request a withdrawal from a payer account (V2).
|
|
131
|
+
* The payer will be asked to authorize the withdrawal.
|
|
132
|
+
*
|
|
133
|
+
* @param withdrawalRequest The withdrawal request details
|
|
134
|
+
* @returns A promise that resolves to the withdrawal reference ID
|
|
135
|
+
*/
|
|
136
|
+
requestToWithdrawV2(withdrawalRequest: WithdrawalRequest): Promise<string>;
|
|
137
|
+
/**
|
|
138
|
+
* Get the details and status of a withdrawal request.
|
|
139
|
+
*
|
|
140
|
+
* @param referenceId The withdrawal reference ID from requestToWithdraw
|
|
141
|
+
* @returns A promise that resolves to the withdrawal details
|
|
142
|
+
*/
|
|
143
|
+
getWithdrawal(referenceId: string): Promise<Withdrawal>;
|
|
144
|
+
/**
|
|
145
|
+
* Send a delivery notification for a completed request to pay.
|
|
146
|
+
*
|
|
147
|
+
* @param referenceId The request to pay reference ID
|
|
148
|
+
* @param notification The delivery notification details
|
|
149
|
+
* @returns A promise that resolves when the notification is sent
|
|
150
|
+
*/
|
|
151
|
+
sendDeliveryNotification(referenceId: string, notification: DeliveryNotification): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Get basic user information for an account holder.
|
|
154
|
+
*
|
|
155
|
+
* @param partyIdType The type of party ID (MSISDN, EMAIL, or PARTY_CODE)
|
|
156
|
+
* @param partyId The party identifier
|
|
157
|
+
* @returns A promise that resolves to the basic user information
|
|
158
|
+
*/
|
|
159
|
+
getBasicUserInfo(partyIdType: PartyIdType, partyId: string): Promise<BasicUserInfo>;
|
|
160
|
+
/**
|
|
161
|
+
* Get the balance of the account in a specific currency.
|
|
162
|
+
*
|
|
163
|
+
* @param currency The ISO4217 currency code
|
|
164
|
+
* @returns A promise that resolves to the account balance in the specified currency
|
|
165
|
+
*/
|
|
166
|
+
getBalanceInCurrency(currency: string): Promise<Balance>;
|
|
167
|
+
/**
|
|
168
|
+
* Request Biometric Consent (BC) authorization.
|
|
169
|
+
* This initiates the BC authorization flow for enhanced security.
|
|
170
|
+
*
|
|
171
|
+
* @param request The BC authorization request
|
|
172
|
+
* @returns A promise that resolves to the BC authorization response with auth_req_id
|
|
173
|
+
*/
|
|
174
|
+
bcAuthorize(request: BcAuthorizeRequest): Promise<BcAuthorizeResponse>;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=collections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../../src/collections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAM3C,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,MAAM,EACX,KAAK,oBAAoB,EACzB,aAAa,EACb,KAAK,KAAK,EACV,WAAW,EACX,iBAAiB,EACjB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACvB,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;;OAOG;IACH,KAAK,EAAE,KAAK,CAAC;IAEb;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,OAAO;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