2021-08-10 08:45:23 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class CustomWizard::AdminProController < CustomWizard::AdminController
|
|
|
|
skip_before_action :check_xhr, :preload_json, :verify_authenticity_token, only: [:authorize, :authorize_callback]
|
|
|
|
|
|
|
|
def index
|
2021-09-01 04:19:00 +02:00
|
|
|
render_serialized(pro, CustomWizard::ProSerializer, root: false)
|
2021-08-10 08:45:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize
|
|
|
|
request_id = SecureRandom.hex(32)
|
|
|
|
cookies[:user_api_request_id] = request_id
|
2021-09-01 04:19:00 +02:00
|
|
|
redirect_to pro.authentication_request(current_user.id, request_id).to_s
|
2021-08-10 08:45:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_callback
|
|
|
|
payload = params[:payload]
|
|
|
|
request_id = cookies[:user_api_request_id]
|
|
|
|
|
2021-09-01 04:19:00 +02:00
|
|
|
pro.authentication_response(request_id, payload)
|
|
|
|
pro.update_subscription
|
2021-08-10 08:45:23 +02:00
|
|
|
|
|
|
|
redirect_to '/admin/wizards/pro'
|
|
|
|
end
|
|
|
|
|
2021-09-01 04:19:00 +02:00
|
|
|
def destroy_authentication
|
|
|
|
if pro.destroy_authentication
|
2021-08-10 08:45:23 +02:00
|
|
|
render json: success_json
|
|
|
|
else
|
|
|
|
render json: failed_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_subscription
|
2021-09-01 04:19:00 +02:00
|
|
|
if pro.update_subscription
|
|
|
|
subscription = CustomWizard::ProSubscriptionSerializer.new(pro.subscription, root: false)
|
|
|
|
render json: success_json.merge(subscription: subscription)
|
2021-08-10 08:45:23 +02:00
|
|
|
else
|
|
|
|
render json: failed_json
|
|
|
|
end
|
|
|
|
end
|
2021-09-01 04:19:00 +02:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def pro
|
|
|
|
@pro ||= CustomWizard::Pro.new
|
|
|
|
end
|
2021-08-10 08:45:23 +02:00
|
|
|
end
|