Class: Kaui::RefundsController

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

Instance Method Summary collapse

Methods inherited from EngineController

#current_ability, #current_user, #options_for_klient

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/kaui/refunds_controller.rb', line 20

def create
  invoice = Kaui::Invoice.find_by_id_or_number(params[:invoice_id], true, 'NONE', options_for_klient)

  items = []
  if params[:adjustment_type] == 'invoiceItemAdjustment'
    (params[: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

  begin
    KillBillClient::Model::InvoicePayment.refund(params[:payment_id], params[:amount], items, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
    flash[:notice] = 'Refund created'
  rescue => e
    flash[:error] = "Error while processing refund: #{as_string(e)}"
  end

  redirect_to kaui_engine.(:id => params[:account_id])
end

#newObject



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

def new
  payment_id = params[:payment_id]
  invoice_id = params[:invoice_id]
   = params[:account_id]

  @refund = KillBillClient::Model::InvoiceItem.new

  begin
    @account = Kaui::Account.find_by_id(, false, false, options_for_klient)
    @payment = Kaui::InvoicePayment::find_by_id(payment_id, false, options_for_klient)
    @invoice = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
  rescue => e
    flash[:error] = "Error while processing refund: #{as_string(e)}"
    redirect_to kaui_engine.(:id => )
  end
end