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

How to open stripe-checkout programatically

Open wbgonz opened this issue 5 years ago • 1 comments

Hi, is there a way to programatically open the react-stripe-checkout dialog?

In My use case I have a subscription form for the user to enter his/her address and then register them through aws cognito so that later I can authenticate securely.

I perform error checking and data validation in the front end first then. When the user clicks the subscribe button I verify that cognito has successfully registered the user. Once the registration is successful I want to be able to open the stripe checkout dialog automatically so that the user has a smooth experience. If its not successful I do not want to open the dialogue.

If anyone could help I would be very grateful

Thank You.

wbgonz avatar Nov 12 '19 11:11 wbgonz

Yes, that should be possible. I'm not exactly an expert with this library, but here is what I did.

In my constructor I have

this.handler = StripeCheckout.configure({
      key: ..., 
      name: ...,
      token: token => {
        ...
      }
    });

Then I have a function I can call when I want to open the dialog:

  stripeCreditCardDialog = () => {
    this.handler.open({
      amount: ...,
    });
  }

bskinny129 avatar Nov 14 '19 00:11 bskinny129