Paid Plans (Partially Solved)

Hi Corvid,

I am trying to check if an individual has a specific plan, I am currently doing this in a backend web module and have managed to get the plans to front end but I want to be able to show an error message before an individual can move on with a Slideshow if they have not purchased a certain plan, I need to do this in code for a number of reasons.

current back end code:

function checkPricingPlan() {
return user.getPricingPlans()
.then((pricingPlans) => {
var planName = pricingPlans;
var n = planName.includes(“Veteran”);
let outcome = pricingPlans;
if (n === true ) {
return outcome;
} else {
return “NORESULTS”;
}
})
. catch ((err) => {
let errorMsg = err;
});
}

clientSide Code:

export function nextPagePage6_click(event) {
hasPricingPlan().then( function (outcome) {
console.log(outcome);
if ( outcome === “NORESULTS”) {
$w(“#noPlan”).show();
} else {
$w(“#slideshow1”).changeSlide(6);
}
if (wixWindow.formFactor === “Desktop”) {
wixWindow.scrollTo(0, 194)
} else {
wixWindow.scrollTo(0, 395);
}
})
}

Dear All,

I have managed to confirm a plan and also then verify it is the plan that I need the customer to have to access a specific site, I need to do this in code for a number of reasons as I am using slideshow and one of my navigation buttons then allows plan holders to move on if they hold the correct plan, there are many other use cases for this also.

Anyway, having gotten my head around the web module, export and import mind warp I have managed to achieve only a partially complete outcome of a complex code for me , at present I can confirm only one plan “FirstPlan” I would like to be able to search all the plans and confirm if the user has one of a number of potential plans that they may hold? now this is most likely possible and a simple fix in the code to achieve this but I am learning as I go. If @yisrael-wix or @andreas-kviby or another could help it would be greatly appreciated.

If I have not made myself clear in the above paragraph, please do feel free to ask what it is that I am looking for.

Backend function:

export function hasPricingPlan() {
return checkPricingPlan()
}
function checkPricingPlan() {
return user.getPricingPlans()
.then((pricingPlans) => {
let firstPlan = pricingPlans[0];
let planName = firstPlan.name;
if (planName.includes(“whatever you want thats in the plan name”)) {
return planName;
} else {
return “NORESULTS”;
}
});
}
Client side code:

export function button_click(event) {
hasPricingPlan().then( function (planName) {
if (planName === “NORESULTS”) {
console.log(“BAD DATA OR NO DATA BACK!”);
} else {
// carry out what you want to do…
}
})
}