app_manager 1.3.6 → 1.3.7

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: b0726560dff151c7c6b5e6fde4f510a43a28c0d3e299c2382ffeb43aea7f26b8
4
- data.tar.gz: d02c49d7627c01fc7cc8096af135f36e39b0e1da002019034943abdb886d0a5b
3
+ metadata.gz: ac3a1d17d520c154419fd5917813fda210900f58d12686723bacf05d99ecbd14
4
+ data.tar.gz: 0f62d38f1160f30e07eb96007f845395ce397f70d82043f76f71aaf8c564e0e0
5
5
  SHA512:
6
- metadata.gz: 99ea34310c0c74e41115169a1a59b146ca75e06573383e2195aec671cc9938e8fb812a93783bf804dffc5eeeadd868b588d6c382fa231eeffd6118588d633f2a
7
- data.tar.gz: 0c91a1c992a85cff1f4834985b65726bb3230d91948fd43109ec199ee25810514dc58242f7a2d30e7ce94db6c29056f9148093c2b3f1113ac95ab52cb72c87f8
6
+ metadata.gz: c6136666c06d579b448ab775a4e9cc6c72f314f0ffc39baccece2d9fe3951a56c1853848d6e83bdfb847037680d2b1e978a4e04b0d440fbc783169a6ecac3e06
7
+ data.tar.gz: 730a1f415a8d7a679ade4bb74b60b84ddc109ecfa661dc950c666c8fa8bdef44dd3faf6d14d0979052ae73c58350ff53225e0fe51f96f4f463a19f7c50314e95
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_manager (1.3.6)
4
+ app_manager (1.3.7)
5
5
  activerecord-import (~> 1.4)
6
6
  httparty
7
7
  kaminari (>= 0.16.3)
@@ -10,6 +10,7 @@ module AppManager
10
10
  def process_plan
11
11
  if params[:shop].present? && params[:plan_id].present?
12
12
  @shop = shop_data
13
+ grandfathered_field = @field_names['grandfathered']
13
14
  if !@shop.nil?
14
15
  plan_obj = AppManager::Client.new
15
16
  plan_data = plan_obj.get_plan(params[:plan_id], params[:shop])
@@ -29,8 +30,13 @@ module AppManager
29
30
  rescue Exception => e
30
31
  Rollbar.error("APP MANAGER Process Plan Failed #{e}")
31
32
  end
32
-
33
- if @shop.update(@plan_field => params[:plan_id])
33
+ @trial_activated_field = AppManager.configuration.field_names['trial_activated_at']
34
+ update_info = {@plan_field => params[:plan_id], @trial_activated_field => nil,grandfathered_field => 0}
35
+ if !config_trial_days.nil? && !plan_data.nil?
36
+ trial_days = plan_data['trial_days'] || 0
37
+ update_info[config_trial_days] = trial_days
38
+ end
39
+ if @shop.update(update_info)
34
40
  begin
35
41
  AppManager::EventHandler.new('charge_created', {
36
42
  "plan" => plan_data,
@@ -42,8 +48,8 @@ module AppManager
42
48
  Rollbar.error("APP MANAGER Error in Process Plan #{e}")
43
49
  end
44
50
  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
51
+ # render json: {'redirect_url' => "#{app_url}?shop=#{params[:shop]}"} and return true
52
+ render json: {'status' => true,'plan_type' => 'free_plan'} and return true
47
53
  else
48
54
  raise Error, "Invalid charge"
49
55
  end
@@ -106,7 +112,14 @@ module AppManager
106
112
 
107
113
  if response['message'] == "success"
108
114
  AppManager.clear_cache
109
- @shop.update(@plan_field => params[:plan],grandfathered_field => nil)
115
+
116
+ update_info = {@plan_field => params[:plan],grandfathered_field => 0}
117
+ if !config_trial_days.nil? && !plan_data.nil?
118
+ trial_days = plan_data['trial_days'] || 0
119
+ update_info[config_trial_days] = trial_days
120
+ end
121
+
122
+ @shop.update(update_info)
110
123
  Thread.new do
111
124
  charge_data = plan_obj.get_charge(@shop[shopify_domain])
112
125
  begin
@@ -133,7 +146,6 @@ module AppManager
133
146
  redirect_to "#{app_url}?shop=#{params[:shop]}", :status => 301 and return
134
147
  else
135
148
  raise Error, "Invalid params, must have charge_id,shop && plan in charge controller"
136
-
137
149
  end
138
150
  end
139
151
  end
@@ -170,6 +182,15 @@ module AppManager
170
182
  AppManager.configuration.app_url
171
183
  end
172
184
 
185
+ def config_trial_days
186
+ @field_names = AppManager.configuration.field_names
187
+ if !@field_names.nil? && @field_names.has_key?('total_trial_days') && !@field_names['total_trial_days'].nil? && !@field_names['total_trial_days'].blank?
188
+ return @field_names['total_trial_days']
189
+ else
190
+ return nil
191
+ end
192
+ end
193
+
173
194
 
174
195
  end
175
196
  end
@@ -86,17 +86,17 @@ module AppManager
86
86
  plans = plans.values if !plans.nil?
87
87
  shopify_plans = params[:shopify_plans] || nil
88
88
  shopify_plans = shopify_plans.values if !shopify_plans.nil?
89
- items_per_page = params[:itemsPerPage] || 25
89
+ items_per_page = 25
90
90
  @shopify_email = AppManager.configuration.field_names['shopify_email']
91
91
  @shopify_plan_name_field = AppManager.configuration.field_names['shopify_plan']
92
- data = model
93
92
  if params[:search]
94
93
  data = model.where("#{@shopify_domain} LIKE :search OR #{@shopify_email} LIKE :search", search: "%#{search}%")
95
94
  data = data.where(@plan_field => plans) if !plans.nil?
96
95
  data = data.where(@shopify_plan_name_field => shopify_plans) if !shopify_plans.nil?
97
96
  data = data.page(params[:page]).per(items_per_page)
98
97
  else
99
- data = model.where(@plan_field => plans) if !plans.nil?
98
+ data = model
99
+ data = data.where(@plan_field => plans) if !plans.nil?
100
100
  data = data.where(@shopify_plan_name_field => shopify_plans) if !shopify_plans.nil?
101
101
  data = data.page(params[:page]).per(items_per_page)
102
102
  end
@@ -126,11 +126,16 @@ module AppManager
126
126
  if params[:shop_domain].present? && params[:plan_id].present? && model
127
127
  @shop = shop_data
128
128
  @trial_activated_field = AppManager.configuration.field_names['trial_activated_at']
129
- if @shop.update(@plan_field => params[:plan_id], @trial_activated_field => DateTime.now)
129
+ plan_obj = AppManager::Client.new
130
+ plan_data = plan_obj.get_plan(params[:plan_id], params[:shop_domain]) rescue nil
131
+ update_info = {@plan_field => params[:plan_id], @trial_activated_field => DateTime.now}
132
+ if !config_trial_days.nil? && !plan_data.nil?
133
+ trial_days = plan_data['trial_days'] || 0
134
+ update_info[config_trial_days] = trial_days
135
+ end
136
+ if @shop.update(update_info)
130
137
  begin
131
138
  AppManager.clear_cache
132
- plan_obj = AppManager::Client.new
133
- plan_data = plan_obj.get_plan(params[:plan_id], params[:shop_domain]) rescue nil
134
139
  AppManager::EventHandler.new('charge_created', {
135
140
  "plan" => plan_data,
136
141
  "charge" => nil,
@@ -210,5 +215,14 @@ module AppManager
210
215
  AppManager.configuration.app_url
211
216
  end
212
217
 
218
+ def config_trial_days
219
+ @field_names = AppManager.configuration.field_names
220
+ if !@field_names.nil? && @field_names.has_key?('total_trial_days') && !@field_names['total_trial_days'].nil? && !@field_names['total_trial_days'].blank?
221
+ return @field_names['total_trial_days']
222
+ else
223
+ return nil
224
+ end
225
+ end
226
+
213
227
  end
214
228
  end
@@ -28,7 +28,8 @@ 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: 30 })
31
+ time_out = Rails.env.development? ? 120 : 30
32
+ response = self.class.send(http_method, path, { body: options, timeout: time_out })
32
33
  end
33
34
  if path.include? "/get-status"
34
35
  data = response
@@ -60,13 +61,15 @@ module AppManager
60
61
  end
61
62
  begin
62
63
  response = self.class.send(http_method, path, { body: options, timeout: 15 })
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
- Rails.cache.write(cache_key, response, expires_in: AppManager.configuration.expires_in)
65
- else
66
- response = response_from_failsafe(path,options)
67
- end
64
+ 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')
65
+ Rails.cache.write(cache_key, response, expires_in: AppManager.configuration.expires_in)
66
+ else
67
+ response = response_from_failsafe(path,options)
68
+ end
68
69
  rescue Net::ReadTimeout => error
69
70
  response = response_from_failsafe(path,options)
71
+ rescue Exception => e
72
+ response = response_from_failsafe(path,options)
70
73
  end
71
74
  return response
72
75
  end
@@ -63,7 +63,12 @@ module AppManager
63
63
  end
64
64
 
65
65
  def save_api_plans(plans)
66
- AppManager::Plan.delete_all
66
+ begin
67
+ # ActiveRecord::Base.establish_connection(:app_manager).connection.execute("TRUNCATE plans RESTART IDENTITY")
68
+ AppManager::Plan.connection.truncate(AppManager::Plan.table_name)
69
+ rescue
70
+ AppManager::Plan.delete_all
71
+ end
67
72
  if plans.any?
68
73
  plan_data = []
69
74
  plans.each do |plan|
@@ -87,7 +92,12 @@ module AppManager
87
92
 
88
93
 
89
94
  def save_api_charges(charges)
90
- AppManager::Charge.delete_all
95
+ begin
96
+ # ActiveRecord::Base.establish_connection(:app_manager).connection.execute("TRUNCATE charges RESTART IDENTITY")
97
+ AppManager::Charge.connection.truncate(AppManager::Charge.table_name)
98
+ rescue
99
+ AppManager::Charge.delete_all
100
+ end
91
101
  if charges.any?
92
102
  charge_data = []
93
103
  charges.each do |charge|
@@ -100,7 +110,12 @@ module AppManager
100
110
 
101
111
 
102
112
  def save_api_apps(apps)
103
- AppManager::App.delete_all
113
+ begin
114
+ # ActiveRecord::Base.establish_connection(:app_manager).connection.execute("TRUNCATE apps RESTART IDENTITY")
115
+ AppManager::App.connection.truncate(AppManager::App.table_name)
116
+ rescue
117
+ AppManager::App.delete_all
118
+ end
104
119
  if apps.any?
105
120
  apps_data = []
106
121
  apps.each do |app|
@@ -112,12 +127,22 @@ module AppManager
112
127
 
113
128
  #Complete
114
129
  def save_api_app_structures(app_structures)
115
- AppManager::AppStructure.delete_all
130
+ begin
131
+ # ActiveRecord::Base.establish_connection(:app_manager).connection.execute("TRUNCATE app_structures RESTART IDENTITY")
132
+ AppManager::AppStructure.connection.truncate(AppManager::AppStructure.table_name)
133
+ rescue
134
+ AppManager::AppStructure.delete_all
135
+ end
116
136
  AppManager::AppStructure.create(banners: app_structures.to_h)
117
137
  end
118
138
 
119
139
  def save_api_discount_plans(discount_plans)
120
- AppManager::DiscountPlan.delete_all
140
+ begin
141
+ # ActiveRecord::Base.establish_connection(:app_manager).connection.execute("TRUNCATE discount_plans RESTART IDENTITY")
142
+ AppManager::DiscountPlan.connection.truncate(AppManager::DiscountPlan.table_name)
143
+ rescue
144
+ AppManager::DiscountPlan.delete_all
145
+ end
121
146
  if discount_plans.any?
122
147
  discount_plans_data = []
123
148
  discount_plans.each do |discount_plan|
@@ -128,7 +153,12 @@ module AppManager
128
153
  end
129
154
 
130
155
  def save_api_extend_trials(extend_trials)
131
- AppManager::ExtendTrial.delete_all
156
+ begin
157
+ # ActiveRecord::Base.establish_connection(:app_manager).connection.execute("TRUNCATE extend_trials RESTART IDENTITY")
158
+ AppManager::ExtendTrial.connection.truncate(AppManager::ExtendTrial.table_name)
159
+ rescue
160
+ AppManager::ExtendTrial.delete_all
161
+ end
132
162
  if extend_trials.any?
133
163
  extend_trials_data = []
134
164
  extend_trials.each do |extend_trial|
@@ -139,7 +169,12 @@ module AppManager
139
169
  end
140
170
 
141
171
  def save_api_plan_users(plan_users)
142
- AppManager::PlanUser.delete_all
172
+ begin
173
+ # ActiveRecord::Base.establish_connection(:app_manager).connection.execute("TRUNCATE plan_users RESTART IDENTITY")
174
+ AppManager::PlanUser.connection.truncate(AppManager::PlanUser.table_name)
175
+ rescue
176
+ AppManager::PlanUser.delete_all
177
+ end
143
178
  if plan_users.any?
144
179
  extend_plan_users = []
145
180
  plan_users.each do |plan_user|
@@ -376,6 +411,11 @@ module AppManager
376
411
  if charge['trial_ends_on'] && DateTime.now < charge['trial_ends_on']
377
412
  @remaining_days = (charge['trial_ends_on'].to_datetime - DateTime.now.to_datetime).to_i
378
413
  end
414
+
415
+ # ADD EXTRA DAY
416
+ if charge['created_at'] && ((charge['created_at'].to_datetime - DateTime.now.to_datetime).to_i == 0)
417
+ @remaining_days = @remaining_days + 1
418
+ end
379
419
  # TODO: Uncomment this code when we implement Shopify trial extension apis
380
420
  # trial_extension_data = AppManager::ExtendTrial.where(shop_domain: @shop_domain, plan_id: @plan_id).order(extend_trial_start_at: :desc)
381
421
  # if trial_extension_data.any?
@@ -59,15 +59,27 @@ module AppManager
59
59
  plan_test = true
60
60
  end
61
61
  trial_days = plan['trial_days'] || 0
62
-
63
62
  if shop && shop.shopify_domain && trial_days
64
63
  trial_activated_at = shop[AppManager.configuration.field_names['trial_activated_at']] rescue nil
65
64
  plan_id_field = shop[AppManager.configuration.plan_id_or_name_field] rescue nil
66
65
  remaining_obj = AppManager::Client.new
67
66
  remaining = remaining_obj.get_remaining_days(shop.shopify_domain,trial_activated_at,plan_id_field)
68
- trial_days = !remaining.nil? ? remaining : trial_days
67
+ # trial_days = !remaining.nil? ? remaining : trial_days
68
+ if !remaining.nil?
69
+ if !plan_id_field.nil?
70
+ plan_obj = AppManager::Client.new
71
+ current_plan = plan_obj.get_plan(plan_id_field) rescue nil
72
+ used_days = (current_plan['trial_days'].to_i - remaining.to_i) if current_plan rescue 0
73
+ if used_days > 0
74
+ days = trial_days - used_days
75
+ trial_days = days > 0 ? days : 0
76
+ end
77
+ else
78
+ trial_days = remaining
79
+ end
80
+ end
69
81
  end
70
-
82
+
71
83
  discount_type = plan['discount_type'] || "percentage"
72
84
  discount_val = discount_type == "percentage" ? (plan['discount'].to_f/ 100) : "#{plan['discount']}"
73
85
  plan_discount = plan['discount'] ? { "discount" => { "durationLimitInIntervals" => (plan['cycle_count'].to_i || 0), "value" => {"#{discount_type}" => discount_val} } } : {}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppManager
4
- VERSION = "1.3.6"
4
+ VERSION = "1.3.7"
5
5
  end
@@ -15,7 +15,8 @@ AppManager.configure do |config|
15
15
  'plan_id' => 'plan_id', # 1. t
16
16
  'created_at' => 'created_at', # 2022-04-15 10:43:05
17
17
  'trial_activated_at' => 'trial_activated_at', # field name that stores trial start/activated date
18
- 'grandfathered' => 'grandfathered'
18
+ 'grandfathered' => 'grandfathered',
19
+ 'total_trial_days' => '' #optional, put a trial days field from your shops table otherwise leave it blank
19
20
  }
20
21
  config.plan_features = [
21
22
  {
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.6
4
+ version: 1.3.7
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-16 00:00:00.000000000 Z
11
+ date: 2022-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty