#loukas_02272

1 messages · Page 1 of 1 (latest)

eternal mortarBOT
keen tulip
#

👋 happy to help

twin thunder
#

hi

keen tulip
#

would you mind sharing the error?

twin thunder
#

error - HttpError: Invalid body statusCode: 400,

keen tulip
#

are you using Docker by any chance?

twin thunder
#

its like any desk?

keen tulip
#

would you mind sharing the whole code of you webhook endpoint app?

twin thunder
#

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);

keen tulip
#

how are you testing it?

twin thunder
#

stripe cli

keen tulip
#

would you mind sharing one more thing please

#

would you mind sharing the code for the app

#

that uses this code

twin thunder
#

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);
});

keen tulip
#

that's not what I meant

#

I meant the api code that imports the code you sent first

eternal mortarBOT
twin thunder
#

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

warm saddle
twin thunder
#

from my backend endpoint

#

stripe logs are showing everything is ok

warm saddle
#

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.

twin thunder
#

ok thank you