react-stripe-elements icon indicating copy to clipboard operation
react-stripe-elements copied to clipboard

With Payment Intent API, Payment Request Button cannot sit with CardElement in the same Element

Open dimileeh opened this issue 7 years ago • 7 comments

Feature request or idea? Consider opening an API review!

Summary

Imagine we want a form with the Payment Request Button and a CardElement - to offer users a choice of how to pay. we start building this form with React and Stripe Elements.

  1. We put these two elements in the single Element (because it's not possible to have two Elements on the same page as I understand).
  2. Now, when a user pays with a 3D secure card using the Payment Request Button, we first send the token to confirmPaymentIntent from which we get a payment intent with the status "requires_action".
  3. We take this payment method and we send it to handleCardPayment.
  4. However, since we have the CardElement in the same Element, handleCardPayment either attempts to read the data from the CardElement (which will be empty), or, if we provide payment method to handleCardPayment, it'll complain that we can't feed it with a payment method when it sees CardElement on the same page.

A workaround is to hide the CardElement if the payment intent comes with a 3D secure auth request. But that looks like a bug to me. Or am I missing something?

dimileeh avatar Jun 23 '19 23:06 dimileeh

Hi @dlihhats

That does indeed sound like a bug, thanks for reporting!

We'll investigate and keep you updated.

Just to clarify, when you say "in the same Element", you mean as descendants of the same <Elements> node, right?

If you happen to have a link to an example were we can reproduce this behavior, that would be helpful as well.

cweiss-stripe avatar Jun 25 '19 13:06 cweiss-stripe

Hi @dlihhats

I was able to reproduce your issue.

it's not possible to have two Elements on the same page as I understand

It actually is possible to do that and it sound like a reasonable workaround to wrap the Payment Request Button and the CardForm in their own separate <Elements> components.

We will fix this issue and release a new version of react-stripe-elements.

cweiss-stripe avatar Jun 28 '19 10:06 cweiss-stripe

Hi @cweiss-stripe! Thank you for looking into this problem, and sorry that I didn't come back sooner.

When I mentioned that per my understanding it was impossible to put two <Elements> containers on the same page, I was thinking of an error that React threw out saying something like "violated single child check".

(I'm just getting started with React, so can't remember exactly, sorry).

But anyway, when you say you'll fix this issue, will we need to wrap Payment Request Button and CardForm into individual <Elements (perhaps with the different key property?), or will they be able to sit within the same <Elements>?

And yes, sorry for the typo in the original post. I meant as you said: "descendants of the same <Elements>".

dimileeh avatar Jun 28 '19 21:06 dimileeh

Hi @dlihhats

Our plan is to fix this. Using two separate <Elements> containers should not be required. That said, this work-around should work for now. Please let me know if you are still seeing issues with the two <Elements> containers approach.

dweedon-stripe avatar Jul 02 '19 17:07 dweedon-stripe

Any news on this? I have the same problem because I need to put a PaymentRequestButton and a CardElement inside the same Elements wrapper. In my case I cannot use two different Elements.

ramiel avatar Sep 12 '19 10:09 ramiel

Hey issue watchers, no news on this yet but we are working to make it much easier to get at the underlying Stripe and Elements instance. Tagging this issue so that we can follow up when it's resolved.

fred-stripe avatar Oct 09 '19 19:10 fred-stripe

Closing this as this project has migrated to React Stripe.js. If you believe this is still important, please re-open it there.

sashko-stripe avatar Mar 26 '21 18:03 sashko-stripe