Class: Kaui::RefundsController

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



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/kaui/refunds_controller.rb', line 17

def create
  invoice = Kaui::Invoice.find_by_id(params.require(:invoice_id), true, 'NONE', options_for_klient)

  if params[:adjustment_type] == 'invoiceItemAdjustment'
    items = []
    (params.to_unsafe_h[:adjustments] || []).each do |ii|
      original_item = find_original_item(invoice.items, ii[0])

      item = KillBillClient::Model::InvoiceItem.new
      item.invoice_item_id = ii[0]
      # If we tried to do a partial item adjustment, we pass the value, if not we don't send any value and let the system
      # decide what is the maximum amount we can have on that item
      item.amount = (ii[1].to_f == original_item.amount) ? nil : ii[1]

      items << item
    end
  end

  KillBillClient::Model::InvoicePayment.refund(params.require(:payment_id), params[:amount], items, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
  redirect_to kaui_engine.(invoice., invoice.invoice_id), :notice => 'Refund created'
end

#newObject



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

def new
  cached_options_for_klient = options_for_klient

  fetch_invoice = promise { Kaui::Invoice.find_by_id(params.require(:invoice_id), true, 'NONE', cached_options_for_klient) }
  fetch_payment = promise { Kaui::InvoicePayment::find_by_id(params.require(:payment_id), false, false, cached_options_for_klient) }
  fetch_bundles = promise { @account.bundles(cached_options_for_klient) }

  @invoice = wait(fetch_invoice)
  @payment = wait(fetch_payment)
  @bundles = wait(fetch_bundles)

  @refund = KillBillClient::Model::InvoiceItem.new(:invoice_id => @invoice.invoice_id)
end