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
Object containing the ID and version of the invoice.
An object with the following boolean property: suppressAuth.
Returns
Fulfilled - URL of the invoice preview.
Return Type:
Was this helpful?
1import { Permissions, webMethod } from 'wix-web-module';2import { invoices } from 'wix-billing-backend';34export const myCreateInvoicePreviewUrlFunction = webMethod(Permissions.Anyone, async (myInvoiceId, myInvoiceVersion) => {5 const id = {6 id: myInvoiceId,7 version: myInvoiceVersion8 };910 const options = {11 suppressAuth: false12 };1314 return await invoices.createInvoicePreviewUrl(id, options);15});1617/* 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 */
1import { Permissions, webMethod } from 'wix-web-module';2import { invoices } from 'wix-billing-backend';34export const myCreateInvoicePreviewUrlFunction = webMethod(Permissions.Anyone, async (myInvoiceId) => {5 const retrievedInvoice = await invoices.getInvoice(myInvoiceId);6 const options = {7 suppressAuth: false8 };910 return await invoices.createInvoicePreviewUrl(retrievedInvoice.id, options);11});1213/* 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*/
1import { Permissions, webMethod } from 'wix-web-module';2import { invoices } from 'wix-billing-backend';3import wixData from 'wix-data';45export const myCreateInvoicePreviewUrlFunction = webMethod(Permissions.Anyone, async () => {67 const returnedInvoices = await wixData.query('Billing/Invoices').find();8 const firstInvoice = returnedInvoices.items[0];910 const id = {11 id: firstInvoice._id,12 version: firstInvoice.version13 };1415 const options = {16 suppressAuth: false17 };1819 return await invoices.createInvoicePreviewUrl(id, options);20});2122/* 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 */