#ShakeR
1 messages · Page 1 of 1 (latest)
Hello! Can you share the code that's producing that error?
stripe.confirmPayment({
elements,
confirmParams: {
// Return URL where the customer should be redirected after the PaymentIntent is confirmed.
return_url: '<?= BASE_URL ?>/checkout-complete',
},
})
.then(function(result) {
if (result.error) {
// Inform the customer that there was an error.
document.getElementById('stripe_err_dom').style.display = 'block';
document.getElementById('stripe_err_msg').innerText = result.error;
}
});```
Direct from your docs here: https://stripe.com/docs/js/payment_intents/confirm_payment
My guess is elements isn't an object. If you log out elements just before that code what do you see?
Hm, that's not it. What does return_url: '<?= BASE_URL ?>/checkout-complete', turn into?
A full URL string
It's valid? Doesn't contain any ' characters or anything?
Same result using this:
You're sure this is the code being run? If you add a breakpoint in the browser do you see anything amiss?
100% The log posted above is right above this block.
I'll drop a log inside the function to be sure
Bah, nvm can't
Do the line numbers match up? Like on the error, it should point you to a specific line, is it pointing you to this code?
The line is inside Stripe's JS
That onClick seems to be pointing to line 1... is the code minified?
It's Stripe's code, yes
Gotcha. Stand by
Where should the stripe.confirmPayment() function live relative to initialize()?
Has to be inside right?
Which initialize() are you referring to?
Oh, I think I understand the issue now. stripe.confirmPayment should be hooked up to your buy button. It should run after someone has filled out the Payment Element and they're ready to pay.
Yeah. Dawning as well...
You're running it immediately after mounting the Payment Element, so it's not fully initialized yet and there's no chance to enter payment info.
How to keep elements inside scope of confirmpayment? It's undefined outside of initialize.
This seems like an opportunity for us to improve that error message. 😅
Nah, it's mostly me sucking at JS. Biggest help would be more than just a bare snippet in the docs.
The initialize() part is your own code, not Stripe's. You can handle that however you want.
We have a guide here: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements
And a quickstart here: https://stripe.com/docs/payments/quickstart
Gotcha. I caught that a few months ago and forgot about it. Always fighting b/w the "Docs" portion of your support and the "API". Thanks for your help. Should have it from here.