Class: Kaui::CreditsController

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

Instance Method Summary collapse

Methods inherited from EngineController

#current_user

Methods included from ErrorHelper

#as_string

Instance Method Details

#createObject



40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/kaui/credits_controller.rb', line 40

def create
  credit = Kaui::Credit.new(params[:credit])
  begin
    Kaui::KillbillHelper::create_credit(credit, current_user, params[:reason], params[:comment])
     = Kaui::KillbillHelper::(credit.)
    flash[:info] = "Credit created"
  rescue => e
    flash[:error] = "Error while starting to create credit: #{as_string(e)}"
  end
  redirect_to Kaui..call(.external_key)
end

#newObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/kaui/credits_controller.rb', line 23

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

  begin
    @account = Kaui::KillbillHelper::(@account_id)
    @invoice = Kaui::KillbillHelper::get_invoice(@invoice_id) unless @invoice_id.nil?
  rescue => e
    flash[:error] = "Error while starting to create credit: #{as_string(e)}"
  end

  credit_amount = @invoice.balance unless @invoice.nil?

  @credit = Kaui::Credit.new("accountId" => @account_id, "invoiceId" => @invoice_id,
                             "creditAmount" => credit_amount, "effectiveDate" => Time.now.utc.iso8601)
end

#showObject



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

def show
  @account_id = params[:account_id]
  @invoice_id = params[:invoice_id]

  if params.has_key?(:account_id)
    begin
    # invoice id can be nil for account level credit
      data = Kaui::KillbillHelper::get_credits(@account_id, @invoice_id)
    rescue => e
      flash[:error] = "Error getting credit information: #{as_string(e)}"
    end
    if data.present?
      @credit = Kaui::Credit.new(data)
    else
      Rails.logger.warn("Did not get back external payments #{response_body}")
    end
  else
    flash[:notice] = "No id given"
  end
end