Class: Admin::SubscriptionsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/tang/admin/subscriptions_controller.rb

Instance Method Summary collapse

Instance Method Details

#apply_couponObject



49
50
51
52
53
54
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 49

def apply_coupon
  @subscription = Subscription.find(params[:subscription_id])
  @coupon = Coupon.find(params[:subscription][:coupon_id])
  ApplySubscriptionDiscount.call(@subscription, @coupon)
  redirect_to admin_subscription_url(@subscription), notice: 'Coupon was successfully applied.'
end

#couponObject



45
46
47
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 45

def coupon
  @subscription = Subscription.find(params[:subscription_id])
end

#destroyObject

DELETE /subscriptions/1



40
41
42
43
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 40

def destroy
  @subscription.cancel!
  redirect_to admin_subscriptions_url, notice: 'Subscription was successfully canceled.'
end

#editObject

GET /subscriptions/1/edit



20
21
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 20

def edit
end

#indexObject

GET /subscriptions



8
9
10
11
12
13
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 8

def index
  @subscriptions = Subscription.includes(:customer).
                                where.not(status: :canceled).
                                paginate(page: params[:page]).
                                order("#{Customer.table_name}.email")
end

#remove_couponObject



56
57
58
59
60
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 56

def remove_coupon
  @subscription = Subscription.find(params[:subscription_id])
  RemoveSubscriptionDiscount.call(@subscription)
  redirect_to admin_subscription_url(@subscription), notice: 'Coupon was successfully removed.'
end

#showObject

GET /subscriptions/1



16
17
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 16

def show
end

#updateObject

PATCH/PUT /subscriptions/1



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 24

def update
  @subscription.end_trial_now = (params[:subscription][:end_trial_now] == '1')
  if @subscription.end_trial_now
    params[:subscription]['trial_end(1i)'] = ''
    params[:subscription]['trial_end(2i)'] = ''
    params[:subscription]['trial_end(3i)'] = ''
  end

  if @subscription.update(subscription_params)
    redirect_to [:admin, @subscription], notice: 'Subscription was successfully updated.'
  else
    render :edit
  end
end