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 {invoices} from 'wix-billing-backend';
2
3const now = new Date()
4const dueDate = new Date()
5dueDate.setDate(now.getDate() + 30)
6
7let customer = {
8 // contact ID and email address must match an
9 // existing contact in the site's contact list
10 "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
11 "email": "john.doe@somedomain.com",
12 "address": {
13 "city": "New York",
14 "subdivision": "NY",
15 "postalCode": "10011",
16 "country": "USA",
17 "addressLine": "235 W 23rd St"
18 },
19 "billingAddress": {
20 "country": "USA",
21 "streetAddress": {
22 "value": "235 W 23rd St",
23 "type": "Name"
24 },
25 "addressLine": "235 W 23rd St, New York, NY 10011, USA",
26 "addressLine2": "secondary address",
27 "postalCode": "10011",
28 "subdivision": "NY",
29 "city": "New York"
30 },
31 "shippingAddress": {
32 "country": "USA",
33 "streetAddress": {
34 "value": "235 W 23rd St",
35 "type": "Name"
36 },
37 "addressLine": "235 W 23rd St, New York, NY 10011, USA",
38 "addressLine2": "secondary address",
39 "postalCode": "10011",
40 "subdivision": "NY",
41 "city": "New York"
42 },
43 "phone": "5555555555",
44 "company": "Some Company",
45 "companyId": "Some Company Id",
46 "fullName": "John Doe",
47 "firstName": "John",
48 "lastName": "Doe"
49};
50
51let lineItems = [
52 {
53 "id": "00001",
54 "name": "Item 1",
55 "description": "First Item",
56 "price": 10.50,
57 "quantity": 3,
58 "taxes": [{
59 "name": "tax name",
60 "rate": 8.5,
61 "code": "tax code"
62 }]
63 },
64 {
65 "id": "00002",
66 "name": "Item 2",
67 "description": "Second Item",
68 "price": 50,
69 "quantity": 1,
70 "taxes": [{
71 "name": "tax name",
72 "rate": 8.5,
73 "code": "tax code"
74 }]
75 }
76];
77
78let discount = {
79 "value": 2.5,
80 "type": "Fixed"
81};
82
83const payments = [{
84 "id": "00001",
85 "type": "Offline",
86 "amount": 25.50,
87 "date": now
88}];
89
90let metadata = {
91 "notes": "Some note.",
92 "legalTerms": "Some legal terms",
93 "sourceUrl": "http://legalurl.com",
94 "source": "Some source",
95 "sourceRefId": "Some source ref id"
96};
97
98let dates = {
99 "issueDate": now,
100 "dueDate": dueDate
101};
102
103export function createInvoice() {
104 let createInvoiceFields = {
105 "title": "My Invoice",
106 "customer": customer,
107 "currency": "USD",
108 "lineItems": lineItems,
109 "discount": discount,
110 "payments": payments,
111 "metadata": metadata,
112 "dates": dates
113 };
114
115 return invoices.createInvoice(createInvoiceFields);
116}
117
118/* Promise resolves to:
119 * {
120 * "id": {
121 * "id": "411a5551-b0f6-4826-8a41-ebae2879f857"
122 * "version": 25
123 * }
124 * }
125*/