mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-22 20:29:08 +00:00
feat(Wise Node): Add Support to download statements as JSON, CSV or PDF (#3468)
This commit is contained in:
@@ -28,7 +28,6 @@ import {
|
||||
import {
|
||||
BorderlessAccount,
|
||||
ExchangeRateAdditionalFields,
|
||||
handleBinaryData,
|
||||
Profile,
|
||||
Recipient,
|
||||
StatementAdditionalFields,
|
||||
@@ -175,7 +174,7 @@ export class Wise implements INodeType {
|
||||
|
||||
let responseData;
|
||||
const returnData: IDataObject[] = [];
|
||||
let downloadReceipt = false;
|
||||
let binaryOutput = false;
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
|
||||
@@ -221,7 +220,8 @@ export class Wise implements INodeType {
|
||||
|
||||
const profileId = this.getNodeParameter('profileId', i);
|
||||
const borderlessAccountId = this.getNodeParameter('borderlessAccountId', i);
|
||||
const endpoint = `v3/profiles/${profileId}/borderless-accounts/${borderlessAccountId}/statement.json`;
|
||||
const format = this.getNodeParameter('format', i) as 'json' | 'csv' | 'pdf';
|
||||
const endpoint = `v3/profiles/${profileId}/borderless-accounts/${borderlessAccountId}/statement.${format}`;
|
||||
|
||||
const qs = {
|
||||
currency: this.getNodeParameter('currency', i),
|
||||
@@ -241,8 +241,19 @@ export class Wise implements INodeType {
|
||||
qs.intervalEnd = moment().utc().format();
|
||||
}
|
||||
|
||||
responseData = await wiseApiRequest.call(this, 'GET', endpoint, {}, qs);
|
||||
if (format === 'json') {
|
||||
responseData = await wiseApiRequest.call(this, 'GET', endpoint, {}, qs);
|
||||
}
|
||||
else {
|
||||
const data = await wiseApiRequest.call(this, 'GET', endpoint, {}, qs, {encoding: 'arraybuffer'});
|
||||
const binaryProperty = this.getNodeParameter('binaryProperty', i) as string;
|
||||
|
||||
items[i].binary = items[i].binary ?? {};
|
||||
items[i].binary![binaryProperty] = await this.helpers.prepareBinaryData(data, this.getNodeParameter('fileName', i) as string);
|
||||
|
||||
responseData = items;
|
||||
binaryOutput = true;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (resource === 'exchangeRate') {
|
||||
@@ -454,14 +465,20 @@ export class Wise implements INodeType {
|
||||
// ----------------------------------
|
||||
|
||||
const transferId = this.getNodeParameter('transferId', i);
|
||||
downloadReceipt = this.getNodeParameter('downloadReceipt', i) as boolean;
|
||||
|
||||
const downloadReceipt = this.getNodeParameter('downloadReceipt', i) as boolean;
|
||||
|
||||
if (downloadReceipt) {
|
||||
|
||||
// https://api-docs.transferwise.com/#transfers-get-receipt-pdf
|
||||
|
||||
responseData = await handleBinaryData.call(this, items, i, `v1/transfers/${transferId}/receipt.pdf`);
|
||||
const data = await wiseApiRequest.call(this, 'GET', `v1/transfers/${transferId}/receipt.pdf`, {}, {}, {encoding: 'arraybuffer'});
|
||||
const binaryProperty = this.getNodeParameter('binaryProperty', i) as string;
|
||||
|
||||
items[i].binary = items[i].binary ?? {};
|
||||
items[i].binary![binaryProperty] = await this.helpers.prepareBinaryData(data, this.getNodeParameter('fileName', i) as string);
|
||||
|
||||
responseData = items;
|
||||
binaryOutput = true;
|
||||
} else {
|
||||
|
||||
// https://api-docs.transferwise.com/#transfers-get-by-id
|
||||
@@ -518,7 +535,7 @@ export class Wise implements INodeType {
|
||||
: returnData.push(responseData);
|
||||
}
|
||||
|
||||
if (downloadReceipt && responseData !== undefined) {
|
||||
if (binaryOutput && responseData !== undefined) {
|
||||
return this.prepareOutputData(responseData);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user