parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

How to configure webhooks from stripe to parse server

Open cyboolo opened this issue 10 years ago • 6 comments

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?

cyboolo avatar Feb 04 '16 08:02 cyboolo

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){..}
});

};

xwizi avatar Feb 04 '16 11:02 xwizi

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 avatar Feb 04 '16 13:02 cyboolo

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

otymartin avatar Nov 24 '16 00:11 otymartin

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) {
//...
};

paulrolfe avatar Jan 22 '17 20:01 paulrolfe

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.

kamalbrowswire avatar Apr 14 '17 11:04 kamalbrowswire

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);
	 }
	});
});

lxknvlk avatar Apr 26 '17 08:04 lxknvlk