How To get Paid Plan Status(yes/No) of a user while using my service using Velo Code ?

here i m a newbie here basically what i need is …i want to use velo api for getting info regarding if any of my user paid for the subscription of the services that my site offers…just want to return if user paid is true than i ll continue its action further using my code …i m having difficulty finding any documentation regarding this …the best i could have found is solution given by an user "Wix Paid Plan " Api i m not sure its gonna work like i wanted please do guide me please.

1 Like

I believe the only way is to use the Wix Paid Plan API…or at least that is the easiest way.

import { orders } from 'wix-paid-plans-backend';
import wixUsers from 'wix-users-backend';

export async function getUserPlan() {
  const user = wixUsers.currentUser;
  if (!user.loggedIn) return null;

  try {
    // strict: false allows getting orders for the current user without full admin privileges in some contexts, 
    // but typically backend modules run with admin privileges anyway.
    const pricingPlans = await orders.listOrders({
        query: {
            filter: {
                "buyer._id": user.id,
                "status": "ACTIVE"
            }
        }
    });

    if (pricingPlans.length > 0) {
      // Returns the first active plan
      return pricingPlans[0].planName; 
    }
    return "Free";
    
  } catch (error) {
    console.error("Error fetching plans", error);
    return "Free";
  }
}

That code uses APIs that have long been deprecated.

Here’s the updated method: