Skip to content

Commit

Permalink
fix(Invoice Ninja Node): Fix assigning an invoice to a payment (#9590)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeShakingSheep authored Jul 3, 2024
1 parent f64ca62 commit 7a3c127
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/nodes-base/nodes/InvoiceNinja/InvoiceNinja.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions packages/nodes-base/nodes/InvoiceNinja/PaymentInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 7a3c127

Please sign in to comment.