# frozen_string_literal: true module Payments class IntegrationsController < BaseController before_action :find_payment, only: [:new, :fail] before_action :find_order, only: [:success] after_action :clear_payment_session, only: [:success, :fail] def new options = { template: "payments/integrations/providers/#{@payment_type.code}", formats: [:html] } if @payment_type.wire_transfer? options[:layout] = 'cabinet' find_structure('payments-wire-transfer') else set_payment_to_session(@payment) end render options end def success find_structure('payments-success') theme = params[:theme] || 'success_terms' # theme = 'evaluation_terms' # _template = "success" # if params[:order_id] && current_account # _template = "affiliate" if @order.has_new_affiliate_payment?(params[:token]) if params[:token] # end # render template: "payments/integrations/#{_template}", layout: "cabinet" respond_with @structure, layout: 'cabinet', locals: { theme: theme } end def fail find_structure('payments-fail') respond_with @structure, layout: 'cabinet' end protected def find_order return unless account_signed_in? @order = begin TranslationCms::Api::Customers::Order.find(params[:order_id]).first rescue JsonApiClient::Errors::ApiError nil end end def clear_payment_session session[:payment_price] = nil session[:payment_id] = nil session[:payment_title] = nil end end end