lib/app_manager/model.rb in app_manager-1.2.5 vs lib/app_manager/model.rb in app_manager-1.2.6

- old
+ new

@@ -3,11 +3,11 @@ extend ActiveSupport::Concern @@remaining_cache_key = "get_remaining_days_key" @@get_charge_key = "get_charge_key" - def has_plan + def has_plan_old if !self[AppManager.configuration.plan_id_or_name_field] return false; end if self[AppManager.configuration.field_names['grandfathered']] return true; @@ -26,10 +26,24 @@ # active_charge = plan_obj.get_charge(shop_domain) rescue nil active_charge = fetch_static_get_charge return active_charge && active_charge['active_charge'].present? && !active_charge['active_charge'].nil? ? true : false end + def has_plan + plan_id = self[AppManager.configuration.plan_id_or_name_field] + if !plan_id + return false; + end + grandfathered = self[AppManager.configuration.field_names['grandfathered']] + grandfathered = grandfathered ? 1 : 0 + shop_domain = self[AppManager.configuration.shopify_domain_field] + trial_activated_at_field = AppManager.configuration.field_names['trial_activated_at'] + trial_activated_at_val = self[trial_activated_at_field] + plan_obj = AppManager::Client.new + response = plan_obj.has_plan(shop_domain,plan_id,trial_activated_at_val,grandfathered) + return (response && response['has_plan']) || false + end def plan_features plan_id = self[AppManager.configuration.plan_id_or_name_field] if !plan_id @@ -49,11 +63,11 @@ end def has_feature(slug) - self.plan_features.select{|x| x['slug'].to_s == slug }.size > 0 + self.plan_features.any? && self.plan_features.select{|x| x['slug'].to_s == slug }.size > 0 ? true : false end def get_feature(slug) plan_features = self.plan_features @@ -65,20 +79,17 @@ nil end end def get_remaining_days - begin shop_domain = self[AppManager.configuration.shopify_domain_field] trial_activated_at_field = AppManager.configuration.field_names['trial_activated_at'] trial_activated_at_val = self[trial_activated_at_field] plan_field = AppManager.configuration.field_names['plan_id'] plan_id = self[plan_field] plan_obj = AppManager::Client.new - return shop_domain ? plan_obj.get_remaining_days(shop_domain,trial_activated_at_val,plan_id) : 0 - rescue Exception => e - return "#{e.inspect}" - end + res = plan_obj.get_remaining_days(shop_domain,trial_activated_at_val,plan_id) + return (res && !res.nil?) ? res : 0 end def get_plan(plan_id=nil) req_plan_id = nil \ No newline at end of file