Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Stripe subscriptions made easy

License

NotificationsYou must be signed in to change notification settings

tansengming/stripe-subscribe

Repository files navigation

Gem VersionBuild StatusCode ClimateTest Coverage

🔴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.

Installation

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

Getting Started

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

Customizing

TBD

Architecture

The engine is built simply but is highly coupled with Stripe, Devise and Rails.

Details TBD

Contributing

TBD

License

The gem is available as open source under the terms of theMIT License.

Code of Conduct

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp