Subsciptions with Stripe made easy for Meteor.
If you are looking for a quick and simple way to add subscriptions to your Meteor app, this is a great option.
- Install this package into your project
meteor add woody:stripe-easy
. - Define your publishable and secret test keys in
Meteor.settings
. - Insert
{{> stripeEasyInputs}}
somewhere in your<form>
. - In the
'submit form'
template event function, make sure there is aMeteor.user()
and handle the subscription like this:
var easy = StripeEasy.submitHelper(e);
var plan_id = "PLAN_ID_FROM_STRIPE"
StripeEasy.subscribe(easy, plan_id, function(err, result){
// do something
});
Awesome. Subscriptions are up.
- Sign up for an account at Stripe - https://stripe.com/
- Open up your dashboard and create some subscription plans. Make note of the plan id for each plan you make. You will need this in Step 6 - https://dashboard.stripe.com/
- Find your Stripe test api keys - https://dashboard.stripe.com/account/apikeys
- Set up your test keys by A) creating a
settings.json
file in the root of your project directory, B) copy/paste the code below replacing the placeholder text with your appropriate keys. C) Startup Meteor with those setting by runningmeteor --settings settings.json
in your terminal.
{
"public" : {
"Stripe" : {
"publicKey" : "YOUR_PUBLISHABLE_KEY"
}
},
"Stripe" : {
"secretKey" : "YOUR_SECRET_KEY"
}
}
- Include the
{{> stripeEasyInputs}}
template inside of a form tag.
<form>
{{> stripeEasyInputs}}
<button type="submit">Submit</button>
</form>
- Handle the submit event on the form. Note that the StripeEasy functions require a
Meteor.user()
. So assuming you either already have a user logged in or your callMeteor.createUser
first, you would handle the event as follows:
'submit form': function (e) {
e.preventDefault();
// make sure there is a Meteor.user() or wrap the following inside the Meteor.createUser callback function
var easy = StripeEasy.submitHelper(e);
var plan_id = "STRIPE_PLAN_ID"; // set however you want, via Session variable or a part of the form.
StripeEasy.subscribe(easy, plan_id, function(err, result){
// if no error, will return the newly created customer object from Stripe
});
},
- To update a subscription you would do the following inside of an event:
var plan_id = "UPDATE_TO_THIS_PLAN_ID";
StripeEasy.update(plan_id, function(err, result){
// result will be the updated subscription object from Stripe
});
Note: A Meteor.user()
is required for these functions to work.
Returns an object to pass to StripeEasy.subscribe()
. Where e
is a jQuery submit form event.
Where obj
is the object returned from StripeEasy.submitHelper(e)
.
The callback function should have two arguments, an error
and a result
argument. On success, it subscribes the curretnly logged in user to the specified plan_id and will modify the user's profile.stripe
to have a customerId
and a subscription
property.
Where plan_id
is the new plan_id to update to.
The callback function should have two arguments, an error
and a result
argument. On success, will update the currently logged in user's profile.stripe.subscription
property with the new subscription and return the subscription object.
Cancels the currently logged in users subscription plan. The callback function should have two arguments, an error
and a result
argument. On success, will update the currently logged in user's profile.stripe.subscription
property.
Easily add CSS classes to the inputs by passing {inputClasses: "input-lg custom-class-name"}
to the StripeEasy.config function.
Has bootstrap error class validation built into the inputs on blur, and also adds icons when bootstrap and font-awesome are added to your project.
- Test error cases suggested by Stripe.
- Write some tests.
- Write more TODOs.
License MIT - http://opensource.org/licenses/MIT