pay 8.1.2 → 8.1.3

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: 2c9bcfe2386dfbf2f1aef6f5f531dfee84f79e7e46e8a50bfa1189d65cf968e9
4
- data.tar.gz: 95d4b7d998ac2439ddcd8e3c174c0349aa4cb131b1477fc166948d1997ae67e5
3
+ metadata.gz: 9c203986ec600312090922863e206b2136fc040e68cdab530575aa521501563b
4
+ data.tar.gz: 9b0f5220d53a014148a3d7a58fc4c2f7fefd5b04fe92ced36c65decfabb4fd34
5
5
  SHA512:
6
- metadata.gz: e6f8ac8309e3d664980c0a6991440197b01de09d8de04c352bd20d6b3a97127fed7dad70f4511056fee585fd45c8014d1af796b75f9da21b2b8a1ef500162856
7
- data.tar.gz: 41b2c842364d6517c4fe40c253424d4a7c45f47aa0fa35dd3dfe7c5ef3f4c79cdcc2fefef53294689986264b09ad3310f3079e3dd63736dc6bf9ab7533154deb
6
+ metadata.gz: 60caf2d4f344da6c2581636ee8d03991ecf0462fb0a7e7c7c502031b733228499c58da2ff47b746401115798a760e2ca759909b9b33d76379c92fdc5168b3666
7
+ data.tar.gz: b530d41e9f0b4ff493575c3b3b74e8af07ff27557f2bf090eefee9b175862e4b05c1b6c9f9515bf38291946074841bfdfcd4e1c2cf0e093a467773a74931e7ec
@@ -95,7 +95,7 @@ module Pay
95
95
 
96
96
  def resume
97
97
  unless resumable?
98
- raise StandardError, "You can only resume subscriptions within their grace period."
98
+ raise Error, "You can only resume subscriptions within their grace period."
99
99
  end
100
100
 
101
101
  if canceled? && on_trial?
@@ -37,7 +37,7 @@ module Pay
37
37
 
38
38
  def resume
39
39
  unless resumable?
40
- raise StandardError, "You can only resume subscriptions within their grace period."
40
+ raise Error, "You can only resume subscriptions within their grace period."
41
41
  end
42
42
 
43
43
  update(status: :active, trial_ends_at: nil, ends_at: nil)
@@ -100,7 +100,7 @@ module Pay
100
100
 
101
101
  def resume
102
102
  unless resumable?
103
- raise StandardError, "You can only resume paused or cancelled subscriptions"
103
+ raise Error, "You can only resume paused or cancelled subscriptions"
104
104
  end
105
105
 
106
106
  if paused? && pause_starts_at? && Time.current < pause_starts_at
@@ -117,8 +117,8 @@ module Pay
117
117
  # Lemon Squeezy requires both the Product ID and Variant ID.
118
118
  # The Variant ID will be saved as the processor_plan
119
119
  def swap(plan, **options)
120
- raise StandardError, "A plan_id is required to swap a subscription" unless plan
121
- raise StandardError, "A variant_id is required to swap a subscription" unless options[:variant_id]
120
+ raise Error, "A plan_id is required to swap a subscription" unless plan
121
+ raise Error, "A variant_id is required to swap a subscription" unless options[:variant_id]
122
122
 
123
123
  ::LemonSqueezy::Subscription.change_plan id: processor_id, plan_id: plan, variant_id: options[:variant_id]
124
124
 
@@ -56,6 +56,14 @@ module Pay
56
56
  else
57
57
  pay_customer.charges.create!(attrs.merge(processor_id: object.id))
58
58
  end
59
+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique
60
+ try += 1
61
+ if try <= retries
62
+ sleep 0.1
63
+ retry
64
+ else
65
+ raise
66
+ end
59
67
  end
60
68
  end
61
69
  end
@@ -8,7 +8,7 @@ module Pay
8
8
  sync(pay_customer: pay_customer, attributes: transaction.payments.first)
9
9
  end
10
10
 
11
- def self.sync(pay_customer:, attributes:)
11
+ def self.sync(pay_customer:, attributes:, try: 0, retries: 1)
12
12
  details = attributes.method_details
13
13
  attrs = {
14
14
  payment_method_type: details.type.downcase
@@ -25,6 +25,14 @@ module Pay
25
25
  payment_method = pay_customer.payment_methods.find_or_initialize_by(processor_id: attributes.payment_method_id)
26
26
  payment_method.update!(attrs)
27
27
  payment_method
28
+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique
29
+ try += 1
30
+ if try <= retries
31
+ sleep 0.1
32
+ retry
33
+ else
34
+ raise
35
+ end
28
36
  end
29
37
 
30
38
  def make_default!
@@ -6,7 +6,7 @@ module Pay
6
6
  sync(transaction.subscription_id) if transaction.subscription_id
7
7
  end
8
8
 
9
- def self.sync(subscription_id, object: nil, name: Pay.default_product_name)
9
+ def self.sync(subscription_id, object: nil, name: Pay.default_product_name, try: 0, retries: 1)
10
10
  # Passthrough is not return from this API, so we can't use that
11
11
  object ||= ::Paddle::Subscription.retrieve(id: subscription_id)
12
12
 
@@ -62,6 +62,14 @@ module Pay
62
62
  else
63
63
  pay_customer.subscriptions.create!(attributes.merge(name: name, processor_id: subscription_id))
64
64
  end
65
+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique
66
+ try += 1
67
+ if try <= retries
68
+ sleep 0.1
69
+ retry
70
+ else
71
+ raise
72
+ end
65
73
  end
66
74
 
67
75
  def api_record(**options)
@@ -135,7 +143,7 @@ module Pay
135
143
 
136
144
  def resume
137
145
  unless resumable?
138
- raise StandardError, "You can only resume paused subscriptions."
146
+ raise Error, "You can only resume paused subscriptions."
139
147
  end
140
148
 
141
149
  # Paddle Billing API only allows "resuming" subscriptions when they are paused
@@ -116,7 +116,7 @@ module Pay
116
116
 
117
117
  def resume
118
118
  unless resumable?
119
- raise StandardError, "You can only resume paused subscriptions."
119
+ raise Error, "You can only resume paused subscriptions."
120
120
  end
121
121
 
122
122
  PaddleClassic.client.users.unpause(subscription_id: processor_id)
@@ -256,7 +256,7 @@ module Pay
256
256
 
257
257
  def resume
258
258
  unless resumable?
259
- raise StandardError, "You can only resume subscriptions within their grace period."
259
+ raise Error, "You can only resume subscriptions within their grace period."
260
260
  end
261
261
 
262
262
  if paused?
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "8.1.2"
2
+ VERSION = "8.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.2
4
+ version: 8.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Charnes
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-10-14 00:00:00.000000000 Z
13
+ date: 2024-10-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
182
  requirements: []
183
- rubygems_version: 3.5.16
183
+ rubygems_version: 3.5.18
184
184
  signing_key:
185
185
  specification_version: 4
186
186
  summary: Payments engine for Ruby on Rails