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



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

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



43
44
45
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 43

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

#destroyObject

DELETE /subscriptions/1



38
39
40
41
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 38

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

#editObject

GET /subscriptions/1/edit



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

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



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

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
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 16

def show; end

#updateObject

PATCH/PUT /subscriptions/1



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

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