maib-mia-sdk 1.0.2 → 1.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maib-mia-sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Node.js SDK for maib MIA API",
5
5
  "keywords": [
6
6
  "maib",
@@ -53,17 +53,17 @@ class MaibMiaApiRequest {
53
53
  /**
54
54
  * Perform API request
55
55
  * @param {string} endpoint - API endpoint
56
+ * @param {string} authToken - Access token
56
57
  * @param {Object} data - Request data
57
- * @param {string} token - Access token
58
58
  * @param {string[]} requiredParams - Array of required field names
59
59
  * @param {string} method - Request HTTP method
60
60
  * @param {Object} params - Request params
61
61
  */
62
- async _executeOperation(endpoint, token, data=null, requiredParams=null, method='POST', params=null) {
63
- MaibMiaApiRequest._validateAccessToken(token);
62
+ async _executeOperation(endpoint, authToken, data = null, requiredParams = null, method = 'POST', params = null) {
63
+ MaibMiaApiRequest._validateAccessToken(authToken);
64
64
  MaibMiaApiRequest._validateParams(data, requiredParams);
65
65
 
66
- return this.client._sendRequest(method, endpoint, data, params, token);
66
+ return this.client._sendRequest(method, endpoint, data, params, authToken);
67
67
  }
68
68
 
69
69
  /**
@@ -96,11 +96,11 @@ class MaibMiaApiRequest {
96
96
 
97
97
  /**
98
98
  * Validates the access token
99
- * @param {string} token - Access token
99
+ * @param {string} authToken - Access token
100
100
  * @throws {MaibMiaValidationError} - If Access token parameter is invalid
101
101
  */
102
- static _validateAccessToken(token) {
103
- if (!token) {
102
+ static _validateAccessToken(authToken) {
103
+ if (!authToken) {
104
104
  throw new MaibMiaValidationError('Access token is required');
105
105
  }
106
106
  }
@@ -121,7 +121,7 @@ class MaibMiaApiRequest {
121
121
  }
122
122
 
123
123
  const missingParams = requiredParams.filter(field =>
124
- data[field] === undefined || data[field] === null
124
+ data[field] == null
125
125
  );
126
126
 
127
127
  if (missingParams.length > 0) {
@@ -134,87 +134,87 @@ class MaibMiaApiRequest {
134
134
  /**
135
135
  * Create QR Code (Static, Dynamic)
136
136
  * @param {Object} data - QR code data
137
- * @param {string} token - Access token
137
+ * @param {string} authToken - Access token
138
138
  * @returns {Promise<Object>} - QR creation response
139
139
  * @link https://docs.maibmerchants.md/mia-qr-api/en/overview/mia-qr-types
140
140
  * @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/payment-initiation/create-qr-code-static-dynamic
141
141
  */
142
- async qrCreate(data, token) {
143
- return this._executeOperation(API_ENDPOINTS.MIA_QR, token, data, REQUIRED_PARAMS.QR_PARAMS);
142
+ async qrCreate(data, authToken) {
143
+ return this._executeOperation(API_ENDPOINTS.MIA_QR, authToken, data, REQUIRED_PARAMS.QR_PARAMS);
144
144
  }
145
145
 
146
146
  /**
147
147
  * Create Hybrid QR Code
148
148
  * @param {Object} data - QR code data
149
- * @param {string} token - Access token
149
+ * @param {string} authToken - Access token
150
150
  * @returns {Promise<Object>} - QR creation response
151
151
  * @link https://docs.maibmerchants.md/mia-qr-api/en/overview/mia-qr-types
152
152
  * @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/payment-initiation/create-hybrid-qr-code
153
153
  */
154
- async qrCreateHybrid(data, token) {
155
- return this._executeOperation(API_ENDPOINTS.MIA_QR_HYBRID, token, data, REQUIRED_PARAMS.QR_HYBRID_PARAMS);
154
+ async qrCreateHybrid(data, authToken) {
155
+ return this._executeOperation(API_ENDPOINTS.MIA_QR_HYBRID, authToken, data, REQUIRED_PARAMS.QR_HYBRID_PARAMS);
156
156
  }
157
157
 
158
158
  /**
159
159
  * Create Extension for QR Code by ID
160
160
  * @param {string} qrId - QR code ID
161
161
  * @param {Object} data - QR code extension data
162
- * @param {string} token - Access token
162
+ * @param {string} authToken - Access token
163
163
  * @returns {Promise<Object>} - QR creation response
164
164
  * @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/payment-initiation/create-hybrid-qr-code/create-extension-for-qr-code-by-id
165
165
  */
166
- async qrCreateExtension(qrId, data, token) {
166
+ async qrCreateExtension(qrId, data, authToken) {
167
167
  const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_QR_EXTENSION, { qrId });
168
- return this._executeOperation(endpoint, token, data, REQUIRED_PARAMS.QR_EXTENSION_PARAMS);
168
+ return this._executeOperation(endpoint, authToken, data, REQUIRED_PARAMS.QR_EXTENSION_PARAMS);
169
169
  }
170
170
 
171
171
  /**
172
172
  * Retrieve QR Details by ID
173
173
  * @param {string} qrId - QR code ID
174
- * @param {string} token - Access token
174
+ * @param {string} authToken - Access token
175
175
  * @returns {Promise<Object>} - QR details
176
176
  * @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/information-retrieval-get/retrieve-qr-details-by-id
177
177
  */
178
- async qrDetails(qrId, token) {
178
+ async qrDetails(qrId, authToken) {
179
179
  const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_QR_ID, { qrId });
180
- return this._executeOperation(endpoint, token, null, null, 'GET');
180
+ return this._executeOperation(endpoint, authToken, null, null, 'GET');
181
181
  }
182
182
 
183
183
  /**
184
184
  * Cancel Active QR (Static, Dynamic)
185
185
  * @param {string} qrId - QR code ID
186
186
  * @param {Object} data - QR code cancellation data
187
- * @param {string} token - Access token
187
+ * @param {string} authToken - Access token
188
188
  * @returns {Promise<Object>} - Cancellation response
189
189
  * @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/payment-cancellation/cancel-active-qr-static-dynamic
190
190
  */
191
- async qrCancel(qrId, data, token) {
191
+ async qrCancel(qrId, data, authToken) {
192
192
  const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_QR_CANCEL, { qrId });
193
- return this._executeOperation(endpoint, token, data);
193
+ return this._executeOperation(endpoint, authToken, data);
194
194
  }
195
195
 
196
196
  /**
197
197
  * Cancel Active QR Extension (Hybrid)
198
198
  * @param {string} qrId - QR code ID
199
199
  * @param {Object} data - QR code extension cancellation data
200
- * @param {string} token - Access token
200
+ * @param {string} authToken - Access token
201
201
  * @returns {Promise<Object>} - Cancellation response
202
202
  * @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/payment-cancellation/cancel-active-qr-extension-hybrid
203
203
  */
204
- async qrCancelExtension(qrId, data, token) {
204
+ async qrCancelExtension(qrId, data, authToken) {
205
205
  const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_QR_EXTENSION_CANCEL, { qrId });
206
- return this._executeOperation(endpoint, token, data);
206
+ return this._executeOperation(endpoint, authToken, data);
207
207
  }
208
208
 
209
209
  /**
210
210
  * Retrieve List of QR Codes with Filtering Options
211
211
  * @param {Object} params - Retrieval params
212
- * @param {string} token - Access token
212
+ * @param {string} authToken - Access token
213
213
  * @returns {Promise<Object>} - Retrieval response
214
214
  * @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/information-retrieval-get/display-list-of-qr-codes-with-filtering-options
215
215
  */
216
- async qrList(params, token) {
217
- return this._executeOperation(API_ENDPOINTS.MIA_QR, token, null, null, 'GET', params);
216
+ async qrList(params, authToken) {
217
+ return this._executeOperation(API_ENDPOINTS.MIA_QR, authToken, null, null, 'GET', params);
218
218
  }
219
219
  //#endregion
220
220
 
@@ -222,48 +222,48 @@ class MaibMiaApiRequest {
222
222
  /**
223
223
  * Payment Simulation (Sandbox)
224
224
  * @param {Object} data - Test payment data
225
- * @param {string} token - Access token
225
+ * @param {string} authToken - Access token
226
226
  * @returns {Promise<Object>} - Test payment response
227
227
  * @link https://docs.maibmerchants.md/mia-qr-api/en/payment-simulation-sandbox
228
228
  */
229
- async testPay(data, token) {
230
- return this._executeOperation(API_ENDPOINTS.MIA_TEST_PAY, token, data, REQUIRED_PARAMS.TEST_PAY_PARAMS);
229
+ async testPay(data, authToken) {
230
+ return this._executeOperation(API_ENDPOINTS.MIA_TEST_PAY, authToken, data, REQUIRED_PARAMS.TEST_PAY_PARAMS);
231
231
  }
232
232
 
233
233
  /**
234
234
  * Retrieve Payment Details by ID
235
235
  * @param {string} payId - Payment ID
236
- * @param {string} token - Access token
236
+ * @param {string} authToken - Access token
237
237
  * @returns {Promise<Object>} - Payment details response
238
238
  * @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/information-retrieval-get/retrieve-payment-details-by-id
239
239
  */
240
- async paymentDetails(payId, token) {
240
+ async paymentDetails(payId, authToken) {
241
241
  const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_PAYMENTS_ID, { payId });
242
- return this._executeOperation(endpoint, token, null, null, 'GET');
242
+ return this._executeOperation(endpoint, authToken, null, null, 'GET');
243
243
  }
244
244
 
245
245
  /**
246
246
  * Refund Completed Payment
247
247
  * @param {string} payId - Payment ID
248
248
  * @param {Object} data - Refund data
249
- * @param {string} token - Access token
249
+ * @param {string} authToken - Access token
250
250
  * @returns {Promise<Object>} - Refund response
251
251
  * @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/payment-refund/refund-completed-payment
252
252
  */
253
- async paymentRefund(payId, data, token) {
253
+ async paymentRefund(payId, data, authToken) {
254
254
  const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.PAYMENTS_REFUND, { payId });
255
- return this._executeOperation(endpoint, token, data);
255
+ return this._executeOperation(endpoint, authToken, data, REQUIRED_PARAMS.PAYMENTS_REFUND_PARAMS);
256
256
  }
257
257
 
258
258
  /**
259
259
  * Retrieve List of Payments with Filtering Options
260
260
  * @param {Object} params - Retrieval params
261
- * @param {string} token - Access token
261
+ * @param {string} authToken - Access token
262
262
  * @link https://docs.maibmerchants.md/mia-qr-api/en/endpoints/information-retrieval-get/retrieve-list-of-payments-with-filtering-options
263
263
  * @returns {Promise<Object>} - Retrieval response
264
264
  */
265
- async paymentList(params, token) {
266
- return this._executeOperation(API_ENDPOINTS.MIA_PAYMENTS, token, null, null, 'GET', params);
265
+ async paymentList(params, authToken) {
266
+ return this._executeOperation(API_ENDPOINTS.MIA_PAYMENTS, authToken, null, null, 'GET', params);
267
267
  }
268
268
  //#endregion
269
269
 
@@ -271,86 +271,86 @@ class MaibMiaApiRequest {
271
271
  /**
272
272
  * Create a new payment request (RTP)
273
273
  * @param {Object} data - RTP data
274
- * @param {string} token - Access token
274
+ * @param {string} authToken - Access token
275
275
  * @returns {Promise<Object>} - RTP creation response
276
276
  * @link https://docs.maibmerchants.md/request-to-pay/api-reference/endpoints/create-a-new-payment-request-rtp
277
277
  */
278
- async rtpCreate(data, token) {
279
- return this._executeOperation(API_ENDPOINTS.MIA_RTP, token, data, REQUIRED_PARAMS.RTP_PARAMS);
278
+ async rtpCreate(data, authToken) {
279
+ return this._executeOperation(API_ENDPOINTS.MIA_RTP, authToken, data, REQUIRED_PARAMS.RTP_PARAMS);
280
280
  }
281
281
 
282
282
  /**
283
283
  * Retrieve the status of a payment request
284
284
  * @param {string} rtpId - RTP ID
285
- * @param {string} token - Access token
285
+ * @param {string} authToken - Access token
286
286
  * @returns {Promise<Object>} - RTP status response
287
287
  * @link https://docs.maibmerchants.md/request-to-pay/api-reference/endpoints/retrieve-the-status-of-a-payment-request
288
288
  */
289
- async rtpStatus(rtpId, token) {
289
+ async rtpStatus(rtpId, authToken) {
290
290
  const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_RTP_ID, { rtpId });
291
- return this._executeOperation(endpoint, token, null, null, 'GET');
291
+ return this._executeOperation(endpoint, authToken, null, null, 'GET');
292
292
  }
293
293
 
294
294
  /**
295
295
  * Cancel a pending payment request
296
296
  * @param {string} rtpId - RTP ID
297
297
  * @param {Object} data - RTP cancellation data
298
- * @param {string} token - Access token
298
+ * @param {string} authToken - Access token
299
299
  * @returns {Promise<Object>} - RTP cancellation response
300
300
  * @link https://docs.maibmerchants.md/request-to-pay/api-reference/endpoints/cancel-a-pending-payment-request
301
301
  */
302
- async rtpCancel(rtpId, data, token) {
302
+ async rtpCancel(rtpId, data, authToken) {
303
303
  const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_RTP_CANCEL, { rtpId });
304
- return this._executeOperation(endpoint, token, data);
304
+ return this._executeOperation(endpoint, authToken, data);
305
305
  }
306
306
 
307
307
  /**
308
308
  * List all payment requests
309
309
  * @param {Object} params - Retrieval params
310
- * @param {string} token - Access token
310
+ * @param {string} authToken - Access token
311
311
  * @returns {Promise<Object>} - Retrieval response
312
312
  * @link https://docs.maibmerchants.md/request-to-pay/api-reference/endpoints/list-all-payment-requests
313
313
  */
314
- async rtpList(params, token) {
315
- return this._executeOperation(API_ENDPOINTS.MIA_RTP, token, null, null, 'GET', params);
314
+ async rtpList(params, authToken) {
315
+ return this._executeOperation(API_ENDPOINTS.MIA_RTP, authToken, null, null, 'GET', params);
316
316
  }
317
317
 
318
318
  /**
319
319
  * Initiate a refund for a completed payment
320
320
  * @param {string} payId - Payment ID
321
321
  * @param {Object} data - Refund data
322
- * @param {string} token - Access token
322
+ * @param {string} authToken - Access token
323
323
  * @returns {Promise<Object>} - Refund response
324
324
  * @link https://docs.maibmerchants.md/request-to-pay/api-reference/endpoints/initiate-a-refund-for-a-completed-payment
325
325
  */
326
- async rtpRefund(payId, data, token) {
326
+ async rtpRefund(payId, data, authToken) {
327
327
  const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_RTP_REFUND, { payId });
328
- return this._executeOperation(endpoint, token, data);
328
+ return this._executeOperation(endpoint, authToken, data);
329
329
  }
330
330
 
331
331
  /**
332
332
  * Simulate acceptance of a payment request
333
333
  * @param {string} rtpId - RTP ID
334
334
  * @param {Object} data - Test payment data
335
- * @param {string} token - Access token
335
+ * @param {string} authToken - Access token
336
336
  * @returns {Promise<Object>} - Test accept response
337
337
  * @link https://docs.maibmerchants.md/request-to-pay/api-reference/sandbox-simulation-environment/simulate-acceptance-of-a-payment-request
338
338
  */
339
- async rtpTestAccept(rtpId, data, token) {
339
+ async rtpTestAccept(rtpId, data, authToken) {
340
340
  const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_RTP_TEST_ACCEPT, { rtpId });
341
- return this._executeOperation(endpoint, token, data, REQUIRED_PARAMS.TEST_ACCEPT_PARAMS);
341
+ return this._executeOperation(endpoint, authToken, data, REQUIRED_PARAMS.TEST_ACCEPT_PARAMS);
342
342
  }
343
343
 
344
344
  /**
345
345
  * Simulate rejection of a payment request
346
346
  * @param {string} rtpId - RTP ID
347
- * @param {string} token - Access token
347
+ * @param {string} authToken - Access token
348
348
  * @returns {Promise<Object>} - Test reject response
349
349
  * @link https://docs.maibmerchants.md/request-to-pay/api-reference/sandbox-simulation-environment/simulate-rejection-of-a-payment-request
350
350
  */
351
- async rtpTestReject(rtpId, token) {
351
+ async rtpTestReject(rtpId, authToken) {
352
352
  const endpoint = MaibMiaApiRequest._buildEndpoint(API_ENDPOINTS.MIA_RTP_TEST_REJECT, { rtpId });
353
- return this._executeOperation(endpoint, token);
353
+ return this._executeOperation(endpoint, authToken);
354
354
  }
355
355
  //#endregion
356
356
  }
package/src/MaibMiaSdk.js CHANGED
@@ -30,15 +30,15 @@ class MaibMiaSdk {
30
30
  });
31
31
  }
32
32
 
33
- setupLogging() {
33
+ setupLogging(logger = console) {
34
34
  this.client.interceptors.request.use(
35
35
  (config) => {
36
36
  const logData = MaibMiaSdk._getLogData(config, config);
37
- console.debug(`${packageName} Request: ${logData.method} ${logData.url}`, logData);
37
+ logger.debug(`${packageName} Request: ${logData.method} ${logData.url}`, logData);
38
38
  return config;
39
39
  },
40
40
  (error) => {
41
- console.error(`${packageName} Request: ${error.message}`, error);
41
+ logger.error(`${packageName} Request: ${error.message}`, error);
42
42
  return Promise.reject(error);
43
43
  }
44
44
  );
@@ -46,13 +46,13 @@ class MaibMiaSdk {
46
46
  this.client.interceptors.response.use(
47
47
  (response) => {
48
48
  const logData = MaibMiaSdk._getLogData(response, response?.config);
49
- console.debug(`${packageName} Response: ${logData.status} ${logData.method} ${logData.url}`, logData);
49
+ logger.debug(`${packageName} Response: ${logData.status} ${logData.method} ${logData.url}`, logData);
50
50
  return response;
51
51
  },
52
52
  (error) => {
53
53
  const config = error.response?.config || error.config;
54
54
  const logData = MaibMiaSdk._getLogData(error.response, config);
55
- console.error(`${packageName} Error: ${logData.status ?? ''} ${logData.data ?? ''}`, logData, error);
55
+ logger.error(`${packageName} Error: ${logData.status ?? ''} ${logData.data ?? ''}`, logData, error);
56
56
  return Promise.reject(error);
57
57
  }
58
58
  );
@@ -210,9 +210,7 @@ class MaibMiaSdk {
210
210
  const hashInput = `${additionalString}:${signatureKey}`;
211
211
 
212
212
  // Hash and base64 encode
213
- const hash = crypto.createHash('sha256').update(hashInput, 'utf8').digest('base64');
214
-
215
- return hash;
213
+ return crypto.createHash('sha256').update(hashInput, 'utf8').digest('base64');
216
214
  }
217
215
  }
218
216
 
package/src/constants.js CHANGED
@@ -48,6 +48,8 @@ const REQUIRED_PARAMS = {
48
48
  QR_EXTENSION_PARAMS: ['expiresAt', 'description'],
49
49
  // https://docs.maibmerchants.md/mia-qr-api/en/payment-simulation-sandbox#request-parameters-body-json
50
50
  TEST_PAY_PARAMS: ['qrId', 'amount', 'iban', 'currency', 'payerName'],
51
+ // https://docs.maibmerchants.md/mia-qr-api/en/endpoints/payment-refund/refund-completed-payment
52
+ PAYMENTS_REFUND_PARAMS: ['reason'],
51
53
  // https://docs.maibmerchants.md/request-to-pay/api-reference/endpoints/create-a-new-payment-request-rtp#request-body-parameters
52
54
  RTP_PARAMS: ['alias', 'amount', 'currency', 'expiresAt', 'description'],
53
55
  // https://docs.maibmerchants.md/request-to-pay/api-reference/sandbox-simulation-environment/simulate-acceptance-of-a-payment-request#request-body-parameters