Class: Aviate::WalletsController

Inherits:
EngineController show all
Defined in:
app/controllers/aviate/wallets_controller.rb

Instance Method Summary collapse

Methods inherited from EngineController

#as_string, #aviate_authentication, #current_tenant_user, #external_paginate, #layout, #log_rescue_error

Instance Method Details

#createObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/aviate/wallets_controller.rb', line 44

def create
  cached_options_for_klient = options_for_klient
  wallet = {
    currency: @account.currency,
    credit_type: params.require(:credit_type),
    amount: params.require(:amount),
    exp_date: params.require(:exp_date).to_time.utc.iso8601,
    top_off_type: params.require(:top_off_type),
    low_watermark: params.require(:low_watermark),
    top_off_amount: params.require(:top_off_amount),
    exp_duration_unit: params.require(:exp_duration_unit),
    exp_duration_length: params.require(:exp_duration_length)
  }
  response = Aviate::WalletApi.create_wallet(params[:account_id], wallet, cached_options_for_klient)
  if response['status'] == 'WALLET_FAILED'
    flash[:error] = response['errorMessage']
    render :new
  elsif response['wallet'].present?
    flash[:error] = response['errorMessage'] if response['errorMessage'].present?
    flash[:notice] = t('flashes.notices.wallet_created_successfully')
    redirect_to (@account.)
  end
end

#indexObject



7
8
9
10
11
12
13
# File 'app/controllers/aviate/wallets_controller.rb', line 7

def index
  @search_query = params[:account_id]
  @account_id = params[:account_id]
  @ordering = params[:ordering] || (@search_query.blank? ? 'desc' : 'asc')
  @offset = params[:offset] || 0
  @limit = params[:limit] || 5
end

#newObject



15
16
17
# File 'app/controllers/aviate/wallets_controller.rb', line 15

def new
  @currency = @account.currency
end

#paginationObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/aviate/wallets_controller.rb', line 68

def pagination
  cached_options_for_klient = options_for_klient
   = params[:account_id]
  searcher = lambda do |search_key|
    WalletApi.retrieve_wallets(search_key, cached_options_for_klient)
  end

  formatter = lambda do |wallet|
    Aviate..call(wallet, , view_context)[1]
  end

  external_paginate , searcher, formatter
end

#showObject



37
38
39
40
41
42
# File 'app/controllers/aviate/wallets_controller.rb', line 37

def show
  wallets = Aviate::WalletApi.retrieve_wallets(params['account_id'], options_for_klient)
  @wallet = wallets.find { |wallet| wallet['walletId'] == params['id'] }
  @wallet = Aviate::Wallet.from_api_response(@wallet)
  @wallet
end

#top_off_configObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/aviate/wallets_controller.rb', line 19

def top_off_config
  update_params = {
    wallet_id: params.require(:wallet_id),
    top_off_type: params.require(:top_off_type),
    low_watermark: params.require(:low_watermark),
    top_off_amount: params.require(:top_off_amount),
    exp_duration_unit: params.require(:exp_duration_unit),
    exp_duration_length: params.require(:exp_duration_length)
  }
  response_code = Aviate::WalletApi.modify_wallet(update_params, options_for_klient)
  if response_code == '200'
    flash[:notice] = t('flashes.notices.wallet_updated_successfully')
  else
    flash[:error] = t('flashes.errors.wallet_update_failed')
  end
  redirect_to kaui_engine.(@account.)
end