Get parameters from Stripe page redirect URL Node.js
I am using Stripe Connect and using their example code in the documentation. You redirect a user to the Stripe page, they sign up and it redirects back to your site. Stripe then sends a code in the URL for you to be able to access and charge the users account.
var CLIENT_ID = 'clientID';
var API_KEY = 'API Key';
var TOKEN_URI = 'https://connect.stripe.com/oauth/token';
var AUTHORIZE_URI = 'https://connect.stripe.com/oauth/authorize';
var qs = require('querystring');
var request = require('request');
var express = require('express');
var app = express();
app.get('/authorize', function(req,res){
res.redirect(AUTHORIZE_URI + '?' + qs.stringify({
response_type: 'code',
scope: 'read_write',
client_id: CLIENT_ID
}));
})
After the redirect this code is what they have in the example:
app.get('/oauth/callback', function(req, res) {
var code = req.query.code;
console.log('code: ', code)
// Make /oauth/token endpoint POST request
request.post({
url: TOKEN_URI,
form: {
grant_type: 'authorization_code',
client_id: CLIENT_ID,
code: code,
client_secret: API_KEY
}
}, function(err, r, body) {
var accessToken = JSON.parse(body).access_token;
console.log('access: ', accessToken)
// Do something with your accessToken
// For demo's sake, output in response:
res.send({ 'Your Token': accessToken });
});
});
The redirect URL is https://connect.stripe.com/oauth/authorize?response_type=code&CLIENT_ID=blahblahblah. When it redirects to my site I the URL is localhost:9000/?scope=read_write&code=blahblahblah. How do I get access to this URL? Thank you!
Answer
I figured it out. In the account settings, under Connect, you have to change the redirect URI to yourURL.com/oauth/callback in order for it to work. I only had it redirecting to yourURL.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM