Moneygun uses the Pay gem for Stripe subscriptions.
rails credentials:editstripe:
publishable_key: pk_test_...
secret_key: sk_test_...
webhook_receive_test_events: true
signing_secret:
- whsec_...Option A: Via seeds
rails db:seedCreates a "Pro plan" with monthly ($99) and yearly ($999) prices.
Option B: Manually in Stripe Dashboard
- Create a product named "Pro plan"
- Add prices:
- Monthly: $99/month
- Yearly: $999/year
Add Stripe price IDs to config/settings.yml:
shared:
plans:
- id: price_xxx # Monthly price ID
unit_amount: 9900
currency: USD
interval: month
- id: price_yyy # Yearly price ID
unit_amount: 99900
currency: USD
interval: yearStripe webhook listener is configured in Procfile.dev and starts automatically with bin/dev:
stripe listen --forward-to localhost:3000/pay/webhooks/stripeCreate a webhook endpoint in Stripe Dashboard:
- URL:
https://yourdomain.com/pay/webhooks/stripe - Events to subscribe:
charge.succeededcharge.refundedcustomer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deletedcheckout.session.completed
Quick setup links with pre-filled events:
Protect routes that require an active subscription:
class Organizations::ProjectsController < Organizations::BaseController
before_action :require_subscription
# ...
endThe require_subscription method is defined in Organizations::BaseController:
def require_subscription
unless Current.organization.has_access?
flash[:alert] = "You need to subscribe to access this page."
redirect_to organization_subscriptions_url(Current.organization)
end
endDisplay subscription state with the helper:
subscription_status_label(organization)Returns:
- Red indicator - No subscription
- Orange indicator - Subscription cancelled (on grace period)
- Green indicator - Active subscription