fix(Invoice Ninja Node): Fix assigning an invoice to a payment (#9590)

This commit is contained in:
CodeShakingSheep 2024-07-03 14:22:48 -05:00 committed by GitHub
parent f64ca621e1
commit 7a3c127b2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 3 deletions

View file

@ -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) {
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;

View file

@ -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;
}