@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
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateRequestToPay = validateRequestToPay;
|
|
4
|
+
exports.validateWithdrawalRequest = validateWithdrawalRequest;
|
|
5
|
+
exports.validateDepositRequest = validateDepositRequest;
|
|
6
|
+
exports.validateRefundRequest = validateRefundRequest;
|
|
7
|
+
exports.validateTransfer = validateTransfer;
|
|
8
|
+
exports.validateGlobalConfig = validateGlobalConfig;
|
|
9
|
+
exports.validateProductConfig = validateProductConfig;
|
|
10
|
+
exports.validateSubscriptionConfig = validateSubscriptionConfig;
|
|
11
|
+
exports.validateUserConfig = validateUserConfig;
|
|
12
|
+
const assert_1 = require("assert");
|
|
13
|
+
const common_1 = require("./common");
|
|
14
|
+
function validateRequestToPay(paymentRequest) {
|
|
15
|
+
const { amount, currency, payer } = paymentRequest || {};
|
|
16
|
+
return Promise.resolve().then(() => {
|
|
17
|
+
(0, assert_1.strictEqual)(isTruthy(amount), true, "amount is required");
|
|
18
|
+
(0, assert_1.strictEqual)(isNumeric(amount), true, "amount must be a number");
|
|
19
|
+
(0, assert_1.strictEqual)(isTruthy(currency), true, "currency is required");
|
|
20
|
+
(0, assert_1.strictEqual)(isTruthy(payer), true, "payer is required");
|
|
21
|
+
(0, assert_1.strictEqual)(isTruthy(payer.partyId), true, "payer.partyId is required");
|
|
22
|
+
(0, assert_1.strictEqual)(isTruthy(payer.partyIdType), true, "payer.partyIdType is required");
|
|
23
|
+
(0, assert_1.strictEqual)(isString(currency), true, "currency must be a string");
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function validateWithdrawalRequest(request) {
|
|
27
|
+
const { amount, currency, payee } = request || {};
|
|
28
|
+
return Promise.resolve().then(() => {
|
|
29
|
+
(0, assert_1.strictEqual)(isTruthy(amount), true, "amount is required");
|
|
30
|
+
(0, assert_1.strictEqual)(isNumeric(amount), true, "amount must be a number");
|
|
31
|
+
(0, assert_1.strictEqual)(isTruthy(currency), true, "currency is required");
|
|
32
|
+
(0, assert_1.strictEqual)(isTruthy(payee), true, "payee is required");
|
|
33
|
+
(0, assert_1.strictEqual)(isTruthy(payee?.partyId), true, "payee.partyId is required");
|
|
34
|
+
(0, assert_1.strictEqual)(isTruthy(payee?.partyIdType), true, "payee.partyIdType is required");
|
|
35
|
+
(0, assert_1.strictEqual)(isString(currency), true, "currency must be a string");
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function validateDepositRequest(request) {
|
|
39
|
+
const { amount, currency, payee } = request || {};
|
|
40
|
+
return Promise.resolve().then(() => {
|
|
41
|
+
(0, assert_1.strictEqual)(isTruthy(amount), true, "amount is required");
|
|
42
|
+
(0, assert_1.strictEqual)(isNumeric(amount), true, "amount must be a number");
|
|
43
|
+
(0, assert_1.strictEqual)(isTruthy(currency), true, "currency is required");
|
|
44
|
+
(0, assert_1.strictEqual)(isTruthy(payee), true, "payee is required");
|
|
45
|
+
(0, assert_1.strictEqual)(isTruthy(payee?.partyId), true, "payee.partyId is required");
|
|
46
|
+
(0, assert_1.strictEqual)(isTruthy(payee?.partyIdType), true, "payee.partyIdType is required");
|
|
47
|
+
(0, assert_1.strictEqual)(isString(currency), true, "currency must be a string");
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function validateRefundRequest(request) {
|
|
51
|
+
const { amount, currency, referenceIdToRefund } = request || {};
|
|
52
|
+
return Promise.resolve().then(() => {
|
|
53
|
+
(0, assert_1.strictEqual)(isTruthy(referenceIdToRefund), true, "referenceIdToRefund is required");
|
|
54
|
+
(0, assert_1.strictEqual)(isUuid4(referenceIdToRefund), true, "referenceIdToRefund must be a valid uuid v4");
|
|
55
|
+
(0, assert_1.strictEqual)(isTruthy(amount), true, "amount is required");
|
|
56
|
+
(0, assert_1.strictEqual)(isNumeric(amount), true, "amount must be a number");
|
|
57
|
+
(0, assert_1.strictEqual)(isTruthy(currency), true, "currency is required");
|
|
58
|
+
(0, assert_1.strictEqual)(isString(currency), true, "currency must be a string");
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function validateTransfer(payoutRequest) {
|
|
62
|
+
const { amount, currency, payee, referenceId } = payoutRequest || {};
|
|
63
|
+
return Promise.resolve().then(() => {
|
|
64
|
+
(0, assert_1.strictEqual)(isTruthy(referenceId), true, "referenceId is required");
|
|
65
|
+
(0, assert_1.strictEqual)(isUuid4(referenceId), true, "referenceId must be a valid uuid v4");
|
|
66
|
+
(0, assert_1.strictEqual)(isTruthy(amount), true, "amount is required");
|
|
67
|
+
(0, assert_1.strictEqual)(isNumeric(amount), true, "amount must be a number");
|
|
68
|
+
(0, assert_1.strictEqual)(isTruthy(currency), true, "currency is required");
|
|
69
|
+
(0, assert_1.strictEqual)(isTruthy(payee), true, "payee is required");
|
|
70
|
+
(0, assert_1.strictEqual)(isTruthy(payee.partyId), true, "payee.partyId is required");
|
|
71
|
+
(0, assert_1.strictEqual)(isTruthy(payee.partyIdType), true, "payee.partyIdType is required");
|
|
72
|
+
(0, assert_1.strictEqual)(isString(currency), true, "amount must be a string");
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function validateGlobalConfig(config) {
|
|
76
|
+
const { callbackHost, baseUrl, environment } = config;
|
|
77
|
+
(0, assert_1.strictEqual)(isTruthy(callbackHost), true, "callbackHost is required");
|
|
78
|
+
if (environment && environment !== common_1.Environment.SANDBOX) {
|
|
79
|
+
(0, assert_1.strictEqual)(isTruthy(baseUrl), true, "baseUrl is required if environment is not sandbox");
|
|
80
|
+
(0, assert_1.strictEqual)(isString(baseUrl), true, "baseUrl must be a string");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function validateProductConfig(config) {
|
|
84
|
+
validateSubscriptionConfig(config);
|
|
85
|
+
validateUserConfig(config);
|
|
86
|
+
}
|
|
87
|
+
function validateSubscriptionConfig(config) {
|
|
88
|
+
const { primaryKey } = config;
|
|
89
|
+
(0, assert_1.strictEqual)(isTruthy(primaryKey), true, "primaryKey is required");
|
|
90
|
+
(0, assert_1.strictEqual)(isString(primaryKey), true, "primaryKey must be a string");
|
|
91
|
+
}
|
|
92
|
+
function validateUserConfig({ userId, userSecret }) {
|
|
93
|
+
(0, assert_1.strictEqual)(isTruthy(userId), true, "userId is required");
|
|
94
|
+
(0, assert_1.strictEqual)(isString(userId), true, "userId must be a string");
|
|
95
|
+
(0, assert_1.strictEqual)(isTruthy(userSecret), true, "userSecret is required");
|
|
96
|
+
(0, assert_1.strictEqual)(isString(userSecret), true, "userSecret must be a string");
|
|
97
|
+
(0, assert_1.strictEqual)(isUuid4(userId), true, "userId must be a valid uuid v4");
|
|
98
|
+
}
|
|
99
|
+
function isNumeric(value) {
|
|
100
|
+
return !isNaN(parseInt(value, 10));
|
|
101
|
+
}
|
|
102
|
+
function isTruthy(value) {
|
|
103
|
+
return !!value;
|
|
104
|
+
}
|
|
105
|
+
function isString(value) {
|
|
106
|
+
return typeof value === "string";
|
|
107
|
+
}
|
|
108
|
+
function isUuid4(value) {
|
|
109
|
+
return /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i.test(value);
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/validate.ts"],"names":[],"mappings":";;AAaA,oDAiBC;AAED,8DAWC;AAED,wDAWC;AAED,sDAUC;AAED,4CAwBC;AAED,oDAYC;AAED,sDAGC;AAED,gEAIC;AAED,gDAQC;AAjID,mCAAqC;AAIrC,qCAAuC;AASvC,SAAgB,oBAAoB,CAClC,cAA8B;IAE9B,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAmB,cAAc,IAAI,EAAE,CAAC;IACzE,OAAO,OAAO,CAAC,OAAO,E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
|
+
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/esm/auth.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { createClient } from "./client";
|
|
2
|
+
export function createTokenRefresher(authorize, config) {
|
|
3
|
+
let credentials;
|
|
4
|
+
return () => {
|
|
5
|
+
if (isExpired(credentials)) {
|
|
6
|
+
const isRefreshTokenValid = credentials?.refreshToken && !isRefreshExpired(credentials);
|
|
7
|
+
const options = isRefreshTokenValid
|
|
8
|
+
? { grant_type: 'refresh_token', refresh_token: credentials.refreshToken }
|
|
9
|
+
: { grant_type: 'client_credentials' };
|
|
10
|
+
return authorize(config, options)
|
|
11
|
+
.then((tokenData) => {
|
|
12
|
+
const { access_token, expires_in, refresh_token, refresh_token_expired_in } = tokenData;
|
|
13
|
+
const expires = Date.now() + expires_in * 1000 - 60000;
|
|
14
|
+
let refreshExpires;
|
|
15
|
+
if (refresh_token_expired_in) {
|
|
16
|
+
refreshExpires = Date.now() + refresh_token_expired_in * 1000 - 60000;
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
accessToken: access_token,
|
|
20
|
+
expires,
|
|
21
|
+
refreshToken: refresh_token,
|
|
22
|
+
refreshExpires,
|
|
23
|
+
};
|
|
24
|
+
})
|
|
25
|
+
.then((freshCredentials) => {
|
|
26
|
+
credentials = freshCredentials;
|
|
27
|
+
return credentials.accessToken;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return Promise.resolve(credentials.accessToken);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function isRefreshExpired(credentials) {
|
|
34
|
+
if (!credentials || !credentials.refreshExpires) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return Date.now() > credentials.refreshExpires;
|
|
38
|
+
}
|
|
39
|
+
export const authorizeCollections = function (config, options, client = createClient(config)) {
|
|
40
|
+
const basicAuthToken = createBasicAuthToken(config);
|
|
41
|
+
return client
|
|
42
|
+
.post("/collection/token/", null, {
|
|
43
|
+
headers: {
|
|
44
|
+
Authorization: `Basic ${basicAuthToken}`,
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
.then((response) => response.data);
|
|
48
|
+
};
|
|
49
|
+
export const authorizeDisbursements = function (config, options, client = createClient(config)) {
|
|
50
|
+
const basicAuthToken = createBasicAuthToken(config);
|
|
51
|
+
return client
|
|
52
|
+
.post("/disbursement/token/", null, {
|
|
53
|
+
headers: {
|
|
54
|
+
Authorization: `Basic ${basicAuthToken}`,
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
.then((response) => response.data);
|
|
58
|
+
};
|
|
59
|
+
export const authorizeRemittance = function (config, options, client = createClient(config)) {
|
|
60
|
+
const basicAuthToken = createBasicAuthToken(config);
|
|
61
|
+
return client
|
|
62
|
+
.post("/remittance/token/", null, {
|
|
63
|
+
headers: {
|
|
64
|
+
Authorization: `Basic ${basicAuthToken}`,
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
.then((response) => response.data);
|
|
68
|
+
};
|
|
69
|
+
export function createBasicAuthToken(config) {
|
|
70
|
+
return Buffer.from(`${config.userId}:${config.userSecret}`).toString("base64");
|
|
71
|
+
}
|
|
72
|
+
function isExpired(credentials) {
|
|
73
|
+
if (!credentials || !credentials.expires) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
return Date.now() > credentials.expires;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/auth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAwBxC,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AAc,EAAE;SACzC;KACF,CAAC;SACD,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC,CAAC;AAEF,MAAM,UAAU,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/esm/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":""}
|
package/lib/esm/cli.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { program } from "commander";
|
|
3
|
+
import * as momo from "./index";
|
|
4
|
+
const version = process.env.npm_package_version || "0.0.0";
|
|
5
|
+
program
|
|
6
|
+
.version(version)
|
|
7
|
+
.description("Create sandbox credentials")
|
|
8
|
+
.option("-x, --host <n>", "Your webhook host")
|
|
9
|
+
.option("-p, --primary-key <n>", "Primary Key")
|
|
10
|
+
.parse(process.argv);
|
|
11
|
+
const options = program.opts();
|
|
12
|
+
if (!options.host || !options.primaryKey) {
|
|
13
|
+
program.help({ error: true });
|
|
14
|
+
}
|
|
15
|
+
const stringify = (obj) => JSON.stringify(obj, null, 2);
|
|
16
|
+
const { Users } = momo.create({ callbackHost: options.host });
|
|
17
|
+
const users = Users({ primaryKey: options.primaryKey });
|
|
18
|
+
users
|
|
19
|
+
.create(options.host)
|
|
20
|
+
.then((userId) => {
|
|
21
|
+
return users.login(userId).then((credentials) => {
|
|
22
|
+
console.log("Momo Sandbox Credentials", stringify({
|
|
23
|
+
userSecret: credentials.apiKey,
|
|
24
|
+
userId,
|
|
25
|
+
}));
|
|
26
|
+
});
|
|
27
|
+
})
|
|
28
|
+
.catch((error) => {
|
|
29
|
+
console.log(error);
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAIhC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC;AAE3D,OAAO;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,OAAO,CAAC,IAAI,EAA0C,CAAC;AAEvE,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;IACzC,OAAO,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,29 @@
|
|
|
1
|
+
import axios, { AxiosHeaders } from "axios";
|
|
2
|
+
import { handleError } from "./errors";
|
|
3
|
+
export function createClient(config, client = axios.create()) {
|
|
4
|
+
if (config.baseUrl) {
|
|
5
|
+
client.defaults.baseURL = config.baseUrl;
|
|
6
|
+
}
|
|
7
|
+
client.defaults.headers.common["Ocp-Apim-Subscription-Key"] =
|
|
8
|
+
config.primaryKey;
|
|
9
|
+
client.defaults.headers.common["X-Target-Environment"] =
|
|
10
|
+
config.environment || "sandbox";
|
|
11
|
+
return withErrorHandling(client);
|
|
12
|
+
}
|
|
13
|
+
export function createAuthClient(refresh, client) {
|
|
14
|
+
client.interceptors.request.use(async (request) => {
|
|
15
|
+
const accessToken = await refresh();
|
|
16
|
+
const headers = request.headers instanceof AxiosHeaders
|
|
17
|
+
? request.headers
|
|
18
|
+
: AxiosHeaders.from(request.headers);
|
|
19
|
+
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
20
|
+
request.headers = headers;
|
|
21
|
+
return request;
|
|
22
|
+
});
|
|
23
|
+
return client;
|
|
24
|
+
}
|
|
25
|
+
export function withErrorHandling(client) {
|
|
26
|
+
client.interceptors.response.use((response) => response, (error) => Promise.reject(handleError(error)));
|
|
27
|
+
return client;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAG5C,OAAO,EAAE,WAAW,EAAE,M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W,CAAC,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;IACtB;;;OAGG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;;OAOG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