shopify-gold 2.1.0.pre → 2.1.1.pre

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: b60caa1e9a44c3ef0460d4c3e8d9f33f4457b9a550d874fc9196c1c6b79f5d9c
4
- data.tar.gz: 747ad055581e3256e19a511e18f798bd891f3cb1886f42a4593871816f5c8972
3
+ metadata.gz: be0da51bb5675160c788669b7ff9b25a27725b473eae16b12c2bd0329328d3cf
4
+ data.tar.gz: 2a93b3f89cdd593eca1f198fc630607c5531d86460f04e1fa04c986ef45f5351
5
5
  SHA512:
6
- metadata.gz: dda0880c7d55806e387a5dd701b024836abecc64dcf235590e6c902894de2d590ec58de342277eb33dda68aceddf02238a1ecb8b77316e58e3808481cbea1f8b
7
- data.tar.gz: 686cfa5a32d461053b21050e9b194c3bf0dd53c1398cd1d338d76e132182eae7342c1453c678b5101ae9c23a02003460bb3cb09439b6c8e6febed5be3704db87
6
+ metadata.gz: 7113dfe26ca0db2d14b83924c80fc0d33762fa18af524a374d81ff66aec80b6e7fe13c7c19f115c7af1d433499c300e911e56cb37dc12af005ceadf58273cd91
7
+ data.tar.gz: 85fbd823becc14c31308c38a5ff272f3a8fbe5f6db99fb57aeaf1fbb23dd9cd8210fd9be5617cf3bd965de66ab4c5d4fa86b8482f65929c4ee29bb628e964a8c
@@ -32,7 +32,9 @@ module Gold
32
32
 
33
33
  outcome = SelectTierOp.new(billing, tier).call
34
34
 
35
- if outcome.ok?
35
+ if outcome.is_a?(Outcomes::TierApplied)
36
+ flash[:success] = "Changed billing to '#{tier.name}'"
37
+ elsif outcome.ok?
36
38
  charge_outcome = ChargeOp.new(billing, process_charge_url).call
37
39
 
38
40
  if charge_outcome.is_a?(Outcomes::ActiveCharge)
@@ -115,8 +117,10 @@ module Gold
115
117
  params[:percentage].to_i,
116
118
  process_charge_url).call
117
119
 
118
- if outcome.ok?
120
+ if outcome.is_a?(Outcomes::PendingCharge)
119
121
  flash[:warning] = "Discount applied, merchant must reauthorize the charge"
122
+ elsif outcome.ok?
123
+ flash[:success] = "Discount updated, will be used for future charges"
120
124
  else
121
125
  flash[:danger] = "Failed to apply discount because '#{outcome.message}'"
122
126
  end
@@ -239,7 +239,8 @@ module Gold
239
239
  transition from: :delayed_charge_accepted, to: %i[charge_activated
240
240
  marked_as_uninstalled]
241
241
 
242
- transition from: :delayed_charge_expired, to: :delayed_charge
242
+ transition from: :delayed_charge_expired, to: %i[delayed_charge
243
+ marked_as_delinquent]
243
244
  transition from: :delayed_charge_declined, to: %i[marked_as_delinquent
244
245
  delayed_charge]
245
246
 
@@ -23,10 +23,17 @@ module Gold
23
23
 
24
24
  return SameDiscount.new if @percentage == @billing.discount_percentage
25
25
 
26
- @billing.transition_to!(:apply_discount, percentage: @percentage)
27
26
  @billing.update(discount_percentage: @percentage)
28
27
 
29
- ChargeOp.new(@billing, @return_url, @test).call
28
+ # If we can transition to apply discount, let's do that. This means we're
29
+ # in a billing state and a new charge will be created. Otherwise, it's
30
+ # OK to just set the `discount_percentage` field for future charges
31
+ if @billing.can_transition_to?(:apply_discount)
32
+ @billing.transition_to!(:apply_discount, percentage: @percentage)
33
+ ChargeOp.new(@billing, @return_url, @test).call
34
+ else
35
+ Success.new
36
+ end
30
37
  end
31
38
  end
32
39
  end
@@ -1,12 +1,11 @@
1
1
  <% billing.shop.with_shopify_session do %>
2
- <% credits = ShopifyAPI::ApplicationCredit.all %>
3
2
  <div class="card mb-3">
4
3
  <div class="card-header">
5
4
  <strong>Credit</strong>
6
5
  </div>
7
6
  <div class="card-body">
8
7
  <h6>Credits</h6>
9
- <% if credits.any? %>
8
+ <% if @credits.any? %>
10
9
  <table class="table celled">
11
10
  <thead>
12
11
  <tr>
@@ -15,7 +14,7 @@
15
14
  </tr>
16
15
  </thead>
17
16
  <tbody>
18
- <% credits.each do |credit| %>
17
+ <% @credits.each do |credit| %>
19
18
  <tr>
20
19
  <td>
21
20
  <%= credit.description %>
@@ -12,11 +12,7 @@
12
12
  value="<%= billing.discount_percentage %>">%
13
13
  <div>
14
14
  <hr>
15
- <% if billing.can_transition_to?(:apply_discount) %>
16
- <%= submit_tag 'Apply discount', class: "btn btn-primary", data: {confirm: "Are you really sure you want to apply this discount?"} %>
17
- <% else %>
18
- <p>Discount cannot be applied in the current state</p>
19
- <% end %>
15
+ <%= submit_tag 'Apply discount', class: "btn btn-primary", data: {confirm: "Are you really sure you want to apply this discount?"} %>
20
16
  </div>
21
17
  <% end %>
22
18
  </div>
data/lib/gold/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gold
2
- VERSION = "2.1.0.pre".freeze
2
+ VERSION = "2.1.1.pre".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: 2.1.0.pre
4
+ version: 2.1.1.pre
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-08-13 00:00:00.000000000 Z
12
+ date: 2019-08-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails