shopify-gold 4.1.0 → 5.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2f3bd33de348c0f6ec3cf6e3f01afc445047d48e1df6f4544e843fe003a6ff1
4
- data.tar.gz: 87c3b24f37dc3c1b6fba30171029af7251f2d248802803ea51d2930e79b7e13e
3
+ metadata.gz: 27bbc1ba14621fd2a39291faa1df4d52e004cb512858d82f04e29fdefd4f43fc
4
+ data.tar.gz: 237848311344321a2b5a218ddbfaed88e133efb7ec9ca3b094718c4db1ac382b
5
5
  SHA512:
6
- metadata.gz: fbffeb717f7a5ec08d084de5a2d1530a1fde2bc7500412084847ce620a9dc8e60f7e24cc33f24498001781a5b0e5ef626a72c84ded3c41c611c28cfede703533
7
- data.tar.gz: 0660e85fab96435db7bbb431b0d955e753399535449890a1c5a9dc87ceffa4b949b9cb40caaef587763ee5f0ab36174246860940cb35dd15a9a50354f6c9ef47
6
+ metadata.gz: f3293e0897c04ad38929c80a2dbb528f5ebfd3f24563e3dcfdcaa68b0a37562ff97406112f4821711ef74d3d539f336a7ccd22de171d6496839be838fc5bde7c
7
+ data.tar.gz: 06c96b494db7fd61e25a3d4189d004b7cedfe4a93d1636795bcf0923f3036f9fb6cc67be48944991d881195564287ab066fc8866b83c8639aefe3ce50b1b2c9c
data/README.md CHANGED
@@ -183,6 +183,11 @@ To add tiers to your app, add a `config/tiers.yml` file. Here's an example file:
183
183
  max_customers: 1000
184
184
  ```
185
185
 
186
+ Any tier that is visible will appear in the list of choices. If it is hidden, you
187
+ can link to it either directly (/tier?id=basic) or indirectly (/start?tier=basic).
188
+ The later will route to the app listing page before selecting this option on the
189
+ tier page.
190
+
186
191
  ## Controller and views
187
192
  Ok, so it's time to get paid. Let's add our module to show merchants tier choices.
188
193
 
@@ -262,11 +267,4 @@ which you can do on Mac via Homebrew with `brew install graphviz`
262
267
 
263
268
  ## Release
264
269
  To release gem, run `gem release`, which depends on having `gem-release` installed
265
- on your system.
266
-
267
- ## Changelog
268
- Version 4.0.0
269
- - Added referral affiliates
270
-
271
- Version 3.2.0
272
- - Removed `force_embedded_redirect` config option
270
+ on your system.
@@ -1,4 +1,4 @@
1
- require_dependency "gold/application_controller"
1
+ require "gold/application_controller"
2
2
 
3
3
  module Gold
4
4
  # Inherit from Shopify's authenticated module
@@ -7,7 +7,7 @@ module Gold
7
7
  layout "gold/billing"
8
8
 
9
9
  rescue_from Statesman::TransitionFailedError do |e|
10
- billing = Billing.find_by!(shop_id: session[:shopify])
10
+ billing = Billing.find_by!(shop_id: session[:shop_id])
11
11
  Gold.logger.error("Shop '#{billing.shop.shopify_domain}' failed to " \
12
12
  "transtion '#{e}'")
13
13
  render "gold/billing/transition_error", layout: "gold/billing",
@@ -44,17 +44,20 @@ module Gold
44
44
 
45
45
  apply_referral_cookie unless billing.tier
46
46
 
47
+ params[:id] = cookies[:gold_tier_id] if cookies[:gold_tier_id].present?
48
+
47
49
  @tiers = Tier.visible
48
50
  end
49
51
 
50
52
  # Process a tier selection.
51
53
  def select_tier
52
54
  @tiers = Tier.visible
53
- @tier = Tier.find(params[:tier])
55
+ @tier = Tier.find(params[:tier])
54
56
  outcome = SelectTierOp.new(billing, @tier).call
55
57
  case outcome
56
58
  when SameTier, TierApplied
57
- redirect_to main_app.root_url
59
+ cookies.delete(:gold_tier_id)
60
+ redirect_to Gold.configuration.after_tier_redirect_path
58
61
  when CannotSelectTier
59
62
  flash.now[:error] = "Your shop is not eligible for this plan"
60
63
  render :tier
@@ -95,7 +98,7 @@ module Gold
95
98
  Gold.logger.info("[#{billing.id}] Charge is ready")
96
99
  end
97
100
 
98
- redirect_to main_app.root_url
101
+ redirect_to Gold.configuration.after_tier_redirect_path
99
102
  else
100
103
  raise "Not sure how to handle #{outcome} on outstanding charge"
101
104
  end
@@ -109,7 +112,7 @@ module Gold
109
112
  case outcome
110
113
  when ActiveCharge
111
114
  ApplyTierOp.new(billing).call
112
- outer_redirect_to_main
115
+ outer_redirect(Gold.configuration.after_tier_redirect_path)
113
116
  when DeclinedCharge
114
117
  redirect_to declined_charge_url
115
118
  when ExpiredCharge
@@ -162,14 +165,14 @@ module Gold
162
165
 
163
166
  # If embedded app, redirect directly through the Shopify admin. This can provide
164
167
  # a better experience than the page rendering and JS kicking off a redirect
165
- def outer_redirect_to_main
168
+ def outer_redirect(redirect_path)
166
169
  if ShopifyApp.configuration.embedded_app
167
170
  shopify_domain = billing.shop.shopify_domain
168
171
  api_key = ShopifyApp.configuration.api_key
169
- fullpath = "/admin/apps/#{api_key}#{main_app.root_path}"
172
+ fullpath = "/admin/apps/#{api_key}#{redirect_path}"
170
173
  redirect_to URI::HTTPS.build(host: shopify_domain, path: fullpath).to_s
171
174
  else
172
- redirect_to main_app.root_url
175
+ redirect_to redirect_path
173
176
  end
174
177
  end
175
178
 
@@ -9,7 +9,7 @@ module Gold
9
9
 
10
10
  # Returns the Gold::Billing instance for the currently logged-in merchant.
11
11
  def billing
12
- @billing ||= Billing.find_by!(shop_id: session[:shopify])
12
+ @billing ||= Billing.find_by!(shop_id: session[:shop_id])
13
13
  rescue ActiveRecord::RecordNotFound
14
14
  raise Gold::Exceptions::BillingNotFound
15
15
  end
@@ -6,7 +6,7 @@ module Gold
6
6
 
7
7
  cookies[:gold_referral_id] = { value: referral.id, expires: 30.days } if referral
8
8
 
9
- redirect_to Gold.configuration.referral_redirect_url
9
+ redirect_to Gold.configuration.app_listing_url
10
10
  end
11
11
  end
12
12
  end
@@ -0,0 +1,9 @@
1
+ module Gold
2
+ class SetupController < ApplicationController
3
+ def new
4
+ tier = Tier.find(params[:tier])
5
+ cookies[:gold_tier_id] = { value: tier.id, expires: 7.days } if tier
6
+ redirect_to Gold.configuration.app_listing_url
7
+ end
8
+ end
9
+ end
@@ -1,4 +1,4 @@
1
- require_dependency "statesman"
1
+ require "statesman"
2
2
 
3
3
  module Gold
4
4
  module Concerns
@@ -1,4 +1,4 @@
1
- require_dependency "statesman"
1
+ require "statesman"
2
2
 
3
3
  module Gold
4
4
  # This is the finite state machine specification that governs how shops may
@@ -230,7 +230,8 @@ module Gold
230
230
  apply_free_tier
231
231
  change_tier
232
232
  staff
233
- optional_charge]
233
+ optional_charge
234
+ marked_as_uninstalled]
234
235
 
235
236
  before_transition to: :optional_charge, &require_metadata(:charge_id)
236
237
  guard_transition to: :optional_charge, &ensure_plan_is(:paying?)
@@ -238,7 +239,8 @@ module Gold
238
239
  optional_charge_accepted
239
240
  optional_charge_declined
240
241
  marked_as_uninstalled]
241
- transition from: :optional_charge_declined, to: :billing
242
+ transition from: :optional_charge_declined, to: %i[billing
243
+ marked_as_uninstalled]
242
244
 
243
245
  transition from: :optional_charge_accepted, to: %i[charge_activated
244
246
  marked_as_uninstalled]
@@ -256,13 +258,17 @@ module Gold
256
258
  marked_as_uninstalled]
257
259
 
258
260
  transition from: :delayed_charge_expired, to: %i[delayed_charge
259
- marked_as_delinquent]
261
+ marked_as_delinquent
262
+ marked_as_uninstalled]
260
263
  transition from: :delayed_charge_declined, to: %i[marked_as_delinquent
261
- delayed_charge]
264
+ delayed_charge
265
+ marked_as_uninstalled]
262
266
 
263
267
  guard_transition to: :marked_as_delinquent,
264
268
  &ensure_min_days_in_state(Gold.configuration.days_until_delinquent)
265
- transition from: :marked_as_delinquent, to: :delinquent
269
+ transition from: :marked_as_delinquent, to: %i[delinquent
270
+ marked_as_uninstalled]
271
+
266
272
  transition from: :delinquent, to: %i[marked_as_uninstalled delayed_charge cleanup]
267
273
 
268
274
  guard_transition to: :affiliate, &ensure_plan_is(:affiliate?)
@@ -20,14 +20,16 @@ module Gold
20
20
 
21
21
  # Returns true if this is a development (non-live) shop.
22
22
  def affiliate?
23
- plan == "affiliate"
23
+ plans = %w[affiliate partner_test]
24
+ plans.include?(plan)
24
25
  end
25
26
 
26
27
  # Returns true if this is a shop owned by Shopify staff. This specifically
27
28
  # excludes Shopify Business shops, as we believe those are paid stores that
28
29
  # Shopify employees use for their own businesses.
29
30
  def staff?
30
- plan == "staff"
31
+ plans = %w[plus_partner_sandbox staff]
32
+ plans.include?(plan)
31
33
  end
32
34
 
33
35
  # Returns true if this shop has been frozen by Shopify for non-payment.
@@ -1,14 +1,19 @@
1
1
  <h1>Your account has been frozen</h1>
2
2
  <p>Hey <%= @shop.shop_owner %>,</p>
3
3
  <p>
4
- We have suspended access to your <%= Gold.configuration.app_name %> usage because we
5
- have not received an authorization of payment towards your new billing tier.
4
+ We have suspended access to your <%= Gold.configuration.app_name %> usage for
5
+ <%= @shop.myshopify_domain %> because we have not received an authorization of
6
+ payment towards your new billing tier.
6
7
  </p>
7
8
  <p>
8
9
  Please respond to this email promptly by logging into the app and approving
9
10
  the displayed charge. If we do not hear from you for more than 30 days, we may
10
11
  choose to delete your account.
11
12
  </p>
13
+ <p>
14
+ If you think this has been made in error, please respond to this email and we'll
15
+ help you get things sorted!
16
+ </p>
12
17
  <p>
13
18
  <a href="<%= shopify_app.login_url %>" class="button">Log in</a>
14
19
  </p>
@@ -1,10 +1,10 @@
1
1
  <h1>Your account has been suspended</h1>
2
2
  <p>Hey <%= @shop.shop_owner %>,</p>
3
3
  <p>
4
- We've suspended access to your <%= Gold.configuration.app_name %> usage because we
5
- believe you are in violation of our terms of service. Until we have reconciled
6
- this problem, you will not be able to access the app, nor will your customers
7
- be able to interact with it.
4
+ We've suspended access to your <%= Gold.configuration.app_name %> usage for
5
+ <%= @shop.myshopify_domain %> because we believe you are in violation of our
6
+ terms of service. Until we have reconciled this problem, you will not be able
7
+ to access the app, nor will your customers be able to interact with it.
8
8
  </p>
9
9
  <p>
10
10
  Please respond to this email promptly by asking how to resolve this suspension
@@ -1,4 +1,6 @@
1
1
  Gold::Engine.routes.draw do
2
+ get "/start", to: "setup#new"
3
+
2
4
  get "/terms", to: "billing#terms", as: "terms"
3
5
  put "/terms", to: "billing#process_terms"
4
6
 
@@ -13,7 +13,8 @@ module Gold
13
13
  :days_until_cleanup,
14
14
  :shop_domain_attribute,
15
15
  :force_embedded_redirect,
16
- :referral_redirect_url
16
+ :app_listing_url,
17
+ :after_tier_redirect_path
17
18
 
18
19
  # Callbacks
19
20
  attr_accessor :on_terms,
@@ -71,7 +72,11 @@ module Gold
71
72
 
72
73
  # The URL to follow after a referral code is tracked
73
74
  # (e.g. https://apps.shopify.com/customr)
74
- @referral_redirect_url = "/"
75
+ @app_listing_url = "https://apps.shopify.com/"
76
+
77
+ # The redirect path after a tier is applied. Use this path to welcome a
78
+ # merchant if they just installed
79
+ @after_tier_redirect_path = "/"
75
80
  end
76
81
 
77
82
  def shop_class
@@ -1,3 +1,3 @@
1
1
  module Gold
2
- VERSION = "4.1.0".freeze
2
+ VERSION = "5.1.1".freeze
3
3
  end
@@ -90,8 +90,17 @@ namespace :gold do
90
90
  end
91
91
 
92
92
  billing.shop.with_shopify_session do
93
- Gold::MarkAsDelinquentOp.new(billing).call
94
- puts "Shop '#{billing.shop.shopify_domain}' is delinquent"
93
+ domain = billing.shop.shopify_domain
94
+
95
+ begin
96
+ Gold::MarkAsDelinquentOp.new(billing).call
97
+ puts "Shop '#{domain}' is delinquent"
98
+ rescue ActiveResource::UnauthorizedAccess
99
+ puts "It looks like '#{domain}' uninstalled, running op..."
100
+ Gold::UninstallOp.new(billing).call
101
+ rescue ActiveResource::ClientError => e
102
+ puts "Error for '#{domain}', #{e}"
103
+ end
95
104
  end
96
105
  end
97
106
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify-gold
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 5.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Smith
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-01-24 00:00:00.000000000 Z
12
+ date: 2020-06-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -17,42 +17,42 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 5.2.0
20
+ version: '6'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 5.2.0
27
+ version: '6'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: sass-rails
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '5.0'
34
+ version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '5.0'
41
+ version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: shopify_app
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '11'
48
+ version: '13'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '11'
55
+ version: '13'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: statesman
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -73,14 +73,14 @@ dependencies:
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '2.5'
76
+ version: '2.7'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '2.5'
83
+ version: '2.7'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: faker
86
86
  requirement: !ruby/object:Gem::Requirement
@@ -113,16 +113,16 @@ dependencies:
113
113
  name: rubocop
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - "~>"
116
+ - - ">="
117
117
  - !ruby/object:Gem::Version
118
- version: 0.74.0
118
+ version: '0.74'
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - "~>"
123
+ - - ">="
124
124
  - !ruby/object:Gem::Version
125
- version: 0.74.0
125
+ version: '0.74'
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: rubocop-rails
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -157,14 +157,14 @@ dependencies:
157
157
  requirements:
158
158
  - - "~>"
159
159
  - !ruby/object:Gem::Version
160
- version: 11.3.0
160
+ version: '13'
161
161
  type: :development
162
162
  prerelease: false
163
163
  version_requirements: !ruby/object:Gem::Requirement
164
164
  requirements:
165
165
  - - "~>"
166
166
  - !ruby/object:Gem::Version
167
- version: 11.3.0
167
+ version: '13'
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: sqlite3
170
170
  requirement: !ruby/object:Gem::Requirement
@@ -185,14 +185,14 @@ dependencies:
185
185
  requirements:
186
186
  - - "~>"
187
187
  - !ruby/object:Gem::Version
188
- version: 3.4.2
188
+ version: '3'
189
189
  type: :development
190
190
  prerelease: false
191
191
  version_requirements: !ruby/object:Gem::Requirement
192
192
  requirements:
193
193
  - - "~>"
194
194
  - !ruby/object:Gem::Version
195
- version: 3.4.2
195
+ version: '3'
196
196
  description: |
197
197
  Gold is Helium's approach to billing for Shopify apps. It provides a
198
198
  framework to build Rails apps upon.
@@ -219,6 +219,7 @@ files:
219
219
  - app/controllers/gold/billing_controller.rb
220
220
  - app/controllers/gold/concerns/merchant_facing.rb
221
221
  - app/controllers/gold/referrals_controller.rb
222
+ - app/controllers/gold/setup_controller.rb
222
223
  - app/jobs/gold/after_authenticate_job.rb
223
224
  - app/jobs/gold/app_uninstalled_job.rb
224
225
  - app/jobs/gold/application_job.rb
@@ -316,7 +317,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
316
317
  - !ruby/object:Gem::Version
317
318
  version: '0'
318
319
  requirements: []
319
- rubygems_version: 3.0.3
320
+ rubygems_version: 3.1.2
320
321
  signing_key:
321
322
  specification_version: 4
322
323
  summary: Helium's approach to billing for Shopify apps