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

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

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