pay 13.4.3 → 13.4.4
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9f8f201bd891602a55599087102e17cb189758b6946da4de83d651aa2f8b499a
|
|
4
|
+
data.tar.gz: d9c4be8669fb8116285011d166fc915eaa5f6cfa6fa94bffd9f520e9fb52a078
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f1dc98e667257ab4c09392ad4d2ada2d007d7a7d927d0a617fbe6260bba0b7f8911a088b23167faec7d48782df21f80f62e00551a325591e361cf72b063b74a8
|
|
7
|
+
data.tar.gz: fe1bdb6ba6a8521aa4a50a07e700b251c82ffa2195d7b4bde6b67f20b72f8c8587af557998fc40069db3038ed6b121a1c742cf2aa574d6f673c0fcc057b30625
|
|
@@ -6,27 +6,34 @@ module Pay
|
|
|
6
6
|
# Lemon Squeezy statuses that Pay spells differently
|
|
7
7
|
STATUSES = Pay.make_shareable({"on_trial" => "trialing", "cancelled" => "canceled"})
|
|
8
8
|
|
|
9
|
+
# Lemon Squeezy keeps a cancelled subscription working until ends_at; store that grace period as active, like Stripe and Paddle
|
|
10
|
+
def self.status_for(status, ends_at)
|
|
11
|
+
status = STATUSES.fetch(status, status)
|
|
12
|
+
(status == "canceled" && ends_at&.future?) ? "active" : status
|
|
13
|
+
end
|
|
14
|
+
|
|
9
15
|
def self.sync(subscription_id, object: nil, name: Pay.default_product_name)
|
|
10
16
|
sync_with_retries do
|
|
11
17
|
subscription = object || ::LemonSqueezy::Subscription.retrieve(id: subscription_id)
|
|
12
18
|
return unless (pay_customer = find_pay_customer(subscription.customer_id))
|
|
13
19
|
|
|
20
|
+
ends_at = (subscription.ends_at ? Time.parse(subscription.ends_at) : nil)
|
|
14
21
|
attributes = {
|
|
15
22
|
current_period_end: subscription.renews_at,
|
|
16
|
-
ends_at:
|
|
23
|
+
ends_at: ends_at,
|
|
17
24
|
pause_resumes_at: (subscription.pause&.resumes_at ? Time.parse(subscription.pause.resumes_at) : nil),
|
|
18
|
-
status:
|
|
25
|
+
status: status_for(subscription.status, ends_at),
|
|
19
26
|
processor_plan: subscription.first_subscription_item.price_id,
|
|
20
27
|
quantity: subscription.first_subscription_item.quantity,
|
|
21
28
|
created_at: (subscription.created_at ? Time.parse(subscription.created_at) : nil),
|
|
22
29
|
updated_at: (subscription.updated_at ? Time.parse(subscription.updated_at) : nil)
|
|
23
30
|
}
|
|
24
31
|
|
|
25
|
-
case
|
|
26
|
-
when "
|
|
32
|
+
case subscription.status
|
|
33
|
+
when "cancelled"
|
|
27
34
|
# Remove payment methods since customer cannot be reused after cancelling
|
|
28
35
|
pay_customer.payment_methods.destroy_all
|
|
29
|
-
when "
|
|
36
|
+
when "on_trial"
|
|
30
37
|
attributes[:trial_ends_at] = Time.parse(subscription.trial_ends_at)
|
|
31
38
|
when "active", "past_due"
|
|
32
39
|
attributes[:trial_ends_at] = nil
|
|
@@ -61,7 +68,8 @@ module Pay
|
|
|
61
68
|
def cancel(**options)
|
|
62
69
|
return if canceled?
|
|
63
70
|
response = ::LemonSqueezy::Subscription.cancel(id: processor_id)
|
|
64
|
-
|
|
71
|
+
ends_at = (response.ends_at ? Time.parse(response.ends_at) : nil)
|
|
72
|
+
update(status: self.class.status_for(response.status, ends_at), ends_at: ends_at)
|
|
65
73
|
rescue ::LemonSqueezy::Error => e
|
|
66
74
|
raise Pay::LemonSqueezy::Error, e
|
|
67
75
|
end
|
|
@@ -118,6 +126,8 @@ module Pay
|
|
|
118
126
|
::LemonSqueezy::Subscription.change_plan id: processor_id, plan_id: plan, variant_id: options[:variant_id]
|
|
119
127
|
|
|
120
128
|
update(processor_plan: options[:variant_id], ends_at: nil, status: :active)
|
|
129
|
+
rescue ::LemonSqueezy::Error => e
|
|
130
|
+
raise Pay::LemonSqueezy::Error, e
|
|
121
131
|
end
|
|
122
132
|
end
|
|
123
133
|
end
|
|
@@ -170,6 +170,8 @@ module Pay
|
|
|
170
170
|
proration_billing_mode: options.delete(:proration_billing_mode) || "prorated_immediately"
|
|
171
171
|
)
|
|
172
172
|
update(processor_plan: plan, ends_at: nil, status: :active)
|
|
173
|
+
rescue ::Paddle::ErrorGenerator => e
|
|
174
|
+
raise Pay::PaddleBilling::Error, e
|
|
173
175
|
end
|
|
174
176
|
|
|
175
177
|
private
|
data/lib/pay/version.rb
CHANGED