shopify-gold 3.1.0 → 3.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: a1a04a46085510f9e78a365b0febc70394fae810d130d6ed4fcbc33add97ae7a
4
- data.tar.gz: f3e0329c1a333700ab7bd44fa85dc34323ff446947d6a73928fbaa0519868afa
3
+ metadata.gz: e78293868f6e71725d206a8702fa7a21b464a4e064b92e66b071438b167bea14
4
+ data.tar.gz: 11b2059ff87e7cb99ad4773f72b1558da33f90e2208272c11ab53fe0219fc894
5
5
  SHA512:
6
- metadata.gz: e93d381fb0fcfc778334acf3ebbfe6c39a7106510e558afc6ad929ec6c731e5c5cd861cad1cf52acab2460539424b1ef4b2600f7e36fbc1183dbaed940dd12cb
7
- data.tar.gz: 580b47448d8e229aa0bd63a15f2522771cb5b82a7438aa3630316a9416abdfefc3407ff59962c5306dc74c616eebb3b6b3980ea4fb29148c93a0b5f795ea5adb
6
+ metadata.gz: d6c36f6b7843d26a206f3136b3fc15cd0e858fa4eccd8c60ca6b8c360da3796dcee0491098a91824704d7e1eff426267e341cf071ae25b92189ccf3d9bf985b3
7
+ data.tar.gz: 3e792f82164acc2c22926eab91a8b59d924edb1b69944fc70ad07dbaeaad03cb80015408cab17b98e6482220a1d2e3d884533d9feb0b523827ef85994034eab8
@@ -15,35 +15,38 @@ module Gold
15
15
  return TierNotFound.new(e.message)
16
16
  end
17
17
 
18
- unless %i[apply_tier apply_free_tier].include?(@billing.current_state)
19
- if tier.free?
20
- @billing.transition_to!(:apply_free_tier, tier_id: tier.id)
21
- elsif @billing.shopify_plan.paying?
22
- @billing.transition_to!(:apply_tier, tier_id: tier.id)
18
+ @billing.transaction do
19
+ unless %i[apply_tier apply_free_tier].include?(@billing.current_state)
20
+ if tier.free?
21
+ @billing.transition_to!(:apply_free_tier, tier_id: tier.id)
22
+ elsif @billing.shopify_plan.paying?
23
+ @billing.transition_to!(:apply_tier, tier_id: tier.id)
24
+ end
23
25
  end
24
- end
25
26
 
26
- @billing.tier = tier
27
- @billing.save!
28
-
29
- if tier.free?
30
- if Gold.configuration.allow_automated_charge_cancellation
31
- # Remove any outstanding active charges
32
- if (charge = ShopifyAPI::RecurringApplicationCharge.current)
33
- request_with_retries do
34
- Gold.logger.info("[#{@billing.id}] Free tier applied, canceling " \
35
- "charge '#{charge.price}' for " \
36
- "'#{@billing.shop.shopify_domain}'")
37
- charge.cancel
27
+ @billing.tier = tier
28
+ @billing.save!
29
+
30
+ if tier.free?
31
+ if Gold.configuration.allow_automated_charge_cancellation
32
+ # Remove any outstanding active charges
33
+ if (charge = ShopifyAPI::RecurringApplicationCharge.current)
34
+ request_with_retries do
35
+ Gold.logger.info("[#{@billing.id}] Free tier applied, canceling " \
36
+ "charge '#{charge.price}' for " \
37
+ "'#{@billing.shop.shopify_domain}'")
38
+ charge.cancel
39
+ end
38
40
  end
41
+ else
42
+ Gold.logger.info("[#{@billing.id}] Would have cancelled charge for " \
43
+ "'#{@billing.shop.shopify_domain}', but prevented by setting")
39
44
  end
40
- else
41
- Gold.logger.info("[#{@billing.id}] Would have cancelled charge for " \
42
- "'#{@billing.shop.shopify_domain}', but prevented by setting")
43
45
  end
46
+
47
+ @billing.transition_to!(billing_state)
44
48
  end
45
49
 
46
- @billing.transition_to!(billing_state)
47
50
  Gold.configuration.on_apply_tier&.call(@billing, tier.id)
48
51
  TierApplied.new
49
52
  end
@@ -34,18 +34,18 @@ module Gold
34
34
 
35
35
  # Mark the beginning of the trial if it hasn't been set already
36
36
  @billing.update(trial_starts_at: Time.current) unless @billing.trial_starts_at
37
+ end
37
38
 
38
- # Process the tier selection, creating charges if necessary
39
- if @billing.shopify_plan.affiliate? ||
40
- @billing.shopify_plan.staff? ||
41
- @tier.free?
39
+ # Process the tier selection, creating charges if necessary
40
+ if @billing.shopify_plan.affiliate? ||
41
+ @billing.shopify_plan.staff? ||
42
+ @tier.free?
42
43
 
43
- # If the shop doesn't need a charge, apply the tier
44
- return ApplyTierOp.new(@billing).call
45
- else
46
- # A valid charge is necessary before applying the new tier
47
- return ChargeNeeded.new
48
- end
44
+ # If the shop doesn't need a charge, apply the tier
45
+ return ApplyTierOp.new(@billing).call
46
+ else
47
+ # A valid charge is necessary before applying the new tier
48
+ return ChargeNeeded.new
49
49
  end
50
50
  end
51
51
  end
data/lib/gold/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gold
2
- VERSION = "3.1.0".freeze
2
+ VERSION = "3.1.1".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.1.0
4
+ version: 3.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: 2019-09-25 00:00:00.000000000 Z
12
+ date: 2019-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails