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
|
2019-07-30 21:29:24 +00:00
|
|
|
include Controllers::NonprofitHelper
|
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
|
|
|
|
|
|
|
def create_trial
|
2019-07-30 21:29:24 +00:00
|
|
|
render JsonResp.new(params) do |_params|
|
2018-03-25 17:30:42 +00:00
|
|
|
requires(:nonprofit_id).as_int
|
|
|
|
requires(:stripe_plan_id).as_string
|
2019-07-30 21:29:24 +00:00
|
|
|
end.when_valid do |params|
|
2018-03-25 17:30:42 +00:00
|
|
|
InsertBillingSubscriptions.trial(params[:nonprofit_id], params[:stripe_plan_id])
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
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])
|
|
|
|
json_saved(@subscription, "Success! You are subscribed to #{Settings.general.name}.")
|
|
|
|
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
|
2019-08-06 12:23:39 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def required_params
|
|
|
|
params.permit(:nonprofit_id, :billing_plan_id, :stripe_subscription_id, :status)
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|