What is the code that you have used?
It’s difficult to predict what could possibly be causing that error without taking a look at the actual code.
And as Dan highlighted above, there is no need to use any backend function as you are simply querying the pricing plans for the logged in user and not anyone else.
Try out this code which works entirely in the frontend:
import { authentication, currentMember } from 'wix-members-frontend';
import { orders } from 'wix-pricing-plans-frontend';
$w.onReady(async () => {
// Check if member is logged in.
console.log("Checking member's login status...");
const isLoggedIn = authentication.loggedIn();
if (isLoggedIn) {
const loggedInMember = await currentMember.getMember();
console.log("Member is logged in: " + loggedInMember.loginEmail + ". Fetching subscription status...");
let planStatus = await getsubstatus();
if (planStatus == "ACTIVE") {
// User has one or more active subscriptions.
// SHOW YOUR DOWNLOAD BUTTON;
} else {
// No active subscription.
// HIDE YOUR DOWNLOAD BUTTON;
}
} else {
// Handle when member isn't logged in
console.log("Member is not logged in. Cannot fetch subscriptions if not logged in.");
// HIDE YOUR DOWNLOAD BUTTON;
}
});
async function getsubstatus() {
try {
const ordersList = await orders.listCurrentMemberOrders();
let activeOrdersArray = [];
console.log("Fetched orders:", ordersList);
if (ordersList.length === 0) {
console.log("No pricing plans ordered.");
return "NA";
}
ordersList.forEach(item => {
if (item.status === "ACTIVE") {
activeOrdersArray.push(item);
}
});
if (activeOrdersArray.length === 0) {
console.log("No currently ACTIVE plans for this user.");
return "NA";
} else {
console.log("User has ACTIVE plan(s):", activeOrdersArray);
return "ACTIVE";
}
} catch (error) {
console.error("Error fetching member orders:", error);
return "NA";
}
}