#ShakeR

1 messages · Page 1 of 1 (latest)

pulsar quiverBOT
steep epoch
#

Hello! Can you share the code that's producing that error?

hidden pollen
#
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;
      }
   });```
steep epoch
#

My guess is elements isn't an object. If you log out elements just before that code what do you see?

hidden pollen
#

const elements = stripe.elements({ clientSecret, appearance });

steep epoch
#

Hm, that's not it. What does return_url: '<?= BASE_URL ?>/checkout-complete', turn into?

hidden pollen
#

A full URL string

steep epoch
#

It's valid? Doesn't contain any ' characters or anything?

hidden pollen
#

Same result using this:

steep epoch
#

You're sure this is the code being run? If you add a breakpoint in the browser do you see anything amiss?

hidden pollen
#

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

steep epoch
#

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?

hidden pollen
#

The line is inside Stripe's JS

steep epoch
#

That onClick seems to be pointing to line 1... is the code minified?

hidden pollen
#

It's Stripe's code, yes

steep epoch
#

The onClick is in your code.

#

The last line of that trace.

hidden pollen
#

Gotcha. Stand by

#

Where should the stripe.confirmPayment() function live relative to initialize()?

#

Has to be inside right?

steep epoch
#

Which initialize() are you referring to?

hidden pollen
steep epoch
#

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.

hidden pollen
#

Yeah. Dawning as well...

steep epoch
#

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.

hidden pollen
#

How to keep elements inside scope of confirmpayment? It's undefined outside of initialize.

steep epoch
#

This seems like an opportunity for us to improve that error message. 😅

hidden pollen
#

Nah, it's mostly me sucking at JS. Biggest help would be more than just a bare snippet in the docs.

steep epoch
#

The initialize() part is your own code, not Stripe's. You can handle that however you want.

hidden pollen
#

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.