shopify-gold 3.3.1 → 4.0.0

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: 42a5ac7dc8ec8aae821dae0eac89a2decbcca38f65439f9376feef1fc83cd853
4
- data.tar.gz: f0d81a473d9349838d77dc764cd05a222d8375db54d2f3ef3693adb22b2edc21
3
+ metadata.gz: 9fcecad6aca73ac1e0cc4f97b8f819d35907c32aa1bb00e40e6bbb19e35fc328
4
+ data.tar.gz: 74f433ee134487242e44fa145273eacbc5a3bc933826490c1a024f34d7d10b89
5
5
  SHA512:
6
- metadata.gz: 0d196f6ca18058e5c5fa9b48630b528607d6397666a67216e6a81103242df58da7156b657ca867d83f003eae5588ab53456b474bc7863e67cff10dba7a0aeecf
7
- data.tar.gz: 1a95630918a319db140fe95816253876acaf6f3b1b504d5a1f1b6f2e9077c54d9b3192dd2ce49c9ec2f9e1d92096af187312903c794f757f35a76f61998ef322
6
+ metadata.gz: 2b0fcb9fa69c799007609982fc77717bc09efd13921373561e122c42b29a472bac7a51fc941c86ae57f5ccbcdd2c715970a8ee9f61b5b901ca8bcbe4c652f894
7
+ data.tar.gz: d0408016b0e8995a3e3f57957b6fe0a42c7f1cb5fc8c6d527fbf7f1c0f67a02612f7cf31f389936954792c728a768d75ec7cf6839e7f40dbb39f2b9ca0f0e835
@@ -3,11 +3,8 @@
3
3
  <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
4
4
  viewBox="0 0 656 672" style="enable-background:new 0 0 656 672;" xml:space="preserve">
5
5
  <style type="text/css">
6
- .st0{filter:url(#Adobe_OpacityMaskFilter);}
7
- .st1{fill-rule:evenodd;clip-rule:evenodd;fill:#FFFFFF;}
8
- .st2{mask:url(#mask-2_1_);fill:none;stroke:url(#Path-8_1_);}
9
- .st3{filter:url(#Adobe_OpacityMaskFilter_1_);}
10
- .st4{mask:url(#mask-2_2_);fill:none;stroke:url(#Path-9_1_);}
6
+ .st0{fill:none;stroke:url(#Path-8_1_);stroke-width:2;}
7
+ .st1{fill:none;stroke:url(#Path-9_1_);stroke-width:2;}
11
8
  </style>
12
9
  <title>Path 8 + Path 9 Mask</title>
13
10
  <desc>Created with Sketch.</desc>
@@ -16,38 +13,18 @@
16
13
  <g transform="translate(720.000000, 143.000000)">
17
14
  <g id="Mask">
18
15
  </g>
19
- <defs>
20
- <filter id="Adobe_OpacityMaskFilter" filterUnits="userSpaceOnUse" x="-3.5" y="47.3" width="278.5" height="654.4">
21
- <feColorMatrix type="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0"/>
22
- </filter>
23
- </defs>
24
- <mask maskUnits="userSpaceOnUse" x="-3.5" y="47.3" width="278.5" height="654.4" id="mask-2_1_">
25
- <g class="st0">
26
- <rect id="path-1_1_" class="st1" width="668" height="735"/>
27
- </g>
28
- </mask>
29
16
 
30
- <linearGradient id="Path-8_1_" gradientUnits="userSpaceOnUse" x1="-354.1977" y1="748.4078" x2="-353.0956" y2="748.4737" gradientTransform="matrix(-188.4878 -657.335 -167.9035 48.1456 59202.0664 -268195.8125)">
17
+ <linearGradient id="Path-8_1_" gradientUnits="userSpaceOnUse" x1="-276.2975" y1="-132.512" x2="-274.6546" y2="-132.6103" gradientTransform="matrix(-188.4878 -657.335 167.9035 -48.1456 -29446.4434 -187179.9844)">
31
18
  <stop offset="0" style="stop-color:#5801E3"/>
32
19
  <stop offset="1" style="stop-color:#42E59A"/>
33
20
  </linearGradient>
34
- <path id="Path-8" class="st2" d="M197.9,701.4C346.2,421.8,279.1,203.9-3.3,47.7"/>
35
- <defs>
36
- <filter id="Adobe_OpacityMaskFilter_1_" filterUnits="userSpaceOnUse" x="-3.4" y="24.1" width="659.1" height="526.6">
37
- <feColorMatrix type="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0"/>
38
- </filter>
39
- </defs>
40
- <mask maskUnits="userSpaceOnUse" x="-3.4" y="24.1" width="659.1" height="526.6" id="mask-2_2_">
41
- <g class="st3">
42
- <rect id="path-1_2_" class="st1" width="668" height="735"/>
43
- </g>
44
- </mask>
21
+ <path id="Path-8" class="st0" d="M197.9,701.4C346.2,421.8,279.1,203.9-3.3,47.7"/>
45
22
 
46
- <linearGradient id="Path-9_1_" gradientUnits="userSpaceOnUse" x1="-353.4046" y1="750.621" x2="-353.7825" y2="749.4943" gradientTransform="matrix(65.1755 -411.5021 -723.7028 -114.6233 566150.875 -59200.8633)">
23
+ <linearGradient id="Path-9_1_" gradientUnits="userSpaceOnUse" x1="-275.2401" y1="-135.0266" x2="-275.7359" y2="-133.5487" gradientTransform="matrix(65.1755 -411.5021 723.7028 114.6233 115344.25 -97625.6484)">
47
24
  <stop offset="0" style="stop-color:#5801E3"/>
48
25
  <stop offset="1" style="stop-color:#FC4646"/>
49
26
  </linearGradient>
50
- <path id="Path-9" class="st4" d="M-2.9,24.3c120.7,306.3,340.2,481.6,658.6,525.9"/>
27
+ <path id="Path-9" class="st1" d="M-2.9,24.3c120.7,306.3,340.2,481.6,658.6,525.9"/>
51
28
  </g>
52
29
  </g>
53
30
  </g>
@@ -0,0 +1,10 @@
1
+ module Gold
2
+ module Admin
3
+ # Main controller for Gold admin to be used in app
4
+ class AdminController < ApplicationController
5
+ credentials = Gold.configuration.admin_credentials
6
+ http_basic_authenticate_with name: credentials[:user],
7
+ password: credentials[:password]
8
+ end
9
+ end
10
+ end
@@ -1,11 +1,7 @@
1
1
  module Gold
2
2
  module Admin
3
3
  # Main controller for Gold to be used in app
4
- class BillingController < ApplicationController
5
- credentials = Gold.configuration.admin_credentials
6
- http_basic_authenticate_with name: credentials[:user],
7
- password: credentials[:password]
8
-
4
+ class BillingController < AdminController
9
5
  around_action :shopify_session
10
6
 
11
7
  rescue_from Statesman::TransitionFailedError,
@@ -0,0 +1,41 @@
1
+ module Gold
2
+ module Admin
3
+ class ReferralsController < AdminController
4
+ def create
5
+ referral = Referral.new(referral_params)
6
+
7
+ if referral.save
8
+ flash[:success] = "Created new referrer"
9
+ else
10
+ message = referral.errors.full_messages.join(", ")
11
+ flash[:danger] = "Failed to create, #{message}"
12
+ end
13
+
14
+ redirect_back(fallback_location: "/admin")
15
+ end
16
+
17
+ def update
18
+ referral = Referral.find(params[:id])
19
+
20
+ if referral.update(referral_params)
21
+ flash[:success] = "Update referrer"
22
+ else
23
+ message = referral.errors.full_messages.join(", ")
24
+ flash[:danger] = "Failed to update, #{message}"
25
+ end
26
+
27
+ redirect_back(fallback_location: "/admin")
28
+ end
29
+
30
+ private
31
+
32
+ def referral_params
33
+ params.require(:referral).permit(:contact_name,
34
+ :contact_email,
35
+ :company,
36
+ :code,
37
+ :discount_percentage)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -41,6 +41,19 @@ module Gold
41
41
  # Show the possible tiers to select from.
42
42
  def tier
43
43
  billing # Expose the @billing variable to the view
44
+
45
+ # Apply a referral tracking. Don't overwrite an existing code
46
+ if !billing.referral && session[:gold_referral_code]
47
+ referral = Gold::Referral.find_by(code: session[:gold_referral_code])
48
+
49
+ if referral
50
+ billing.referral = referral
51
+ billing.update(
52
+ discount_percentage: referral.discount_percentage || 0
53
+ )
54
+ end
55
+ end
56
+
44
57
  @tiers = Tier.visible
45
58
  end
46
59
 
@@ -0,0 +1,12 @@
1
+ module Gold
2
+ # Handles referral tracking
3
+ class ReferralsController < ApplicationController
4
+ def track
5
+ referral = Referral.find_by(code: params[:code])
6
+
7
+ session[:gold_referral_code] = referral.code if referral
8
+
9
+ redirect_to Gold.configuration.referral_redirect_url
10
+ end
11
+ end
12
+ end
@@ -35,6 +35,10 @@ module Gold
35
35
 
36
36
  # rubocop:disable Rails/ReflectionClassName
37
37
  belongs_to :shop, class_name: Gold.shop_class.to_s
38
+ belongs_to :referral, class_name: "Gold::Referral",
39
+ foreign_key: "gold_referral_id",
40
+ inverse_of: :billings,
41
+ optional: true
38
42
  has_many :transitions, class_name: transition_class.to_s,
39
43
  autosave: false,
40
44
  dependent: :destroy
@@ -0,0 +1,23 @@
1
+ module Gold
2
+ # A referral can be assigned to a billing record, which can be helpful for
3
+ # tracking affiliates with discount codes
4
+ class Referral < ApplicationRecord
5
+ has_many :billings, dependent: :nullify,
6
+ foreign_key: "gold_referral_id",
7
+ inverse_of: "referral"
8
+
9
+ validates :code, presence: true, uniqueness: true
10
+ validates :discount_percentage, numericality: {
11
+ greater_than_or_equal_to: 0,
12
+ less_than_or_equal_to: 100
13
+ }
14
+
15
+ before_validation :ensure_code_format
16
+
17
+ private
18
+
19
+ def ensure_code_format
20
+ self.code = code.parameterize.underscore.upcase
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+ <div class="card mb-3">
2
+ <div class="card-header">
3
+ <strong>Merchants</strong>
4
+ </div>
5
+ <div class="card-body">
6
+ <% if billings.any? %>
7
+ <table class="table celled">
8
+ <thead>
9
+ <tr>
10
+ <th>Domain</th>
11
+ <th>Sign up</th>
12
+ <th>Plan</th>
13
+ <th>Monthly price</th>
14
+ <th>Installed</th>
15
+ </tr>
16
+ </thead>
17
+ <tbody>
18
+ <% billings.each do |billing| %>
19
+ <% shop = billing.shop %>
20
+ <tr>
21
+ <td><%= shop.domain %></td>
22
+ <td><%= time_ago_in_words(shop.created_at) %> ago</td>
23
+ <td><%= billing&.tier&.id %></td>
24
+ <td>
25
+ <%= number_to_currency(shop.monthly_price / 100) %>
26
+ </td>
27
+ <td>
28
+ <% if shop.installed? %>
29
+ <span class="green">Yes</span>
30
+ <% else %>
31
+ <span class="red">No</span>
32
+ <% end %>
33
+ </td>
34
+ </tr>
35
+ <% end %>
36
+ </tbody>
37
+ </table>
38
+ <% else %>
39
+ <p>No shops</p>
40
+ <% end %>
41
+ </div>
42
+ </div>
@@ -0,0 +1,28 @@
1
+ <%= form_for(referral, url: referral.new_record? ? gold_admin_engine.referrals_path : gold_admin_engine.referral_path(referral.id)) do |f| %>
2
+ <div class="form-group">
3
+ <label>Full name</label>
4
+ <%= f.text_field :contact_name, class: "form-control" %>
5
+ </div>
6
+
7
+ <div class="form-group">
8
+ <label>Email</label>
9
+ <%= f.email_field :contact_email, class: "form-control" %>
10
+ </div>
11
+
12
+ <div class="form-group">
13
+ <label>Company</label>
14
+ <%= f.text_field :company, class: "form-control" %>
15
+ </div>
16
+
17
+ <div class="form-group">
18
+ <label>Code</label>
19
+ <%= f.text_field :code, class: "form-control" %>
20
+ </div>
21
+
22
+ <div class="form-group">
23
+ <label>Discount percentage</label>
24
+ <%= f.number_field :discount_percentage, class: "form-control", min: 0, max: 100 %>
25
+ </div>
26
+
27
+ <%= f.submit class: "btn btn-primary" %>
28
+ <% end %>
data/config/routes.rb CHANGED
@@ -16,6 +16,8 @@ Gold::Engine.routes.draw do
16
16
  get "/unavailable", to: "billing#unavailable", as: "unavailable"
17
17
 
18
18
  get "/uninstalled", to: "billing#uninstalled", as: "uninstalled"
19
+
20
+ get "/referral", to: "referrals#track", as: "referral"
19
21
  end
20
22
 
21
23
  Gold::AdminEngine.routes.draw do
@@ -30,4 +32,9 @@ Gold::AdminEngine.routes.draw do
30
32
  put '/override_shopify_plan', to: 'admin/billing#override_shopify_plan', as: 'override_shopify_plan'
31
33
  delete '/charge/:id', to: 'admin/billing#cancel_charge', as: 'cancel_charge'
32
34
  end
35
+
36
+ scope :referrals do
37
+ post "/", to: "admin/referrals#create", as: "referrals"
38
+ patch "/:id", to: "admin/referrals#update", as: "referral"
39
+ end
33
40
  end
@@ -0,0 +1,15 @@
1
+ class CreateGoldReferrals < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :gold_referrals do |t|
4
+ t.string :contact_name
5
+ t.string :contact_email
6
+ t.string :company
7
+ t.string :code, index: { unique: true }, null: false
8
+ t.integer :discount_percentage, default: 0
9
+
10
+ t.timestamps null: false
11
+ end
12
+
13
+ add_column :gold_billings, :gold_referral_id, :integer
14
+ end
15
+ end
@@ -12,7 +12,8 @@ module Gold
12
12
  :days_until_delinquent,
13
13
  :days_until_cleanup,
14
14
  :shop_domain_attribute,
15
- :force_embedded_redirect
15
+ :force_embedded_redirect,
16
+ :referral_redirect_url
16
17
 
17
18
  # Callbacks
18
19
  attr_accessor :on_terms,
@@ -67,6 +68,10 @@ module Gold
67
68
 
68
69
  # If Gold is allowed to cancel charges (paid -> free) automatically
69
70
  @allow_automated_charge_cancellation = true
71
+
72
+ # The URL to follow after a referral code is tracked
73
+ # (e.g. https://apps.shopify.com/customr)
74
+ @referral_redirect_url = "/"
70
75
  end
71
76
 
72
77
  def shop_class
data/lib/gold/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gold
2
- VERSION = "3.3.1".freeze
2
+ VERSION = "4.0.0".freeze
3
3
  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: 3.3.1
4
+ version: 4.0.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: 2019-12-11 00:00:00.000000000 Z
12
+ date: 2020-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -211,11 +211,14 @@ files:
211
211
  - app/assets/javascripts/gold/billing.js
212
212
  - app/assets/stylesheets/gold/billing.sass
213
213
  - app/assets/stylesheets/shopify/polaris.css
214
+ - app/controllers/gold/admin/admin_controller.rb
214
215
  - app/controllers/gold/admin/billing_controller.rb
216
+ - app/controllers/gold/admin/referrals_controller.rb
215
217
  - app/controllers/gold/application_controller.rb
216
218
  - app/controllers/gold/authenticated_controller.rb
217
219
  - app/controllers/gold/billing_controller.rb
218
220
  - app/controllers/gold/concerns/merchant_facing.rb
221
+ - app/controllers/gold/referrals_controller.rb
219
222
  - app/jobs/gold/after_authenticate_job.rb
220
223
  - app/jobs/gold/app_uninstalled_job.rb
221
224
  - app/jobs/gold/application_job.rb
@@ -224,6 +227,7 @@ files:
224
227
  - app/models/gold/billing.rb
225
228
  - app/models/gold/concerns/gilded.rb
226
229
  - app/models/gold/machine.rb
230
+ - app/models/gold/referral.rb
227
231
  - app/models/gold/shopify_plan.rb
228
232
  - app/models/gold/tier.rb
229
233
  - app/models/gold/transition.rb
@@ -254,6 +258,8 @@ files:
254
258
  - app/views/gold/admin/billing/_status.erb
255
259
  - app/views/gold/admin/billing/_tier.erb
256
260
  - app/views/gold/admin/billing/_trial_days.erb
261
+ - app/views/gold/admin/referrals/_billings.erb
262
+ - app/views/gold/admin/referrals/_form.erb
257
263
  - app/views/gold/billing/_inner_head.html.erb
258
264
  - app/views/gold/billing/declined_charge.html.erb
259
265
  - app/views/gold/billing/expired_charge.html.erb
@@ -276,6 +282,7 @@ files:
276
282
  - db/migrate/01_create_gold_billing.rb
277
283
  - db/migrate/02_create_gold_transitions.rb
278
284
  - db/migrate/03_add_foreign_key_to_billing.rb
285
+ - db/migrate/04_create_gold_referrals.rb
279
286
  - lib/gold.rb
280
287
  - lib/gold/admin_engine.rb
281
288
  - lib/gold/billing_migrator.rb