Ad
What Does The "comma" Syntax Mean When Calling A Function In Stripe?
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
Related Questions
- → Maximum call stack exceeded when instantiating class inside of a module
- → Browserify api: how to pass advanced option to script
- → Node.js Passing object from server.js to external modules?
- → gulp-rename makes copies, but does not replace
- → requiring RX.js in node.js
- → Remove an ObjectId from an array of objectId
- → Can not connect to Redis
- → React: How to publish page on server using React-starter-kit
- → Express - better pattern for passing data between middleware functions
- → Can't get plotly + node.js to stream data coming through POST requests
- → IsGenerator implementation
- → Async/Await not waiting
- → (Socket.io on nodejs) Updating div with mysql data stops without showing error
Ad