Search code examples
node.jsherokuparse-server

Require modul not working when I migrate from parse to heroku


I migrated from parse to heroku and I am trying to get cloud code to work. Everything works fine when the cloud code file is blank, but when I add the require Stripe or Twilio lines in the main.js file, nothing in my app loads. What am I doing wrong?

package.json

"dependencies": {
"express": "~4.11.x",
"kerberos": "~0.0.x",
"parse": "~1.8.0",
"parse-server": "~2.2.12",
"stripe": "~4.9.0",
"twilio": "~2.9.2"
}

main.js

var Stripe = require('stripe');
Stripe.initialize('sk_test_xxxxxxx');

Solution

  • i had issues with this today

    I did it by trial and error, here is what i remember

    https://www.npmjs.com/package/stripe <- thats where i got the cloud code from

    1. in the root directory of your parse-server through command prompt i executed the following - npm install stripe
    2. then i added the stripe dependancy to package.json (this stack overflow post was the missing key) "stripe": "~4.9.0",
    3. the cloud code is as follows

    Parse.Cloud.define("charge", function(request, response) {

    var stripe = require('stripe')('sk_test_****');
    
    stripe.customers.create({
      email: theEmailAddress
    }).then(function(customer) {
      return stripe.charges.create({
        amount: yourAmount, 
        currency: yourCurrency,
        card: yourToken,
        description: yourDescription
      });
    }).then(function(charge) {
      // New charge created on a new customer 
    }).catch(function(err) {
      // Deal with an error 
    });
    

    });

    1. use that cloud code through your app and see if it works in your stripe dashboard (you must check in the dashboard)

    so the two 'breakthroughs' came when i added stripe as a dependancy in package.json and also can you see that var stripe = require is inside the the cloud code function