Class: Kaui::Bundle
- Inherits:
-
KillBillClient::Model::Bundle
- Object
- KillBillClient::Model::Bundle
- Kaui::Bundle
- Defined in:
- app/models/kaui/bundle.rb
Constant Summary collapse
- SEARCH_FIELDS =
[ ['bundle_id', 'Bundle ID'], ['bundle_external_key', 'Bundle External Key'], ['subscription_id', 'Subscription ID'], ['subscription_external_key', 'Subscription External Key'] ].freeze
Class Method Summary collapse
- .find_by_id_or_key(bundle_id_or_key, options = {}) ⇒ Object
- .get_active_bundle_or_latest_created(bundles, time_zone = nil) ⇒ Object
- .list_or_search(search_key = nil, offset = 0, limit = 10, options = {}) ⇒ Object
- .list_transfer_policy_params ⇒ Object
- .list_transfer_policy_params_keys ⇒ Object
Class Method Details
.find_by_id_or_key(bundle_id_or_key, options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/kaui/bundle.rb', line 11 def self.find_by_id_or_key(bundle_id_or_key, = {}) if /[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}/.match?(bundle_id_or_key) bundle = begin find_by_id(bundle_id_or_key, ) rescue StandardError nil end return bundle unless bundle.nil? end # Return the active one find_by_external_key(bundle_id_or_key, false, ) end |
.get_active_bundle_or_latest_created(bundles, time_zone = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/models/kaui/bundle.rb', line 33 def self.get_active_bundle_or_latest_created(bundles, time_zone = nil) return nil if bundles.empty? latest_start_date = nil latest_bundle = nil bundles.each do |b| b.subscriptions.each do |s| next unless s.product_category != 'ADD_ON' if latest_start_date.nil? || latest_start_date < s.start_date latest_start_date = s.start_date latest_bundle = b end return b if s.cancelled_date.nil? || s.cancelled_date > ActionController::Base.helpers.current_time(time_zone) end end latest_bundle end |
.list_or_search(search_key = nil, offset = 0, limit = 10, options = {}) ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/models/kaui/bundle.rb', line 25 def self.list_or_search(search_key = nil, offset = 0, limit = 10, = {}) if search_key.present? find_in_batches_by_search_key(search_key, offset, limit, ) else find_in_batches(offset, limit, ) end end |
.list_transfer_policy_params ⇒ Object
55 56 57 58 59 60 61 |
# File 'app/models/kaui/bundle.rb', line 55 def self.list_transfer_policy_params [ # [I18n.translate('start_of_term'), 'START_OF_TERM'], Temporarily removed as it is not supported by Kill Bill [I18n.t('end_of_term'), 'END_OF_TERM'], [I18n.t('immediate'), 'IMMEDIATE'] ] end |
.list_transfer_policy_params_keys ⇒ Object
63 64 65 |
# File 'app/models/kaui/bundle.rb', line 63 def self.list_transfer_policy_params_keys %w[END_OF_TERM IMMEDIATE] end |