ewngs / szamlazz.js

Node.js client for Szamlazz.hu
MIT License
38 stars 34 forks source link

Example of saving storno invoice #23

Closed aron123 closed 1 year ago

aron123 commented 3 years ago

Hi,

Is there any example how to save storno invoices to the file system? I tried the following, but when trying to open the saved file in Adobe Reader, it notifies me, that the file is corrupted.

(async () => {
    try {
        const res = await reverseInvoice({
            invoiceId: 'xxx',
            eInvoice: true,
            requestInvoiceDownload: true
        });
        //console.log(res.pdf)
        fs.writeFileSync('./tmp.pdf', res.pdf, 'binary');
    } catch (err) {
        console.log('ERR', err);
    }

})();

My client is the following:

const szamlazzHu = new szamlazz.Client({
    authToken: process.env.SZAMLAZZ_API_KEY,
    eInvoice: true,
    requestInvoiceDownload: true,
    downloadedInvoiceCount: 1,
    responseVersion: 1
});

export const reverseInvoice = util.promisify(szamlazzHu.reverseInvoice).bind(szamlazzHu);

B.T.W.: It would be great if pdfs can be converted to Buffer objects (like in the issueInvoice method) either when issuing, reversing or querying one.

Thanks for your help.

mondalaci commented 1 year ago

Hi there, and sorry for the late reply!

I want to prune issues and only leave related PRs open, so I'm closing this issue in favor of #24. Thanks for your contribution, and feel free to rework your PR any time; I'll review and merge it.