- Notifications
You must be signed in to change notification settings - Fork0
Stripe subscriptions made easy
License
tansengming/stripe-subscribe
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
🔴This gem is still in Alpha and has not been tested on Production 🔴
This is a Rails Engine that makes it easy to work with Stripe Subscriptions. It provides,
- views and controllers for showing Stripe plans
- integrated with views and controllers for payments
- methods on any Devise resource to fetch it's Stripe subscriptions
Checking a user's subscription and getting the user to subscribe to a plan can be as simple as,
# app/controllers/paid_features_controller.rbclassPaidFeaturesController <ApplicationControllerdefshowifcurrent_user.stripe_active_subcsription?# checks subscription from Striperenderelseredirect_tostripe_subscribe.plans_path# to select and pay for a planendendend
📫 Sign up for the Newsletter to receive occasional updates.
On the road-map: handling cancellations, switching plans, trials, coupons, discounts, dealing with refunds. Feel free to post an issue if I'm missing anything.
Add this line to your application's Gemfile:
gem'stripe-subscribe',github:'tansengming/stripe-subscribe'
And then execute:
$ bundle
Install and run the migrations:
$ rails stripe_subscribe:install:migrations$ rails db:migrate
These are the files that have to be updated on your Rails app. Don't panic.
.├─ config│ ├─ stripe│ │ └─ plans.rb│ └─ routes.rb└─ app ├─ models │ └─ user.rb └─ controllers └─ paid_features_controller.rb
Configure your plans atconfig/stripe/plans.rb
. The plans defined here will be uploaded to Stripe and used to render the plans page,
# config/stripe/plans.rbStripe.plan:prodo |plan|plan.name='Professional'plan.amount=1999plan.currency='usd'plan.interval='month'end
Run this to upload the plans to Stripe,
$ rake stripe:prepare
Update the routes to mount the engine. This will be the routes where users get to select a plan and pay for it. Make sure it is mounted within Devise'sauthenticate
helper so only authenticated users get access.
# config/routes.rbRails.application.routes.drawdoauthenticate:userdomountStripe::Subscribe::Engine=>"/stripe/subscribe"endend
Include the module to mix in Stripe subscription methods to theUser
. E.g.#stripe_active_subcsription?
,stripe_customer
etc.
# app/models/user.rbclassUser <ApplicationRecordincludeStripe::Subscriberableend
You are now ready for user subscriptions on Stripe!
You can use the new methods to retrieve a user's subscription status on the controller and block access to the action until they become a subscriber.
Redirecting users tostripe_subscribe.plans_path
will take the user to a page with the plans listed onconfig/stripe/plans.rb
. They will then be able to select a plan and pay for them on those pages.
# app/controllers/paid_features_controller.rbclassPaidFeaturesController <ApplicationControllerdefshowifcurrent_user.stripe_active_subcsription?renderelseredirect_tostripe_subscribe.plans_pathendendend
TBD
The engine is built simply but is highly coupled with Stripe, Devise and Rails.
Details TBD
TBD
The gem is available as open source under the terms of theMIT License.
Please note that this project is released with a Contributor Code ofConduct. By participating in this project you agree to abide by itsterms, which can be found in theCODE_OF_CONDUCT.md
file in thisrepository.
About
Stripe subscriptions made easy
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.