Skip to content

Latest commit

 

History

History
119 lines (85 loc) · 3.38 KB

File metadata and controls

119 lines (85 loc) · 3.38 KB

Stripe Integration

Moneygun uses the Pay gem for Stripe subscriptions.

Configuration

1. Add Credentials

rails credentials:edit
stripe:
  publishable_key: pk_test_...
  secret_key: sk_test_...
  webhook_receive_test_events: true
  signing_secret:
    - whsec_...

2. Create Products and Prices

Option A: Via seeds

rails db:seed

Creates a "Pro plan" with monthly ($99) and yearly ($999) prices.

Option B: Manually in Stripe Dashboard

  1. Create a product named "Pro plan"
  2. Add prices:
    • Monthly: $99/month
    • Yearly: $999/year

3. Configure Plans

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: year

Webhooks

Development

Stripe webhook listener is configured in Procfile.dev and starts automatically with bin/dev:

stripe listen --forward-to localhost:3000/pay/webhooks/stripe

Production

Create a webhook endpoint in Stripe Dashboard:

  • URL: https://yourdomain.com/pay/webhooks/stripe
  • Events to subscribe:
    • charge.succeeded
    • charge.refunded
    • customer.subscription.created
    • customer.subscription.updated
    • customer.subscription.deleted
    • checkout.session.completed

Quick setup links with pre-filled events:

Requiring Subscriptions

Protect routes that require an active subscription:

class Organizations::ProjectsController < Organizations::BaseController
  before_action :require_subscription

  # ...
end

The 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
end

Subscription Status

Display 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