Search...
createInvoice( )
Creates a new invoice.
Description
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.
Syntax
function createInvoice(invoiceFields: InvoiceFields): Promise<Response>
createInvoice Parameters
NAME
TYPE
DESCRIPTION
invoiceFields
InvoiceFields
The data used to create an invoice.
Returns
Fulfilled - ID of the created invoice.
Return Type:
Promise<Response>
NAME
TYPE
DESCRIPTION
id
IdAndVersion
ID and version information.
Was this helpful?
Create a new invoice
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { invoices } from 'wix-billing-backend';34const now = new Date();5const dueDate = new Date();6dueDate.setDate(now.getDate() + 30);78let customer = {9 // contact ID and email address must match an10 // existing contact in the site's contact list11 "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",12 "email": "john.doe@somedomain.com",13 "address": {14 "city": "New York",15 "subdivision": "NY",16 "postalCode": "10011",17 "country": "USA",18 "addressLine": "235 W 23rd St"19 },20 "billingAddress": {21 "country": "USA",22 "streetAddress": {23 "value": "235 W 23rd St",24 "type": "Name"25 },26 "addressLine": "235 W 23rd St, New York, NY 10011, USA",27 "addressLine2": "secondary address",28 "postalCode": "10011",29 "subdivision": "NY",30 "city": "New York"31 },32 "shippingAddress": {33 "country": "USA",34 "streetAddress": {35 "value": "235 W 23rd St",36 "type": "Name"37 },38 "addressLine": "235 W 23rd St, New York, NY 10011, USA",39 "addressLine2": "secondary address",40 "postalCode": "10011",41 "subdivision": "NY",42 "city": "New York"43 },44 "phone": "5555555555",45 "company": "Some Company",46 "companyId": "Some Company Id",47 "fullName": "John Doe",48 "firstName": "John",49 "lastName": "Doe"50};5152let lineItems = [53 {54 "id": "00001",55 "name": "Item 1",56 "description": "First Item",57 "price": 10.50,58 "quantity": 3,59 "taxes": [{60 "name": "tax name",61 "rate": 8.5,62 "code": "tax code"63 }]64 },65 {66 "id": "00002",67 "name": "Item 2",68 "description": "Second Item",69 "price": 50,70 "quantity": 1,71 "taxes": [{72 "name": "tax name",73 "rate": 8.5,74 "code": "tax code"75 }]76 }77];7879let discount = {80 "value": 2.5,81 "type": "Fixed"82};8384const payments = [{85 "id": "00001",86 "type": "Offline",87 "amount": 25.50,88 "date": now89}];9091let metadata = {92 "notes": "Some note.",93 "legalTerms": "Some legal terms",94 "sourceUrl": "http://legalurl.com",95 "source": "Some source",96 "sourceRefId": "Some source ref id"97};9899let dates = {100 "issueDate": now,101 "dueDate": dueDate102};103104export const createInvoice = webMethod(Permissions.Anyone, () => {105 let createInvoiceFields = {106 "title": "My Invoice",107 "customer": customer,108 "currency": "USD",109 "lineItems": lineItems,110 "discount": discount,111 "payments": payments,112 "metadata": metadata,113 "dates": dates,114 "locale": {115 language: "ja"116 }117 };118119 return invoices.createInvoice(createInvoiceFields);120});121122/* Promise resolves to:123 * {124 * "id": {125 * "id": "fe00fd47-c30e-47da-9b5a-8cacfbed744d"126 * "version": 23127 * }128 * }129*/