#meet_code
1 messages ¡ Page 1 of 1 (latest)
đ 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.
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.
- meet_code, 6 hours ago, 26 messages
Hi there, looks like the initialization may have some issue. Can you share your whole code?
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();
});
Yeah and what options that you are passing in?
allow: 'payment *',
mode: 'payment',
amount: 1099,
currency: 'usd',
paymentMethodCreation: 'manual',
setupFutureUsage: 'off_session',
onBehalfOf: 'test',
appearance: appearance,
};
Okie, can you share the full file?
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');
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
unusual as in !! ?
Can't tell if it relates to your error yet. But on which line do you see the error?