app_manager 1.5.1 → 1.6.1
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 -61
- data/README.md +18 -4
- data/app/controllers/app_manager/charges_controller.rb +6 -3
- data/app_manager.gemspec +1 -1
- data/lib/app_manager/graphql_helper.rb +16 -0
- data/lib/app_manager/model.rb +170 -0
- data/lib/app_manager/version.rb +1 -1
- data/lib/generators/app_manager/install/templates/app_manager.rb.tt +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf415f568160cb4d0f964d01a39022df2906cd0cce3f5511f1a3f2fc19fe1155
|
4
|
+
data.tar.gz: fe3d01cf07acc3346a00f43723a016d86884a1fc01820b882de0462a6d92ecec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d2884af860d6872fa7e434574743219b8f8ca6cba0fa186c7ce05f5383c68cb4323ceff6d5c0bf984fbdc6231939a81005fdad0f500efeb56c8888ecfc86e67
|
7
|
+
data.tar.gz: 00ade8b2e4e6a9160a8c8e445d8693b39b79ffe649dedde189fa83856e9876d06d8bdfa7963a87010da4f268c0ccfdbf34fc096f665929db79db2ecb38e80d14
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
app_manager (1.
|
4
|
+
app_manager (1.6.1)
|
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.4.
|
14
|
-
actionpack (= 7.0.4.
|
15
|
-
activesupport (= 7.0.4.
|
13
|
+
actioncable (7.0.4.3)
|
14
|
+
actionpack (= 7.0.4.3)
|
15
|
+
activesupport (= 7.0.4.3)
|
16
16
|
nio4r (~> 2.0)
|
17
17
|
websocket-driver (>= 0.6.1)
|
18
|
-
actionmailbox (7.0.4.
|
19
|
-
actionpack (= 7.0.4.
|
20
|
-
activejob (= 7.0.4.
|
21
|
-
activerecord (= 7.0.4.
|
22
|
-
activestorage (= 7.0.4.
|
23
|
-
activesupport (= 7.0.4.
|
18
|
+
actionmailbox (7.0.4.3)
|
19
|
+
actionpack (= 7.0.4.3)
|
20
|
+
activejob (= 7.0.4.3)
|
21
|
+
activerecord (= 7.0.4.3)
|
22
|
+
activestorage (= 7.0.4.3)
|
23
|
+
activesupport (= 7.0.4.3)
|
24
24
|
mail (>= 2.7.1)
|
25
25
|
net-imap
|
26
26
|
net-pop
|
27
27
|
net-smtp
|
28
|
-
actionmailer (7.0.4.
|
29
|
-
actionpack (= 7.0.4.
|
30
|
-
actionview (= 7.0.4.
|
31
|
-
activejob (= 7.0.4.
|
32
|
-
activesupport (= 7.0.4.
|
28
|
+
actionmailer (7.0.4.3)
|
29
|
+
actionpack (= 7.0.4.3)
|
30
|
+
actionview (= 7.0.4.3)
|
31
|
+
activejob (= 7.0.4.3)
|
32
|
+
activesupport (= 7.0.4.3)
|
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.4.
|
39
|
-
actionview (= 7.0.4.
|
40
|
-
activesupport (= 7.0.4.
|
38
|
+
actionpack (7.0.4.3)
|
39
|
+
actionview (= 7.0.4.3)
|
40
|
+
activesupport (= 7.0.4.3)
|
41
41
|
rack (~> 2.0, >= 2.2.0)
|
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.4.
|
46
|
-
actionpack (= 7.0.4.
|
47
|
-
activerecord (= 7.0.4.
|
48
|
-
activestorage (= 7.0.4.
|
49
|
-
activesupport (= 7.0.4.
|
45
|
+
actiontext (7.0.4.3)
|
46
|
+
actionpack (= 7.0.4.3)
|
47
|
+
activerecord (= 7.0.4.3)
|
48
|
+
activestorage (= 7.0.4.3)
|
49
|
+
activesupport (= 7.0.4.3)
|
50
50
|
globalid (>= 0.6.0)
|
51
51
|
nokogiri (>= 1.8.5)
|
52
|
-
actionview (7.0.4.
|
53
|
-
activesupport (= 7.0.4.
|
52
|
+
actionview (7.0.4.3)
|
53
|
+
activesupport (= 7.0.4.3)
|
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.4.
|
59
|
-
activesupport (= 7.0.4.
|
58
|
+
activejob (7.0.4.3)
|
59
|
+
activesupport (= 7.0.4.3)
|
60
60
|
globalid (>= 0.3.6)
|
61
|
-
activemodel (7.0.4.
|
62
|
-
activesupport (= 7.0.4.
|
63
|
-
activerecord (7.0.4.
|
64
|
-
activemodel (= 7.0.4.
|
65
|
-
activesupport (= 7.0.4.
|
61
|
+
activemodel (7.0.4.3)
|
62
|
+
activesupport (= 7.0.4.3)
|
63
|
+
activerecord (7.0.4.3)
|
64
|
+
activemodel (= 7.0.4.3)
|
65
|
+
activesupport (= 7.0.4.3)
|
66
66
|
activerecord-import (1.4.1)
|
67
67
|
activerecord (>= 4.2)
|
68
|
-
activestorage (7.0.4.
|
69
|
-
actionpack (= 7.0.4.
|
70
|
-
activejob (= 7.0.4.
|
71
|
-
activerecord (= 7.0.4.
|
72
|
-
activesupport (= 7.0.4.
|
68
|
+
activestorage (7.0.4.3)
|
69
|
+
actionpack (= 7.0.4.3)
|
70
|
+
activejob (= 7.0.4.3)
|
71
|
+
activerecord (= 7.0.4.3)
|
72
|
+
activesupport (= 7.0.4.3)
|
73
73
|
marcel (~> 1.0)
|
74
74
|
mini_mime (>= 1.1.0)
|
75
|
-
activesupport (7.0.4.
|
75
|
+
activesupport (7.0.4.3)
|
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)
|
@@ -121,7 +121,7 @@ GEM
|
|
121
121
|
method_source (1.0.0)
|
122
122
|
mini_mime (1.1.2)
|
123
123
|
mini_portile2 (2.8.1)
|
124
|
-
minitest (5.
|
124
|
+
minitest (5.18.0)
|
125
125
|
multi_xml (0.6.0)
|
126
126
|
net-imap (0.3.4)
|
127
127
|
date
|
@@ -133,7 +133,7 @@ GEM
|
|
133
133
|
net-smtp (0.3.3)
|
134
134
|
net-protocol
|
135
135
|
nio4r (2.5.8)
|
136
|
-
nokogiri (1.14.
|
136
|
+
nokogiri (1.14.2)
|
137
137
|
mini_portile2 (~> 2.8.0)
|
138
138
|
racc (~> 1.4)
|
139
139
|
pry (0.14.1)
|
@@ -141,31 +141,31 @@ GEM
|
|
141
141
|
method_source (~> 1.0)
|
142
142
|
public_suffix (4.0.6)
|
143
143
|
racc (1.6.2)
|
144
|
-
rack (2.2.6.
|
145
|
-
rack-test (2.0
|
144
|
+
rack (2.2.6.4)
|
145
|
+
rack-test (2.1.0)
|
146
146
|
rack (>= 1.3)
|
147
|
-
rails (7.0.4.
|
148
|
-
actioncable (= 7.0.4.
|
149
|
-
actionmailbox (= 7.0.4.
|
150
|
-
actionmailer (= 7.0.4.
|
151
|
-
actionpack (= 7.0.4.
|
152
|
-
actiontext (= 7.0.4.
|
153
|
-
actionview (= 7.0.4.
|
154
|
-
activejob (= 7.0.4.
|
155
|
-
activemodel (= 7.0.4.
|
156
|
-
activerecord (= 7.0.4.
|
157
|
-
activestorage (= 7.0.4.
|
158
|
-
activesupport (= 7.0.4.
|
147
|
+
rails (7.0.4.3)
|
148
|
+
actioncable (= 7.0.4.3)
|
149
|
+
actionmailbox (= 7.0.4.3)
|
150
|
+
actionmailer (= 7.0.4.3)
|
151
|
+
actionpack (= 7.0.4.3)
|
152
|
+
actiontext (= 7.0.4.3)
|
153
|
+
actionview (= 7.0.4.3)
|
154
|
+
activejob (= 7.0.4.3)
|
155
|
+
activemodel (= 7.0.4.3)
|
156
|
+
activerecord (= 7.0.4.3)
|
157
|
+
activestorage (= 7.0.4.3)
|
158
|
+
activesupport (= 7.0.4.3)
|
159
159
|
bundler (>= 1.15.0)
|
160
|
-
railties (= 7.0.4.
|
160
|
+
railties (= 7.0.4.3)
|
161
161
|
rails-dom-testing (2.0.3)
|
162
162
|
activesupport (>= 4.2.0)
|
163
163
|
nokogiri (>= 1.6)
|
164
164
|
rails-html-sanitizer (1.5.0)
|
165
165
|
loofah (~> 2.19, >= 2.19.1)
|
166
|
-
railties (7.0.4.
|
167
|
-
actionpack (= 7.0.4.
|
168
|
-
activesupport (= 7.0.4.
|
166
|
+
railties (7.0.4.3)
|
167
|
+
actionpack (= 7.0.4.3)
|
168
|
+
activesupport (= 7.0.4.3)
|
169
169
|
method_source
|
170
170
|
rake (>= 12.2)
|
171
171
|
thor (~> 1.0)
|
@@ -188,7 +188,7 @@ GEM
|
|
188
188
|
rspec-support (~> 3.11.0)
|
189
189
|
rspec-support (3.11.0)
|
190
190
|
thor (1.2.1)
|
191
|
-
timeout (0.3.
|
191
|
+
timeout (0.3.2)
|
192
192
|
tzinfo (2.0.6)
|
193
193
|
concurrent-ruby (~> 1.0)
|
194
194
|
webmock (3.14.0)
|
@@ -198,7 +198,7 @@ GEM
|
|
198
198
|
websocket-driver (0.7.5)
|
199
199
|
websocket-extensions (>= 0.1.0)
|
200
200
|
websocket-extensions (0.1.5)
|
201
|
-
zeitwerk (2.6.
|
201
|
+
zeitwerk (2.6.7)
|
202
202
|
|
203
203
|
PLATFORMS
|
204
204
|
ruby
|
data/README.md
CHANGED
@@ -55,6 +55,7 @@ AppManager.configure do |config|
|
|
55
55
|
config.shopify_table_name = 'shops' # Table name which is generated by shopify mostly it is 'shops'
|
56
56
|
config.shopify_domain_field = 'shopify_domain' #shopify domain field
|
57
57
|
config.plan_id_or_name_field = 'plan_id'
|
58
|
+
config.shopify_app_slug = '' #Add your app slug here
|
58
59
|
config.field_names = {
|
59
60
|
'name' => 'shopify_domain', # demo-rahul-tiwari.myshopify.com
|
60
61
|
'shopify_email' => 'email', # rahul.t@hulkapps.com
|
@@ -63,7 +64,8 @@ AppManager.configure do |config|
|
|
63
64
|
'plan_id' => 'plan_id', # 1. t
|
64
65
|
'created_at' => 'created_at', # 2022-04-15 10:43:05
|
65
66
|
'trial_activated_at' => 'trial_activated_at', # field name that stores trial start/activated date
|
66
|
-
'grandfathered' => 'grandfathered'
|
67
|
+
'grandfathered' => 'grandfathered',
|
68
|
+
'total_trial_days' => '' #optional, put a trial days field from your shops table otherwise leave it blank
|
67
69
|
}
|
68
70
|
config.plan_features = [
|
69
71
|
{
|
@@ -119,7 +121,7 @@ AppManager.configure do |config|
|
|
119
121
|
"group_order" => "1",
|
120
122
|
"group" => "Group Name",
|
121
123
|
}
|
122
|
-
]
|
124
|
+
]
|
123
125
|
end
|
124
126
|
#Required, Values type : integer, boolean, string, array #
|
125
127
|
#Format: percentage, count, string
|
@@ -173,9 +175,11 @@ and then you can use follwing methods with your shop objects.
|
|
173
175
|
|
174
176
|
if you pass @shop.get_plan(plan_id) it will return that particular plan hash like @shop.get_plan(311)
|
175
177
|
|
176
|
-
@shop.get_charge # return current charge hash, it will return nil if current plan is free
|
178
|
+
@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
|
177
179
|
|
178
|
-
@shop.
|
180
|
+
@shop.cancel_charge # it will cancel charge in app manager and will return success to true if done from app manager
|
181
|
+
|
182
|
+
@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.
|
179
183
|
|
180
184
|
@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
185
|
|
@@ -191,6 +195,16 @@ and then you can use follwing methods with your shop objects.
|
|
191
195
|
|
192
196
|
@shop.get_all_plans # return all app plans array
|
193
197
|
|
198
|
+
@shop.get_active_charge_app_manager # return active charge hash from app manager otherwise nil
|
199
|
+
|
200
|
+
@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
|
+
@shop.get_current_shopify_charge # return active charge hash from shopify https://shopify.dev/docs/api/admin-graphql/2022-10/queries/currentAppInstallation otherwise nil
|
203
|
+
|
204
|
+
@shop.active_shopify_charge_id # return active shopify charge id if shop has any current shopify reccurring charge otherwise nil
|
205
|
+
|
206
|
+
@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.
|
207
|
+
|
194
208
|
```
|
195
209
|
|
196
210
|
|
@@ -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
|
data/app_manager.gemspec
CHANGED
@@ -5,7 +5,7 @@ require_relative "lib/app_manager/version"
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "app_manager"
|
7
7
|
spec.version = AppManager::VERSION
|
8
|
-
spec.authors = "Hulkapps"
|
8
|
+
spec.authors = "Rahul Tiwari @ Hulkapps"
|
9
9
|
spec.email = "rahul.t@hulkapps.com"
|
10
10
|
|
11
11
|
spec.summary = "An API wrapper of Hulkapps AppManager portal"
|
@@ -42,6 +42,8 @@ module AppManager
|
|
42
42
|
query = query.dup.force_encoding("UTF-8")
|
43
43
|
if variables.present?
|
44
44
|
query = {"query": "#{query}","variables": variables }
|
45
|
+
else
|
46
|
+
query = {"query": "#{query}","variables": {} }
|
45
47
|
end
|
46
48
|
if is_json
|
47
49
|
response = api_call(query.to_json,true)
|
@@ -176,6 +178,20 @@ module AppManager
|
|
176
178
|
return data
|
177
179
|
end
|
178
180
|
|
181
|
+
def recurring_charge_current_api_call(shop)
|
182
|
+
query = 'query {
|
183
|
+
currentAppInstallation {
|
184
|
+
activeSubscriptions {
|
185
|
+
id
|
186
|
+
name
|
187
|
+
test
|
188
|
+
}
|
189
|
+
}
|
190
|
+
}'
|
191
|
+
data = run_graph_api(query,{})
|
192
|
+
return data
|
193
|
+
end
|
194
|
+
|
179
195
|
end
|
180
196
|
end
|
181
197
|
|
data/lib/app_manager/model.rb
CHANGED
@@ -152,6 +152,176 @@ 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
|
+
|
190
|
+
def get_active_charge_app_manager
|
191
|
+
active_charge = self.get_charge rescue nil
|
192
|
+
return active_charge && active_charge['active_charge'].present? && !active_charge['active_charge'].nil? ? active_charge['active_charge'] : nil
|
193
|
+
end
|
194
|
+
|
195
|
+
def has_valid_app_manager_plan_id
|
196
|
+
shop_plan_id = self[AppManager.configuration.plan_id_or_name_field]
|
197
|
+
shop_domain = self[AppManager.configuration.shopify_domain_field]
|
198
|
+
plan_obj = AppManager::Client.new
|
199
|
+
plans = plan_obj.get_plans(shop_domain) rescue nil
|
200
|
+
return shop_plan_id && (plans && plans.any? && plans.collect{|e| e['id']}.include?(shop_plan_id)) ? true : false
|
201
|
+
end
|
202
|
+
|
203
|
+
def update_app_manager_charge(current_shopify_charge_id=nil)
|
204
|
+
charge_updated = nil
|
205
|
+
begin
|
206
|
+
shop_plan_id = self[AppManager.configuration.plan_id_or_name_field]
|
207
|
+
shop_domain = self[AppManager.configuration.shopify_domain_field]
|
208
|
+
if get_active_charge_app_manager.nil?
|
209
|
+
current_charge_id = current_shopify_charge_id.present? ? current_shopify_charge_id : active_shopify_charge_id
|
210
|
+
if current_charge_id.present?
|
211
|
+
if has_valid_app_manager_plan_id
|
212
|
+
if charge_update_call(self,shop_plan_id,current_charge_id)
|
213
|
+
charge_updated = true
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
return charge_updated
|
219
|
+
rescue Exception => e
|
220
|
+
Rollbar.error("Warning in APP MANAGER, trying to get update_app_manager_charge >>>> #{e.inspect}")
|
221
|
+
return nil
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def active_shopify_charge_id
|
226
|
+
begin
|
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"]
|
230
|
+
if current_shopify_charge_id
|
231
|
+
return current_shopify_charge_id.split('/')[-1] rescue nil
|
232
|
+
else
|
233
|
+
return nil
|
234
|
+
end
|
235
|
+
else
|
236
|
+
return nil
|
237
|
+
end
|
238
|
+
rescue Exception => e
|
239
|
+
Rollbar.error("Warning in APP MANAGER, trying to get active shopify charge id >>>> #{e.inspect}")
|
240
|
+
return nil
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
def app_manager_charge_update(shop,shopify_current_charge_obj)
|
245
|
+
if shop.present? && shop.plan_id.present? && shopify_current_charge_obj.present?
|
246
|
+
charge_update_call(shop,shop.plan_id,shopify_current_charge_obj['id'],shopify_current_charge_obj)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def charge_update_call(shop,shop_plan_id,current_charge_id,charge_obj={})
|
251
|
+
charge_callback_done = nil
|
252
|
+
# begin
|
253
|
+
@shop = shop
|
254
|
+
@field_names = AppManager.configuration.field_names
|
255
|
+
shopify_token = @field_names['shopify_token']
|
256
|
+
shopify_domain = @field_names['name']
|
257
|
+
grandfathered_field = @field_names['grandfathered']
|
258
|
+
shop_domain = @shop[AppManager.configuration.shopify_domain_field]
|
259
|
+
if !@shop.nil?
|
260
|
+
if charge_obj.present? && !charge_obj.nil?
|
261
|
+
shopify_charge_obj = charge_obj
|
262
|
+
else
|
263
|
+
headers = {"X-Shopify-Access-Token" => @shop[shopify_token]}
|
264
|
+
charges = HTTParty.get('https://' + shop_domain + '/admin/api/' + AppManager.configuration.shopify_api_version + '/recurring_application_charges/' + current_charge_id + '.json', :headers => headers)
|
265
|
+
shopify_charge_obj = charges.parsed_response && charges.parsed_response.is_a?(Hash) && charges.parsed_response.has_key?('recurring_application_charge') ? charges.parsed_response['recurring_application_charge'] : {}
|
266
|
+
end
|
267
|
+
|
268
|
+
if shopify_charge_obj.present?
|
269
|
+
plan_obj = AppManager::Client.new
|
270
|
+
plan_data = plan_obj.get_plan(shop_plan_id, shop_domain)
|
271
|
+
charge = shopify_charge_obj
|
272
|
+
charge['charge_id'] = charge['id']
|
273
|
+
charge['type'] = 'recurring'
|
274
|
+
charge['plan_id'] = shop_plan_id
|
275
|
+
charge['shop_domain'] = shop_domain
|
276
|
+
charge['interval'] = plan_data['interval']['value']
|
277
|
+
['api_client_id', 'return_url', 'decorated_return_url','id','id','currency'].each { |k| charge.delete k }
|
278
|
+
charge_ob = AppManager::Client.new(nil, json_req = true)
|
279
|
+
response = charge_ob.store_charge(charge.to_json)
|
280
|
+
|
281
|
+
if response['message'] == "success"
|
282
|
+
AppManager.clear_cache
|
283
|
+
|
284
|
+
update_info = {AppManager.configuration.plan_id_or_name_field => shop_plan_id,grandfathered_field => 0}
|
285
|
+
if !config_trial_days.nil? && !plan_data.nil?
|
286
|
+
trial_days = plan_data['trial_days'] || 0
|
287
|
+
update_info[config_trial_days] = trial_days
|
288
|
+
end
|
289
|
+
|
290
|
+
if @shop.update(update_info)
|
291
|
+
charge_callback_done = true
|
292
|
+
end
|
293
|
+
Thread.new do
|
294
|
+
charge_data = plan_obj.get_charge(@shop[shopify_domain])
|
295
|
+
begin
|
296
|
+
AppManager::EventHandler.new('charge_created', {
|
297
|
+
"plan" => plan_data,
|
298
|
+
"charge" => charge,
|
299
|
+
"previous_charge" => charge_data ? (charge_data['cancelled_charge'] || nil) : nil,
|
300
|
+
"shopify_domain" => shop_domain
|
301
|
+
})
|
302
|
+
rescue Exception => e
|
303
|
+
Rollbar.error("Warning in APP MANAGER model Charge Created Callback Event Fire>>>> #{e.inspect}")
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
return charge_callback_done
|
310
|
+
# rescue Exception => e
|
311
|
+
# Rollbar.error("Warning in APP MANAGER model charge_callback, trying to update active shopify charge in app manager>>>> #{e.inspect}")
|
312
|
+
# return nil
|
313
|
+
# end
|
314
|
+
end
|
315
|
+
|
316
|
+
def config_trial_days
|
317
|
+
@field_names = AppManager.configuration.field_names
|
318
|
+
if !@field_names.nil? && @field_names.has_key?('total_trial_days') && !@field_names['total_trial_days'].nil? && !@field_names['total_trial_days'].blank?
|
319
|
+
return @field_names['total_trial_days']
|
320
|
+
else
|
321
|
+
return nil
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
155
325
|
def set_default_plan(plan_id = nil)
|
156
326
|
begin
|
157
327
|
if plan_id.nil?
|
data/lib/app_manager/version.rb
CHANGED
@@ -7,6 +7,7 @@ AppManager.configure do |config|
|
|
7
7
|
config.shopify_table_name = 'shops' # Table name which is generated by shopify mostly it is 'shops'
|
8
8
|
config.shopify_domain_field = 'shopify_domain' #shopify domain field
|
9
9
|
config.plan_id_or_name_field = 'plan_id'
|
10
|
+
config.shopify_app_slug = '' #Add your app slug here
|
10
11
|
config.field_names = {
|
11
12
|
'name' => 'shopify_domain', # demo-rahul-tiwari.myshopify.com
|
12
13
|
'shopify_email' => 'email', # rahul.t@hulkapps.com
|
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.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Hulkapps
|
7
|
+
- Rahul Tiwari @ Hulkapps
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|