mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
* Change env SELF_HOSTING_ENABLED to SELF_HOSTED * Initial Stripe implementation * Fix portal link * Use webhook signatures * Migrated to new Stripe gem conventions Also updated resource routing * Added faraday-multipart gem to resolve middleware notice * Merge fix * Merge fix * Temporary upgrade prompt for early access * Lint fix * i18n fixes * Remove catch-all rescue * Update .env.example
36 lines
1.1 KiB
Ruby
36 lines
1.1 KiB
Ruby
class SubscriptionsController < ApplicationController
|
|
def new
|
|
client = Stripe::StripeClient.new(ENV["STRIPE_SECRET_KEY"])
|
|
|
|
if Current.family.stripe_customer_id.blank?
|
|
customer = client.v1.customers.create(
|
|
email: Current.family.primary_user.email,
|
|
metadata: { family_id: Current.family.id }
|
|
)
|
|
Current.family.update(stripe_customer_id: customer.id)
|
|
end
|
|
|
|
session = client.v1.checkout.sessions.create({
|
|
customer: Current.family.stripe_customer_id,
|
|
line_items: [ {
|
|
price: ENV["STRIPE_PLAN_ID"],
|
|
quantity: 1
|
|
} ],
|
|
mode: "subscription",
|
|
success_url: settings_billing_url,
|
|
cancel_url: settings_billing_url
|
|
})
|
|
|
|
redirect_to session.url, allow_other_host: true, status: :see_other
|
|
end
|
|
|
|
def show
|
|
client = Stripe::StripeClient.new(ENV["STRIPE_SECRET_KEY"])
|
|
|
|
portal_session = client.v1.billing_portal.sessions.create(
|
|
customer: Current.family.stripe_customer_id,
|
|
return_url: settings_billing_url
|
|
)
|
|
redirect_to portal_session.url, allow_other_host: true, status: :see_other
|
|
end
|
|
end
|