82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'app/controllers/effective/subscriptions_controller.rb', line 82
def destroy
@plan = Stripe::Plan.retrieve(params[:id])
raise ActiveRecord::RecordNotFound unless @plan.present?
@subscription = @customer.subscriptions.find { |subscription| subscription.stripe_plan_id == params[:id] }
@stripe_subscription = @subscription.try(:stripe_subscription)
raise ActiveRecord::RecordNotFound unless @subscription.present?
EffectiveOrders.authorized?(self, :destroy, @subscription)
if @subscription.present?
begin
@stripe_subscription.delete if @stripe_subscription
@subscription.destroy
flash[:success] = "Successfully unsubscribed from #{params[:id]}"
rescue => e
flash[:danger] = "Unable to unsubscribe. Message: \"#{e.message}\"."
end
else
flash[:danger] = "Unable to find stripe subscription for #{params[:id]}" unless @subscription.present?
end
redirect_to effective_orders.subscriptions_path
end
|