diff --git a/examples/bankLetter.js b/examples/bankLetter.js new file mode 100755 index 0000000..543cee8 --- /dev/null +++ b/examples/bankLetter.js @@ -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); + }); diff --git a/examples/initialize.js b/examples/initialize.js new file mode 100755 index 0000000..aade1eb --- /dev/null +++ b/examples/initialize.js @@ -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); + }); diff --git a/examples/save-bank-kesy.js b/examples/save-bank-kesy.js new file mode 100755 index 0000000..adffa8f --- /dev/null +++ b/examples/save-bank-kesy.js @@ -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); + }); diff --git a/examples/send-hbt-order.js b/examples/send-hbt-order.js new file mode 100755 index 0000000..02da48e --- /dev/null +++ b/examples/send-hbt-order.js @@ -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); + });