thoughtbot / fake_stripe

A Stripe fake so that you can avoid hitting Stripe servers in tests.
MIT License
401 stars 78 forks source link

react-stripe-js is unable to create individual elements #115

Closed mpmenne closed 1 month ago

mpmenne commented 4 years ago

So we're using the react-stripe-js to render Stripe elements on the page. When we render the Stripe elements using the JavaScript returned by the STRIPE_JS_HOST/v3/, it renders every component each time we call create. Please check out the example below.

Here is a code example.

    this.stripe = Stripe(stripeApiKey);
    const elements = this.stripe.elements();

    this.cardNumber = elements.create('cardNumber', {
      placeholder: this.cardTarget.dataset.placeholder,
      style: this.style,
    });
    this.cardExpiry = elements.create('cardExpiry', {
      placeholder: this.dateTarget.dataset.placeholder,
      style: this.style,
    });
    this.cardCvc = elements.create('cardCvc', {
      placeholder: this.cvcTarget.dataset.placeholder,
      style: this.style,
    });
    this.postalCode = elements.create('postalCode', {
      placeholder: this.postalCodeTarget.dataset.placeholder,
      style: this.style,
    });

Expected Result

Screen Shot 2020-04-14 at 4 58 57 PM

Actual Result

Screen Shot 2020-04-14 at 4 58 46 PM

It looks like we have the parameters, we just need to dynamically render the correct fields: https://github.com/thoughtbot/fake_stripe/blob/master/lib/fake_stripe/assets/v3.js#L24

Happy to submit a PR if other people are seeing this issue as well.

mpmenne commented 4 years ago

Submitted PR #116 to address this issue. Please take a look and let me know if you have any feedback!

stefannibrasil commented 1 month ago

Closing this because fake_stripe has been deprecated: https://github.com/thoughtbot/fake_stripe/pull/154