Class: Spree::Admin::PayoutProfilesController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/admin/payout_profiles_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



58
59
60
61
# File 'app/controllers/spree/admin/payout_profiles_controller.rb', line 58

def index
  @search = Spree::PayoutProfile.ransack(params[:q])
  @payout_profiles = @search.result.page(page).per(per_page).order(default: :desc)
end

#load_typesObject



28
29
30
# File 'app/controllers/spree/admin/payout_profiles_controller.rb', line 28

def load_types
  @types = ['Spree::PayoutProfiles::PaywayV2']
end

#location_after_saveObject

override



64
65
66
# File 'app/controllers/spree/admin/payout_profiles_controller.rb', line 64

def location_after_save
  edit_object_url(@object)
end

#model_classObject

override



78
79
80
# File 'app/controllers/spree/admin/payout_profiles_controller.rb', line 78

def model_class
  Spree::PayoutProfile
end

#pageObject



82
83
84
# File 'app/controllers/spree/admin/payout_profiles_controller.rb', line 82

def page
  params[:page] || 1
end

#per_pageObject



86
87
88
# File 'app/controllers/spree/admin/payout_profiles_controller.rb', line 86

def per_page
  params[:per_page] || 12
end

#permitted_resource_paramsObject

override permit all attributes for now.



70
71
72
73
74
75
# File 'app/controllers/spree/admin/payout_profiles_controller.rb', line 70

def permitted_resource_params
  key = ActiveModel::Naming.param_key(@object)
  permit_keys = params.require(key).keys

  params.require(key).permit(permit_keys)
end

#request_creatorObject



54
55
56
# File 'app/controllers/spree/admin/payout_profiles_controller.rb', line 54

def request_creator
  ::Vpago::PayoutProfiles::Payway::PayoutProfileRequestCreator
end

#request_updaterObject



50
51
52
# File 'app/controllers/spree/admin/payout_profiles_controller.rb', line 50

def request_updater
  ::Vpago::PayoutProfiles::Payway::PayoutProfileRequestUpdater
end

#reset_verificationObject

when updated, active must be false. call verify_with_bank to reactivate with bank.



16
17
18
# File 'app/controllers/spree/admin/payout_profiles_controller.rb', line 16

def reset_verification
  @object.reset_verification!
end

#save_defaults!Object



20
21
22
23
24
25
26
# File 'app/controllers/spree/admin/payout_profiles_controller.rb', line 20

def save_defaults!
  instance = Spree::PayoutProfile.find(@object.id)

  instance.default = Spree::Store.default.name == instance.name
  instance.set_default_preferences if instance.respond_to?(:set_default_preferences)
  instance.save!
end

#verify_with_bankObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/spree/admin/payout_profiles_controller.rb', line 32

def verify_with_bank
  @object = Spree::PayoutProfile.find(params[:id])

  instance = if @object.registered_in_bank?
               request_updater.new(@object)
             else
               request_creator.new(@object)
             end

  if instance.call
    flash[:success] = flash_message_for(@object, :successfully_updated)
  else
    flash[:error] = instance.error_messages.to_s
  end

  redirect_to edit_object_url(@object)
end