#Simon1709
1 messages · Page 1 of 1 (latest)
Hello 👋
We should have an example here
https://stripe.com/docs/connect/collect-then-transfer-guide?platform=web&payment-ui=elements#accept-payment
we use the direct account method
If you're looking for docs on creating a direct charge then that's here
https://stripe.com/docs/connect/direct-charges
Ah!
jinx
This section goes over how to create a PaymentIntent and initialize Stripe.js
https://stripe.com/docs/connect/direct-charges#create-a-charge
i know how to do the backend side
i think
but its more the frontend
changing to the payment element
hmmm
the Stripe object is bound to the window right
in a react app the docs use the ElementsProvider
Ah you use react. In that case, you'd pass the connected account ID to loadStripe function
https://stripe.com/docs/connect/collect-then-transfer-guide?platform=web&payment-ui=elements#add-and-configure-the-elements-provider-to-your-payment-page
let me see if we have an example
yeah this is the bit that confusing me
where do i pass it in the connected account
id
currently the way i do it is wrong as i create all paymentMethods etc on the one account and copy them to the connected account when i charge
Ah found the guide
https://stripe.com/docs/connect/creating-a-payments-page?platform=web&ui=elements&destination-or-direct=direct-charges
This section has a React example of how to initialize Stripe.js
https://stripe.com/docs/connect/creating-a-payments-page?platform=web&ui=elements&destination-or-direct=direct-charges#add-stripe.js-and-elements-to-your-page
1 thing is they say to initialize it outside of a component
but then i need it inside to figure out my connected account id
as its dynamically loaded
here it says load it outside of the component
so it doesnt recreate the stripe object on every render
It doesn't, no.
my app doesnt know my connected account id at that point
basically on my site they have to choose different locations which inturn have different account ids
so i would have to put it inside the component
which would potentially cause it to be created multiple times
I see. In that case, you would want to initialize Stripe after the location is selected
Your component hierarchy would be different
what does your component hierarchy look like?
function Layout() {
const { selectedCenter } = useCenterContext();
let options = selectedCenter?.isPaymentConnected
? { stripeAccount: selectedCenter?.stripe_account_id }
: {};
const stripePromise = loadStripe(
import.meta.env.VITE_STRIPE_PUBLISHED_KEY,
options
);
so i have a layout component
<main className="main">
<Elements key={selectedCenter.id} stripe={stripePromise}>
<Outlet />
</Elements>
</main>
then i render out the elements
this is the site
so when you click manchester
it would then load the layout
and the center
the center then has the connected account
and all the other pages are in the outlet
How about instead of initializing elements on <Outlet> level, you initialize it just before loading the PaymentElement?