app_manager 1.3.3 → 1.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +61 -56
- data/app/controllers/app_manager/charges_controller.rb +55 -46
- data/app/controllers/app_manager/plans_controller.rb +2 -1
- data/app_manager.gemspec +3 -0
- data/lib/app_manager/client/connection.rb +6 -2
- data/lib/app_manager/client.rb +2 -0
- data/lib/app_manager/fail_safe.rb +32 -19
- data/lib/app_manager/model.rb +1 -2
- data/lib/app_manager/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0726560dff151c7c6b5e6fde4f510a43a28c0d3e299c2382ffeb43aea7f26b8
|
4
|
+
data.tar.gz: d02c49d7627c01fc7cc8096af135f36e39b0e1da002019034943abdb886d0a5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99ea34310c0c74e41115169a1a59b146ca75e06573383e2195aec671cc9938e8fb812a93783bf804dffc5eeeadd868b588d6c382fa231eeffd6118588d633f2a
|
7
|
+
data.tar.gz: 0c91a1c992a85cff1f4834985b65726bb3230d91948fd43109ec199ee25810514dc58242f7a2d30e7ce94db6c29056f9148093c2b3f1113ac95ab52cb72c87f8
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
app_manager (1.3.
|
4
|
+
app_manager (1.3.6)
|
5
|
+
activerecord-import (~> 1.4)
|
5
6
|
httparty
|
6
7
|
kaminari (>= 0.16.3)
|
7
8
|
rails (>= 5.2.0)
|
@@ -9,67 +10,69 @@ PATH
|
|
9
10
|
GEM
|
10
11
|
remote: https://rubygems.org/
|
11
12
|
specs:
|
12
|
-
actioncable (7.0.3)
|
13
|
-
actionpack (= 7.0.3)
|
14
|
-
activesupport (= 7.0.3)
|
13
|
+
actioncable (7.0.3.1)
|
14
|
+
actionpack (= 7.0.3.1)
|
15
|
+
activesupport (= 7.0.3.1)
|
15
16
|
nio4r (~> 2.0)
|
16
17
|
websocket-driver (>= 0.6.1)
|
17
|
-
actionmailbox (7.0.3)
|
18
|
-
actionpack (= 7.0.3)
|
19
|
-
activejob (= 7.0.3)
|
20
|
-
activerecord (= 7.0.3)
|
21
|
-
activestorage (= 7.0.3)
|
22
|
-
activesupport (= 7.0.3)
|
18
|
+
actionmailbox (7.0.3.1)
|
19
|
+
actionpack (= 7.0.3.1)
|
20
|
+
activejob (= 7.0.3.1)
|
21
|
+
activerecord (= 7.0.3.1)
|
22
|
+
activestorage (= 7.0.3.1)
|
23
|
+
activesupport (= 7.0.3.1)
|
23
24
|
mail (>= 2.7.1)
|
24
25
|
net-imap
|
25
26
|
net-pop
|
26
27
|
net-smtp
|
27
|
-
actionmailer (7.0.3)
|
28
|
-
actionpack (= 7.0.3)
|
29
|
-
actionview (= 7.0.3)
|
30
|
-
activejob (= 7.0.3)
|
31
|
-
activesupport (= 7.0.3)
|
28
|
+
actionmailer (7.0.3.1)
|
29
|
+
actionpack (= 7.0.3.1)
|
30
|
+
actionview (= 7.0.3.1)
|
31
|
+
activejob (= 7.0.3.1)
|
32
|
+
activesupport (= 7.0.3.1)
|
32
33
|
mail (~> 2.5, >= 2.5.4)
|
33
34
|
net-imap
|
34
35
|
net-pop
|
35
36
|
net-smtp
|
36
37
|
rails-dom-testing (~> 2.0)
|
37
|
-
actionpack (7.0.3)
|
38
|
-
actionview (= 7.0.3)
|
39
|
-
activesupport (= 7.0.3)
|
38
|
+
actionpack (7.0.3.1)
|
39
|
+
actionview (= 7.0.3.1)
|
40
|
+
activesupport (= 7.0.3.1)
|
40
41
|
rack (~> 2.0, >= 2.2.0)
|
41
42
|
rack-test (>= 0.6.3)
|
42
43
|
rails-dom-testing (~> 2.0)
|
43
44
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
44
|
-
actiontext (7.0.3)
|
45
|
-
actionpack (= 7.0.3)
|
46
|
-
activerecord (= 7.0.3)
|
47
|
-
activestorage (= 7.0.3)
|
48
|
-
activesupport (= 7.0.3)
|
45
|
+
actiontext (7.0.3.1)
|
46
|
+
actionpack (= 7.0.3.1)
|
47
|
+
activerecord (= 7.0.3.1)
|
48
|
+
activestorage (= 7.0.3.1)
|
49
|
+
activesupport (= 7.0.3.1)
|
49
50
|
globalid (>= 0.6.0)
|
50
51
|
nokogiri (>= 1.8.5)
|
51
|
-
actionview (7.0.3)
|
52
|
-
activesupport (= 7.0.3)
|
52
|
+
actionview (7.0.3.1)
|
53
|
+
activesupport (= 7.0.3.1)
|
53
54
|
builder (~> 3.1)
|
54
55
|
erubi (~> 1.4)
|
55
56
|
rails-dom-testing (~> 2.0)
|
56
57
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
57
|
-
activejob (7.0.3)
|
58
|
-
activesupport (= 7.0.3)
|
58
|
+
activejob (7.0.3.1)
|
59
|
+
activesupport (= 7.0.3.1)
|
59
60
|
globalid (>= 0.3.6)
|
60
|
-
activemodel (7.0.3)
|
61
|
-
activesupport (= 7.0.3)
|
62
|
-
activerecord (7.0.3)
|
63
|
-
activemodel (= 7.0.3)
|
64
|
-
activesupport (= 7.0.3)
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
61
|
+
activemodel (7.0.3.1)
|
62
|
+
activesupport (= 7.0.3.1)
|
63
|
+
activerecord (7.0.3.1)
|
64
|
+
activemodel (= 7.0.3.1)
|
65
|
+
activesupport (= 7.0.3.1)
|
66
|
+
activerecord-import (1.4.0)
|
67
|
+
activerecord (>= 4.2)
|
68
|
+
activestorage (7.0.3.1)
|
69
|
+
actionpack (= 7.0.3.1)
|
70
|
+
activejob (= 7.0.3.1)
|
71
|
+
activerecord (= 7.0.3.1)
|
72
|
+
activesupport (= 7.0.3.1)
|
70
73
|
marcel (~> 1.0)
|
71
74
|
mini_mime (>= 1.1.0)
|
72
|
-
activesupport (7.0.3)
|
75
|
+
activesupport (7.0.3.1)
|
73
76
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
74
77
|
i18n (>= 1.6, < 2)
|
75
78
|
minitest (>= 5.1)
|
@@ -92,7 +95,7 @@ GEM
|
|
92
95
|
httparty (0.20.0)
|
93
96
|
mime-types (~> 3.0)
|
94
97
|
multi_xml (>= 0.5.2)
|
95
|
-
i18n (1.
|
98
|
+
i18n (1.12.0)
|
96
99
|
concurrent-ruby (~> 1.0)
|
97
100
|
kaminari (1.2.2)
|
98
101
|
activesupport (>= 4.1.0)
|
@@ -117,6 +120,7 @@ GEM
|
|
117
120
|
mime-types-data (~> 3.2015)
|
118
121
|
mime-types-data (3.2022.0105)
|
119
122
|
mini_mime (1.1.2)
|
123
|
+
mini_portile2 (2.8.0)
|
120
124
|
minitest (5.16.2)
|
121
125
|
multi_xml (0.6.0)
|
122
126
|
net-imap (0.2.3)
|
@@ -134,7 +138,8 @@ GEM
|
|
134
138
|
net-protocol
|
135
139
|
timeout
|
136
140
|
nio4r (2.5.8)
|
137
|
-
nokogiri (1.13.
|
141
|
+
nokogiri (1.13.7)
|
142
|
+
mini_portile2 (~> 2.8.0)
|
138
143
|
racc (~> 1.4)
|
139
144
|
pry (0.14.1)
|
140
145
|
coderay (~> 1.1)
|
@@ -144,28 +149,28 @@ GEM
|
|
144
149
|
rack (2.2.4)
|
145
150
|
rack-test (2.0.2)
|
146
151
|
rack (>= 1.3)
|
147
|
-
rails (7.0.3)
|
148
|
-
actioncable (= 7.0.3)
|
149
|
-
actionmailbox (= 7.0.3)
|
150
|
-
actionmailer (= 7.0.3)
|
151
|
-
actionpack (= 7.0.3)
|
152
|
-
actiontext (= 7.0.3)
|
153
|
-
actionview (= 7.0.3)
|
154
|
-
activejob (= 7.0.3)
|
155
|
-
activemodel (= 7.0.3)
|
156
|
-
activerecord (= 7.0.3)
|
157
|
-
activestorage (= 7.0.3)
|
158
|
-
activesupport (= 7.0.3)
|
152
|
+
rails (7.0.3.1)
|
153
|
+
actioncable (= 7.0.3.1)
|
154
|
+
actionmailbox (= 7.0.3.1)
|
155
|
+
actionmailer (= 7.0.3.1)
|
156
|
+
actionpack (= 7.0.3.1)
|
157
|
+
actiontext (= 7.0.3.1)
|
158
|
+
actionview (= 7.0.3.1)
|
159
|
+
activejob (= 7.0.3.1)
|
160
|
+
activemodel (= 7.0.3.1)
|
161
|
+
activerecord (= 7.0.3.1)
|
162
|
+
activestorage (= 7.0.3.1)
|
163
|
+
activesupport (= 7.0.3.1)
|
159
164
|
bundler (>= 1.15.0)
|
160
|
-
railties (= 7.0.3)
|
165
|
+
railties (= 7.0.3.1)
|
161
166
|
rails-dom-testing (2.0.3)
|
162
167
|
activesupport (>= 4.2.0)
|
163
168
|
nokogiri (>= 1.6)
|
164
169
|
rails-html-sanitizer (1.4.3)
|
165
170
|
loofah (~> 2.3)
|
166
|
-
railties (7.0.3)
|
167
|
-
actionpack (= 7.0.3)
|
168
|
-
activesupport (= 7.0.3)
|
171
|
+
railties (7.0.3.1)
|
172
|
+
actionpack (= 7.0.3.1)
|
173
|
+
activesupport (= 7.0.3.1)
|
169
174
|
method_source
|
170
175
|
rake (>= 12.2)
|
171
176
|
thor (~> 1.0)
|
@@ -15,38 +15,39 @@ module AppManager
|
|
15
15
|
plan_data = plan_obj.get_plan(params[:plan_id], params[:shop])
|
16
16
|
# render json: plan_data and return #use this to test plan failsafe api
|
17
17
|
if plan_data.present? && plan_data.is_a?(Hash)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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'].nil? && !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"]["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)
|
27
|
+
end
|
27
28
|
end
|
29
|
+
rescue Exception => e
|
30
|
+
Rollbar.error("APP MANAGER Process Plan Failed #{e}")
|
28
31
|
end
|
29
|
-
rescue Exception => e
|
30
|
-
Rollbar.error("APP MANAGER Process Plan Failed #{e}")
|
31
|
-
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
33
|
+
if @shop.update(@plan_field => params[:plan_id])
|
34
|
+
begin
|
35
|
+
AppManager::EventHandler.new('charge_created', {
|
36
|
+
"plan" => plan_data,
|
37
|
+
"charge" => nil,
|
38
|
+
"previous_charge" => nil,
|
39
|
+
"shopify_domain" => params[:shop]
|
40
|
+
})
|
41
|
+
rescue Exception => e
|
42
|
+
Rollbar.error("APP MANAGER Error in Process Plan #{e}")
|
43
|
+
end
|
44
|
+
AppManager.clear_cache
|
45
|
+
render json: {'redirect_url' => "#{app_url}?shop=#{params[:shop]}"} and return true
|
46
|
+
# render json: {'status' => true,'plan_type' =>'free_plan'} and return true
|
47
|
+
else
|
48
|
+
raise Error, "Invalid charge"
|
43
49
|
end
|
44
|
-
AppManager.clear_cache
|
45
|
-
render json: {'redirect_url' => "#{app_url}?shop=#{params[:shop]}"} and return true
|
46
|
-
else
|
47
|
-
raise Error, "Invalid charge"
|
48
50
|
end
|
49
|
-
end
|
50
51
|
request_data = {'shop' => @shop.shopify_domain, 'timestamp' => Time.now.to_i, 'plan' => params[:plan_id]}
|
51
52
|
return_url = "#{app_url}#{plan_callback_path}?#{Rack::Utils.build_query(request_data)}"
|
52
53
|
gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain, @shop.shopify_token)
|
@@ -91,30 +92,33 @@ module AppManager
|
|
91
92
|
charge['shop_domain'] = params[:shop]
|
92
93
|
charge['interval'] = plan_data['interval']['value']
|
93
94
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
95
|
+
# new_plan_obj = AppManager::Client.new
|
96
|
+
# if !@plan_field.nil?
|
97
|
+
# begin
|
98
|
+
# new_plan_obj.cancel_charge(@shop[shopify_domain], @shop[@plan_field])
|
99
|
+
# rescue Exception => e
|
100
|
+
# Rollbar.error("APP MANAGER Error in Cancel charge >>>> #{e.inspect}")
|
101
|
+
# end
|
102
|
+
# end
|
101
103
|
|
102
104
|
charge_ob = AppManager::Client.new(nil, json_req = true)
|
103
105
|
response = charge_ob.store_charge(charge.to_json)
|
104
106
|
|
105
107
|
if response['message'] == "success"
|
106
108
|
AppManager.clear_cache
|
107
|
-
@shop.update(@plan_field => params[:plan],grandfathered_field =>
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
109
|
+
@shop.update(@plan_field => params[:plan],grandfathered_field => nil)
|
110
|
+
Thread.new do
|
111
|
+
charge_data = plan_obj.get_charge(@shop[shopify_domain])
|
112
|
+
begin
|
113
|
+
AppManager::EventHandler.new('charge_created', {
|
114
|
+
"plan" => plan_data,
|
115
|
+
"charge" => charge,
|
116
|
+
"previous_charge" => charge_data ? (charge_data['cancelled_charge'] || nil) : nil,
|
117
|
+
"shopify_domain" => params[:shop]
|
118
|
+
})
|
119
|
+
rescue Exception => e
|
120
|
+
Rollbar.error("Error in APP MANAGER Charge Created Callback >>>> #{e.inspect}")
|
121
|
+
end
|
118
122
|
end
|
119
123
|
end
|
120
124
|
redirect_to "#{app_url}?shop=#{params[:shop]}", :status => 301 and return
|
@@ -125,7 +129,12 @@ module AppManager
|
|
125
129
|
raise ModelNotFound, "Shop not found"
|
126
130
|
end
|
127
131
|
else
|
128
|
-
|
132
|
+
if params[:shop].present?
|
133
|
+
redirect_to "#{app_url}?shop=#{params[:shop]}", :status => 301 and return
|
134
|
+
else
|
135
|
+
raise Error, "Invalid params, must have charge_id,shop && plan in charge controller"
|
136
|
+
|
137
|
+
end
|
129
138
|
end
|
130
139
|
end
|
131
140
|
|
@@ -128,6 +128,7 @@ module AppManager
|
|
128
128
|
@trial_activated_field = AppManager.configuration.field_names['trial_activated_at']
|
129
129
|
if @shop.update(@plan_field => params[:plan_id], @trial_activated_field => DateTime.now)
|
130
130
|
begin
|
131
|
+
AppManager.clear_cache
|
131
132
|
plan_obj = AppManager::Client.new
|
132
133
|
plan_data = plan_obj.get_plan(params[:plan_id], params[:shop_domain]) rescue nil
|
133
134
|
AppManager::EventHandler.new('charge_created', {
|
@@ -161,7 +162,7 @@ module AppManager
|
|
161
162
|
Thread.new do
|
162
163
|
@fs = AppManager::FailSafe.new
|
163
164
|
begin
|
164
|
-
|
165
|
+
@fs.sync_app_manager
|
165
166
|
rescue Exception => e
|
166
167
|
Rails.logger.info "APP MANAGER >>>> LOCAL DB couldn't sync with POTAL DB #{e.inspect}"
|
167
168
|
end
|
data/app_manager.gemspec
CHANGED
@@ -33,6 +33,9 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_dependency "httparty"
|
34
34
|
spec.add_dependency "rails", '>= 5.2.0'
|
35
35
|
spec.add_dependency "kaminari", '>= 0.16.3'
|
36
|
+
spec.add_dependency "activerecord-import", '~> 1.4'
|
37
|
+
|
38
|
+
|
36
39
|
# spec.add_dependency "sqlite3", '~> 1.3.0'
|
37
40
|
# For more information and examples about making a new gem, checkout our
|
38
41
|
# guide at: https://bundler.io/guides/creating_gem.html
|
@@ -28,7 +28,7 @@ module AppManager
|
|
28
28
|
response = response_from_cache_for_api(http_method, path, options)
|
29
29
|
failsafe_or_caching_done = true
|
30
30
|
else
|
31
|
-
response = self.class.send(http_method, path, { body: options, timeout:
|
31
|
+
response = self.class.send(http_method, path, { body: options, timeout: 30 })
|
32
32
|
end
|
33
33
|
if path.include? "/get-status"
|
34
34
|
data = response
|
@@ -58,12 +58,16 @@ module AppManager
|
|
58
58
|
if fetch_static_cached_response(cache_key).present?
|
59
59
|
return fetch_static_cached_response(cache_key)
|
60
60
|
end
|
61
|
-
|
61
|
+
begin
|
62
|
+
response = self.class.send(http_method, path, { body: options, timeout: 15 })
|
62
63
|
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')
|
63
64
|
Rails.cache.write(cache_key, response, expires_in: AppManager.configuration.expires_in)
|
64
65
|
else
|
65
66
|
response = response_from_failsafe(path,options)
|
66
67
|
end
|
68
|
+
rescue Net::ReadTimeout => error
|
69
|
+
response = response_from_failsafe(path,options)
|
70
|
+
end
|
67
71
|
return response
|
68
72
|
end
|
69
73
|
|
data/lib/app_manager/client.rb
CHANGED
@@ -2,17 +2,18 @@ require 'json'
|
|
2
2
|
require 'date'
|
3
3
|
require 'time'
|
4
4
|
require "fileutils"
|
5
|
-
|
5
|
+
require 'active_record'
|
6
|
+
require 'activerecord-import'
|
6
7
|
module AppManager
|
7
8
|
|
8
9
|
class FailSafe
|
9
10
|
|
10
11
|
def initialize(db_name = 'app_manager_local')
|
11
|
-
begin
|
12
|
-
|
13
|
-
rescue Exception => e
|
14
|
-
|
15
|
-
end
|
12
|
+
# begin
|
13
|
+
# FileUtils.chmod 0664, "db/#{db_name}.db"
|
14
|
+
# rescue Exception => e
|
15
|
+
# puts ">>>>>> #{e.inspect}"
|
16
|
+
# end
|
16
17
|
# @apm_db = SQLite3::Database.open "db/#{db_name}.db"
|
17
18
|
# @apm_db.results_as_hash = true
|
18
19
|
end
|
@@ -62,8 +63,9 @@ module AppManager
|
|
62
63
|
end
|
63
64
|
|
64
65
|
def save_api_plans(plans)
|
65
|
-
AppManager::Plan.
|
66
|
+
AppManager::Plan.delete_all
|
66
67
|
if plans.any?
|
68
|
+
plan_data = []
|
67
69
|
plans.each do |plan|
|
68
70
|
interval = {}
|
69
71
|
shopify_plans = []
|
@@ -77,62 +79,73 @@ module AppManager
|
|
77
79
|
public_val = plan['public'] ? 1 : 0
|
78
80
|
store_base_plan = plan['store_base_plan'] ? 1 : 0
|
79
81
|
choose_later_plan = plan['choose_later_plan'] ? 1 : 0
|
80
|
-
AppManager::Plan.
|
82
|
+
plan_data << AppManager::Plan.new(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"])
|
81
83
|
end
|
84
|
+
AppManager::Plan.bulk_import plan_data
|
82
85
|
end
|
83
86
|
end
|
84
87
|
|
85
88
|
|
86
89
|
def save_api_charges(charges)
|
87
|
-
AppManager::Charge.
|
90
|
+
AppManager::Charge.delete_all
|
88
91
|
if charges.any?
|
92
|
+
charge_data = []
|
89
93
|
charges.each do |charge|
|
90
94
|
charge_test = charge['test'] ? true : false
|
91
|
-
AppManager::Charge.
|
95
|
+
charge_data << AppManager::Charge.new(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)
|
92
96
|
end
|
97
|
+
AppManager::Charge.bulk_import charge_data
|
93
98
|
end
|
94
99
|
end
|
95
100
|
|
96
101
|
|
97
102
|
def save_api_apps(apps)
|
98
|
-
AppManager::App.
|
103
|
+
AppManager::App.delete_all
|
99
104
|
if apps.any?
|
105
|
+
apps_data = []
|
100
106
|
apps.each do |app|
|
101
|
-
AppManager::App.
|
107
|
+
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'])
|
102
108
|
end
|
109
|
+
AppManager::Charge.bulk_import apps_data
|
103
110
|
end
|
104
111
|
end
|
105
112
|
|
106
113
|
#Complete
|
107
114
|
def save_api_app_structures(app_structures)
|
108
|
-
AppManager::AppStructure.
|
115
|
+
AppManager::AppStructure.delete_all
|
109
116
|
AppManager::AppStructure.create(banners: app_structures.to_h)
|
110
117
|
end
|
111
118
|
|
112
119
|
def save_api_discount_plans(discount_plans)
|
113
|
-
AppManager::DiscountPlan.
|
120
|
+
AppManager::DiscountPlan.delete_all
|
114
121
|
if discount_plans.any?
|
122
|
+
discount_plans_data = []
|
115
123
|
discount_plans.each do |discount_plan|
|
116
|
-
AppManager::DiscountPlan.
|
124
|
+
discount_plans_data << AppManager::DiscountPlan.new(id: discount_plan['id'], discount: discount_plan['discount'], shop_domain: discount_plan['shop_domain'], cycle_count: discount_plan['cycle_count'], plan_id: discount_plan['plan_id'], created_by: discount_plan['created_by'], created_at: discount_plan['created_at'], updated_at: discount_plan['updated_at'], app_id: discount_plan['app_id'], discount_type: discount_plan['discount_type'])
|
117
125
|
end
|
126
|
+
AppManager::DiscountPlan.bulk_import discount_plans_data
|
118
127
|
end
|
119
128
|
end
|
120
129
|
|
121
130
|
def save_api_extend_trials(extend_trials)
|
122
|
-
AppManager::ExtendTrial.
|
131
|
+
AppManager::ExtendTrial.delete_all
|
123
132
|
if extend_trials.any?
|
133
|
+
extend_trials_data = []
|
124
134
|
extend_trials.each do |extend_trial|
|
125
|
-
AppManager::ExtendTrial.
|
135
|
+
extend_trials_data << AppManager::ExtendTrial.new(id: extend_trial['id'], shop_domain: extend_trial['shop_domain'], plan_id: extend_trial['plan_id'], app_id: extend_trial['app_id'], days: extend_trial['days'], created_by: extend_trial['created_by'], created_at: extend_trial['created_at'], updated_at: extend_trial['updated_at'], extend_trial_start_at: extend_trial['extend_trial_start_at'])
|
126
136
|
end
|
137
|
+
AppManager::ExtendTrial.bulk_import extend_trials_data
|
127
138
|
end
|
128
139
|
end
|
129
140
|
|
130
141
|
def save_api_plan_users(plan_users)
|
131
|
-
AppManager::PlanUser.
|
142
|
+
AppManager::PlanUser.delete_all
|
132
143
|
if plan_users.any?
|
144
|
+
extend_plan_users = []
|
133
145
|
plan_users.each do |plan_user|
|
134
|
-
AppManager::PlanUser.
|
146
|
+
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'])
|
135
147
|
end
|
148
|
+
AppManager::ExtendTrial.bulk_import extend_plan_users
|
136
149
|
end
|
137
150
|
end
|
138
151
|
|
data/lib/app_manager/model.rb
CHANGED
@@ -84,7 +84,7 @@ module AppManager
|
|
84
84
|
res = plan_obj.get_remaining_days(shop_domain, trial_activated_at_val, plan_id)
|
85
85
|
return (res && !res.nil?) ? res : 0
|
86
86
|
rescue Exception => e
|
87
|
-
|
87
|
+
return 0
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -98,7 +98,6 @@ module AppManager
|
|
98
98
|
if shop_plan_id && !shop_plan_id.nil?
|
99
99
|
req_plan_id = shop_plan_id
|
100
100
|
else
|
101
|
-
Rollbar.error("Invalid params, must have charge_id,shop && plan")
|
102
101
|
return {}
|
103
102
|
end
|
104
103
|
end
|
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.3.
|
4
|
+
version: 1.3.6
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.16.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord-import
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.4'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.4'
|
55
69
|
description: Provides helper function to access AppManager API
|
56
70
|
email: rahul.t@hulkapps.com
|
57
71
|
executables: []
|