#Louis Daubié
1 messages · Page 1 of 1 (latest)
Hi! Let me help you with this.
I am using nodejs for the server side and react js for the front side
For now i can start a payment intent on server but when i want to confirm on the front-end i got this error
Right know this is the flow i try
Start to load stripe platform instance on front end
Use the card element for generate au token, send a payment request to my api
On the api i create the customer with the token if is not exist and create a paymentIntent on the stripe connected account i whant
with the customer and the payment method,
send back to the front end the client secret
then when i try. to use stripe.confirmCardPayment(client_secret) i got the error above
I can share some part of the code if it's can help you
It looks like you are confirming the payment on a different account. PaymentIntents and Customers can only live on one account, be it a Platform or a Connected account.
Are you trying to do a Direct or Destination payment?
i trying to do a direct payment
Yes it is why i think, a make a payment intent for a connected account but on my front end is platforme instance
but i have to share my customer between several stripe connect account
You need to use Stripe-Account header on the frontend as well
Yes but when i use stipeAccount header on the frontend when i try to create the customer with the token, i got an error who tell me the payment method does not exist
So should i use 2 stripe instance ? one for creating and register the card on platform customer ? then duplicate to connect account, create the paymentIntent and use the 2nd stripe insntance for confirm it ?
What do you mean by "stripe instance"?
stripe(stripeCredentials.api_key, {
stripeAccount: stripeCredentials.stripeAccount,
});
stripe(stripeCredentials.api_key,);
on server side
const res = await loadStripe(STRIPE_KEY);
on front side
You only need to use one account. The Platform account can control the Connected accounts
So you also need to use stripeAccount header on the backend when you create the PaymentIntent
Yes i can already create the paymentIntent on the stripe connect
with this
await Stripe.paymentIntents.create(data, {
accountId: XXXXX
}),
Are you sure then you use the same Connected account ID on the backend and frontend? acct_xxx
when i do this await stripe.confirmCardPayment(response?.data?.paymentResponse.message.client_secret);
i got some error 'payment intent not found'
i can send account information on this request ?
Please send the PaymentIntent ID pi_xxx
pi_3MI8fMR2pTkOCvq61X7scGQc
Hello 👋
Stepping in as vanya needs to step away soon
Hello
Seems like you're creating direct charges yes?
yes !
Gotcha so in that case, Your server creates a PaymentIntent directly on the connected account using Platform's secret key and Stripe-Account header.
https://stripe.com/docs/connect/authentication#stripe-account-header
In your client-side code, you seem to be initialising Stripe.js with Platform account's publishable key. What you need is what you shared above, Initialise Stripe.js with a Stripe-Account header as well (pointing to the connected account ID that owns the PaymentIntent) as shown in our docs here
https://stripe.com/docs/connect/authentication#adding-the-connected-account-id-to-a-client-side-application
const stripePromise = loadStripe('{{PLATFORM_PUBLISHABLE_KEY}}', {
stripeAccount: '{{CONNECTED_STRIPE_ACCOUNT_ID}}',
});
No i can not do this
because when a try it and whant to create customer
i got an error 'the token doesn't exist'
because i register the customer on platform accbnt
then i clone it into connected account before start initialize payment
i need this because i have to share customer accorss several stripe connect account
I understand, but if you're cloning the customer already (before creating the PaymentIntent) then you shouldn't get the token doesn't exist error. You might be doing something wrong in the flow.
Are you referring to this guide here?
https://stripe.com/docs/connect/cloning-customers-across-accounts
yes
but i can not cloning the customer if i use the stripe connect acocunt
because when i want to get the token
i got an error
'customer should have payment method'
So your customer doesn't have a stored payment method on the platform account?
Hold on, let's take a step back
the guide you're using assumes that you have a payment method stored for the customer on the platform account.
It allows you to re-use the customer
across different connected accounts along with their payment methods
So first you'd want to attach a payment method on the customer on your platform account and then try and clone them. Otherwise, let's say you got the flow working here but even then your payment method would only be stored on the connected account & won't be sharable with the platform (as well as other connected accounts)
does that make sense?
actualy i can created customer on attach payment method in the same flow of strating payementItent
my customer i created on platforme with is paymentMethod
i can get the token on clone in accounnt
So here's what your flow would look like
1/ Create a customer on your platform account
2/ Collect a PaymentMethod and attach it to the customer (on the platform account)
3/ Create a customer on your connected account (cloned customer)
4/ Clone the Payment Method across
https://stripe.com/docs/payments/payment-methods/connect#cloning-payment-methods
and i can start paymentIntent froms erver
The guide you're following currently is for when your platform uses our old Sources API
Use the link above for instructions related to PaymentMethods API
the only thing who make trouble is when i whant to confirm payment
You can't confirm a PaymentIntent owned by a connected account just by using Platform's publishable key.
The code needs to know which account owns the PaymentIntent
We can not juste add the stripeAccountId on the confirmCardPayment ?
because i need platforme account for create customer and payment method, if i use connect instance, i could not retrieve the payement method, so i can not create customer and share it
no that's not how it works. Stripe.js when initialised takes the Stripe-Account parameter.
If you build two instances of Stripe, you'll see unexpected behaivors with payments.
when i initialised stripe on the server side, i don't need to give an stripe account id
i can add it when i make the paymentIntent
Yes server-side and client-side libraries are different and function differently.
I don't understand, how can i create customer on platform if i using connected account on front end...
Customer creation API requires your secret-key which should only be used by your server-side code
So your server will create a customer
not your client-side code
yes expect the paymentMethod created is on the connected account, not platforme
so i can not create my customer
because i got this errror 'payment method not found'
as i am on the platforme account on the backend
You said your customer on the platform account has a PaymentMethod already
and connected on front ent
not i created all when the customer try to paid and click on 'save my card'
so before the first paiement, customer and payment method not exist if i don't create it
if i do this : const { error, token } = await stripe.createToken(cardElement);
with connected instance and send it on back end
when i do this const stripeCustomer = await Stripe.customers.create({
description: Client ${customer_id},
email: customerResponse[0].email,
name: ${customerResponse[0].firstname} ${customerResponse[0].lastname},
source: token.id
});
i got an error
because the payment method is on the connect account not on platform..
I'm sorry I don't understand what flow you want to build here.
In order to share the PaymentMethod information across connected accounts, the details need to exist on the Platform already.
You can't create this information on the connected account and send it upwards to the platform account.
If you want to "clone" the customer and re-use payment methods then you need to change your flow to first create PaymentMethods on the platform account and then clone it across.
You can use SetupIntents API to store customer's payment method information on Platform account
https://stripe.com/docs/payments/save-and-reuse
and then clone it across
https://stripe.com/docs/payments/payment-methods/connect#cloning-payment-methods
We don't support saving a card on the Platform account while paying a charge created by connected account
ok thanks you
NP! 🙂 Sorry for all the back and forth
no problem have a good end of the year
You too! Good Luck and Happy Holidays 🎉
thanks