Class: Aviate::WalletsController
Instance Method Summary
collapse
#as_string, #aviate_authentication, #current_tenant_user, #external_paginate, #layout, #log_rescue_error
Instance Method Details
#create ⇒ Object
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_wallets_path(@account.account_id)
end
end
|
#index ⇒ Object
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
|
#new ⇒ Object
15
16
17
|
# File 'app/controllers/aviate/wallets_controller.rb', line 15
def new
@currency = @account.currency
end
|
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'app/controllers/aviate/wallets_controller.rb', line 68
def
cached_options_for_klient = options_for_klient
account_id = params[:account_id]
searcher = lambda do |search_key|
WalletApi.retrieve_wallets(search_key, cached_options_for_klient)
end
formatter = lambda do |wallet|
Aviate.account_wallets_columns.call(wallet, account_id, view_context)[1]
end
external_paginate account_id, searcher, formatter
end
|
#show ⇒ Object
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_config ⇒ Object
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_wallets_path(@account.account_id)
end
|