#Xcoder - Firebase
1 messages · Page 1 of 1 (latest)
Let's continue in this thread.
hey there
i am using stripe
MY payment method is working
BUT!!! i want my transaction data in firebase
I have added a webhook file in my api folder
and linke it to
firebase
ok
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 th DB);
})
.catch(console.log);
}
export default async (req,res) => {
if (req.method === 'POST'){
const requestBuffer = await buffer(req);
const payload = requestBuffer.toString();
const sig = req.headers["stripe-signature"];
let event;
//verify that the event posted came from stripe
try{
event= stripe.webhooks.constructEvent(payload,sig,endpointSecret);
}catch(err){
console.log('ERROR', err.message)
return res.status(400).send(`Webhook error: ${err.message}`);
}
//handle the checkout.session.completed event
if(event.type === 'checkout.session.completed'){
const session = event.data.object;
//fullfill he orders
return fulfillOrder(session)
.then(() =>{
return res.status(200);
} )
.catch((err) =>{
return res.status(400).send(`Webhook Error:${err.message}`);
})
}
}
}
export const config={
api:{
bodyParser: false,
externalResolver: true,
}
}
this is my webhook file
code
Can you give me the ID of an event you expected to trigger this code?
here is my git hub repo
I am following a youtube video
1:21:27 Creating the Webhook!
he is creating webhook
at 1:21:27
and linking with firebase
so that he can get the data in firebase
can you please help me with that
I can try, but I need the ID of an event related to this. Can you provide one?
You should be able to get it from your Stripe Dashboard in Developer > Events.
It's the ID that starts with evt_
evt_1KTvfFSH4ImyLd8NUM4g8WVU
You don't have a webhook endpoint set up to listen for that event. Are you using Stripe CLI to forward the events?
yeah
Are you seeing the events appear in Stripe CLI as expected?
yeah
but when i enter
like
stripe listen --forward-to localhost:3000
on my vscode terminal
it gives me error
so i have to go on stripe folder in c drive
What error does it give you?
Could not create process with command 'C:\Users\mohd isa\scoop\apps\stripe\current\stripe.exe listen --forward-to localhost:3000/api/webhook'.
If you run stripe -v what version does it say you're using?
Could not create process with command 'C:\Users\mohd isa\scoop\apps\stripe\current\stripe.exe -v'.
i am running this cammand in my visual studio code
How did you install Stripe CLI?