thailey01 thailey01 - 1 year ago 212
Node.js Question

Parse-Server Cloud-Code and Stripe

I'm running a Parse-Server instance for a mobile web-app on Heroku. My problem is Stripe checkout plugin is working fine in my html page, but when the token is created and I call my Cloud Code it seems as if creating the variable initializing stripe does nothing. This is my cloud code.

var stripe = require('stripe')('sk_test_******');
Parse.Cloud.define("pay", function(req, res){
var token = req.params.token;
var amount = req.params.amount;
var email =;
// stripe is null

Upon calling this, the value of stripe is null and I cannot figure out why. I have added stripe: '~4.7.0' in my package.json file and have run npm install to locally create all node modules. I don't know if it makes a difference but in my index.js file I have created a router

app.use('/', express.static(path.join(__dirname, '/public')));

because it's easier to access files in the public directory this way. Otherwise I would have to reference files in my public directory with /public/filename everytime I wanted to include that file. Any help would be much appreciated.

Answer Source

I gave up trying to run this charge in Cloud Code. Instead I created a route '/charge' in my index.js file and called it using a jQuery post. Here is my code in index.js

var stripe = require('stripe')('sk_test_****');
var bodyParser = require('body-parser');
    extended: false
}));'/charge', function(req, res){
    var token = req.body.token;
    var amount = req.body.amount;
        amount: amount,
        currency: 'usd',
        source: token,
    }, function(err, charge){
            // Error check
            res.send('Payment successful!');

Here is my jQuery request

var handler = StripeCheckout.configure({
    key: 'pk_test_****',
    locale: 'auto',
    token: function(token){
        $.post('/charge', {
            amount: total,
        }, function(data, status){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download