Class: Admin::Externals::GbPrimepay::MerchantsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/externals/gb_primepay/merchants_controller.rb

Overview

typed: ignore

Instance Method Summary collapse

Instance Method Details

#createObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/admin/externals/gb_primepay/merchants_controller.rb', line 45

def create
  accepted_credit_cards = process_accepted_credit_cards(params[:externals_gb_primepay_merchant][:accepted_credit_cards])

  @merchant = Externals::GbPrimepay::Merchant.new(permitted_param.merge(accepted_credit_cards: accepted_credit_cards))
  if @merchant.valid? && @merchant.save
    update_restaurants(@merchant,
                       params.require(:externals_gb_primepay_merchant).permit(restaurants_attributes: [:id,
                                                                                                       :_destroy])[:restaurants_attributes]&.values)
    redirect_to [:admin, @merchant], notice: 'Create successfully'
  else
    flash[:alert] = @merchant.errors.full_messages.to_sentence
    render :edit
  end
end

#destroyObject



64
65
66
67
68
69
70
# File 'app/controllers/admin/externals/gb_primepay/merchants_controller.rb', line 64

def destroy
  if merchant.destroy
    redirect_to admin_externals_gb_primepay_merchants_path, notice: 'Deleted successfully'
  else
    redirect_to admin_externals_gb_primepay_merchants_path, alert: merchant.errors.full_messages.to_sentence
  end
end

#editObject



15
16
17
# File 'app/controllers/admin/externals/gb_primepay/merchants_controller.rb', line 15

def edit
  set_meta_tags title: "Edit GB Primepay Merchants #{merchant.name}"
end

#indexObject



6
7
8
9
10
11
12
13
# File 'app/controllers/admin/externals/gb_primepay/merchants_controller.rb', line 6

def index
  set_meta_tags title: 'GB Primepay Merchants Overview'
  @grid = ::Admin::Externals::GbPrimepay::MerchantsGrid.new(params[:branches_grid]) do |scope|
    scope.page(params[:page]).per(50)
  end
  etag = CityHash.hash32([self.class.to_s, @grid.assets.cache_key, params])
  return unless stale?(etag: etag)
end

#newObject



19
20
21
22
23
# File 'app/controllers/admin/externals/gb_primepay/merchants_controller.rb', line 19

def new
  set_meta_tags title: 'Add new GB Primepay Merchants'
  @merchant = Externals::GbPrimepay::Merchant.new
  @merchant.restaurants.build
end

#showObject



60
61
62
# File 'app/controllers/admin/externals/gb_primepay/merchants_controller.rb', line 60

def show
  set_meta_tags title: "#{merchant.name} GB Primepay Merchant"
end

#updateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/admin/externals/gb_primepay/merchants_controller.rb', line 25

def update
  accepted_credit_cards = process_accepted_credit_cards(params[:externals_gb_primepay_merchant][:accepted_credit_cards])

  if keys_changed? && !validate_users
    flash[:alert] = 'Unauthorized Access: You do not have permission to edit the Keys.'
    render :edit
    return
  end

  if @merchant.update(permitted_param.merge(accepted_credit_cards: accepted_credit_cards))
    update_restaurants(@merchant,
                       params.require(:externals_gb_primepay_merchant).permit(restaurants_attributes: [:id,
                                                                                                       :_destroy])[:restaurants_attributes]&.values)
    redirect_to [:admin, @merchant], notice: 'Updated successfully'
  else
    flash[:alert] = @merchant.errors.full_messages.to_sentence
    render :edit
  end
end