Retrieving the active Pricing Plan name

:red_question_mark: Question Body

Hi everyone,

I’m having difficulty retrieving the active Pricing Plan name for the currently logged-in user in my Velo backend code. My goal is to use this plan name to enforce usage limits (quotas) on a button click in the frontend.

The Goal

I need a reliable backend function that returns the string value of the user’s active plan (e.g., 'Pro', 'Basic', or 'Default') so I can determine the template creation limit on the frontend.

My Backend Code Attempts (plans.jsw)

I’ve attempted several methods using wix-pricing-plans-backend, but they all fail to correctly identify my active plan and consistently return 'Default' in the logs:

  • Attempt 1: Using getPlanOrders with a query (which works for some users):

    JavaScript

    import wixPricingPlansBackend from "wix-pricing-plans-backend";
    import wixUsers from 'wix-users-backend';
    
    export async function getActivePlanName() {
      // ... (code to check userId)
      try {
        const ordersResult = await wixPricingPlansBackend.getPlanOrders({
          query: wixPricingPlansBackend.queryPlanOrders()
            .eq("receiverId", userId) 
            .hasSome("status", ["Active", "Pending"]) // Statuses may be the issue
            .limit(1) 
        });
        // ... (check ordersResult and return planName)
      } catch (error) {
        // ...
      }
    }
    
    
  • Attempt 2: Using isPlanMember (which shows red in my Velo editor, indicating a Linter issue):

    JavaScript

    // ...
    const isPro = await wixPricingPlansBackend.isPlanMember('Pro');
    if (isPro) return 'Pro';
    // ...
    
    

The Result

The console consistently shows the following output, indicating the backend is failing to retrieve the actual plan name:

console.log from Backend: “Found active plan: Default”

console.log from Frontend: “Quota Check: FULL. Current: 0, Limit: 0. Opening NoTemplate.”

My Questions

  1. What is the most stable and currently supported Velo API function to reliably get the active plan name of the current user, avoiding Linter errors like the ones I’m seeing with queryPlanOrders and isPlanMember?

  2. Are there specific Wix Pricing Plan statuses (like 'TRIAL' or 'FREE') that I must include in my query, or is the issue more likely related to file permissions on the backend JSW file? (Permissions are currently set to ‘Site Member’).

Any guidance on the correct API usage or troubleshooting data/permissions would be greatly appreciated!

Thank you!
Eliran

Hey Eliran,

Looks like you’ve taken the help of AI to generate this bit of code that you are using - which is great; however AI sometimes does not have access to the latest APIs and updates that have taken effect in the Wix ecosystem, which is why if you were to ask ChatGPT to generate Velo code for you, it will do so using old, deprecated APIs and formats - such as wix-users and the .jsw file format. Infact not only these, but Velo as a whole is now being replaced by the Wix Javascript SDK.

The point of me telling you this is because I’d recommend instead of using external AI tools, you’ll get more accurate results using Wix’s very own AI code assistant, that will help you write code, inside the Wix IDE and you can also use the Velo AI Assistant for the same, which you will find on the API Reference Documentation pages.

Another quick, effiecient and recommended way is to first look up on the forum and search for posts that may highlight a similar issue to yours before posting a question of your own. Chances are - someone has already faced the same roadblock and has managed to come up with a solution or a workaround, and the answer is right there - just a search away.

And here it is - follow the steps in this post where I have explained how to fetch the active plans of a logged in user. You can use it as a base layer and customise it to achieve the functionality you need: