I actually found a way to make this work, what I’ve done is deploy a simple page (hosted for free on firebase) that would redirect to checkout using the session ID.
This is the entire flow :
Wix Frontend (the checkout is triggered by the click of a “subscribe” button)
const stripeApiKey = "pk_test_1234"
export async function subscribeBtn_click(event) {
let checkoutSession = await
getCheckoutSession(userData.customerID)
if (checkoutSession.id !== undefined) {
wix Location .to("your redirect link")
} else {
console.log('Checkout Session Error');
}
}
Wix Backend :
export async function getCheckoutSession(customerID) {
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [{
price: 'plan_G6s0UB8YiPvOoZ',
quantity: 1,
}],
mode: 'subscription',
success_url: 'your success',
cancel_url: 'your cancel',
customer: customerID
});
return session;
}
Redirect Page’s JS (hosted on Firebase):
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
var stripe
if (urlParams.has('apiKey')) {
stripe = Stripe(urlParams.get('apiKey'));
if (urlParams.has('sessionID')) {
let stripeSessionID = urlParams.get('sessionID')
stripe.redirectToCheckout({
sessionId: stripeSessionID
}).then(function (result) {
console.log(result);
});
}
}else {
console.log("Failed, reason : No Params");
}