app_manager 2.2.4 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b79e8f73435de3ded9d7a71d76c5658884d624c96944ae4a1fa6aa9d96504fcc
4
- data.tar.gz: cca64ffae23b40444c8abc95ea1d9474b201c74569661e958d145744eff2195e
3
+ metadata.gz: 36ca82cb72a3f61eda4cca501641a538818ab940091361691256a3ababd7b873
4
+ data.tar.gz: 8e8df05176547bb94c03799de4e08f77b5381608194c6a22144e21b10a57be56
5
5
  SHA512:
6
- metadata.gz: ce51ba456521c7877e92602bcea65a7238eaf2f57b275d2746d8931e75f6074be343386ff96c3d51d5b674800bf56c2e4423c65e80addaaae7777f281d6dd455
7
- data.tar.gz: 42d2907e6918b99dd9bceb0f1cf720c08a17bb71de1f4f520b2d17ad741a800ba617c4955c6de68ea894efd667915487dbad522f68646738d34943e907a4bcf0
6
+ metadata.gz: 1caaec8b97367a4932827a60f11d5c0ae338940334f822061c605e9285fad753ab42ee8b5d6503df0ea7315f2df680da935ad8a47c4e2daa9d8b90b847a3dbc9
7
+ data.tar.gz: 5d2f94082fac014e53bce3c361cbd1e9295a2d8e24d97db543ecd8e4b6ac998f0b5dfcbabc748a2bfa783689d8d6d35d2bb1831902c15eb0258f2eaffe9f5a27
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_manager (2.2.4)
4
+ app_manager (2.3.0)
5
5
  activerecord-import (~> 1.4)
6
6
  httparty
7
7
  kaminari (>= 0.16.3)
@@ -139,7 +139,6 @@ GEM
139
139
  marcel (1.0.4)
140
140
  method_source (1.0.0)
141
141
  mini_mime (1.1.5)
142
- mini_portile2 (2.8.6)
143
142
  minitest (5.22.3)
144
143
  multi_xml (0.6.0)
145
144
  mutex_m (0.2.0)
@@ -153,8 +152,7 @@ GEM
153
152
  net-smtp (0.5.0)
154
153
  net-protocol
155
154
  nio4r (2.7.1)
156
- nokogiri (1.15.6)
157
- mini_portile2 (~> 2.8.2)
155
+ nokogiri (1.15.6-x86_64-linux)
158
156
  racc (~> 1.4)
159
157
  pry (0.14.1)
160
158
  coderay (~> 1.1)
@@ -2,7 +2,7 @@ require_dependency "app_manager/application_controller"
2
2
  module AppManager
3
3
  class ChargesController < ApplicationController
4
4
  include HTTParty
5
- skip_before_action :verify_authenticity_token, :only => [:process_plan]
5
+ skip_before_action :verify_authenticity_token, :only => [:process_plan,:activate_global,:cancel_charge,:cancel_global]
6
6
  before_action :params_permit
7
7
  require 'time'
8
8
  require 'rack'
@@ -140,7 +140,7 @@ module AppManager
140
140
 
141
141
  begin
142
142
  plan_obj = AppManager::Client.new
143
- if params[:discount].present? && !params[:discount].nil? && params[:discount] != '0'
143
+ if params[:discount].present? && !params[:discount].nil? && params[:discount] != '0' && !plan['is_global']
144
144
  discounted_plans = plan_obj.get_related_discounted_plans(params[:discount])
145
145
  if discounted_plans.empty? || discounted_plans.include?(params[:plan].to_i)
146
146
  plan_obj.discount_used(@shop[shopify_domain], params[:discount])
@@ -191,6 +191,71 @@ module AppManager
191
191
  end
192
192
  end
193
193
 
194
+ def cancel_charge
195
+ if params[:charge_id].present? && params[:shop].present?
196
+ @shop = shop_data
197
+ shopify_token = @field_names['shopify_token']
198
+ begin
199
+ gq_obj = AppManager::GraphqlHelper.new(@shop[@shopify_domain], @shop[shopify_token])
200
+ rec_cancel_data = gq_obj.recurring_charge_cancel_api_call(params[:charge_id], @shop)
201
+ rescue Exception => e
202
+ Rollbar.error("APP MANAGER Cancel Plan Failed #{e.inspect}-#{e.backtrace}")
203
+ end
204
+ end
205
+ head :ok
206
+ end
207
+
208
+ def activate_global
209
+ if params[:shop].present? && params[:plan_id].present?
210
+ @shop = shop_data
211
+ grandfathered_field = @field_names['grandfathered']
212
+ trial_activated_field = @field_names['trial_activated_at']
213
+ if !@shop.nil?
214
+ plan_obj = AppManager::Client.new
215
+ plan_data = plan_obj.get_plan(params[:plan_id], params[:shop])
216
+ update_info = {@plan_field => params[:plan_id], trial_activated_field => nil,grandfathered_field => 0}
217
+ if !config_trial_days.nil? && !plan_data.nil?
218
+ trial_days = plan_data['trial_days'] || 0
219
+ update_info[config_trial_days] = trial_days
220
+ end
221
+ if @shop.update(update_info)
222
+ begin
223
+ plan_data['shop_domain'] = params[:shop];
224
+ plan_data['old_plan'] = params[:old_plan] || nil;
225
+ AppManager::EventHandler.new('charge_created', {
226
+ "plan" => plan_data,
227
+ "charge" => nil,
228
+ "previous_charge" => nil,
229
+ "shopify_domain" => params[:shop]
230
+ })
231
+ rescue Exception => e
232
+ Rollbar.error("APP MANAGER Error in Activate Global plan #{e.inspect}-#{e.backtrace}")
233
+ end
234
+ AppManager.clear_cache
235
+ end
236
+ end
237
+ render json: {'status' => true,'plan_type' => 'global_plan'} and return true
238
+ end
239
+ end
240
+
241
+ def cancel_global
242
+ if params[:shop].present?
243
+ @shop = shop_data
244
+ grandfathered_field = @field_names['grandfathered']
245
+ trial_activated_field = @field_names['trial_activated_at']
246
+ if !@shop.nil?
247
+ update_info = {@plan_field => nil, trial_activated_field => nil,grandfathered_field => 0}
248
+ if !config_trial_days.nil?
249
+ update_info[config_trial_days] = 0
250
+ end
251
+ @shop.update(update_info)
252
+ AppManager.clear_cache
253
+ end
254
+ render json: {'status' => true,'plan_type' => 'cancel_plan'} and return true
255
+ end
256
+ end
257
+
258
+
194
259
  private
195
260
 
196
261
  def params_permit
@@ -20,6 +20,7 @@ module AppManager
20
20
  default_plan_id = nil
21
21
  choose_later = false
22
22
  trial_activated_at = nil
23
+ global_plan = nil
23
24
  plan_obj = AppManager::Client.new
24
25
  plans = []
25
26
  if params[:shop_domain].present? && !AppManager.configuration.plan_features.nil?
@@ -32,7 +33,7 @@ module AppManager
32
33
  shopify_plan_field = AppManager.configuration.field_names['shopify_plan']
33
34
  shopify_plan = @shop[shopify_plan_field] rescue nil
34
35
  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
35
-
36
+ global_plan = plans&.find { |x| x["is_global"] == 1 or x["is_global"] == true }
36
37
  @trial_activated_field = AppManager.configuration.field_names['trial_activated_at']
37
38
  trial_activated_at = @shop[@trial_activated_field] rescue nil
38
39
  active_charge = plan_obj.get_charge(params[:shop_domain])
@@ -72,11 +73,17 @@ module AppManager
72
73
  promotional_discount = plan_obj.get_promotional_discount(params[:shop_domain],discount_local_storage)
73
74
  promotional_discount = [] if promotional_discount.class.to_s == "Hash" && promotional_discount.has_key?('status') && promotional_discount['status'] == 404
74
75
  end
76
+
77
+ bundle_obj = AppManager::Client.new
78
+ app_bundle_data = bundle_obj.get_app_bundle_data
79
+
75
80
  response = {
76
81
  'plans' => plans,
77
82
  'promotional_discount' => promotional_discount,
78
83
  'shopify_plan' => shopify_plan,
79
84
  'plan' => plan,
85
+ 'bundle_plan' => global_plan,
86
+ 'bundle_details' => app_bundle_data,
80
87
  'default_plan_id' => default_plan_id,
81
88
  'choose_later' => choose_later,
82
89
  'has_active_charge' => (((active_charge && active_charge.any? && !active_charge['active_charge'].nil?) or !trial_activated_at) ? true : false)
data/config/routes.rb CHANGED
@@ -11,6 +11,11 @@ AppManager::Engine.routes.draw do
11
11
  get 'plan/process/:plan_id' => 'charges#process_plan'
12
12
  get 'plan/callback' => 'charges#callback', as: :plan_callback
13
13
 
14
+ post 'cancel-charge' => 'charges#cancel_charge'
15
+ post 'plan/activate-global' => 'charges#activate_global'
16
+ post 'plan/cancel-global' => 'charges#cancel_global'
17
+
18
+
14
19
  scope 'app-manager-api' do
15
20
  post 'store-charge' => 'plans#store_charge'
16
21
  end
@@ -37,7 +37,7 @@ module AppManager
37
37
  end
38
38
 
39
39
  def cache_path
40
- @cache_path = "app-manager-cache"
40
+ @cache_path = "app-manager-cache/#{ENV['SHOPIFY_APP_SLUG']}"
41
41
  if @options[:cache_path].present?
42
42
  @cache_path = "#{@cache_path}#{@options[:cache_path]}"
43
43
  elsif AppManager.configuration.refresh_by_request_params?
@@ -24,7 +24,7 @@ module AppManager
24
24
 
25
25
  def request(http_method, path, options)
26
26
  failsafe_or_caching_done = false
27
- if http_method.to_s == 'get' && !path.include?("/get-status") && !path.include?("/sync-charge")
27
+ if http_method.to_s == 'get' && !path.include?("/get-status") && !path.include?("/sync-charge") && AppManager.configuration.enable_caching
28
28
  response = response_from_cache_for_api(http_method, path, options)
29
29
  failsafe_or_caching_done = true
30
30
  else
@@ -69,7 +69,8 @@ module AppManager
69
69
  end
70
70
 
71
71
  def response_from_cache_for_api(http_method, path, options)
72
- cache_key = "app-manager-cache/#{path}"
72
+ Rails.logger.info "Caching data enabled >>>>>>>>>>>>>>>>>>>>>>>>"
73
+ cache_key = "app-manager-cache/#{ENV['SHOPIFY_APP_SLUG']}/#{path}"
73
74
  if fetch_static_cached_response(cache_key).present?
74
75
  return fetch_static_cached_response(cache_key)
75
76
  end
@@ -133,6 +134,10 @@ module AppManager
133
134
  return @fs.store_discount_used(params,options)
134
135
  when 'get-related-discounted-plans'
135
136
  return @fs.get_local_related_discounted_plans(params,options)
137
+ when 'app-bundle-data'
138
+ return []
139
+ when 'activate-global-plan'
140
+ return nil
136
141
  else
137
142
  return nil
138
143
  end
@@ -43,6 +43,14 @@ 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_app_bundle_data
47
+ get("/app-bundle-data")
48
+ end
49
+
50
+ def check_and_activate_global_plan(shop_domain)
51
+ get("/activate-global-plan?shop_domain=#{shop_domain}")
52
+ end
53
+
46
54
  def get_promotional_discount(shop_domain = nil,code)
47
55
  get("/discount?shop_domain=#{shop_domain}&code=#{code}")
48
56
  end
@@ -94,7 +94,7 @@ module AppManager
94
94
  discount_type = plan['discount_type'] || "percentage"
95
95
  discount_val = discount_type == "percentage" ? (plan['discount'].to_f/ 100) : "#{plan['discount']}"
96
96
  if !@api_version.nil? && @api_version.to_s.include?('2024')
97
- plan_discount = if plan['discount'] && plan['cycle_count']
97
+ plan_discount = if plan['discount'] && plan['cycle_count'] && plan['cycle_count'].to_i != 0
98
98
  {
99
99
  "discount" => { "durationLimitInIntervals" => (plan['cycle_count'].to_i),
100
100
  "value" => {"#{discount_type}" => discount_val}
@@ -115,7 +115,7 @@ module AppManager
115
115
 
116
116
  if promotional_discount.any?
117
117
 
118
- if promotional_discount['plan_relation'].any? && !promotional_discount['plan_relation'].include?(plan['id'])
118
+ if promotional_discount['plan_relation'].any? && !promotional_discount['plan_relation'].include?(plan['id']) && plan['is_global']
119
119
  plan_discount = {}
120
120
  else
121
121
 
@@ -403,7 +403,7 @@ module AppManager
403
403
 
404
404
 
405
405
  def fetch_static_remaining_days
406
- @remaining_cache_key = "app-manager-cache/#{self.shopify_domain}-remaining_days"
406
+ @remaining_cache_key = "app-manager-cache/#{ENV['SHOPIFY_APP_SLUG']}/#{self.shopify_domain}-remaining_days"
407
407
  if fetch_cached_static_remaining_days(@remaining_cache_key).present?
408
408
  return fetch_cached_static_remaining_days(@remaining_cache_key)
409
409
  end
@@ -420,7 +420,7 @@ module AppManager
420
420
 
421
421
 
422
422
  def fetch_static_get_charge
423
- @get_charge_key = "app-manager-cache/#{self.shopify_domain}-get_charge"
423
+ @get_charge_key = "app-manager-cache/#{ENV['SHOPIFY_APP_SLUG']}/#{self.shopify_domain}-get_charge"
424
424
  if fetch_cached_static_get_charge(@get_charge_key).present?
425
425
  return fetch_cached_static_get_charge(@get_charge_key)
426
426
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppManager
4
- VERSION = "2.2.4"
4
+ VERSION = "2.3.0"
5
5
  end
data/lib/app_manager.rb CHANGED
@@ -28,7 +28,8 @@ module AppManager
28
28
 
29
29
  def self.clear_cache
30
30
  begin
31
- Rails.cache.delete_matched('app-manager-cache/*')
31
+ Rails.cache.delete_matched("app-manager-cache/*")
32
+ Rails.cache.delete_matched("app-manager-cache/#{ENV['SHOPIFY_APP_SLUG']}/*")
32
33
  rescue Exception => e
33
34
  Rollbar.error("APP MANAGER Error in Clear Cache #{e}")
34
35
  end
@@ -47,6 +47,14 @@ module AppManager
47
47
  end
48
48
  end
49
49
 
50
+ def create_global_field_to_plans_migration
51
+ if self.class.migration_exists?("db/app_manager", "add_is_global_to_plans")
52
+ say_status("skipped", "Migration add_is_global_to_plans.rb already exists")
53
+ else
54
+ migration_template("add_is_global_to_plans.erb", "db/app_manager/add_is_global_to_plans.rb")
55
+ end
56
+ end
57
+
50
58
 
51
59
  private
52
60
 
@@ -0,0 +1,7 @@
1
+ class AddIsGlobalToPlans < ActiveRecord::Migration[<%= rails_migration_version %>]
2
+ def change
3
+ unless column_exists?(:plans, :is_global)
4
+ add_column :plans, :is_global, :boolean, default: false
5
+ end
6
+ end
7
+ 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.2.4
4
+ version: 2.3.0
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-04-30 00:00:00.000000000 Z
11
+ date: 2024-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -125,6 +125,7 @@ files:
125
125
  - lib/generators/app_manager/install/install_generator.rb
126
126
  - lib/generators/app_manager/install/templates/add_discount_tables.erb
127
127
  - lib/generators/app_manager/install/templates/add_external_charge_field.erb
128
+ - lib/generators/app_manager/install/templates/add_is_global_to_plans.erb
128
129
  - lib/generators/app_manager/install/templates/add_plan_trial_grandfathered_to_shops.erb
129
130
  - lib/generators/app_manager/install/templates/app_manager.rb.tt
130
131
  - lib/generators/app_manager/install/templates/failsafe_tables.erb