#Kvts-webhook-error
1 messages · Page 1 of 1 (latest)
Hey there. That error would imply to me that for whatever reason we cannot reach your webhook handler
Those are simply event retries: https://stripe.com/docs/webhooks/best-practices#events-and-retries
So because we didn't receive a 2xx response initially, we'll reattempt delivery X number of times over a certain period
Can you share the ID of the Event object? (evt_xxx)
The FUNCTION_INVOCATION_TIMEOUT error would imply that your code isn't even being ran/invoked
But that's not really a Stripe issue
but I can see my payment in payments section with correct order items
so it should ran
Can you share the ID of the Event object? (evt_xxx)
You should probably check the function logs on Vercel, too
The amount of time (in seconds) that a Serverless Function is allowed to process an HTTP request before it must respond. The maximum execution timeout is 5 seconds when deployed on a Personal Account (Hobby plan). For Teams, the execution timeout is 15 seconds (Pro plan) or 30 seconds (Enterprise plan).
I guess this is your issue: https://vercel.com/docs/concepts/limits/overview#serverless-function-execution-timeout
Your fulfillOrder function probably isn't resolving within the 5 second limit
You probably just need to handle that synchronously and return the 2xx response immediately
before fullfill funcion?
That's our recommended approach (we expect a 2xx response within a ~couple seconds)
Not before, no. Otherwise fulfillOrder will never be hit
Just don't use a promise chain
You just call fulfillOrder and then res.send
now it's just like that
It's not though. You're still waiting on fulfillOrder to resolve before res.status
maybe i should put it at the beggining of fulfill function?
Alternatively you could optimise that fulfillOrder function as its seemingly taking a while to resolve
I guess you're just working within the confines of the Vercel limits
ok but my order still completes
Did you check the Vercel logs?
Fullfilling Order!!!
SUCCESS: Order cs_test_a1k9VlFppKHg1jDr6iDu6usXu1GUipRHm76wHFczVActHpdxqVEjlKOddn has been added to DB!
2022-01-05T12:18:03.252Z d498a695-9aa4-4d03-adfc-1e7f53ac498f Task timed out after 10.01 seconds
this is the log
i could just simply stop that webhook retry option
that would solve my problem
but i do not know how
It wouldn't, it would compound your problem as we'd just eventually disable the webhook as non-responsive: https://stripe.com/docs/webhooks/best-practices#disable-logic
You can't disable retries anyway
You need to reconfigure your webhook handler. I think the res.status(200) is never being hit in the promise chain
Probably because of the .then in your fulfillOrder function
what do you suggest apart of then() ?
You just need to return from that function, without the .then
i put console.log() before res.status and it fired
so i think res.status hits
but i will try your way
didn't worked :/
What didn't?
returning res.status from that function
No, you just need to return that call to Firebase without the .then()
No, inside the fullfillOrder function. Remove the .then (with the console.log)
This isn't really a Stripe issue, so I'm somewhat limited in what support I can provide. But your webhook should instead look something like:
try {
if (event.type === 'checkout.session.completed') {
await fulfillOrder(session)
}
res.status(200).send(`Received!`)
} catch (err) {
res.status(400).send(`Error: ${err}`)
}
There's a good Node example here: https://stripe.com/docs/webhooks/quickstart
Are you redeploying this function each time to Vercel? Have you tried using the Stripe CLI when testing webhooks?
Can you paste the full code (not screenshots) of both the handler and the fullfillOrder function
import { buffer } from "micro";
import * as admin from "firebase-admin";
// Secure a connection to firebase
const serviceAccount = require("../../../permissions.json");
const app = !admin.apps.length
? admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
})
: admin.app();
// Stripe
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
const endpointSecurit = process.env.STRIPE_SIGNING_SECRET;
const fullfillOrder = async (session) => {
console.log("Fullfilling Order!!!");
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(),
email: session.metadata.email,
})
};
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;
try {
event = await stripe.webhooks.constructEvent(
payload,
sig,
endpointSecurit
);
} catch (e) {
console.log("ERROR", e.message);
return res.status(400).send({ message: "Webhook error: " + e.message });
}
try {
if (event.type === "checkout.session.completed") {
const session = event.data.object;
await fullfillOrder(session);
}
res.status(200).send(`Received!`);
} catch (err) {
res.status(400).send(`Error: ${err}`);
}
}
};
export const config = {
api: {
bodyParser: false,
externalResolver: true,
},
};
And what error are you seeing in Vercel on the most recent deployment?
Fullfilling Order!!!
SUCCESS: Order cs_test_a1A6THXv6GsHM9idzgNKl3qm3H4qBJeYVYo1qF608Q23sWvHZxFibqJhaY has been added to DB!
2022-01-05T12:58:39.025Z 425ff1a8-715c-4140-a0b9-c32de351160f Task timed out after 10.01 seconds
always same error