I seem to be having trouble with .getPricingPlans() It seems to me that something is being returned, as it doesn’t seem to be null. That said, it could also just not be working. Any help with this is greatly appreciated.
I cannot get this to return anything (not even null) from an account that has no pricing plan:
user.getPricingPlans()
.then( (pricingPlans) =>
let firstPlan = pricingPlans[0];
let planName = firstPlan.name;
let startDate = firstPlan.startDate;
let expiryDate = firstPlan.expiryDate;
} );
Just console log to see what is being returned…
Console.log(planName);
console logging isn’t working is the main problem. It seems like the promise is just never being returned at all.
console log will always work, it will just log “undefined” if there is noting defined for planName.
Maybe I should rephrase it: console log isn’t firing because it’s not getting that far. I’m trying to figure out why it’s stopping.
@christianeasterly
try this…
import wixUsers from ‘wix-users’;
$w.onReady( function () {
if (wixUsers.currentUser.loggedIn) {
let user = wixUsers.currentUser;
console.log(user);
user.getPricingPlans()
.then((pricingPlans) => {
let firstPlan = pricingPlans[0];
let planName = firstPlan.name;
console.log(planName);
let startDate = firstPlan.startDate;
let expiryDate = firstPlan.expiryDate;
console.log(startDate);
console.log(expiryDate);
})
} **else**
console.log("user is not logged in");
})
The pricingplan functions isnt working at all. Even i just try to log a random string.
have you physically added the pricing plan app to your site and added a plan to the logged in user ?
Yes I even got an email saying the member has signed up for a plan.
I tested the code there, it only works on the live site, it will not work on preview mode. I suspect you are trying to do this in preview mode ?
No I’m using live mode. I tried displaying random text in a textbox to test if the function even started and it doesnt.
I have copied the code exactly the same as I have written above and it works on my site. So I can confirm that the code above is not the issue.
-
you may have some additional code on your page interfering with the code above
-
you may have some issue with your paid plan app
Never mind, I see the problem. How does the plans update? Are previous plans stored in the database and if so does it act like a queue or a stack?
@mikemoynihan99 Thanks for you responses by the way. I think I have figured out there was an issue with my chrome and firefox installs. All of sudden everything broke and then live wouldnt load. I reinstalled the browsers and I’m now actually seeing the console log firing. Not sure what kamoi is dealing with but I think my issue is resolved now.
That said: the code you pasted doesn’t work at all for me either.
Hello, have you ever found the answer to your final question? Are plans stored in a database?
got it! I arranged mine as follows, try using .catch (err)
$w.onReady(function () {
let user = wixUsers.currentUser; // "get user "
user.getPricingPlans()
.then((pricingPlans) => {
let firstPlan = pricingPlans[0];
let planName = firstPlan.name; // "get user plan"
if (planName === "plan1") {// your code here}
if (planName === "plan2") {// your code here}
if (planName === "plan3") {// your code here}
if (planName === "plan4") {// your code here}
if (planName === "plan5") {// your code here}
})
.catch((err) => { //detect if user dont have a plan, and execute a function
console.log("no-plans-detected")
// your code here
});
})