pay 4.1.0 → 4.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b424cae3cd4905b55f734e86687c12fba5972aeade9dc81f430d364d29bd9ea6
4
- data.tar.gz: 709ca786d171e5b5652fb1a4de5206b2564155a0adabfb02476282eefbfe473a
3
+ metadata.gz: cfd57b19e4d88a7b44ce680b18018fb9f6d623a98354d3858f10ac97ec87711a
4
+ data.tar.gz: f18db44917f38b0d97f7907fe22c46e4408afa7acea95468381bfaab58b7c66e
5
5
  SHA512:
6
- metadata.gz: d153b66802f9ffea402b973ea2420f2cbb9ae6666dfe4c81d49457ac11045c06ee2e54f2ea3410fd5a7b3452461ca580e1cf52cde6831ab9238c624862cbe831
7
- data.tar.gz: 2c22450d862a9d39d6abed5b3cc1454c657e15ab92399f64d2c306b69cf600fb2cf838d8d2080d285d42d62b0554de526a72bb7602b342eeecdeff4b49670cbd
6
+ metadata.gz: 2e34a3196a14ee151faf1ff5a6f7c69360e035f6d74374b91f2502225b3bdf93c2db05e44569a0939514b3aabb42e497a2064a9c2294d1220279d755c87da206
7
+ data.tar.gz: a20484911fb6f1e173a9f92af70ec44a7c9fad2f31b5486538079232d2cae92dc789949201fdbbe8060835c59ad91f7b4e5d1f435e5678c73d444758d2f67a90
@@ -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
- scope :active, -> { where(status: ["trialing", "active"], ends_at: nil).or(on_grace_period).or(on_trial) }
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
- paddle_paused_from.present?
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
@@ -178,6 +178,7 @@ module Pay
178
178
  end
179
179
 
180
180
  def create_setup_intent(options = {})
181
+ customer unless processor_id?
181
182
  ::Stripe::SetupIntent.create({
182
183
  customer: processor_id,
183
184
  usage: :off_session
@@ -100,7 +100,15 @@ module Pay
100
100
 
101
101
  # Common expand options for all requests that create, retrieve, or update a Stripe Subscription
102
102
  def self.expand_options
103
- {expand: ["pending_setup_intent", "latest_invoice.payment_intent", "latest_invoice.charge"]}
103
+ {
104
+ expand: [
105
+ "pending_setup_intent",
106
+ "latest_invoice.payment_intent",
107
+ "latest_invoice.charge",
108
+ "latest_invoice.total_discount_amounts.discount",
109
+ "latest_invoice.total_tax_amounts.tax_rate"
110
+ ]
111
+ }
104
112
  end
105
113
 
106
114
  def initialize(pay_subscription)
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "4.1.0"
2
+ VERSION = "4.2.1"
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: 4.1.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Charnes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-07-28 00:00:00.000000000 Z
12
+ date: 2022-08-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails