I am running a Node.js script to get a JSON response from Stripe using these instructions https://stripe.com/docs/connect/standard-accounts#token-request
However, I am getting the following error with the below code:
Error: Route.post() requires a callback function but got a [object Object]
Code
var app = express();
var stripe = require('stripe')('sk_test_XXXXXXXXXXXXXXXX')
var bodyParser = require('body-parser')
var request = require('request')
app.post('/ptaccountid',(req,res) => {
var authCode = req.body.code;
app.post('https://connect.stripe.com/oauth/token', {
form: {
client_secret: "sk_test_XXXXXXXXXXXXXXXX",
code: authCode,
grant_type: "authorization_code",
}
}, function(err, response, body) {
if (!err && response.statusCode == 200) {
console.log(body)
}
});
});
You should be using request.post
instead of app.post
Check below code,
app.post('/ptaccountid',(req,res) => {
var authCode = req.body.code;
request.post('https://connect.stript.com/oauth/token', {
form: {
client_secret: "sk_test_XXXXXXXXXXXXXXXX",
code: authCode,
grant_type: "authorization_code",
}
}, function(err, response, body) {
if (!err && response.statusCode == 200) {
console.log(body)
}
});
});
Hope this helps!