Class: Aviate::WalletsController
- Inherits:
-
EngineController
- Object
- EngineController
- Aviate::WalletsController
- Defined in:
- app/controllers/aviate/wallets_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #pagination ⇒ Object
- #show ⇒ Object
- #top_off_config ⇒ Object
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 = 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, ) 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
22 23 24 |
# File 'app/controllers/aviate/wallets_controller.rb', line 22 def new @currency = @account.currency end |
#pagination ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/aviate/wallets_controller.rb', line 68 def pagination = account_id = params[:account_id] searcher = lambda do |search_key| WalletApi.retrieve_wallets(search_key, ) 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
15 16 17 18 19 20 |
# File 'app/controllers/aviate/wallets_controller.rb', line 15 def show wallets = Aviate::WalletApi.retrieve_wallets(params['account_id'], ) @wallet = wallets.find { |wallet| wallet['walletId'] == params['id'] } @wallet = Aviate::Wallet.from_api_response(@wallet) @wallet end |
#top_off_config ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/aviate/wallets_controller.rb', line 26 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, ) if response_code == '200' flash[:notice] = t('flashes.notices.wallet_updated_successfully') else flash[:error] = t('flashes.errors.wallet_update_failed') end redirect_to account_wallets_path(@account.account_id) end |