shopify-gold 4.1.1 → 5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc3de898120461b0d5ea6dc6fa8147159567c2ed350aebfc59b2eeea30a0a83b
4
- data.tar.gz: b9c36b007cad3d7f25470b150c3daab8b1f041fd5e1177f23cdb02c798e1d1c9
3
+ metadata.gz: bc350b0d446abe5859b2fd037803a15465163c684532f8f9c65a31aa30aee03a
4
+ data.tar.gz: 190287a79e30730c8873e7150a3c1e30163f7e8b4aaab27fcd1433831ea16e84
5
5
  SHA512:
6
- metadata.gz: 94e3a447a5693bce00e7848a6968ae7799af0a40d15cfd639cdce123c25b8731a53a7cdabdd0e45d9039464feaf8817c76d6960cd60445550bed5419a27debce
7
- data.tar.gz: f9114585d4d95d47fec91637a3223d3a81cec05e7dd72e92549b34c897e07dec6eccf6afad5ddb78ba3746bd25977add8bb5d3c104ebcb1a520774adb9d2067e
6
+ metadata.gz: 6dff593d4596f5c7d627ae98812f53bb12395cd5df06fa59dbe6ac2eb2b81d73640e22d311bc81728c98bff0a1120e5f2e5ff8f624924950facf6a882bedb607
7
+ data.tar.gz: 3b33761e82d90e0698380096ed23dfdeefc1a0dab7004ee28395f46b654d4c4ef06a04d404a6c7f29693cccccca5b323820177306b1b54a40f238ab00ff5d42c
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.
@@ -79,11 +79,11 @@ module Gold
79
79
  end
80
80
 
81
81
  def qualifications
82
- parent ? parent.qualifications : @qualifications
82
+ parent ? parent.qualifications.merge(@qualifications) : @qualifications
83
83
  end
84
84
 
85
85
  def features
86
- parent ? parent.features : @features
86
+ parent ? parent.features.merge(@features) : @features
87
87
  end
88
88
 
89
89
  def parent
@@ -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.1".freeze
2
+ VERSION = "5.2.0".freeze
3
3
  end
@@ -66,6 +66,8 @@ namespace :gold do
66
66
  Gold::UninstallOp.new(billing).call
67
67
  rescue ActiveResource::ClientError => e
68
68
  puts "Error for '#{billing.shop.shopify_domain}', #{e}"
69
+ rescue Statesman::GuardFailedError => e
70
+ puts "Cannot transition: #{e.message}"
69
71
  end
70
72
  end
71
73
  end
@@ -90,8 +92,17 @@ namespace :gold do
90
92
  end
91
93
 
92
94
  billing.shop.with_shopify_session do
93
- Gold::MarkAsDelinquentOp.new(billing).call
94
- puts "Shop '#{billing.shop.shopify_domain}' is delinquent"
95
+ domain = billing.shop.shopify_domain
96
+
97
+ begin
98
+ Gold::MarkAsDelinquentOp.new(billing).call
99
+ puts "Shop '#{domain}' is delinquent"
100
+ rescue ActiveResource::UnauthorizedAccess
101
+ puts "It looks like '#{domain}' uninstalled, running op..."
102
+ Gold::UninstallOp.new(billing).call
103
+ rescue ActiveResource::ClientError => e
104
+ puts "Error for '#{domain}', #{e}"
105
+ end
95
106
  end
96
107
  end
97
108
  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.1
4
+ version: 5.2.0
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-02-04 00:00:00.000000000 Z
12
+ date: 2020-07-09 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