Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to configure webhooks from stripe to parse server #234

Closed
cyboolo opened this issue Feb 4, 2016 · 6 comments
Closed

How to configure webhooks from stripe to parse server #234

cyboolo opened this issue Feb 4, 2016 · 6 comments

Comments

@cyboolo
Copy link

cyboolo commented Feb 4, 2016

Hi,

Before migration this webhook configured on stripe dashboard worked perfectly:

https://<**myParseapp**>:javascript-key=<**myJSkey**>@api.parse.com/functions/new_invoice

Now, when I try to do the same with my parse server on heroku:

https://<**myParseapp**>:javascript-key=<**myJSkey**>@something.herokuapp.com/parse/functions/new_invoice

I got error "403 unauthorized" when I test this webhooks from stripe dashboard.

How could I fix that please?

@xwizi
Copy link

xwizi commented Feb 4, 2016

Have you checked your keys are set-up correctly?

A workaround:

in index.js (if you used the demo app or in your express routes) you could pass your token etc

// exposes a new api route that can be used in stripe  //yourdomain/api/stripe
app.get('/api/stripe', function(req, res) {

Parse.Cloud.run("new_invoice",req.body[0],
{ 
 success:function(e){...},
 error:function(e){..}
});

};

@cyboolo
Copy link
Author

cyboolo commented Feb 4, 2016

Thank you for your help, I could find a solution by doing these modifications:

You must have in your code:

var stripe = require('stripe')('your live or test stripe key');
var Parse = require('parse').Parse;
var Parse = require('parse/node').Parse;
var bodyParser = require('body-parser');

then add:
app.use( bodyParser.json() );

and finally the code to receive webhook and launch function from cloud code:

app.post('/stripe', function(req, res){

Parse.initialize("appId", "JsKey"); 
Parse.Cloud.run('hello',{}, {
success: function(obj) { res.send(obj); },
error: function(error) {
res.status(500);
res.send(error);
}
});

});

In webhook testing mode on stripe I get the response from my cloud code function, in that case "hello world!"

@cyboolo cyboolo closed this as completed Feb 4, 2016
@otymartin
Copy link

@cyboolo hi so are webhooks working for you with parse-server and cloudcode?

@paulrolfe
Copy link

paulrolfe commented Jan 22, 2017

Just making this a little clearer for people still having trouble. Also this express doc was super helpful for me. https://expressjs.com/en/api.html#req

I was using a webhook with twilio.

// index.js
var hooks = require('./cloud/hooks');
var bodyParser = require('body-parser');
//...
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded

app.post('/receiveSMS', function(req, res) {
  console.log("RECEVIED SMS FROM: " + req.body.From);
  console.log("Body: " + req.body.Body);
  var passedRequest = {"params": req.body}; // That's how my receiveSMS function expects it. You may not need this.
  hooks.receiveSMS(passedRequest, {
    success: function(obj) {
      res.status(200).send(obj);
    },
    error: function(error) {
      res.status(500).send(error);
    }
  });
});

Then in hooks.js

var client = require('twilio')('keys','andsuch');
var SomeParseObjectYouMightNeed = Parse.Object.extend("SomeParseObjectYouMightNeed");

exports.receiveSMS = function(request, response) {
//...
};

@kamalbrowswire
Copy link

Hi
I am new in parse-server and i have to create webhook for a class.I can't understand what is the Webhook URL and where to use.

@lxknvlk
Copy link

lxknvlk commented Apr 26, 2017

Cofirming working solution:

var bodyParser = require('body-parser');
app.use( bodyParser.json() );

app.post('/api/stripe', function(request, response) {	
	var body = request.body;
	var id = body.id;

	var params = {
		id : id
	}
	
	Parse.Cloud.run("stripeWebHook", params,{
	 success:function(e){
	 	response.status(200).send(e);
	 },
	 error:function(e){
	 	response.status(-1).send(e);
	 }
	});
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants