app_manager 1.1.7 → 1.2.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 +3 -3
- data/README.md +24 -4
- data/app/controllers/app_manager/charges_controller.rb +26 -10
- data/app/controllers/app_manager/plans_controller.rb +30 -11
- data/lib/app_manager/client/plans.rb +6 -2
- data/lib/app_manager/fail_safe.rb +55 -11
- data/lib/app_manager/graphql_helper.rb +26 -0
- data/lib/app_manager/model.rb +74 -17
- data/lib/app_manager/version.rb +1 -1
- data/lib/generators/app_manager/install/templates/app_manager.rb.tt +4 -2
- 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: bd770dce16b7f6239b4d98067abafbf7701a3dd5b02cd4094b2f264c2ce9d8dd
|
|
4
|
+
data.tar.gz: 466aa7a4aba2811f53b582b0d2fa6dd7b94b2eb0430ef146729214414175ad8c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6d6e415883e4a5e08155776f041da234c099ec0a9c17814be2013d7efafa91263d117046c35b2dd95c4a0809230a637878cb1d9e1f785b385e9f9588269547db
|
|
7
|
+
data.tar.gz: 0d3e02114538f9178a88cfc1e2f30409227852088755121c47dd1648d20bd1919e78228f197c41199ae02f2251fef66953ae6ee560b46389ded1bd555f48088a
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
app_manager (1.1
|
|
4
|
+
app_manager (1.2.1)
|
|
5
5
|
httparty
|
|
6
6
|
kaminari (>= 0.16.3)
|
|
7
7
|
rails (>= 5.2.0)
|
|
@@ -119,7 +119,7 @@ GEM
|
|
|
119
119
|
mime-types-data (3.2022.0105)
|
|
120
120
|
mini_mime (1.1.2)
|
|
121
121
|
mini_portile2 (2.8.0)
|
|
122
|
-
minitest (5.16.
|
|
122
|
+
minitest (5.16.2)
|
|
123
123
|
multi_xml (0.6.0)
|
|
124
124
|
net-imap (0.2.3)
|
|
125
125
|
digest
|
|
@@ -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.
|
|
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.
|
|
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,17 +13,32 @@ 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',{
|
|
21
35
|
"plan" => plan_data,
|
|
22
36
|
"charge" => nil,
|
|
23
|
-
"previous_charge" => nil
|
|
37
|
+
"previous_charge" => nil,
|
|
38
|
+
"shopify_domain" => params[:shop]
|
|
24
39
|
})
|
|
25
40
|
rescue Exception => e
|
|
26
|
-
Rails.logger.info "APP
|
|
41
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
|
27
42
|
end
|
|
28
43
|
AppManager.clear_cache
|
|
29
44
|
render json: {'redirect_url' => "#{app_url}?shop=#{params[:shop]}"} and return true
|
|
@@ -68,17 +83,17 @@ module AppManager
|
|
|
68
83
|
plan_data = plan_obj.get_plan(params[:plan],params[:shop])
|
|
69
84
|
|
|
70
85
|
charge = charges.parsed_response['recurring_application_charge']
|
|
71
|
-
charge['charge_id'] = charge['id']
|
|
72
|
-
charge['type'] = 'recurring'
|
|
73
|
-
charge['plan_id'] = params[:plan]
|
|
74
|
-
charge['shop_domain'] = params[:shop]
|
|
75
|
-
charge['interval'] = plan_data['interval']['value']
|
|
86
|
+
charge['charge_id'] = charge['id']
|
|
87
|
+
charge['type'] = 'recurring'
|
|
88
|
+
charge['plan_id'] = params[:plan]
|
|
89
|
+
charge['shop_domain'] = params[:shop]
|
|
90
|
+
charge['interval'] = plan_data['interval']['value']
|
|
76
91
|
|
|
77
92
|
if !@plan_field.nil?
|
|
78
93
|
begin
|
|
79
94
|
plan_obj.cancel_charge(@shop[shopify_domain],@shop[@plan_field])
|
|
80
95
|
rescue Exception => e
|
|
81
|
-
Rails.logger.info "APP
|
|
96
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
|
82
97
|
end
|
|
83
98
|
end
|
|
84
99
|
|
|
@@ -93,10 +108,11 @@ module AppManager
|
|
|
93
108
|
AppManager::EventHandler.new('charge_created',{
|
|
94
109
|
"plan" => plan_data,
|
|
95
110
|
"charge" => charge,
|
|
96
|
-
"previous_charge" => charge_data ? (charge_data['cancelled_charge'] || nil) : nil
|
|
111
|
+
"previous_charge" => charge_data ? (charge_data['cancelled_charge'] || nil) : nil,
|
|
112
|
+
"shopify_domain" => params[:shop]
|
|
97
113
|
})
|
|
98
114
|
rescue Exception => e
|
|
99
|
-
Rails.logger.info "APP
|
|
115
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
|
100
116
|
end
|
|
101
117
|
end
|
|
102
118
|
redirect_to "#{app_url}?shop=#{params[:shop]}", :status => 301 and return
|
|
@@ -13,36 +13,38 @@ module AppManager
|
|
|
13
13
|
|
|
14
14
|
def plans
|
|
15
15
|
active_plan_id_or_name = shopify_plan = plan = nil
|
|
16
|
+
active_charge = nil
|
|
16
17
|
default_plan_id = nil
|
|
17
18
|
choose_later = false
|
|
18
19
|
plan_obj = AppManager::Client.new
|
|
19
20
|
plans = []
|
|
20
21
|
if params[:shop_domain].present? && !AppManager.configuration.plan_features.nil?
|
|
21
|
-
plans = plan_obj.get_plans(params[:shop_domain])
|
|
22
22
|
@shop = shop_data
|
|
23
23
|
if !@shop.nil?
|
|
24
|
-
active_plan_id_or_name = @shop[@plan_field]
|
|
24
|
+
active_plan_id_or_name = @shop[@plan_field] rescue nil
|
|
25
|
+
plans = plan_obj.get_plans(params[:shop_domain],active_plan_id_or_name)
|
|
25
26
|
if !@field_names.nil? && @field_names.has_key?('shopify_plan') && !@field_names.nil?
|
|
26
27
|
shopify_plan_field = AppManager.configuration.field_names['shopify_plan']
|
|
27
28
|
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
|
|
29
|
+
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
30
|
|
|
30
31
|
@trial_activated_field = AppManager.configuration.field_names['trial_activated_at']
|
|
31
32
|
trial_activated_at = @shop[@trial_activated_field] rescue nil
|
|
32
33
|
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
|
|
34
|
+
if active_charge && active_charge.any? && active_charge['active_charge'].nil? && active_charge['cancelled_charge'].nil? && !trial_activated_at
|
|
34
35
|
choose_later = true
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
end
|
|
38
39
|
else
|
|
39
|
-
Rails.logger.info "APP
|
|
40
|
+
Rails.logger.info "APP MANAGER >>>> Either model is defined wrong or config.plan_id_or_name_field is nil in initializer ==="
|
|
40
41
|
end
|
|
41
42
|
else
|
|
42
|
-
Rails.logger.info "APP
|
|
43
|
+
Rails.logger.info "APP MANAGER >>>> Either params missing store_domain or config.plan_features is nil in initializer ==="
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
|
|
47
|
+
plans = plan_obj.get_plans(params[:shop_domain]) if plans && plans.blank?
|
|
46
48
|
default_plan_data = plans.select{|x| x['choose_later_plan'] == true }
|
|
47
49
|
if default_plan_data.any?
|
|
48
50
|
if default_plan_data.select{|x| x['store_base_plan'] == true }.size > 0
|
|
@@ -63,7 +65,8 @@ module AppManager
|
|
|
63
65
|
'shopify_plan' => shopify_plan,
|
|
64
66
|
'plan' => plan,
|
|
65
67
|
'default_plan_id' => default_plan_id,
|
|
66
|
-
'choose_later' => choose_later
|
|
68
|
+
'choose_later' => choose_later,
|
|
69
|
+
'has_active_charge' => (!active_charge['active_charge'].nil? ? true : false)
|
|
67
70
|
}
|
|
68
71
|
render json: response
|
|
69
72
|
end
|
|
@@ -118,8 +121,24 @@ module AppManager
|
|
|
118
121
|
if params[:shop_domain].present? && params[:plan_id].present? && model
|
|
119
122
|
@shop = shop_data
|
|
120
123
|
@trial_activated_field = AppManager.configuration.field_names['trial_activated_at']
|
|
121
|
-
@shop.update(@plan_field => params[:plan_id],@trial_activated_field => DateTime.now)
|
|
122
|
-
|
|
124
|
+
if @shop.update(@plan_field => params[:plan_id],@trial_activated_field => DateTime.now)
|
|
125
|
+
begin
|
|
126
|
+
plan_obj = AppManager::Client.new
|
|
127
|
+
plan_data = plan_obj.get_plan(params[:plan_id],params[:shop_domain]) rescue nil
|
|
128
|
+
AppManager::EventHandler.new('charge_created',{
|
|
129
|
+
"plan" => plan_data,
|
|
130
|
+
"charge" => nil,
|
|
131
|
+
"previous_charge" => nil,
|
|
132
|
+
"choose_later" => true,
|
|
133
|
+
"shopify_domain" => params[:shop_domain]
|
|
134
|
+
})
|
|
135
|
+
rescue Exception => e
|
|
136
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
|
137
|
+
end
|
|
138
|
+
render json: {'status' => true}
|
|
139
|
+
else
|
|
140
|
+
render json: {'status' => false,'error' => "#{@shop.errors.full_messages.to_sentence}"}, status: 422
|
|
141
|
+
end
|
|
123
142
|
else
|
|
124
143
|
render json: {'status' => false,'error' => 'Shop not found or missing shop'}, status: 422
|
|
125
144
|
end
|
|
@@ -139,13 +158,13 @@ module AppManager
|
|
|
139
158
|
begin
|
|
140
159
|
@fs.sync_app_manager
|
|
141
160
|
rescue Exception => e
|
|
142
|
-
Rails.logger.info "APP
|
|
161
|
+
Rails.logger.info "APP MANAGER >>>> LOCAL DB couldn't sync with POTAL DB #{e.inspect}"
|
|
143
162
|
end
|
|
144
163
|
|
|
145
164
|
begin
|
|
146
165
|
@fs.save_api_data(params)
|
|
147
166
|
rescue Exception => e
|
|
148
|
-
Rails.logger.info "APP
|
|
167
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
|
149
168
|
end
|
|
150
169
|
AppManager.clear_cache
|
|
151
170
|
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
|
|
@@ -28,37 +28,37 @@ module AppManager
|
|
|
28
28
|
begin
|
|
29
29
|
save_api_plans(params["plans"])
|
|
30
30
|
rescue Exception => e
|
|
31
|
-
Rails.logger.info "APP
|
|
31
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
|
32
32
|
end
|
|
33
33
|
begin
|
|
34
34
|
save_api_charges(params["charges"])
|
|
35
35
|
rescue Exception => e
|
|
36
|
-
Rails.logger.info "APP
|
|
36
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
|
37
37
|
end
|
|
38
38
|
begin
|
|
39
39
|
save_api_apps(params["apps"])
|
|
40
40
|
rescue Exception => e
|
|
41
|
-
Rails.logger.info "APP
|
|
41
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
|
42
42
|
end
|
|
43
43
|
begin
|
|
44
44
|
save_api_app_structures(params["app_structures"])
|
|
45
45
|
rescue Exception => e
|
|
46
|
-
Rails.logger.info "APP
|
|
46
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
|
47
47
|
end
|
|
48
48
|
begin
|
|
49
49
|
save_api_discount_plans(params["discount_plans"])
|
|
50
50
|
rescue Exception => e
|
|
51
|
-
Rails.logger.info "APP
|
|
51
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
|
52
52
|
end
|
|
53
53
|
begin
|
|
54
54
|
save_api_extend_trials(params["extend_trials"])
|
|
55
55
|
rescue Exception => e
|
|
56
|
-
Rails.logger.info "APP
|
|
56
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
|
57
57
|
end
|
|
58
58
|
begin
|
|
59
59
|
save_api_plan_users(params["plan_users"])
|
|
60
60
|
rescue Exception => e
|
|
61
|
-
Rails.logger.info "APP
|
|
61
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
|
|
@@ -194,11 +194,22 @@ module AppManager
|
|
|
194
194
|
|
|
195
195
|
|
|
196
196
|
def get_local_plans(params)
|
|
197
|
+
|
|
197
198
|
plans_data = []
|
|
198
199
|
|
|
199
200
|
active_plan_id = nil
|
|
201
|
+
active_charge_price = nil
|
|
202
|
+
|
|
200
203
|
charges = @apm_db.execute( "SELECT * FROM charges WHERE shop_domain = ? ",params['shop_domain'])
|
|
201
|
-
|
|
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
|
|
202
213
|
|
|
203
214
|
custom_plan_ids = []
|
|
204
215
|
plan_users = @apm_db.execute( "SELECT * FROM plan_users WHERE shop_domain = ? ",params['shop_domain'])
|
|
@@ -232,7 +243,7 @@ module AppManager
|
|
|
232
243
|
new_plan[key] = val.collect{|e|e['value']}
|
|
233
244
|
elsif ['affiliate'].include?(key)
|
|
234
245
|
new_plan[key] = eval(value)
|
|
235
|
-
elsif ['is_custom','public','store_base_plan'].include?(key)
|
|
246
|
+
elsif ['is_custom','public','store_base_plan','choose_later_plan'].include?(key)
|
|
236
247
|
new_plan[key] = (value == 0 ? false : true)
|
|
237
248
|
elsif ['test'].include?(key)
|
|
238
249
|
new_plan[key] = (value == 0 ? nil : true)
|
|
@@ -255,12 +266,41 @@ module AppManager
|
|
|
255
266
|
features_by_plan.each do |fp|
|
|
256
267
|
fp['name'] = features.find{|e| e['uuid'] == fp['feature_id']}['name'] rescue nil
|
|
257
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
|
|
258
270
|
features_by_plans_data.push(fp)
|
|
259
271
|
end
|
|
260
272
|
end
|
|
261
273
|
end
|
|
262
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
|
+
|
|
263
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
|
+
|
|
264
304
|
if features_by_plans_data.select{|e| e['plan_id'] == plan['id']}.size > 0
|
|
265
305
|
feature_hash = {}
|
|
266
306
|
features_by_plans_data.select{|e| e['plan_id'] == plan['id']}.each do |fp|
|
|
@@ -271,11 +311,14 @@ module AppManager
|
|
|
271
311
|
features = nil
|
|
272
312
|
end
|
|
273
313
|
plan['features'] = features
|
|
314
|
+
plan['old_plan_id'] = nil
|
|
315
|
+
|
|
274
316
|
end
|
|
275
317
|
|
|
276
318
|
plans = plans_data
|
|
277
319
|
end
|
|
278
320
|
|
|
321
|
+
|
|
279
322
|
return plans
|
|
280
323
|
end
|
|
281
324
|
|
|
@@ -291,7 +334,7 @@ module AppManager
|
|
|
291
334
|
new_plan[key] = val
|
|
292
335
|
elsif ['shopify_plans','affiliate','features'].include?(key)
|
|
293
336
|
new_plan[key] = eval(value)
|
|
294
|
-
elsif ['is_custom','public','store_base_plan'].include?(key)
|
|
337
|
+
elsif ['is_custom','public','store_base_plan','choose_later_plan'].include?(key)
|
|
295
338
|
new_plan[key] = (value == 0 ? false : true)
|
|
296
339
|
elsif ['test'].include?(key)
|
|
297
340
|
new_plan[key] = (value == 0 ? nil : true)
|
|
@@ -308,7 +351,7 @@ module AppManager
|
|
|
308
351
|
end
|
|
309
352
|
plan_data['app'] = app_data
|
|
310
353
|
end
|
|
311
|
-
|
|
354
|
+
plan_data['old_plan_id'] = nil # Temporary for migration puspose only
|
|
312
355
|
if params["shop_domain"].present? && plan_data
|
|
313
356
|
@apm_db.execute( "SELECT * FROM discount_plans WHERE plan_id = ? AND shop_domain = ? ", params["plan_id"],params["shop_domain"]) do |cd|
|
|
314
357
|
plan_data['discount'] = cd['discount'] if cd rescue plan_data['discount']
|
|
@@ -322,6 +365,7 @@ module AppManager
|
|
|
322
365
|
end
|
|
323
366
|
|
|
324
367
|
end
|
|
368
|
+
|
|
325
369
|
return plan_data
|
|
326
370
|
end
|
|
327
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
|
|
data/lib/app_manager/model.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
79
|
-
|
|
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(
|
|
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
|
-
|
|
128
|
+
return plan_obj.get_plans(shop_domain,active_plan_id)
|
|
90
129
|
rescue Exception => e
|
|
91
|
-
|
|
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
|
|
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)
|
data/lib/app_manager/version.rb
CHANGED
|
@@ -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
|
|
4
|
+
version: 1.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hulkapps
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-07-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|