From 7a3c127b2cbea01f9a21c8d517d1dc919bc8121f Mon Sep 17 00:00:00 2001 From: CodeShakingSheep <19874562+CodeShakingSheep@users.noreply.github.com> Date: Wed, 3 Jul 2024 14:22:48 -0500 Subject: [PATCH] fix(Invoice Ninja Node): Fix assigning an invoice to a payment (#9590) --- .../nodes/InvoiceNinja/InvoiceNinja.node.ts | 19 ++++++++++++++++--- .../nodes/InvoiceNinja/PaymentInterface.ts | 7 +++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/nodes-base/nodes/InvoiceNinja/InvoiceNinja.node.ts b/packages/nodes-base/nodes/InvoiceNinja/InvoiceNinja.node.ts index b056949150..e1c30be41b 100644 --- a/packages/nodes-base/nodes/InvoiceNinja/InvoiceNinja.node.ts +++ b/packages/nodes-base/nodes/InvoiceNinja/InvoiceNinja.node.ts @@ -660,18 +660,31 @@ export class InvoiceNinja implements INodeType { if (resource === 'payment') { if (operation === 'create') { const additionalFields = this.getNodeParameter('additionalFields', i); - const invoice = this.getNodeParameter('invoice', i) as number; + const invoice = this.getNodeParameter('invoice', i) as number | string; const client = ( await invoiceNinjaApiRequest.call(this, 'GET', `/invoices/${invoice}`, {}, qs) ).data?.client_id as string; const amount = this.getNodeParameter('amount', i) as number; const body: IPayment = { - invoice_id: invoice, amount, client_id: client, }; + if (apiVersion === 'v4') { + body.invoice_id = invoice as number; + } else if (apiVersion === 'v5') { + body.invoices = [ + { + invoice_id: invoice as string, + amount, + }, + ]; + } if (additionalFields.paymentType) { - body.payment_type_id = additionalFields.paymentType as number; + if (apiVersion === 'v4') { + body.payment_type_id = additionalFields.paymentType as number; + } else if (apiVersion == 'v5') { + body.type_id = additionalFields.paymentType as number; + } } if (additionalFields.transferReference) { body.transaction_reference = additionalFields.transferReference as string; diff --git a/packages/nodes-base/nodes/InvoiceNinja/PaymentInterface.ts b/packages/nodes-base/nodes/InvoiceNinja/PaymentInterface.ts index 6b0d04fad9..c7df748950 100644 --- a/packages/nodes-base/nodes/InvoiceNinja/PaymentInterface.ts +++ b/packages/nodes-base/nodes/InvoiceNinja/PaymentInterface.ts @@ -2,7 +2,14 @@ export interface IPayment { invoice_id?: number; amount?: number; payment_type_id?: number; + type_id?: number; transaction_reference?: string; private_notes?: string; client_id?: string; + invoices?: IInvoice[]; +} + +export interface IInvoice { + invoice_id: string; + amount: number; }