Merge pull request #10 from yagop/examples

Provide examples
This commit is contained in:
Dimitar Nanov 2019-10-03 09:20:29 +03:00 committed by GitHub
commit 15546df9ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 122 additions and 0 deletions

31
examples/bankLetter.js Executable file
View File

@ -0,0 +1,31 @@
#! /usr/bin/env node
'use strict';
const ebics = require('../index');
const path = require('path');
const fs = require('fs');
const os = require('os');
const client = new ebics.Client({
url: 'https://ebics.server',
partnerId: '',
userId: '',
hostId: '',
passphrase: 'test', // keys-test will be decrypted with this passphrase
keyStorage: ebics.fsKeysStorage('./keys-test'),
});
const bankName = 'Bank name';
const template = fs.readFileSync('./templates/ini.hbs').toString();
const letter = new ebics.BankLetter({ client, bankName, template });
const bankLetterFile = path.join(os.homedir(), 'bankLetter.html');
letter.serialize(bankLetterFile)
.then(() => {
console.log('Send your bank the letter (%s)', bankLetterFile);
})
.catch((err) => {
console.error(err);
process.exit(1);
});

32
examples/initialize.js Executable file
View File

@ -0,0 +1,32 @@
#! /usr/bin/env node
'use strict';
const ebics = require('../index');
const client = new ebics.Client({
url: 'https://ebics.server',
partnerId: 'PARTNER',
userId: 'USER',
hostId: 'HOST',
passphrase: 'test', // keys-test will be encrypted with this passphrase
keyStorage: ebics.fsKeysStorage('./keys-test'),
});
// New keys will be generated and saved in ./keys-test
client.send(ebics.Orders.INI)
.then((resp) => {
console.log('Respose for INI order %j', resp);
return client.send(ebics.Orders.HIA);
})
.then((resp) => {
console.log('Reponse for HIA order %j', resp);
if (resp.technicalCode !== '000000')
throw new Error('Something might went wrong');
console.log('Public keys should be sent to bank now. See examples/bankLetter.js');
})
.catch((err) => {
console.error(err);
process.exit(1);
});

30
examples/save-bank-kesy.js Executable file
View File

@ -0,0 +1,30 @@
#! /usr/bin/env node
'use strict';
const ebics = require('../index');
const client = new ebics.Client({
url: 'https://ebics.server',
partnerId: '',
userId: '',
hostId: '',
passphrase: 'test', // keys-test will be decrypted with this passphrase
keyStorage: ebics.fsKeysStorage('./keys-test'),
});
// Client keys must be already generated and send by letter.
// The bank should have enabled the user
client.send(ebics.Orders.HPB)
.then((resp) => {
console.log('Respose for HPB order %j', resp);
if (resp.technicalCode !== '000000')
throw new Error('Something went wrong');
console.log('Received bank keys: %j', resp.bankKeys);
return client.setBankKeys(resp.bankKeys);
})
.catch((err) => {
console.error(err);
process.exit(1);
});

29
examples/send-hbt-order.js Executable file
View File

@ -0,0 +1,29 @@
#! /usr/bin/env node
'use strict';
const ebics = require('../index');
const client = new ebics.Client({
url: 'https://ebics.server',
partnerId: '',
userId: '',
hostId: '',
passphrase: 'test', // keys-test will be decrypted with this passphrase
keyStorage: ebics.fsKeysStorage('./keys-test'),
});
// The bank keys must have been already saved
client.send(ebics.Orders.HTD)
.then((resp) => {
console.log('Respose for HTD order %j', resp);
if (resp.technicalCode !== '000000')
throw new Error('Something went wrong');
const data = Buffer.from(resp.orderData);
console.log(data.toString('utf8'));
})
.catch((err) => {
console.error(err);
process.exit(1);
});