app_manager 2.0.0 → 2.2.0
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 +11 -11
- data/app/controllers/app_manager/charges_controller.rb +10 -9
- data/app/controllers/app_manager/plans_controller.rb +3 -6
- data/lib/app_manager/client/connection.rb +3 -1
- data/lib/app_manager/client/plans.rb +6 -2
- data/lib/app_manager/fail_safe.rb +6 -10
- data/lib/app_manager/graphql_helper.rb +5 -8
- data/lib/app_manager/set_local_storage.rb +34 -0
- data/lib/app_manager/version.rb +1 -1
- data/lib/app_manager.rb +0 -27
- metadata +3 -3
- data/lib/app_manager/set_cookie.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f97b31c44449e934975e233f07a745d883e58abd3a29ccd30537ec0e1ba6bca2
|
4
|
+
data.tar.gz: 863e6b243cd1c16839c4d5c9d7f3a3a0b1b47909ce613c9ff075e21d996ce314
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31f071cf42a3cfec28b0fae59cedfc72c2b24b80a85c237932acf0d118807977a961aa199ebd5435f5ddcb4f9310a27ac47589b35db953f39e61fbdd7e6d25d6
|
7
|
+
data.tar.gz: 67769978a3d30041d329e02a22432dad4d936a5254ac711e118a03be50101e11260aa22929a2c210ddbec027c44b60fa807f0c51dc494e6aac92a16033b8b83d
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
app_manager (2.
|
4
|
+
app_manager (2.2.0)
|
5
5
|
activerecord-import (~> 1.4)
|
6
6
|
httparty
|
7
7
|
kaminari (>= 0.16.3)
|
@@ -68,7 +68,7 @@ GEM
|
|
68
68
|
activemodel (= 7.1.3.2)
|
69
69
|
activesupport (= 7.1.3.2)
|
70
70
|
timeout (>= 0.4.0)
|
71
|
-
activerecord-import (1.
|
71
|
+
activerecord-import (1.6.0)
|
72
72
|
activerecord (>= 4.2)
|
73
73
|
activestorage (7.1.3.2)
|
74
74
|
actionpack (= 7.1.3.2)
|
@@ -89,7 +89,7 @@ GEM
|
|
89
89
|
addressable (2.8.0)
|
90
90
|
public_suffix (>= 2.0.2, < 5.0)
|
91
91
|
base64 (0.2.0)
|
92
|
-
bigdecimal (3.1.
|
92
|
+
bigdecimal (3.1.7)
|
93
93
|
builder (3.2.4)
|
94
94
|
coderay (1.1.3)
|
95
95
|
concurrent-ruby (1.2.3)
|
@@ -137,8 +137,8 @@ GEM
|
|
137
137
|
marcel (1.0.4)
|
138
138
|
method_source (1.0.0)
|
139
139
|
mini_mime (1.1.5)
|
140
|
-
mini_portile2 (2.8.
|
141
|
-
minitest (5.22.
|
140
|
+
mini_portile2 (2.8.6)
|
141
|
+
minitest (5.22.3)
|
142
142
|
multi_xml (0.6.0)
|
143
143
|
mutex_m (0.2.0)
|
144
144
|
net-imap (0.3.7)
|
@@ -148,10 +148,10 @@ GEM
|
|
148
148
|
net-protocol
|
149
149
|
net-protocol (0.2.2)
|
150
150
|
timeout
|
151
|
-
net-smtp (0.
|
151
|
+
net-smtp (0.5.0)
|
152
152
|
net-protocol
|
153
|
-
nio4r (2.7.
|
154
|
-
nokogiri (1.15.
|
153
|
+
nio4r (2.7.1)
|
154
|
+
nokogiri (1.15.6)
|
155
155
|
mini_portile2 (~> 2.8.2)
|
156
156
|
racc (~> 1.4)
|
157
157
|
pry (0.14.1)
|
@@ -161,7 +161,7 @@ GEM
|
|
161
161
|
stringio
|
162
162
|
public_suffix (4.0.6)
|
163
163
|
racc (1.7.3)
|
164
|
-
rack (3.0.
|
164
|
+
rack (3.0.10)
|
165
165
|
rack-session (2.0.0)
|
166
166
|
rack (>= 3.0.0)
|
167
167
|
rack-test (2.1.0)
|
@@ -199,9 +199,9 @@ GEM
|
|
199
199
|
thor (~> 1.0, >= 1.2.2)
|
200
200
|
zeitwerk (~> 2.6)
|
201
201
|
rake (13.0.6)
|
202
|
-
rdoc (6.6.
|
202
|
+
rdoc (6.6.3.1)
|
203
203
|
psych (>= 4.0.0)
|
204
|
-
reline (0.
|
204
|
+
reline (0.5.1)
|
205
205
|
io-console (~> 0.5)
|
206
206
|
rexml (3.2.5)
|
207
207
|
rspec (3.11.0)
|
@@ -41,6 +41,7 @@ module AppManager
|
|
41
41
|
end
|
42
42
|
if @shop.update(update_info)
|
43
43
|
begin
|
44
|
+
plan_data['old_plan'] = params[:old_plan] || nil;
|
44
45
|
AppManager::EventHandler.new('charge_created', {
|
45
46
|
"plan" => plan_data,
|
46
47
|
"charge" => nil,
|
@@ -59,11 +60,12 @@ module AppManager
|
|
59
60
|
end
|
60
61
|
request_data = {'shop' => @shop.shopify_domain, 'timestamp' => Time.now.to_i, 'plan' => params[:plan_id]}
|
61
62
|
request_data.merge!('host' => params['host']) if params['host'].present?
|
63
|
+
request_data.merge!('old_plan' => params['old_plan']) if params['old_plan'].present?
|
62
64
|
|
63
65
|
return_url = "#{app_url}#{plan_callback_path}?#{Rack::Utils.build_query(request_data)}"
|
64
|
-
discount_cookie = AppManager.resolve_from_cookies(self.request)
|
65
66
|
gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain, @shop.shopify_token)
|
66
|
-
|
67
|
+
discount_local_storage = params[:discount_code].present? && !params[:discount_code].nil? ? params[:discount_code] : nil
|
68
|
+
data = gq_obj.recurring_charge_api_call(plan_data, return_url, @shop,discount_local_storage)
|
67
69
|
if data.present? && !data["errors"].present? && (data["data"].present? && data["data"]["appSubscriptionCreate"].present? && (!data["data"]["appSubscriptionCreate"]["userErrors"].any? && data["data"]["appSubscriptionCreate"]["confirmationUrl"]))
|
68
70
|
redirect_charge = data["data"]["appSubscriptionCreate"]["confirmationUrl"]
|
69
71
|
render json: {'redirect_url' => redirect_charge}
|
@@ -88,8 +90,7 @@ module AppManager
|
|
88
90
|
shopify_token = @field_names['shopify_token']
|
89
91
|
shopify_domain = @field_names['name']
|
90
92
|
grandfathered_field = @field_names['grandfathered']
|
91
|
-
discounted_plans =
|
92
|
-
discounted_plans = discounted_plans.map!(&:to_s) if discounted_plans.any?
|
93
|
+
discounted_plans = []
|
93
94
|
if !@shop.nil?
|
94
95
|
old_plan_id = @shop[@plan_field]
|
95
96
|
old_plan_data = nil
|
@@ -139,11 +140,11 @@ module AppManager
|
|
139
140
|
|
140
141
|
begin
|
141
142
|
plan_obj = AppManager::Client.new
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
143
|
+
if params[:discount].present? && !params[:discount].nil?
|
144
|
+
discounted_plans = plan_obj.get_related_discounted_plans(params[:discount])
|
145
|
+
if discounted_plans.empty? || discounted_plans.include?(params[:plan].to_i)
|
146
|
+
plan_obj.discount_used(@shop[shopify_domain], params[:discount])
|
147
|
+
end
|
147
148
|
end
|
148
149
|
rescue
|
149
150
|
Rollbar.error("Error in APP MANAGER Discount used API call >>>> #{e.inspect}")
|
@@ -66,15 +66,12 @@ module AppManager
|
|
66
66
|
end
|
67
67
|
|
68
68
|
promotional_discount = []
|
69
|
-
|
70
|
-
|
71
|
-
created_at = @shop[AppManager.configuration.field_names['created_at']]
|
72
|
-
reinstall = AppManager.check_if_reinstall(created_at)
|
69
|
+
if params[:discount_code].present? && !params[:discount_code].nil? && @shop
|
70
|
+
discount_local_storage = params[:discount_code]
|
73
71
|
plan_obj = AppManager::Client.new
|
74
|
-
promotional_discount = plan_obj.get_promotional_discount(params[:shop_domain],
|
72
|
+
promotional_discount = plan_obj.get_promotional_discount(params[:shop_domain],discount_local_storage)
|
75
73
|
promotional_discount = [] if promotional_discount.class.to_s == "Hash" && promotional_discount.has_key?('status') && promotional_discount['status'] == 404
|
76
74
|
end
|
77
|
-
|
78
75
|
response = {
|
79
76
|
'plans' => plans,
|
80
77
|
'promotional_discount' => promotional_discount,
|
@@ -74,7 +74,7 @@ module AppManager
|
|
74
74
|
return fetch_static_cached_response(cache_key)
|
75
75
|
end
|
76
76
|
begin
|
77
|
-
response = self.class.send(http_method, path, { body: options, timeout:
|
77
|
+
response = self.class.send(http_method, path, { body: options, timeout: 120 })
|
78
78
|
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')
|
79
79
|
Rails.cache.write(cache_key, response, expires_in: AppManager.configuration.expires_in)
|
80
80
|
else
|
@@ -131,6 +131,8 @@ module AppManager
|
|
131
131
|
return @fs.get_local_discount(params, options)
|
132
132
|
when 'use-discount'
|
133
133
|
return @fs.store_discount_used(params,options)
|
134
|
+
when 'get-related-discounted-plans'
|
135
|
+
return @fs.get_local_related_discounted_plans(params,options)
|
134
136
|
else
|
135
137
|
return nil
|
136
138
|
end
|
@@ -43,8 +43,8 @@ module AppManager
|
|
43
43
|
get("/has-plan?shop_domain=#{shop_domain}&plan_id=#{plan_id}&trial_activated_at=#{trial_activated_at}&grandfathered=#{grandfathered}")
|
44
44
|
end
|
45
45
|
|
46
|
-
def get_promotional_discount(shop_domain = nil,
|
47
|
-
get("/discount?shop_domain=#{shop_domain}&
|
46
|
+
def get_promotional_discount(shop_domain = nil,code)
|
47
|
+
get("/discount?shop_domain=#{shop_domain}&code=#{code}")
|
48
48
|
end
|
49
49
|
|
50
50
|
def discount_used(shop_domain, discount_id)
|
@@ -55,6 +55,10 @@ module AppManager
|
|
55
55
|
post("/use-discount-sync", options)
|
56
56
|
end
|
57
57
|
|
58
|
+
def get_related_discounted_plans(discount_id)
|
59
|
+
get("/get-related-discounted-plans?discount_id=#{discount_id}")
|
60
|
+
end
|
61
|
+
|
58
62
|
end
|
59
63
|
end
|
60
64
|
end
|
@@ -224,10 +224,6 @@ module AppManager
|
|
224
224
|
promotional_discounts_data = []
|
225
225
|
promotional_discounts.each do |promotional_discount|
|
226
226
|
|
227
|
-
Rails.logger.info " "
|
228
|
-
Rails.logger.info "=== promotional_discount===========#{promotional_discount.inspect}"
|
229
|
-
Rails.logger.info " "
|
230
|
-
|
231
227
|
promotional_discounts_data << AppManager::Discount.new(
|
232
228
|
discount_id: promotional_discount['id'],
|
233
229
|
name: promotional_discount['name'],
|
@@ -249,9 +245,6 @@ module AppManager
|
|
249
245
|
)
|
250
246
|
end
|
251
247
|
|
252
|
-
Rails.logger.info " "
|
253
|
-
Rails.logger.info "=== promotional_discounts_data===========#{promotional_discounts_data.inspect}"
|
254
|
-
Rails.logger.info " "
|
255
248
|
AppManager::Discount.bulk_import promotional_discounts_data
|
256
249
|
end
|
257
250
|
end
|
@@ -614,14 +607,12 @@ module AppManager
|
|
614
607
|
|
615
608
|
def get_local_discount(params, options)
|
616
609
|
code = [params['code']].pack('H*')
|
617
|
-
code_type = params['code_type']
|
618
|
-
reinstall = params['reinstall']
|
619
610
|
shop_domain = params['shop_domain']
|
620
611
|
now = Time.now
|
621
612
|
|
622
613
|
discount_data = AppManager::Discount.where(enabled: true)
|
623
614
|
.where('valid_from <= ?', now)
|
624
|
-
.where('valid_to >= ?', now)
|
615
|
+
.where('valid_to IS NULL OR valid_to >= ?', now)
|
625
616
|
.where(code: code)
|
626
617
|
.first
|
627
618
|
return [] if discount_data.nil?
|
@@ -674,6 +665,11 @@ module AppManager
|
|
674
665
|
|
675
666
|
end
|
676
667
|
|
668
|
+
def get_local_related_discounted_plans(params, options)
|
669
|
+
discounted_plans = DiscountLinkPlan.where(discount_id: params['discount_id']).pluck(:plan_id) rescue []
|
670
|
+
return discounted_plans
|
671
|
+
end
|
672
|
+
|
677
673
|
def store_local_charge(params, options)
|
678
674
|
message = {"message" => 'fail'}
|
679
675
|
if options
|
@@ -54,7 +54,7 @@ module AppManager
|
|
54
54
|
end
|
55
55
|
|
56
56
|
|
57
|
-
def recurring_charge_api_call(plan,return_url,shop,
|
57
|
+
def recurring_charge_api_call(plan,return_url,shop,discount_local_storage)
|
58
58
|
plan_test = nil
|
59
59
|
shop_plan_field = AppManager.configuration.field_names['shopify_plan'] rescue nil
|
60
60
|
if !plan['affiliate'].nil? && plan['affiliate'].any? && !shop_plan_field.nil? && plan['affiliate'].map{|e| e['value']}.include?(shop[shop_plan_field])
|
@@ -84,11 +84,9 @@ module AppManager
|
|
84
84
|
end
|
85
85
|
|
86
86
|
promotional_discount = []
|
87
|
-
if
|
88
|
-
created_at = shop[AppManager.configuration.field_names['created_at']]
|
89
|
-
reinstall = AppManager.check_if_reinstall(created_at)
|
87
|
+
if !discount_local_storage.nil? && shop
|
90
88
|
plan_obj = AppManager::Client.new
|
91
|
-
promotional_discount = plan_obj.get_promotional_discount(shop.shopify_domain,
|
89
|
+
promotional_discount = plan_obj.get_promotional_discount(shop.shopify_domain, discount_local_storage)
|
92
90
|
promotional_discount = [] if promotional_discount.class.to_s == "Hash" && promotional_discount.has_key?('status') && promotional_discount['status'] == 404
|
93
91
|
end
|
94
92
|
|
@@ -141,9 +139,8 @@ module AppManager
|
|
141
139
|
promotional_discount_applies = promotional_discount.present? && promotional_discount.any?
|
142
140
|
promotional_discount_id = discount_exists && promotional_discount_applies ? 0 : promotional_discount_applies ? promotional_discount['id'] : 0
|
143
141
|
|
144
|
-
|
145
|
-
|
146
|
-
return_url += "&promo_discount=#{promotional_discount_id}&discounted_plans=#{Rack::Utils.escape(plans_relation.to_json)}"
|
142
|
+
return_url += "&discount=#{promotional_discount_id}"
|
143
|
+
|
147
144
|
|
148
145
|
price_details = {
|
149
146
|
"price": { "amount": plan['price'], "currencyCode": 'USD' },
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
# app/middleware/set_cookie.rb
|
4
|
+
module AppManager
|
5
|
+
class SetLocalStorage
|
6
|
+
def initialize(app, condition,destination_url)
|
7
|
+
@app = app
|
8
|
+
@condition = condition
|
9
|
+
@destination_url = destination_url
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
request = Rack::Request.new(env)
|
14
|
+
|
15
|
+
if @condition.call(request)
|
16
|
+
url = URI.parse(request.url)
|
17
|
+
host = url.host
|
18
|
+
discount_code = request.path.split('/')[2] rescue ''
|
19
|
+
AppManager.clear_cache #clearing cache
|
20
|
+
# Set a 302 response with an external URL and a cookie
|
21
|
+
return [
|
22
|
+
302,
|
23
|
+
{
|
24
|
+
'Location' => "#{@destination_url}?discount_code=#{discount_code}" ,
|
25
|
+
'Content-Type' => 'text/plain'
|
26
|
+
},
|
27
|
+
['Redirecting to external URL with cookie']
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
31
|
+
@app.call(env)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/app_manager/version.rb
CHANGED
data/lib/app_manager.rb
CHANGED
@@ -16,25 +16,8 @@ require "app_manager/model"
|
|
16
16
|
require "app_manager/fail_safe"
|
17
17
|
require 'app_manager/railtie' if defined?(Rails)
|
18
18
|
require 'app_manager/exceptions'
|
19
|
-
require 'action_dispatch/middleware/cookies' if defined?(Rails)
|
20
|
-
require "action_controller"
|
21
19
|
|
22
20
|
module AppManager
|
23
|
-
module CookiesHandler
|
24
|
-
include ActionController::Cookies
|
25
|
-
|
26
|
-
def self.resolve_from_cookies(request)
|
27
|
-
if request.cookies['ShopCircleDiscount'].present?
|
28
|
-
{
|
29
|
-
'codeType' => 'normal',
|
30
|
-
'code' => request.cookies['ShopCircleDiscount']
|
31
|
-
}
|
32
|
-
else
|
33
|
-
nil
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
21
|
def self.configure
|
39
22
|
yield configuration
|
40
23
|
end
|
@@ -51,14 +34,4 @@ module AppManager
|
|
51
34
|
end
|
52
35
|
end
|
53
36
|
|
54
|
-
def self.resolve_from_cookies(request)
|
55
|
-
CookiesHandler.resolve_from_cookies(request)
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.check_if_reinstall(created_at)
|
59
|
-
created_at < (Time.now - 5.minutes) ? 1 : 0
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
|
64
37
|
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: 2.
|
4
|
+
version: 2.2.0
|
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: 2024-
|
11
|
+
date: 2024-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -119,7 +119,7 @@ files:
|
|
119
119
|
- lib/app_manager/protection.rb
|
120
120
|
- lib/app_manager/railtie.rb
|
121
121
|
- lib/app_manager/response_cache.rb
|
122
|
-
- lib/app_manager/
|
122
|
+
- lib/app_manager/set_local_storage.rb
|
123
123
|
- lib/app_manager/tasks/sync/local_app_manager.rake
|
124
124
|
- lib/app_manager/version.rb
|
125
125
|
- lib/generators/app_manager/install/install_generator.rb
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# app/middleware/set_cookie_middleware.rb
|
2
|
-
require 'action_dispatch/middleware/cookies'
|
3
|
-
require 'uri'
|
4
|
-
|
5
|
-
# app/middleware/set_cookie.rb
|
6
|
-
module AppManager
|
7
|
-
class SetCookie
|
8
|
-
def initialize(app, condition)
|
9
|
-
@app = app
|
10
|
-
@condition = condition
|
11
|
-
end
|
12
|
-
|
13
|
-
def call(env)
|
14
|
-
request = Rack::Request.new(env)
|
15
|
-
|
16
|
-
if @condition.call(request)
|
17
|
-
url = URI.parse(request.url)
|
18
|
-
host = url.host
|
19
|
-
discount_code = request.path.split('/')[2]
|
20
|
-
|
21
|
-
# Set a cookie named 'ShopCircleDiscount' with the extracted values
|
22
|
-
lifetime = Time.now + 60 * 60 * 24 * 365
|
23
|
-
cookie_value = discount_code
|
24
|
-
|
25
|
-
AppManager.clear_cache #clearing cache
|
26
|
-
# Set a 302 response with an external URL and a cookie
|
27
|
-
return [
|
28
|
-
302,
|
29
|
-
{
|
30
|
-
'Location' => 'https://admin.shopify.com/admin/apps/'+ENV['SHOPIFY_APP_SLUG']+'/home/plan' ,
|
31
|
-
'Set-Cookie' => "ShopCircleDiscount=#{cookie_value}; expires=#{lifetime.utc.strftime('%a, %d %b %Y %H:%M:%S GMT')}; path=/; domain=#{host}; secure; HttpOnly; SameSite=None",
|
32
|
-
'Content-Type' => 'text/plain'
|
33
|
-
},
|
34
|
-
['Redirecting to external URL with cookie']
|
35
|
-
]
|
36
|
-
end
|
37
|
-
|
38
|
-
@app.call(env)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|