From 8af3cb50c5b5b4d31e270c904f0e0baba2ee271d Mon Sep 17 00:00:00 2001 From: Herman van Hazendonk Date: Wed, 24 Mar 2021 22:14:21 +0100 Subject: [PATCH] Add sample code for zipped CAMT statements Some banks provide zipped CAMT statements, add some example code on how to write these to a file. Signed-off-by: Herman van Hazendonk --- examples/send-c52-order-zipped.js | 28 ++++++++++++++++++++++++++++ examples/send-c53-order-zipped.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 examples/send-c52-order-zipped.js create mode 100644 examples/send-c53-order-zipped.js diff --git a/examples/send-c52-order-zipped.js b/examples/send-c52-order-zipped.js new file mode 100644 index 0000000..1ff6922 --- /dev/null +++ b/examples/send-c52-order-zipped.js @@ -0,0 +1,28 @@ +#! /usr/bin/env node + +'use strict'; + +const fs = require('fs'); + +const client = require('./getClient')(); +const { Orders } = require('../index'); + +// The bank keys must have been already saved +client.send(Orders.C52(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD' + .then((resp) => { + console.log('Response for C52 order %j', resp); + if (resp.technicalCode !== '000000') + throw new Error('Something went wrong'); + + // Parsing and processing the CAMT052 file should happen somewhere here, ideally after saving it to disk + const data = Buffer.from(resp.orderData); + let distPath = "CAMT052.zip"; + const dstZip = fs.createWriteStream(distPath); + dstZip.write(data); + dstZip.end(); + }) + + .catch((err) => { + console.error(err); + process.exit(1); + }); diff --git a/examples/send-c53-order-zipped.js b/examples/send-c53-order-zipped.js new file mode 100644 index 0000000..cf9b432 --- /dev/null +++ b/examples/send-c53-order-zipped.js @@ -0,0 +1,28 @@ +#! /usr/bin/env node + +'use strict'; + +const fs = require('fs'); + +const client = require('./getClient')(); +const { Orders } = require('../index'); + +// The bank keys must have been already saved +client.send(Orders.C53(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD' + .then((resp) => { + console.log('Response for C53 order %j', resp); + if (resp.technicalCode !== '000000') + throw new Error('Something went wrong'); + + // Parsing and processing the CAMT053 file should happen somewhere here, ideally after saving it to disk + const data = Buffer.from(resp.orderData); + let distPath = "CAMT053.zip"; + const dstZip = fs.createWriteStream(distPath); + dstZip.write(data); + dstZip.end(); + }) + + .catch((err) => { + console.error(err); + process.exit(1); + });