#jasontheadams - Elements

1 messages ยท Page 1 of 1 (latest)

worldly tusk
#

Hello! You still around?

#

Can you share the code you're using that leads to the empty object issue?

glass needle
#

Hi! Here you go!

#
        try {
            const {error} = await stripeElement.confirmPayment({
                elements: this.elements,
                confirmParams: {
                    return_url: 'http://givewp.local',
                },
            });

            console.log({error});
        } catch (error) {
            console.log({error});
        }
#
                const elementWrap = document.querySelector(element[1]);
                const options = {
                    clientSecret: elementWrap.dataset.stripeClientSecret,
                };
                this.elements = stripe.elements(options);
                paymentElement.push(this.elements.create('payment'));
worldly tusk
#

Ah, was just about to ask for that code as well. ๐Ÿ™‚

glass needle
#

The fields are showing up just fine. This happens after filling them out and attempting to run stripe.confirmPayment()

worldly tusk
#

If you change this line:

const {error} = await stripeElement.confirmPayment({

To this:

const result = await stripeElement.confirmPayment({

And then log the result does that provide more information?

glass needle
#

I'm afraid not. Stripe.js is doing throw Error somewhere internally, so if I don't wrap it in a try...catch it just fails.

#

Hmm... what version of @stripe/stripe-js is required for this to work?

worldly tusk
#

The version of that package shouldn't matter as the latest version of Stripe.js is always loaded regardless.

glass needle
#

Ah, ok.

worldly tusk
#

Are you sure the publishable key you're using matches the account of the Payment Intent and context?

#

Do you mind sharing the publishable key?

#

Also, just to confirm, the redirect doesn't happen, right?

glass needle
#

Correct, no redirect. Just a console error. Let me track down the publishable key..

#

I believe this is being used:
pk_test_51HAi7MIqONfMPfffm7aqctG4tU9dumWShQ5GzniuKDO749fITyyPCWOiilgaGSCpj80VeGoPyU5AMrkY4LFYVL1500wEdXqr0J

worldly tusk
#

That looks like the correct one.

#

Does the error in the console provide a stack trace or any additional details?

glass needle
#

Nope, it's quite empty.

worldly tusk
#

Cool cool cool. Any activity in the network tab of the dev tools when this happens?

glass needle
#

Ohhhh good question

#

Negative.

worldly tusk
#

Okay, so it's not even getting that far... ๐Ÿค”

#

Let me see if I can reproduce on my end if it's okay with you? I might end up confirming that Payment Intent, is that okay?

glass needle
#

No problem! I'm going to try removing the try...catch and look at where the Error is being thrown in the stripe code to see if that gives any clues.

#

Nope, I'm not getting any further information. It only tells me that the error occurred in an unresolved promise.

worldly tusk
#

Okay, well, I can't reproduce and successfully confirmed on my first try. Let me share the code that worked...

#
      const stripe = Stripe('pk_test_51HAi7MIqONfMPfffm7aqctG4tU9dumWShQ5GzniuKDO749fITyyPCWOiilgaGSCpj80VeGoPyU5AMrkY4LFYVL1500wEdXqr0J');
      
      const elements = stripe.elements({
        clientSecret: 'pi_3KCBmlIqONfMPfff29EXLJfl_secret_<REDACTED>',
      });
      
      const paymentElement = elements.create('payment');
      
      paymentElement.mount("#payment-element");
      
      // Pay Button
      const payButton = document.querySelector('#payButton');
      
      payButton.addEventListener('click', async (event) => {
        outputElement.innerHTML = 'Processing...';
        
        const {error} = await stripe.confirmPayment({
          elements: elements,
          confirmParams: {
            return_url: "https://<REDACTED>/payment-element/discord-test.php?showPaymentResult",
          }
        });
#

I used the 4242 test card and it confirmed no problem.

#

What method of payment have you been using? Maybe spin up another Payment Element and see if the 4242 test card works if you haven't tried that one already?

#

Someone else on my team noticed this thread and mentioned they ran into the same situation with someone who was initializing multiple instances of Stripe.js and using different instances to mount the Payment Element and call stripe.confirmPayment. Could that be happening?

glass needle
#

That is entirely possible. I mean this in the best possible way, but our old Stripe code is a mess. ๐Ÿ˜ฌ

#

I'll try just bypassing much of our code and doing it manually.

#

(And I'm using 4242 as well. Classic.)

worldly tusk
glass needle
#

Oh snap! Tell your buddy thanks! That was it. Apparently our code is spinning up multiple instances of Stripe.js. When I forcefully limited to one it worked. ๐ŸŽ‰

worldly tusk
#

Nice!

glass needle
#

Thanks for your help! I'm not sure how long it would've take me to figure that out.

worldly tusk
#

Same, honestly! That's a tricky one!

#

I let them know and told them thank you. ๐Ÿ™‚

glass needle
#

Seems like we're doing something seriously un-kosher as stripe.js doesn't even throw a meaningful error. Not sure if that should be passed along to the stripe.js team?

Anyway, you all are great. Hope you have a wonderful rest of your holiday season!