app_manager 1.1.1 → 1.1.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac02414e46b02e9c7e33c7a5625dce22ba413e4a1081dc4f99596c659b1d08da
|
4
|
+
data.tar.gz: d61fdc1266e5c9946ae2a4e32c79db8d6179f155a7b9f3827079046624820563
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 218eacfcbc353cdbdacc77d72ff557c28c8b354ad4f0c4d07d781d6f6b556cf067e955dc77f29c8fa5bd81b2acba7883dd507ddeeb6853024c406e73e03ccfb2
|
7
|
+
data.tar.gz: e71153006dfeb712762d4da2064534e6b1801ccd4a9010ee2b0f61aae29fe1eda1bfa6c5d8867b61931dca7cf8adddb7493f08faf2f0d0a981ba6859e4fd0a30
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
app_manager (1.1.
|
4
|
+
app_manager (1.1.2)
|
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.1)
|
123
123
|
multi_xml (0.6.0)
|
124
124
|
net-imap (0.2.3)
|
125
125
|
digest
|
@@ -147,8 +147,8 @@ GEM
|
|
147
147
|
public_suffix (4.0.6)
|
148
148
|
racc (1.6.0)
|
149
149
|
rack (2.2.3.1)
|
150
|
-
rack-test (
|
151
|
-
rack (>= 1.
|
150
|
+
rack-test (2.0.0)
|
151
|
+
rack (>= 1.3)
|
152
152
|
rails (7.0.3)
|
153
153
|
actioncable (= 7.0.3)
|
154
154
|
actionmailbox (= 7.0.3)
|
@@ -14,6 +14,23 @@ module AppManager
|
|
14
14
|
plan_obj = AppManager::Client.new
|
15
15
|
plan_data = plan_obj.get_plan(params[:plan_id],params[:shop])
|
16
16
|
if plan_data.present? && plan_data.is_a?(Hash)
|
17
|
+
if plan_data['price'] == 0
|
18
|
+
if @shop.update(@plan_field => params[:plan_id])
|
19
|
+
begin
|
20
|
+
AppManager::EventHandler.new('charge_created',{
|
21
|
+
"plan" => plan_data,
|
22
|
+
"charge" => nil,
|
23
|
+
"previous_charge" => nil
|
24
|
+
})
|
25
|
+
rescue Exception => e
|
26
|
+
Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
|
27
|
+
end
|
28
|
+
AppManager.clear_cache
|
29
|
+
render json: {'redirect_url' => "#{app_url}?shop=#{params[:shop]}"} and return true
|
30
|
+
else
|
31
|
+
raise Error, "Invalid charge"
|
32
|
+
end
|
33
|
+
end
|
17
34
|
request_data = {'shop' => @shop.shopify_domain, 'timestamp' => Time.now.to_i, 'plan' => params[:plan_id]}
|
18
35
|
return_url = "#{app_url}#{plan_callback_path}?#{Rack::Utils.build_query(request_data)}"
|
19
36
|
gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain,@shop.shopify_token)
|
@@ -61,7 +78,7 @@ module AppManager
|
|
61
78
|
begin
|
62
79
|
plan_obj.cancel_charge(@shop[shopify_domain],@shop[@plan_field])
|
63
80
|
rescue Exception => e
|
64
|
-
|
81
|
+
Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
|
65
82
|
end
|
66
83
|
end
|
67
84
|
|
@@ -70,13 +87,17 @@ module AppManager
|
|
70
87
|
|
71
88
|
if response['message'] == "success"
|
72
89
|
AppManager.clear_cache
|
73
|
-
|
90
|
+
@shop.update(@plan_field => params[:plan])
|
74
91
|
charge_data = plan_obj.get_charge(@shop[shopify_domain])
|
75
|
-
|
92
|
+
begin
|
93
|
+
AppManager::EventHandler.new('charge_created',{
|
76
94
|
"plan" => plan_data,
|
77
95
|
"charge" => charge,
|
78
96
|
"previous_charge" => charge_data ? (charge_data['cancelled_charge'] || nil) : nil
|
79
97
|
})
|
98
|
+
rescue Exception => e
|
99
|
+
Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
|
100
|
+
end
|
80
101
|
end
|
81
102
|
redirect_to "#{app_url}?shop=#{params[:shop]}", :status => 301 and return
|
82
103
|
else
|
@@ -14,6 +14,7 @@ module AppManager
|
|
14
14
|
def plans
|
15
15
|
active_plan_id_or_name = shopify_plan = plan = nil
|
16
16
|
default_plan_id = nil
|
17
|
+
choose_later = false
|
17
18
|
plan_obj = AppManager::Client.new
|
18
19
|
plans = []
|
19
20
|
if params[:shop_domain].present? && !AppManager.configuration.plan_features.nil?
|
@@ -25,6 +26,14 @@ module AppManager
|
|
25
26
|
shopify_plan_field = AppManager.configuration.field_names['shopify_plan']
|
26
27
|
shopify_plan = @shop[shopify_plan_field] rescue nil
|
27
28
|
plan = plans.any? && !active_plan_id_or_name.nil? ? (plans.find{|x| x["id"] == active_plan_id_or_name}.present? ? plans.find{|x| x["id"] == active_plan_id_or_name} : nil ) : nil
|
29
|
+
|
30
|
+
@trial_activated_field = AppManager.configuration.field_names['trial_activated_at']
|
31
|
+
trial_activated_at = @shop[@trial_activated_field] rescue nil
|
32
|
+
active_charge = plan_obj.get_charge(params[:shop_domain])
|
33
|
+
if active_charge.any? && active_charge['active_charge'].nil? && active_charge['cancelled_charge'].nil? && trial_activated_at
|
34
|
+
choose_later = true
|
35
|
+
end
|
36
|
+
|
28
37
|
end
|
29
38
|
else
|
30
39
|
Rails.logger.info "APP MANGAGER >>>> Either model is defined wrong or config.plan_id_or_name_field is nil in initializer ==="
|
@@ -34,33 +43,27 @@ module AppManager
|
|
34
43
|
end
|
35
44
|
|
36
45
|
|
37
|
-
|
38
|
-
default_plan_data
|
39
|
-
|
40
|
-
|
41
|
-
if store_base_plan
|
42
|
-
begin
|
43
|
-
shopify_plans = default_plan_data.map { |e| e.map { |key, value| [e['shopify_plans'], e['id']] }.to_h }
|
46
|
+
default_plan_data = plans.select{|x| x['choose_later_plan'] == true }
|
47
|
+
if default_plan_data.any?
|
48
|
+
if default_plan_data.select{|x| x['store_base_plan'] == true }.size > 0
|
49
|
+
shopify_plans = plans.select{|x| x['interval'] == 'EVERY_30_DAYS' }
|
44
50
|
shopify_plans.each do |shp|
|
45
|
-
if shp
|
46
|
-
|
47
|
-
|
48
|
-
break
|
49
|
-
end
|
51
|
+
if shp && shp["shopify_plans"].include?(shopify_plan)
|
52
|
+
default_plan_id = shp["id"]
|
53
|
+
break
|
50
54
|
end
|
51
55
|
end
|
52
|
-
|
53
|
-
|
56
|
+
else
|
57
|
+
default_plan_id = default_plan_data.map{|e| e['id']}.first if default_plan_data.any? rescue nil
|
54
58
|
end
|
55
|
-
else
|
56
|
-
default_plan_id = default_plan_data.map{|e| e['id']}.first if default_plan_data.any? rescue nil
|
57
59
|
end
|
58
60
|
|
59
61
|
response = {
|
60
62
|
'plans' => plans,
|
61
63
|
'shopify_plan' => shopify_plan,
|
62
64
|
'plan' => plan,
|
63
|
-
'default_plan_id' => default_plan_id
|
65
|
+
'default_plan_id' => default_plan_id,
|
66
|
+
'choose_later' => choose_later
|
64
67
|
}
|
65
68
|
render json: response
|
66
69
|
end
|
@@ -98,8 +101,9 @@ module AppManager
|
|
98
101
|
|
99
102
|
def active_without_plan
|
100
103
|
if params[:shop_domain].present? && params[:plan_id].present? && model
|
104
|
+
@shop = shop_data
|
101
105
|
@trial_activated_field = AppManager.configuration.field_names['trial_activated_at']
|
102
|
-
|
106
|
+
@shop.update(@plan_field => params[:plan_id],@trial_activated_field => DateTime.now)
|
103
107
|
render json: {'status' => true}
|
104
108
|
else
|
105
109
|
render json: {'status' => false,'error' => 'Shop not found or missing shop'}, status: 422
|
@@ -50,7 +50,7 @@ module AppManager
|
|
50
50
|
|
51
51
|
def save_api_plans(plans)
|
52
52
|
@apm_db.execute("DROP TABLE IF EXISTS plans;")
|
53
|
-
@apm_db.execute "CREATE TABLE IF NOT EXISTS plans(id integer,type varchar(255), name varchar(255), price float, offer_text varchar(255), interval text, shopify_plans text, trial_days integer, test boolean, on_install integer, is_custom boolean, app_id integer, base_plan integer, created_at datetime, updated_at datetime, public boolean, discount integer, cycle_count integer, store_base_plan boolean, discount_type varchar(255), affiliate text, features text, deleted_at datetime)"
|
53
|
+
@apm_db.execute "CREATE TABLE IF NOT EXISTS plans(id integer,type varchar(255), name varchar(255), price float, offer_text varchar(255), description varchar(255), interval text, shopify_plans text, trial_days integer, test boolean, on_install integer, is_custom boolean, app_id integer, base_plan integer, created_at datetime, updated_at datetime, public boolean, discount integer, cycle_count integer, store_base_plan boolean, choose_later_plan boolean, discount_type varchar(255), affiliate text, features text, deleted_at datetime)"
|
54
54
|
|
55
55
|
if plans.any?
|
56
56
|
plans.each do |plan|
|
@@ -66,7 +66,8 @@ module AppManager
|
|
66
66
|
is_custom = plan['is_custom'] ? 1 : 0
|
67
67
|
public_val = plan['public'] ? 1 : 0
|
68
68
|
store_base_plan = plan['store_base_plan'] ? 1 : 0
|
69
|
-
|
69
|
+
choose_later_plan = plan['choose_later_plan'] ? 1 : 0
|
70
|
+
@apm_db.execute("INSERT INTO plans ( id , type , name , price , offer_text, description , interval , shopify_plans , trial_days , test , on_install , is_custom , app_id , base_plan , created_at, updated_at , public , discount , cycle_count , store_base_plan, choose_later_plan , discount_type, affiliate, features, deleted_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",plan["id"], plan["type"], plan["name"], plan["price"], plan["offer_text"], plan["description"], "#{interval}", "#{shopify_plans}", plan["trial_days"], plan_test, plan["on_install"], is_custom, plan["app_id"], plan["base_plan"], plan["created_at"], plan["updated_at"],public_val, plan["discount"], plan["cycle_count"], store_base_plan, choose_later_plan, plan["discount_type"], "#{affiliate}", "#{features}",plan["deleted_at"])
|
70
71
|
end
|
71
72
|
end
|
72
73
|
end
|
@@ -77,7 +78,8 @@ module AppManager
|
|
77
78
|
@apm_db.execute "CREATE TABLE IF NOT EXISTS charges(id INTEGER PRIMARY KEY,charge_id varchar(255),test boolean, status varchar(255),name varchar(255), type varchar(255), price float,interval varchar(255),trial_days integer,billing_on datetime,activated_on datetime,trial_ends_on datetime,cancelled_on datetime, expires_on datetime,plan_id integer,description text,shop_domain varchar(255),created_at datetime, updated_at datetime, app_id integer, sync boolean DEFAULT 0,process_type varchar(255))"
|
78
79
|
if charges.any?
|
79
80
|
charges.each do |charge|
|
80
|
-
|
81
|
+
charge_test = charge['test'] ? 1 : 0
|
82
|
+
@apm_db.execute("INSERT INTO charges (id ,charge_id ,test , status ,name , type , price ,interval ,trial_days ,billing_on ,activated_on ,trial_ends_on ,cancelled_on , expires_on ,plan_id ,description ,shop_domain ,created_at , updated_at, app_id, sync ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", nil,charge["charge_id"],charge_test,charge["status"],charge["name"],charge["type"],charge["price"],charge["interval"],charge["trial_days"],charge["billing_on"],charge["activated_on"],charge["trial_ends_on"],charge["cancelled_on"],charge["expires_on"],charge["plan_id"],charge["description"],charge["shop_domain"],charge["created_at"],charge["updated_at"],charge["app_id"],1)
|
81
83
|
end
|
82
84
|
end
|
83
85
|
end
|
data/lib/app_manager/model.rb
CHANGED
@@ -23,7 +23,7 @@ module AppManager
|
|
23
23
|
shopify_fields = @field_names = AppManager.configuration.field_names
|
24
24
|
plan_obj = AppManager::Client.new
|
25
25
|
active_charge = plan_obj.get_charge(shopify_fields['name']) rescue nil
|
26
|
-
return active_charge ? true : false
|
26
|
+
return activeCharge['active_charge'].present? && !activeCharge['active_charge'].nil? ? true : false
|
27
27
|
end
|
28
28
|
|
29
29
|
|
@@ -86,14 +86,58 @@ module AppManager
|
|
86
86
|
begin
|
87
87
|
shop_domain = self[AppManager.configuration.shopify_domain_field]
|
88
88
|
plan_obj = AppManager::Client.new
|
89
|
-
return plan_obj.get_charge(
|
89
|
+
return plan_obj.get_charge(shop_domain)
|
90
90
|
rescue Exception => e
|
91
91
|
return "#{e.inspect}"
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
+
def set_default_plan(plan_id=nil)
|
96
|
+
begin
|
97
|
+
if plan_id.nil?
|
98
|
+
shop_domain = self[AppManager.configuration.shopify_domain_field]
|
99
|
+
plan_obj = AppManager::Client.new
|
100
|
+
plans = plan_obj.get_plans(shop_domain)
|
101
|
+
free_plans = plans.select{|x| x['price'] == 0 && x['public'] == true}
|
102
|
+
if free_plans.any?
|
103
|
+
self.plan_id = free_plans.first["id"]
|
104
|
+
self.save
|
105
|
+
else
|
106
|
+
raise Error, "Free Plan is not available"
|
107
|
+
end
|
108
|
+
else
|
109
|
+
self.plan_id = plan_id
|
110
|
+
self.save
|
111
|
+
end
|
112
|
+
rescue Exception => e
|
113
|
+
return "#{e.inspect}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
|
95
118
|
|
96
119
|
|
120
|
+
def get_plans_by_features(feature_slugs)
|
121
|
+
if feature_slugs.any?
|
122
|
+
plan_data = []
|
123
|
+
shop_domain = self[AppManager.configuration.shopify_domain_field]
|
124
|
+
plan_obj = AppManager::Client.new
|
125
|
+
plans = plan_obj.get_plans(shop_domain)
|
126
|
+
plans = plans.select{|x| x['interval'] == 'EVERY_30_DAYS' && x['public'] == true}
|
127
|
+
plans.each do |plan|
|
128
|
+
if plan['features'].any? && plan['features'].values.any? && plan['features'].values.collect{|c| c['slug']}.any?
|
129
|
+
plan_feature_slugs = plan['features'].values.collect{|c| c['slug']}.sort
|
130
|
+
if (feature_slugs & plan_feature_slugs).any? && ((feature_slugs & plan_feature_slugs).sort == feature_slugs.sort)
|
131
|
+
plan_data.push(plan)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
return plan_data
|
136
|
+
else
|
137
|
+
return 'feature_slugs is required'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
97
141
|
private
|
98
142
|
|
99
143
|
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.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hulkapps
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|