app_manager 1.3.5 → 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19143ee5bb30c0d6f1dce901a195eb9fe021ee4755dd752e45ee364f6146687d
4
- data.tar.gz: 99eecbe9df8a0263077579c308c8b1838c6bbbceec699ea7289dd806d0ce469d
3
+ metadata.gz: b0726560dff151c7c6b5e6fde4f510a43a28c0d3e299c2382ffeb43aea7f26b8
4
+ data.tar.gz: d02c49d7627c01fc7cc8096af135f36e39b0e1da002019034943abdb886d0a5b
5
5
  SHA512:
6
- metadata.gz: 8c264bf7f5b5d4d1f207a1d79dfcf398a624d077f2a4543cdbfacb7e06b39f26420c92aa8d654392a39a7db22c144b1810000533390531840b43150b526de3eb
7
- data.tar.gz: 044cf45961370e69beb87a761e74d7bb1a25e4674931195c2d0e49d786bfcb16aee1878a9e25e76bb0af1e3ece9034a24c7728ceabde5a991364560162d8c996
6
+ metadata.gz: 99ea34310c0c74e41115169a1a59b146ca75e06573383e2195aec671cc9938e8fb812a93783bf804dffc5eeeadd868b588d6c382fa231eeffd6118588d633f2a
7
+ data.tar.gz: 0c91a1c992a85cff1f4834985b65726bb3230d91948fd43109ec199ee25810514dc58242f7a2d30e7ce94db6c29056f9148093c2b3f1113ac95ab52cb72c87f8
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_manager (1.3.5)
4
+ app_manager (1.3.6)
5
+ activerecord-import (~> 1.4)
5
6
  httparty
6
7
  kaminari (>= 0.16.3)
7
8
  rails (>= 5.2.0)
@@ -62,6 +63,8 @@ GEM
62
63
  activerecord (7.0.3.1)
63
64
  activemodel (= 7.0.3.1)
64
65
  activesupport (= 7.0.3.1)
66
+ activerecord-import (1.4.0)
67
+ activerecord (>= 4.2)
65
68
  activestorage (7.0.3.1)
66
69
  actionpack (= 7.0.3.1)
67
70
  activejob (= 7.0.3.1)
@@ -92,7 +95,7 @@ GEM
92
95
  httparty (0.20.0)
93
96
  mime-types (~> 3.0)
94
97
  multi_xml (>= 0.5.2)
95
- i18n (1.11.0)
98
+ i18n (1.12.0)
96
99
  concurrent-ruby (~> 1.0)
97
100
  kaminari (1.2.2)
98
101
  activesupport (>= 4.1.0)
@@ -15,38 +15,39 @@ module AppManager
15
15
  plan_data = plan_obj.get_plan(params[:plan_id], params[:shop])
16
16
  # render json: plan_data and return #use this to test plan failsafe api
17
17
  if plan_data.present? && plan_data.is_a?(Hash)
18
- if plan_data['price'] == 0
19
- active_charge_data = plan_obj.get_charge(params[:shop])
20
- begin
21
- if active_charge_data && active_charge_data.any? && !active_charge_data['active_charge'].nil? && !active_charge_data['active_charge']['charge_id'].nil?
22
- gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain, @shop.shopify_token)
23
- rec_cancel_data = gq_obj.recurring_charge_cancel_api_call(active_charge_data['active_charge']['charge_id'], @shop)
24
- if !rec_cancel_data["errors"].present? && (rec_cancel_data["data"].present? && rec_cancel_data["data"]["appSubscriptionCancel"].present? && !rec_cancel_data["data"]["appSubscriptionCancel"]["userErrors"].any? && (rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["status"] == 'CANCELLED'))
25
- cancelled_charge_id = rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["id"].split('/')[-1]
26
- plan_obj.cancel_charge(params[:shop], cancelled_charge_id)
18
+ if plan_data['price'] == 0
19
+ active_charge_data = plan_obj.get_charge(params[:shop])
20
+ begin
21
+ if active_charge_data && active_charge_data.any? && !active_charge_data['active_charge'].nil? && !active_charge_data['active_charge']['charge_id'].nil?
22
+ gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain, @shop.shopify_token)
23
+ rec_cancel_data = gq_obj.recurring_charge_cancel_api_call(active_charge_data['active_charge']['charge_id'], @shop)
24
+ if !rec_cancel_data["errors"].present? && (rec_cancel_data["data"].present? && rec_cancel_data["data"]["appSubscriptionCancel"].present? && !rec_cancel_data["data"]["appSubscriptionCancel"]["userErrors"].any? && (rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["status"] == 'CANCELLED'))
25
+ cancelled_charge_id = rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["id"].split('/')[-1]
26
+ plan_obj.cancel_charge(params[:shop], cancelled_charge_id)
27
+ end
27
28
  end
29
+ rescue Exception => e
30
+ Rollbar.error("APP MANAGER Process Plan Failed #{e}")
28
31
  end
29
- rescue Exception => e
30
- Rollbar.error("APP MANAGER Process Plan Failed #{e}")
31
- end
32
32
 
33
- if @shop.update(@plan_field => params[:plan_id])
34
- begin
35
- AppManager::EventHandler.new('charge_created', {
36
- "plan" => plan_data,
37
- "charge" => nil,
38
- "previous_charge" => nil,
39
- "shopify_domain" => params[:shop]
40
- })
41
- rescue Exception => e
42
- Rollbar.error("APP MANAGER Error in Process Plan #{e}")
33
+ if @shop.update(@plan_field => params[:plan_id])
34
+ begin
35
+ AppManager::EventHandler.new('charge_created', {
36
+ "plan" => plan_data,
37
+ "charge" => nil,
38
+ "previous_charge" => nil,
39
+ "shopify_domain" => params[:shop]
40
+ })
41
+ rescue Exception => e
42
+ Rollbar.error("APP MANAGER Error in Process Plan #{e}")
43
+ end
44
+ AppManager.clear_cache
45
+ render json: {'redirect_url' => "#{app_url}?shop=#{params[:shop]}"} and return true
46
+ # render json: {'status' => true,'plan_type' =>'free_plan'} and return true
47
+ else
48
+ raise Error, "Invalid charge"
43
49
  end
44
- AppManager.clear_cache
45
- render json: {'redirect_url' => "#{app_url}?shop=#{params[:shop]}"} and return true
46
- else
47
- raise Error, "Invalid charge"
48
50
  end
49
- end
50
51
  request_data = {'shop' => @shop.shopify_domain, 'timestamp' => Time.now.to_i, 'plan' => params[:plan_id]}
51
52
  return_url = "#{app_url}#{plan_callback_path}?#{Rack::Utils.build_query(request_data)}"
52
53
  gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain, @shop.shopify_token)
@@ -91,30 +92,33 @@ module AppManager
91
92
  charge['shop_domain'] = params[:shop]
92
93
  charge['interval'] = plan_data['interval']['value']
93
94
 
94
- if !@plan_field.nil?
95
- begin
96
- plan_obj.cancel_charge(@shop[shopify_domain], @shop[@plan_field])
97
- rescue Exception => e
98
- Rollbar.error("APP MANAGER Error in Cancel charge >>>> #{e.inspect}")
99
- end
100
- end
95
+ # new_plan_obj = AppManager::Client.new
96
+ # if !@plan_field.nil?
97
+ # begin
98
+ # new_plan_obj.cancel_charge(@shop[shopify_domain], @shop[@plan_field])
99
+ # rescue Exception => e
100
+ # Rollbar.error("APP MANAGER Error in Cancel charge >>>> #{e.inspect}")
101
+ # end
102
+ # end
101
103
 
102
104
  charge_ob = AppManager::Client.new(nil, json_req = true)
103
105
  response = charge_ob.store_charge(charge.to_json)
104
106
 
105
107
  if response['message'] == "success"
106
108
  AppManager.clear_cache
107
- @shop.update(@plan_field => params[:plan],grandfathered_field => 0)
108
- charge_data = plan_obj.get_charge(@shop[shopify_domain])
109
- begin
110
- AppManager::EventHandler.new('charge_created', {
111
- "plan" => plan_data,
112
- "charge" => charge,
113
- "previous_charge" => charge_data ? (charge_data['cancelled_charge'] || nil) : nil,
114
- "shopify_domain" => params[:shop]
115
- })
116
- rescue Exception => e
117
- Rollbar.error("Error in APP MANAGER Charge Created Callback >>>> #{e.inspect}")
109
+ @shop.update(@plan_field => params[:plan],grandfathered_field => nil)
110
+ Thread.new do
111
+ charge_data = plan_obj.get_charge(@shop[shopify_domain])
112
+ begin
113
+ AppManager::EventHandler.new('charge_created', {
114
+ "plan" => plan_data,
115
+ "charge" => charge,
116
+ "previous_charge" => charge_data ? (charge_data['cancelled_charge'] || nil) : nil,
117
+ "shopify_domain" => params[:shop]
118
+ })
119
+ rescue Exception => e
120
+ Rollbar.error("Error in APP MANAGER Charge Created Callback >>>> #{e.inspect}")
121
+ end
118
122
  end
119
123
  end
120
124
  redirect_to "#{app_url}?shop=#{params[:shop]}", :status => 301 and return
@@ -125,7 +129,12 @@ module AppManager
125
129
  raise ModelNotFound, "Shop not found"
126
130
  end
127
131
  else
128
- raise Error, "Invalid params, must have charge_id,shop && plan"
132
+ if params[:shop].present?
133
+ redirect_to "#{app_url}?shop=#{params[:shop]}", :status => 301 and return
134
+ else
135
+ raise Error, "Invalid params, must have charge_id,shop && plan in charge controller"
136
+
137
+ end
129
138
  end
130
139
  end
131
140
 
@@ -128,6 +128,7 @@ module AppManager
128
128
  @trial_activated_field = AppManager.configuration.field_names['trial_activated_at']
129
129
  if @shop.update(@plan_field => params[:plan_id], @trial_activated_field => DateTime.now)
130
130
  begin
131
+ AppManager.clear_cache
131
132
  plan_obj = AppManager::Client.new
132
133
  plan_data = plan_obj.get_plan(params[:plan_id], params[:shop_domain]) rescue nil
133
134
  AppManager::EventHandler.new('charge_created', {
data/app_manager.gemspec CHANGED
@@ -33,6 +33,9 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency "httparty"
34
34
  spec.add_dependency "rails", '>= 5.2.0'
35
35
  spec.add_dependency "kaminari", '>= 0.16.3'
36
+ spec.add_dependency "activerecord-import", '~> 1.4'
37
+
38
+
36
39
  # spec.add_dependency "sqlite3", '~> 1.3.0'
37
40
  # For more information and examples about making a new gem, checkout our
38
41
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -28,7 +28,7 @@ module AppManager
28
28
  response = response_from_cache_for_api(http_method, path, options)
29
29
  failsafe_or_caching_done = true
30
30
  else
31
- response = self.class.send(http_method, path, { body: options, timeout: 10 })
31
+ response = self.class.send(http_method, path, { body: options, timeout: 30 })
32
32
  end
33
33
  if path.include? "/get-status"
34
34
  data = response
@@ -59,7 +59,7 @@ module AppManager
59
59
  return fetch_static_cached_response(cache_key)
60
60
  end
61
61
  begin
62
- response = self.class.send(http_method, path, { body: options, timeout: 10 })
62
+ response = self.class.send(http_method, path, { body: options, timeout: 15 })
63
63
  if response.class.to_s == "HTTParty::Response" && (response.code.to_s.start_with?('2') or response.code.to_s.start_with?('4')) && (response.code.to_s != '429')
64
64
  Rails.cache.write(cache_key, response, expires_in: AppManager.configuration.expires_in)
65
65
  else
@@ -9,6 +9,8 @@ module AppManager
9
9
  include AppManager::Client::Banners
10
10
  include AppManager::Client::Plans
11
11
 
12
+ # debug_output $stderr if Rails.env.development?
13
+
12
14
  format :json
13
15
 
14
16
 
@@ -2,17 +2,18 @@ require 'json'
2
2
  require 'date'
3
3
  require 'time'
4
4
  require "fileutils"
5
-
5
+ require 'active_record'
6
+ require 'activerecord-import'
6
7
  module AppManager
7
8
 
8
9
  class FailSafe
9
10
 
10
11
  def initialize(db_name = 'app_manager_local')
11
- begin
12
- FileUtils.chmod 0664, "db/#{db_name}.db"
13
- rescue Exception => e
14
- puts ">>>>>> #{e.inspect}"
15
- end
12
+ # begin
13
+ # FileUtils.chmod 0664, "db/#{db_name}.db"
14
+ # rescue Exception => e
15
+ # puts ">>>>>> #{e.inspect}"
16
+ # end
16
17
  # @apm_db = SQLite3::Database.open "db/#{db_name}.db"
17
18
  # @apm_db.results_as_hash = true
18
19
  end
@@ -62,8 +63,9 @@ module AppManager
62
63
  end
63
64
 
64
65
  def save_api_plans(plans)
65
- AppManager::Plan.destroy_all
66
+ AppManager::Plan.delete_all
66
67
  if plans.any?
68
+ plan_data = []
67
69
  plans.each do |plan|
68
70
  interval = {}
69
71
  shopify_plans = []
@@ -77,62 +79,73 @@ module AppManager
77
79
  public_val = plan['public'] ? 1 : 0
78
80
  store_base_plan = plan['store_base_plan'] ? 1 : 0
79
81
  choose_later_plan = plan['choose_later_plan'] ? 1 : 0
80
- AppManager::Plan.create(id: plan["id"], type: plan["type"], name: plan["name"], price: plan["price"], offer_text: plan["offer_text"], description: plan["description"], interval: interval, shopify_plans: shopify_plans, trial_days: plan["trial_days"], test: plan_test, on_install: plan["on_install"], is_custom: is_custom, app_id: plan["app_id"], base_plan: plan["base_plan"], created_at: plan["created_at"], updated_at: plan["updated_at"], public: public_val, discount: plan["discount"], cycle_count: plan["cycle_count"], store_base_plan: store_base_plan, choose_later_plan: choose_later_plan, discount_type: plan["discount_type"], affiliate: affiliate, features: features, deleted_at: plan["deleted_at"])
82
+ plan_data << AppManager::Plan.new(id: plan["id"], type: plan["type"], name: plan["name"], price: plan["price"], offer_text: plan["offer_text"], description: plan["description"], interval: interval, shopify_plans: shopify_plans, trial_days: plan["trial_days"], test: plan_test, on_install: plan["on_install"], is_custom: is_custom, app_id: plan["app_id"], base_plan: plan["base_plan"], created_at: plan["created_at"], updated_at: plan["updated_at"], public: public_val, discount: plan["discount"], cycle_count: plan["cycle_count"], store_base_plan: store_base_plan, choose_later_plan: choose_later_plan, discount_type: plan["discount_type"], affiliate: affiliate, features: features, deleted_at: plan["deleted_at"])
81
83
  end
84
+ AppManager::Plan.bulk_import plan_data
82
85
  end
83
86
  end
84
87
 
85
88
 
86
89
  def save_api_charges(charges)
87
- AppManager::Charge.destroy_all
90
+ AppManager::Charge.delete_all
88
91
  if charges.any?
92
+ charge_data = []
89
93
  charges.each do |charge|
90
94
  charge_test = charge['test'] ? true : false
91
- AppManager::Charge.create(charge_id: charge["charge_id"], test: charge_test, status: charge["status"], name: charge["name"], type: charge["type"], price: charge["price"], interval: charge["interval"], trial_days: charge["trial_days"], billing_on: charge["billing_on"], activated_on: charge["activated_on"], trial_ends_on: charge["trial_ends_on"], cancelled_on: charge["cancelled_on"], expires_on: charge["expires_on"], plan_id: charge["plan_id"], description: charge["description"], shop_domain: charge["shop_domain"], created_at: charge["created_at"], updated_at: charge["updated_at"], app_id: charge["app_id"], sync: true)
95
+ charge_data << AppManager::Charge.new(charge_id: charge["charge_id"], test: charge_test, status: charge["status"], name: charge["name"], type: charge["type"], price: charge["price"], interval: charge["interval"], trial_days: charge["trial_days"], billing_on: charge["billing_on"], activated_on: charge["activated_on"], trial_ends_on: charge["trial_ends_on"], cancelled_on: charge["cancelled_on"], expires_on: charge["expires_on"], plan_id: charge["plan_id"], description: charge["description"], shop_domain: charge["shop_domain"], created_at: charge["created_at"], updated_at: charge["updated_at"], app_id: charge["app_id"], sync: true)
92
96
  end
97
+ AppManager::Charge.bulk_import charge_data
93
98
  end
94
99
  end
95
100
 
96
101
 
97
102
  def save_api_apps(apps)
98
- AppManager::App.destroy_all
103
+ AppManager::App.delete_all
99
104
  if apps.any?
105
+ apps_data = []
100
106
  apps.each do |app|
101
- AppManager::App.create(id: app['id'], name: app['name'], slug: app['slug'], url: app['url'], image: app['image'], api_token: app['api_token'], slack: app['slack'], created_at: app['created_at'], updated_at: app['updated_at'])
107
+ apps_data << AppManager::App.new(id: app['id'], name: app['name'], slug: app['slug'], url: app['url'], image: app['image'], api_token: app['api_token'], slack: app['slack'], created_at: app['created_at'], updated_at: app['updated_at'])
102
108
  end
109
+ AppManager::Charge.bulk_import apps_data
103
110
  end
104
111
  end
105
112
 
106
113
  #Complete
107
114
  def save_api_app_structures(app_structures)
108
- AppManager::AppStructure.destroy_all
115
+ AppManager::AppStructure.delete_all
109
116
  AppManager::AppStructure.create(banners: app_structures.to_h)
110
117
  end
111
118
 
112
119
  def save_api_discount_plans(discount_plans)
113
- AppManager::DiscountPlan.destroy_all
120
+ AppManager::DiscountPlan.delete_all
114
121
  if discount_plans.any?
122
+ discount_plans_data = []
115
123
  discount_plans.each do |discount_plan|
116
- AppManager::DiscountPlan.create(id: discount_plan['id'], discount: discount_plan['discount'], shop_domain: discount_plan['shop_domain'], cycle_count: discount_plan['cycle_count'], plan_id: discount_plan['plan_id'], created_by: discount_plan['created_by'], created_at: discount_plan['created_at'], updated_at: discount_plan['updated_at'], app_id: discount_plan['app_id'], discount_type: discount_plan['discount_type'])
124
+ discount_plans_data << AppManager::DiscountPlan.new(id: discount_plan['id'], discount: discount_plan['discount'], shop_domain: discount_plan['shop_domain'], cycle_count: discount_plan['cycle_count'], plan_id: discount_plan['plan_id'], created_by: discount_plan['created_by'], created_at: discount_plan['created_at'], updated_at: discount_plan['updated_at'], app_id: discount_plan['app_id'], discount_type: discount_plan['discount_type'])
117
125
  end
126
+ AppManager::DiscountPlan.bulk_import discount_plans_data
118
127
  end
119
128
  end
120
129
 
121
130
  def save_api_extend_trials(extend_trials)
122
- AppManager::ExtendTrial.destroy_all
131
+ AppManager::ExtendTrial.delete_all
123
132
  if extend_trials.any?
133
+ extend_trials_data = []
124
134
  extend_trials.each do |extend_trial|
125
- AppManager::ExtendTrial.create(id: extend_trial['id'], shop_domain: extend_trial['shop_domain'], plan_id: extend_trial['plan_id'], app_id: extend_trial['app_id'], days: extend_trial['days'], created_by: extend_trial['created_by'], created_at: extend_trial['created_at'], updated_at: extend_trial['updated_at'], extend_trial_start_at: extend_trial['extend_trial_start_at'])
135
+ extend_trials_data << AppManager::ExtendTrial.new(id: extend_trial['id'], shop_domain: extend_trial['shop_domain'], plan_id: extend_trial['plan_id'], app_id: extend_trial['app_id'], days: extend_trial['days'], created_by: extend_trial['created_by'], created_at: extend_trial['created_at'], updated_at: extend_trial['updated_at'], extend_trial_start_at: extend_trial['extend_trial_start_at'])
126
136
  end
137
+ AppManager::ExtendTrial.bulk_import extend_trials_data
127
138
  end
128
139
  end
129
140
 
130
141
  def save_api_plan_users(plan_users)
131
- AppManager::PlanUser.destroy_all
142
+ AppManager::PlanUser.delete_all
132
143
  if plan_users.any?
144
+ extend_plan_users = []
133
145
  plan_users.each do |plan_user|
134
- AppManager::PlanUser.create(id: plan_user['id'], shop_domain: plan_user['shop_domain'], plan_id: plan_user['plan_id'], created_by: plan_user['created_by'], created_at: plan_user['created_at'], updated_at: plan_user['updated_at'])
146
+ extend_plan_users << AppManager::PlanUser.new(id: plan_user['id'], shop_domain: plan_user['shop_domain'], plan_id: plan_user['plan_id'], created_by: plan_user['created_by'], created_at: plan_user['created_at'], updated_at: plan_user['updated_at'])
135
147
  end
148
+ AppManager::ExtendTrial.bulk_import extend_plan_users
136
149
  end
137
150
  end
138
151
 
@@ -84,7 +84,7 @@ module AppManager
84
84
  res = plan_obj.get_remaining_days(shop_domain, trial_activated_at_val, plan_id)
85
85
  return (res && !res.nil?) ? res : 0
86
86
  rescue Exception => e
87
- Rollbar.error("APP MANAGER Get Remaining Days Failed #{e}")
87
+ return 0
88
88
  end
89
89
  end
90
90
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppManager
4
- VERSION = "1.3.5"
4
+ VERSION = "1.3.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.5
4
+ version: 1.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hulkapps
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-13 00:00:00.000000000 Z
11
+ date: 2022-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.16.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: activerecord-import
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.4'
55
69
  description: Provides helper function to access AppManager API
56
70
  email: rahul.t@hulkapps.com
57
71
  executables: []