#awombmayu_code

1 messages ยท Page 1 of 1 (latest)

steel tendonBOT
#

๐Ÿ‘‹ 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/1442441689959632968

๐Ÿ“ 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.

near ridge
#

๐Ÿ‘‹ Hi there. When exactly do you see the duplicated messages? E.g. at page load, or when a user takes a particular action, or when your code makes a particular call? And do the duplicate messages appear at exactly the same time?

lavish spade
#

they appear on same time, when i go to my checkout site

near ridge
#

So from the log message, I guess you're creating a payment intent on checkout load? Is this in a useEffect?

lavish spade
#

yes

near ridge
#

Would you be able to provide a snippet of that code?

lavish spade
#
    useEffect(() => {
        setLoading(true);
        const amountInCents = Math.round(totalAmount * 100);
        const metadataCartString = getStripeMetadataCart(); 

        if (amountInCents <= 0) {
             setClientSecret(null);
             setLoading(false);
             return;
        }

        // 1. Client Secret vom Backend anfordern
        fetch('/api/create-payment-intent', { 
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ 
                amount: amountInCents,
                metadata: { cart_details: metadataCartString } 
            }) 
        })
        .then((res) => res.json())
        .then((data) => {
            if (data.clientSecret) {
                setClientSecret(data.clientSecret);  
            } else {
                console.error("Server lieferte kein clientSecret:", data.error);
                setClientSecret(null); 
            }
        })
        .catch(error => {
            console.error("Netzwerkfehler beim Abrufen des clientSecret:", error);
            setClientSecret(null); 
        })
        .finally(() => {
            setLoading(false);
        });
    }, [totalAmount, getStripeMetadataCart]);```
near ridge
#

I presume getStripeMetadataCart is a function? I think having a function as a dependency like this can be a bit unpredictable. Even if it returns the same value, the reference could change, or the function may be technically creating a new object. So I think the first thing I would try is to refactor so that you're not requiring a function in the dependency array

steel tendonBOT