#jasfo_code

1 messages · Page 1 of 1 (latest)

solid stratusBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1285533949753425992

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

spark urchin
#

code back :

const createPaymentIntent = async (req, res) => {
    const {
        promoCode,
        email,
        first_name,
        last_name,
        civility,
        creation_date,
        street,
        complement,
        postal_code,
        city,
        country,
        paymentIntentId
    } = req.body;

    let amount = 9900; 
    
    try {
        if (promoCode) {
            try {
                amount = 12600
                const coupon = await stripe.coupons.retrieve(promoCode);
                if (coupon.amount_off) {
                    amount -= coupon.amount_off; // Réduction en montant fixe
                } else if (coupon.percent_off) {
                    amount -= (amount * (coupon.percent_off / 100)); // Réduction en pourcentage
                }
            } catch (error) {
                console.log("Invalid promo code: ", error.message);
            }
        }

        let paymentIntent;
        if (!paymentIntentId) {
            paymentIntent = await stripe.paymentIntents.create({
                amount,
                currency: 'eur',
                payment_method_types: ['card'],
                description: 'Frais de dossier - création',
                metadata: {
                    integration_check: 'accept_a_payment',
                    email,
                    first_name,
                    last_name,
                    civility,
                    creation_date,
                    street,
                    complement,
                    postal_code,
                    city,
                    country
                },
            });
        } else {
            paymentIntent = await stripe.paymentIntents.update(paymentIntentId, {
                amount,
                description: 'Frais de dossier - création',
                metadata: {
                    integration_check: 'accept_a_payment',
                    email,
                    first_name,
                    last_name,
                    civility,
                    creation_date,
                    street,
                    complement,
                    postal_code,
                    city,
                    country
                },
            });
        }

        res.send({
            clientSecret: paymentIntent.client_secret,
            paymentIntentId: paymentIntent.id, // Retourne également l'ID du paymentIntent
        });
    } catch (error) {
        console.error("Error creating/updating payment intent: ", error.message);
        res.status(500).send({ error: error.message });
    }
};
violet nebula
#

👋 happy to help

spark urchin
violet nebula
#

would you mind just sending the javascript part that concerns the Stripe Element please?

spark urchin
#
async function fetchClientSecret(promoCode = '') {
            // Check if there is a paymentIntentId in local storage
            const paymentIntentId = getPaymentIntentId();

            const response = await fetch('https://sandbox.api.mon-autoentreprise.fr/guichet/createPaymentIntent', {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({
                    promoCode,
                    email: params.get('email'),
                    first_name: params.get('first_name'),
                    last_name: params.get('last_name'),
                    civility: params.get('civility'),
                    creation_date: params.get('creation_date'),
                    street: params.get('street'),
                    complement: params.get('complement'),
                    postal_code: params.get('postal_code'),
                    city: params.get('city'),
                    country: params.get('country'),
                    paymentIntentId: paymentIntentId,
                }),
            });

            if (!response.ok) {
                throw new Error(`An error has occurred: ${response.status}`);
            }

            const data = await response.json();
            console.log(data);
            clientSecret = data.clientSecret;

            // Save paymentIntentId to local storage
            savePaymentIntentId(data.paymentIntentId);

            elements = stripe.elements({ clientSecret });
            paymentElement = elements.create('payment');
            paymentElement.mount('#card-element');
        }
#

And when I put a coupon a call this function

violet nebula
#

is there an accessible website where I could test this?

spark urchin
#

Yes

violet nebula
#

what are the steps to reproduce?

spark urchin
#

Just when you go to this page and wait 5 seconds, the page freezes

violet nebula
#

it's loading correctly for me

#

and I was able to apply the promocode

spark urchin
#

For me, I have a huge latency, and when I did an analysis with page insight, I have errors in the analysis (I'm on Google Chrome)

violet nebula
#

are you on a vpn?

spark urchin
#

nop

violet nebula
#

It's working fine for me

#

I tried that again

spark urchin
#

I have this

violet nebula
#

I can't seem to reproduce

spark urchin
#

It's really strange, in my console I also have these errors

solid stratusBOT
spark urchin
#

my bad, the error of the first screenshot it's just me, i have tested with my 5g, but I still have this latency bug

minor arrow
#

Which "latency bug" exactly?

spark urchin
minor arrow
#

I am trying this in my browser and I don't see the same behavior. It might be an issue with your browser/computer.

spark urchin
#

I just tried on two other PCs in our company using both Google Chrome and Firefox, and unfortunately, I still experience the latency issue. Are there any known bugs related to WordPress? Locally, it doesn't lag at all, but in production, there are noticeable latencies.

minor arrow
#

I don't know much about WordPress. I can't reproduce the issue so it's hard for me to say why you're seeing this. In any case it doesn't seem to be related to Stripe since I see the lags on the other parts of the page in your video.