Class: Kaui::TransactionsController

Inherits:
EngineController show all
Defined in:
app/controllers/kaui/transactions_controller.rb

Constant Summary

Constants included from EngineControllerUtil

EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD

Instance Method Summary collapse

Methods inherited from EngineController

#check_for_redirect_to_tenant_screen, #current_ability, #current_user, #options_for_klient, #populate_account_details, #retrieve_allowed_users_for_current_user, #retrieve_tenants_for_current_user

Instance Method Details

#createObject



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

def create
  transaction = Kaui::Transaction.new(params[:transaction].delete_if { |_key, value| value.blank? })

  plugin_properties = params[:plugin_properties].values.reject { |item| (item['value'].blank? || item['key'].blank?) } unless params[:plugin_properties].blank?
  unless plugin_properties.blank?
    plugin_properties.map! do |property|
      KillBillClient::Model::PluginPropertyAttributes.new(property)
    end
  end

  options = plugin_properties.blank? ? options_for_klient : { pluginProperty: plugin_properties }.merge(options_for_klient)

  control_plugin_names = params[:control_plugin_names].reject(&:blank?) unless params[:control_plugin_names].blank?
  options.merge!({ controlPluginNames: control_plugin_names }) unless control_plugin_names.blank?

  payment = transaction.create(params.require(:account_id), params[:payment_method_id], current_user.kb_username, params[:reason], params[:comment], options)
  redirect_to kaui_engine.(payment., payment.payment_id), notice: 'Transaction successfully created'
end

#fix_transaction_stateObject



45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/kaui/transactions_controller.rb', line 45

def fix_transaction_state
  transaction = Kaui::Transaction.new(params[:transaction].delete_if { |_key, value| value.blank? })
  payment_id = transaction.payment_id
  transaction_id = transaction.transaction_id
  transaction_status = transaction.status

  Kaui::Admin.fix_transaction_state(payment_id, transaction_id, transaction_status, current_user.kb_username, params[:reason], params[:comment], options_for_klient)

  redirect_to kaui_engine.(params.require(:account_id), payment_id), notice: "Transaction successfully transitioned to #{transaction_status}"
end

#newObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/kaui/transactions_controller.rb', line 10

def new
  @account_id = params[:account_id]
  @payment_method_id = params[:payment_method_id]

  transaction_id = params[:transaction_id].presence
  if transaction_id.nil?
    @transaction = Kaui::Transaction.new(payment_id: params[:payment_id],
                                         amount: params[:amount],
                                         currency: params[:currency],
                                         transaction_type: params[:transaction_type])
  else
    payment = Kaui::Payment.find_by_transaction_id(transaction_id, false, false, options_for_klient)
    @transaction = Kaui::Transaction.build_from_raw_transaction(payment.transactions.find { |tx| tx.transaction_id == transaction_id })
  end
end

#restful_showObject



5
6
7
8
# File 'app/controllers/kaui/transactions_controller.rb', line 5

def restful_show
  payment = Kaui::Payment.find_by_transaction_id(params.require(:id), false, true, options_for_klient)
  redirect_to (payment., payment.payment_id)
end