app_manager 2.3.7 → 2.4.1
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 +4 -4
- data/Gemfile.lock +7 -6
- data/app/controllers/app_manager/charges_controller.rb +1 -1
- data/app/controllers/app_manager/plans_controller.rb +38 -5
- data/config/routes.rb +16 -19
- data/lib/app_manager/config.rb +5 -0
- data/lib/app_manager/fail_safe.rb +262 -2
- data/lib/app_manager/version.rb +1 -1
- data/lib/generators/app_manager/install/templates/app_manager.rb.tt +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c95901b20e1d3c4085bf8c8405134e61d4a4866e28639a172945e70de743dbfb
|
|
4
|
+
data.tar.gz: c121594095bf641eeed150a9622a4a94a6bbb422ae958833ded6250dc9a7c881
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 538a10b897e1345edabc150ae24d6629ec093ed3aa70b34f84be0ebbc2af3b82c8c29a6ed7be929a5d66c7b9af7a36bdf6a264a2d6ac6afa87a691913e6561d5
|
|
7
|
+
data.tar.gz: 48b7037ace77ff9db72c6d910d1108eaae836e0aae96e380ff4486a80e32f6a17e662fa68ffd84aafb66b9d07cc58f356077072de7f7ea24f716af372b3c1239
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
app_manager (2.
|
|
4
|
+
app_manager (2.4.1)
|
|
5
5
|
activerecord-import (~> 1.4)
|
|
6
6
|
httparty
|
|
7
7
|
kaminari (>= 0.16.3)
|
|
@@ -103,7 +103,7 @@ GEM
|
|
|
103
103
|
diff-lcs (1.6.2)
|
|
104
104
|
dotenv (2.1.2)
|
|
105
105
|
drb (2.2.3)
|
|
106
|
-
erb (6.0.
|
|
106
|
+
erb (6.0.2)
|
|
107
107
|
erubi (1.13.1)
|
|
108
108
|
globalid (1.3.0)
|
|
109
109
|
activesupport (>= 6.1)
|
|
@@ -147,7 +147,8 @@ GEM
|
|
|
147
147
|
method_source (1.1.0)
|
|
148
148
|
mini_mime (1.1.5)
|
|
149
149
|
mini_portile2 (2.8.9)
|
|
150
|
-
minitest (6.0.
|
|
150
|
+
minitest (6.0.2)
|
|
151
|
+
drb (~> 2.0)
|
|
151
152
|
prism (~> 1.5)
|
|
152
153
|
multi_xml (0.8.1)
|
|
153
154
|
bigdecimal (>= 3.1, < 5)
|
|
@@ -205,8 +206,8 @@ GEM
|
|
|
205
206
|
activesupport (>= 5.0.0)
|
|
206
207
|
minitest
|
|
207
208
|
nokogiri (>= 1.6)
|
|
208
|
-
rails-html-sanitizer (1.
|
|
209
|
-
loofah (~> 2.
|
|
209
|
+
rails-html-sanitizer (1.7.0)
|
|
210
|
+
loofah (~> 2.25)
|
|
210
211
|
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
|
211
212
|
railties (8.1.2)
|
|
212
213
|
actionpack (= 8.1.2)
|
|
@@ -257,7 +258,7 @@ GEM
|
|
|
257
258
|
base64
|
|
258
259
|
websocket-extensions (>= 0.1.0)
|
|
259
260
|
websocket-extensions (0.1.5)
|
|
260
|
-
zeitwerk (2.7.
|
|
261
|
+
zeitwerk (2.7.5)
|
|
261
262
|
|
|
262
263
|
PLATFORMS
|
|
263
264
|
ruby
|
|
@@ -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_data['is_global'] == 0
|
|
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])
|
|
@@ -13,6 +13,8 @@ module AppManager
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
def plans
|
|
16
|
+
most_popular_plan_ids_raw = AppManager.configuration.most_popular_plan_ids || []
|
|
17
|
+
most_popular_plan_ids = Array(most_popular_plan_ids_raw).filter_map { |v| v.to_s =~ /\A\d+\z/ ? v.to_i : nil }.uniq
|
|
16
18
|
active_plan_id_or_name = nil
|
|
17
19
|
shopify_plan = nil
|
|
18
20
|
plan = nil
|
|
@@ -96,6 +98,7 @@ module AppManager
|
|
|
96
98
|
'bundle_plan' => bundle_plan,
|
|
97
99
|
'bundle_details' => app_bundle_data,
|
|
98
100
|
'default_plan_id' => default_plan_id,
|
|
101
|
+
'most_popular_plan_ids' => most_popular_plan_ids,
|
|
99
102
|
'choose_later' => choose_later,
|
|
100
103
|
'has_active_charge' => (((active_charge && active_charge.any? && !active_charge['active_charge'].nil?) or !trial_activated_at) ? true : false),
|
|
101
104
|
'global_plan_charge' => plan.present? && plan['is_global'] && active_charge.present? && active_charge.any? && !active_charge['active_charge'].nil? && !active_charge['bundle_charge'].nil?
|
|
@@ -192,20 +195,50 @@ module AppManager
|
|
|
192
195
|
|
|
193
196
|
def fail_safe_backup
|
|
194
197
|
params_permit
|
|
198
|
+
backup_type = params[:backup_type] || "full"
|
|
199
|
+
if (backup_type == "incremental")
|
|
200
|
+
fail_safe_incremental_backup
|
|
201
|
+
else
|
|
202
|
+
rebuild_failsafe
|
|
203
|
+
end
|
|
204
|
+
head :ok
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def fail_safe_incremental_backup
|
|
195
208
|
Thread.new do
|
|
196
209
|
@fs = AppManager::FailSafe.new
|
|
197
210
|
begin
|
|
198
|
-
|
|
211
|
+
@fs.sync_app_manager
|
|
199
212
|
rescue Exception => e
|
|
200
213
|
Rails.logger.info "APP MANAGER >>>> LOCAL DB couldn't sync with POTAL DB #{e.inspect}"
|
|
201
214
|
end
|
|
202
215
|
|
|
203
216
|
begin
|
|
204
|
-
|
|
205
|
-
|
|
217
|
+
@fs.fail_safe_incremental_backup(params)
|
|
218
|
+
rescue Exception => e
|
|
219
|
+
Rails.logger.info "APP MANAGER fail_safe_incremental_backup >>>> #{e.inspect}"
|
|
220
|
+
end
|
|
221
|
+
AppManager.clear_cache
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def rebuild_failsafe
|
|
227
|
+
params_permit
|
|
228
|
+
Thread.new do
|
|
229
|
+
@fs = AppManager::FailSafe.new
|
|
230
|
+
begin
|
|
231
|
+
@fs.sync_app_manager
|
|
232
|
+
rescue Exception => e
|
|
233
|
+
Rails.logger.info "APP MANAGER >>>> LOCAL DB couldn't sync with POTAL DB #{e.inspect}"
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
begin
|
|
237
|
+
@fs.save_api_data(params)
|
|
238
|
+
rescue Exception => e
|
|
206
239
|
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
|
207
|
-
|
|
208
|
-
|
|
240
|
+
end
|
|
241
|
+
AppManager.clear_cache
|
|
209
242
|
end
|
|
210
243
|
head :ok
|
|
211
244
|
end
|
data/config/routes.rb
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
AppManager::Engine.routes.draw do
|
|
2
2
|
scope 'api/app-manager' do
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
scope 'app-manager-api' do
|
|
20
|
-
post 'store-charge' => 'plans#store_charge'
|
|
21
|
-
end
|
|
3
|
+
get 'marketing-banners' => 'banners#marketing_banner'
|
|
4
|
+
get 'plan-features' => 'plans#index'
|
|
5
|
+
get 'plans' => 'plans#plans'
|
|
6
|
+
get 'users' => 'plans#users'
|
|
7
|
+
post 'active-without-plan' => 'plans#active_without_plan'
|
|
8
|
+
post 'burst-cache' => 'plans#burst_cache'
|
|
9
|
+
post 'fail-safe-backup' => 'plans#fail_safe_backup'
|
|
10
|
+
post 'fail-safe-backup-full' => 'plans#rebuild_failsafe'
|
|
11
|
+
get 'plan/process/:plan_id' => 'charges#process_plan'
|
|
12
|
+
get 'plan/callback' => 'charges#callback', as: :plan_callback
|
|
13
|
+
post 'cancel-charge' => 'charges#cancel_charge'
|
|
14
|
+
post 'plan/activate-global' => 'charges#activate_global'
|
|
15
|
+
post 'plan/cancel-global' => 'charges#cancel_global'
|
|
16
|
+
scope 'app-manager-api' do
|
|
17
|
+
post 'store-charge' => 'plans#store_charge'
|
|
18
|
+
end
|
|
22
19
|
end
|
|
23
20
|
end
|
data/lib/app_manager/config.rb
CHANGED
|
@@ -14,6 +14,7 @@ module AppManager
|
|
|
14
14
|
attr_accessor :field_names
|
|
15
15
|
attr_accessor :refresh_by_request_params
|
|
16
16
|
attr_accessor :shopify_app_slug
|
|
17
|
+
attr_accessor :most_popular_plan_ids
|
|
17
18
|
attr_accessor :plan_page_route
|
|
18
19
|
|
|
19
20
|
def initialize
|
|
@@ -28,6 +29,7 @@ module AppManager
|
|
|
28
29
|
@plan_id_or_name_field = nil
|
|
29
30
|
@shopify_app_slug = nil
|
|
30
31
|
@plan_page_route = nil
|
|
32
|
+
@most_popular_plan_ids = []
|
|
31
33
|
@field_names = {
|
|
32
34
|
'name' => 'shopify_domain', # sample example: demo-chirag-parmar.myshopify.com
|
|
33
35
|
'shopify_email' => 'email', # chirag.p@hulkapps.com
|
|
@@ -94,5 +96,8 @@ module AppManager
|
|
|
94
96
|
@plan_page_route
|
|
95
97
|
end
|
|
96
98
|
|
|
99
|
+
def most_popular_plan_ids
|
|
100
|
+
@most_popular_plan_ids
|
|
101
|
+
end
|
|
97
102
|
end
|
|
98
103
|
end
|
|
@@ -110,7 +110,9 @@ module AppManager
|
|
|
110
110
|
store_base_plan = plan['store_base_plan'] ? 1 : 0
|
|
111
111
|
choose_later_plan = plan['choose_later_plan'] ? 1 : 0
|
|
112
112
|
is_external_charge = plan['is_external_charge'] ? 1 : 0
|
|
113
|
+
if !plan["id"].nil?
|
|
113
114
|
plan_data << AppManager::Plan.new(plan_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"],is_external_charge: plan["is_external_charge"],external_charge_limit: plan["external_charge_limit"],terms: plan["terms"])
|
|
115
|
+
end
|
|
114
116
|
end
|
|
115
117
|
AppManager::Plan.bulk_import plan_data
|
|
116
118
|
end
|
|
@@ -128,7 +130,9 @@ module AppManager
|
|
|
128
130
|
charge_data = []
|
|
129
131
|
charges.each do |charge|
|
|
130
132
|
charge_test = charge['test'] ? true : false
|
|
133
|
+
if !charge["id"].nil?
|
|
131
134
|
charge_data << AppManager::Charge.new(c_id: charge["id"],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)
|
|
135
|
+
end
|
|
132
136
|
end
|
|
133
137
|
AppManager::Charge.bulk_import charge_data
|
|
134
138
|
end
|
|
@@ -148,7 +152,7 @@ module AppManager
|
|
|
148
152
|
# 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'])
|
|
149
153
|
apps_data << AppManager::App.new(app_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'])
|
|
150
154
|
end
|
|
151
|
-
AppManager::
|
|
155
|
+
AppManager::App.bulk_import apps_data
|
|
152
156
|
end
|
|
153
157
|
end
|
|
154
158
|
|
|
@@ -207,7 +211,7 @@ module AppManager
|
|
|
207
211
|
if plan_users.any?
|
|
208
212
|
extend_plan_users = []
|
|
209
213
|
plan_users.each do |plan_user|
|
|
210
|
-
extend_plan_users << AppManager::PlanUser.new(plan_user_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'])
|
|
214
|
+
extend_plan_users << AppManager::PlanUser.new(plan_user_id: plan_user['id'],shop_domain: plan_user['shop_domain'], plan_id: plan_user['plan_id'], app_id: plan_user['app_id'],created_by: plan_user['created_by'], created_at: plan_user['created_at'], updated_at: plan_user['updated_at'])
|
|
211
215
|
# 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'])
|
|
212
216
|
end
|
|
213
217
|
AppManager::PlanUser.bulk_import extend_plan_users
|
|
@@ -754,6 +758,262 @@ module AppManager
|
|
|
754
758
|
end
|
|
755
759
|
|
|
756
760
|
|
|
761
|
+
|
|
762
|
+
def standardize_data_format(data)
|
|
763
|
+
case data
|
|
764
|
+
when Array
|
|
765
|
+
data
|
|
766
|
+
when Hash
|
|
767
|
+
[data]
|
|
768
|
+
else
|
|
769
|
+
[]
|
|
770
|
+
end
|
|
771
|
+
end
|
|
772
|
+
|
|
773
|
+
def single_record?(data)
|
|
774
|
+
return true if data.is_a?(Hash) && data.key?("id")
|
|
775
|
+
return true if data.respond_to?(:id) && data.id.present?
|
|
776
|
+
false
|
|
777
|
+
end
|
|
778
|
+
|
|
779
|
+
def format_date(value)
|
|
780
|
+
Time.parse(value.to_s).strftime("%Y-%m-%d %H:%M:%S")
|
|
781
|
+
rescue
|
|
782
|
+
value
|
|
783
|
+
end
|
|
784
|
+
|
|
785
|
+
def filter_data(data, date_fields = [], exclude_keys = %w[app_id pivot])
|
|
786
|
+
rows = standardize_data_format(data)
|
|
787
|
+
|
|
788
|
+
processed = rows.map do |row|
|
|
789
|
+
row = row.is_a?(Hash) ? row : {}
|
|
790
|
+
serialize_row_for_failsafe(row, date_fields, exclude_keys)
|
|
791
|
+
end
|
|
792
|
+
|
|
793
|
+
processed.first || {}
|
|
794
|
+
end
|
|
795
|
+
|
|
796
|
+
def serialize_row_for_failsafe(row, date_fields, exclude_keys)
|
|
797
|
+
row.each_with_object({}) do |(key, value), result|
|
|
798
|
+
next if exclude_keys.include?(key.to_s)
|
|
799
|
+
|
|
800
|
+
if date_fields.include?(key.to_s) && value.present?
|
|
801
|
+
result[key] = format_date(value)
|
|
802
|
+
elsif value.is_a?(Hash) || value.is_a?(Array)
|
|
803
|
+
result[key] = value.to_json
|
|
804
|
+
else
|
|
805
|
+
result[key] = value
|
|
806
|
+
end
|
|
807
|
+
end
|
|
808
|
+
end
|
|
809
|
+
|
|
810
|
+
def fail_safe_incremental_backup(params)
|
|
811
|
+
params = params.to_unsafe_h.deep_stringify_keys
|
|
812
|
+
|
|
813
|
+
sync_type = params["sync_type"]
|
|
814
|
+
payload = params["payload"] || {}
|
|
815
|
+
|
|
816
|
+
#initialize_failsafe_db
|
|
817
|
+
|
|
818
|
+
date_fields = %w[
|
|
819
|
+
created_at
|
|
820
|
+
updated_at
|
|
821
|
+
deleted_at
|
|
822
|
+
valid_from
|
|
823
|
+
valid_to
|
|
824
|
+
cancelled_on
|
|
825
|
+
]
|
|
826
|
+
|
|
827
|
+
case sync_type
|
|
828
|
+
|
|
829
|
+
when "plans"
|
|
830
|
+
|
|
831
|
+
payload["plan_id"] = payload.delete("id")
|
|
832
|
+
payload["test"] ||= 0
|
|
833
|
+
|
|
834
|
+
filtered = filter_data(payload, date_fields)
|
|
835
|
+
|
|
836
|
+
record = AppManager::Plan.find_or_initialize_by(
|
|
837
|
+
plan_id: filtered["plan_id"]
|
|
838
|
+
)
|
|
839
|
+
|
|
840
|
+
record.update!(filtered)
|
|
841
|
+
when "plan-delete"
|
|
842
|
+
AppManager::Plan.where(plan_id: payload["id"]).delete_all
|
|
843
|
+
|
|
844
|
+
when "plan-user-delete"
|
|
845
|
+
AppManager::PlanUser.where(shop_domain: payload["shop_domain"]).delete_all
|
|
846
|
+
|
|
847
|
+
when "charges"
|
|
848
|
+
payload["c_id"] = payload.delete("id")
|
|
849
|
+
filtered = filter_data(payload, date_fields)
|
|
850
|
+
|
|
851
|
+
record = AppManager::Charge.find_or_initialize_by(c_id: filtered["c_id"])
|
|
852
|
+
record.update!(filtered)
|
|
853
|
+
|
|
854
|
+
when "charges-cancel"
|
|
855
|
+
AppManager::Charge
|
|
856
|
+
.where(shop_domain: payload["shop_domain"])
|
|
857
|
+
.update_all(
|
|
858
|
+
status: "cancelled",
|
|
859
|
+
cancelled_on: format_date(payload["cancelled_on"] || Time.current),
|
|
860
|
+
updated_at: format_date(Time.current)
|
|
861
|
+
)
|
|
862
|
+
|
|
863
|
+
when "banners"
|
|
864
|
+
record = AppManager::AppStructure.first_or_initialize
|
|
865
|
+
|
|
866
|
+
record.banners =
|
|
867
|
+
if payload.is_a?(String)
|
|
868
|
+
payload
|
|
869
|
+
else
|
|
870
|
+
payload.to_json
|
|
871
|
+
end
|
|
872
|
+
|
|
873
|
+
record.save!
|
|
874
|
+
|
|
875
|
+
when "promotional-discounts"
|
|
876
|
+
|
|
877
|
+
# Normalize main payload
|
|
878
|
+
payload["discount_id"] = payload.delete("id")
|
|
879
|
+
payload["discount_type"] = payload.delete("type")
|
|
880
|
+
|
|
881
|
+
filtered = filter_data(payload, date_fields, ["pivot"])
|
|
882
|
+
|
|
883
|
+
main_data = filtered.except(
|
|
884
|
+
"shops_relation",
|
|
885
|
+
"apps_relation",
|
|
886
|
+
"plans_relation",
|
|
887
|
+
"usage_relation"
|
|
888
|
+
)
|
|
889
|
+
|
|
890
|
+
discount = AppManager::Discount.find_or_initialize_by(
|
|
891
|
+
discount_id: main_data["discount_id"]
|
|
892
|
+
)
|
|
893
|
+
discount.update!(main_data)
|
|
894
|
+
|
|
895
|
+
# ==========================================================
|
|
896
|
+
# SHOPS RELATION
|
|
897
|
+
# ==========================================================
|
|
898
|
+
|
|
899
|
+
if payload["shops_relation"].present?
|
|
900
|
+
|
|
901
|
+
AppManager::DiscountShop
|
|
902
|
+
.where(discount_id: main_data["discount_id"])
|
|
903
|
+
.delete_all
|
|
904
|
+
|
|
905
|
+
rows = Array(payload["shops_relation"]).map do |row|
|
|
906
|
+
row = row.deep_stringify_keys
|
|
907
|
+
|
|
908
|
+
{
|
|
909
|
+
"discount_id" => main_data["discount_id"],
|
|
910
|
+
"domain" => row["domain"]
|
|
911
|
+
}
|
|
912
|
+
end
|
|
913
|
+
|
|
914
|
+
AppManager::DiscountShop.insert_all(rows) if rows.present?
|
|
915
|
+
end
|
|
916
|
+
|
|
917
|
+
# ==========================================================
|
|
918
|
+
# PLANS RELATION
|
|
919
|
+
# ==========================================================
|
|
920
|
+
|
|
921
|
+
if payload["plans_relation"].present?
|
|
922
|
+
|
|
923
|
+
AppManager::DiscountLinkPlan
|
|
924
|
+
.where(discount_id: main_data["discount_id"])
|
|
925
|
+
.delete_all
|
|
926
|
+
|
|
927
|
+
rows = Array(payload["plans_relation"]).map do |row|
|
|
928
|
+
row = row.deep_stringify_keys
|
|
929
|
+
|
|
930
|
+
{
|
|
931
|
+
"discount_id" => main_data["discount_id"],
|
|
932
|
+
"plan_id" => row["plan_id"]
|
|
933
|
+
}
|
|
934
|
+
end
|
|
935
|
+
|
|
936
|
+
AppManager::DiscountLinkPlan.insert_all(rows) if rows.present?
|
|
937
|
+
end
|
|
938
|
+
|
|
939
|
+
# ==========================================================
|
|
940
|
+
# USAGE RELATION
|
|
941
|
+
# ==========================================================
|
|
942
|
+
|
|
943
|
+
if payload["usage_relation"].present?
|
|
944
|
+
|
|
945
|
+
AppManager::DiscountUsageLog
|
|
946
|
+
.where(discount_id: main_data["discount_id"])
|
|
947
|
+
.delete_all
|
|
948
|
+
|
|
949
|
+
rows = Array(payload["usage_relation"]).map do |row|
|
|
950
|
+
row = row.deep_stringify_keys
|
|
951
|
+
{
|
|
952
|
+
"discount_id" => main_data["discount_id"],
|
|
953
|
+
"domain" => row["domain"],
|
|
954
|
+
"created_at" => row["created_at"],
|
|
955
|
+
"updated_at" => row["updated_at"],
|
|
956
|
+
"app_id" => row["app_id"],
|
|
957
|
+
"sync" => row['sync'],
|
|
958
|
+
"process_type" => row['process_type']
|
|
959
|
+
}
|
|
960
|
+
end
|
|
961
|
+
|
|
962
|
+
AppManager::DiscountUsageLog.insert_all(rows) if rows.present?
|
|
963
|
+
end
|
|
964
|
+
|
|
965
|
+
when "promotional-discounts-delete"
|
|
966
|
+
AppManager::Discount
|
|
967
|
+
.where(discount_id: payload["id"])
|
|
968
|
+
.update_all(
|
|
969
|
+
deleted_at: format_date(payload["deleted_at"] || Time.current),
|
|
970
|
+
updated_at: format_date(Time.current)
|
|
971
|
+
)
|
|
972
|
+
|
|
973
|
+
when "plan-discount"
|
|
974
|
+
filtered = filter_data(payload, date_fields)
|
|
975
|
+
|
|
976
|
+
record = AppManager::DiscountPlan.find_or_initialize_by(
|
|
977
|
+
discount_plan_id: filtered["discount_plan_id"]
|
|
978
|
+
)
|
|
979
|
+
record.update!(filtered)
|
|
980
|
+
|
|
981
|
+
when "plan-user"
|
|
982
|
+
payload["plan_user_id"] = payload.delete("id")
|
|
983
|
+
filtered = filter_data(payload, date_fields)
|
|
984
|
+
|
|
985
|
+
record = AppManager::PlanUser.find_or_initialize_by(
|
|
986
|
+
plan_user_id: filtered["plan_user_id"]
|
|
987
|
+
)
|
|
988
|
+
record.update!(filtered)
|
|
989
|
+
|
|
990
|
+
when "extend-trial"
|
|
991
|
+
filtered = filter_data(payload, date_fields)
|
|
992
|
+
|
|
993
|
+
record = AppManager::ExtendTrial.find_or_initialize_by(
|
|
994
|
+
extend_trial_id: filtered["extend_trial_id"]
|
|
995
|
+
)
|
|
996
|
+
record.update!(filtered)
|
|
997
|
+
|
|
998
|
+
when "promotional-discounts-app-removed"
|
|
999
|
+
|
|
1000
|
+
discount_id = payload["id"]
|
|
1001
|
+
|
|
1002
|
+
AppManager::Discount
|
|
1003
|
+
.where(discount_id: discount_id)
|
|
1004
|
+
.delete_all
|
|
1005
|
+
|
|
1006
|
+
AppManager::DiscountShop
|
|
1007
|
+
.where(discount_id: discount_id)
|
|
1008
|
+
.delete_all
|
|
1009
|
+
|
|
1010
|
+
AppManager::DiscountUsageLog
|
|
1011
|
+
.where(discount_id: discount_id)
|
|
1012
|
+
.delete_all
|
|
1013
|
+
else
|
|
1014
|
+
# Rails.logger.error("Failsafe: Unhandled sync type: #{sync_type}")
|
|
1015
|
+
end
|
|
1016
|
+
end
|
|
757
1017
|
end
|
|
758
1018
|
|
|
759
1019
|
end
|
data/lib/app_manager/version.rb
CHANGED
|
@@ -8,6 +8,7 @@ AppManager.configure do |config|
|
|
|
8
8
|
config.shopify_domain_field = 'shopify_domain' #shopify domain field
|
|
9
9
|
config.plan_id_or_name_field = 'plan_id'
|
|
10
10
|
config.shopify_app_slug = '' #Add your app slug here
|
|
11
|
+
config.most_popular_plan_ids = [] #Add your app slug here
|
|
11
12
|
config.field_names = {
|
|
12
13
|
'name' => 'shopify_domain', # demo-rahul-tiwari.myshopify.com
|
|
13
14
|
'shopify_email' => 'email', # rahul.t@hulkapps.com
|
|
@@ -17,6 +18,7 @@ AppManager.configure do |config|
|
|
|
17
18
|
'created_at' => 'created_at', # 2022-04-15 10:43:05
|
|
18
19
|
'trial_activated_at' => 'trial_activated_at', # field name that stores trial start/activated date
|
|
19
20
|
'grandfathered' => 'grandfathered',
|
|
21
|
+
'partner_development' => 'partner_development',
|
|
20
22
|
'total_trial_days' => '' #optional, put a trial days field from your shops table otherwise leave it blank
|
|
21
23
|
}
|
|
22
24
|
config.plan_features = [
|
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.
|
|
4
|
+
version: 2.4.1
|
|
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: 2026-02-
|
|
11
|
+
date: 2026-02-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|