I have been using the Run Payments with Stripe extension and setting up webhooks like checkout.session.completed. I am interested in knowing how to successfully post the job object to Firestore after a successful payment.
Here's my .ts code:
const docRef = await db
.collection('users')
.doc(uid)
.collection('checkout_sessions')
.add({
automatic_tax: true,
tax_id_collection: true,
payment_method_types: ["card"],
mode: 'subscription',
line_items: [
{
price: this.paymentPlan.stripePriceId,
quantity: 1,
description: jobData.jobLevel + ' ' + jobData.jobTitle,
},
],
allow_promotion_codes: true,
success_url: 'http://localhost:4200/success',
cancel_url: 'http://localhost:4200/success',
metadata: {
payId: payId
}
});
// Wait for the CheckoutSession ...
docRef.onSnapshot((snap) => {
const { error, url } = snap.data() as any;
if (error) {
alert(`An error occurred: ${error.message}`);
}
if (url) {
window.location.assign(url);
}
this.loading = false;
});
this.db.collection('users').doc(uid).collection('jobs').add(job).then(() => {
console.log('Job posted successfully!');
}).catch(error => {
console.error('Error posting job:', error);
});
Do I need to create custom Firebase functions to handle the webhook and post the job?
Thank you!