Sha256: 02ce273b69a36bf28cfffe8dc99dd96edc71b4df37941592a6974278dd8630f7

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

module Spree
  module Admin
    class MelhorEnvioController < BaseController
      before_action :set_melhor_envio_preferences

      def index
      end

      def update
        @me_preferences[:postal_code_from] = params[:postal_code_from]
        @me_preferences[:client_id] = params[:client_id]
        @me_preferences[:client_secret] = params[:client_secret]
        @me_preferences[:refresh_token] = params[:refresh_token]
        Spree::Store.first.update(preferences: { melhor_envio: @me_preferences })
        redirect_to admin_melhor_envio_index_path
      end

      def authorize
        code = params[:code]
        authorize_json = MeApi::Client.new.authorize(
          client_id: @me_preferences[:client_id],
          client_secret: @me_preferences[:client_secret],
          code: code,
          redirect_url: admin_melhor_envio_authorize_url
        ).json
        @me_preferences[:access_token] = authorize_json["access_token"]
        @me_preferences[:refresh_token] = authorize_json["refresh_token"]
        @me_preferences[:token_expires_in] = (DateTime.now + authorize_json["expires_in"].seconds).to_s
        Spree::Store.first.update(preferences: { melhor_envio: @me_preferences })
        redirect_to admin_melhor_envio_index_path
      end

      private

      def set_melhor_envio_preferences
        @me_preferences = Spree::Store.first.preferences[:melhor_envio]
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_me-1.0.1 app/controller/spree/admin/melhor_envio_controller.rb
solidus_me-1.0.0 app/controller/spree/admin/melhor_envio_controller.rb
solidus_me-0.0.1 app/controller/spree/admin/melhor_envio_controller.rb