14 Day Money Back Guarantee

The Complete SaaS Kit for Node.js

Save thousands of dollars in development time and deploy your new SaaS application at warp speed
Buy Now

Why Gravity?

Building software is expensive and time-consuming. Gravity provides you with all the boilerplate functionality needed for a SaaS web-app so you can focus on building the features that matter.

For Founders

  • Save weeks of time
  • Get to market faster
  • Slash development costs
  • Generate revenue sooner

For Freelancers & Agencies

  • Maximise your profit
  • Deliver projects faster
  • Save weeks of time
  • Avoid writing boring code

What You Get

Powered By

Stripe Logo Mailgun Logo

Pricing

How it Works

Download the code and run the setup file. In less than two minutes, you’ll have a fully-functioning web application that can process payments, manage users and deliver SaaS metrics for your business.

Code Examples

  • 
    /*
    * auth.signupAccount()
    * creates a new account + a new stripe customer
    * processes the payment and creates a new recurring monthly subscription
    * params are passed from the front-end signup form via router.js
    */
    
    exports.signupAccount = function(name, email, password, referer, stripe_id, plan, session){
    
      return new Promise(function(resolve, reject){
    
        var accountId, planPrice;
    
        // check if the email address is already registered with an account
        account.doesExist(email, null).then(function(exists){
    
          if (!exists)
            return account.create(email, referer, stripe_id, plan);
          else
            throw ({ status: false, error: "emailError", message: "Account already exists" });
    
        }).then(function(res){
    
          // create a new stripe customer
          accountId = res;
          return account.createStripeCustomer(email, stripe_id);
    
        }).then(function(customerId){
    
          // subscribe the account to a new stipe subscription plan
          return account.subscribeToPlan(accountId, customerId, plan);
    
        }).then(function(price){
    
          // create the user and add to account
          planPrice = price;
          return user.create(name, email, password, accountId, "owner");
    
        }).then(function(userId){
    
          // set permissions and autheticate user
          session.user = userId;
          session.account = accountId;
          session.permission = "owner";
    
          // send welcome email
          mail.send(email, "Welcome to Gravity!", "welcome-account", { name: name, plan: plan, price: planPrice });
    
          // redirect user to dashboard
          resolve({ success: true });
    
        }).catch(function(err){
    
          reject(err);
    
        });
      });
    }
    
    
  • 
    /*
    * user.invite()
    * invites a new user to join an account
    * uses invites table in the db to verify invites and remove need to
    * expose the account id in the front-end URL query
    * if a user has already been invited, the invite will be re-sent
    */
    
    exports.invite = function(email, accountId){
    
      // check if user has already been invited
      var sql = "SELECT account_id, invite_id FROM invites WHERE email = ? AND used = 0";
    
      db.query(sql, [email]).then(function(data){
    
        // user has been invited, re-send invite
        if (data.length > 0){
    
          inviteURL = settings.domain + "/user/signup#" + data[0].invite_id;
          sendInviteEmail(email, accountId, inviteURL);
    
          // update invite
          sql = "UPDATE invites SET date_sent = NOW()";
          db.query(sql).catch(function(err){ reject({ success: false, message: err }); });
    
        }
        else {
    
          // create a new invite
          var inviteID = randomstring.generate(16);
          var sql = "INSERT INTO invites VALUES (null, ?, ?, ?, NOW(), false)";
          var params = [inviteID, email, accountId]
    
          db.query(sql, params).then(function(){
    
            return inviteURL = settings.domain + "/user/signup#" + inviteID;
    
          }).then(function(inviteURL){
    
            sendInviteEmail(email, accountId, inviteURL);
    
          }).catch(function(err){
    
            reject({ success: false, message: err });
    
          });
        }
      });
    }
    
    

Got a Question?

Need some more information? Just drop us an email and we’d be happy to answer any questions you have.

Contact Buy Now