Need help using wixBilling.invoices.createInvoicePreviewUrl() from web module

When a user hits a “Submit” button on the page, I want to generate an invoice and navigate the user to the invoice preview. I do this by calling a function inside of a web module.

The function executes successfully when I test in Preview mode, however, it fails when testing on the live site. I get the error: “Required permissions are missing(wix-quotes.manage)”
The web module permissions are set to “Anyone”.

I can also successfully run “wixBilling.invoices.createInvoice(createInvoiceFields)” within the web module, so it just seems that “wixBilling.invoices.createInvoicePreviewUrl(idAndVersion)” is giving me trouble. Below is a stripped down version of my larger function for the purposes of troubleshooting. Behavior is the same.


Frontend code

import {testFunction} from 'backend/webmodule_functions';
export function testButton(event) {
    let invoiceId = "11cc31a6-7f6d-8ge6-a21b-0ba7177add84";
    let invoiceVersion = "24";
    
    const idAndVersion = {
         "id": invoiceId,
         "version": invoiceVersion
    };

    testFunction(idAndVersion)
    .then ( (response) => {
        console.log("Invoice url: " + response);
    })
    .catch(error => {
        console.log(error);      
    })

Backend code in webmodule_functions.jsw

import wixBilling from 'wix-billing-backend'; 

export function testFunction(idAndVersion) {
    return wixBilling.invoices.createInvoicePreviewUrl(idAndVersion);
}

Do you have Wix Invoices app installed on your site for this to work with?
invoices
The wix-billing-backend module contains functionality for working with your site’s invoices from backend code.

Also, make sure that you are using the code properly for Wix Billing Backend - Invoices.
https://www.wix.com/corvid/reference/wix-billing-backend.invoices.html#createInvoicePreviewUrl

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);
    } );
}

The same with creating an invoice too.
https://www.wix.com/corvid/reference/wix-billing-backend.invoices.html#createInvoicePreviewUrl

The same with IdAndVersion
https://www.wix.com/corvid/reference/wix-billing-backend.invoices.html#IdAndVersion

Hi @givemeawhiskey, thanks for the prompt response. I don’t know of any “Wix invoices app” other than the ‘wix-billing-backend’ module and the invoice features that come with any Wix account. But yes, I’m loading:

import wixBilling from 'wix-billing-backend'

To clarify, the .createInvoice() method works just fine for me. However the .createInvoicePreviewUrl() does not. My above example uses hardcoded values for the IdAndVersion object, which were returned when I created an invoice.

I’ve been troubleshooting this for several days with no luck. Even when I start fresh with nothing but that function itself, I get an error. I think it’s either a permissions problem or I’m using the module in an unintended way.

@kyleburzota Any luck with this? I am facing similar issue

same issue. no luck

@kyleburzota If you call the createinvoicepreviewurl() from frontend, you need suppressAuth. Are you using suppressAuth to create a preview url?
https://www.wix.com/velo/reference/wix-billing-backend/invoices-obj/createinvoicepreviewurl

After changing promise handling with await call, it worked.

@jacobg this bug still persists in the Wix Editor backend test runner. Many of the
wix-billing-backend
APIs do not work. Here’s a few examples.

Create a Price Quote API (works)

image

Get a Price Quote API (NOT WORKING)

image

This error seems to claim the Price Quote (entity) doesn’t exist?

Delete a Price Quote API (NOT WORKING)

image

The error states that the wix-price-quotes, manage permission is missing. I’m the only user and also the admin.

Send Price Quote API (NOT WORKING)

image

What are we doing wrong?