Class: Kaui::BundlesController

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

Instance Method Summary collapse

Methods inherited from EngineController

#current_user

Methods included from ErrorHelper

#as_string

Instance Method Details

#do_transferObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/kaui/bundles_controller.rb', line 44

def do_transfer
  bundle_id = params[:id]
  key = params[:new_account_key]
  if key.present?
    begin
      result = Kaui::KillbillHelper.(key)
    rescue => e
      flash[:error] = "Error while retrieving account for #{key}: #{as_string(e)}"
      render :action => :index
      return
    end
    if bundle_id.present? && result.is_a?(Kaui::Account)
      @new_account = result
      begin
        Kaui::KillbillHelper::transfer_bundle(bundle_id, @new_account.)
        flash[:info] = "Bundle transfered successfully"
      rescue => e
        flash[:error] = "Error transfering bundle #{as_string(e)}"
      end
      redirect_to Kaui..call(@new_account.external_key)
      return
    else
      flash[:error] = "Could not retrieve account #{result}"
    end
  else
    flash[:error] = "No account key given"
  end

  begin
    @bundle = Kaui::KillbillHelper::get_bundle(bundle_id)
    @account = Kaui::KillbillHelper::(bundle_id)
  rescue => e
    flash[:error] = "Error while redirecting: #{as_string(e)}"
    render :transfer
  end
end

#indexObject



3
4
5
6
7
# File 'app/controllers/kaui/bundles_controller.rb', line 3

def index
  if params[:bundle_id].present?
    redirect_to kaui_engine.bundle_path(params[:bundle_id])
  end
end

#showObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/kaui/bundles_controller.rb', line 9

def show
  key = params[:id]
  if key.present?
    begin
      @bundle = Kaui::KillbillHelper::get_bundle_by_key(key, params[:account_id])

      if @bundle.present?
        @account = Kaui::KillbillHelper::(@bundle.bundle_id)
        @subscriptions = Kaui::KillbillHelper::get_subscriptions_for_bundle(@bundle.bundle_id)
        @overdue_state = Kaui::KillbillHelper::get_overdue_state_for_bundle(@bundle.bundle_id)
      else
        flash[:error] = "Bundle #{key} not found"
        render :action => :index
      end
    rescue => e
      flash[:error] = "Error while retrieving bundle information for #{key}: #{as_string(e)}"
    end
  else
    flash[:error] = "No id given"
  end
end

#transferObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/kaui/bundles_controller.rb', line 31

def transfer
  bundle_id = params[:id]
  begin
    @bundle = Kaui::KillbillHelper::get_bundle(bundle_id)
    @account = Kaui::KillbillHelper::(bundle_id)
  rescue => e
    flash[:error] = "Error while preparing to transfer bundle: #{as_string(e)}"
  end
  if @account.nil?
    flash[:error] = "Account not found for bundle id #{bundle_id}"
  end
end