#prattprattpratt_error
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/1221933601474740315
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Maybe I should say "I assume submitting a payment via the card/address elements throws this error because express checkout is in the elements instance."
Although the error only occurs if I'm in a browser that doesn't have any available payment methods (e.g., Google Pay, Apple Pay), so maybe not ๐ค the express checkout element is in there either way
Hi there, sorry for the delay!
No stress!
I'm pretty sure you'll need to unmount the element that's not being used in your confirm call
How do I unmount an element that I am rendering with React Stripe.js? i.e., I don't have an instance of the element floating around that I can .unmount like I'm assuming I would have if I was just using stripe JS. I'm just rendering <ExpressCheckout />
I couldn't find anything in the React Stripe.js docs, just the Unmount an Element section in the normal Stripe JS docs.
Give me a few minutes, I'll need to loop in a teammate who's more experiened with React
Sounds good, thanks
Hello! Can you share the code that's throwing this error?
Also, can you confirm you're using the Card Element and not the Payment Element?
I think you mean the Payment Element, as the Card Element is legacy and won't work with stripe.confirmSetup, but want to be sure.
I do mean the Card Element
It seems to be going through as long as I'm in a browser that has an available payment method in the express checkout element ๐ค
That's very unusual. Why are you using the Card Element instead of the Payment Element?
The Payment Element is too opinionated from a design perspective. I needed something more bare bones to match the designs I was given.
Is there a different element to collect card info that has less Stripe UI?
Using the Card Element + the Address Element isn't a supported configuration and likely won't work as expected. I stronly recommend you switch to the Payment Element if possible.
No.
The Appearance API lets you radically alter the visual appearance of the Payment Element though: https://docs.stripe.com/elements/appearance-api
Thanks for the info!
It wouldn't surprise me if the unexpected behavior you're seeing is due to some unusual interaction with the Card Element. I recommend you replace it with the Payment Element and try again. Make sure you use this approach, which is the one that's compatible with the Express Checkout Element: https://docs.stripe.com/payments/accept-a-payment-deferred?platform=web&type=setup&client=react
Can I just use the Card element and not the Address element? Or is the Card element obsolete?
The Card Element is legacy and is not recommended. It still works standalone, but you should use the Payment Element when building a new integration.
If you do use the Card Element you can add your own fields for address info and pass that info in when you call the various Stripe.js APIs to confirm an Intent.
Ok. Any thoughts on the initial question of the possibility of unmounting specific elements that aren't being used?
You shouldn't have to unmount them, it should just work, but I've never tried it with the Card Element in the mix like that.
What options are you passing to the Elements instance?
To answer your question directly, you should be able to call .unmount() on the Element you want to unmount: https://docs.stripe.com/js/element/other_methods/unmount
How do I access the element in React to .unmount it? I understand that it shouldn't be necessary so it doesn't sound like something I will pursue.
{
mode: 'setup',
currency: 'usd',
paymentMethodTypes: ['card'],
appearance: {
theme: 'stripe',
variables: {
borderRadius: '8px',
colorDanger: colors.red[70],
colorIconCardError: colors.red[70],
colorIconCardCvcError: colors.red[70],
colorText: colors.gray[90],
colorTextPlaceholder: colors.gray[60],
fontLineHeight: '24px',
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSmooth: 'always',
fontSizeBase: isMobile ? '16px' : '18px',
},
rules: {
'.Input': {
boxShadow: 'none',
},
},
},
}
}
And the error happens if you never interact with the Express Checkout Element?
Oh, wait.
I know what's happening.
The error happens if I submit a payment using my Card + Address element setup only if I am in a browser that doesn't return any available payment methods in the express checkout onReady
stripe.confirmSetup() is only designed to work with newer Elements, like the Express Checkout Element and Payment Element. Normally when you have both a Payment Element and Express Checkout Element stripe.confirmSetup() will use whichever of those has payment info it in, basically. However, you're using the Card Element, which stripe.confirmSetup() is not compatible with, so it can't "see" the Card Element at all. It only sees the Express Checkout Element, thinks it's the only way to possibly pay, and thus throws an error because you're not using it correctly for Express Checkout Element.
You would need to use stripe.confirmCardPayment() with the Card Element, which is the legacy method that works with that legacy Element: https://docs.stripe.com/js/payment_intents/confirm_card_payment
You can specify the specific Card Element instance when you call that: https://docs.stripe.com/js/payment_intents/confirm_card_payment#stripe_confirm_card_payment-with_element-payment_method-card
If you stick with the Card Element (which, again, I do not recommend) you should still use stripe.confirmSetup for the Express Checkout Element.
Makes sense. I just confirmed that I don't get the error when I'm in a browser with ExpressCheckout available payment methods because it's just always using ExpressCheckout ๐คฆโโ๏ธ looks like I have my smoking gun (the Card element)
Yep. You can make it work with the Card Element, I think, but the code will be more complex, it will be prone to unusual gotchas because it's not a recommended configuration, and will be more likely to break because you're mixing legacy and modern approaches in a single implementation.
Last question, if I do a dual setup with Payment+Address (or just Payment) and ExpressCheckout, how do I specify which element is being used in confirmSetup? Or should it know not to use ExpressCheckout if the other has user input?
It should just know and work without you doing anything special.
Great, thanks. Appreciate all the help!