app_manager 1.2.0 → 1.2.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 332f708479d365509b91a40229d7be81e2d4ff29bc14ec4d24f59cad3dd007d8
|
4
|
+
data.tar.gz: addf31453c0847a80a734994ec65d8eaa8eb9a8bf18067359e3e97c5cbd06ac6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cafc22adef5875aea99cc8f8acebc7ee79e187359bf7aa6408d1692390a79af37e721efe3e7fd7a3a23e898b092988eca098a0ce6d3f737cfae30ceb19422243
|
7
|
+
data.tar.gz: d74683f76df315f6a9b03f3f357d09ef63d50f0efd18b64e7fd83a160603cc26078ab82fc1d2c0041772de37f656714f554ac83656514cbd59a2c25220e2efc8
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
app_manager (1.2.
|
4
|
+
app_manager (1.2.3)
|
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
|
@@ -18,11 +18,12 @@ module AppManager
|
|
18
18
|
if plan_data['price'] == 0
|
19
19
|
active_charge_data = plan_obj.get_charge(params[:shop])
|
20
20
|
begin
|
21
|
-
if active_charge_data && active_charge_data.any? && !active_charge_data['active_charge']['charge_id'].nil?
|
21
|
+
if active_charge_data && active_charge_data.any? && !active_charge_data['active_charge'].nil? && !active_charge_data['active_charge']['charge_id'].nil?
|
22
22
|
gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain,@shop.shopify_token)
|
23
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"]["
|
25
|
-
|
24
|
+
if !rec_cancel_data["errors"].present? && (rec_cancel_data["data"].present? && rec_cancel_data["data"]["appSubscriptionCancel"].present? && !rec_cancel_data["data"]["appSubscriptionCancel"]["userErrors"].any? && (rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["status"] == 'CANCELLED'))
|
25
|
+
cancelled_charge_id = rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["id"].split('/')[-1]
|
26
|
+
plan_obj.cancel_charge(params[:shop],cancelled_charge_id)
|
26
27
|
end
|
27
28
|
end
|
28
29
|
rescue Exception => e
|
@@ -34,7 +35,8 @@ module AppManager
|
|
34
35
|
AppManager::EventHandler.new('charge_created',{
|
35
36
|
"plan" => plan_data,
|
36
37
|
"charge" => nil,
|
37
|
-
"previous_charge" => nil
|
38
|
+
"previous_charge" => nil,
|
39
|
+
"shopify_domain" => params[:shop]
|
38
40
|
})
|
39
41
|
rescue Exception => e
|
40
42
|
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
@@ -82,11 +84,11 @@ module AppManager
|
|
82
84
|
plan_data = plan_obj.get_plan(params[:plan],params[:shop])
|
83
85
|
|
84
86
|
charge = charges.parsed_response['recurring_application_charge']
|
85
|
-
charge['charge_id'] = charge['id']
|
86
|
-
charge['type'] = 'recurring'
|
87
|
-
charge['plan_id'] = params[:plan]
|
88
|
-
charge['shop_domain'] = params[:shop]
|
89
|
-
charge['interval'] = plan_data['interval']['value']
|
87
|
+
charge['charge_id'] = charge['id']
|
88
|
+
charge['type'] = 'recurring'
|
89
|
+
charge['plan_id'] = params[:plan]
|
90
|
+
charge['shop_domain'] = params[:shop]
|
91
|
+
charge['interval'] = plan_data['interval']['value']
|
90
92
|
|
91
93
|
if !@plan_field.nil?
|
92
94
|
begin
|
@@ -107,7 +109,8 @@ module AppManager
|
|
107
109
|
AppManager::EventHandler.new('charge_created',{
|
108
110
|
"plan" => plan_data,
|
109
111
|
"charge" => charge,
|
110
|
-
"previous_charge" => charge_data ? (charge_data['cancelled_charge'] || nil) : nil
|
112
|
+
"previous_charge" => charge_data ? (charge_data['cancelled_charge'] || nil) : nil,
|
113
|
+
"shopify_domain" => params[:shop]
|
111
114
|
})
|
112
115
|
rescue Exception => e
|
113
116
|
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
@@ -13,6 +13,7 @@ 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
|
@@ -30,7 +31,7 @@ module AppManager
|
|
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 && 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
|
|
@@ -64,7 +65,8 @@ module AppManager
|
|
64
65
|
'shopify_plan' => shopify_plan,
|
65
66
|
'plan' => plan,
|
66
67
|
'default_plan_id' => default_plan_id,
|
67
|
-
'choose_later' => choose_later
|
68
|
+
'choose_later' => choose_later,
|
69
|
+
'has_active_charge' => (!active_charge['active_charge'].nil? ? true : false)
|
68
70
|
}
|
69
71
|
render json: response
|
70
72
|
end
|
@@ -127,12 +129,13 @@ module AppManager
|
|
127
129
|
"plan" => plan_data,
|
128
130
|
"charge" => nil,
|
129
131
|
"previous_charge" => nil,
|
130
|
-
"choose_later" => true
|
132
|
+
"choose_later" => true,
|
133
|
+
"shopify_domain" => params[:shop_domain]
|
131
134
|
})
|
132
135
|
rescue Exception => e
|
133
136
|
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
134
137
|
end
|
135
|
-
|
138
|
+
render json: {'status' => true}
|
136
139
|
else
|
137
140
|
render json: {'status' => false,'error' => "#{@shop.errors.full_messages.to_sentence}"}, status: 422
|
138
141
|
end
|
@@ -169,6 +172,7 @@ module AppManager
|
|
169
172
|
end
|
170
173
|
|
171
174
|
|
175
|
+
|
172
176
|
private
|
173
177
|
|
174
178
|
def params_permit
|
@@ -29,36 +29,90 @@ module AppManager
|
|
29
29
|
save_api_plans(params["plans"])
|
30
30
|
rescue Exception => e
|
31
31
|
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
32
|
+
begin
|
33
|
+
create_plan_table
|
34
|
+
save_api_plans(params["plans"])
|
35
|
+
rescue Exception => e
|
36
|
+
Rails.logger.info "APP MANAGER FailSafe >>>> #{e.inspect}"
|
37
|
+
end
|
32
38
|
end
|
39
|
+
|
40
|
+
|
33
41
|
begin
|
34
42
|
save_api_charges(params["charges"])
|
35
43
|
rescue Exception => e
|
36
|
-
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
44
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
45
|
+
begin
|
46
|
+
create_charges_table
|
47
|
+
save_api_charges(params["charges"])
|
48
|
+
rescue Exception => e
|
49
|
+
Rails.logger.info "APP MANAGER FailSafe >>>> #{e.inspect}"
|
50
|
+
end
|
37
51
|
end
|
52
|
+
|
53
|
+
|
38
54
|
begin
|
39
55
|
save_api_apps(params["apps"])
|
40
56
|
rescue Exception => e
|
41
|
-
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
57
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
58
|
+
begin
|
59
|
+
create_apps_table
|
60
|
+
save_api_apps(params["apps"])
|
61
|
+
rescue Exception => e
|
62
|
+
Rails.logger.info "APP MANAGER FailSafe >>>> #{e.inspect}"
|
63
|
+
end
|
42
64
|
end
|
65
|
+
|
66
|
+
|
43
67
|
begin
|
44
68
|
save_api_app_structures(params["app_structures"])
|
45
69
|
rescue Exception => e
|
46
|
-
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
70
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
71
|
+
begin
|
72
|
+
create_app_structures_table
|
73
|
+
save_api_app_structures(params["app_structures"])
|
74
|
+
rescue Exception => e
|
75
|
+
Rails.logger.info "APP MANAGER FailSafe >>>> #{e.inspect}"
|
76
|
+
end
|
47
77
|
end
|
78
|
+
|
79
|
+
|
48
80
|
begin
|
49
81
|
save_api_discount_plans(params["discount_plans"])
|
50
82
|
rescue Exception => e
|
51
83
|
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
84
|
+
begin
|
85
|
+
create_discount_plans_table
|
86
|
+
save_api_discount_plans(params["discount_plans"])
|
87
|
+
rescue Exception => e
|
88
|
+
Rails.logger.info "APP MANAGER FailSafe >>>> #{e.inspect}"
|
89
|
+
end
|
52
90
|
end
|
91
|
+
|
92
|
+
|
53
93
|
begin
|
54
94
|
save_api_extend_trials(params["extend_trials"])
|
55
95
|
rescue Exception => e
|
56
|
-
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
96
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
97
|
+
begin
|
98
|
+
create_extend_trials_table
|
99
|
+
save_api_extend_trials(params["extend_trials"])
|
100
|
+
rescue Exception => e
|
101
|
+
Rails.logger.info "APP MANAGER FailSafe >>>> #{e.inspect}"
|
102
|
+
end
|
57
103
|
end
|
104
|
+
|
105
|
+
|
58
106
|
begin
|
59
107
|
save_api_plan_users(params["plan_users"])
|
60
108
|
rescue Exception => e
|
61
|
-
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
109
|
+
Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
|
110
|
+
begin
|
111
|
+
create_plan_users_table
|
112
|
+
save_api_plan_users(params["plan_users"])
|
113
|
+
rescue Exception => e
|
114
|
+
Rails.logger.info "APP MANAGER FailSafe >>>> #{e.inspect}"
|
115
|
+
end
|
62
116
|
end
|
63
117
|
end
|
64
118
|
|
data/lib/app_manager/model.rb
CHANGED
@@ -2,7 +2,8 @@ module AppManager
|
|
2
2
|
module Model
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
|
5
|
+
@@remaining_cache_key = "get_remaining_days_key"
|
6
|
+
@@get_charge_key = "get_charge_key"
|
6
7
|
|
7
8
|
def has_plan
|
8
9
|
if !self[AppManager.configuration.plan_id_or_name_field]
|
@@ -16,14 +17,15 @@ module AppManager
|
|
16
17
|
Rails.logger.info "Plan id found nil or not set"
|
17
18
|
return false;
|
18
19
|
end
|
19
|
-
remaining_days =
|
20
|
+
remaining_days = fetch_static_remaining_days
|
20
21
|
if remaining_days > 0
|
21
22
|
return true
|
22
23
|
end
|
23
|
-
plan_obj = AppManager::Client.new
|
24
|
-
shop_domain = self[AppManager.configuration.shopify_domain_field]
|
25
|
-
active_charge = plan_obj.get_charge(shop_domain) rescue nil
|
26
|
-
|
24
|
+
# plan_obj = AppManager::Client.new
|
25
|
+
# shop_domain = self[AppManager.configuration.shopify_domain_field]
|
26
|
+
# active_charge = plan_obj.get_charge(shop_domain) rescue nil
|
27
|
+
active_charge = fetch_static_get_charge
|
28
|
+
return active_charge && active_charge['active_charge'].present? && !active_charge['active_charge'].nil? ? true : false
|
27
29
|
end
|
28
30
|
|
29
31
|
|
@@ -195,6 +197,40 @@ module AppManager
|
|
195
197
|
|
196
198
|
|
197
199
|
|
200
|
+
def fetch_static_remaining_days
|
201
|
+
@remaining_cache_key = "app-manager-cache/#{self.shopify_domain}-remaining_days"
|
202
|
+
if fetch_cached_static_remaining_days(@remaining_cache_key).present?
|
203
|
+
return fetch_cached_static_remaining_days(@remaining_cache_key)
|
204
|
+
end
|
205
|
+
remaining_days = self.get_remaining_days
|
206
|
+
Rails.cache.write(@remaining_cache_key, remaining_days, expires_in: AppManager.configuration.expires_in)
|
207
|
+
return remaining_days
|
208
|
+
end
|
209
|
+
|
210
|
+
def fetch_cached_static_remaining_days(cache_key)
|
211
|
+
if Rails.cache.read(cache_key).present?
|
212
|
+
return Rails.cache.read(cache_key)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
def fetch_static_get_charge
|
218
|
+
@get_charge_key = "app-manager-cache/#{self.shopify_domain}-get_charge"
|
219
|
+
if fetch_cached_static_get_charge(@get_charge_key).present?
|
220
|
+
return fetch_cached_static_get_charge(@get_charge_key)
|
221
|
+
end
|
222
|
+
charge = self.get_charge
|
223
|
+
Rails.cache.write(@get_charge_key, charge, expires_in: AppManager.configuration.expires_in)
|
224
|
+
return charge
|
225
|
+
end
|
226
|
+
|
227
|
+
def fetch_cached_static_get_charge(cache_key)
|
228
|
+
if Rails.cache.read(cache_key).present?
|
229
|
+
return Rails.cache.read(cache_key)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
|
198
234
|
private
|
199
235
|
|
200
236
|
def casted_value(value,value_type)
|
data/lib/app_manager/version.rb
CHANGED
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.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hulkapps
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|