devdude19289
devdude19289

Reputation: 153

create customer for stripe connected account node.js

I have this:

 const paymentMethod = await stripe.paymentMethods.create({
    type: 'card',
    card: {
      number: '4242424242424242',
      exp_month: 1,
      exp_year: 2024,
      cvc: '123',
    },
  });

  console.log(paymentMethod.id)
  const customer = await stripe.customers.create({
    payment_method: paymentMethod.id,
  });

what this does is creates a payment method and links it to the customer in which i create on the spot. However, I need to create the customer for a stripeAccount, instead of my own. I am also programmatically creating stripe accounts for my merchants, so now I want to link the customer i create to the specific merchant.

here's what I found you can do for paymentIntents, that I thought you may be able to do for stripe accounts, but it doesn't seem so:

const paymentIntent = await stripe.paymentIntents.create({
    amount: 2000,
    currency: 'usd',
    customer: customerid
  }, {
    stripeAccount: 'myaccount_id',
});

so how can i use stripeAccount within creation of customer?

Upvotes: 0

Views: 2396

Answers (1)

karllekko
karllekko

Reputation: 7268

You can use stripeAccount for any API request, it works the same way on all of them. There's an example directly in Stripe's documentation: https://stripe.com/docs/connect/authentication#stripe-account-header

const customer = await stripe.customers.create(
  {email: '[email protected]'},
  {stripeAccount: '{{CONNECTED_STRIPE_ACCOUNT_ID}}'}
);

As an aside, note also your integration seems a little wrong — you should never be calling stripe.paymentMethods.create with raw card details like that unless you want large PCI compliance headache(https://stripe.com/docs/security/guide#validating-pci-compliance under "API Direct"). You should use Stripe's frontends like Elements/Checkout.

Upvotes: 2

Related Questions