Ad

What Does The "comma" Syntax Mean When Calling A Function In Stripe?

- 1 answer

I am attempting to create a new customer in Stripe. I am successful but confused about how their documentation styles the function call.

I cannot seem to find any information on their official docs. https://stripe.com/docs/api/customers/create?lang=node

For example:

stripe.customers.create({
  description: 'Customer for [email protected]',
  source: "tok_visa" // obtained with Stripe.js
}, function(err, customer) {
  // asynchronously called
});

I am assuming it is similar to ".then((err, customer) =>{}', but cannot seem to use the function call with this syntax.

Any explanation would be helpful!

Ad

Answer

What you know are Promises, and they are the preferred way to do async today. Stripe's API is using the callback (also called errback) style, which predates Promises.

It is similar to

.then(customer => ...).catch(err => ...)

However, Stripe's Node library returns promises as well, so you can convert your example to:

stripe.customers.create({
  description: 'Customer for [email protected]',
  source: "tok_visa" // obtained with Stripe.js
})
.then(customer => ...)
.catch(err => ...);
Ad
source: stackoverflow.com
Ad