createInvoice( )


Creates a new invoice.

The createInvoice() function returns a Promise that resolves to the created invoice's ID when the invoice is created.

Note: The customer ID and email address listed on the invoice must match an existing contact in the site's contact list.

Method Declaration
Copy
function createInvoice(invoiceFields: InvoiceFields): Promise<Response>;
Method Parameters
invoiceFieldsInvoiceFieldsRequired

The data used to create an invoice.

Returns
Return Type:Promise<Response>
Create a new invoice
JavaScript
import { Permissions, webMethod } from "wix-web-module"; import { invoices } from "wix-billing-backend"; const now = new Date(); const dueDate = new Date(); dueDate.setDate(now.getDate() + 30); let customer = { // contact ID and email address must match an // existing contact in the site's contact list contactId: "4f7c6637-0657-4696-a00b-9bc2ae4e035d", email: "john.doe@somedomain.com", address: { city: "New York", subdivision: "NY", postalCode: "10011", country: "USA", addressLine: "235 W 23rd St", }, billingAddress: { country: "USA", streetAddress: { value: "235 W 23rd St", type: "Name", }, addressLine: "235 W 23rd St, New York, NY 10011, USA", addressLine2: "secondary address", postalCode: "10011", subdivision: "NY", city: "New York", }, shippingAddress: { country: "USA", streetAddress: { value: "235 W 23rd St", type: "Name", }, addressLine: "235 W 23rd St, New York, NY 10011, USA", addressLine2: "secondary address", postalCode: "10011", subdivision: "NY", city: "New York", }, phone: "5555555555", company: "Some Company", companyId: "Some Company Id", fullName: "John Doe", firstName: "John", lastName: "Doe", }; let lineItems = [ { id: "00001", name: "Item 1", description: "First Item", price: 10.5, quantity: 3, taxes: [ { name: "tax name", rate: 8.5, code: "tax code", }, ], }, { id: "00002", name: "Item 2", description: "Second Item", price: 50, quantity: 1, taxes: [ { name: "tax name", rate: 8.5, code: "tax code", }, ], }, ]; let discount = { value: 2.5, type: "Fixed", }; const payments = [ { id: "00001", type: "Offline", amount: 25.5, date: now, }, ]; let metadata = { notes: "Some note.", legalTerms: "Some legal terms", sourceUrl: "http://legalurl.com", source: "Some source", sourceRefId: "Some source ref id", }; let dates = { issueDate: now, dueDate: dueDate, }; export const createInvoice = webMethod(Permissions.Anyone, () => { let createInvoiceFields = { title: "My Invoice", customer: customer, currency: "USD", lineItems: lineItems, discount: discount, payments: payments, metadata: metadata, dates: dates, locale: { language: "ja", }, }; return invoices.createInvoice(createInvoiceFields); }); /* Promise resolves to: * { * "id": { * "id": "fe00fd47-c30e-47da-9b5a-8cacfbed744d" * "version": 23 * } * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?