2019-01-16 16:28:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# API Controller for resources of type Subscription
|
2016-03-23 18:39:41 +01:00
|
|
|
class API::SubscriptionsController < API::ApiController
|
2023-01-03 17:17:39 +01:00
|
|
|
before_action :set_subscription, only: %i[show payment_details cancel]
|
2016-03-23 18:39:41 +01:00
|
|
|
before_action :authenticate_user!
|
|
|
|
|
|
|
|
def show
|
|
|
|
authorize @subscription
|
|
|
|
end
|
|
|
|
|
2021-10-08 19:14:47 +02:00
|
|
|
def payment_details
|
|
|
|
authorize @subscription
|
|
|
|
end
|
|
|
|
|
2023-01-03 17:17:39 +01:00
|
|
|
def cancel
|
|
|
|
authorize @subscription
|
2023-02-17 11:44:04 +01:00
|
|
|
if @subscription.expire(Time.current)
|
2023-01-03 17:17:39 +01:00
|
|
|
render :show, status: :ok, location: @subscription
|
|
|
|
else
|
|
|
|
render json: { error: 'already expired' }, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-23 18:39:41 +01:00
|
|
|
private
|
|
|
|
|
2018-12-06 18:26:01 +01:00
|
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
|
|
def set_subscription
|
|
|
|
@subscription = Subscription.find(params[:id])
|
|
|
|
end
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|