CorvidReference

invoices

The wix-billing-backend module contains functionality for working with your site's invoices from backend code.

To use the Invoices API, import wixBilling from the wix-billing-backend module:

   import wixBilling from 'wix-billing-backend';

Table of Contents

OBJECTS

?
Objects used when setting, getting, or calling the properties and methods listed above.
AddressAn object that contains address information.
CalculatedTaxAn object that contains calculated tax information.
CustomerAn object that contains customer information.
DiscountAn object that contains discount information.
EmailInfoAn object that contains information used to send an invoice to a customer.
IdAndVersionAn object that contains ID and version information.
InvoiceAn object that represents an invoice.
InvoiceDatesAn object that contains date information for an invoice.
InvoiceDynamicTotalsAn object that contains information about invoice totals that change when payments are received.
InvoiceFieldsAn object that contains information used when creating or updating an invoice.
ItemizedFeeAn object that contains itemized fee information.
LineItemAn object that contains line item information.
LineItemTaxAn object that contains tax information for a line item.
LocaleAn object that contains locale information.
MetaDataAn object that contains metadata information.
PaymentAn object that contains information about an invoice payment.
ResponseAn object that contains response information.
TotalPriceAn object that contains price totals.

addPayment( )

Adds a payment to the invoice and reports the payment to the payment provider.

Description

The addPayment() function returns a Promise that resolves when the specified payment is added to the invoice with the specified ID.

Syntax

function addPayment(id: IdAndVersion, payment: Payment): Promise<Response>
PARAMETERS
?
Values that you pass to a function.
id
ID and version of the invoice.
payment
The payment that should be added to the invoice.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<Response>
Fulfilled - When the payment is added to the invoice.

Examples

Add a payment to an invoice

import wixBilling from 'wix-billing-backend';

export function addPayment(id, version, type, amount) {
  const idAndVersion = {
    "id": id,
    "version": version
  };

  const payment = {
    "type": type,
    "amount": amount,
    "date": Date.now()
  };

  return wixBilling.invoices.addPayment(idAndVersion, payment);
}

/* Promise resolves to:
 * {
 *   {
 *     "id": {
 *       "id": "1ed3a515-24f9-4039-8937-2e69b6a2f33a",
 *       "version": 31
 *     }
 *   }
 * }
*/

Get the invoice version and add a payment to an invoice

import wixBilling from 'wix-billing-backend';

export function addPayment(id, payment) {
  return wixBilling.invoices.getInvoice(id)
    .then( (result) => {
      return wixBilling.invoices.addPayment(result.id, payment);
    });
}

/* Promise resolves to:
 * {
 *   {
 *     "id": {
 *       "id": "1ed3a515-24f9-4039-8937-2e69b6a2f33a",
 *       "version": 31
 *     }
 *   }
 * }
*/

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>
PARAMETERS
?
Values that you pass to a function.
invoiceFields
The data used to create an invoice.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<Response>
Fulfilled - ID of the created invoice.

Examples

Create a new invoice

import wixBilling 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"
  },
  "phone": "5555555555",
  "company": "Some Company",
  "fullName": "John Doe",
  "firstName": "John",
  "lastName": "Doe"
};

let lineItems = [
  {
    "id": "00001",
    "name": "Item 1",
    "description": "First Item",
    "price": 10.50,
    "quantity": 3,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  },
  {
    "id": "00002",
    "name": "Item 2",
    "description": "Second Item",
    "price": 50,
    "quantity": 1,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  }
];

let discount = {
  "value": 2.5,
  "type": "Fixed"
};

const payments = [{
  "id": "00001",
  "type": "Offline",
  "amount": 25.50,
  "date": now
}];

let metadata = {
  "notes": "Some note.",
  "legalTerms": "Some legal terms",
  "sourceUrl": "http://legalurl.com"
};

let dates = {
  "issueDate": now,
  "dueDate": dueDate
};

export function createInvoice() {
  let createInvoiceFields = {
    "title": "My Invoice",
    "customer": customer,
    "currency": "USD",
    "lineItems": lineItems,
    "discount": discount,
    "payments": payments,
    "metadata": metadata,
    "dates": dates
  };

  return wixBilling.invoices.createInvoice(createInvoiceFields);
}

/* Promise resolves to:
 * {
 *   "id": {
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857"
 *     "version": 25
 *   }
 * }
*/

createInvoicePreviewUrl( )

Creates a link that can be used by a customer to preview the invoice.

Description

The createInvoicePreviewUrl() function returns a Promise that resolves to a temporary link to a preview of the invoice with the specified ID.

Syntax

function createInvoicePreviewUrl(id: IdAndVersion): Promise<string>
PARAMETERS
?
Values that you pass to a function.
id
ID and version of the invoice.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<string>
Fulfilled - URL of the invoice preview.

Examples

Create invoice preview link

import wixBilling from 'wix-billing-backend';

export function createInvoicePreviewUrl(id, version) {
  const idAndVersion = {
    "id": id,
    "version": version
  };

  return wixBilling.invoices.createInvoicePreviewUrl(idAndVersion);
}

Get the invoice version and create the invoice preview link

import wixBilling from 'wix-billing-backend';

export function createInvoicePreviewUrl(id) {
  return wixBilling.invoices.getInvoice(id)
    .then( (result) => {
      return wixBilling.invoices.createInvoicePreviewUrl(result.id);
    } );
}

deleteInvoice( )

Deletes an invoice by ID.

Description

The deleteInvoice() function returns a Promise that resolves when the invoice with the specified ID is deleted.

Syntax

function deleteInvoice(id: string): Promise<void>
PARAMETERS
?
Values that you pass to a function.
id
string
ID of the invoice to delete.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the specified invoice is deleted.

Examples

Delete invoice by ID

import wixBilling from 'wix-billing-backend';

export function deleteInvoice(id) {
  return wixBilling.invoices.deleteInvoice(id);
}

getInvoice( )

Gets an existing invoice by ID.

Description

The getInvoice() function returns a Promise that resolves to the invoice with the specified ID.

Syntax

function getInvoice(id: string): Promise<Invoice>
PARAMETERS
?
Values that you pass to a function.
id
string
ID of the invoice to get.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<Invoice>
Fulfilled - The invoice with the given ID.

Examples

Get invoice by ID

import wixBilling from 'wix-billing-backend';

export function getInvoice(id) {
  return wixBilling.invoices.getInvoice(id);
}

/* Promise resolves to:
 * 
 * {  
 *   "id":{  
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857",
 *     "version": 25
 *   },
 *   "status": "Draft",
 *   "number": "0000001",
 *   "title": "My Invoice",
 *   "currency": "USD",
 *   "customer": {  
 *     "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
 *     "email": "john.doe@somedomain.com",
 *     "address": {  
 *       "street": "235 W 23rd St",
 *       "city": "New York",
 *       "zip": "10011",
 *       "state": "NY",
 *       "country": "USA"
 *     },
 *     "phone": "5555555555",
 *     "company": "Some Company",
 *     "fullName": "John Doe",
 *     "firstName": "John",
 *     "lastName": "Doe"
 *   },
 *   "dates": {  
 *     "issueDate": 2019-03-13T00:00:00.000Z,
 *     "dueDate": 2019-06-12T00:00:00.000Z
 *   },
 *   "discount": {
 *     "value": 2.5,
 *     "type": "Fixed"
 *   },
 *   "lineItems":[  
 *     {  
 *       "id": "00001",
 *       "name": "Item 1",
 *       "description": "First Item",
 *       "price": 10.5,
 *       "quantity": 3,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     },
 *     {
 *       "id": "00002",
 *       "name": "Item 2",
 *       "description": "Second Item",
 *       "price": 50,
 *       "quantity": 1,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     }
 *   ],
 *   "locale": {  
 *     "language": "en"
 *   },
 *   "payments": [{
 *     "id": "4j9q4o00-4205-8q83-003d-3ofd9d8wmf0w",
 *     "type": "offline",
 *     "amount": "25.50",
 *     "date": 2019-03-23T00:00:00.000Z"
 *   }],
 *   "totals": {  
 *     "discountAmount": null,
 *     "taxedAmount": 6.93,
 *     "fees": [],
 *     "subtotal": 81.5,
 *     "total": 88.43
 *   },
 *   "dynamicTotals": {
 *     "paidAmount": 25.50,
 *     "balance": 62.39
 *   },
 *   "taxes": [  
 *     {  
 *       "name": "tax name",
 *       "rate": 8.5,
 *       "taxable": 81.5,
 *       "taxed": 6.93
 *     }
 *   ],
 *   "metadata": {  
 *     "notes": "Some note",
 *     "legalTerms": "Some legal terms",
 *     "sourceUrl": "http://legalurl.com"
 *   },
 *   "paymentTerms": {  
 *     "termType": "DueOnReceipt",
 *     "termData": "some term data"
 *   }
 * }
 */

sendInvoice( )

Sends an invoice preview link to a customer via email.

Description

The sendInvoice() function returns a Promise that resolves when the invoice with the specified ID and version is sent to the customer listed on the invoice.

Use the emailOptions parameter to specify the subject and body of the email sent to the customer.

Syntax

function sendInvoice(id: IdAndVersion, emailInfo: EmailInfo): Promise<void>
PARAMETERS
?
Values that you pass to a function.
id
ID and version of the invoice to send.
emailInfo
Information used when sending the email.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the specified invoice is sent.

Examples

Send an invoice to a customer

import wixBilling from 'wix-billing-backend';

export function sendInvoiceToCustomer(id, version, subject, body) {
  const idAndVersion = {
    "id": id,
    "version": version
  };

  const emailInfo = {
    "subject": subject,
    "body": body
  };

  return wixBilling.invoices.sendInvoice(idAndVersion, emailInfo);
}

Get the invoice version and send the invoice to a customer

import wixBilling from 'wix-billing-backend';

export function sendInvoiceToCustomer(id, subject, body) {
  const emailInfo = {
    "subject": subject,
    "body": body
  };
  
  return wixBilling.invoices.getInvoice(id)
    .then( (result) => {
      return wixBilling.invoices.sendInvoice(result.id, emailInfo);
    } );
}

updateInvoice( )

Update an existing invoice.

Description

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

Note

The customer listed on the invoice must be an existing site contact or member.

Syntax

function updateInvoice(id: IdAndVersion, invoiceFields: InvoiceFields): Promise<Response>
PARAMETERS
?
Values that you pass to a function.
id
ID and version of the invoice to update.
invoiceFields
The data used to update the invoice.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<Response>
Fulfilled - ID and version of the updated invoice.

Examples

Update an existing invoice

import wixBilling from 'wix-billing-backend';

export function updateInvoice(id) {
  return wixBilling.invoices.getInvoice(id)
    .then( (result) => {
      //make some changes
      result.metadata.notes = "An updated note.";

      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 wixBilling.invoices.updateInvoice(result.id, updateFields);
    } );
}

/* Promise resolves to:
 * {
 *   {
 *     "id": {
 *       "id": "1ed3a515-24f9-4039-8937-2e69b6a2f33a",
 *       "version": 31
 *     }
 *   }
 * }
 */

voidInvoice( )

Voids an invoice.

Description

The voidInvoice() function returns a Promise that resolves when the invoice with the specified ID is voided.

Calling voidInvoice() on a draft invoice causes an error.

Syntax

function voidInvoice(id: IdAndVersion): Promise<void>
PARAMETERS
?
Values that you pass to a function.
id
ID and version of the invoice to void.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the specified invoice is voided.

Examples

Void invoice

import wixBilling from 'wix-billing-backend';

export function voidInvoice(id) {
  return wixBilling.invoices.getInvoice(id)
    .then( (result) => {
      return wixBilling.invoices.voidInvoice(result.id);
    } );
}

Get the invoice version and void the invoice

import wixBilling from 'wix-billing-backend';

export function voidInvoice(id, version) {
  const idAndVersion = {
    "id": id,
    "version": version
  };

  return wixBilling.invoices.getInvoice(id)
    .then( (result) => {
      return wixBilling.invoices.voidInvoice(idAndVersion);
    } );
}

Address

An object that contains address information.

See Also

Customer

Syntax

type Address = {
  addressLine: string
  subdivision: string
  city: string
  postalCode: string
  country: string
  formatted: string
}
MEMBERS
?
The properties of an object.
addressLine
string
Address line.
subdivision
string
Address subdivision.
city
string
Address city.
postalCode
string
Address postal code.
country
string
Address country.
formatted
string
Address in human readable format.

Examples

Create a new invoice

import wixBilling 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"
  },
  "phone": "5555555555",
  "company": "Some Company",
  "fullName": "John Doe",
  "firstName": "John",
  "lastName": "Doe"
};

let lineItems = [
  {
    "id": "00001",
    "name": "Item 1",
    "description": "First Item",
    "price": 10.50,
    "quantity": 3,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  },
  {
    "id": "00002",
    "name": "Item 2",
    "description": "Second Item",
    "price": 50,
    "quantity": 1,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  }
];

let discount = {
  "value": 2.5,
  "type": "Fixed"
};

const payments = [{
  "id": "00001",
  "type": "Offline",
  "amount": 25.50,
  "date": now
}];

let metadata = {
  "notes": "Some note.",
  "legalTerms": "Some legal terms",
  "sourceUrl": "http://legalurl.com"
};

let dates = {
  "issueDate": now,
  "dueDate": dueDate
};

export function createInvoice() {
  let createInvoiceFields = {
    "title": "My Invoice",
    "customer": customer,
    "currency": "USD",
    "lineItems": lineItems,
    "discount": discount,
    "payments": payments,
    "metadata": metadata,
    "dates": dates
  };

  return wixBilling.invoices.createInvoice(createInvoiceFields);
}

/* Promise resolves to:
 * {
 *   "id": {
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857"
 *     "version": 25
 *   }
 * }
*/

Get an invoice by ID

import wixBilling from 'wix-billing-backend';

export function getInvoice(id) {
  return wixBilling.invoices.getInvoice(id);
}

/* Promise resolves to:
 * 
 * {  
 *   "id":{  
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857",
 *     "version": 25
 *   },
 *   "status": "Draft",
 *   "number": "0000001",
 *   "title": "My Invoice",
 *   "currency": "USD",
 *   "customer": {  
 *     "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
 *     "email": "john.doe@somedomain.com",
 *     "address": {  
 *       "street": "235 W 23rd St",
 *       "city": "New York",
 *       "zip": "10011",
 *       "state": "NY",
 *       "country": "USA"
 *     },
 *     "phone": "5555555555",
 *     "company": "Some Company",
 *     "fullName": "John Doe",
 *     "firstName": "John",
 *     "lastName": "Doe"
 *   },
 *   "dates": {  
 *     "issueDate": 2019-03-13T00:00:00.000Z,
 *     "dueDate": 2019-06-12T00:00:00.000Z
 *   },
 *   "discount": {
 *     "value": 2.5,
 *     "type": "Fixed"
 *   },
 *   "lineItems":[  
 *     {  
 *       "id": "00001",
 *       "name": "Item 1",
 *       "description": "First Item",
 *       "price": 10.5,
 *       "quantity": 3,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     },
 *     {
 *       "id": "00002",
 *       "name": "Item 2",
 *       "description": "Second Item",
 *       "price": 50,
 *       "quantity": 1,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     }
 *   ],
 *   "locale": {  
 *     "language": "en"
 *   },
 *   "payments": [{
 *     "id": "4j9q4o00-4205-8q83-003d-3ofd9d8wmf0w",
 *     "type": "offline",
 *     "amount": "25.50",
 *     "date": 2019-03-23T00:00:00.000Z"
 *   }],
 *   "totals": {  
 *     "discountAmount": null,
 *     "taxedAmount": 6.93,
 *     "fees": [],
 *     "subtotal": 81.5,
 *     "total": 88.43
 *   },
 *   "dynamicTotals": {
 *     "paidAmount": 25.50,
 *     "balance": 62.39
 *   },
 *   "taxes": [  
 *     {  
 *       "name": "tax name",
 *       "rate": 8.5,
 *       "taxable": 81.5,
 *       "taxed": 6.93
 *     }
 *   ],
 *   "metadata": {  
 *     "notes": "Some note",
 *     "legalTerms": "Some legal terms",
 *     "sourceUrl": "http://legalurl.com"
 *   },
 *   "paymentTerms": {  
 *     "termType": "DueOnReceipt",
 *     "termData": "some term data"
 *   }
 * }
 */

CalculatedTax

An object that contains calculated tax information.

See Also

Invoice

Syntax

type CalculatedTax = {
  name: string
  rate: number
  taxable: number
  taxed: number
}
MEMBERS
?
The properties of an object.
name
string
Tax name.
rate
number
Tax rate.
taxable
number
Total value of taxable goods.
taxed
number
Total amount of tax applied.

Examples

Get invoice by ID

import wixBilling from 'wix-billing-backend';

export function getInvoice(id) {
  return wixBilling.invoices.getInvoice(id);
}

/* Promise resolves to:
 * 
 * {  
 *   "id":{  
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857",
 *     "version": 25
 *   },
 *   "status": "Draft",
 *   "number": "0000001",
 *   "title": "My Invoice",
 *   "currency": "USD",
 *   "customer": {  
 *     "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
 *     "email": "john.doe@somedomain.com",
 *     "address": {  
 *       "street": "235 W 23rd St",
 *       "city": "New York",
 *       "zip": "10011",
 *       "state": "NY",
 *       "country": "USA"
 *     },
 *     "phone": "5555555555",
 *     "company": "Some Company",
 *     "fullName": "John Doe",
 *     "firstName": "John",
 *     "lastName": "Doe"
 *   },
 *   "dates": {  
 *     "issueDate": 2019-03-13T00:00:00.000Z,
 *     "dueDate": 2019-06-12T00:00:00.000Z
 *   },
 *   "discount": {
 *     "value": 2.5,
 *     "type": "Fixed"
 *   },
 *   "lineItems":[  
 *     {  
 *       "id": "00001",
 *       "name": "Item 1",
 *       "description": "First Item",
 *       "price": 10.5,
 *       "quantity": 3,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     },
 *     {
 *       "id": "00002",
 *       "name": "Item 2",
 *       "description": "Second Item",
 *       "price": 50,
 *       "quantity": 1,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     }
 *   ],
 *   "locale": {  
 *     "language": "en"
 *   },
 *   "payments": [{
 *     "id": "4j9q4o00-4205-8q83-003d-3ofd9d8wmf0w",
 *     "type": "offline",
 *     "amount": "25.50",
 *     "date": 2019-03-23T00:00:00.000Z"
 *   }],
 *   "totals": {  
 *     "discountAmount": null,
 *     "taxedAmount": 6.93,
 *     "fees": [],
 *     "subtotal": 81.5,
 *     "total": 88.43
 *   },
 *   "dynamicTotals": {
 *     "paidAmount": 25.50,
 *     "balance": 62.39
 *   },
 *   "taxes": [  
 *     {  
 *       "name": "tax name",
 *       "rate": 8.5,
 *       "taxable": 81.5,
 *       "taxed": 6.93
 *     }
 *   ],
 *   "metadata": {  
 *     "notes": "Some note",
 *     "legalTerms": "Some legal terms",
 *     "sourceUrl": "http://legalurl.com"
 *   },
 *   "paymentTerms": {  
 *     "termType": "DueOnReceipt",
 *     "termData": "some term data"
 *   }
 * }
 */

Customer

An object that contains customer information.

See Also

Invoice, [InvoiceFields]#InvoiceFields), createInvoice( ), getInvoice( ), updateInvoice( )

Syntax

type Customer = {
  contactId: string
  email: string
  address: Address
  phone: string
  company: string
  fullName: string
  firstName: string
  lastName: string
}
MEMBERS
?
The properties of an object.
contactId
string
Contact ID.
email
string
Email address.
address(Optional)
Physical address.
phone(Optional)
string
Phone number.
company(Optional)
string
Company name.
fullName(Optional)
string
Full name.
firstName(Optional)
string
First name.
lastName(Optional)
string
Last name.

Examples

Create a new invoice

import wixBilling 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"
  },
  "phone": "5555555555",
  "company": "Some Company",
  "fullName": "John Doe",
  "firstName": "John",
  "lastName": "Doe"
};

let lineItems = [
  {
    "id": "00001",
    "name": "Item 1",
    "description": "First Item",
    "price": 10.50,
    "quantity": 3,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  },
  {
    "id": "00002",
    "name": "Item 2",
    "description": "Second Item",
    "price": 50,
    "quantity": 1,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  }
];

let discount = {
  "value": 2.5,
  "type": "Fixed"
};

const payments = [{
  "id": "00001",
  "type": "Offline",
  "amount": 25.50,
  "date": now
}];

let metadata = {
  "notes": "Some note.",
  "legalTerms": "Some legal terms",
  "sourceUrl": "http://legalurl.com"
};

let dates = {
  "issueDate": now,
  "dueDate": dueDate
};

export function createInvoice() {
  let createInvoiceFields = {
    "title": "My Invoice",
    "customer": customer,
    "currency": "USD",
    "lineItems": lineItems,
    "discount": discount,
    "payments": payments,
    "metadata": metadata,
    "dates": dates
  };

  return wixBilling.invoices.createInvoice(createInvoiceFields);
}

/* Promise resolves to:
 * {
 *   "id": {
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857"
 *     "version": 25
 *   }
 * }
*/

Get invoice by ID

import wixBilling from 'wix-billing-backend';

export function getInvoice(id) {
  return wixBilling.invoices.getInvoice(id);
}

/* Promise resolves to:
 * 
 * {  
 *   "id":{  
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857",
 *     "version": 25
 *   },
 *   "status": "Draft",
 *   "number": "0000001",
 *   "title": "My Invoice",
 *   "currency": "USD",
 *   "customer": {  
 *     "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
 *     "email": "john.doe@somedomain.com",
 *     "address": {  
 *       "street": "235 W 23rd St",
 *       "city": "New York",
 *       "zip": "10011",
 *       "state": "NY",
 *       "country": "USA"
 *     },
 *     "phone": "5555555555",
 *     "company": "Some Company",
 *     "fullName": "John Doe",
 *     "firstName": "John",
 *     "lastName": "Doe"
 *   },
 *   "dates": {  
 *     "issueDate": 2019-03-13T00:00:00.000Z,
 *     "dueDate": 2019-06-12T00:00:00.000Z
 *   },
 *   "discount": {
 *     "value": 2.5,
 *     "type": "Fixed"
 *   },
 *   "lineItems":[  
 *     {  
 *       "id": "00001",
 *       "name": "Item 1",
 *       "description": "First Item",
 *       "price": 10.5,
 *       "quantity": 3,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     },
 *     {
 *       "id": "00002",
 *       "name": "Item 2",
 *       "description": "Second Item",
 *       "price": 50,
 *       "quantity": 1,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     }
 *   ],
 *   "locale": {  
 *     "language": "en"
 *   },
 *   "payments": [{
 *     "id": "4j9q4o00-4205-8q83-003d-3ofd9d8wmf0w",
 *     "type": "offline",
 *     "amount": "25.50",
 *     "date": 2019-03-23T00:00:00.000Z"
 *   }],
 *   "totals": {  
 *     "discountAmount": null,
 *     "taxedAmount": 6.93,
 *     "fees": [],
 *     "subtotal": 81.5,
 *     "total": 88.43
 *   },
 *   "dynamicTotals": {
 *     "paidAmount": 25.50,
 *     "balance": 62.39
 *   },
 *   "taxes": [  
 *     {  
 *       "name": "tax name",
 *       "rate": 8.5,
 *       "taxable": 81.5,
 *       "taxed": 6.93
 *     }
 *   ],
 *   "metadata": {  
 *     "notes": "Some note",
 *     "legalTerms": "Some legal terms",
 *     "sourceUrl": "http://legalurl.com"
 *   },
 *   "paymentTerms": {  
 *     "termType": "DueOnReceipt",
 *     "termData": "some term data"
 *   }
 * }
 */

Discount

An object that contains discount information.

See Also

Invoice, InvoiceFields

Syntax

type Discount = {
  value: number
  type: string
}
MEMBERS
?
The properties of an object.
value
number
Discount amount.
type
string

Discount type.

Either:

  • "Fixed": A fixed amount is deducted.
  • "Percentage": A percentage of the total amount is deducted.

Examples

Create a new invoice

import wixBilling 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"
  },
  "phone": "5555555555",
  "company": "Some Company",
  "fullName": "John Doe",
  "firstName": "John",
  "lastName": "Doe"
};

let lineItems = [
  {
    "id": "00001",
    "name": "Item 1",
    "description": "First Item",
    "price": 10.50,
    "quantity": 3,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  },
  {
    "id": "00002",
    "name": "Item 2",
    "description": "Second Item",
    "price": 50,
    "quantity": 1,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  }
];

let discount = {
  "value": 2.5,
  "type": "Fixed"
};

const payments = [{
  "id": "00001",
  "type": "Offline",
  "amount": 25.50,
  "date": now
}];

let metadata = {
  "notes": "Some note.",
  "legalTerms": "Some legal terms",
  "sourceUrl": "http://legalurl.com"
};

let dates = {
  "issueDate": now,
  "dueDate": dueDate
};

export function createInvoice() {
  let createInvoiceFields = {
    "title": "My Invoice",
    "customer": customer,
    "currency": "USD",
    "lineItems": lineItems,
    "discount": discount,
    "payments": payments,
    "metadata": metadata,
    "dates": dates
  };

  return wixBilling.invoices.createInvoice(createInvoiceFields);
}

/* Promise resolves to:
 * {
 *   "id": {
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857"
 *     "version": 25
 *   }
 * }
*/

Update an existing invoice

import wixBilling from 'wix-billing-backend';

export function updateInvoice(id) {
  return wixBilling.invoices.getInvoice(id)
    .then( (result) => {
      //make some changes
      result.metadata.notes = "An updated note.";

      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 wixBilling.invoices.updateInvoice(result.id, updateFields);
    } );
}

/* Promise resolves to:
 * {
 *   {
 *     "id": {
 *       "id": "1ed3a515-24f9-4039-8937-2e69b6a2f33a",
 *       "version": 31
 *     }
 *   }
 * }
 */

EmailInfo

An object that contains information used to send an invoice to a customer.

Syntax

type EmailInfo = {
  subject: string
  body: string
}
MEMBERS
?
The properties of an object.
subject
string
Email subject.
body
string

Email body. Limited formatting in the email body can be achieved using standard JavaScript string formatting.

Examples

Send an invoice to a customer

import wixBilling from 'wix-billing-backend';

export function sendInvoiceToCustomer(id, version, subject, body) {
  const idAndVersion = {
    "id": id,
    "version": version
  };

  const emailInfo = {
    "subject": subject,
    "body": body
  };

  return wixBilling.invoices.sendInvoice(idAndVersion, emailInfo);
}

Get the invoice version and send the invoice to a customer

import wixBilling from 'wix-billing-backend';

export function sendInvoiceToCustomer(id, subject, body) {
  const emailInfo = {
    "subject": subject,
    "body": body
  };
  
  return wixBilling.invoices.getInvoice(id)
    .then( (result) => {
      return wixBilling.invoices.sendInvoice(result.id, emailInfo);
    } );
}

IdAndVersion

An object that contains ID and version information.

See Also

Invoice, UpdateInvoiceRequest

Syntax

type IdAndVersion = {
  id: string
  version: number
}
MEMBERS
?
The properties of an object.
id
string
Invoice ID.
version
number
Invoice version.

Examples

Get invoice by ID

import wixBilling from 'wix-billing-backend';

export function getInvoice(id) {
  return wixBilling.invoices.getInvoice(id);
}

/* Promise resolves to:
 * 
 * {  
 *   "id":{  
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857",
 *     "version": 25
 *   },
 *   "status": "Draft",
 *   "number": "0000001",
 *   "title": "My Invoice",
 *   "currency": "USD",
 *   "customer": {  
 *     "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
 *     "email": "john.doe@somedomain.com",
 *     "address": {  
 *       "street": "235 W 23rd St",
 *       "city": "New York",
 *       "zip": "10011",
 *       "state": "NY",
 *       "country": "USA"
 *     },
 *     "phone": "5555555555",
 *     "company": "Some Company",
 *     "fullName": "John Doe",
 *     "firstName": "John",
 *     "lastName": "Doe"
 *   },
 *   "dates": {  
 *     "issueDate": 2019-03-13T00:00:00.000Z,
 *     "dueDate": 2019-06-12T00:00:00.000Z
 *   },
 *   "discount": {
 *     "value": 2.5,
 *     "type": "Fixed"
 *   },
 *   "lineItems":[  
 *     {  
 *       "id": "00001",
 *       "name": "Item 1",
 *       "description": "First Item",
 *       "price": 10.5,
 *       "quantity": 3,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     },
 *     {
 *       "id": "00002",
 *       "name": "Item 2",
 *       "description": "Second Item",
 *       "price": 50,
 *       "quantity": 1,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     }
 *   ],
 *   "locale": {  
 *     "language": "en"
 *   },
 *   "payments": [{
 *     "id": "4j9q4o00-4205-8q83-003d-3ofd9d8wmf0w",
 *     "type": "offline",
 *     "amount": "25.50",
 *     "date": 2019-03-23T00:00:00.000Z"
 *   }],
 *   "totals": {  
 *     "discountAmount": null,
 *     "taxedAmount": 6.93,
 *     "fees": [],
 *     "subtotal": 81.5,
 *     "total": 88.43
 *   },
 *   "dynamicTotals": {
 *     "paidAmount": 25.50,
 *     "balance": 62.39
 *   },
 *   "taxes": [  
 *     {  
 *       "name": "tax name",
 *       "rate": 8.5,
 *       "taxable": 81.5,
 *       "taxed": 6.93
 *     }
 *   ],
 *   "metadata": {  
 *     "notes": "Some note",
 *     "legalTerms": "Some legal terms",
 *     "sourceUrl": "http://legalurl.com"
 *   },
 *   "paymentTerms": {  
 *     "termType": "DueOnReceipt",
 *     "termData": "some term data"
 *   }
 * }
 */

Update an existing invoice

import wixBilling from 'wix-billing-backend';

export function updateInvoice(id) {
  return wixBilling.invoices.getInvoice(id)
    .then( (result) => {
      //make some changes
      result.metadata.notes = "An updated note.";

      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 wixBilling.invoices.updateInvoice(result.id, updateFields);
    } );
}

/* Promise resolves to:
 * {
 *   {
 *     "id": {
 *       "id": "1ed3a515-24f9-4039-8937-2e69b6a2f33a",
 *       "version": 31
 *     }
 *   }
 * }
 */

Invoice

An object that represents an invoice.

See Also

getInvoice( )

Syntax

type Invoice = {
  id: IdAndVersion
  status: string
  number: string
  title: string
  currency: string
  locale: Locale
  customer: Customer
  lineItems: Array<LineItem>
  discount: Discount
  payments: Array<Payment>
  taxes: Array<CalculatedTax>
  totals: TotalPrice
  dynamicTotals: InvoiceDynamicTotals
  metadata: MetaData
  dates: InvoiceDates
}
MEMBERS
?
The properties of an object.
id
ID and version of the invoice.
status
string

Status of the invoice. One of:

  • "Draft"
  • "Sent"
  • "Processing"
  • "Paid"
  • "Overdue"
  • "Void"
  • "Deleted"
  • "PartiallyPaid"
  • "PartialAndOverdue"
number
string
Number of the invoice, unique within your site.
title
string
Title of the invoice.
currency
string
Currency code.
locale
Locale information.
customer
Customer listed on the invoice.
lineItems
Array<LineItem>
Line items listed on the invoice.
discount
Discount included in the invoice.
payments
Array<Payment>
List of payments already received from the customer.
taxes
List of taxes calculated based on the line items.
totals
Total values.
dynamicTotals
Invoice dynamic totals.
metadata
Additional metadata included in the invoice.
dates
Dates associated with the invoice.

Examples

Get invoice by ID

import wixBilling from 'wix-billing-backend';

export function getInvoice(id) {
  return wixBilling.invoices.getInvoice(id);
}

/* Promise resolves to:
 * 
 * {  
 *   "id":{  
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857",
 *     "version": 25
 *   },
 *   "status": "Draft",
 *   "number": "0000001",
 *   "title": "My Invoice",
 *   "currency": "USD",
 *   "customer": {  
 *     "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
 *     "email": "john.doe@somedomain.com",
 *     "address": {  
 *       "street": "235 W 23rd St",
 *       "city": "New York",
 *       "zip": "10011",
 *       "state": "NY",
 *       "country": "USA"
 *     },
 *     "phone": "5555555555",
 *     "company": "Some Company",
 *     "fullName": "John Doe",
 *     "firstName": "John",
 *     "lastName": "Doe"
 *   },
 *   "dates": {  
 *     "issueDate": 2019-03-13T00:00:00.000Z,
 *     "dueDate": 2019-06-12T00:00:00.000Z
 *   },
 *   "discount": {
 *     "value": 2.5,
 *     "type": "Fixed"
 *   },
 *   "lineItems":[  
 *     {  
 *       "id": "00001",
 *       "name": "Item 1",
 *       "description": "First Item",
 *       "price": 10.5,
 *       "quantity": 3,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     },
 *     {
 *       "id": "00002",
 *       "name": "Item 2",
 *       "description": "Second Item",
 *       "price": 50,
 *       "quantity": 1,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     }
 *   ],
 *   "locale": {  
 *     "language": "en"
 *   },
 *   "payments": [{
 *     "id": "4j9q4o00-4205-8q83-003d-3ofd9d8wmf0w",
 *     "type": "offline",
 *     "amount": "25.50",
 *     "date": 2019-03-23T00:00:00.000Z"
 *   }],
 *   "totals": {  
 *     "discountAmount": null,
 *     "taxedAmount": 6.93,
 *     "fees": [],
 *     "subtotal": 81.5,
 *     "total": 88.43
 *   },
 *   "dynamicTotals": {
 *     "paidAmount": 25.50,
 *     "balance": 62.39
 *   },
 *   "taxes": [  
 *     {  
 *       "name": "tax name",
 *       "rate": 8.5,
 *       "taxable": 81.5,
 *       "taxed": 6.93
 *     }
 *   ],
 *   "metadata": {  
 *     "notes": "Some note",
 *     "legalTerms": "Some legal terms",
 *     "sourceUrl": "http://legalurl.com"
 *   },
 *   "paymentTerms": {  
 *     "termType": "DueOnReceipt",
 *     "termData": "some term data"
 *   }
 * }
 */

InvoiceDates

An object that contains date information for an invoice.

See Also

Invoice

Syntax

type InvoiceDates = {
  issueDate: Date
  dueDate: Date
}
MEMBERS
?
The properties of an object.
issueDate
Date
Invoice issue date.
dueDate
Date
Invoice due date.

Examples

Get invoice by ID

import wixBilling from 'wix-billing-backend';

export function getInvoice(id) {
  return wixBilling.invoices.getInvoice(id);
}

/* Promise resolves to:
 * 
 * {  
 *   "id":{  
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857",
 *     "version": 25
 *   },
 *   "status": "Draft",
 *   "number": "0000001",
 *   "title": "My Invoice",
 *   "currency": "USD",
 *   "customer": {  
 *     "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
 *     "email": "john.doe@somedomain.com",
 *     "address": {  
 *       "street": "235 W 23rd St",
 *       "city": "New York",
 *       "zip": "10011",
 *       "state": "NY",
 *       "country": "USA"
 *     },
 *     "phone": "5555555555",
 *     "company": "Some Company",
 *     "fullName": "John Doe",
 *     "firstName": "John",
 *     "lastName": "Doe"
 *   },
 *   "dates": {  
 *     "issueDate": 2019-03-13T00:00:00.000Z,
 *     "dueDate": 2019-06-12T00:00:00.000Z
 *   },
 *   "discount": {
 *     "value": 2.5,
 *     "type": "Fixed"
 *   },
 *   "lineItems":[  
 *     {  
 *       "id": "00001",
 *       "name": "Item 1",
 *       "description": "First Item",
 *       "price": 10.5,
 *       "quantity": 3,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     },
 *     {
 *       "id": "00002",
 *       "name": "Item 2",
 *       "description": "Second Item",
 *       "price": 50,
 *       "quantity": 1,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     }
 *   ],
 *   "locale": {  
 *     "language": "en"
 *   },
 *   "payments": [{
 *     "id": "4j9q4o00-4205-8q83-003d-3ofd9d8wmf0w",
 *     "type": "offline",
 *     "amount": "25.50",
 *     "date": 2019-03-23T00:00:00.000Z"
 *   }],
 *   "totals": {  
 *     "discountAmount": null,
 *     "taxedAmount": 6.93,
 *     "fees": [],
 *     "subtotal": 81.5,
 *     "total": 88.43
 *   },
 *   "dynamicTotals": {
 *     "paidAmount": 25.50,
 *     "balance": 62.39
 *   },
 *   "taxes": [  
 *     {  
 *       "name": "tax name",
 *       "rate": 8.5,
 *       "taxable": 81.5,
 *       "taxed": 6.93
 *     }
 *   ],
 *   "metadata": {  
 *     "notes": "Some note",
 *     "legalTerms": "Some legal terms",
 *     "sourceUrl": "http://legalurl.com"
 *   },
 *   "paymentTerms": {  
 *     "termType": "DueOnReceipt",
 *     "termData": "some term data"
 *   }
 * }
 */

Create a new invoice

import wixBilling 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"
  },
  "phone": "5555555555",
  "company": "Some Company",
  "fullName": "John Doe",
  "firstName": "John",
  "lastName": "Doe"
};

let lineItems = [
  {
    "id": "00001",
    "name": "Item 1",
    "description": "First Item",
    "price": 10.50,
    "quantity": 3,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  },
  {
    "id": "00002",
    "name": "Item 2",
    "description": "Second Item",
    "price": 50,
    "quantity": 1,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  }
];

let discount = {
  "value": 2.5,
  "type": "Fixed"
};

const payments = [{
  "id": "00001",
  "type": "Offline",
  "amount": 25.50,
  "date": now
}];

let metadata = {
  "notes": "Some note.",
  "legalTerms": "Some legal terms",
  "sourceUrl": "http://legalurl.com"
};

let dates = {
  "issueDate": now,
  "dueDate": dueDate
};

export function createInvoice() {
  let createInvoiceFields = {
    "title": "My Invoice",
    "customer": customer,
    "currency": "USD",
    "lineItems": lineItems,
    "discount": discount,
    "payments": payments,
    "metadata": metadata,
    "dates": dates
  };

  return wixBilling.invoices.createInvoice(createInvoiceFields);
}

/* Promise resolves to:
 * {
 *   "id": {
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857"
 *     "version": 25
 *   }
 * }
*/

InvoiceDynamicTotals

An object that contains information about invoice totals that change when payments are received.

See Also

Invoice

Syntax

type InvoiceDynamicTotals = {
  paidAmount: number
  balance: number
}
MEMBERS
?
The properties of an object.
paidAmount
number
Amount paid.
balance
number
Balance amount.

Examples

Get invoice by ID

import wixBilling from 'wix-billing-backend';

export function getInvoice(id) {
  return wixBilling.invoices.getInvoice(id);
}

/* Promise resolves to:
 * 
 * {  
 *   "id":{  
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857",
 *     "version": 25
 *   },
 *   "status": "Draft",
 *   "number": "0000001",
 *   "title": "My Invoice",
 *   "currency": "USD",
 *   "customer": {  
 *     "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
 *     "email": "john.doe@somedomain.com",
 *     "address": {  
 *       "street": "235 W 23rd St",
 *       "city": "New York",
 *       "zip": "10011",
 *       "state": "NY",
 *       "country": "USA"
 *     },
 *     "phone": "5555555555",
 *     "company": "Some Company",
 *     "fullName": "John Doe",
 *     "firstName": "John",
 *     "lastName": "Doe"
 *   },
 *   "dates": {  
 *     "issueDate": 2019-03-13T00:00:00.000Z,
 *     "dueDate": 2019-06-12T00:00:00.000Z
 *   },
 *   "discount": {
 *     "value": 2.5,
 *     "type": "Fixed"
 *   },
 *   "lineItems":[  
 *     {  
 *       "id": "00001",
 *       "name": "Item 1",
 *       "description": "First Item",
 *       "price": 10.5,
 *       "quantity": 3,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     },
 *     {
 *       "id": "00002",
 *       "name": "Item 2",
 *       "description": "Second Item",
 *       "price": 50,
 *       "quantity": 1,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     }
 *   ],
 *   "locale": {  
 *     "language": "en"
 *   },
 *   "payments": [{
 *     "id": "4j9q4o00-4205-8q83-003d-3ofd9d8wmf0w",
 *     "type": "offline",
 *     "amount": "25.50",
 *     "date": 2019-03-23T00:00:00.000Z"
 *   }],
 *   "totals": {  
 *     "discountAmount": null,
 *     "taxedAmount": 6.93,
 *     "fees": [],
 *     "subtotal": 81.5,
 *     "total": 88.43
 *   },
 *   "dynamicTotals": {
 *     "paidAmount": 25.50,
 *     "balance": 62.39
 *   },
 *   "taxes": [  
 *     {  
 *       "name": "tax name",
 *       "rate": 8.5,
 *       "taxable": 81.5,
 *       "taxed": 6.93
 *     }
 *   ],
 *   "metadata": {  
 *     "notes": "Some note",
 *     "legalTerms": "Some legal terms",
 *     "sourceUrl": "http://legalurl.com"
 *   },
 *   "paymentTerms": {  
 *     "termType": "DueOnReceipt",
 *     "termData": "some term data"
 *   }
 * }
 */

InvoiceFields

An object that contains information used when creating or updating an invoice.

See Also

createInvoice( ), updateInvoice( )

Syntax

type InvoiceFields = {
  title: string
  customer: Customer
  currency: string
  lineItems: Array<LineItem>
  discount: Discount
  payments: Array<Payment>
  metadata: MetaData
  dates: InvoiceDates
}
MEMBERS
?
The properties of an object.
title
string
Title of the invoice.
customer
Customer listed on the invoice.
currency
string
Currency code.
lineItems
Array<LineItem>
Line items listed on the invoice.
discount(Optional)
Discount included in the invoice.
payments
Array<Payment>
Invoice payments.
metadata(Optional)
Invoice metadata.
dates
Dates associated with the invoice.

Examples

Create a new invoice

import wixBilling 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"
  },
  "phone": "5555555555",
  "company": "Some Company",
  "fullName": "John Doe",
  "firstName": "John",
  "lastName": "Doe"
};

let lineItems = [
  {
    "id": "00001",
    "name": "Item 1",
    "description": "First Item",
    "price": 10.50,
    "quantity": 3,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  },
  {
    "id": "00002",
    "name": "Item 2",
    "description": "Second Item",
    "price": 50,
    "quantity": 1,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  }
];

let discount = {
  "value": 2.5,
  "type": "Fixed"
};

const payments = [{
  "id": "00001",
  "type": "Offline",
  "amount": 25.50,
  "date": now
}];

let metadata = {
  "notes": "Some note.",
  "legalTerms": "Some legal terms",
  "sourceUrl": "http://legalurl.com"
};

let dates = {
  "issueDate": now,
  "dueDate": dueDate
};

export function createInvoice() {
  let createInvoiceFields = {
    "title": "My Invoice",
    "customer": customer,
    "currency": "USD",
    "lineItems": lineItems,
    "discount": discount,
    "payments": payments,
    "metadata": metadata,
    "dates": dates
  };

  return wixBilling.invoices.createInvoice(createInvoiceFields);
}

/* Promise resolves to:
 * {
 *   "id": {
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857"
 *     "version": 25
 *   }
 * }
*/

Update an existing invoice

import wixBilling from 'wix-billing-backend';

export function updateInvoice(id) {
  return wixBilling.invoices.getInvoice(id)
    .then( (result) => {
      //make some changes
      result.metadata.notes = "An updated note.";

      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 wixBilling.invoices.updateInvoice(result.id, updateFields);
    } );
}

/* Promise resolves to:
 * {
 *   {
 *     "id": {
 *       "id": "1ed3a515-24f9-4039-8937-2e69b6a2f33a",
 *       "version": 31
 *     }
 *   }
 * }
 */

ItemizedFee

An object that contains itemized fee information.

See Also

TotalPrice

Syntax

type ItemizedFee = {
  name: string
  price: number
}
MEMBERS
?
The properties of an object.
name
string
Item fee name.
price
number
Item fee price.

Examples

Get an invoice by ID

import wixBilling from 'wix-billing-backend';

export function getInvoice(id) {
  return wixBilling.invoices.getInvoice(id);
}

/* Promise resolves to:
 * 
 * {  
 *   "id":{  
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857",
 *     "version": 25
 *   },
 *   "status": "Draft",
 *   "number": "0000001",
 *   "title": "My Invoice",
 *   "currency": "USD",
 *   "customer": {  
 *     "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
 *     "email": "john.doe@somedomain.com",
 *     "address": {  
 *       "street": "235 W 23rd St",
 *       "city": "New York",
 *       "zip": "10011",
 *       "state": "NY",
 *       "country": "USA"
 *     },
 *     "phone": "5555555555",
 *     "company": "Some Company",
 *     "fullName": "John Doe",
 *     "firstName": "John",
 *     "lastName": "Doe"
 *   },
 *   "dates": {  
 *     "issueDate": 2019-03-13T00:00:00.000Z,
 *     "dueDate": 2019-06-12T00:00:00.000Z
 *   },
 *   "discount": {
 *     "value": 2.5,
 *     "type": "Fixed"
 *   },
 *   "lineItems":[  
 *     {  
 *       "id": "00001",
 *       "name": "Item 1",
 *       "description": "First Item",
 *       "price": 10.5,
 *       "quantity": 3,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     },
 *     {
 *       "id": "00002",
 *       "name": "Item 2",
 *       "description": "Second Item",
 *       "price": 50,
 *       "quantity": 1,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     }
 *   ],
 *   "locale": {  
 *     "language": "en"
 *   },
 *   "payments": [{
 *     "id": "4j9q4o00-4205-8q83-003d-3ofd9d8wmf0w",
 *     "type": "offline",
 *     "amount": "25.50",
 *     "date": 2019-03-23T00:00:00.000Z"
 *   }],
 *   "totals": {  
 *     "discountAmount": null,
 *     "taxedAmount": 6.93,
 *     "fees": [],
 *     "subtotal": 81.5,
 *     "total": 88.43
 *   },
 *   "dynamicTotals": {
 *     "paidAmount": 25.50,
 *     "balance": 62.39
 *   },
 *   "taxes": [  
 *     {  
 *       "name": "tax name",
 *       "rate": 8.5,
 *       "taxable": 81.5,
 *       "taxed": 6.93
 *     }
 *   ],
 *   "metadata": {  
 *     "notes": "Some note",
 *     "legalTerms": "Some legal terms",
 *     "sourceUrl": "http://legalurl.com"
 *   },
 *   "paymentTerms": {  
 *     "termType": "DueOnReceipt",
 *     "termData": "some term data"
 *   }
 * }
 */

LineItem

An object that contains line item information.

See Also

InvoiceFields

Syntax

type LineItem = {
  id: string
  name: string
  description: string
  price: number
  quantity: number
  taxes: Array<LineItemTax>
}
MEMBERS
?
The properties of an object.
id
string
Line item ID.
name
string
Line item name.
description
string
Line item description.
price
number
Line item price.
quantity
number
Line item quantity.
taxes(Optional)
Line item taxes.

Examples

Create a new invoice

import wixBilling 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"
  },
  "phone": "5555555555",
  "company": "Some Company",
  "fullName": "John Doe",
  "firstName": "John",
  "lastName": "Doe"
};

let lineItems = [
  {
    "id": "00001",
    "name": "Item 1",
    "description": "First Item",
    "price": 10.50,
    "quantity": 3,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  },
  {
    "id": "00002",
    "name": "Item 2",
    "description": "Second Item",
    "price": 50,
    "quantity": 1,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  }
];

let discount = {
  "value": 2.5,
  "type": "Fixed"
};

const payments = [{
  "id": "00001",
  "type": "Offline",
  "amount": 25.50,
  "date": now
}];

let metadata = {
  "notes": "Some note.",
  "legalTerms": "Some legal terms",
  "sourceUrl": "http://legalurl.com"
};

let dates = {
  "issueDate": now,
  "dueDate": dueDate
};

export function createInvoice() {
  let createInvoiceFields = {
    "title": "My Invoice",
    "customer": customer,
    "currency": "USD",
    "lineItems": lineItems,
    "discount": discount,
    "payments": payments,
    "metadata": metadata,
    "dates": dates
  };

  return wixBilling.invoices.createInvoice(createInvoiceFields);
}

/* Promise resolves to:
 * {
 *   "id": {
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857"
 *     "version": 25
 *   }
 * }
*/

Get invoice by ID

import wixBilling from 'wix-billing-backend';

export function getInvoice(id) {
  return wixBilling.invoices.getInvoice(id);
}

/* Promise resolves to:
 * 
 * {  
 *   "id":{  
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857",
 *     "version": 25
 *   },
 *   "status": "Draft",
 *   "number": "0000001",
 *   "title": "My Invoice",
 *   "currency": "USD",
 *   "customer": {  
 *     "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
 *     "email": "john.doe@somedomain.com",
 *     "address": {  
 *       "street": "235 W 23rd St",
 *       "city": "New York",
 *       "zip": "10011",
 *       "state": "NY",
 *       "country": "USA"
 *     },
 *     "phone": "5555555555",
 *     "company": "Some Company",
 *     "fullName": "John Doe",
 *     "firstName": "John",
 *     "lastName": "Doe"
 *   },
 *   "dates": {  
 *     "issueDate": 2019-03-13T00:00:00.000Z,
 *     "dueDate": 2019-06-12T00:00:00.000Z
 *   },
 *   "discount": {
 *     "value": 2.5,
 *     "type": "Fixed"
 *   },
 *   "lineItems":[  
 *     {  
 *       "id": "00001",
 *       "name": "Item 1",
 *       "description": "First Item",
 *       "price": 10.5,
 *       "quantity": 3,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     },
 *     {
 *       "id": "00002",
 *       "name": "Item 2",
 *       "description": "Second Item",
 *       "price": 50,
 *       "quantity": 1,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     }
 *   ],
 *   "locale": {  
 *     "language": "en"
 *   },
 *   "payments": [{
 *     "id": "4j9q4o00-4205-8q83-003d-3ofd9d8wmf0w",
 *     "type": "offline",
 *     "amount": "25.50",
 *     "date": 2019-03-23T00:00:00.000Z"
 *   }],
 *   "totals": {  
 *     "discountAmount": null,
 *     "taxedAmount": 6.93,
 *     "fees": [],
 *     "subtotal": 81.5,
 *     "total": 88.43
 *   },
 *   "dynamicTotals": {
 *     "paidAmount": 25.50,
 *     "balance": 62.39
 *   },
 *   "taxes": [  
 *     {  
 *       "name": "tax name",
 *       "rate": 8.5,
 *       "taxable": 81.5,
 *       "taxed": 6.93
 *     }
 *   ],
 *   "metadata": {  
 *     "notes": "Some note",
 *     "legalTerms": "Some legal terms",
 *     "sourceUrl": "http://legalurl.com"
 *   },
 *   "paymentTerms": {  
 *     "termType": "DueOnReceipt",
 *     "termData": "some term data"
 *   }
 * }
 */

LineItemTax

An object that contains tax information for a line item.

See Also

LineItem

Syntax

type LineItemTax = {
  name: string
  rate: number
}
MEMBERS
?
The properties of an object.
name
string
Line item tax name.
rate
number
Line item tax rate.

Examples

Create a new invoice

import wixBilling 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"
  },
  "phone": "5555555555",
  "company": "Some Company",
  "fullName": "John Doe",
  "firstName": "John",
  "lastName": "Doe"
};

let lineItems = [
  {
    "id": "00001",
    "name": "Item 1",
    "description": "First Item",
    "price": 10.50,
    "quantity": 3,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  },
  {
    "id": "00002",
    "name": "Item 2",
    "description": "Second Item",
    "price": 50,
    "quantity": 1,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  }
];

let discount = {
  "value": 2.5,
  "type": "Fixed"
};

const payments = [{
  "id": "00001",
  "type": "Offline",
  "amount": 25.50,
  "date": now
}];

let metadata = {
  "notes": "Some note.",
  "legalTerms": "Some legal terms",
  "sourceUrl": "http://legalurl.com"
};

let dates = {
  "issueDate": now,
  "dueDate": dueDate
};

export function createInvoice() {
  let createInvoiceFields = {
    "title": "My Invoice",
    "customer": customer,
    "currency": "USD",
    "lineItems": lineItems,
    "discount": discount,
    "payments": payments,
    "metadata": metadata,
    "dates": dates
  };

  return wixBilling.invoices.createInvoice(createInvoiceFields);
}

/* Promise resolves to:
 * {
 *   "id": {
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857"
 *     "version": 25
 *   }
 * }
*/

Get an invoice by ID

import wixBilling from 'wix-billing-backend';

export function getInvoice(id) {
  return wixBilling.invoices.getInvoice(id);
}

/* Promise resolves to:
 * 
 * {  
 *   "id":{  
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857",
 *     "version": 25
 *   },
 *   "status": "Draft",
 *   "number": "0000001",
 *   "title": "My Invoice",
 *   "currency": "USD",
 *   "customer": {  
 *     "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
 *     "email": "john.doe@somedomain.com",
 *     "address": {  
 *       "street": "235 W 23rd St",
 *       "city": "New York",
 *       "zip": "10011",
 *       "state": "NY",
 *       "country": "USA"
 *     },
 *     "phone": "5555555555",
 *     "company": "Some Company",
 *     "fullName": "John Doe",
 *     "firstName": "John",
 *     "lastName": "Doe"
 *   },
 *   "dates": {  
 *     "issueDate": 2019-03-13T00:00:00.000Z,
 *     "dueDate": 2019-06-12T00:00:00.000Z
 *   },
 *   "discount": {
 *     "value": 2.5,
 *     "type": "Fixed"
 *   },
 *   "lineItems":[  
 *     {  
 *       "id": "00001",
 *       "name": "Item 1",
 *       "description": "First Item",
 *       "price": 10.5,
 *       "quantity": 3,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     },
 *     {
 *       "id": "00002",
 *       "name": "Item 2",
 *       "description": "Second Item",
 *       "price": 50,
 *       "quantity": 1,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     }
 *   ],
 *   "locale": {  
 *     "language": "en"
 *   },
 *   "payments": [{
 *     "id": "4j9q4o00-4205-8q83-003d-3ofd9d8wmf0w",
 *     "type": "offline",
 *     "amount": "25.50",
 *     "date": 2019-03-23T00:00:00.000Z"
 *   }],
 *   "totals": {  
 *     "discountAmount": null,
 *     "taxedAmount": 6.93,
 *     "fees": [],
 *     "subtotal": 81.5,
 *     "total": 88.43
 *   },
 *   "dynamicTotals": {
 *     "paidAmount": 25.50,
 *     "balance": 62.39
 *   },
 *   "taxes": [  
 *     {  
 *       "name": "tax name",
 *       "rate": 8.5,
 *       "taxable": 81.5,
 *       "taxed": 6.93
 *     }
 *   ],
 *   "metadata": {  
 *     "notes": "Some note",
 *     "legalTerms": "Some legal terms",
 *     "sourceUrl": "http://legalurl.com"
 *   },
 *   "paymentTerms": {  
 *     "termType": "DueOnReceipt",
 *     "termData": "some term data"
 *   }
 * }
 */

Locale

An object that contains locale information.

See Also

Invoice

Syntax

type Locale = {
  language: string
}
MEMBERS
?
The properties of an object.
language
string

An IETF language tag. Some common language tags include:

  • "en-US": English, United States
  • "en-GB": English, British
  • "es-ES": Spanish, Spain
  • "de-DE": German, Germany
  • "ja-JP": Japanese, Japan
  • "fr-CH": French, Switzerland
  • "it-IT": Italian, Italy

Examples

Get invoice by ID

import wixBilling from 'wix-billing-backend';

export function getInvoice(id) {
  return wixBilling.invoices.getInvoice(id);
}

/* Promise resolves to:
 * 
 * {  
 *   "id":{  
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857",
 *     "version": 25
 *   },
 *   "status": "Draft",
 *   "number": "0000001",
 *   "title": "My Invoice",
 *   "currency": "USD",
 *   "customer": {  
 *     "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
 *     "email": "john.doe@somedomain.com",
 *     "address": {  
 *       "street": "235 W 23rd St",
 *       "city": "New York",
 *       "zip": "10011",
 *       "state": "NY",
 *       "country": "USA"
 *     },
 *     "phone": "5555555555",
 *     "company": "Some Company",
 *     "fullName": "John Doe",
 *     "firstName": "John",
 *     "lastName": "Doe"
 *   },
 *   "dates": {  
 *     "issueDate": 2019-03-13T00:00:00.000Z,
 *     "dueDate": 2019-06-12T00:00:00.000Z
 *   },
 *   "discount": {
 *     "value": 2.5,
 *     "type": "Fixed"
 *   },
 *   "lineItems":[  
 *     {  
 *       "id": "00001",
 *       "name": "Item 1",
 *       "description": "First Item",
 *       "price": 10.5,
 *       "quantity": 3,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     },
 *     {
 *       "id": "00002",
 *       "name": "Item 2",
 *       "description": "Second Item",
 *       "price": 50,
 *       "quantity": 1,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     }
 *   ],
 *   "locale": {  
 *     "language": "en"
 *   },
 *   "payments": [{
 *     "id": "4j9q4o00-4205-8q83-003d-3ofd9d8wmf0w",
 *     "type": "offline",
 *     "amount": "25.50",
 *     "date": 2019-03-23T00:00:00.000Z"
 *   }],
 *   "totals": {  
 *     "discountAmount": null,
 *     "taxedAmount": 6.93,
 *     "fees": [],
 *     "subtotal": 81.5,
 *     "total": 88.43
 *   },
 *   "dynamicTotals": {
 *     "paidAmount": 25.50,
 *     "balance": 62.39
 *   },
 *   "taxes": [  
 *     {  
 *       "name": "tax name",
 *       "rate": 8.5,
 *       "taxable": 81.5,
 *       "taxed": 6.93
 *     }
 *   ],
 *   "metadata": {  
 *     "notes": "Some note",
 *     "legalTerms": "Some legal terms",
 *     "sourceUrl": "http://legalurl.com"
 *   },
 *   "paymentTerms": {  
 *     "termType": "DueOnReceipt",
 *     "termData": "some term data"
 *   }
 * }
 */

MetaData

An object that contains metadata information.

See Also

Invoice, InvoiceFields

Syntax

type MetaData = {
  notes: string
  legalTerms: string
  sourceUrl: string
}
MEMBERS
?
The properties of an object.
notes(Optional)
string
Invoice notes.
legalTerms(Optional)
string
Legal terms.
sourceUrl(Optional)
string
URL to legal terms.

Examples

Create a new invoice

import wixBilling 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"
  },
  "phone": "5555555555",
  "company": "Some Company",
  "fullName": "John Doe",
  "firstName": "John",
  "lastName": "Doe"
};

let lineItems = [
  {
    "id": "00001",
    "name": "Item 1",
    "description": "First Item",
    "price": 10.50,
    "quantity": 3,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  },
  {
    "id": "00002",
    "name": "Item 2",
    "description": "Second Item",
    "price": 50,
    "quantity": 1,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  }
];

let discount = {
  "value": 2.5,
  "type": "Fixed"
};

const payments = [{
  "id": "00001",
  "type": "Offline",
  "amount": 25.50,
  "date": now
}];

let metadata = {
  "notes": "Some note.",
  "legalTerms": "Some legal terms",
  "sourceUrl": "http://legalurl.com"
};

let dates = {
  "issueDate": now,
  "dueDate": dueDate
};

export function createInvoice() {
  let createInvoiceFields = {
    "title": "My Invoice",
    "customer": customer,
    "currency": "USD",
    "lineItems": lineItems,
    "discount": discount,
    "payments": payments,
    "metadata": metadata,
    "dates": dates
  };

  return wixBilling.invoices.createInvoice(createInvoiceFields);
}

/* Promise resolves to:
 * {
 *   "id": {
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857"
 *     "version": 25
 *   }
 * }
*/

Get invoice by ID

import wixBilling from 'wix-billing-backend';

export function getInvoice(id) {
  return wixBilling.invoices.getInvoice(id);
}

/* Promise resolves to:
 * 
 * {  
 *   "id":{  
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857",
 *     "version": 25
 *   },
 *   "status": "Draft",
 *   "number": "0000001",
 *   "title": "My Invoice",
 *   "currency": "USD",
 *   "customer": {  
 *     "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
 *     "email": "john.doe@somedomain.com",
 *     "address": {  
 *       "street": "235 W 23rd St",
 *       "city": "New York",
 *       "zip": "10011",
 *       "state": "NY",
 *       "country": "USA"
 *     },
 *     "phone": "5555555555",
 *     "company": "Some Company",
 *     "fullName": "John Doe",
 *     "firstName": "John",
 *     "lastName": "Doe"
 *   },
 *   "dates": {  
 *     "issueDate": 2019-03-13T00:00:00.000Z,
 *     "dueDate": 2019-06-12T00:00:00.000Z
 *   },
 *   "discount": {
 *     "value": 2.5,
 *     "type": "Fixed"
 *   },
 *   "lineItems":[  
 *     {  
 *       "id": "00001",
 *       "name": "Item 1",
 *       "description": "First Item",
 *       "price": 10.5,
 *       "quantity": 3,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     },
 *     {
 *       "id": "00002",
 *       "name": "Item 2",
 *       "description": "Second Item",
 *       "price": 50,
 *       "quantity": 1,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     }
 *   ],
 *   "locale": {  
 *     "language": "en"
 *   },
 *   "payments": [{
 *     "id": "4j9q4o00-4205-8q83-003d-3ofd9d8wmf0w",
 *     "type": "offline",
 *     "amount": "25.50",
 *     "date": 2019-03-23T00:00:00.000Z"
 *   }],
 *   "totals": {  
 *     "discountAmount": null,
 *     "taxedAmount": 6.93,
 *     "fees": [],
 *     "subtotal": 81.5,
 *     "total": 88.43
 *   },
 *   "dynamicTotals": {
 *     "paidAmount": 25.50,
 *     "balance": 62.39
 *   },
 *   "taxes": [  
 *     {  
 *       "name": "tax name",
 *       "rate": 8.5,
 *       "taxable": 81.5,
 *       "taxed": 6.93
 *     }
 *   ],
 *   "metadata": {  
 *     "notes": "Some note",
 *     "legalTerms": "Some legal terms",
 *     "sourceUrl": "http://legalurl.com"
 *   },
 *   "paymentTerms": {  
 *     "termType": "DueOnReceipt",
 *     "termData": "some term data"
 *   }
 * }
 */

Payment

An object that contains information about an invoice payment.

See Also

Invoice

Syntax

type Payment = {
  id: string
  type: string
  amount: number
  date: Date
}
MEMBERS
?
The properties of an object.
id
string
Payment id.
type
string
Payment type, describing how the payment was made.
amount
number
Payment amount.
date
Date
Payment date.

Examples

Get invoice by ID

import wixBilling from 'wix-billing-backend';

export function getInvoice(id) {
  return wixBilling.invoices.getInvoice(id);
}

/* Promise resolves to:
 * 
 * {  
 *   "id":{  
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857",
 *     "version": 25
 *   },
 *   "status": "Draft",
 *   "number": "0000001",
 *   "title": "My Invoice",
 *   "currency": "USD",
 *   "customer": {  
 *     "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
 *     "email": "john.doe@somedomain.com",
 *     "address": {  
 *       "street": "235 W 23rd St",
 *       "city": "New York",
 *       "zip": "10011",
 *       "state": "NY",
 *       "country": "USA"
 *     },
 *     "phone": "5555555555",
 *     "company": "Some Company",
 *     "fullName": "John Doe",
 *     "firstName": "John",
 *     "lastName": "Doe"
 *   },
 *   "dates": {  
 *     "issueDate": 2019-03-13T00:00:00.000Z,
 *     "dueDate": 2019-06-12T00:00:00.000Z
 *   },
 *   "discount": {
 *     "value": 2.5,
 *     "type": "Fixed"
 *   },
 *   "lineItems":[  
 *     {  
 *       "id": "00001",
 *       "name": "Item 1",
 *       "description": "First Item",
 *       "price": 10.5,
 *       "quantity": 3,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     },
 *     {
 *       "id": "00002",
 *       "name": "Item 2",
 *       "description": "Second Item",
 *       "price": 50,
 *       "quantity": 1,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     }
 *   ],
 *   "locale": {  
 *     "language": "en"
 *   },
 *   "payments": [{
 *     "id": "4j9q4o00-4205-8q83-003d-3ofd9d8wmf0w",
 *     "type": "offline",
 *     "amount": "25.50",
 *     "date": 2019-03-23T00:00:00.000Z"
 *   }],
 *   "totals": {  
 *     "discountAmount": null,
 *     "taxedAmount": 6.93,
 *     "fees": [],
 *     "subtotal": 81.5,
 *     "total": 88.43
 *   },
 *   "dynamicTotals": {
 *     "paidAmount": 25.50,
 *     "balance": 62.39
 *   },
 *   "taxes": [  
 *     {  
 *       "name": "tax name",
 *       "rate": 8.5,
 *       "taxable": 81.5,
 *       "taxed": 6.93
 *     }
 *   ],
 *   "metadata": {  
 *     "notes": "Some note",
 *     "legalTerms": "Some legal terms",
 *     "sourceUrl": "http://legalurl.com"
 *   },
 *   "paymentTerms": {  
 *     "termType": "DueOnReceipt",
 *     "termData": "some term data"
 *   }
 * }
 */

Response

An object that contains response information.

Syntax

type Response = {
  id: IdAndVersion
}
MEMBERS
?
The properties of an object.
id
ID and version information.

Examples

Create a new invoice

import wixBilling 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"
  },
  "phone": "5555555555",
  "company": "Some Company",
  "fullName": "John Doe",
  "firstName": "John",
  "lastName": "Doe"
};

let lineItems = [
  {
    "id": "00001",
    "name": "Item 1",
    "description": "First Item",
    "price": 10.50,
    "quantity": 3,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  },
  {
    "id": "00002",
    "name": "Item 2",
    "description": "Second Item",
    "price": 50,
    "quantity": 1,
    "taxes": [{
      "name": "tax name",
      "rate": 8.5
    }]
  }
];

let discount = {
  "value": 2.5,
  "type": "Fixed"
};

const payments = [{
  "id": "00001",
  "type": "Offline",
  "amount": 25.50,
  "date": now
}];

let metadata = {
  "notes": "Some note.",
  "legalTerms": "Some legal terms",
  "sourceUrl": "http://legalurl.com"
};

let dates = {
  "issueDate": now,
  "dueDate": dueDate
};

export function createInvoice() {
  let createInvoiceFields = {
    "title": "My Invoice",
    "customer": customer,
    "currency": "USD",
    "lineItems": lineItems,
    "discount": discount,
    "payments": payments,
    "metadata": metadata,
    "dates": dates
  };

  return wixBilling.invoices.createInvoice(createInvoiceFields);
}

/* Promise resolves to:
 * {
 *   "id": {
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857"
 *     "version": 25
 *   }
 * }
*/

Update an existing invoice

import wixBilling from 'wix-billing-backend';

export function updateInvoice(id) {
  return wixBilling.invoices.getInvoice(id)
    .then( (result) => {
      //make some changes
      result.metadata.notes = "An updated note.";

      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 wixBilling.invoices.updateInvoice(result.id, updateFields);
    } );
}

/* Promise resolves to:
 * {
 *   {
 *     "id": {
 *       "id": "1ed3a515-24f9-4039-8937-2e69b6a2f33a",
 *       "version": 31
 *     }
 *   }
 * }
 */

TotalPrice

An object that contains price totals.

See Also

Invoice

Syntax

type TotalPrice = {
  discountAmount: number
  fees: Array<ItemizedFee>
  taxedAmount: number
  subtotal: number
  total: number
}
MEMBERS
?
The properties of an object.
discountAmount
number
Discount amount.
fees
List of itemized fees.
taxedAmount
number
Sum of line item tax amounts.
subtotal
number
Subtotal of the line items without the tax included.
total
number
Total price of the itemized fees and taxes.

Examples

Get invoice by ID

import wixBilling from 'wix-billing-backend';

export function getInvoice(id) {
  return wixBilling.invoices.getInvoice(id);
}

/* Promise resolves to:
 * 
 * {  
 *   "id":{  
 *     "id": "411a5551-b0f6-4826-8a41-ebae2879f857",
 *     "version": 25
 *   },
 *   "status": "Draft",
 *   "number": "0000001",
 *   "title": "My Invoice",
 *   "currency": "USD",
 *   "customer": {  
 *     "contactId": "4f7c6637-0657-4696-a00b-9bc2ae4e035d",
 *     "email": "john.doe@somedomain.com",
 *     "address": {  
 *       "street": "235 W 23rd St",
 *       "city": "New York",
 *       "zip": "10011",
 *       "state": "NY",
 *       "country": "USA"
 *     },
 *     "phone": "5555555555",
 *     "company": "Some Company",
 *     "fullName": "John Doe",
 *     "firstName": "John",
 *     "lastName": "Doe"
 *   },
 *   "dates": {  
 *     "issueDate": 2019-03-13T00:00:00.000Z,
 *     "dueDate": 2019-06-12T00:00:00.000Z
 *   },
 *   "discount": {
 *     "value": 2.5,
 *     "type": "Fixed"
 *   },
 *   "lineItems":[  
 *     {  
 *       "id": "00001",
 *       "name": "Item 1",
 *       "description": "First Item",
 *       "price": 10.5,
 *       "quantity": 3,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     },
 *     {
 *       "id": "00002",
 *       "name": "Item 2",
 *       "description": "Second Item",
 *       "price": 50,
 *       "quantity": 1,
 *       "taxes": [
 *         {
 *           "name": "tax name",
 *           "rate": 8.5
 *         }
 *       ]
 *     }
 *   ],
 *   "locale": {  
 *     "language": "en"
 *   },
 *   "payments": [{
 *     "id": "4j9q4o00-4205-8q83-003d-3ofd9d8wmf0w",
 *     "type": "offline",
 *     "amount": "25.50",
 *     "date": 2019-03-23T00:00:00.000Z"
 *   }],
 *   "totals": {  
 *     "discountAmount": null,
 *     "taxedAmount": 6.93,
 *     "fees": [],
 *     "subtotal": 81.5,
 *     "total": 88.43
 *   },
 *   "dynamicTotals": {
 *     "paidAmount": 25.50,
 *     "balance": 62.39
 *   },
 *   "taxes": [  
 *     {  
 *       "name": "tax name",
 *       "rate": 8.5,
 *       "taxable": 81.5,
 *       "taxed": 6.93
 *     }
 *   ],
 *   "metadata": {  
 *     "notes": "Some note",
 *     "legalTerms": "Some legal terms",
 *     "sourceUrl": "http://legalurl.com"
 *   },
 *   "paymentTerms": {  
 *     "termType": "DueOnReceipt",
 *     "termData": "some term data"
 *   }
 * }
 */