Search.../

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.

You can get a list of invoices by querying your site's "Billing/Invoices" collection. Each invoice in the query result contains the _id and version fields, which must be used when calling createInvoicePreviewUrl().

By default, createInvoicePreviewUrl() can be called by site contributors only. To allow customers to generate the invoice preview link, set suppressAuth in the options argument to true.

Syntax

function createInvoicePreviewUrl(id: IdAndVersion, [options: AuthOptions]): Promise<string>

createInvoicePreviewUrl Parameters

NAME
TYPE
DESCRIPTION
id
IdAndVersion

Object containing the ID and version of the invoice.

options
Optional
AuthOptions

An object with the following boolean property: suppressAuth.

Returns

Fulfilled - URL of the invoice preview.

Return Type:

Promise<string>

Was this helpful?

Create invoice preview link

Copy Code
1import { invoices } from 'wix-billing-backend';
2
3export async function myCreateInvoicePreviewUrlFunction(myInvoiceId, myInvoiceVersion) {
4 const id = {
5 id: myInvoiceId,
6 version: myInvoiceVersion
7 };
8
9 const options = {
10 suppressAuth: false
11 };
12
13 return await invoices.createInvoicePreviewUrl(id, options);
14}
15
16/* Promise resolves to:
17 *
18 * "https://invoices.wix.com/invoice/4ffbe78f-d789-5f3b-9a01-e892987ee43e:a5af37a4-753d-4701-8518-be23920ac3a0/view?token=628fa483-a473-4408-bac7-7501e81b32e3"
19 */
Get the invoice version and create the invoice preview link

Copy Code
1import { invoices } from 'wix-billing-backend';
2
3export async function myCreateInvoicePreviewUrlFunction(myInvoiceId) {
4 const retrievedInvoice = await invoices.getInvoice(myInvoiceId);
5 const options = {
6 suppressAuth: false
7 };
8
9 return await invoices.createInvoicePreviewUrl(retrievedInvoice.id, options);
10}
11
12/* Promise resolves to:
13 *
14 * "https://invoices.wix.com/invoice/4ffbe78f-d789-5f3b-9a01-e892987ee43e:a5af37a4-753d-4701-8518-be23920ac3a0/view?token=628fa483-a473-4408-bac7-7501e81b32e3"
15*/
Query invoices and create the invoice preview link for the first result

Copy Code
1import { invoices } from 'wix-billing-backend';
2import wixData from 'wix-data';
3
4export async function myCreateInvoicePreviewUrlFunction() {
5
6 const returnedInvoices = await wixData.query('Billing/Invoices').find();
7 const firstInvoice = returnedInvoices.items[0];
8
9 const id = {
10 id: firstInvoice._id,
11 version: firstInvoice.version
12 };
13
14 const options = {
15 suppressAuth: false
16 };
17
18 return await invoices.createInvoicePreviewUrl(id, options);
19}
20
21/* Promise resolves to:
22 *
23 * "https://invoices.wix.com/invoice/4ffbe78f-d789-5f3b-9a01-e892987ee43e:a5af37a4-753d-4701-8518-be23920ac3a0/view?token=628fa483-a473-4408-bac7-7501e81b32e3"
24 */