I have this Firebase v8 syntax to push the Stripe checkout items into Firestore and I would like to migrate it to Firebase v9 please
import * as admin from "firebase-admin";
const serviceAccount = require("../../../permissions.json");
const app = !admin.apps.length ? admin.initializeApp({
credential: admin.credential.cert(serviceAccount) }) : admin.app();
const pushIntoStore = async (session) => {
return app.firestore()
.collection("users")
.doc(session.metadata.email)
.collection("orders")
.doc(session.id).set({
amount: session.amount_total / 100,
amount_shipping: session.total_details.amount_shipping / 100,
images: JSON.parse(session.metadata.images),
timestamp: admin.firestore.FieldValue.serverTimestamp()
})
.then( () => {
console.log(`SUCCESS: Order ${session.id} has been added to the DB`)
});
};
all of it please. I have the session and the data so don't worry about that. I just need all Firebase code refactored, plus the timestamp part also please, thanks! :) the above code basically creates a collection users then inserts a new document with a custom id which is - session.metadata.email -> then further on for each custom id it creates another collection called orders in which it sets document with another custom id which is session.id - and inside the document sets the data object. Thanks again!