@mft/moneyhub-api-client 4.14.0 → 4.15.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/package.json +1 -1
- package/readme.md +125 -9
- package/src/__tests__/index.js +5 -0
- package/src/get-auth-urls.js +71 -0
- package/src/index.js +2 -1
- package/src/requests/recurring-payments.js +37 -0
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -289,7 +289,7 @@ Creates a request object
|
|
|
289
289
|
const tokens = await moneyhub.requestObject({
|
|
290
290
|
scope: "the-required-scope",
|
|
291
291
|
state: "state",
|
|
292
|
-
nonce: "nonce,
|
|
292
|
+
nonce: "nonce",
|
|
293
293
|
claims: claimsObject,
|
|
294
294
|
})
|
|
295
295
|
```
|
|
@@ -322,7 +322,7 @@ Creates a connection auth request
|
|
|
322
322
|
|
|
323
323
|
```javascript
|
|
324
324
|
const tokens = await moneyhub.createAuthRequest({
|
|
325
|
-
redirectUri: "redirect-uri,
|
|
325
|
+
redirectUri: "redirect-uri",
|
|
326
326
|
userId: "user-id",
|
|
327
327
|
scope:"openid 1ffe704d39629a929c8e293880fb449a", // replace bank id with the bank you want to connect to
|
|
328
328
|
categorisationType: "personal", // optional - defaults to personal
|
|
@@ -334,7 +334,7 @@ Creates a reauth auth request
|
|
|
334
334
|
|
|
335
335
|
```javascript
|
|
336
336
|
const tokens = await moneyhub.createAuthRequest({
|
|
337
|
-
redirectUri: "redirect-uri,
|
|
337
|
+
redirectUri: "redirect-uri",
|
|
338
338
|
userId: "user-id",
|
|
339
339
|
connectionId: "connection-id",
|
|
340
340
|
scope:"openid reauth",
|
|
@@ -345,7 +345,7 @@ Creates a refresh auth request
|
|
|
345
345
|
|
|
346
346
|
```javascript
|
|
347
347
|
const tokens = await moneyhub.createAuthRequest({
|
|
348
|
-
redirectUri: "redirect-uri,
|
|
348
|
+
redirectUri: "redirect-uri",
|
|
349
349
|
userId: "user-id",
|
|
350
350
|
connectionId: "connection-id",
|
|
351
351
|
scope:"openid refresh",
|
|
@@ -356,14 +356,14 @@ Creates a payment auth request
|
|
|
356
356
|
|
|
357
357
|
```javascript
|
|
358
358
|
const tokens = await moneyhub.createAuthRequest({
|
|
359
|
-
redirectUri: "redirect-uri,
|
|
359
|
+
redirectUri: "redirect-uri",
|
|
360
360
|
userId: "user-id",
|
|
361
361
|
connectionId: "connection-id",
|
|
362
362
|
scope:"openid payment",
|
|
363
363
|
payment: {
|
|
364
364
|
payeeId: "payee-id",
|
|
365
365
|
amount: 200,
|
|
366
|
-
payeeRef: "Payee ref,
|
|
366
|
+
payeeRef: "Payee ref",
|
|
367
367
|
payerRef: "Payer ref"
|
|
368
368
|
},
|
|
369
369
|
})
|
|
@@ -373,7 +373,7 @@ Creates a reverse payment auth request
|
|
|
373
373
|
|
|
374
374
|
```javascript
|
|
375
375
|
const tokens = await moneyhub.createAuthRequest({
|
|
376
|
-
redirectUri: "redirect-uri,
|
|
376
|
+
redirectUri: "redirect-uri",
|
|
377
377
|
userId: "user-id",
|
|
378
378
|
connectionId: "connection-id",
|
|
379
379
|
scope:"openid reverse_payment",
|
|
@@ -438,7 +438,7 @@ Helper method that gets the correct client credentials access token and then reg
|
|
|
438
438
|
|
|
439
439
|
```javascript
|
|
440
440
|
const user = await moneyhub.registerUser({
|
|
441
|
-
clientUserId: "your user id"
|
|
441
|
+
clientUserId: "your user id" // optional
|
|
442
442
|
})
|
|
443
443
|
```
|
|
444
444
|
|
|
@@ -1113,7 +1113,7 @@ const url = await moneyhub.getPaymentAuthorizeUrl({
|
|
|
1113
1113
|
state: "your state value",
|
|
1114
1114
|
nonce: "your nonce value", // optional
|
|
1115
1115
|
context: "Payment context [Other,BillPayment,PartyToParty]", // optional - defaults to PartyToParty
|
|
1116
|
-
userId: "Moneyhub API User ID you wish to attach to the payment" // optional
|
|
1116
|
+
userId: "Moneyhub API User ID you wish to attach to the payment", // optional
|
|
1117
1117
|
claims: claimsObject, // optional
|
|
1118
1118
|
})
|
|
1119
1119
|
|
|
@@ -1333,6 +1333,122 @@ const standingOrder = await moneyhub.getStandingOrder({
|
|
|
1333
1333
|
})
|
|
1334
1334
|
```
|
|
1335
1335
|
|
|
1336
|
+
### Recurring Payments (VRP)
|
|
1337
|
+
|
|
1338
|
+
#### `getRecurringPaymentAuthorizeUrl`
|
|
1339
|
+
|
|
1340
|
+
This is a helper function that returns an authorize url to authorize a recurring payment with the selected bank. This function uses the following scope with the value of the bankId provided `recurring_payment:create openid id:${bankId}`. It also requires the authentication to be `client_secret_jwt` or `private_key_jwt`.
|
|
1341
|
+
|
|
1342
|
+
```javascript
|
|
1343
|
+
const url = await moneyhub.getRecurringPaymentAuthorizeUrl({
|
|
1344
|
+
bankId: "Bank id to authorise payment from",
|
|
1345
|
+
payeeId: "Id of payee",
|
|
1346
|
+
payeeType: "Payee type [api-payee|mh-user-account]", // optional - defaults to api-payee
|
|
1347
|
+
payerId: "Id of payer", // requird only if payerType is defined
|
|
1348
|
+
payerType: "Payer type [mh-user-account]", // required only if payerId is used
|
|
1349
|
+
reference: "The reference for recurring payment",
|
|
1350
|
+
validFromDate: "The date from which the authorisation is effective" , // should be in an international format, e.g. 15-MAR-2021 or ISO date
|
|
1351
|
+
validToDate: "The date to which the authorisation is effective", // should be in an international format, e.g. 15-MAR-2021 or ISO date
|
|
1352
|
+
maximumIndividualAmount: "The maimum single amount that will be allowed", // the valid in whole minor units (i.e. pence)
|
|
1353
|
+
currency: "The currency code for the maxiumum recurring payment amount [GBP]",
|
|
1354
|
+
periodicLimits: [
|
|
1355
|
+
{
|
|
1356
|
+
amount: "The maximum amount for this recurring payment limit", // the valid in whole minor units (i.e. pence)
|
|
1357
|
+
currency: "The currency code for this recurring payment limit [GBP]",
|
|
1358
|
+
periodType: "The period over which the limit is effective [Day, Week, Fortnight, Month, Half-year, Year]",
|
|
1359
|
+
periodAlignment: "Specifies whether the period starts on the date of consent creation or lines up with a calendar [Consent, Calendar]",
|
|
1360
|
+
}
|
|
1361
|
+
],
|
|
1362
|
+
type: [
|
|
1363
|
+
"Sweeping", // Specifies that the recurring payment is for the purpose of sweeping payments
|
|
1364
|
+
"Other" // Specifies that the recurring payment is for other payments of another purpose
|
|
1365
|
+
],
|
|
1366
|
+
context: "Payment context [Other,BillPayment,PartyToParty]", // optional - defaults to PartyToParty
|
|
1367
|
+
state: "your state value",
|
|
1368
|
+
nonce: "your nonce value", // optional
|
|
1369
|
+
claims: claimsObject, // optional
|
|
1370
|
+
})
|
|
1371
|
+
|
|
1372
|
+
// Scope used with the bankId provided
|
|
1373
|
+
const scope = `recurring_payment:create openid id:${bankId}`
|
|
1374
|
+
|
|
1375
|
+
// Default claims if none are provided
|
|
1376
|
+
const defaultClaims = {
|
|
1377
|
+
id_token: {
|
|
1378
|
+
"mh:con_id": {
|
|
1379
|
+
essential: true,
|
|
1380
|
+
},
|
|
1381
|
+
"mh:recurring_payment": {
|
|
1382
|
+
essential: true,
|
|
1383
|
+
value: {
|
|
1384
|
+
payeeId,
|
|
1385
|
+
payeeType,
|
|
1386
|
+
payerId,
|
|
1387
|
+
payerType,
|
|
1388
|
+
reference,
|
|
1389
|
+
validFromDate,
|
|
1390
|
+
validToDate,
|
|
1391
|
+
maximumIndividualAmount,
|
|
1392
|
+
currency,
|
|
1393
|
+
periodicLimits,
|
|
1394
|
+
context,
|
|
1395
|
+
},
|
|
1396
|
+
},
|
|
1397
|
+
},
|
|
1398
|
+
}
|
|
1399
|
+
```
|
|
1400
|
+
|
|
1401
|
+
#### `getRecurringPayments`
|
|
1402
|
+
|
|
1403
|
+
This method returns a list of initiated recurring payment consents. This function uses the scope `recurring_payment:read`
|
|
1404
|
+
|
|
1405
|
+
```javascript
|
|
1406
|
+
const recurringPayments = await moneyhub.getRecurringPayments({
|
|
1407
|
+
limit: "limit", // optional
|
|
1408
|
+
offset: "offset", // optional
|
|
1409
|
+
userId: "user-id", // optional
|
|
1410
|
+
payeeId: "payee-id", // optional
|
|
1411
|
+
startDate: "2020-01-01", // optional
|
|
1412
|
+
endDate: "2020-12-31", // optional
|
|
1413
|
+
})
|
|
1414
|
+
```
|
|
1415
|
+
|
|
1416
|
+
#### `getRecurringPayment`
|
|
1417
|
+
|
|
1418
|
+
This method gets a recurring payment consent. This function uses the scope `recurring_payment:create`
|
|
1419
|
+
|
|
1420
|
+
```javascript
|
|
1421
|
+
const recurringPayment = await moneyhub.getRecurringPayment({
|
|
1422
|
+
recurringPaymentId: "Id of the recurring payment consent"
|
|
1423
|
+
})
|
|
1424
|
+
```
|
|
1425
|
+
|
|
1426
|
+
#### `makeRecurringPayment`
|
|
1427
|
+
|
|
1428
|
+
This method creates a payment using the recurring payment consent. This function uses the scope `recurring_payment:create`
|
|
1429
|
+
|
|
1430
|
+
```javascript
|
|
1431
|
+
const recurringPayments = await moneyhub.getRecurringPayments({
|
|
1432
|
+
recurringPaymentId: "Id of the recurring payment consent",
|
|
1433
|
+
payment: {
|
|
1434
|
+
payeeId: "payee-id", // optional
|
|
1435
|
+
amount: 200,
|
|
1436
|
+
payeeRef: "Payee ref",
|
|
1437
|
+
payerRef: "Payer ref"
|
|
1438
|
+
}
|
|
1439
|
+
})
|
|
1440
|
+
```
|
|
1441
|
+
|
|
1442
|
+
#### `revokeRecurringPayment`
|
|
1443
|
+
|
|
1444
|
+
This method revokes a recurring payment consent. This function uses the scope `recurring_payment:create`
|
|
1445
|
+
|
|
1446
|
+
```javascript
|
|
1447
|
+
const revokedRecurringPayment = await moneyhub.revokeRecurringPayment({
|
|
1448
|
+
recurringPaymentId: "Id of the recurring payment consent"
|
|
1449
|
+
})
|
|
1450
|
+
```
|
|
1451
|
+
|
|
1336
1452
|
#### `getRegularTransactions`
|
|
1337
1453
|
|
|
1338
1454
|
Get all the regular transactions for a user, there is an option to pass an account ID as a parameter as a filter. This function uses the scope `accounts:read`, `transactions:read:all` and `regular_transactions:read`
|
package/src/__tests__/index.js
CHANGED
|
@@ -92,6 +92,10 @@ describe("API client", () => {
|
|
|
92
92
|
"getRentalRecords",
|
|
93
93
|
"createRentalRecord",
|
|
94
94
|
"deleteRentalRecord",
|
|
95
|
+
"getRecurringPayments",
|
|
96
|
+
"getRecurringPayment",
|
|
97
|
+
"makeRecurringPayment",
|
|
98
|
+
"revokeRecurringPayment",
|
|
95
99
|
"getAuthorizeUrl",
|
|
96
100
|
"getAuthorizeUrlFromRequestUri",
|
|
97
101
|
"requestObject",
|
|
@@ -101,6 +105,7 @@ describe("API client", () => {
|
|
|
101
105
|
"getRefreshAuthorizeUrlForCreatedUser",
|
|
102
106
|
"getPaymentAuthorizeUrl",
|
|
103
107
|
"getReversePaymentAuthorizeUrl",
|
|
108
|
+
"getRecurringPaymentAuthorizeUrl",
|
|
104
109
|
"getStandingOrderAuthorizeUrl",
|
|
105
110
|
"exchangeCodeForTokensLegacy",
|
|
106
111
|
"exchangeCodeForTokens",
|
package/src/get-auth-urls.js
CHANGED
|
@@ -329,6 +329,77 @@ module.exports = ({client, config}) => {
|
|
|
329
329
|
return url
|
|
330
330
|
},
|
|
331
331
|
|
|
332
|
+
getRecurringPaymentAuthorizeUrl: async ({
|
|
333
|
+
bankId,
|
|
334
|
+
payeeId,
|
|
335
|
+
payeeType,
|
|
336
|
+
payerId,
|
|
337
|
+
payerType,
|
|
338
|
+
reference,
|
|
339
|
+
validFromDate,
|
|
340
|
+
validToDate,
|
|
341
|
+
maximumIndividualAmount,
|
|
342
|
+
currency,
|
|
343
|
+
periodicLimits,
|
|
344
|
+
type,
|
|
345
|
+
context,
|
|
346
|
+
state,
|
|
347
|
+
nonce,
|
|
348
|
+
userId,
|
|
349
|
+
claims = {},
|
|
350
|
+
}) => {
|
|
351
|
+
if (!state) {
|
|
352
|
+
console.error("State is required")
|
|
353
|
+
throw new Error("Missing parameters")
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const scope = `recurring_payment:create openid id:${bankId}`
|
|
357
|
+
const defaultClaims = {
|
|
358
|
+
id_token: {
|
|
359
|
+
"mh:con_id": {
|
|
360
|
+
essential: true,
|
|
361
|
+
},
|
|
362
|
+
"mh:recurring_payment": {
|
|
363
|
+
essential: true,
|
|
364
|
+
value: {
|
|
365
|
+
payeeId,
|
|
366
|
+
payeeType,
|
|
367
|
+
payerId,
|
|
368
|
+
payerType,
|
|
369
|
+
reference,
|
|
370
|
+
validFromDate,
|
|
371
|
+
validToDate,
|
|
372
|
+
maximumIndividualAmount,
|
|
373
|
+
currency,
|
|
374
|
+
periodicLimits,
|
|
375
|
+
type,
|
|
376
|
+
context,
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
...userId && {
|
|
380
|
+
sub: {
|
|
381
|
+
value: userId
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const _claims = R.mergeDeepRight(defaultClaims, claims)
|
|
388
|
+
|
|
389
|
+
const request = await requestObject({
|
|
390
|
+
scope,
|
|
391
|
+
state,
|
|
392
|
+
claims: _claims,
|
|
393
|
+
nonce,
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
const requestUri = await getRequestUri(request)
|
|
397
|
+
const url = getAuthorizeUrlFromRequestUri({
|
|
398
|
+
requestUri,
|
|
399
|
+
})
|
|
400
|
+
return url
|
|
401
|
+
},
|
|
402
|
+
|
|
332
403
|
getStandingOrderAuthorizeUrl: async ({
|
|
333
404
|
bankId,
|
|
334
405
|
payeeId,
|
package/src/index.js
CHANGED
|
@@ -20,7 +20,8 @@ const requestFactories = [
|
|
|
20
20
|
require("./requests/categories"),
|
|
21
21
|
require("./requests/standing-orders"),
|
|
22
22
|
require("./requests/regular-transactions"),
|
|
23
|
-
require("./requests/rental-records")
|
|
23
|
+
require("./requests/rental-records"),
|
|
24
|
+
require("./requests/recurring-payments"),
|
|
24
25
|
]
|
|
25
26
|
const DEFAULT_TIMEOUT = 60000
|
|
26
27
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module.exports = ({config, request}) => {
|
|
2
|
+
const {identityServiceUrl} = config
|
|
3
|
+
|
|
4
|
+
return {
|
|
5
|
+
getRecurringPayments: async (params = {}) =>
|
|
6
|
+
request(`${identityServiceUrl}/recurring-payments`, {
|
|
7
|
+
searchParams: params,
|
|
8
|
+
cc: {
|
|
9
|
+
scope: "recurring_payment:read",
|
|
10
|
+
},
|
|
11
|
+
}),
|
|
12
|
+
|
|
13
|
+
getRecurringPayment: async ({recurringPaymentId}) =>
|
|
14
|
+
request(`${identityServiceUrl}/recurring-payments/${recurringPaymentId}`, {
|
|
15
|
+
cc: {
|
|
16
|
+
scope: "recurring_payment:read",
|
|
17
|
+
},
|
|
18
|
+
}),
|
|
19
|
+
|
|
20
|
+
makeRecurringPayment: async ({recurringPaymentId, payment}) =>
|
|
21
|
+
request(`${identityServiceUrl}/recurring-payments/${recurringPaymentId}/pay`, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
body: payment,
|
|
24
|
+
cc: {
|
|
25
|
+
scope: "recurring_payment:create",
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
|
|
29
|
+
revokeRecurringPayment: async ({recurringPaymentId}) =>
|
|
30
|
+
request(`${identityServiceUrl}/recurring-payments/${recurringPaymentId}`, {
|
|
31
|
+
method: "DELETE",
|
|
32
|
+
cc: {
|
|
33
|
+
scope: "recurring_payment:create",
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
}
|
|
37
|
+
}
|