Class: Kaui::ChargesController

Inherits:
EngineController show all
Defined in:
app/controllers/kaui/charges_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


19
20
21
22
23
24
25
26
27
# File 'app/controllers/kaui/charges_controller.rb', line 19

def create
  charge = Kaui::InvoiceItem.new(params.require(:invoice_item).delete_if { |key, value| value.blank? })
  charge. ||= params.require(:account_id)

  auto_commit = params[:auto_commit] == '1'

  charge = charge.create(auto_commit, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
  redirect_to kaui_engine.(charge., charge.invoice_id), :notice => 'Charge was successfully created'
end

#newObject


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/kaui/charges_controller.rb', line 3

def new
  invoice_id = params[:invoice_id]
  amount = params[:amount]

  if invoice_id.present?
    @invoice = Kaui::Invoice.find_by_id(invoice_id, 'NONE', options_for_klient)
    amount ||= @invoice.balance
    currency = @invoice.currency
  else
    @invoice = nil
    currency = params[:currency] || 'USD'
  end

  @charge = Kaui::InvoiceItem.new(:account_id => params.require(:account_id), :invoice_id => invoice_id, :amount => amount, :currency => currency)
end