pay 8.1.1 → 8.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b493128b8cda84a754699e14ae59d19c88948998591ba8e52494c201c4af12ad
4
- data.tar.gz: 85cdd057383abbd32ae348f0f05951f93a77dabf3221c220bdd6fa415fbf7c9f
3
+ metadata.gz: 9c203986ec600312090922863e206b2136fc040e68cdab530575aa521501563b
4
+ data.tar.gz: 9b0f5220d53a014148a3d7a58fc4c2f7fefd5b04fe92ced36c65decfabb4fd34
5
5
  SHA512:
6
- metadata.gz: 56b5fdcb946e5f951a6169e61f954abcdb8a1f3e56bfbd0627752660305ec6ebe143837d014a8c6113e377a17ad46185232b0d0f18c0e81014b73271caafee36
7
- data.tar.gz: 3e3c5a3ae2664590ffa99a09c6e3ffbd9a622a0972509509cb020e78491e0993346801c0918f59978f4ebf241723e743beb99dd273ac29c11b06f6da61c1bfa2
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)
@@ -9,7 +9,7 @@ module Pay
9
9
 
10
10
  attributes = {
11
11
  current_period_end: object.renews_at,
12
- ends_at: (object.ends_at ? Time.parse(object..ends_at) : nil),
12
+ ends_at: (object.ends_at ? Time.parse(object.ends_at) : nil),
13
13
  pause_starts_at: (object.pause&.resumes_at ? Time.parse(object.pause.resumes_at) : nil),
14
14
  status: object.status,
15
15
  processor_plan: object.first_subscription_item.price_id,
@@ -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
@@ -24,7 +24,7 @@ module Pay
24
24
  pc
25
25
  else
26
26
  pc = ::Paddle::Customer.create(email: email, name: customer_name)
27
- update!(processor_id: sc.id)
27
+ update!(processor_id: pc.id)
28
28
  pc
29
29
  end
30
30
  rescue ::Paddle::Error => e
@@ -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)
@@ -102,7 +110,11 @@ module Pay
102
110
  quantity: quantity
103
111
  }]
104
112
 
105
- ::Paddle::Subscription.update(id: processor_id, items: items, proration_billing_mode: "prorated_immediately")
113
+ ::Paddle::Subscription.update(
114
+ id: processor_id,
115
+ items: items,
116
+ proration_billing_mode: options.delete(:proration_billing_mode) || "prorated_immediately"
117
+ )
106
118
  update(quantity: quantity)
107
119
  rescue ::Paddle::Error => e
108
120
  raise Pay::PaddleBilling::Error, e
@@ -131,7 +143,7 @@ module Pay
131
143
 
132
144
  def resume
133
145
  unless resumable?
134
- raise StandardError, "You can only resume paused subscriptions."
146
+ raise Error, "You can only resume paused subscriptions."
135
147
  end
136
148
 
137
149
  # Paddle Billing API only allows "resuming" subscriptions when they are paused
@@ -148,12 +160,18 @@ module Pay
148
160
  end
149
161
 
150
162
  def swap(plan, **options)
163
+ raise ArgumentError, "plan must be a string" unless plan.is_a?(String)
164
+
151
165
  items = [{
152
166
  price_id: plan,
153
167
  quantity: quantity || 1
154
168
  }]
155
169
 
156
- ::Paddle::Subscription.update(id: processor_id, items: items, proration_billing_mode: "prorated_immediately")
170
+ ::Paddle::Subscription.update(
171
+ id: processor_id,
172
+ items: items,
173
+ proration_billing_mode: options.delete(:proration_billing_mode) || "prorated_immediately"
174
+ )
157
175
  update(processor_plan: plan, ends_at: nil, status: :active)
158
176
  end
159
177
 
@@ -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.1"
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.1
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-04 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