pay 8.1.2 → 8.2.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: 2c9bcfe2386dfbf2f1aef6f5f531dfee84f79e7e46e8a50bfa1189d65cf968e9
4
- data.tar.gz: 95d4b7d998ac2439ddcd8e3c174c0349aa4cb131b1477fc166948d1997ae67e5
3
+ metadata.gz: 508c9227734d74f5b2bc54796fa176fb712d7028ac6a81eeeff6c3366b271190
4
+ data.tar.gz: f21dc281d1ab89d2bb11c77b41ebefeed886b193d98551b751a881faaf6b8733
5
5
  SHA512:
6
- metadata.gz: e6f8ac8309e3d664980c0a6991440197b01de09d8de04c352bd20d6b3a97127fed7dad70f4511056fee585fd45c8014d1af796b75f9da21b2b8a1ef500162856
7
- data.tar.gz: 41b2c842364d6517c4fe40c253424d4a7c45f47aa0fa35dd3dfe7c5ef3f4c79cdcc2fefef53294689986264b09ad3310f3079e3dd63736dc6bf9ab7533154deb
6
+ metadata.gz: 1ab54cc78bb095352008d705439e86081e2f8348e253ec610e04d39cbefb305a8e93999fc112379ad8ef0c614e3fe7e658532510bae92b6b405c195ddd65d154
7
+ data.tar.gz: 9908d0317fda0cd3c0f849fb43ef529c57b742442faa1278ac0ea9bd1c1aa326845acb009f87269ecaa3841c1ef53e686de1052b3909e55b98b379aa8a264eab
@@ -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?
@@ -32,12 +32,16 @@ module Pay
32
32
  end
33
33
 
34
34
  def resumable?
35
- on_grace_period? || paused?
35
+ if data&.has_key?("resumable")
36
+ data["resumable"]
37
+ else
38
+ on_grace_period? || paused?
39
+ end
36
40
  end
37
41
 
38
42
  def resume
39
43
  unless resumable?
40
- raise StandardError, "You can only resume subscriptions within their grace period."
44
+ raise Error, "You can only resume subscriptions within their grace period."
41
45
  end
42
46
 
43
47
  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)
@@ -91,7 +99,7 @@ module Pay
91
99
  end
92
100
 
93
101
  def cancel_now!(**options)
94
- cancel(options.merge(effective_from: "immediately"))
102
+ cancel(**options.merge(effective_from: "immediately"))
95
103
  rescue ::Paddle::Error => e
96
104
  raise Pay::PaddleBilling::Error, e
97
105
  end
@@ -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.2.0"
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.2.0
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-11-19 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.23
184
184
  signing_key:
185
185
  specification_version: 4
186
186
  summary: Payments engine for Ruby on Rails