2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
class BillingSubscriptionsController < ApplicationController
|
2020-05-11 18:38:50 +00:00
|
|
|
include Controllers::Nonprofit::Current
|
|
|
|
include Controllers::Nonprofit::Authorization
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
before_action :authenticate_nonprofit_admin!
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def create
|
2018-03-25 17:30:42 +00:00
|
|
|
@nonprofit ||= Nonprofit.find(params[:nonprofit_id])
|
2019-07-30 21:29:24 +00:00
|
|
|
@subscription = BillingSubscription.create_with_stripe(@nonprofit, params[:billing_subscription])
|
2020-06-10 22:31:47 +00:00
|
|
|
json_saved(@subscription, "Success! You are subscribed to #{Houdini.general.name}.")
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
# post /nonprofits/:nonprofit_id/billing_subscription/cancel
|
2019-07-30 21:29:24 +00:00
|
|
|
def cancel
|
|
|
|
@result = CancelBillingSubscription.with_stripe(@nonprofit)
|
|
|
|
flash[:notice] = "Your subscription has been cancelled. We'll email you soon with exports."
|
2018-03-25 17:30:42 +00:00
|
|
|
redirect_to root_url
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
# get nonprofits/:nonprofit_id/billing_subscription/cancellation
|
|
|
|
def cancellation
|
|
|
|
@nonprofit = current_nonprofit
|
|
|
|
@billing_plan = @nonprofit.billing_plan
|
|
|
|
@billing_subscription = @nonprofit.billing_subscription
|
|
|
|
end
|
|
|
|
end
|