I've learned that firebase puts it's API functions into sleep mode
, which is a problem for me. I call a function called createCheckoutSession
every-time a user enters their info on the register, and then it'll initiate the API function in firebase. If this doesn't get initiated every 2-3 minutes, it will shut down, and take 8 seconds to load up. That is not very good.
So how do I call createCheckoutSession
when a user lands on the regsiter page, before they type in all there details, so that by the time they hit next, the function in fireabase will already be up and running. Basically to initiate the API function in firebase, without actually rendering the stripe page, so it can be kept running in the bkg.
here's the stripe function:
export async function createCheckoutSession(activtyStatus){
let user = firebase.auth().currentUser;
//price ID with trial TEST ID
//price ID with trial LIVE ID
var price = 'price_1IGW85KDPaWWeL1yjWsi9oRa'
if (activtyStatus == "canceled") {
//live price
price = 'price_1IfmDsKDPaWWeL1ywjMTGarh'
}
const checkoutSessionRef = await firestore
.collection('customers')
.doc(user.uid)
.collection('checkout_sessions')
.add({
price: price,
success_url: "http://localhost:3000/clients",
cancel_url: "http://localhost:3000/signin",
});
// Wait for the CheckoutSession to get attached by the extension
checkoutSessionRef.onSnapshot(function (snap) {
const { error, sessionId } = snap.data();
if (error) {
// Show an error to your customer and
// inspect your Cloud Function logs in the Firebase console.
console.log(`An error occured: ${error.message}`);
}
if (sessionId) {
// We have a session, let's redirect to Checkout
// Init Stripe
const stripe = window.Stripe('pk_live');
console.log("line 116 checkout.js")
stripe.redirectToCheckout({sessionId})
console.log("logged stripe")
}
});
}