2025-04-19 07:18:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2025-04-23 16:46:39 -04:00
|
|
|
class Api::V1::SubscriptionsController < ApiController
|
|
|
|
|
skip_before_action :authenticate_api_key, only: %i[callback]
|
2025-05-16 12:51:48 -04:00
|
|
|
|
2025-04-19 07:18:39 -04:00
|
|
|
def callback
|
2025-04-23 16:46:39 -04:00
|
|
|
decoded_token = Subscription::DecodeJwtToken.new(params[:token]).call
|
2025-04-19 07:18:39 -04:00
|
|
|
|
2025-04-23 16:46:39 -04:00
|
|
|
user = User.find(decoded_token[:user_id])
|
|
|
|
|
user.update!(status: decoded_token[:status], active_until: decoded_token[:active_until])
|
2025-04-19 07:18:39 -04:00
|
|
|
|
2025-04-23 16:46:39 -04:00
|
|
|
render json: { message: 'Subscription updated successfully' }
|
|
|
|
|
rescue JWT::DecodeError => e
|
2025-05-03 14:36:09 -04:00
|
|
|
ExceptionReporter.call(e)
|
2025-04-23 16:46:39 -04:00
|
|
|
render json: { message: 'Failed to verify subscription update.' }, status: :unauthorized
|
|
|
|
|
rescue ArgumentError => e
|
2025-05-03 14:36:09 -04:00
|
|
|
ExceptionReporter.call(e)
|
2025-09-12 15:08:45 -04:00
|
|
|
render json: { message: 'Invalid subscription data received.' }, status: :unprocessable_content
|
2025-04-19 07:18:39 -04:00
|
|
|
end
|
|
|
|
|
end
|