Here is the wix page which i am talking about https://hotbodypal.wixsite.com/website/create-order?email=newuser4@ex.com&slug=premium-monthly-gp
Here is the code from routes.js to handle routing
export function create_order_Router(request) {
return wixUsersBackend.generateSessionToken(request.query.email)
.then((sessionToken) => {
console.log("session token", sessionToken);
return ok("create-order-page", {sessionToken, query: request.query});
});
}
Here in this code i am passing email in query parameters then in routes.js file i am executing generateSessionToken method to get login session token. then passing this token in router-data to page “create-order-page”
At Frontend side code on Ready:
import wixPaidPlans from 'wix-paid-plans';
import wixWindow from 'wix-window';
import wixData from 'wix-data';
import wixUsers from 'wix-users'import wixLocation from 'wix-location';
$w.onReady(async function () {
$w("#group17").hide();
$w("#socialBar7").hide();
var routerData = wixWindow.getRouterData();
console.log("router data", routerData.query)
if ((routerData.query.status == "done") || (routerData.query.status == "failed")) {
console.log("done");
} else {
await wixUsers.logout();
await wixUsers.applySessionToken(routerData.sessionToken)
wixData.query("PaidPlans/Plans").eq("slug", routerData.query.slug)
.find()
.then(async (res) => {
if (res.items.length > 0) {
console.log("create order page");
wixPaidPlans.orderPlan(res.items[0]._id)
.then((myOrder) => {
console.log("my order", myOrder);
setTimeout(function () {
wixLocation.to(wixLocation.url + "&status=done")
}, 500)
})
.catch(async (error) => {
console.log("error", error)
setTimeout(function () {
wixLocation.to(wixLocation.url + "&status=failed")
}, 500)
})
} else {
setTimeout(function () {
wixLocation.to(wixLocation.url + "&status=failed")
}, 500)
}
})
}
});
at frontens side i am getting session token and slug for pricing plan. first i am calling applySessionToken to login the user using oken. and then i am fetching plan data from database usign plan slug
Then using plan Id i am executing orderPlan Method to create subscription for free plan. but as a result it is activating 2 subscriptions with same plan.
there is not other page or code calling orderPlan method.
Please help me to fix this strange issue