#loukas_02272
1 messages · Page 1 of 1 (latest)
👋 happy to help
hi
would you mind sharing the error?
error - HttpError: Invalid body statusCode: 400,
[ERROR] Failed to POST: Post "http://localhost:3000/api/stripe-check": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
are you using Docker by any chance?
its like any desk?
would you mind sharing the whole code of you webhook endpoint app?
import { buffer } from 'micro';
import Cors from 'micro-cors';
import Stripe from 'stripe';
// Προσαρμόστε τον κλειδί πρόσβασης (secret key) του Stripe εδώ
const stripe = new Stripe('sk_test_51MRYanJqOM1uXchCrFzAepgDJhj87ZpYz0ipQYahDouyAmKBkRtzXUQsCVgo2NaGQ41N2nYEEViYd02x7h31jKAP00npgMdCQZ');
const cors = Cors({
allowMethods: ['POST', 'HEAD'],
});
const webhookHandler = async (req, res) => {
if (req.method === 'POST') {
const requestBuffer = await buffer(req);
const payload = requestBuffer.toString();
const sig = req.headers['stripe-signature'];
try {
// Επαληθεύστε την υπογραφή του Stripe
const event = stripe.webhooks.constructEvent(payload, sig, 'whsec_383e597551232b44783cfa86ccbd4d4f8032d0310c9ce2e67a556a33fc9caff4');
// Εδώ μπορείτε να αποκτήσετε πρόσβαση στο object της ειδοποίησης
const paymentIntent = event.data.object;
// Εδώ μπορείτε να επεξεργαστείτε τα δεδομένα της ειδοποίησης
console.log('Received webhook for PaymentIntent:', paymentIntent.id);
res.status(200).json({ received: true });
} catch (err) {
console.error('Error processing webhook:', err.message);
res.status(400).json({ received: false });
}
} else {
res.setHeader('Allow', 'POST');
res.status(405).end('Method Not Allowed');
}
}
export default cors(webhookHandler);
how are you testing it?
stripe cli
would you mind sharing one more thing please
would you mind sharing the code for the app
that uses this code
fetch('/api/stripe-check',
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
}
)
.then((response) => console.log(response.json()))
.then((data) => {
if (data.success) {
setPaymentData(data.paymentData);
} else {
console.error('Failed to fetch payment data:', data.message);
}
})
.catch((error) => {
console.error('Error fetching payment data:', error);
});
the api/stripe-check.js is called from the success page to check if the payment was successful, sorry if i cannot understand what else you want me to send you
Hey! Taking over for my colleague. First I want to double check with you something first, are you getting this error fomr a Stripe API or from your backend endpoint ?
if this comes from Stripe APi, can you share the ID (req_xxx) of the failing API request?
https://support.stripe.com/questions/finding-the-id-for-an-api-request
Sorry, without having your complete backend and frontend API call, I'm not sure that I'm able to help you. This channel is for Stripe APIs issues. I invite you to debug your integration and double check your calls.
ok thank you