#benkass-customer-node

1 messages ยท Page 1 of 1 (latest)

mint bluffBOT
wraith compass
#

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'
wide adder
#

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

wraith compass
wraith compass
wide adder
#

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?

wraith compass
#

Updated above. I have two things I do with stripe here. 1. create a customer, and 2, create a payment method for the customer

wide adder
#

I'm really sorry I'm still really confused by the whole code

wraith compass
#

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

wide adder
#

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?

wraith compass
#

yes, and one moment please. I have been debugging so long that my brain was seeing Stripe. for this.. Checking...

wide adder
#

yeah I worry you removed tons of context here and are mixing up a lot of things

#

benkass-customer-node

wraith compass
#

Thanks. Checking....

mint bluffBOT
wraith compass
#

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'

sand solstice
#

๐Ÿ‘‹ hopping in here

wraith compass
#

welcome ๐Ÿ™‚

sand solstice
#

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

wraith compass
#

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?

sand solstice
wraith compass
#

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?

sand solstice
#

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

wraith compass
#

The first case

sand solstice
#

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

wraith compass
#

Ok. Is there an article that shows how to accomplish that?

sand solstice
wraith compass
#

Great! Thank you! Iโ€™ll have a read. Appreciate your help.