maib-mia-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/LICENSE +674 -0
- package/README.md +146 -0
- package/package.json +56 -0
- package/src/MaibMiaApiRequest.js +339 -0
- package/src/MaibMiaAuthRequest.js +49 -0
- package/src/MaibMiaSdk.js +219 -0
- package/src/constants.js +61 -0
- package/src/errors.js +32 -0
- package/src/index.js +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Node.js SDK for maib MIA API
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
* maib MIA QR API docs: https://docs.maibmerchants.md/mia-qr-api
|
|
6
|
+
* maib Request to Pay (RTP) docs: https://docs.maibmerchants.md/request-to-pay
|
|
7
|
+
* GitHub project https://github.com/alexminza/maib-mia-sdk-node
|
|
8
|
+
* NPM package https://www.npmjs.com/package/maib-mia-sdk
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
To easily install or upgrade to the latest release, use `npm`:
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
npm install maib-mia-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Getting started
|
|
18
|
+
Import SDK:
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
const {
|
|
22
|
+
MaibMiaSdk,
|
|
23
|
+
MaibMiaAuthRequest,
|
|
24
|
+
MaibMiaApiRequest
|
|
25
|
+
} = require('maib-mia-sdk');
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Add project configuration:
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
const MAIB_MIA_CLIENT_ID = process.env.MAIB_MIA_CLIENT_ID;
|
|
32
|
+
const MAIB_MIA_CLIENT_SECRET = process.env.MAIB_MIA_CLIENT_SECRET;
|
|
33
|
+
const MAIB_MIA_SIGNATURE_KEY = process.env.MAIB_MIA_SIGNATURE_KEY;
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## SDK usage examples
|
|
37
|
+
### Get Access Token with Client ID and Client Secret
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
const maibMiaAuth = await MaibMiaAuthRequest
|
|
41
|
+
.create(MaibMiaSdk.SANDBOX_BASE_URL)
|
|
42
|
+
.generateToken(MAIB_MIA_CLIENT_ID, MAIB_MIA_CLIENT_SECRET);
|
|
43
|
+
|
|
44
|
+
const maibMiaToken = maibMiaAuth.accessToken;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Create a dynamic order payment QR
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
const maibMiaExpiresAt = new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString();
|
|
51
|
+
const maibMiaQrData = {
|
|
52
|
+
'type': 'Dynamic',
|
|
53
|
+
'expiresAt': maibMiaExpiresAt,
|
|
54
|
+
'amountType': 'Fixed',
|
|
55
|
+
'amount': 50.00,
|
|
56
|
+
'currency': 'MDL',
|
|
57
|
+
'orderId': '123',
|
|
58
|
+
'description': 'Order #123',
|
|
59
|
+
'callbackUrl': 'https://example.com/callback',
|
|
60
|
+
'redirectUrl': 'https://example.com/success'
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const maibMiaApiRequest = MaibMiaApiRequest.create(MaibMiaSdk.SANDBOX_BASE_URL);
|
|
64
|
+
const maibMiaQrCreateResponse = await maibMiaApiRequest.qrCreate(maibMiaQrData, maibMiaToken);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Create a RTP (Request To Pay)
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
const maibMiaRtpData = {
|
|
71
|
+
'alias': '3736xxxxxxx',
|
|
72
|
+
'amount': 150.00,
|
|
73
|
+
'expiresAt': maibMiaExpiresAt,
|
|
74
|
+
'currency': 'MDL',
|
|
75
|
+
'description': 'Invoice #123',
|
|
76
|
+
'orderId': '123',
|
|
77
|
+
'terminalId': 'P011111',
|
|
78
|
+
'callbackUrl': 'https://example.com/callback',
|
|
79
|
+
'redirectUrl': 'https://example.com/success'
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const maibMiaRtpCreateResponse = await maibMiaApiRequest.rtpCreate(maibMiaRtpData, maibMiaToken);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Validate callback signature
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
const callbackData = {
|
|
89
|
+
'result': {
|
|
90
|
+
'qrId': 'c3108b2f-6c2e-43a2-bdea-123456789012',
|
|
91
|
+
'extensionId': '3fe7f013-23a6-4d09-a4a4-123456789012',
|
|
92
|
+
'qrStatus': 'Paid',
|
|
93
|
+
'payId': 'eb361f48-bb39-45e2-950b-123456789012',
|
|
94
|
+
'referenceId': 'MIA0001234567',
|
|
95
|
+
'orderId': '123',
|
|
96
|
+
'amount': 50.00,
|
|
97
|
+
'commission': 0.1,
|
|
98
|
+
'currency': 'MDL',
|
|
99
|
+
'payerName': 'TEST QR PAYMENT',
|
|
100
|
+
'payerIban': 'MD88AG000000011621810140',
|
|
101
|
+
'executedAt': '2025-04-18T14:04:11.81145+00:00',
|
|
102
|
+
'terminalId': null
|
|
103
|
+
},
|
|
104
|
+
'signature': 'fHM+l4L1ycFWZDRTh/Vr8oybq1Q1xySdjyvmFQCmZ4s='
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const validateCallbackResult = MaibMiaSdk.validateCallbackSignature(callbackData, MAIB_MIA_SIGNATURE_KEY);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Get QR details
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
const qrId = maibMiaQrCreateResponse.qrId;
|
|
114
|
+
const maibMiaQrDetailsResponse = await maibMiaApiRequest.qrDetails(qrId, maibMiaToken);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Perform a test QR payment
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
const maibTestPayData = {
|
|
121
|
+
'qrId': qrId,
|
|
122
|
+
'amount': maibMiaQrData.amount,
|
|
123
|
+
'iban': 'MD88AG000000011621810140',
|
|
124
|
+
'currency': maibMiaQrData.currency,
|
|
125
|
+
'payerName': 'TEST QR PAYMENT'
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const maibMiaTestPayResponse = await maibMiaApiRequest.testPay(maibTestPayData, maibMiaToken);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Get payment details
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
const payId = maibMiaTestPayResponse.payId;
|
|
135
|
+
const maibMiaPaymentDetailsResponse = await maibMiaApiRequest.paymentDetails(payId, maibMiaToken);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Refund payment
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
const maibMiaPaymentRefundData = {
|
|
142
|
+
'reason': 'Test refund reason'
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const maibMiaPaymentRefundResponse = await maibMiaApiRequest.paymentRefund(payId, maibMiaPaymentRefundData, maibMiaToken);
|
|
146
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "maib-mia-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Node.js SDK for maib MIA API",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"maib",
|
|
7
|
+
"moldova",
|
|
8
|
+
"mia",
|
|
9
|
+
"qr",
|
|
10
|
+
"rtp",
|
|
11
|
+
"payments",
|
|
12
|
+
"api",
|
|
13
|
+
"sdk"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/alexminza/maib-mia-sdk-node",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/alexminza/maib-mia-sdk-node/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/alexminza/maib-mia-sdk-node.git"
|
|
22
|
+
},
|
|
23
|
+
"license": "GPL-3.0",
|
|
24
|
+
"author": "Alexander Minza",
|
|
25
|
+
"type": "commonjs",
|
|
26
|
+
"main": "src/index.js",
|
|
27
|
+
"files": [
|
|
28
|
+
"src"
|
|
29
|
+
],
|
|
30
|
+
"directories": {
|
|
31
|
+
"test": "test"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"test": "jest",
|
|
35
|
+
"test:watch": "jest --watch",
|
|
36
|
+
"test:coverage": "jest --coverage",
|
|
37
|
+
"lint": "eslint src/ test/",
|
|
38
|
+
"lint:fix": "eslint src/ test/ --fix",
|
|
39
|
+
"prepublishOnly": "npm test && npm run lint"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"axios": "^1.6.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@eslint/js": "^9.39.2",
|
|
46
|
+
"@types/node": "^20.0.0",
|
|
47
|
+
"dotenv": "^16.3.0",
|
|
48
|
+
"eslint": "^9.39.2",
|
|
49
|
+
"globals": "^16.5.0",
|
|
50
|
+
"jest": "^29.7.0"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=18.0.0",
|
|
54
|
+
"npm": ">=6.0.0"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js SDK for maib MIA API
|
|
3
|
+
* API Request Handler
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { API_ENDPOINTS, REQUIRED_PARAMS } = require('./constants');
|
|
7
|
+
const { MaibMiaValidationError } = require('./errors');
|
|
8
|
+
|
|
9
|
+
const MaibMiaSdk = require('./MaibMiaSdk');
|
|
10
|
+
|
|
11
|
+
class MaibMiaApiRequest {
|
|
12
|
+
//#region Init
|
|
13
|
+
/**
|
|
14
|
+
* Create a new MaibMiaApiRequest instance
|
|
15
|
+
* @param {string} baseUrl - maib MIA API base url
|
|
16
|
+
* @param {number} timeout - API request timeout in milliseconds
|
|
17
|
+
*/
|
|
18
|
+
constructor(baseUrl = MaibMiaSdk.DEFAULT_BASE_URL, timeout = MaibMiaSdk.DEFAULT_TIMEOUT) {
|
|
19
|
+
this.client = new MaibMiaSdk(baseUrl, timeout);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Static factory method to create an instance
|
|
24
|
+
* @param {string} baseUrl - maib MIA API base url
|
|
25
|
+
* @param {number} timeout - API request timeout in milliseconds
|
|
26
|
+
* @returns {MaibMiaApiRequest}
|
|
27
|
+
*/
|
|
28
|
+
static create(baseUrl = MaibMiaSdk.DEFAULT_BASE_URL, timeout = MaibMiaSdk.DEFAULT_TIMEOUT) {
|
|
29
|
+
return new MaibMiaApiRequest(baseUrl, timeout);
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
|
|
33
|
+
//#region Operation
|
|
34
|
+
/**
|
|
35
|
+
* Perform API request
|
|
36
|
+
* @param {string} endpoint - API endpoint
|
|
37
|
+
* @param {Object} data - Request data
|
|
38
|
+
* @param {string} token - Access token
|
|
39
|
+
* @param {string[]} requiredParams - Array of required field names
|
|
40
|
+
* @param {string} method - Request HTTP method
|
|
41
|
+
* @param {Object} params - Request params
|
|
42
|
+
*/
|
|
43
|
+
async _executeOperation(endpoint, token, data=null, requiredParams=null, method='POST', params=null) {
|
|
44
|
+
MaibMiaApiRequest._validateAccessToken(token);
|
|
45
|
+
MaibMiaApiRequest._validateParams(data, requiredParams);
|
|
46
|
+
|
|
47
|
+
return this.client._sendRequest(method, endpoint, data, params, token);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Replace path parameters in URL
|
|
52
|
+
* @param {string} path - URL path with parameters
|
|
53
|
+
* @param {Object} params - Parameters to replace
|
|
54
|
+
* @returns {string} - Path with replaced parameters
|
|
55
|
+
*/
|
|
56
|
+
static _buildEndpoint(path, params) {
|
|
57
|
+
let result = path;
|
|
58
|
+
|
|
59
|
+
for (const [key, value] of Object.entries(params)) {
|
|
60
|
+
MaibMiaApiRequest._validateIdParam(value);
|
|
61
|
+
result = result.replace(`:${key}`, value);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Validates Entity ID
|
|
69
|
+
* @param {string} entityId - Entity ID
|
|
70
|
+
* @throws {MaibMiaValidationError} - If Entity ID parameter is invalid
|
|
71
|
+
*/
|
|
72
|
+
static _validateIdParam(entityId) {
|
|
73
|
+
if (!entityId) {
|
|
74
|
+
throw new MaibMiaValidationError('ID parameter is required');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Validates the access token
|
|
80
|
+
* @param {string} token - Access token
|
|
81
|
+
* @throws {MaibMiaValidationError} - If Access token parameter is invalid
|
|
82
|
+
*/
|
|
83
|
+
static _validateAccessToken(token) {
|
|
84
|
+
if (!token) {
|
|
85
|
+
throw new MaibMiaValidationError('Access token is required');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Validate required parameters
|
|
91
|
+
* @param {Object} data - Data object to validate
|
|
92
|
+
* @param {string[]} requiredParams - Array of required parameter names
|
|
93
|
+
* @throws {MaibMiaValidationError} - If any required parameter is missing
|
|
94
|
+
*/
|
|
95
|
+
static _validateParams(data, requiredParams) {
|
|
96
|
+
if (!requiredParams || requiredParams.length === 0) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!data) {
|
|
101
|
+
throw new MaibMiaValidationError(`Missing required parameters: ${requiredParams.join(', ')}`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const missingParams = requiredParams.filter(field =>
|
|
105
|
+
data[field] === undefined || data[field] === null
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
if (missingParams.length > 0) {
|
|
109
|
+
throw new MaibMiaValidationError(`Missing required parameters: ${missingParams.join(', ')}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
|
|
114
|
+
//#region QR
|
|
115
|
+
/**
|
|
116
|
+
* Create QR Code (Static, Dynamic)
|
|
117
|
+
* @param {Object} data - QR code data
|
|
118
|
+
* @param {string} token - Access token
|
|
119
|
+
* @returns {Promise<Object>} - QR creation response
|
|
120
|
+
* @link https://docs.maibmerchants.md/mia-qr-api/en/overview/mia-qr-types
|
|
121
|
+
* @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/payment-initiation/create-qr-code-static-dynamic
|
|
122
|
+
*/
|
|
123
|
+
async qrCreate(data, token) {
|
|
124
|
+
return this._executeOperation(API_ENDPOINTS.MIA_QR, token, data, REQUIRED_PARAMS.QR_PARAMS);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Create Hybrid QR Code
|
|
129
|
+
* @param {Object} data - QR code data
|
|
130
|
+
* @param {string} token - Access token
|
|
131
|
+
* @returns {Promise<Object>} - QR creation response
|
|
132
|
+
* @link https://docs.maibmerchants.md/mia-qr-api/en/overview/mia-qr-types
|
|
133
|
+
* @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/payment-initiation/create-hybrid-qr-code
|
|
134
|
+
*/
|
|
135
|
+
async qrCreateHybrid(data, token) {
|
|
136
|
+
return this._executeOperation(API_ENDPOINTS.MIA_QR_HYBRID, token, data, REQUIRED_PARAMS.QR_HYBRID_PARAMS);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Create Extension for QR Code by ID
|
|
141
|
+
* @param {string} qrId - QR code ID
|
|
142
|
+
* @param {Object} data - QR code extension data
|
|
143
|
+
* @param {string} token - Access token
|
|
144
|
+
* @returns {Promise<Object>} - QR creation response
|
|
145
|
+
* @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/payment-initiation/create-hybrid-qr-code/create-extension-for-qr-code-by-id
|
|
146
|
+
*/
|
|
147
|
+
async qrCreateExtension(qrId, data, token) {
|
|
148
|
+
const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_QR_EXTENSION, { qrId });
|
|
149
|
+
return this._executeOperation(endpoint, token, data, REQUIRED_PARAMS.QR_EXTENSION_PARAMS);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Retrieve QR Details by ID
|
|
154
|
+
* @param {string} qrId - QR code ID
|
|
155
|
+
* @param {string} token - Access token
|
|
156
|
+
* @returns {Promise<Object>} - QR details
|
|
157
|
+
* @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/information-retrieval-get/retrieve-qr-details-by-id
|
|
158
|
+
*/
|
|
159
|
+
async qrDetails(qrId, token) {
|
|
160
|
+
const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_QR_ID, { qrId });
|
|
161
|
+
return this._executeOperation(endpoint, token, null, null, 'GET');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Cancel Active QR (Static, Dynamic)
|
|
166
|
+
* @param {string} qrId - QR code ID
|
|
167
|
+
* @param {Object} data - QR code cancellation data
|
|
168
|
+
* @param {string} token - Access token
|
|
169
|
+
* @returns {Promise<Object>} - Cancellation response
|
|
170
|
+
* @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/payment-cancellation/cancel-active-qr-static-dynamic
|
|
171
|
+
*/
|
|
172
|
+
async qrCancel(qrId, data, token) {
|
|
173
|
+
const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_QR_CANCEL, { qrId });
|
|
174
|
+
return this._executeOperation(endpoint, token, data);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Cancel Active QR Extension (Hybrid)
|
|
179
|
+
* @param {string} qrId - QR code ID
|
|
180
|
+
* @param {Object} data - QR code extension cancellation data
|
|
181
|
+
* @param {string} token - Access token
|
|
182
|
+
* @returns {Promise<Object>} - Cancellation response
|
|
183
|
+
* @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/payment-cancellation/cancel-active-qr-extension-hybrid
|
|
184
|
+
*/
|
|
185
|
+
async qrCancelExtension(qrId, data, token) {
|
|
186
|
+
const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_QR_EXTENSION_CANCEL, { qrId });
|
|
187
|
+
return this._executeOperation(endpoint, token, data);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Retrieve List of QR Codes with Filtering Options
|
|
192
|
+
* @param {Object} params - Retrieval params
|
|
193
|
+
* @param {string} token - Access token
|
|
194
|
+
* @returns {Promise<Object>} - Retrieval response
|
|
195
|
+
* @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/information-retrieval-get/display-list-of-qr-codes-with-filtering-options
|
|
196
|
+
*/
|
|
197
|
+
async qrList(params, token) {
|
|
198
|
+
return this._executeOperation(API_ENDPOINTS.MIA_QR, token, null, null, 'GET', params);
|
|
199
|
+
}
|
|
200
|
+
//#endregion
|
|
201
|
+
|
|
202
|
+
//#region Payment
|
|
203
|
+
/**
|
|
204
|
+
* Payment Simulation (Sandbox)
|
|
205
|
+
* @param {Object} data - Test payment data
|
|
206
|
+
* @param {string} token - Access token
|
|
207
|
+
* @returns {Promise<Object>} - Test payment response
|
|
208
|
+
* @link https://docs.maibmerchants.md/mia-qr-api/en/payment-simulation-sandbox
|
|
209
|
+
*/
|
|
210
|
+
async testPay(data, token) {
|
|
211
|
+
return this._executeOperation(API_ENDPOINTS.MIA_TEST_PAY, token, data, REQUIRED_PARAMS.TEST_PAY_PARAMS);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Retrieve Payment Details by ID
|
|
216
|
+
* @param {string} payId - Payment ID
|
|
217
|
+
* @param {string} token - Access token
|
|
218
|
+
* @returns {Promise<Object>} - Payment details response
|
|
219
|
+
* @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/information-retrieval-get/retrieve-payment-details-by-id
|
|
220
|
+
*/
|
|
221
|
+
async paymentDetails(payId, token) {
|
|
222
|
+
const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_PAYMENTS_ID, { payId });
|
|
223
|
+
return this._executeOperation(endpoint, token, null, null, 'GET');
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Refund Completed Payment
|
|
228
|
+
* @param {string} payId - Payment ID
|
|
229
|
+
* @param {Object} data - Refund data
|
|
230
|
+
* @param {string} token - Access token
|
|
231
|
+
* @returns {Promise<Object>} - Refund response
|
|
232
|
+
* @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/payment-refund/refund-completed-payment
|
|
233
|
+
*/
|
|
234
|
+
async paymentRefund(payId, data, token) {
|
|
235
|
+
const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_PAYMENTS_REFUND, { payId });
|
|
236
|
+
return this._executeOperation(endpoint, token, data);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Retrieve List of Payments with Filtering Options
|
|
241
|
+
* @param {Object} params - Retrieval params
|
|
242
|
+
* @param {string} token - Access token
|
|
243
|
+
* @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/information-retrieval-get/retrieve-list-of-payments-with-filtering-options
|
|
244
|
+
* @returns {Promise<Object>} - Retrieval response
|
|
245
|
+
*/
|
|
246
|
+
async paymentList(params, token) {
|
|
247
|
+
return this._executeOperation(API_ENDPOINTS.MIA_PAYMENTS, token, null, null, 'GET', params);
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
|
|
251
|
+
//#region RTP
|
|
252
|
+
/**
|
|
253
|
+
* Create a new payment request (RTP)
|
|
254
|
+
* @param {Object} data - RTP data
|
|
255
|
+
* @param {string} token - Access token
|
|
256
|
+
* @returns {Promise<Object>} - RTP creation response
|
|
257
|
+
* @link https://docs.maibmerchants.md/request-to-pay/api-reference/endpoints/create-a-new-payment-request-rtp
|
|
258
|
+
*/
|
|
259
|
+
async rtpCreate(data, token) {
|
|
260
|
+
return this._executeOperation(API_ENDPOINTS.MIA_RTP, token, data, REQUIRED_PARAMS.RTP_PARAMS);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Retrieve the status of a payment request
|
|
265
|
+
* @param {string} rtpId - RTP ID
|
|
266
|
+
* @param {string} token - Access token
|
|
267
|
+
* @returns {Promise<Object>} - RTP status response
|
|
268
|
+
* @link https://docs.maibmerchants.md/request-to-pay/api-reference/endpoints/retrieve-the-status-of-a-payment-request
|
|
269
|
+
*/
|
|
270
|
+
async rtpStatus(rtpId, token) {
|
|
271
|
+
const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_RTP_ID, { rtpId });
|
|
272
|
+
return this._executeOperation(endpoint, token, null, null, 'GET');
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Cancel a pending payment request
|
|
277
|
+
* @param {string} rtpId - RTP ID
|
|
278
|
+
* @param {Object} data - RTP cancellation data
|
|
279
|
+
* @param {string} token - Access token
|
|
280
|
+
* @returns {Promise<Object>} - RTP cancellation response
|
|
281
|
+
* @link https://docs.maibmerchants.md/request-to-pay/api-reference/endpoints/cancel-a-pending-payment-request
|
|
282
|
+
*/
|
|
283
|
+
async rtpCancel(rtpId, data, token) {
|
|
284
|
+
const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_RTP_CANCEL, { rtpId });
|
|
285
|
+
return this._executeOperation(endpoint, token, data);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* List all payment requests
|
|
290
|
+
* @param {Object} params - Retrieval params
|
|
291
|
+
* @param {string} token - Access token
|
|
292
|
+
* @returns {Promise<Object>} - Retrieval response
|
|
293
|
+
* @link https://docs.maibmerchants.md/request-to-pay/api-reference/endpoints/list-all-payment-requests
|
|
294
|
+
*/
|
|
295
|
+
async rtpList(params, token) {
|
|
296
|
+
return this._executeOperation(API_ENDPOINTS.MIA_RTP, token, null, null, 'GET', params);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Initiate a refund for a completed payment
|
|
301
|
+
* @param {string} payId - Payment ID
|
|
302
|
+
* @param {Object} data - Refund data
|
|
303
|
+
* @param {string} token - Access token
|
|
304
|
+
* @returns {Promise<Object>} - Refund response
|
|
305
|
+
* @link https://docs.maibmerchants.md/request-to-pay/api-reference/endpoints/initiate-a-refund-for-a-completed-payment
|
|
306
|
+
*/
|
|
307
|
+
async rtpRefund(payId, data, token) {
|
|
308
|
+
const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_RTP_REFUND, { payId });
|
|
309
|
+
return this._executeOperation(endpoint, token, data);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Simulate acceptance of a payment request
|
|
314
|
+
* @param {string} rtpId - RTP ID
|
|
315
|
+
* @param {Object} data - Test payment data
|
|
316
|
+
* @param {string} token - Access token
|
|
317
|
+
* @returns {Promise<Object>} - Test accept response
|
|
318
|
+
* @link https://docs.maibmerchants.md/request-to-pay/api-reference/sandbox-simulation-environment/simulate-acceptance-of-a-payment-request
|
|
319
|
+
*/
|
|
320
|
+
async rtpTestAccept(rtpId, data, token) {
|
|
321
|
+
const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_RTP_TEST_ACCEPT, { rtpId });
|
|
322
|
+
return this._executeOperation(endpoint, token, data, REQUIRED_PARAMS.TEST_ACCEPT_PARAMS);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Simulate rejection of a payment request
|
|
327
|
+
* @param {string} rtpId - RTP ID
|
|
328
|
+
* @param {string} token - Access token
|
|
329
|
+
* @returns {Promise<Object>} - Test reject response
|
|
330
|
+
* @link https://docs.maibmerchants.md/request-to-pay/api-reference/sandbox-simulation-environment/simulate-rejection-of-a-payment-request
|
|
331
|
+
*/
|
|
332
|
+
async rtpTestReject(rtpId, token) {
|
|
333
|
+
const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_RTP_TEST_REJECT, { rtpId });
|
|
334
|
+
return this._executeOperation(endpoint, token);
|
|
335
|
+
}
|
|
336
|
+
//#endregion
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
module.exports = MaibMiaApiRequest;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js SDK for maib MIA API
|
|
3
|
+
* Authentication Request Handler
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { API_ENDPOINTS } = require('./constants');
|
|
7
|
+
const { MaibMiaValidationError } = require('./errors');
|
|
8
|
+
|
|
9
|
+
const MaibMiaSdk = require('./MaibMiaSdk');
|
|
10
|
+
|
|
11
|
+
class MaibMiaAuthRequest {
|
|
12
|
+
/**
|
|
13
|
+
* Create a new MaibMiaAuthRequest instance
|
|
14
|
+
* @param {string} baseUrl - maib MIA API base url
|
|
15
|
+
* @param {number} timeout - API request timeout in milliseconds
|
|
16
|
+
*/
|
|
17
|
+
constructor(baseUrl = MaibMiaSdk.DEFAULT_BASE_URL, timeout = MaibMiaSdk.DEFAULT_TIMEOUT) {
|
|
18
|
+
this.client = new MaibMiaSdk(baseUrl, timeout);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Static factory method to create an instance
|
|
23
|
+
* @param {string} baseUrl - maib MIA API base url
|
|
24
|
+
* @param {number} timeout - API request timeout in milliseconds
|
|
25
|
+
* @returns {MaibMiaAuthRequest}
|
|
26
|
+
*/
|
|
27
|
+
static create(baseUrl = MaibMiaSdk.DEFAULT_BASE_URL, timeout = MaibMiaSdk.DEFAULT_TIMEOUT) {
|
|
28
|
+
return new MaibMiaAuthRequest(baseUrl, timeout);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Obtain Authentication Token
|
|
33
|
+
* @param {string} clientId - Client ID
|
|
34
|
+
* @param {string} clientSecret - Client secret
|
|
35
|
+
* @returns {Promise<Object>} - Token response object
|
|
36
|
+
* @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/authentication/obtain-authentication-token
|
|
37
|
+
* @throws {MaibMiaValidationError} - If Client ID or Client secret are invalid
|
|
38
|
+
*/
|
|
39
|
+
async generateToken(clientId, clientSecret) {
|
|
40
|
+
if (!clientId || !clientSecret) {
|
|
41
|
+
throw new MaibMiaValidationError('Client ID and Client Secret are required');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const tokenData = { clientId, clientSecret };
|
|
45
|
+
return this.client._sendRequest('POST', API_ENDPOINTS.AUTH_TOKEN, tokenData);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = MaibMiaAuthRequest;
|