#fedoraus
1 messages · Page 1 of 1 (latest)
Hey! Bit of a broad question! Is there a specific use case you're trying to account for?
yes, i can show you part of my code, using checkout session and retrieving data from stripe webhook
const sigHeader = req.headers['stripe-signature'] || '';
let event;
try {
event = stripe.webhooks.constructEvent(req.rawBody, sigHeader, 'whsec_gqeT2XbtqYqOGR73oUmVljPbdB8GgUYB');
} catch (error) {
res.status(400).send('Bad request sent.');
return;
}
functions.logger.info(event);
console.log(event);
const {email} = await stripe.customers.retrieve(event.data.object.customer);
await firestore.doc(email).set({subscription_date: new Date(), interval: 'monthly'}, {merge: true});
res.sendStatus(200);
});```
before the customer clicks checkout, i need to connect firebase user with cutomer user
I'm not very familiar with Firebase, but when you receive Stripe webhook event you should have the customerId
You are listening to what Webhook event ?
payment_intent.succeeded
Great, so you'll have the customerId in the event body you'll receive:
https://stripe.com/docs/api/payment_intents/object#payment_intent_object-customer
but how i can connect the uid firebase and customer id from stripe??
When creating the Checkout Session for your customer, you can add metadatas to it:
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-metadata
You can listen to the webhook event checkout.session.completed you'll get those metadatas (which contains your Customer Firebase UID) and the customerId
thank you very much!