I am working with Firebase Functions and Stripe to build out an ecommerce web application. I have implemented indexedDB (idb library) to store the shopping cart in memory and pass the cart between the shopping and checkout pages. I am currently having an issue trying to determine to correct flow to know if the payment was successful. I can see in the firebase database that the checkout_sessions and payments collections are being filled but when the page redirects from the stripe checkout session how can I have my site check if the payment was successful, as I don't have any context from returning from the page and processing data based off returning from the checkout page. I have attached a few screenshots and the code that I am using to process the payment
I would like to update the checkoutsession with the status of the payment after it finishes but I can't figure out how to edit the Cloud functions for stripe to include that information or create my own cloud function to process it.
static async dbCheckOut(idbCart){/* const payments = getStripePayments(app, {
productsCollection: "products",
customersCollection: "customers",
});
console.log(payments)
const session = await createCheckoutSession(payments, {
line_items: [
{
price: 'price_1OMuJZFU1DIWwfN5gbLDdzZi',
quantity: 2,
},
{
price: 'price_1OMuLEFU1DIWwfN5YQzvfXZw',
quantity: 2,
},
],
});
console.log(session)
window.location.assign(session.url) */
const currentUser = auth.currentUser.uid
console.log(currentUser)
const chklines = DBHelper.buildCheckoutLines(idbCart)
const successUrl = 'http://127.0.0.1:5500/public/shopping.html'
let checkoutSessionData = {
mode: 'payment',
line_items: chklines,
success_url: successUrl, // can set this to a custom page
cancel_url: 'http://127.0.0.1:5500/public/cart.html', // can set this to a custom page
ui_mode: 'embedded' // set checkout session to embedded
}
const chkoutSessionRef = collection(db,"customers", currentUser, "checkout_sessions")
console.log(chkoutSessionRef)
const docRef = await addDoc(chkoutSessionRef, checkoutSessionData)
/* const chkoutSessionRef = await addDoc(
collection(db, `customers/${currentUser}/checkout_sessions`, checkoutSessionData)
);*/
onSnapshot(docRef, (snap) => {
const { error, url } = snap.data()
if (error) {
new Error(`An error occurred: ${error.message}`);
}
if (url) {
//pass url to chechkout html page to have show in iframe
//before returning need to call a function to clear the cart
if(url === successUrl){
dbPromise.clear(storeName)
}
window.location.assign(url);
}
})
}
```[[[enter image description here](https://i.stack.imgur.com/g2PFi.png)](https://i.stack.imgur.com/wSSYW.png)]
I have tried editing the cloud functions provided by the Stripe Firebase extension. These functions can be found in the Google Cloud console. I attempting to edit them to include the payment_status element but it does not appear to be working
[enter image description here](https://i.stack.imgur.com/70cQW.png)