pay 4.1.1 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of pay might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/models/pay/subscription.rb +16 -2
- data/lib/pay/paddle/subscription.rb +2 -2
- data/lib/pay/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21dbf64c59853ff5226ba4896f3d25c29625182637cc4ac43f9eaffb60433ec7
|
4
|
+
data.tar.gz: e0cd4bfa462306aa0ddf15244a2d536c36a97e45b2d4acb2564cee9c8143351b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3b007b3190cb534dec8953486a21fca0b9fe82d26a1caa80dc27a405f835bbb8424c034508e8adc5f36ce3d9ae526a4334d1a5a315b43ebba472dc60f0772f1
|
7
|
+
data.tar.gz: 0f0390f51f53fad304ceb5866d1f68a3a5af7272ce33403c27b0362e916d0ad20de756f77a3375f466ec8866d0d2a97e006a15c6dd3f18ac221fb4fc10d3f467
|
@@ -11,7 +11,9 @@ module Pay
|
|
11
11
|
scope :on_trial, -> { where.not(trial_ends_at: nil).where("#{table_name}.trial_ends_at > ?", Time.zone.now) }
|
12
12
|
scope :cancelled, -> { where.not(ends_at: nil) }
|
13
13
|
scope :on_grace_period, -> { cancelled.where("#{table_name}.ends_at > ?", Time.zone.now) }
|
14
|
-
|
14
|
+
# Stripe considers paused subscriptions to be active, therefore we reflect that in this scope and
|
15
|
+
# make it consistent across all processors
|
16
|
+
scope :active, -> { where(status: ["trialing", "active", "paused"], ends_at: nil).or(on_grace_period).or(on_trial) }
|
15
17
|
scope :incomplete, -> { where(status: :incomplete) }
|
16
18
|
scope :past_due, -> { where(status: :past_due) }
|
17
19
|
scope :with_active_customer, -> { joins(:customer).merge(Customer.active) }
|
@@ -49,6 +51,18 @@ module Pay
|
|
49
51
|
scope processor_name, -> { joins(:customer).where(pay_customers: {processor: processor_name}) }
|
50
52
|
end
|
51
53
|
|
54
|
+
def self.active_without_paused
|
55
|
+
case Pay::Adapter.current_adapter
|
56
|
+
when "postgresql", "postgis"
|
57
|
+
active.where("data->>'pause_behavior' IS NULL AND status != 'paused'")
|
58
|
+
when "mysql2"
|
59
|
+
active.where("data->>'$.pause_behavior' IS NULL AND status != 'paused'")
|
60
|
+
when "sqlite3"
|
61
|
+
# sqlite 3.38 supports ->> syntax, however, sqlite 3.37 is what ships with Ubuntu 22.04.
|
62
|
+
active.where("json_extract(data, '$.pause_behavior') IS NULL AND status != 'paused'")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
52
66
|
def self.with_metered_items
|
53
67
|
case Pay::Adapter.current_adapter
|
54
68
|
when "sqlite3"
|
@@ -108,7 +122,7 @@ module Pay
|
|
108
122
|
end
|
109
123
|
|
110
124
|
def active?
|
111
|
-
["trialing", "active"].include?(status) && (ends_at.nil? || on_grace_period? || on_trial?)
|
125
|
+
["trialing", "active", "paused"].include?(status) && (ends_at.nil? || on_grace_period? || on_trial?)
|
112
126
|
end
|
113
127
|
|
114
128
|
def past_due?
|
@@ -107,13 +107,13 @@ module Pay
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def paused?
|
110
|
-
|
110
|
+
pay_subscription.status == "paused"
|
111
111
|
end
|
112
112
|
|
113
113
|
def pause
|
114
114
|
attributes = {pause: true}
|
115
115
|
response = PaddlePay::Subscription::User.update(processor_id, attributes)
|
116
|
-
pay_subscription.update(paddle_paused_from: Time.zone.parse(response.dig(:next_payment, :date)))
|
116
|
+
pay_subscription.update(status: :paused, paddle_paused_from: Time.zone.parse(response.dig(:next_payment, :date)))
|
117
117
|
rescue ::PaddlePay::PaddlePayError => e
|
118
118
|
raise Pay::Paddle::Error, e
|
119
119
|
end
|
data/lib/pay/version.rb
CHANGED