pay 6.2.0 → 6.2.2

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: 9b9bea4dde4674321c5fcc0315db2fbd79afa882e329b6ba922aa0cc01c1a91e
4
- data.tar.gz: 0fe8b739284c825223d0ec377407ddf2f3fef5f846a5b11e57cf80ea144de2a8
3
+ metadata.gz: 10e2efeb851c80d2bb81878942929c95411fa43a781bfdfee41f3d9b99da61b4
4
+ data.tar.gz: 7080610378fd2efa259611084f41160143186ef06fb1c9d997e7d1cee72eb74d
5
5
  SHA512:
6
- metadata.gz: 54184916de0ec236cdfb4eef54ff62add646b7ddc1f4cb43fa150e5b7ef517f1a780603a63807c626ef41567522d765cce9a15390b728f98a2701e3b3ddd44ea
7
- data.tar.gz: 256c12615777ed0933b41290e7f33a52e155e9be192f034ad9e95a1ae301198e1f8c3d4ceae6568e021612981b8c32de1cae80a65a15f548bc41b68c318dd4b1
6
+ metadata.gz: 4d3032094987e54cf1834619b96064cf77335f03b2e45555de4eb059cee0c6b1e0783abb6077621fe138301dd5fe29b415a3cd4e829c63bf55493208275e0025
7
+ data.tar.gz: 6331154cae0f9f1c99a63b57c92e0b82e9197247ead694e9854a081eea19a2ff2859eef07d839b10b1d7204c00e42694ffce25e3f4f54f1e984e9f333dadc96e
@@ -11,7 +11,7 @@ module Pay
11
11
  scope :on_trial, -> { where.not(trial_ends_at: nil).where("#{table_name}.trial_ends_at > ?", Time.current) }
12
12
  scope :cancelled, -> { where.not(ends_at: nil) }
13
13
  scope :on_grace_period, -> { cancelled.where("#{table_name}.ends_at > ?", Time.current) }
14
- scope :active, -> { where(status: ["trialing", "active"], ends_at: nil).pause_not_started.or(on_grace_period).or(on_trial) }
14
+ scope :active, -> { where(status: ["trialing", "active", "canceled"], ends_at: nil).pause_not_started.or(on_grace_period).or(on_trial) }
15
15
  scope :paused, -> { where(status: "paused").or(where("pause_starts_at <= ?", Time.current)) }
16
16
  scope :pause_not_started, -> { where("pause_starts_at IS NULL OR pause_starts_at > ?", Time.current) }
17
17
  scope :active_or_paused, -> { active.or(paused) }
@@ -98,6 +98,10 @@ module Pay
98
98
  canceled?
99
99
  end
100
100
 
101
+ def ended?
102
+ ends_at? && Time.current.after?(ends_at)
103
+ end
104
+
101
105
  def on_grace_period?
102
106
  (ends_at? && Time.current < ends_at) ||
103
107
  ((status == "paused" || pause_behavior == "void") && will_pause?)
@@ -108,11 +112,19 @@ module Pay
108
112
  end
109
113
 
110
114
  def pause_active?
111
- (status == "paused" || pause_behavior == "void") && (pause_starts_at.nil? || pause_starts_at >= Time.current)
115
+ if status == "paused" # Paddle
116
+ true
117
+ elsif pause_behavior == "void"
118
+ pause_starts_at.nil? || Time.current.after?(pause_starts_at)
119
+ end
112
120
  end
113
121
 
122
+ # If you cancel during a trial, you should still retain access until the end of the trial
123
+ # Otherwise a subscription is active unless it has ended or is currently paused
124
+ # Check the subscription status so we don't accidentally consider "incomplete", "past_due", or other statuses as active
114
125
  def active?
115
- ["trialing", "active"].include?(status) && (!(canceled? || paused?) || on_trial? || on_grace_period?)
126
+ ["trialing", "active", "canceled"].include?(status) &&
127
+ (!(canceled? || paused?) || on_trial? || on_grace_period?)
116
128
  end
117
129
 
118
130
  def past_due?
@@ -32,12 +32,20 @@ module Pay
32
32
  created_at: object.created_at,
33
33
  current_period_end: object.billing_period_end_date,
34
34
  current_period_start: object.billing_period_start_date,
35
- ends_at: (object.updated_at if object.status == "Canceled"),
36
35
  processor_plan: object.plan_id,
37
36
  status: object.status.underscore,
38
37
  trial_ends_at: (object.created_at + object.trial_duration.send(object.trial_duration_unit) if object.trial_period)
39
38
  }
40
39
 
40
+ # Canceled subscriptions should have access through the paid_through_date or updated_at
41
+ if object.status == "Canceled"
42
+ attributes[:ends_at] = object.updated_at
43
+
44
+ # Set grace period for subscriptions that are marked to be canceled
45
+ elsif object.status == "Active" && object.number_of_billing_cycles
46
+ attributes[:ends_at] = object.paid_through_date.end_of_day
47
+ end
48
+
41
49
  pay_subscription = pay_customer.subscriptions.find_by(processor_id: object.id)
42
50
  if pay_subscription
43
51
  pay_subscription.with_lock { pay_subscription.update!(attributes) }
@@ -66,29 +74,21 @@ module Pay
66
74
  end
67
75
 
68
76
  def cancel(**options)
69
- subscription = processor_subscription
70
-
71
- if on_trial?
72
- gateway.subscription.cancel(processor_subscription.id)
73
- pay_subscription.update(status: :canceled, ends_at: trial_ends_at)
77
+ result = if on_trial?
78
+ gateway.subscription.cancel(processor_id)
74
79
  else
75
80
  gateway.subscription.update(subscription.id, {
76
81
  number_of_billing_cycles: subscription.current_billing_cycle
77
82
  })
78
- pay_subscription.update(status: :canceled, ends_at: subscription.billing_period_end_date.to_date)
79
83
  end
84
+ pay_subscription.sync!(object: result.subscription)
80
85
  rescue ::Braintree::BraintreeError => e
81
86
  raise Pay::Braintree::Error, e
82
87
  end
83
88
 
84
89
  def cancel_now!(**options)
85
- gateway.subscription.cancel(processor_subscription.id)
86
- ends_at = Time.current
87
- pay_subscription.update!(
88
- status: :canceled,
89
- trial_ends_at: (ends_at if pay_subscription.trial_ends_at?),
90
- ends_at: ends_at
91
- )
90
+ result = gateway.subscription.cancel(processor_id)
91
+ pay_subscription.sync!(object: result.subscription)
92
92
  rescue ::Braintree::BraintreeError => e
93
93
  raise Pay::Braintree::Error, e
94
94
  end
@@ -97,10 +97,6 @@ module Pay
97
97
  raise NotImplementedError, "Braintree does not support setting quantity on subscriptions"
98
98
  end
99
99
 
100
- def on_grace_period?
101
- canceled? && Time.current < ends_at
102
- end
103
-
104
100
  def paused?
105
101
  false
106
102
  end
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "6.2.0"
2
+ VERSION = "6.2.2"
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: 6.2.0
4
+ version: 6.2.2
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-12-23 00:00:00.000000000 Z
12
+ date: 2023-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -220,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  - !ruby/object:Gem::Version
221
221
  version: '0'
222
222
  requirements: []
223
- rubygems_version: 3.3.7
223
+ rubygems_version: 3.3.26
224
224
  signing_key:
225
225
  specification_version: 4
226
226
  summary: Payments engine for Ruby on Rails