lib/app_manager/model.rb in app_manager-2.2.0 vs lib/app_manager/model.rb in app_manager-2.2.2

- old
+ new

@@ -146,11 +146,11 @@ if shop_plan_id && shop_domain plan_obj = AppManager::Client.new plan_obj.cancel_charge(shop_domain, shop_plan_id) end rescue Exception => e - return "#{e.inspect}" + return "#{e.inspect}-#{e.backtrace}" end end def cancel_current_shopify_charge begin @@ -168,11 +168,11 @@ AppManager.clear_cache end end end rescue Exception => e - return "#{e.inspect}" + return "#{e.inspect}-#{e.backtrace}" end end def get_current_shopify_charge begin @@ -180,11 +180,11 @@ data = gq_obj.recurring_charge_current_api_call(self) if !data["errors"].present? && (data["data"].present? && data["data"]["currentAppInstallation"].present? && data["data"]["currentAppInstallation"]["activeSubscriptions"].present?) return data["data"]["currentAppInstallation"]["activeSubscriptions"].first end rescue Exception => e - Rollbar.error("Warning in APP MANAGER, trying to get_current_shopify_charge >>>> #{e.inspect}") + Rollbar.error("Warning in APP MANAGER, trying to get_current_shopify_charge >>>> #{e.inspect}-#{e.backtrace}") return nil end end def get_active_charge_app_manager @@ -215,15 +215,36 @@ end end end return charge_updated rescue Exception => e - Rollbar.error("Warning in APP MANAGER, trying to get update_app_manager_charge >>>> #{e.inspect}") + Rollbar.error("Warning in APP MANAGER, trying to get update_app_manager_charge >>>> #{e.inspect}-#{e.backtrace}") return nil end end + def update_app_manager_charge_with_plan_id(current_shopify_charge_id=nil,shop_custom_plan_id=nil) + charge_updated = nil + begin + shop_plan_id = self[AppManager.configuration.plan_id_or_name_field] + shop_domain = self[AppManager.configuration.shopify_domain_field] + current_charge_id = current_shopify_charge_id.present? ? current_shopify_charge_id : active_shopify_charge_id + plan_id = shop_custom_plan_id.present? ? shop_custom_plan_id : shop_plan_id + if current_charge_id.present? + if plan_id.present? + if charge_update_call(self,plan_id,current_charge_id) + charge_updated = true + end + end + end + return charge_updated + rescue Exception => e + Rollbar.error("Warning in APP MANAGER, trying to get update_app_manager_charge_with_plan_id >>>> #{e.inspect}-#{e.backtrace}") + return nil + end + end + def active_shopify_charge_id begin get_active_shopify_charge = self.get_current_shopify_charge if get_active_shopify_charge.present? && !get_active_shopify_charge.nil? current_shopify_charge_id = get_active_shopify_charge["id"] @@ -234,11 +255,11 @@ end else return nil end rescue Exception => e - Rollbar.error("Warning in APP MANAGER, trying to get active shopify charge id >>>> #{e.inspect}") + Rollbar.error("Warning in APP MANAGER, trying to get active shopify charge id >>>> #{e.inspect}-#{e.backtrace}") return nil end end def app_manager_charge_update(shop,shopify_current_charge_obj) @@ -298,19 +319,20 @@ "charge" => charge, "previous_charge" => charge_data ? (charge_data['cancelled_charge'] || nil) : nil, "shopify_domain" => shop_domain }) rescue Exception => e - Rollbar.error("Warning in APP MANAGER model Charge Created Callback Event Fire>>>> #{e.inspect}") + Rollbar.error("Warning in APP MANAGER model Charge Created Callback Event Fire>>>> #{e.inspect}-#{e.backtrace}") end + Thread.exit # Terminate the thread once processing is done end end end end return charge_callback_done # rescue Exception => e - # Rollbar.error("Warning in APP MANAGER model charge_callback, trying to update active shopify charge in app manager>>>> #{e.inspect}") + # Rollbar.error("Warning in APP MANAGER model charge_callback, trying to update active shopify charge in app manager>>>> #{e.inspect}-#{e.backtrace}") # return nil # end end def active_shopfiy_charge_full @@ -349,11 +371,11 @@ else self.plan_id = plan_id self.save end rescue Exception => e - return "#{e.inspect}" + return "#{e.inspect}-#{e.backtrace}" end end def get_plans_by_features(feature_slugs, params = "false") @@ -363,13 +385,13 @@ shop_domain = self[AppManager.configuration.shopify_domain_field] plan_obj = AppManager::Client.new plans = plan_obj.get_plans(shop_domain) plans = plans.select { |x| x['interval'] == 'EVERY_30_DAYS' && x['public'] == true } plans.each do |plan| - next if (params && !params.nil? && params == "exclude_current_plan" && !shop_plan_id.nil? && plan["id"] == shop_plan_id) + next if (params && !params.nil? && params == "exclude_current_plan" && !shop_plan_id.nil? && !plan["id"].nil? && plan["id"] == shop_plan_id) if plan && (plan['features'] && plan['features'].any?) && (plan['features'].values && plan['features'].values.any?) && (plan['features'].values.collect { |c| c['slug'] } && plan['features'].values.collect { |c| c['slug'] }.any?) plan_feature_slugs = plan['features'].values.collect { |c| c['slug'] }.sort - if (feature_slugs & plan_feature_slugs).any? && ((feature_slugs & plan_feature_slugs).sort == feature_slugs.sort) + if plan_feature_slugs && (feature_slugs & plan_feature_slugs).any? && ((feature_slugs & plan_feature_slugs).sort == feature_slugs.sort) plan_data.push(plan) end end end return plan_data