kaui 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,11 +28,15 @@ class Kaui::AccountsController < Kaui::EngineController
28
28
  begin
29
29
  @tags = Kaui::KillbillHelper::get_tags_for_account(@account.account_id).sort
30
30
  @account_emails = Kaui::AccountEmail.where(:account_id => @account.account_id)
31
- @payment_methods = Kaui::KillbillHelper::get_payment_methods(@account.account_id)
31
+ @payment_methods = Kaui::KillbillHelper::get_non_external_payment_methods(@account.account_id)
32
32
  @bundles = Kaui::KillbillHelper::get_bundles(@account.account_id)
33
+
34
+ @overdue_state_by_bundle_id = {}
33
35
  @subscriptions_by_bundle_id = {}
34
36
 
35
37
  @bundles.each do |bundle|
38
+ @overdue_state_by_bundle_id[bundle.bundle_id] = Kaui::KillbillHelper::get_overdue_state_for_bundle(bundle.bundle_id)
39
+
36
40
  subscriptions = Kaui::KillbillHelper::get_subscriptions_for_bundle(bundle.bundle_id)
37
41
  if subscriptions.present?
38
42
  @subscriptions_by_bundle_id[bundle.bundle_id.to_s] = (@subscriptions_by_bundle_id[bundle.bundle_id.to_s] || []) + subscriptions
@@ -54,7 +58,7 @@ class Kaui::AccountsController < Kaui::EngineController
54
58
  @account_id = params[:id]
55
59
  if @account_id.present?
56
60
  begin
57
- @payment_methods = Kaui::KillbillHelper::get_payment_methods(@account_id)
61
+ @payment_methods = Kaui::KillbillHelper::get_non_external_payment_methods(@account_id)
58
62
  rescue => e
59
63
  flash[:error] = "Error while getting payment methods: #{as_string(e)}"
60
64
  end
@@ -15,6 +15,7 @@ class Kaui::BundlesController < Kaui::EngineController
15
15
  if @bundle.present?
16
16
  @account = Kaui::KillbillHelper::get_account_by_bundle_id(@bundle.bundle_id)
17
17
  @subscriptions = Kaui::KillbillHelper::get_subscriptions_for_bundle(@bundle.bundle_id)
18
+ @overdue_state = Kaui::KillbillHelper::get_overdue_state_for_bundle(@bundle.bundle_id)
18
19
  else
19
20
  flash[:error] = "Bundle #{key} not found"
20
21
  render :action => :index
@@ -331,6 +331,10 @@ module Kaui
331
331
  "X-Killbill-Comment" => "#{comment}"
332
332
  end
333
333
 
334
+ def self.get_non_external_payment_methods(account_id)
335
+ self.get_payment_methods(account_id).reject { |x| x.plugin_name == '__EXTERNAL_PAYMENT__' }
336
+ end
337
+
334
338
  def self.get_payment_methods(account_id)
335
339
  data = call_killbill :get, "/1.0/kb/accounts/#{account_id}/paymentMethods?withPluginInfo=true"
336
340
  process_response(data, :multiple) {|json| Kaui::PaymentMethod.new(json) }
@@ -490,6 +494,13 @@ module Kaui
490
494
  end
491
495
  end
492
496
 
497
+ ############## OVERDUE ##############
498
+
499
+ def self.get_overdue_state_for_bundle(bundle_id)
500
+ data = call_killbill :get, "/1.0/kb/overdue/bundles/#{bundle_id}"
501
+ process_response(data, :single) { |json| Kaui::OverdueState.new(json) }
502
+ end
503
+
493
504
  ############## ANALYTICS ##############
494
505
 
495
506
  def self.get_accounts_created_over_time
@@ -1,9 +1,5 @@
1
1
  class Kaui::BillCycleDay < Kaui::Base
2
+
2
3
  define_attr :day_of_month_local
3
4
  define_attr :day_of_month_utc
4
-
5
- def initialize(data = {})
6
- super(:day_of_month_local => data['dayOfMonthLocal'],
7
- :day_of_month_utc => data['dayOfMonthUTC'])
8
- end
9
5
  end
@@ -0,0 +1,10 @@
1
+ class Kaui::OverdueState < Kaui::Base
2
+
3
+ define_attr :name
4
+ define_attr :external_message
5
+ define_attr :days_between_payment_retries
6
+ define_attr :disable_entitlement_and_changes_blocked
7
+ define_attr :block_changes
8
+ define_attr :clear_state
9
+ define_attr :reevaluation_interval_days
10
+ end
@@ -65,7 +65,14 @@
65
65
  <% @bundles.each do |bundle| %>
66
66
  <% subs = @subscriptions_by_bundle_id[bundle.bundle_id] %>
67
67
  <% if subs.present? %>
68
- <h2>Bundle <%= link_to Kaui.bundle_key_display_string.call(bundle.external_key), Kaui.bundle_home_path.call(bundle.bundle_id) if bundle.external_key.present? %>&nbsp;</h2>
68
+ <h2>Bundle <%= link_to Kaui.bundle_key_display_string.call(bundle.external_key), Kaui.bundle_home_path.call(bundle.bundle_id) if bundle.external_key.present? %>&nbsp;</h2>Overdue state:
69
+ <% if @overdue_state_by_bundle_id[bundle.bundle_id].nil? %>
70
+ unknown
71
+ <% elsif @overdue_state_by_bundle_id[bundle.bundle_id].clear_state %>
72
+ <span class='label label-success'>Good</span>
73
+ <% else %>
74
+ <span class='label label-important'><%= @overdue_state_by_bundle_id[bundle.bundle_id].name %></span>
75
+ <% end %>
69
76
  <%= render :partial => "kaui/subscriptions/subscriptions_table", :locals => { :subscriptions => subs } %>
70
77
  <% end %>
71
78
  <% end %>
@@ -7,7 +7,15 @@
7
7
  <dd><%= link_to @account.email, Kaui.account_home_path.call(@account.external_key) %>&nbsp;</dd>
8
8
  <dt>Bundle key:</dt>
9
9
  <dd><%= @bundle.external_key %>&nbsp;</dd>
10
- <dd><%= link_to "Transfer Ownership", kaui_engine.transfer_bundle_path(@bundle.bundle_id), :class => "btn btn-mini" %></dd>
10
+ <dt>Overdue status:</dt>
11
+ <% if @overdue_state.nil? %>
12
+ <dd>unknown<dd>
13
+ <% elsif @overdue_state.clear_state %>
14
+ <dd><span class='label label-success'>Good</span><dd>
15
+ <% else %>
16
+ <dd><span class='label label-important'><%= @overdue_state.name %></span><dd>
17
+ <% end %>
18
+ <%= link_to "Transfer Ownership", kaui_engine.transfer_bundle_path(@bundle.bundle_id), :class => "btn btn-mini" %></dd>
11
19
  <% if @subscriptions.present? %>
12
20
  <%= render :partial => "kaui/subscriptions/subscriptions_table", :locals => { :subscriptions => @subscriptions } %>
13
21
  <% end %>
data/lib/kaui/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kaui
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end