app_manager 1.1.6 → 1.2.0

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: 3c7139d80f35a011691ed85a8f0d62f164210fc1a2e1ab830bdd29820f0dff49
4
- data.tar.gz: 7ea3211619b2e2ff457bc87929bf3879dafe5471aa3771427137251f33f386f8
3
+ metadata.gz: 3ef86306a34e83be7d439ecda3ca318a33146373c0a5f8cd910d5da1cf06d587
4
+ data.tar.gz: 1239cc87364f045b966f9f2ccc24ca770c7fdd07dda704b25d7b37bf2a49dc05
5
5
  SHA512:
6
- metadata.gz: fccc462df489a3ddfcd71a371b0ab41ca35e0358fcbc0220f1ef477d8fabf6419036b5ce4b37d4d33f3f93b2426987c0ef8588b6a9cce5d3025dc98330d28d02
7
- data.tar.gz: af2479eee70e4bcb9be2503b45fa09a70eae273c8f46357642000dc7f8d9dc5b821e7c5393caba6f1b87245c8b72fcf0d75ee07253d4f25b2214f038874da68e
6
+ metadata.gz: db78e088159f14d5bad35456c2a3b41e87e5e813bcd92a12c32562d8882ba698e6eae97f6a7807e8b94ccf6673234f6cd58ef3c8846c40e6df3a97dbe6e8f266
7
+ data.tar.gz: d9d6dcb07015cde6b085473762cdffa39f12bf03ed7d2af0c9c79fe6849b29338b839f0f31712fd362fa7b037318bf9fa72754e0847ca09fe3a5f86a4f974a75
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_manager (1.1.6)
4
+ app_manager (1.2.0)
5
5
  httparty
6
6
  kaminari (>= 0.16.3)
7
7
  rails (>= 5.2.0)
@@ -146,7 +146,7 @@ GEM
146
146
  method_source (~> 1.0)
147
147
  public_suffix (4.0.6)
148
148
  racc (1.6.0)
149
- rack (2.2.3.1)
149
+ rack (2.2.4)
150
150
  rack-test (2.0.2)
151
151
  rack (>= 1.3)
152
152
  rails (7.0.3)
data/README.md CHANGED
@@ -109,8 +109,9 @@ AppManager.configure do |config|
109
109
  "description" => "Feature Description",
110
110
  "value_type" => "array",
111
111
  "values" => [
112
- "val 1",
113
- "val 2"
112
+ "val-1" => "val 1",
113
+ "val-2" => "val 2",
114
+ "val-3" => "val 3",
114
115
  ],
115
116
  "format" => "string",
116
117
  "display_order" => 4,
@@ -118,7 +119,7 @@ AppManager.configure do |config|
118
119
  "group_order" => "1",
119
120
  "group" => "Group Name",
120
121
  }
121
- ]
122
+ ]
122
123
  end
123
124
  #Required, Values type : integer, boolean, string, array #
124
125
  #Format: percentage, count, string
@@ -170,7 +171,26 @@ and then you can use follwing methods with your shop objects.
170
171
 
171
172
  @shop.get_plan # return current plan hash
172
173
 
173
- @shop.get_charge # return current charge hash
174
+ if you pass @shop.get_plan(plan_id) it will return that particular plan hash like @shop.get_plan(311)
175
+
176
+ @shop.get_charge # return current charge hash, it will return nil if current plan is free
177
+
178
+ @shop.set_default_plan(plan_id=nil) #if plan id is passed nil, then it will set the free(public and $0 price) to active and if passed it will set that plan to active plan
179
+
180
+ @shop.get_plans_by_features(feature_slugs) # pass feature_slugs as an array even if one slug and it will return plans array which have that slug found. Example:
181
+
182
+ @shop.get_plans_by_features(['quantity-based-discount'])
183
+ @shop.get_plans_by_features(['quantity-based-discount','multiple-discount-types'])
184
+
185
+
186
+ you can pass string argument 'exclude_current_plan' which will return all plans that matching features except current plan
187
+
188
+ @shop.get_plans_by_features(['quantity-based-discount'],'exclude_current_plan')
189
+ @shop.get_plans_by_features(['quantity-based-discount','multiple-discount-types'],'exclude_current_plan')
190
+
191
+
192
+ @shop.get_all_plans # return all app plans array
193
+
174
194
  ```
175
195
 
176
196
 
@@ -13,8 +13,22 @@ module AppManager
13
13
  if !@shop.nil?
14
14
  plan_obj = AppManager::Client.new
15
15
  plan_data = plan_obj.get_plan(params[:plan_id],params[:shop])
16
+ # render json: plan_data and return #use this to test plan failsafe api
16
17
  if plan_data.present? && plan_data.is_a?(Hash)
17
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']['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"]["appSubscriptionCreate"]["userErrors"].any? && (rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["status"] == 'CANCELLED'))
25
+ plan_obj.cancel_charge(params[:shop],active_charge_data['active_charge']['plan_id'])
26
+ end
27
+ end
28
+ rescue Exception => e
29
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
30
+ end
31
+
18
32
  if @shop.update(@plan_field => params[:plan_id])
19
33
  begin
20
34
  AppManager::EventHandler.new('charge_created',{
@@ -23,7 +37,7 @@ module AppManager
23
37
  "previous_charge" => nil
24
38
  })
25
39
  rescue Exception => e
26
- Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
40
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
27
41
  end
28
42
  AppManager.clear_cache
29
43
  render json: {'redirect_url' => "#{app_url}?shop=#{params[:shop]}"} and return true
@@ -78,7 +92,7 @@ module AppManager
78
92
  begin
79
93
  plan_obj.cancel_charge(@shop[shopify_domain],@shop[@plan_field])
80
94
  rescue Exception => e
81
- Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
95
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
82
96
  end
83
97
  end
84
98
 
@@ -96,7 +110,7 @@ module AppManager
96
110
  "previous_charge" => charge_data ? (charge_data['cancelled_charge'] || nil) : nil
97
111
  })
98
112
  rescue Exception => e
99
- Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
113
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
100
114
  end
101
115
  end
102
116
  redirect_to "#{app_url}?shop=#{params[:shop]}", :status => 301 and return
@@ -18,31 +18,32 @@ module AppManager
18
18
  plan_obj = AppManager::Client.new
19
19
  plans = []
20
20
  if params[:shop_domain].present? && !AppManager.configuration.plan_features.nil?
21
- plans = plan_obj.get_plans(params[:shop_domain])
22
21
  @shop = shop_data
23
22
  if !@shop.nil?
24
- active_plan_id_or_name = @shop[@plan_field]
23
+ active_plan_id_or_name = @shop[@plan_field] rescue nil
24
+ plans = plan_obj.get_plans(params[:shop_domain],active_plan_id_or_name)
25
25
  if !@field_names.nil? && @field_names.has_key?('shopify_plan') && !@field_names.nil?
26
26
  shopify_plan_field = AppManager.configuration.field_names['shopify_plan']
27
27
  shopify_plan = @shop[shopify_plan_field] rescue nil
28
- plan = plans.any? && !active_plan_id_or_name.nil? ? (plans.find{|x| x["id"] == active_plan_id_or_name}.present? ? plans.find{|x| x["id"] == active_plan_id_or_name} : nil ) : nil
28
+ plan = plans && plans.any? && !active_plan_id_or_name.nil? ? (plans.find{|x| x["id"] == active_plan_id_or_name}.present? ? plans.find{|x| x["id"] == active_plan_id_or_name} : nil ) : nil
29
29
 
30
30
  @trial_activated_field = AppManager.configuration.field_names['trial_activated_at']
31
31
  trial_activated_at = @shop[@trial_activated_field] rescue nil
32
32
  active_charge = plan_obj.get_charge(params[:shop_domain])
33
- if active_charge.any? && active_charge['active_charge'].nil? && active_charge['cancelled_charge'].nil? && trial_activated_at
33
+ if active_charge && active_charge.any? && active_charge['active_charge'].nil? && active_charge['cancelled_charge'].nil? && trial_activated_at
34
34
  choose_later = true
35
35
  end
36
36
 
37
37
  end
38
38
  else
39
- Rails.logger.info "APP MANGAGER >>>> Either model is defined wrong or config.plan_id_or_name_field is nil in initializer ==="
39
+ Rails.logger.info "APP MANAGER >>>> Either model is defined wrong or config.plan_id_or_name_field is nil in initializer ==="
40
40
  end
41
41
  else
42
- Rails.logger.info "APP MANGAGER >>>> Either params missing store_domain or config.plan_features is nil in initializer ==="
42
+ Rails.logger.info "APP MANAGER >>>> Either params missing store_domain or config.plan_features is nil in initializer ==="
43
43
  end
44
44
 
45
45
 
46
+ plans = plan_obj.get_plans(params[:shop_domain]) if plans && plans.blank?
46
47
  default_plan_data = plans.select{|x| x['choose_later_plan'] == true }
47
48
  if default_plan_data.any?
48
49
  if default_plan_data.select{|x| x['store_base_plan'] == true }.size > 0
@@ -118,8 +119,23 @@ module AppManager
118
119
  if params[:shop_domain].present? && params[:plan_id].present? && model
119
120
  @shop = shop_data
120
121
  @trial_activated_field = AppManager.configuration.field_names['trial_activated_at']
121
- @shop.update(@plan_field => params[:plan_id],@trial_activated_field => DateTime.now)
122
+ if @shop.update(@plan_field => params[:plan_id],@trial_activated_field => DateTime.now)
123
+ begin
124
+ plan_obj = AppManager::Client.new
125
+ plan_data = plan_obj.get_plan(params[:plan_id],params[:shop_domain]) rescue nil
126
+ AppManager::EventHandler.new('charge_created',{
127
+ "plan" => plan_data,
128
+ "charge" => nil,
129
+ "previous_charge" => nil,
130
+ "choose_later" => true
131
+ })
132
+ rescue Exception => e
133
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
134
+ end
122
135
  render json: {'status' => true}
136
+ else
137
+ render json: {'status' => false,'error' => "#{@shop.errors.full_messages.to_sentence}"}, status: 422
138
+ end
123
139
  else
124
140
  render json: {'status' => false,'error' => 'Shop not found or missing shop'}, status: 422
125
141
  end
@@ -139,13 +155,13 @@ module AppManager
139
155
  begin
140
156
  @fs.sync_app_manager
141
157
  rescue Exception => e
142
- Rails.logger.info "APP MANGAGER >>>> LOCAL DB couldn't sync with POTAL DB #{e.inspect}"
158
+ Rails.logger.info "APP MANAGER >>>> LOCAL DB couldn't sync with POTAL DB #{e.inspect}"
143
159
  end
144
160
 
145
161
  begin
146
162
  @fs.save_api_data(params)
147
163
  rescue Exception => e
148
- Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
164
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
149
165
  end
150
166
  AppManager.clear_cache
151
167
  end
@@ -2,8 +2,8 @@ module AppManager
2
2
  class Client
3
3
  module Plans
4
4
 
5
- def get_plans(shop_domain)
6
- get("/plans?shop_domain=#{shop_domain}")
5
+ def get_plans(shop_domain,active_plan_id=nil)
6
+ get("/plans?shop_domain=#{shop_domain}&active_plan_id=#{active_plan_id}")
7
7
  end
8
8
 
9
9
  def get_plan(plan_id,shop_domain=nil)
@@ -18,6 +18,10 @@ module AppManager
18
18
  post("/cancel-charge", {shop_domain: shop_domain,plan_id: plan_id})
19
19
  end
20
20
 
21
+ def update_charge(shop_domain,plan_id)
22
+ post("/update-charge", {shop_domain: shop_domain,plan_id: plan_id})
23
+ end
24
+
21
25
  def sync_charge(options = {})
22
26
  post("/sync-charge", options)
23
27
  end
@@ -9,7 +9,11 @@ module AppManager
9
9
 
10
10
  def initialize(db_name='app_manager_local')
11
11
  @apm_db = SQLite3::Database.open "db/#{db_name}.db"
12
- FileUtils.chmod 0755, "db/#{db_name}.db"
12
+ begin
13
+ FileUtils.chmod 0777, "db/#{db_name}.db"
14
+ rescue Exception => e
15
+ puts ">>>>>> #{e.inspect}"
16
+ end
13
17
  @apm_db.results_as_hash = true
14
18
  create_plan_table
15
19
  create_charges_table
@@ -24,37 +28,37 @@ module AppManager
24
28
  begin
25
29
  save_api_plans(params["plans"])
26
30
  rescue Exception => e
27
- Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
31
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
28
32
  end
29
33
  begin
30
34
  save_api_charges(params["charges"])
31
35
  rescue Exception => e
32
- Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
36
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
33
37
  end
34
38
  begin
35
39
  save_api_apps(params["apps"])
36
40
  rescue Exception => e
37
- Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
41
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
38
42
  end
39
43
  begin
40
44
  save_api_app_structures(params["app_structures"])
41
45
  rescue Exception => e
42
- Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
46
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
43
47
  end
44
48
  begin
45
49
  save_api_discount_plans(params["discount_plans"])
46
50
  rescue Exception => e
47
- Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
51
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
48
52
  end
49
53
  begin
50
54
  save_api_extend_trials(params["extend_trials"])
51
55
  rescue Exception => e
52
- Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
56
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
53
57
  end
54
58
  begin
55
59
  save_api_plan_users(params["plan_users"])
56
60
  rescue Exception => e
57
- Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
61
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
58
62
  end
59
63
  end
60
64
 
@@ -190,11 +194,22 @@ module AppManager
190
194
 
191
195
 
192
196
  def get_local_plans(params)
197
+
193
198
  plans_data = []
194
199
 
195
200
  active_plan_id = nil
201
+ active_charge_price = nil
202
+
196
203
  charges = @apm_db.execute( "SELECT * FROM charges WHERE shop_domain = ? ",params['shop_domain'])
197
- active_plan_id = charges.first['plan_id'] if charges.any?
204
+
205
+ if charges.any?
206
+ active_plan_id = charges.first['plan_id']
207
+ active_charge_price = charges.first['price']
208
+ elsif params['active_plan_id'].present? && !params['active_plan_id'].nil?
209
+ active_plan_id = params['active_plan_id']
210
+ plan_data = @apm_db.execute( "SELECT * FROM plans WHERE id = ?", active_plan_id)
211
+ active_charge_price = plan_data.first['price'] if plan_data.any?
212
+ end
198
213
 
199
214
  custom_plan_ids = []
200
215
  plan_users = @apm_db.execute( "SELECT * FROM plan_users WHERE shop_domain = ? ",params['shop_domain'])
@@ -228,7 +243,7 @@ module AppManager
228
243
  new_plan[key] = val.collect{|e|e['value']}
229
244
  elsif ['affiliate'].include?(key)
230
245
  new_plan[key] = eval(value)
231
- elsif ['is_custom','public','store_base_plan'].include?(key)
246
+ elsif ['is_custom','public','store_base_plan','choose_later_plan'].include?(key)
232
247
  new_plan[key] = (value == 0 ? false : true)
233
248
  elsif ['test'].include?(key)
234
249
  new_plan[key] = (value == 0 ? nil : true)
@@ -251,12 +266,41 @@ module AppManager
251
266
  features_by_plan.each do |fp|
252
267
  fp['name'] = features.find{|e| e['uuid'] == fp['feature_id']}['name'] rescue nil
253
268
  fp['format'] = features.find{|e| e['uuid'] == fp['feature_id']}['format'] rescue nil
269
+ fp['slug'] = features.find{|e| e['uuid'] == fp['feature_id']}['slug'] rescue nil
254
270
  features_by_plans_data.push(fp)
255
271
  end
256
272
  end
257
273
  end
258
274
 
275
+
276
+ custom_discounts_data = []
277
+ if params["shop_domain"].present? && plan_data
278
+ custom_discounts = @apm_db.execute( "SELECT * FROM discount_plans WHERE shop_domain = ? ORDER BY created_at DESC", params["shop_domain"])
279
+ if custom_discounts.any?
280
+ custom_discounts.each do |custom_discount|
281
+ new_custom_discount = {}
282
+ custom_discount.each_with_index do |(key, value), index|
283
+ new_custom_discount[key] = value unless key.class == Integer
284
+ end
285
+ custom_discounts_data.push(new_custom_discount)
286
+ end
287
+ end
288
+ end
289
+
259
290
  plans_data.each do |plan|
291
+ if (!active_plan_id.nil? && plan['id'] == active_plan_id)
292
+ plan['price'] = active_charge_price
293
+ end
294
+
295
+ if custom_discounts_data.any? && custom_discounts_data.select{|e| e['plan_id'] == plan['id']}.size > 0
296
+ cd_hash = {}
297
+ custom_discounts_data.select{|e| e['plan_id'] == plan['id']}.each do |cd|
298
+ plan['discount'] = cd['discount']
299
+ plan['discount_type'] = cd['discount_type']
300
+ plan['cycle_count'] = cd['cycle_count']
301
+ end
302
+ end
303
+
260
304
  if features_by_plans_data.select{|e| e['plan_id'] == plan['id']}.size > 0
261
305
  feature_hash = {}
262
306
  features_by_plans_data.select{|e| e['plan_id'] == plan['id']}.each do |fp|
@@ -267,11 +311,14 @@ module AppManager
267
311
  features = nil
268
312
  end
269
313
  plan['features'] = features
314
+ plan['old_plan_id'] = nil
315
+
270
316
  end
271
317
 
272
318
  plans = plans_data
273
319
  end
274
320
 
321
+
275
322
  return plans
276
323
  end
277
324
 
@@ -287,7 +334,7 @@ module AppManager
287
334
  new_plan[key] = val
288
335
  elsif ['shopify_plans','affiliate','features'].include?(key)
289
336
  new_plan[key] = eval(value)
290
- elsif ['is_custom','public','store_base_plan'].include?(key)
337
+ elsif ['is_custom','public','store_base_plan','choose_later_plan'].include?(key)
291
338
  new_plan[key] = (value == 0 ? false : true)
292
339
  elsif ['test'].include?(key)
293
340
  new_plan[key] = (value == 0 ? nil : true)
@@ -304,7 +351,7 @@ module AppManager
304
351
  end
305
352
  plan_data['app'] = app_data
306
353
  end
307
-
354
+ plan_data['old_plan_id'] = nil # Temporary for migration puspose only
308
355
  if params["shop_domain"].present? && plan_data
309
356
  @apm_db.execute( "SELECT * FROM discount_plans WHERE plan_id = ? AND shop_domain = ? ", params["plan_id"],params["shop_domain"]) do |cd|
310
357
  plan_data['discount'] = cd['discount'] if cd rescue plan_data['discount']
@@ -318,6 +365,7 @@ module AppManager
318
365
  end
319
366
 
320
367
  end
368
+
321
369
  return plan_data
322
370
  end
323
371
 
@@ -122,6 +122,32 @@ module AppManager
122
122
  return data
123
123
  end
124
124
 
125
+
126
+ def recurring_charge_cancel_api_call(charge_id,shop)
127
+ query = 'mutation(
128
+ $id: ID!
129
+ ){
130
+ appSubscriptionCancel(
131
+ id: $id
132
+ ) {
133
+ userErrors {
134
+ field
135
+ message
136
+ }
137
+ appSubscription {
138
+ id
139
+ status
140
+ }
141
+ }
142
+ }
143
+ '
144
+ variables = {
145
+ "id": "gid://shopify/AppSubscription/#{charge_id}"
146
+ }
147
+ data = run_graph_api(query,variables)
148
+ return data
149
+ end
150
+
125
151
  end
126
152
  end
127
153
 
@@ -31,7 +31,8 @@ module AppManager
31
31
  def plan_features
32
32
  plan_id = self[AppManager.configuration.plan_id_or_name_field]
33
33
  if !plan_id
34
- raise Error, "Plan id not found"
34
+ Rails.logger.info "Plan id found nil or not set in DB"
35
+ return []
35
36
  end
36
37
  plan_obj = AppManager::Client.new
37
38
  plans = plan_obj.get_plan(plan_id)
@@ -64,34 +65,86 @@ module AppManager
64
65
  end
65
66
 
66
67
  def get_remaining_days
67
- shop_domain = self[AppManager.configuration.shopify_domain_field]
68
- trial_activated_at_field = AppManager.configuration.field_names['trial_activated_at']
69
- trial_activated_at_val = self[trial_activated_at_field]
70
- plan_field = AppManager.configuration.field_names['plan_id']
71
- plan_id = self[plan_field]
72
- plan_obj = AppManager::Client.new
73
- shop_domain ? plan_obj.get_remaining_days(shop_domain,trial_activated_at_val,plan_id) : 0
68
+ begin
69
+ shop_domain = self[AppManager.configuration.shopify_domain_field]
70
+ trial_activated_at_field = AppManager.configuration.field_names['trial_activated_at']
71
+ trial_activated_at_val = self[trial_activated_at_field]
72
+ plan_field = AppManager.configuration.field_names['plan_id']
73
+ plan_id = self[plan_field]
74
+ plan_obj = AppManager::Client.new
75
+ shop_domain ? plan_obj.get_remaining_days(shop_domain,trial_activated_at_val,plan_id) : 0
76
+ rescue Exception => e
77
+ return "#{e.inspect}"
78
+ end
74
79
  end
75
80
 
76
81
 
77
- def get_plan
78
- if !self[AppManager.configuration.plan_id_or_name_field]
79
- raise Error, "Invalid params, must have charge_id,shop && plan"
82
+ def get_plan(plan_id=nil)
83
+ req_plan_id = nil
84
+ if !plan_id.nil?
85
+ req_plan_id = plan_id
86
+ else
87
+ shop_plan_id = self[AppManager.configuration.plan_id_or_name_field]
88
+ if shop_plan_id && !shop_plan_id.nil?
89
+ req_plan_id = shop_plan_id
90
+ else
91
+ Rails.logger.info "Invalid params, must have charge_id,shop && plan"
92
+ return {}
93
+ end
80
94
  end
81
- plan_obj = AppManager::Client.new
82
- return plan_obj.get_plan(self[AppManager.configuration.plan_id_or_name_field])
95
+ plan_obj = AppManager::Client.new if req_plan_id
96
+ return req_plan_id ? plan_obj.get_plan(req_plan_id) : {}
83
97
  end
84
98
 
85
99
  def get_charge
100
+ shop_plan_id = self[AppManager.configuration.plan_id_or_name_field]
101
+ found_free_plan = false
102
+ if shop_plan_id && !shop_plan_id.nil?
103
+ plan_obj = AppManager::Client.new
104
+ plan = plan_obj.get_plan(shop_plan_id) rescue nil
105
+ if plan && plan['price'] == 0 && plan['public'] == true
106
+ found_free_plan = true
107
+ return nil
108
+ end
109
+ end
110
+ if !found_free_plan
111
+ begin
112
+ shop_domain = self[AppManager.configuration.shopify_domain_field]
113
+ plan_obj = AppManager::Client.new
114
+ return plan_obj.get_charge(shop_domain)
115
+ rescue Exception => e
116
+ Rails.logger.info "#{e.inspect}"
117
+ return nil
118
+ end
119
+ end
120
+ end
121
+
122
+ def get_all_plans
86
123
  begin
87
124
  shop_domain = self[AppManager.configuration.shopify_domain_field]
125
+ shop_plan_id = self[AppManager.configuration.plan_id_or_name_field]
126
+ active_plan_id = shop_plan_id && shop_plan_id.nil? ? nil : shop_plan_id
88
127
  plan_obj = AppManager::Client.new
89
- return plan_obj.get_charge(shop_domain)
128
+ return plan_obj.get_plans(shop_domain,active_plan_id)
90
129
  rescue Exception => e
91
- return "#{e.inspect}"
130
+ Rails.logger.info "#{e.inspect}"
131
+ return []
92
132
  end
93
133
  end
94
134
 
135
+ def cancel_charge
136
+ begin
137
+ shop_plan_id = self[AppManager.configuration.plan_id_or_name_field]
138
+ shop_domain = self[AppManager.configuration.shopify_domain_field]
139
+ if shop_plan_id && shop_domain
140
+ plan_obj = AppManager::Client.new
141
+ plan_obj.cancel_charge(shop_domain,shop_plan_id)
142
+ end
143
+ rescue Exception => e
144
+ return "#{e.inspect}"
145
+ end
146
+ end
147
+
95
148
  def set_default_plan(plan_id=nil)
96
149
  begin
97
150
  if plan_id.nil?
@@ -117,15 +170,17 @@ module AppManager
117
170
 
118
171
 
119
172
 
120
- def get_plans_by_features(feature_slugs)
173
+ def get_plans_by_features(feature_slugs,params="false")
121
174
  if feature_slugs.any?
175
+ shop_plan_id = self[AppManager.configuration.plan_id_or_name_field]
122
176
  plan_data = []
123
177
  shop_domain = self[AppManager.configuration.shopify_domain_field]
124
178
  plan_obj = AppManager::Client.new
125
179
  plans = plan_obj.get_plans(shop_domain)
126
180
  plans = plans.select{|x| x['interval'] == 'EVERY_30_DAYS' && x['public'] == true}
127
181
  plans.each do |plan|
128
- if plan['features'].any? && plan['features'].values.any? && plan['features'].values.collect{|c| c['slug']}.any?
182
+ next if (params && !params.nil? && params == "exclude_current_plan" && !shop_plan_id.nil? && plan["id"] == shop_plan_id)
183
+ 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?)
129
184
  plan_feature_slugs = plan['features'].values.collect{|c| c['slug']}.sort
130
185
  if (feature_slugs & plan_feature_slugs).any? && ((feature_slugs & plan_feature_slugs).sort == feature_slugs.sort)
131
186
  plan_data.push(plan)
@@ -138,6 +193,8 @@ module AppManager
138
193
  end
139
194
  end
140
195
 
196
+
197
+
141
198
  private
142
199
 
143
200
  def casted_value(value,value_type)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppManager
4
- VERSION = "1.1.6"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -61,8 +61,9 @@ AppManager.configure do |config|
61
61
  "description" => "Feature Description",
62
62
  "value_type" => "array",
63
63
  "values" => [
64
- "val 1",
65
- "val 2"
64
+ "val-1" => "val 1",
65
+ "val-2" => "val 2",
66
+ "val-3" => "val 3",
66
67
  ],
67
68
  "format" => "string",
68
69
  "display_order" => 4,
@@ -83,5 +84,6 @@ end
83
84
  ActiveSupport::Notifications.subscribe "charge_created" do |name, start, finish, id, payload|
84
85
  Rails.logger.debug "========APP MANAGER========="
85
86
  Rails.logger.debug "DATA : #{payload}"
87
+ #payload hash contains 3 keys, "plan", "charge", "previous_charge" and an extra key "choose_later" => "true" renders when clicked on choose later
86
88
  Rails.logger.debug "========APP MANAGER========="
87
89
  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.1.6
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hulkapps
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-29 00:00:00.000000000 Z
11
+ date: 2022-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty