#benkass-customer-node
1 messages ยท Page 1 of 1 (latest)
Let me share some code
try {
const newCustomer = await stripe.customers.create({ name, description: uid })
const variables = {
customer: newCustomer.id,
amount,
receipt_email,
description,
funding_source
} as any
if(connected_account_id){
variables.connected_account_id = connected_account_id;
}
const paymentMethod = await this.createPaymentMethod(variables);
console.log("Fetched new paymentMethod", paymentMethod)
return paymentMethod;
} catch (error) {
console.log("Error 1", error.message)
throw new GraphQLError(error.message);
}
When this is running, the log shows:
> Created new customer cus_Ofti1Ac6MSleVP
> Error 1 No such customer: 'cus_Ofti1Ac6MSleVP'
those logs are pretty cryptic and I don't understand which part is Stripe code and which part is your own code.
const newCustomer = await stripe.customers.create({ name, description: uid })``` like this creates a Customer.
What is that `documentRef.update`?
also you seem to menion Connect in the middle but I don't really get your code at all right now, and what is variables and such
but if you create the Customer on the platform and then try to update/change it on another account it would never work
Yes, that part creates a customer.
Then documentRef.update is graphQL updating the user record
Some users will be merchants who would have a stripe connect account
Not sure what you mean here
so what's the problem? GraphQL is purely your own internal API. I don't really understand your abstraction and which exact part of the code is failing. Can you remove everything that isn't Stripe and explain exactly what part is failing?
Updated above. I have two things I do with stripe here. 1. create a customer, and 2, create a payment method for the customer
I'm really sorry I'm still really confused by the whole code
However,the log shows that it first created the customer, but then I get an error (I believe thrown by createPaymentMethod) that says there is no such customer
You have const newCustomer = await stripe.customers.create
And then. you have const paymentMethod = await this.createPaymentMethod(
What is this in the second code? Why isn't it stripe?
Also what are you trying to do, what's the context of the code? Why are you creating a PaymentMethod server-side?
yes, and one moment please. I have been debugging so long that my brain was seeing Stripe. for this.. Checking...
yeah I worry you removed tons of context here and are mixing up a lot of things
If you are a Connect platform, you need to make sure all the API requests are scoped to the right account. If you create a Customer on the platform, you can't then use that Customer id on a connected account when you pass the stripeAccount option from https://stripe.com/docs/connect/authentication#authentication-via-the-stripe-account-header
Fairly certain you are doing that mistake right now
benkass-customer-node
Thanks. Checking....
so this.createPaymentMethod essentially fires this:
await stripe.paymentIntents.create(
{
currency: 'usd',
amount: 7419,
customer: 'cus_Ofti1Ac6MSleVP',
description: 'order from XYZ',
receipt_email: 'xyz@mailinator.com'
}, {
stripeAccount: 'acct_1NkveLENrXFoOICw',
}
);
Mind you, I'm in test env. I checked and the customer does exist but I'm getting an error No such customer: 'cus_Ofti1Ac6MSleVP'
๐ hopping in here
welcome ๐
From that code it looks like the error is what koopajah mentioned earlier - you created the customer on the platform account, but your subsequent requests to create a paymetn intent are trying to use that customer on the connected account
Oh, one moment, I'll read the docs koopajah referenced
Are you essentially saying that I cannot create customers on our platform and have them pay connected accounts that we created for the merchants on our app?
Correct - you'd need to clone them down to the connected accounts and then use the cloned customer/payment methods instead (https://stripe.com/docs/connect/cloning-customers-across-accounts)
reading...
Sorry, it's not entirely clear to me.
We have an app. our customers are stored on our stripe account with stripe.customers.create.
We then create a new payment method for the new customer with stripe.paymentIntents.create
If they want to load their account's virtual wallet with funds we just do
paymentIntent = await stripe.paymentIntents.create(
paymentIntentObject
);
When they want to pay directly, we let them buy from our merchants who have a connected account:
paymentIntent = await stripe.paymentIntents.create(
paymentIntentObject, {
stripeAccount: connected_account_id,
}
);
I believe I'm supposed to, before running stripe.paymentIntents.create, either check if the customer id is cloned on the connected account or create it (maybe it's just one api call)? Is that it? And only then run stripe.paymentIntents.create?
that's when I first create a token and then create the charge, right?
Let's back up for a second - is your intention to save payment methods for future usage to allow your customers to pay again across all your different connected accounts?
Or do you want your customer to provide new payment methods for every new connected account they want to pay
The first case
Gotcha - then you need to create the Customer + a Setup Intent on the platform and use that to first collect payment details. Then you'd clone the payment method that was just setup to the connected account and use that to create + confirm a payment intent
Ok. Is there an article that shows how to accomplish that?
I don't think we have docs on this, but we do have this article https://dev.to/stripe/single-slider-direct-charges-on-multiple-accounts-with-cloning-ic5 that walks through this end to end
Great! Thank you! Iโll have a read. Appreciate your help.