-
Notifications
You must be signed in to change notification settings - Fork 319
Redux Form #55
Comments
Hi there! How are you setting up your component tree? Is there a wrapping component before your Stripe-injected component? |
Thank you for your help. deposit.js
deposit_element.js
|
I also get this error on the server side. |
@hurano I'm not sure what's going on with the Redux issue but I am curious to see what turns up! |
It seems like there are some issue with connect not Redux form. I think its because of too much rendering. If I remove connect, there is no error on frontend and backend. Thanks. |
@hurano how do you actually map the elements states to props? |
I was able to dig in further, and I finally have a page that reproduces the error! So—progress. What seems to be happening is that both the Redux HOC and the Stripe HOC want to configure things in the React context for the component, however, whichever component is the outermost "wins". For example, if you do this:
The Stripe context (which keeps track of the elements) will be available in the wrapped version of If instead you do this:
The Redux context (which is used to pass the Redux store into connect()d components) will be used instead. If Redux's context is the "outer" HOC, then the Stripe-created HOC will lose track of the There doesn't seem to be any merging of the wrapped component's I'm not sure what the solution is here, but now we know what's happening and how to reproduce. I'll continue research on this end, as I'm not sure if it's a Stripe bug, a Redux bug, or a bug with how React contexts + HOC work (there are some issues on the React repo that suggest this may be the case). [1] https://facebook.github.io/react/docs/context.html#how-to-use-context |
Interesting, this could indeed be the issue I was having with |
I added an explanation for this issue to the readme: Please let me know if the suggested solutions do not solve your problems. |
Hi @cweiss-stripe, @fred-stripe I have a CardAdd component that is a simple form with just one element:
I have a CardList component that basically mounts the CardAdd component as a collapsible component.
My App Component where i attach the provider:
On filling the values and submitting it (using the a sample value gives me the error mentioned above). Version : 1.4.1, |
The possible solutions in the Troubleshooting section did not work for me. Instead, I instantiated my stripe provider inside my connected component and used all my stripe stuff outside of redux (so my onSubmit is defined in my React component though I dispatch things from there to update my store after getting my token). |
Very disappointed with Stripe's implementation of their React library. I have to refactor a lot of code to make this work with my pre-existing app. Ideally I would have liked to import one line of JSX and be done with it. Why is there so much boilerplate code for no apparent reason? |
@saurishkar it looks like you aren't using the That said, the error message should have been clearer here and tell you that you should be using an Element. We'll work on fixing that! @siakaramalegos sorry to hear that! Do you have a reproduction or sample code to show why the troubleshooting section didn't work? It would also be helpful to know the versions of React, Redux, react-redux, and react-stripe-elements you're using. @viktorbakari sorry that using the library has proven frustrating. Can you share what you hope your ideal API might look like ("one line of JSX" as you mention)? The boilerplate might seem like too much, but in many ways is necessary.
We're always open to feedback on simplifying the interface, so would love to hear about what is frustrating or confusing, and how we can improve things. |
@atty-stripe See my comment for the solution that worked for me. |
@siakaramalegos do you have an example of your code anywhere? I've been having the same trouble and have my redux form with my stripe injected form inside of it. I can't figure out how to connect the two. |
@chagoy it has been a while, and the repo is private, but I think this is the basic gist - act like you're not using Redux: Checkout Container class CheckoutContainer extends Component {
render() {
const fonts = [{ cssSrc: "https://fonts.googleapis.com/css?family=Podkova:400" }]
return (
<StripeProvider apiKey={stripePubkey}>
<Elements fonts={fonts}>
<Checkout {...this.props} />
</Elements>
</StripeProvider>
)
}
}
const mapStateToProps = (state) => {
// state to props things not related to the stripe element itself
}
const mapDispatchToProps = (dispatch) => {
// dispatch to props things not related to the stripe element itself
}
export default connect(mapStateToProps, mapDispatchToProps)(CheckoutContainer) And then checkout itself: import {injectStripe} from 'react-stripe-elements';
class Checkout extends Component {
onSubmit = (e) => {
e.preventDefault()
// Delete all previous errors and invalid states
this.props.clearErrors()
const { stripe, hold } = this.props
const { gross, hold_id } = hold
const form = e.target
const data = validate.collectFormValues(form)
const { first_name, last_name } = data
const requestData = {
first_name,
last_name,
hold_id,
expecting_to_pay: gross,
}
// Disable payment button
this.props.requestBooking()
// Get stripe token if payment needed
if (gross > 0) {
stripe.createToken({ name: data.card_name })
.then(({ token, error }) => {
if (error) {
this.props.receiveErrors({card: error.message})
return
}
requestData.stripe_token = token.id
this.props.createBooking(requestData, form)
})
} else {
this.props.createBooking(requestData, form)
}
}
render() {
const {
errors,
hold,
isLoading,
requestingBooking,
} = this.props;
return (
<div>
<h2>Payment</h2>
<form id="payment-form" onSubmit={this.onSubmit}>
<Input
name="first_name"
placeholder="Your first name"
required
errors={errors.first_name} />
<Input
name="last_name"
placeholder="Your last name"
required
errors={errors.last_name} />
<CreditCardGroup
total={hold.gross}
errors={errors} />
<PayButton
isLoading={isLoading}
total={hold.gross}
requestingBooking={requestingBooking} />
</form>
</div>
)
}
}
export default injectStripe(BookingCheckout) |
Has anyone actually managed to set this up with redux-form yet? I have struggled with this for the better part of a week. An official example using redux-form would be very appreciated. |
Hey
I got it to work. Let’s see if this makes sense. Here is my component structure
<MainFormComponent> // in componentDidMount you’ll set the stripe key as it’s done on the docs. Also, write an onSubmit function that will be called on form submission, however form will submit on the InjectedCheckoutForm, not from here.
<StripeProvider> // pass it a prop called stripe which is equal to your stripe key.
<Elements>
<form>
<InjectedCheckoutForm> In this component is where you create a token and make your post to your stripe endpoint. -> also, make sure at the bottom you are doing `export default injectStripe(InjectedCheckoutForm)` // <CardElement/> goes inside of here as well.
</form>
</Elements>
</StripeProvider>
</MainFormComponent>
At the bottom you gotta define MainFormComponent = reduxForm({form: ‘name’, onSubmitSuccess: doSubmitSuccess}) and then export default connect(mapStateToProps)(MainFormComponent)
I hope this all makes sense. If not just message me and I’d be willing to walk through it with you.
… On Dec 6, 2018, at 9:32 AM, Chris Wright ***@***.***> wrote:
Has anyone actually managed to set this up with redux-form yet? I have struggled with this for the better part of a week.
An official example using redux-form would be very appreciated.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#55 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AQGzuArRKEshRorAf5BqA5qOT1wTR6m9ks5u2VSngaJpZM4OsFx7>.
|
^^^ The 'onSubmitSuccess' callback approach worked well. If you need to call redux actions from the callback, they are in the props argument passed into the callback. So basically, the redux form onSubmit handler is called first. If your validation passes, you will return the the submitted data in the return of the handler. Next, the 'onSubmitSuccess' callback is called. The submitted data is then sent as the first argument - the function signature is strip extra Billing Info fields to pass into createToken():
Callback example:
This is what my form container looks like:
So what chagoy said, just a few different words 😄
|
Were are you injecting the stripe? I tried following your example but I can't get the values of redux form into the |
Ok so unfortunately I don’t have an answer here. I have an idea of what’s going on, but that’s call I’ve got.
When I first set this up it actually freaked me out because I had the same though. How do I connect the dispatch action in redux on form submit and how do I send the info to stripe?
What I’ve found is that the original form gets injected with stripe and there is an additional checkout component which has the card element inside. The additional checkout component should also have your send button. If you have a button on the original form take it out.
I’m not sure how or why but if I click the submit inside the checkout component it will actually submit both components. My first form makes the query to my back end using `onSubmit(values) { return this.props.dispatch(register(values))}` meanwhile checkout does the onSubmit fetch to the stripe endpoint.
I think ideally the checkout component would receive the info from the original form component and do one query, but I could not get that to work.
… On Dec 18, 2018, at 9:18 AM, Agustina Chaer ***@***.***> wrote:
onSubmitSuccess: submitSuccess
Were are you injecting the stripe? I tried following your example but I can't get the values of redux form into the submitSuccess function
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#55 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AQGzuPjMtmJMe0-lEYIkNIAMOHdIVkNzks5u6SNggaJpZM4OsFx7>.
|
@aguscha333 sorry for delay - trying to get our Stripe integration out the door before next semester classes start! I will provide more of my code here... This first file is the parent component to the billing form component - See
Here is the ReduxForm class (with onSubmitSuccess registered with ReduxForm HOC)
|
I got this error message when I run this.props.stripe.createToken on redux form.
The text was updated successfully, but these errors were encountered: