Comments (5)
So I think I figured out why the above code doesn't work.
Tl;dr
If you want to use the injectStripe
HOC, you cannot do so on a component that renders <Elements>
directly. You must pull out the code that <Elements>
wraps into it's own component and use injectStripe
on that before nesting it within <Elements>
.
Details
This example works fine
class _CardForm extends React.Component {
render() {
return (
<form onSubmit={() => this.props.stripe.createToken().then(payload => console.log(payload))}>
<label>
Card details
<CardElement />
</label>
<button>Pay</button>
</form>
)
}
}
const CardForm = injectStripe(_CardForm)
class Checkout extends React.Component {
render() {
return (
<div className="Checkout">
<h1>Available Elements</h1>
<Elements>
<CardForm />
</Elements>
</div>
)
}
}
const App = () => {
return (
<StripeProvider apiKey="pk_RXwtgk4Z5VR82S94vtwmam6P8qMXQ">
<Checkout />
</StripeProvider>
)
}
ReactDOM.render(<App />, document.querySelector('.App'))
Notice that the only difference between this chunk of code and the code in the original issue description is that I've pulled out the wrapping <Elements>
code into a new component called <Checkout />
.
Unless I am missing something, it would appear that if you want to use injectStripe
, you cannot do so on a component that renders <Elements>
directly. You must pull out the code that <Elements>
wraps into it's own component.
I suppose this makes sense, since the component rendered within <Elements>
is injected with the stripe
prop at build time, before it actually knows that the code making use of stripe
is rendered within <Elements>
.
I'd be happy to submit a PR for it if this is something y'all would like more explicit documentation on.
from react-stripe-elements.
Awesome, I'm glad you figured it out :). That's exactly right. A PR for docs would be great!
from react-stripe-elements.
@indiesquidge
I've set up my checkout component form using react-stripe-elements' and my onsubmit handler is returning the stripe token. I'm just not sure what I'm supposed to do now?
- Does react-stripe-elements handle the API call for making the payment for me using my test API key?
- Or do I need to take the token and do the API call myself using the token that's returned?
from react-stripe-elements.
@rdalfonso once you get the token, you need to send it to your backend, which should call the Stripe API at /v1/charges. You can use one of our server side bindings to help you do this. More instructions in our docs here: https://stripe.com/docs/charges.
from react-stripe-elements.
@atty-stripe - I came to that same conclusion after re-re-reading the documentation. Thought I could make an API call from the browser. Problem is solved. Thanks!
from react-stripe-elements.
Related Issues (20)
- CardNumberElement Placeholder Not Working HOT 1
- CardCvcElement onComplete fires after three digits for AMEX card HOT 2
- docs: confirmCardPayment with split card elements needs a docs update HOT 1
- Payment Fields are not clickable in Samsung device HOT 2
- My Stripe promise with React never resolves even after trying a timeout HOT 1
- 3D Secure Test Payment Screen iFrame - Any way to preview or control width/height? HOT 1
- Not able to customize CSS of CardElement HOT 1
- Split Card Number Not Inserted with 1Password Autofill HOT 1
- Elements locale option not localizing HOT 5
- When click on stripe element its getting blur HOT 1
- About scan card feature in mobile device HOT 1
- PaymentRequestButton Does Not Load On Safari PWA HOT 1
- Stripe console message : parameter: betas is not a recognized parameter. HOT 2
- Connection Failure text in CardNumberElement HOT 3
- loadStripe does not seem to work
- styling CardElement HOT 1
- Add support for extra types of buttons for Apple Pay HOT 1
- Elements tag doesn't accept locale HOT 2
- Add a full stripe elements integration example HOT 1
- PaymentRequestButtonElement Integration Error with saved browser card HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-stripe-elements.