How can can I import and install Stripe to my Meteor 1.3 app?


#1

I’m creating a Meteor app that will sell one of our customer’s products. I’ve decided to try and use Stripe to handle the payments (in particular Stripe Connect), and to charge an ‘application fee’ for each sale. I have seen several tutorials, but nothing for Meteor 1.3, which I would prefer to use.

My questions:

  1. Do I still need to use mrgalaxy:stripe or kadira:stripe-connect in order to use the Node API for Stripe? I have tried to use both, and am getting incredibly confused with the documentation of these packages, which I now believe are outdated.

  2. If not, exactly how should I install and import Stripe for my app?

  3. What do I need to do differently on client and on server to import Stripe?

What I have tried:

In my app directory:
meteor npm install --save stripe.

In my client side javascript code:

import stripe from "stripe"

var stripe = require("stripe"("sk_******************")

Meteor.startup(function() {
    stripe.setPublishableKey("sk_******************");
});

Some sources say that the first line should import the package, but the NPM documentation suggests otherwise. Using this code, chrome’s debugger gives me :

Uncaught TypeError: require("...").createServer is not a function

which is running in node_modules/stripe/lib/stripe.js, and the "..." is actually "http" in the stripe.js.

I am epically confused right now and would give my right index finger for clear instruction on what exactly to write in my javascript file, so I can go from where I am now to creating my first charge object.

Thanks in advance!


#2

I am also having trouble. Did you find any clear solution?


#3

You can’t use both, you must either use

import connectToStripe from 'stripe';
const stripe = connectToStripe('sk_**********');

Or

var stripe = require("stripe")("sk_******************");

The import syntax is coming from the new javascript module specs.

The http package is a nodejs library package and can’t be used in the browser. It seems you are using the server-side stripe package.
I advise you to use stripe in the server-side code of your application, it will be more secure. Your can then create some meteor methods to interact with it from the client.