app_manager 1.6.0 → 1.6.2
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 +72 -71
- data/README.md +12 -4
- data/app/controllers/app_manager/charges_controller.rb +25 -13
- data/lib/app_manager/config.rb +6 -0
- data/lib/app_manager/graphql_helper.rb +50 -0
- data/lib/app_manager/model.rb +50 -5
- data/lib/app_manager/version.rb +1 -1
- 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: ea6c61b1ae005d14902a296e6c1a43e28679313985905b295fb24f4f361434cd
|
|
4
|
+
data.tar.gz: f586f0d88bbb8ccda1fcd4a1c67aea648755909219c8c26671b744eb4c132ee2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 27fd9ec25e4c6e1aa49b06dd2668abdc8f3f51efe6becf6fee47bbecc187e9c5bc51485a0ff40a46d4427d08b675738c7af35fc6815958577e33d30fb295de63
|
|
7
|
+
data.tar.gz: 1f817a3e9193b58e3b792ab36ea567174058f0e39e265c75f6cac5b463a26387007aa6226807b9bd9626171e90ab396b1cbf496c466fae66106ec73eeca2b743
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
app_manager (1.6.
|
|
4
|
+
app_manager (1.6.2)
|
|
5
5
|
activerecord-import (~> 1.4)
|
|
6
6
|
httparty
|
|
7
7
|
kaminari (>= 0.16.3)
|
|
@@ -10,69 +10,69 @@ PATH
|
|
|
10
10
|
GEM
|
|
11
11
|
remote: https://rubygems.org/
|
|
12
12
|
specs:
|
|
13
|
-
actioncable (7.0.
|
|
14
|
-
actionpack (= 7.0.
|
|
15
|
-
activesupport (= 7.0.
|
|
13
|
+
actioncable (7.0.5)
|
|
14
|
+
actionpack (= 7.0.5)
|
|
15
|
+
activesupport (= 7.0.5)
|
|
16
16
|
nio4r (~> 2.0)
|
|
17
17
|
websocket-driver (>= 0.6.1)
|
|
18
|
-
actionmailbox (7.0.
|
|
19
|
-
actionpack (= 7.0.
|
|
20
|
-
activejob (= 7.0.
|
|
21
|
-
activerecord (= 7.0.
|
|
22
|
-
activestorage (= 7.0.
|
|
23
|
-
activesupport (= 7.0.
|
|
18
|
+
actionmailbox (7.0.5)
|
|
19
|
+
actionpack (= 7.0.5)
|
|
20
|
+
activejob (= 7.0.5)
|
|
21
|
+
activerecord (= 7.0.5)
|
|
22
|
+
activestorage (= 7.0.5)
|
|
23
|
+
activesupport (= 7.0.5)
|
|
24
24
|
mail (>= 2.7.1)
|
|
25
25
|
net-imap
|
|
26
26
|
net-pop
|
|
27
27
|
net-smtp
|
|
28
|
-
actionmailer (7.0.
|
|
29
|
-
actionpack (= 7.0.
|
|
30
|
-
actionview (= 7.0.
|
|
31
|
-
activejob (= 7.0.
|
|
32
|
-
activesupport (= 7.0.
|
|
28
|
+
actionmailer (7.0.5)
|
|
29
|
+
actionpack (= 7.0.5)
|
|
30
|
+
actionview (= 7.0.5)
|
|
31
|
+
activejob (= 7.0.5)
|
|
32
|
+
activesupport (= 7.0.5)
|
|
33
33
|
mail (~> 2.5, >= 2.5.4)
|
|
34
34
|
net-imap
|
|
35
35
|
net-pop
|
|
36
36
|
net-smtp
|
|
37
37
|
rails-dom-testing (~> 2.0)
|
|
38
|
-
actionpack (7.0.
|
|
39
|
-
actionview (= 7.0.
|
|
40
|
-
activesupport (= 7.0.
|
|
41
|
-
rack (~> 2.0, >= 2.2.
|
|
38
|
+
actionpack (7.0.5)
|
|
39
|
+
actionview (= 7.0.5)
|
|
40
|
+
activesupport (= 7.0.5)
|
|
41
|
+
rack (~> 2.0, >= 2.2.4)
|
|
42
42
|
rack-test (>= 0.6.3)
|
|
43
43
|
rails-dom-testing (~> 2.0)
|
|
44
44
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
45
|
-
actiontext (7.0.
|
|
46
|
-
actionpack (= 7.0.
|
|
47
|
-
activerecord (= 7.0.
|
|
48
|
-
activestorage (= 7.0.
|
|
49
|
-
activesupport (= 7.0.
|
|
45
|
+
actiontext (7.0.5)
|
|
46
|
+
actionpack (= 7.0.5)
|
|
47
|
+
activerecord (= 7.0.5)
|
|
48
|
+
activestorage (= 7.0.5)
|
|
49
|
+
activesupport (= 7.0.5)
|
|
50
50
|
globalid (>= 0.6.0)
|
|
51
51
|
nokogiri (>= 1.8.5)
|
|
52
|
-
actionview (7.0.
|
|
53
|
-
activesupport (= 7.0.
|
|
52
|
+
actionview (7.0.5)
|
|
53
|
+
activesupport (= 7.0.5)
|
|
54
54
|
builder (~> 3.1)
|
|
55
55
|
erubi (~> 1.4)
|
|
56
56
|
rails-dom-testing (~> 2.0)
|
|
57
57
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
58
|
-
activejob (7.0.
|
|
59
|
-
activesupport (= 7.0.
|
|
58
|
+
activejob (7.0.5)
|
|
59
|
+
activesupport (= 7.0.5)
|
|
60
60
|
globalid (>= 0.3.6)
|
|
61
|
-
activemodel (7.0.
|
|
62
|
-
activesupport (= 7.0.
|
|
63
|
-
activerecord (7.0.
|
|
64
|
-
activemodel (= 7.0.
|
|
65
|
-
activesupport (= 7.0.
|
|
61
|
+
activemodel (7.0.5)
|
|
62
|
+
activesupport (= 7.0.5)
|
|
63
|
+
activerecord (7.0.5)
|
|
64
|
+
activemodel (= 7.0.5)
|
|
65
|
+
activesupport (= 7.0.5)
|
|
66
66
|
activerecord-import (1.4.1)
|
|
67
67
|
activerecord (>= 4.2)
|
|
68
|
-
activestorage (7.0.
|
|
69
|
-
actionpack (= 7.0.
|
|
70
|
-
activejob (= 7.0.
|
|
71
|
-
activerecord (= 7.0.
|
|
72
|
-
activesupport (= 7.0.
|
|
68
|
+
activestorage (7.0.5)
|
|
69
|
+
actionpack (= 7.0.5)
|
|
70
|
+
activejob (= 7.0.5)
|
|
71
|
+
activerecord (= 7.0.5)
|
|
72
|
+
activesupport (= 7.0.5)
|
|
73
73
|
marcel (~> 1.0)
|
|
74
74
|
mini_mime (>= 1.1.0)
|
|
75
|
-
activesupport (7.0.
|
|
75
|
+
activesupport (7.0.5)
|
|
76
76
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
77
77
|
i18n (>= 1.6, < 2)
|
|
78
78
|
minitest (>= 5.1)
|
|
@@ -81,7 +81,7 @@ GEM
|
|
|
81
81
|
public_suffix (>= 2.0.2, < 5.0)
|
|
82
82
|
builder (3.2.4)
|
|
83
83
|
coderay (1.1.3)
|
|
84
|
-
concurrent-ruby (1.2.
|
|
84
|
+
concurrent-ruby (1.2.2)
|
|
85
85
|
crack (0.4.5)
|
|
86
86
|
rexml
|
|
87
87
|
crass (1.0.6)
|
|
@@ -95,7 +95,7 @@ GEM
|
|
|
95
95
|
httparty (0.21.0)
|
|
96
96
|
mini_mime (>= 1.0.0)
|
|
97
97
|
multi_xml (>= 0.5.2)
|
|
98
|
-
i18n (1.
|
|
98
|
+
i18n (1.14.1)
|
|
99
99
|
concurrent-ruby (~> 1.0)
|
|
100
100
|
kaminari (1.2.2)
|
|
101
101
|
activesupport (>= 4.1.0)
|
|
@@ -109,9 +109,9 @@ GEM
|
|
|
109
109
|
activerecord
|
|
110
110
|
kaminari-core (= 1.2.2)
|
|
111
111
|
kaminari-core (1.2.2)
|
|
112
|
-
loofah (2.
|
|
112
|
+
loofah (2.21.3)
|
|
113
113
|
crass (~> 1.0.2)
|
|
114
|
-
nokogiri (>= 1.
|
|
114
|
+
nokogiri (>= 1.12.0)
|
|
115
115
|
mail (2.8.1)
|
|
116
116
|
mini_mime (>= 0.1.1)
|
|
117
117
|
net-imap
|
|
@@ -120,8 +120,8 @@ GEM
|
|
|
120
120
|
marcel (1.0.2)
|
|
121
121
|
method_source (1.0.0)
|
|
122
122
|
mini_mime (1.1.2)
|
|
123
|
-
mini_portile2 (2.8.
|
|
124
|
-
minitest (5.
|
|
123
|
+
mini_portile2 (2.8.2)
|
|
124
|
+
minitest (5.18.0)
|
|
125
125
|
multi_xml (0.6.0)
|
|
126
126
|
net-imap (0.3.4)
|
|
127
127
|
date
|
|
@@ -132,40 +132,41 @@ GEM
|
|
|
132
132
|
timeout
|
|
133
133
|
net-smtp (0.3.3)
|
|
134
134
|
net-protocol
|
|
135
|
-
nio4r (2.5.
|
|
136
|
-
nokogiri (1.
|
|
137
|
-
mini_portile2 (~> 2.8.
|
|
135
|
+
nio4r (2.5.9)
|
|
136
|
+
nokogiri (1.15.2)
|
|
137
|
+
mini_portile2 (~> 2.8.2)
|
|
138
138
|
racc (~> 1.4)
|
|
139
139
|
pry (0.14.1)
|
|
140
140
|
coderay (~> 1.1)
|
|
141
141
|
method_source (~> 1.0)
|
|
142
142
|
public_suffix (4.0.6)
|
|
143
143
|
racc (1.6.2)
|
|
144
|
-
rack (2.2.
|
|
145
|
-
rack-test (2.0
|
|
144
|
+
rack (2.2.7)
|
|
145
|
+
rack-test (2.1.0)
|
|
146
146
|
rack (>= 1.3)
|
|
147
|
-
rails (7.0.
|
|
148
|
-
actioncable (= 7.0.
|
|
149
|
-
actionmailbox (= 7.0.
|
|
150
|
-
actionmailer (= 7.0.
|
|
151
|
-
actionpack (= 7.0.
|
|
152
|
-
actiontext (= 7.0.
|
|
153
|
-
actionview (= 7.0.
|
|
154
|
-
activejob (= 7.0.
|
|
155
|
-
activemodel (= 7.0.
|
|
156
|
-
activerecord (= 7.0.
|
|
157
|
-
activestorage (= 7.0.
|
|
158
|
-
activesupport (= 7.0.
|
|
147
|
+
rails (7.0.5)
|
|
148
|
+
actioncable (= 7.0.5)
|
|
149
|
+
actionmailbox (= 7.0.5)
|
|
150
|
+
actionmailer (= 7.0.5)
|
|
151
|
+
actionpack (= 7.0.5)
|
|
152
|
+
actiontext (= 7.0.5)
|
|
153
|
+
actionview (= 7.0.5)
|
|
154
|
+
activejob (= 7.0.5)
|
|
155
|
+
activemodel (= 7.0.5)
|
|
156
|
+
activerecord (= 7.0.5)
|
|
157
|
+
activestorage (= 7.0.5)
|
|
158
|
+
activesupport (= 7.0.5)
|
|
159
159
|
bundler (>= 1.15.0)
|
|
160
|
-
railties (= 7.0.
|
|
160
|
+
railties (= 7.0.5)
|
|
161
161
|
rails-dom-testing (2.0.3)
|
|
162
162
|
activesupport (>= 4.2.0)
|
|
163
163
|
nokogiri (>= 1.6)
|
|
164
|
-
rails-html-sanitizer (1.
|
|
165
|
-
loofah (~> 2.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
164
|
+
rails-html-sanitizer (1.6.0)
|
|
165
|
+
loofah (~> 2.21)
|
|
166
|
+
nokogiri (~> 1.14)
|
|
167
|
+
railties (7.0.5)
|
|
168
|
+
actionpack (= 7.0.5)
|
|
169
|
+
activesupport (= 7.0.5)
|
|
169
170
|
method_source
|
|
170
171
|
rake (>= 12.2)
|
|
171
172
|
thor (~> 1.0)
|
|
@@ -187,8 +188,8 @@ GEM
|
|
|
187
188
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
188
189
|
rspec-support (~> 3.11.0)
|
|
189
190
|
rspec-support (3.11.0)
|
|
190
|
-
thor (1.2.
|
|
191
|
-
timeout (0.3.
|
|
191
|
+
thor (1.2.2)
|
|
192
|
+
timeout (0.3.2)
|
|
192
193
|
tzinfo (2.0.6)
|
|
193
194
|
concurrent-ruby (~> 1.0)
|
|
194
195
|
webmock (3.14.0)
|
|
@@ -198,7 +199,7 @@ GEM
|
|
|
198
199
|
websocket-driver (0.7.5)
|
|
199
200
|
websocket-extensions (>= 0.1.0)
|
|
200
201
|
websocket-extensions (0.1.5)
|
|
201
|
-
zeitwerk (2.6.
|
|
202
|
+
zeitwerk (2.6.8)
|
|
202
203
|
|
|
203
204
|
PLATFORMS
|
|
204
205
|
ruby
|
data/README.md
CHANGED
|
@@ -56,6 +56,7 @@ AppManager.configure do |config|
|
|
|
56
56
|
config.shopify_domain_field = 'shopify_domain' #shopify domain field
|
|
57
57
|
config.plan_id_or_name_field = 'plan_id'
|
|
58
58
|
config.shopify_app_slug = '' #Add your app slug here
|
|
59
|
+
config.plan_page_route = '' #Add your app's plan page route here without first slash. Ex. "payment"
|
|
59
60
|
config.field_names = {
|
|
60
61
|
'name' => 'shopify_domain', # demo-rahul-tiwari.myshopify.com
|
|
61
62
|
'shopify_email' => 'email', # rahul.t@hulkapps.com
|
|
@@ -175,9 +176,11 @@ and then you can use follwing methods with your shop objects.
|
|
|
175
176
|
|
|
176
177
|
if you pass @shop.get_plan(plan_id) it will return that particular plan hash like @shop.get_plan(311)
|
|
177
178
|
|
|
178
|
-
@shop.get_charge # return current charge hash, it will return nil if current plan is free
|
|
179
|
+
@shop.get_charge # return current charge hash from app manager with 'active_charge' & 'cancelled_charge' keys, it will return nil if current plan is free
|
|
179
180
|
|
|
180
|
-
@shop.
|
|
181
|
+
@shop.cancel_charge # it will cancel charge in app manager and will return success to true if done from app manager
|
|
182
|
+
|
|
183
|
+
@shop.set_default_plan(plan_id=nil) #if plan id is passed nil, then it will set the free(public and $0 price) plan_id in database and if passed it will set that plan_id in database.
|
|
181
184
|
|
|
182
185
|
@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:
|
|
183
186
|
|
|
@@ -193,12 +196,17 @@ and then you can use follwing methods with your shop objects.
|
|
|
193
196
|
|
|
194
197
|
@shop.get_all_plans # return all app plans array
|
|
195
198
|
|
|
196
|
-
@shop.active_shopify_charge_id # return active shopify charge id if shop has any current reccurring charge otherwise nil
|
|
197
|
-
|
|
198
199
|
@shop.get_active_charge_app_manager # return active charge hash from app manager otherwise nil
|
|
199
200
|
|
|
200
201
|
@shop.update_app_manager_charge # return true if shop has shopify recurring charge but app manager doesn't then it update to app manager and return true otherwise nil
|
|
201
202
|
|
|
203
|
+
@shop.get_current_shopify_charge # return active charge hash from shopify https://shopify.dev/docs/api/admin-graphql/2022-10/queries/currentAppInstallation otherwise nil
|
|
204
|
+
|
|
205
|
+
@shop.active_shopify_charge_id # return active shopify charge id if shop has any current shopify reccurring charge otherwise nil
|
|
206
|
+
|
|
207
|
+
@shop.cancel_current_shopify_charge # It will cancel charge in shopify if there is any, if success then it will cancel charge in app manager as well using (@shop.cancel_charge ) and will make plan_id and grandfathered field to false. It will clear cache as well.
|
|
208
|
+
|
|
209
|
+
@shop.active_shopfiy_charge_full #It will give shopify recurring charge graphql object with discounted price details
|
|
202
210
|
```
|
|
203
211
|
|
|
204
212
|
|
|
@@ -16,15 +16,18 @@ module AppManager
|
|
|
16
16
|
plan_data = plan_obj.get_plan(params[:plan_id], params[:shop])
|
|
17
17
|
# render json: plan_data and return #use this to test plan failsafe api
|
|
18
18
|
if plan_data.present? && plan_data.is_a?(Hash)
|
|
19
|
-
if plan_data['price'] == 0
|
|
19
|
+
if plan_data['price'] == 0 && plan_data['is_external_charge'] == false
|
|
20
20
|
active_charge_data = plan_obj.get_charge(params[:shop])
|
|
21
21
|
begin
|
|
22
22
|
if active_charge_data && active_charge_data.any? && !active_charge_data['active_charge'].nil? && !active_charge_data['active_charge']['charge_id'].nil?
|
|
23
23
|
gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain, @shop.shopify_token)
|
|
24
24
|
rec_cancel_data = gq_obj.recurring_charge_cancel_api_call(active_charge_data['active_charge']['charge_id'], @shop)
|
|
25
25
|
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'))
|
|
26
|
-
cancelled_charge_id = rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["id"].split('/')[-1]
|
|
27
|
-
|
|
26
|
+
# cancelled_charge_id = rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["id"].split('/')[-1]
|
|
27
|
+
shop_plan_id = @shop[AppManager.configuration.plan_id_or_name_field]
|
|
28
|
+
if !shop_plan_id.nil?
|
|
29
|
+
plan_obj.cancel_charge(params[:shop], shop_plan_id)
|
|
30
|
+
end
|
|
28
31
|
end
|
|
29
32
|
end
|
|
30
33
|
rescue Exception => e
|
|
@@ -83,6 +86,8 @@ module AppManager
|
|
|
83
86
|
shopify_domain = @field_names['name']
|
|
84
87
|
grandfathered_field = @field_names['grandfathered']
|
|
85
88
|
if !@shop.nil?
|
|
89
|
+
old_plan_id = @shop[@plan_field]
|
|
90
|
+
old_plan_data = nil
|
|
86
91
|
headers = {"X-Shopify-Access-Token" => @shop[shopify_token]}
|
|
87
92
|
charges = HTTParty.get('https://' + @shop[shopify_domain] + '/admin/api/' + @api_version + '/recurring_application_charges/' + params[:charge_id] + '.json', :headers => headers)
|
|
88
93
|
|
|
@@ -99,14 +104,6 @@ module AppManager
|
|
|
99
104
|
charge['interval'] = plan_data['interval']['value']
|
|
100
105
|
|
|
101
106
|
['api_client_id', 'return_url', 'decorated_return_url','id','id','currency'].each { |k| charge.delete k }
|
|
102
|
-
# new_plan_obj = AppManager::Client.new
|
|
103
|
-
# if !@plan_field.nil?
|
|
104
|
-
# begin
|
|
105
|
-
# new_plan_obj.cancel_charge(@shop[shopify_domain], @shop[@plan_field])
|
|
106
|
-
# rescue Exception => e
|
|
107
|
-
# Rollbar.error("APP MANAGER Error in Cancel charge >>>> #{e.inspect}")
|
|
108
|
-
# end
|
|
109
|
-
# end
|
|
110
107
|
|
|
111
108
|
charge_ob = AppManager::Client.new(nil, json_req = true)
|
|
112
109
|
response = charge_ob.store_charge(charge.to_json)
|
|
@@ -121,6 +118,7 @@ module AppManager
|
|
|
121
118
|
end
|
|
122
119
|
|
|
123
120
|
@shop.update(update_info)
|
|
121
|
+
|
|
124
122
|
Thread.new do
|
|
125
123
|
charge_data = plan_obj.get_charge(@shop[shopify_domain])
|
|
126
124
|
begin
|
|
@@ -136,8 +134,18 @@ module AppManager
|
|
|
136
134
|
end
|
|
137
135
|
end
|
|
138
136
|
embed_host = Base64.encode64(params[:shop] + "/admin")
|
|
139
|
-
|
|
140
|
-
if
|
|
137
|
+
|
|
138
|
+
if !old_plan_id.nil?
|
|
139
|
+
plan_obj = AppManager::Client.new
|
|
140
|
+
old_plan_data = plan_obj.get_plan(old_plan_id, params[:shop])
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
current_plan_string = !plan_data.nil? ? "#{plan_data['name'].gsub(" ", "-")}-#{plan_data['interval']['label']}" : "" rescue ""
|
|
144
|
+
old_plan_string = !old_plan_data.nil? ? "#{old_plan_data['name'].gsub(" ", "-")}-#{old_plan_data['interval']['label']}" : "" rescue ""
|
|
145
|
+
plan_query_string = "new_plan=#{current_plan_string}&old_plan=#{old_plan_string}"
|
|
146
|
+
if app_slug.present? && plan_page_route_value.present?
|
|
147
|
+
redirect_to "https://#{params[:shop]}/admin/apps/#{app_slug}/#{plan_page_route_value}?#{plan_query_string}"
|
|
148
|
+
elsif app_slug.present? && !plan_page_route_value.present?
|
|
141
149
|
redirect_to "https://#{params[:shop]}/admin/apps/#{app_slug}"
|
|
142
150
|
else
|
|
143
151
|
redirect_to "#{app_url}?host=#{embed_host}&shop=#{params[:shop]}", :status => 301 and return
|
|
@@ -198,6 +206,10 @@ module AppManager
|
|
|
198
206
|
AppManager.configuration.shopify_app_slug
|
|
199
207
|
end
|
|
200
208
|
|
|
209
|
+
def plan_page_route_value
|
|
210
|
+
AppManager.configuration.plan_page_route
|
|
211
|
+
end
|
|
212
|
+
|
|
201
213
|
def config_trial_days
|
|
202
214
|
@field_names = AppManager.configuration.field_names
|
|
203
215
|
if !@field_names.nil? && @field_names.has_key?('total_trial_days') && !@field_names['total_trial_days'].nil? && !@field_names['total_trial_days'].blank?
|
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 :plan_page_route
|
|
17
18
|
|
|
18
19
|
def initialize
|
|
19
20
|
@refresh_by_request_params = true
|
|
@@ -26,6 +27,7 @@ module AppManager
|
|
|
26
27
|
@shopify_domain_field = 'shopify_domain'
|
|
27
28
|
@plan_id_or_name_field = nil
|
|
28
29
|
@shopify_app_slug = nil
|
|
30
|
+
@plan_page_route = nil
|
|
29
31
|
@field_names = {
|
|
30
32
|
'name' => 'shopify_domain', # sample example: demo-chirag-parmar.myshopify.com
|
|
31
33
|
'shopify_email' => 'email', # chirag.p@hulkapps.com
|
|
@@ -88,5 +90,9 @@ module AppManager
|
|
|
88
90
|
@shopify_app_slug
|
|
89
91
|
end
|
|
90
92
|
|
|
93
|
+
def plan_page_route
|
|
94
|
+
@plan_page_route
|
|
95
|
+
end
|
|
96
|
+
|
|
91
97
|
end
|
|
92
98
|
end
|
|
@@ -192,6 +192,56 @@ module AppManager
|
|
|
192
192
|
return data
|
|
193
193
|
end
|
|
194
194
|
|
|
195
|
+
def current_rc_charge_gql(shopify_charge_id)
|
|
196
|
+
query = 'query {
|
|
197
|
+
node(id: "gid://shopify/AppSubscription/'+shopify_charge_id+'") {
|
|
198
|
+
...on AppSubscription {
|
|
199
|
+
createdAt
|
|
200
|
+
currentPeriodEnd
|
|
201
|
+
id
|
|
202
|
+
name
|
|
203
|
+
status
|
|
204
|
+
test
|
|
205
|
+
lineItems {
|
|
206
|
+
plan {
|
|
207
|
+
pricingDetails {
|
|
208
|
+
...on AppRecurringPricing {
|
|
209
|
+
interval
|
|
210
|
+
price {
|
|
211
|
+
amount
|
|
212
|
+
currencyCode
|
|
213
|
+
}
|
|
214
|
+
discount {
|
|
215
|
+
priceAfterDiscount {
|
|
216
|
+
amount
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
...on AppUsagePricing {
|
|
221
|
+
terms
|
|
222
|
+
cappedAmount {
|
|
223
|
+
amount
|
|
224
|
+
currencyCode
|
|
225
|
+
|
|
226
|
+
}
|
|
227
|
+
balanceUsed {
|
|
228
|
+
amount
|
|
229
|
+
currencyCode
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}'
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
data = run_graph_api(query,'')
|
|
241
|
+
return data
|
|
242
|
+
|
|
243
|
+
end
|
|
244
|
+
|
|
195
245
|
end
|
|
196
246
|
end
|
|
197
247
|
|
data/lib/app_manager/model.rb
CHANGED
|
@@ -152,6 +152,41 @@ module AppManager
|
|
|
152
152
|
end
|
|
153
153
|
end
|
|
154
154
|
|
|
155
|
+
def cancel_current_shopify_charge
|
|
156
|
+
begin
|
|
157
|
+
@field_names = AppManager.configuration.field_names
|
|
158
|
+
shopify_active_charge_id = self.active_shopify_charge_id
|
|
159
|
+
if shopify_active_charge_id.present?
|
|
160
|
+
gq_obj = AppManager::GraphqlHelper.new(self.shopify_domain, self.shopify_token)
|
|
161
|
+
rec_cancel_data = gq_obj.recurring_charge_cancel_api_call(shopify_active_charge_id, self)
|
|
162
|
+
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'))
|
|
163
|
+
cancelled_charge_id = rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["id"].split('/')[-1]
|
|
164
|
+
self.cancel_charge
|
|
165
|
+
grandfathered_field = @field_names['grandfathered']
|
|
166
|
+
update_info = {AppManager.configuration.plan_id_or_name_field => nil,grandfathered_field => false}
|
|
167
|
+
if self.update(update_info)
|
|
168
|
+
AppManager.clear_cache
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
rescue Exception => e
|
|
173
|
+
return "#{e.inspect}"
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def get_current_shopify_charge
|
|
178
|
+
begin
|
|
179
|
+
gq_obj = AppManager::GraphqlHelper.new(self.shopify_domain, self.shopify_token)
|
|
180
|
+
data = gq_obj.recurring_charge_current_api_call(self)
|
|
181
|
+
if !data["errors"].present? && (data["data"].present? && data["data"]["currentAppInstallation"].present? && data["data"]["currentAppInstallation"]["activeSubscriptions"].present?)
|
|
182
|
+
return data["data"]["currentAppInstallation"]["activeSubscriptions"].first
|
|
183
|
+
end
|
|
184
|
+
rescue Exception => e
|
|
185
|
+
Rollbar.error("Warning in APP MANAGER, trying to get_current_shopify_charge >>>> #{e.inspect}")
|
|
186
|
+
return nil
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
155
190
|
def get_active_charge_app_manager
|
|
156
191
|
active_charge = self.get_charge rescue nil
|
|
157
192
|
return active_charge && active_charge['active_charge'].present? && !active_charge['active_charge'].nil? ? active_charge['active_charge'] : nil
|
|
@@ -182,17 +217,16 @@ module AppManager
|
|
|
182
217
|
end
|
|
183
218
|
return charge_updated
|
|
184
219
|
rescue Exception => e
|
|
185
|
-
Rollbar.error("Warning in APP MANAGER, trying to get
|
|
220
|
+
Rollbar.error("Warning in APP MANAGER, trying to get update_app_manager_charge >>>> #{e.inspect}")
|
|
186
221
|
return nil
|
|
187
222
|
end
|
|
188
223
|
end
|
|
189
224
|
|
|
190
225
|
def active_shopify_charge_id
|
|
191
226
|
begin
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
current_shopify_charge_id = data["data"]["currentAppInstallation"]["activeSubscriptions"].first["id"]
|
|
227
|
+
get_active_shopify_charge = self.get_current_shopify_charge
|
|
228
|
+
if get_active_shopify_charge.present? && !get_active_shopify_charge.nil?
|
|
229
|
+
current_shopify_charge_id = get_active_shopify_charge["id"]
|
|
196
230
|
if current_shopify_charge_id
|
|
197
231
|
return current_shopify_charge_id.split('/')[-1] rescue nil
|
|
198
232
|
else
|
|
@@ -279,6 +313,17 @@ module AppManager
|
|
|
279
313
|
# end
|
|
280
314
|
end
|
|
281
315
|
|
|
316
|
+
def active_shopfiy_charge_full
|
|
317
|
+
active_charge_id = self.active_shopify_charge_id
|
|
318
|
+
if active_charge_id.present?
|
|
319
|
+
gq_obj = AppManager::GraphqlHelper.new(self.shopify_domain, self.shopify_token)
|
|
320
|
+
rac_data = gq_obj.current_rc_charge_gql(active_charge_id)
|
|
321
|
+
return rac_data
|
|
322
|
+
else
|
|
323
|
+
return nil
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
|
|
282
327
|
def config_trial_days
|
|
283
328
|
@field_names = AppManager.configuration.field_names
|
|
284
329
|
if !@field_names.nil? && @field_names.has_key?('total_trial_days') && !@field_names['total_trial_days'].nil? && !@field_names['total_trial_days'].blank?
|
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.6.
|
|
4
|
+
version: 1.6.2
|
|
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: 2023-
|
|
11
|
+
date: 2023-06-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|