Skip to content

Commit 0ccbacb

Browse files
author
Jenkins
committed
latest version
1 parent 3ec0bcf commit 0ccbacb

33 files changed

+3004
-198
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Npm
2+
node_modules
3+
*/node_modules

examples/ExampleAccountDetails.js

Lines changed: 0 additions & 117 deletions
This file was deleted.

examples/ExampleConfigureUsers.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

examples/ExampleGetInstitutions.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

examples/accounts/AccountsUtil.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
var constants = require('../constants.js')
2+
var YapilyApi = require('@yapily/yapily-api')
3+
4+
var defaultClient = YapilyApi.ApiClient.instance
5+
6+
var basicAuth = defaultClient.authentications['basicAuth']
7+
basicAuth.username = constants.APPLICATION_ID
8+
basicAuth.password = constants.APPLICATION_SECRET
9+
10+
var accountAuthorisationRequest = new YapilyApi.AccountAuthorisationRequest();
11+
var accountsApi = new YapilyApi.AccountsApi()
12+
13+
/**
14+
* Yapily POST /account-auth-requests endpoint
15+
*
16+
* See: https://api.yapily.com/explorer#!/Accounts/initiateAccountRequestUsingPOST
17+
*/
18+
module.exports.initiateAccountRequestUsingPOST = function(userUuid, institutionId, callback) {
19+
20+
accountAuthorisationRequest.userUuid = userUuid;
21+
accountAuthorisationRequest.institutionId = institutionId;
22+
console.log("\nCreating authorisation request object: \n\n", accountAuthorisationRequest)
23+
24+
accountsApi.initiateAccountRequestUsingPOST(accountAuthorisationRequest, function(error, response){
25+
if(error) {
26+
console.log("\nError creating authorisation request: \n\n", error)
27+
} else {
28+
console.log("\nCreated account authorisation request: \n\n", response)
29+
callback(null, response);
30+
}
31+
});
32+
}
33+
34+
/**
35+
* Yapily PATCH /account-auth-requests endpoint
36+
*
37+
* See: https://api.yapily.com/explorer#!/Accounts/reAuthoriseAccountUsingPATCH
38+
*/
39+
module.exports.reAuthoriseAccountUsingPATCH = function(consentToken, callback) {
40+
41+
accountsApi.reAuthoriseAccountUsingPATCH(consentToken, function(error, response){
42+
if(error) {
43+
console.log("\nError re-authorising existing consent request: \n\n", error)
44+
} else {
45+
console.log("\nRe-authorising existing consent request: \n\n", response)
46+
callback(null, response);
47+
}
48+
});
49+
}
50+
51+
/**
52+
* Yapily GET /accounts endpoint
53+
*
54+
* See: https://api.yapily.com/explorer#!/Accounts/getAccountsUsingGET
55+
*/
56+
module.exports.getAccountsUsingGET = function(consentToken, callback) {
57+
58+
accountsApi.getAccountsUsingGET(consentToken, function(error, accounts) {
59+
if(error) {
60+
if (error.status == 403) {
61+
console.log("\nError retrieving accounts with this consent. It is likely the bank has revoked the token. Create a new consent to access the accounts \n" +
62+
"You can run the accounts/ReAuthoriseConsent example using this consentToken to re-use the same feature scopes\n\n")
63+
} else {
64+
console.log("\nError retrieving accounts with this consent", error)
65+
}
66+
} else {
67+
console.log("\n Accounts received: ")
68+
69+
console.log("\n\n**************ACCOUNTS******************")
70+
console.log(accounts)
71+
console.log("****************************************")
72+
73+
callback(null, accounts)
74+
}
75+
});
76+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const readline = require('readline')
2+
var util = require('util')
3+
4+
var constants = require('../constants.js')
5+
var YapilyApi = require('@yapily/yapily-api')
6+
var StatusEnum = require('@yapily/yapily-api').Consent.StatusEnum;
7+
8+
var ApplicationUserUtils = require('../users/ApplicationUserUtils')
9+
var AccountsUtil = require('./AccountsUtil');
10+
var ConsentUtils = require('../consents/ConsentsUtils');
11+
12+
var defaultClient = YapilyApi.ApiClient.instance
13+
14+
var basicAuth = defaultClient.authentications['basicAuth']
15+
basicAuth.username = constants.APPLICATION_ID
16+
basicAuth.password = constants.APPLICATION_SECRET
17+
18+
INSTITUTION_ID = constants.INSTITUTION_ID
19+
USER_ID = constants.USER_ID
20+
21+
var createReadLine = function() {
22+
23+
return readline.createInterface({
24+
input: process.stdin,
25+
output: process.stdout
26+
})
27+
}
28+
29+
var authorizationReadline = createReadLine()
30+
31+
//Get an existing user
32+
ApplicationUserUtils.getUserUsingGET(USER_ID, function(error, user) {
33+
var now = new Date();
34+
if(user) {
35+
36+
opts = {
37+
"filterUserUuid": [ USER_ID ],
38+
"filterInstitution": [ INSTITUTION_ID ],
39+
"filterStatus": [ StatusEnum.AUTHORIZED ],
40+
"limit": 1
41+
}
42+
43+
//Get the first consent for this user and institution that is authorised
44+
ConsentUtils.getConsentsUsingGET(opts, function(error, consents) {
45+
if(consents) {
46+
var consentToken = consents.data[0].consentToken;
47+
var consentId = consents.data[0].id;
48+
49+
//A successful authenticated request should have the consent token
50+
if(consentToken != null) {
51+
console.log("\nConsent Token fetched for consent with id: %s", consentId)
52+
53+
//Use this consentToken to get all the available accounts
54+
AccountsUtil.getAccountsUsingGET(consentToken, function(error, accounts) {
55+
})
56+
}
57+
} else {
58+
console.log("\nCould not find an existing authorized consent token. It may have expired or been revoked by the institution. Try creating a new consent!.")
59+
}
60+
})
61+
}
62+
})

0 commit comments

Comments
 (0)