#meet_code

1 messages ¡ Page 1 of 1 (latest)

mortal whaleBOT
#

👋 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/1275693033131610112

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

heavy gazelleBOT
#

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.

feral warren
#

Hi there, looks like the initialization may have some issue. Can you share your whole code?

pliant siren
#
var elements;
    // Function to initialize Stripe Elements
    function initializeElements() {
        console.log('elements were initialized. ');
        if (!stripe) return;
        
        elements = stripe.elements(options);
        window.elements = elements;
        window.stripe = stripe;
    }

    document.addEventListener('DOMContentLoaded', function() {
        initializeElements();
    });
feral warren
#

Yeah and what options that you are passing in?

pliant siren
#
        allow: 'payment *',
        mode: 'payment',
        amount: 1099,
        currency: 'usd',
        paymentMethodCreation: 'manual',
        setupFutureUsage: 'off_session',
        onBehalfOf: 'test',
        appearance: appearance,
    };
feral warren
#

Okie, can you share the full file?

pliant siren
#

this is my whole script for initializing element:

<script src="https://js.stripe.com/v3/"></script>
<script>
    var stripe = Stripe('valid_publishable_key');
    const appearance = {
        theme: 'stripe',
        labels: 'floating',
        
        variables: {
            colorPrimary: '#0570de',
            colorBackground: '#ffffff',
            colorText: '#30313d',
            colorDanger: '#df1b41',
            fontFamily: 'Ideal Sans, system-ui, sans-serif',
            fontSizeBase: '12px',
            spacingUnit: '1px',
            borderRadius: '4px',
        }
    };
    
    const options = {
        allow: 'payment *',
        mode: 'payment',
        amount: 1099,
        currency: 'usd',
        paymentMethodCreation: 'manual',
        setupFutureUsage: 'off_session',
        onBehalfOf: 'test',
        appearance: appearance,
    };

    var elements;
    // Function to initialize Stripe Elements
    function initializeElements() {
        console.log('elements were initialized. ');
        if (!stripe) return;
        
        elements = stripe.elements(options);
        window.elements = elements;
        window.stripe = stripe;
    }

    document.addEventListener('DOMContentLoaded', function() {
        initializeElements();
    });
</script>
#

following is for calling confirmation token API:

setTimeout(() => {
                stripe.createConfirmationToken({
                    elements,
                    params: {
                        payment_method_data: {
                            billing_details: {
                                name: name,
                                address: {
                                    line1: street,
                                    city: city,
                                    state: state,
                                    country: countryCode2Char,
                                    postal_code: zipCode,
                                }
                            }
                        }
                    }
                }).then(({error, confirmationToken}) => {
                    if (error) {
                        stripeConfirmationTokenGenerationError(error);
                    } else {
                        console.log(confirmationToken);
                        stripeConfirmationTokenGeneration(confirmationToken);
                    }
                });
            }, 1000);
#

mounting the element:

elements = window.elements;
    if (!window.paymentElement) {
        var paymentElement = elements.create('payment', {
            fields: {
                billingDetails: {
                    address: {
                        country: 'never',
                        postalCode: 'never'
                    }
                }
            }
        });
        window.paymentElement = paymentElement;
    }
    window.paymentElement.mount('#payment-element');
feral warren
#

Okie and on which line do you see the error?

#

The code looks a bit unusual

#

That you define elements and paymentElement as global variable in window

pliant siren
#

unusual as in !! ?

feral warren
#

Can't tell if it relates to your error yet. But on which line do you see the error?

pliant siren
#

NVM, got the issue. i was missing a character (not sure how) for the value of 'onBehalfOf' !

#

i was getting the error while loading the DOM only