#RSS1N2-Element
1 messages · Page 1 of 1 (latest)
My web site allows users to create tournaments. Then the public signs up for those tournaments and pays the creator. A small fee goes to me. So depending on which tournament the end user chooses, the connected account that the funds flow to also changes.
Okie, so which API are you using? Destination Charges with Elements?
Yes, I think so.
Can you give an example code, how are you setting that stripe prop?
I have a feeling that's Direct Charge rather than Destination Charge
When the payment dialog is rendered I do this:useEffect(() => {
if (!initializedStripe) {
console.log("Initializing Stripe for EasyPayment!")
setStripePromise(loadStripe("pk_test_51****", {stripeAccount: 'acct_1IqNF****'}))
setInitializedStripe(true)
}
setStripePromise uses React context to get the promise out to the Elements Wrapper that encompasses all my components for the app.
The idea here is that stripeAccount can be different everytime this component is used. Hence, setStripePromise can be called with different values.
Note: Values are hard coded for testing purposes
Thoughts?
Stripe React Js, correct? https://github.com/stripe/react-stripe-js
Yes: import { CardElement, useElements, useStripe } from "@stripe/react-stripe-js"
You are right. you would need to know the Stripe Account before going into this page. I think the best part forward is trying to capture which tournament Connected Account before going to this page, then based on that initialize the Stripe element. Sorry for the inconvenience
THat's easy enough, but I have a feeling the issue will persist as long as I'm setting the promise while in a child of that Elements component and its stripe prop that it's complaining about. The older docs reference a StripeProvider that looks like it solves this issue by allowing the app to manage the stripe prop directly. But it doesn't appear to be supported anymore. Can you shed some light on how the stripe prop is supposed to be set dynamically in scenarios like this?
Could you elaborate on that old Stripe Provider? I will try to find information around that change
Here is some usage I found:
<StripeProvider
apiKey={process.env.REACT_APP_API_STRIPE_PUBLISH}
stripeAccount={this.state.userEvent.organiser.stripeAccountID}
>
<Elements>
<CheckoutForm/>
</Elements>
</StripeProvider>
I see, pretty much it's here https://github.com/stripe/react-stripe-js/blob/master/docs/migrating.md#2-remove-stripeprovider
I think you only can recreate the promise each time...
Yes, so it was replaced with Elements containing the stripe Promise as a prop. But that's the one you can only set once.
I am sorry I don't have a better offer. It has been this way from when the change happened
Good news. I just got it working. The trick was to not fight the client API, and just initialize the Promise once on the client. Then on the server you clone the PaymentMethod that was created with the client's Promise to the connected account. Thanks for hanging in there with me. These are complicated issues that I'm sure you guys can't always get resolution on. But it's awesome to have access to someone to talk to in real-time.