app_manager 2.0.0 → 2.2.2

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: 1093f4ae3ee06a00f81bf11ad98bb1669f6b9f931bed69a430525733058143a0
4
- data.tar.gz: 9a3a425bdf82d12982f33ace1e86a1e5b47bbc7b3430ccd96b0469967cbf2f65
3
+ metadata.gz: be4fee3fa2e98fefd78bc65eb9172801baadbc53b302b10c885fd113dfa1a508
4
+ data.tar.gz: 2c0a489b9bc8fca1f6338373d0fa48b6495d29f794fd3f4fc70c4e6a72271377
5
5
  SHA512:
6
- metadata.gz: 9306209e778f2593afc88cdaf1f468f8c0ccefddd197e3ecfcb516301581577131975ed73dde14decae361454d32955f25c80220edab9cc755955f986d37a747
7
- data.tar.gz: b0f6d9c366e807ebaa5d5fd5de056ecd3f7e93addfbdc944cda14ec915dc86a5e20d4b248426dfe04bc7c5962887d858fd01eed6de2bc4ae7c5976540e9c8c6a
6
+ metadata.gz: 56fa65b2c2e6972d4b0ba43fe5752068f6583b412eb29c55c46d6ee11353af3e374919384ca5d8289b0b13648c05c5cbb1a7fad80cec46a9348b175504330668
7
+ data.tar.gz: e24bc7e35e1a3046a637b6805c03fe2a0bce0e9014bb13cd34f5168abc96140aba10974da887dbfa7113a636ee4776fd224b6fa3535855d0d860cb6ad319b797
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_manager (2.0.0)
4
+ app_manager (2.2.2)
5
5
  activerecord-import (~> 1.4)
6
6
  httparty
7
7
  kaminari (>= 0.16.3)
@@ -68,7 +68,7 @@ GEM
68
68
  activemodel (= 7.1.3.2)
69
69
  activesupport (= 7.1.3.2)
70
70
  timeout (>= 0.4.0)
71
- activerecord-import (1.5.1)
71
+ activerecord-import (1.6.0)
72
72
  activerecord (>= 4.2)
73
73
  activestorage (7.1.3.2)
74
74
  actionpack (= 7.1.3.2)
@@ -89,7 +89,7 @@ GEM
89
89
  addressable (2.8.0)
90
90
  public_suffix (>= 2.0.2, < 5.0)
91
91
  base64 (0.2.0)
92
- bigdecimal (3.1.6)
92
+ bigdecimal (3.1.7)
93
93
  builder (3.2.4)
94
94
  coderay (1.1.3)
95
95
  concurrent-ruby (1.2.3)
@@ -137,8 +137,8 @@ GEM
137
137
  marcel (1.0.4)
138
138
  method_source (1.0.0)
139
139
  mini_mime (1.1.5)
140
- mini_portile2 (2.8.5)
141
- minitest (5.22.2)
140
+ mini_portile2 (2.8.6)
141
+ minitest (5.22.3)
142
142
  multi_xml (0.6.0)
143
143
  mutex_m (0.2.0)
144
144
  net-imap (0.3.7)
@@ -148,10 +148,10 @@ GEM
148
148
  net-protocol
149
149
  net-protocol (0.2.2)
150
150
  timeout
151
- net-smtp (0.4.0.1)
151
+ net-smtp (0.5.0)
152
152
  net-protocol
153
- nio4r (2.7.0)
154
- nokogiri (1.15.5)
153
+ nio4r (2.7.1)
154
+ nokogiri (1.15.6)
155
155
  mini_portile2 (~> 2.8.2)
156
156
  racc (~> 1.4)
157
157
  pry (0.14.1)
@@ -161,7 +161,7 @@ GEM
161
161
  stringio
162
162
  public_suffix (4.0.6)
163
163
  racc (1.7.3)
164
- rack (3.0.9.1)
164
+ rack (3.0.10)
165
165
  rack-session (2.0.0)
166
166
  rack (>= 3.0.0)
167
167
  rack-test (2.1.0)
@@ -199,9 +199,9 @@ GEM
199
199
  thor (~> 1.0, >= 1.2.2)
200
200
  zeitwerk (~> 2.6)
201
201
  rake (13.0.6)
202
- rdoc (6.6.2)
202
+ rdoc (6.6.3.1)
203
203
  psych (>= 4.0.0)
204
- reline (0.4.3)
204
+ reline (0.5.3)
205
205
  io-console (~> 0.5)
206
206
  rexml (3.2.5)
207
207
  rspec (3.11.0)
data/README.md CHANGED
@@ -198,7 +198,9 @@ and then you can use follwing methods with your shop objects.
198
198
 
199
199
  @shop.get_active_charge_app_manager # return active charge hash from app manager otherwise nil
200
200
 
201
- @shop.update_app_manager_charge # return true if shop has shopify recurring charge but app manager doesn't then it update to app manager and return true otherwise nil
201
+ @shop.update_app_manager_charge # return true if shop has shopify recurring charge but app manager doesn't then it update to app manager and return true otherwise nil. This method also accepts current shopify charge id, so you can pass it if you already. This will reduce the extra call like this @shop.update_app_manager_charge("xx23432434")
202
+
203
+ @shop.update_app_manager_charge_with_plan_id # same as update_app_manager_charge method, the only difference is that, it will not check the plan_id in the shop table is valid from app manager. This method also accepts two parameters, first is current shopify charge id and second is plan_id .It shop table doesn't have plan_id saved then you can pass in second parameter. @shop.update_app_manager_charge_with_plan_id("xx23432434",23)
202
204
 
203
205
  @shop.get_current_shopify_charge # return active charge hash from shopify https://shopify.dev/docs/api/admin-graphql/2022-10/queries/currentAppInstallation otherwise nil
204
206
 
@@ -217,19 +219,20 @@ and then you can use follwing methods with your shop objects.
217
219
  * Update app manager gem in your project's Gemfile
218
220
 
219
221
  ```ruby
220
- gem 'app_manager', '2.0.0'
222
+ gem 'app_manager', '2.2.2'
221
223
  ```
222
224
  * In Rails project, in application.rb, add following line after require "rails/all" line
223
225
 
224
226
  ```ruby
225
- require 'app_manager/set_cookie'
227
+ require 'app_manager/set_local_storage'
226
228
  ```
227
229
 
228
230
  * In route.rb file, add following route with constraints
229
231
  ```ruby
230
232
  condition = ->(request) { request.path_info.include?('/discount/') }
233
+ plan_url = "https://admin.shopify.com/admin/apps/#{ENV['SHOPIFY_APP_SLUG']}/home/plan"
231
234
  constraints(condition) do
232
- get '/discount/*any', to: AppManager::SetCookie.new(Rails.application, condition)
235
+ get '/discount/*any', to: AppManager::SetLocalStorage.new(Rails.application, condition, plan_url)
233
236
  end
234
237
  ```
235
238
  * If updating gem from 1.6.1, then run these commands on rails root.
@@ -41,6 +41,7 @@ module AppManager
41
41
  end
42
42
  if @shop.update(update_info)
43
43
  begin
44
+ plan_data['old_plan'] = params[:old_plan] || nil;
44
45
  AppManager::EventHandler.new('charge_created', {
45
46
  "plan" => plan_data,
46
47
  "charge" => nil,
@@ -59,11 +60,12 @@ module AppManager
59
60
  end
60
61
  request_data = {'shop' => @shop.shopify_domain, 'timestamp' => Time.now.to_i, 'plan' => params[:plan_id]}
61
62
  request_data.merge!('host' => params['host']) if params['host'].present?
63
+ request_data.merge!('old_plan' => params['old_plan']) if params['old_plan'].present?
62
64
 
63
65
  return_url = "#{app_url}#{plan_callback_path}?#{Rack::Utils.build_query(request_data)}"
64
- discount_cookie = AppManager.resolve_from_cookies(self.request)
65
66
  gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain, @shop.shopify_token)
66
- data = gq_obj.recurring_charge_api_call(plan_data, return_url, @shop,discount_cookie)
67
+ discount_local_storage = params[:discount_code].present? && !params[:discount_code].nil? ? params[:discount_code] : nil
68
+ data = gq_obj.recurring_charge_api_call(plan_data, return_url, @shop,discount_local_storage)
67
69
  if data.present? && !data["errors"].present? && (data["data"].present? && data["data"]["appSubscriptionCreate"].present? && (!data["data"]["appSubscriptionCreate"]["userErrors"].any? && data["data"]["appSubscriptionCreate"]["confirmationUrl"]))
68
70
  redirect_charge = data["data"]["appSubscriptionCreate"]["confirmationUrl"]
69
71
  render json: {'redirect_url' => redirect_charge}
@@ -88,8 +90,7 @@ module AppManager
88
90
  shopify_token = @field_names['shopify_token']
89
91
  shopify_domain = @field_names['name']
90
92
  grandfathered_field = @field_names['grandfathered']
91
- discounted_plans = JSON.parse(params[:discounted_plans]) rescue []
92
- discounted_plans = discounted_plans.map!(&:to_s) if discounted_plans.any?
93
+ discounted_plans = []
93
94
  if !@shop.nil?
94
95
  old_plan_id = @shop[@plan_field]
95
96
  old_plan_data = nil
@@ -139,11 +140,11 @@ module AppManager
139
140
 
140
141
  begin
141
142
  plan_obj = AppManager::Client.new
142
- discounted_plans_present = discounted_plans.present? && discounted_plans.any?
143
- if params[:promo_discount].present? && discounted_plans_present && discounted_plans.include?(params[:plan])
144
- plan_obj.discount_used(@shop[shopify_domain], params[:promo_discount])
145
- elsif params[:promo_discount].present? && discounted_plans.blank?
146
- plan_obj.discount_used(@shop[shopify_domain], params[:promo_discount])
143
+ if params[:discount].present? && !params[:discount].nil?
144
+ discounted_plans = plan_obj.get_related_discounted_plans(params[:discount])
145
+ if discounted_plans.empty? || discounted_plans.include?(params[:plan].to_i)
146
+ plan_obj.discount_used(@shop[shopify_domain], params[:discount])
147
+ end
147
148
  end
148
149
  rescue
149
150
  Rollbar.error("Error in APP MANAGER Discount used API call >>>> #{e.inspect}")
@@ -66,15 +66,12 @@ module AppManager
66
66
  end
67
67
 
68
68
  promotional_discount = []
69
- discount_cookie = AppManager.resolve_from_cookies(self.request)
70
- if discount_cookie && @shop
71
- created_at = @shop[AppManager.configuration.field_names['created_at']]
72
- reinstall = AppManager.check_if_reinstall(created_at)
69
+ if params[:discount_code].present? && !params[:discount_code].nil? && @shop
70
+ discount_local_storage = params[:discount_code]
73
71
  plan_obj = AppManager::Client.new
74
- promotional_discount = plan_obj.get_promotional_discount(params[:shop_domain], discount_cookie['codeType'], discount_cookie['code'], reinstall)
72
+ promotional_discount = plan_obj.get_promotional_discount(params[:shop_domain],discount_local_storage)
75
73
  promotional_discount = [] if promotional_discount.class.to_s == "Hash" && promotional_discount.has_key?('status') && promotional_discount['status'] == 404
76
74
  end
77
-
78
75
  response = {
79
76
  'plans' => plans,
80
77
  'promotional_discount' => promotional_discount,
@@ -74,7 +74,7 @@ module AppManager
74
74
  return fetch_static_cached_response(cache_key)
75
75
  end
76
76
  begin
77
- response = self.class.send(http_method, path, { body: options, timeout: 1 })
77
+ response = self.class.send(http_method, path, { body: options, timeout: 120 })
78
78
  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')
79
79
  Rails.cache.write(cache_key, response, expires_in: AppManager.configuration.expires_in)
80
80
  else
@@ -131,6 +131,8 @@ module AppManager
131
131
  return @fs.get_local_discount(params, options)
132
132
  when 'use-discount'
133
133
  return @fs.store_discount_used(params,options)
134
+ when 'get-related-discounted-plans'
135
+ return @fs.get_local_related_discounted_plans(params,options)
134
136
  else
135
137
  return nil
136
138
  end
@@ -43,8 +43,8 @@ module AppManager
43
43
  get("/has-plan?shop_domain=#{shop_domain}&plan_id=#{plan_id}&trial_activated_at=#{trial_activated_at}&grandfathered=#{grandfathered}")
44
44
  end
45
45
 
46
- def get_promotional_discount(shop_domain = nil, code_type, code, reinstall)
47
- get("/discount?shop_domain=#{shop_domain}&reinstall=#{reinstall}&code_type=#{code_type}&code=#{code}")
46
+ def get_promotional_discount(shop_domain = nil,code)
47
+ get("/discount?shop_domain=#{shop_domain}&code=#{code}")
48
48
  end
49
49
 
50
50
  def discount_used(shop_domain, discount_id)
@@ -55,6 +55,10 @@ module AppManager
55
55
  post("/use-discount-sync", options)
56
56
  end
57
57
 
58
+ def get_related_discounted_plans(discount_id)
59
+ get("/get-related-discounted-plans?discount_id=#{discount_id}")
60
+ end
61
+
58
62
  end
59
63
  end
60
64
  end
@@ -224,10 +224,6 @@ module AppManager
224
224
  promotional_discounts_data = []
225
225
  promotional_discounts.each do |promotional_discount|
226
226
 
227
- Rails.logger.info " "
228
- Rails.logger.info "=== promotional_discount===========#{promotional_discount.inspect}"
229
- Rails.logger.info " "
230
-
231
227
  promotional_discounts_data << AppManager::Discount.new(
232
228
  discount_id: promotional_discount['id'],
233
229
  name: promotional_discount['name'],
@@ -249,9 +245,6 @@ module AppManager
249
245
  )
250
246
  end
251
247
 
252
- Rails.logger.info " "
253
- Rails.logger.info "=== promotional_discounts_data===========#{promotional_discounts_data.inspect}"
254
- Rails.logger.info " "
255
248
  AppManager::Discount.bulk_import promotional_discounts_data
256
249
  end
257
250
  end
@@ -614,14 +607,12 @@ module AppManager
614
607
 
615
608
  def get_local_discount(params, options)
616
609
  code = [params['code']].pack('H*')
617
- code_type = params['code_type']
618
- reinstall = params['reinstall']
619
610
  shop_domain = params['shop_domain']
620
611
  now = Time.now
621
612
 
622
613
  discount_data = AppManager::Discount.where(enabled: true)
623
614
  .where('valid_from <= ?', now)
624
- .where('valid_to >= ?', now)
615
+ .where('valid_to IS NULL OR valid_to >= ?', now)
625
616
  .where(code: code)
626
617
  .first
627
618
  return [] if discount_data.nil?
@@ -674,6 +665,11 @@ module AppManager
674
665
 
675
666
  end
676
667
 
668
+ def get_local_related_discounted_plans(params, options)
669
+ discounted_plans = DiscountLinkPlan.where(discount_id: params['discount_id']).pluck(:plan_id) rescue []
670
+ return discounted_plans
671
+ end
672
+
677
673
  def store_local_charge(params, options)
678
674
  message = {"message" => 'fail'}
679
675
  if options
@@ -54,7 +54,7 @@ module AppManager
54
54
  end
55
55
 
56
56
 
57
- def recurring_charge_api_call(plan,return_url,shop,discount_cookie)
57
+ def recurring_charge_api_call(plan,return_url,shop,discount_local_storage)
58
58
  plan_test = nil
59
59
  shop_plan_field = AppManager.configuration.field_names['shopify_plan'] rescue nil
60
60
  if !plan['affiliate'].nil? && plan['affiliate'].any? && !shop_plan_field.nil? && plan['affiliate'].map{|e| e['value']}.include?(shop[shop_plan_field])
@@ -84,11 +84,9 @@ module AppManager
84
84
  end
85
85
 
86
86
  promotional_discount = []
87
- if discount_cookie && shop
88
- created_at = shop[AppManager.configuration.field_names['created_at']]
89
- reinstall = AppManager.check_if_reinstall(created_at)
87
+ if !discount_local_storage.nil? && shop
90
88
  plan_obj = AppManager::Client.new
91
- promotional_discount = plan_obj.get_promotional_discount(shop.shopify_domain, discount_cookie['codeType'], discount_cookie['code'], reinstall)
89
+ promotional_discount = plan_obj.get_promotional_discount(shop.shopify_domain, discount_local_storage)
92
90
  promotional_discount = [] if promotional_discount.class.to_s == "Hash" && promotional_discount.has_key?('status') && promotional_discount['status'] == 404
93
91
  end
94
92
 
@@ -141,9 +139,8 @@ module AppManager
141
139
  promotional_discount_applies = promotional_discount.present? && promotional_discount.any?
142
140
  promotional_discount_id = discount_exists && promotional_discount_applies ? 0 : promotional_discount_applies ? promotional_discount['id'] : 0
143
141
 
144
- plans_relation = promotional_discount.present? && promotional_discount['plan_relation'].any? ? promotional_discount['plan_relation'] : []
145
- # Append additional data to the existing return_url
146
- return_url += "&promo_discount=#{promotional_discount_id}&discounted_plans=#{Rack::Utils.escape(plans_relation.to_json)}"
142
+ return_url += "&discount=#{promotional_discount_id}"
143
+
147
144
 
148
145
  price_details = {
149
146
  "price": { "amount": plan['price'], "currencyCode": 'USD' },
@@ -148,7 +148,7 @@ module AppManager
148
148
  plan_obj.cancel_charge(shop_domain, shop_plan_id)
149
149
  end
150
150
  rescue Exception => e
151
- return "#{e.inspect}"
151
+ return "#{e.inspect}-#{e.backtrace}"
152
152
  end
153
153
  end
154
154
 
@@ -170,7 +170,7 @@ module AppManager
170
170
  end
171
171
  end
172
172
  rescue Exception => e
173
- return "#{e.inspect}"
173
+ return "#{e.inspect}-#{e.backtrace}"
174
174
  end
175
175
  end
176
176
 
@@ -182,7 +182,7 @@ module AppManager
182
182
  return data["data"]["currentAppInstallation"]["activeSubscriptions"].first
183
183
  end
184
184
  rescue Exception => e
185
- Rollbar.error("Warning in APP MANAGER, trying to get_current_shopify_charge >>>> #{e.inspect}")
185
+ Rollbar.error("Warning in APP MANAGER, trying to get_current_shopify_charge >>>> #{e.inspect}-#{e.backtrace}")
186
186
  return nil
187
187
  end
188
188
  end
@@ -217,7 +217,28 @@ module AppManager
217
217
  end
218
218
  return charge_updated
219
219
  rescue Exception => e
220
- Rollbar.error("Warning in APP MANAGER, trying to get update_app_manager_charge >>>> #{e.inspect}")
220
+ Rollbar.error("Warning in APP MANAGER, trying to get update_app_manager_charge >>>> #{e.inspect}-#{e.backtrace}")
221
+ return nil
222
+ end
223
+ end
224
+
225
+ def update_app_manager_charge_with_plan_id(current_shopify_charge_id=nil,shop_custom_plan_id=nil)
226
+ charge_updated = nil
227
+ begin
228
+ shop_plan_id = self[AppManager.configuration.plan_id_or_name_field]
229
+ shop_domain = self[AppManager.configuration.shopify_domain_field]
230
+ current_charge_id = current_shopify_charge_id.present? ? current_shopify_charge_id : active_shopify_charge_id
231
+ plan_id = shop_custom_plan_id.present? ? shop_custom_plan_id : shop_plan_id
232
+ if current_charge_id.present?
233
+ if plan_id.present?
234
+ if charge_update_call(self,plan_id,current_charge_id)
235
+ charge_updated = true
236
+ end
237
+ end
238
+ end
239
+ return charge_updated
240
+ rescue Exception => e
241
+ Rollbar.error("Warning in APP MANAGER, trying to get update_app_manager_charge_with_plan_id >>>> #{e.inspect}-#{e.backtrace}")
221
242
  return nil
222
243
  end
223
244
  end
@@ -236,7 +257,7 @@ module AppManager
236
257
  return nil
237
258
  end
238
259
  rescue Exception => e
239
- Rollbar.error("Warning in APP MANAGER, trying to get active shopify charge id >>>> #{e.inspect}")
260
+ Rollbar.error("Warning in APP MANAGER, trying to get active shopify charge id >>>> #{e.inspect}-#{e.backtrace}")
240
261
  return nil
241
262
  end
242
263
  end
@@ -300,15 +321,16 @@ module AppManager
300
321
  "shopify_domain" => shop_domain
301
322
  })
302
323
  rescue Exception => e
303
- Rollbar.error("Warning in APP MANAGER model Charge Created Callback Event Fire>>>> #{e.inspect}")
324
+ Rollbar.error("Warning in APP MANAGER model Charge Created Callback Event Fire>>>> #{e.inspect}-#{e.backtrace}")
304
325
  end
326
+ Thread.exit # Terminate the thread once processing is done
305
327
  end
306
328
  end
307
329
  end
308
330
  end
309
331
  return charge_callback_done
310
332
  # rescue Exception => e
311
- # Rollbar.error("Warning in APP MANAGER model charge_callback, trying to update active shopify charge in app manager>>>> #{e.inspect}")
333
+ # Rollbar.error("Warning in APP MANAGER model charge_callback, trying to update active shopify charge in app manager>>>> #{e.inspect}-#{e.backtrace}")
312
334
  # return nil
313
335
  # end
314
336
  end
@@ -351,7 +373,7 @@ module AppManager
351
373
  self.save
352
374
  end
353
375
  rescue Exception => e
354
- return "#{e.inspect}"
376
+ return "#{e.inspect}-#{e.backtrace}"
355
377
  end
356
378
  end
357
379
 
@@ -365,10 +387,10 @@ module AppManager
365
387
  plans = plan_obj.get_plans(shop_domain)
366
388
  plans = plans.select { |x| x['interval'] == 'EVERY_30_DAYS' && x['public'] == true }
367
389
  plans.each do |plan|
368
- next if (params && !params.nil? && params == "exclude_current_plan" && !shop_plan_id.nil? && plan["id"] == shop_plan_id)
390
+ next if (params && !params.nil? && params == "exclude_current_plan" && !shop_plan_id.nil? && !plan["id"].nil? && plan["id"] == shop_plan_id)
369
391
  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?)
370
392
  plan_feature_slugs = plan['features'].values.collect { |c| c['slug'] }.sort
371
- if (feature_slugs & plan_feature_slugs).any? && ((feature_slugs & plan_feature_slugs).sort == feature_slugs.sort)
393
+ if plan_feature_slugs && (feature_slugs & plan_feature_slugs).any? && ((feature_slugs & plan_feature_slugs).sort == feature_slugs.sort)
372
394
  plan_data.push(plan)
373
395
  end
374
396
  end
@@ -0,0 +1,34 @@
1
+ require 'uri'
2
+
3
+ # app/middleware/set_cookie.rb
4
+ module AppManager
5
+ class SetLocalStorage
6
+ def initialize(app, condition,destination_url)
7
+ @app = app
8
+ @condition = condition
9
+ @destination_url = destination_url
10
+ end
11
+
12
+ def call(env)
13
+ request = Rack::Request.new(env)
14
+
15
+ if @condition.call(request)
16
+ url = URI.parse(request.url)
17
+ host = url.host
18
+ discount_code = request.path.split('/')[2] rescue ''
19
+ AppManager.clear_cache #clearing cache
20
+ # Set a 302 response with an external URL and a cookie
21
+ return [
22
+ 302,
23
+ {
24
+ 'Location' => "#{@destination_url}?discount_code=#{discount_code}" ,
25
+ 'Content-Type' => 'text/plain'
26
+ },
27
+ ['Redirecting to external URL with cookie']
28
+ ]
29
+ end
30
+
31
+ @app.call(env)
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppManager
4
- VERSION = "2.0.0"
4
+ VERSION = "2.2.2"
5
5
  end
data/lib/app_manager.rb CHANGED
@@ -16,25 +16,8 @@ require "app_manager/model"
16
16
  require "app_manager/fail_safe"
17
17
  require 'app_manager/railtie' if defined?(Rails)
18
18
  require 'app_manager/exceptions'
19
- require 'action_dispatch/middleware/cookies' if defined?(Rails)
20
- require "action_controller"
21
19
 
22
20
  module AppManager
23
- module CookiesHandler
24
- include ActionController::Cookies
25
-
26
- def self.resolve_from_cookies(request)
27
- if request.cookies['ShopCircleDiscount'].present?
28
- {
29
- 'codeType' => 'normal',
30
- 'code' => request.cookies['ShopCircleDiscount']
31
- }
32
- else
33
- nil
34
- end
35
- end
36
- end
37
-
38
21
  def self.configure
39
22
  yield configuration
40
23
  end
@@ -51,14 +34,4 @@ module AppManager
51
34
  end
52
35
  end
53
36
 
54
- def self.resolve_from_cookies(request)
55
- CookiesHandler.resolve_from_cookies(request)
56
- end
57
-
58
- def self.check_if_reinstall(created_at)
59
- created_at < (Time.now - 5.minutes) ? 1 : 0
60
- end
61
-
62
-
63
-
64
37
  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: 2.0.0
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rahul Tiwari @ Hulkapps
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-11 00:00:00.000000000 Z
11
+ date: 2024-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -119,7 +119,7 @@ files:
119
119
  - lib/app_manager/protection.rb
120
120
  - lib/app_manager/railtie.rb
121
121
  - lib/app_manager/response_cache.rb
122
- - lib/app_manager/set_cookie.rb
122
+ - lib/app_manager/set_local_storage.rb
123
123
  - lib/app_manager/tasks/sync/local_app_manager.rake
124
124
  - lib/app_manager/version.rb
125
125
  - lib/generators/app_manager/install/install_generator.rb
@@ -1,41 +0,0 @@
1
- # app/middleware/set_cookie_middleware.rb
2
- require 'action_dispatch/middleware/cookies'
3
- require 'uri'
4
-
5
- # app/middleware/set_cookie.rb
6
- module AppManager
7
- class SetCookie
8
- def initialize(app, condition)
9
- @app = app
10
- @condition = condition
11
- end
12
-
13
- def call(env)
14
- request = Rack::Request.new(env)
15
-
16
- if @condition.call(request)
17
- url = URI.parse(request.url)
18
- host = url.host
19
- discount_code = request.path.split('/')[2]
20
-
21
- # Set a cookie named 'ShopCircleDiscount' with the extracted values
22
- lifetime = Time.now + 60 * 60 * 24 * 365
23
- cookie_value = discount_code
24
-
25
- AppManager.clear_cache #clearing cache
26
- # Set a 302 response with an external URL and a cookie
27
- return [
28
- 302,
29
- {
30
- 'Location' => 'https://admin.shopify.com/admin/apps/'+ENV['SHOPIFY_APP_SLUG']+'/home/plan' ,
31
- 'Set-Cookie' => "ShopCircleDiscount=#{cookie_value}; expires=#{lifetime.utc.strftime('%a, %d %b %Y %H:%M:%S GMT')}; path=/; domain=#{host}; secure; HttpOnly; SameSite=None",
32
- 'Content-Type' => 'text/plain'
33
- },
34
- ['Redirecting to external URL with cookie']
35
- ]
36
- end
37
-
38
- @app.call(env)
39
- end
40
- end
41
- end