I have the code below on the backend events.js page. I am trying to add a note to the invoice once it is created. The person checks out and an invoice is automatically created, but nothing happens. I tried to see if anything printed to the console after I checked out but it does not look like it is triggering. I checked the invoices that were created and no note was added to them. Any advice?
Thank you!
import { invoices } from ‘wix-billing-backend’ ;
import { session } from ‘wix-storage’ ;
export function wixBilling_ onInvoiceCreated( event ) {
console . log ( “INVOICE CREATED” );
updateInvoice ( event . id . id );
}
export function updateInvoice ( invoiceId ) {
return invoices . getInvoice ( invoiceId )
. then ( ( result ) => {
//make some changes
result . metadata . notes = session . getItem ( “petSummary” );
console . log ( "INVOICE CREATED SO THE NOTES SHOULD BE UPDATING: " + result . metadata . notes );
**let** updateFields = {
"title" : result . title ,
"customer" : result . customer ,
"currency" : result . currency ,
"lineItems" : result . lineItems ,
"discount" : result . discount ,
"payments" : result . payments ,
"metadata" : result . metadata ,
"dates" : result . dates
};
**return** invoices . updateInvoice ( result . id , updateFields );
} );
}