pay 6.2.1 → 6.2.3

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: 9d8242bdc260e76f9e9c077f041ee09da8fded112a04fc89f2974976b92e7406
4
- data.tar.gz: 87b7f3b72d0b2b1340a4403405ad3b64139e93e524d73ed5335e3e6ad3a67778
3
+ metadata.gz: 38b66c0598271a99f2293bf71a7c44e8877a98d45e06540597ae81c3de9e2d53
4
+ data.tar.gz: c95b9e20ad640bc614fb293f708034e4ca4339868abf89def91eb245ce3c3f21
5
5
  SHA512:
6
- metadata.gz: ea09e83ce4431f9653b9c3d97a5cb2dbdde7e19cc2d38bd6e074ad01519e5d3c4ecdd1eabfbb985e05981c7d706f8ba37e5563901cf93693f9da0f0ef4afba68
7
- data.tar.gz: 9f3500262f3bc1686f0620f7b10e69b562fb983113cd9c6213a1b75868d72b2c6aa1da27b4f15dda3a964e028d892c3e66daef029816860c79c7a2fd8863759a
6
+ metadata.gz: 8b72f9b22b361d10f9693009f48395474f3b93b46e9031faaa3e109eeb16f2a3e2645cd54084d948f04a5d249cc07568b351ad40e25cb3a2b23c4a82a44c0a60
7
+ data.tar.gz: 0a2135703836be6edfcd5994035d8c7b57d866365b381b66646b03347134b3a87b8506aa19981966124611aaf2cf2b6889c9f3fad415a7344737a28097dcc77c
@@ -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?
@@ -6,7 +6,7 @@ module Pay
6
6
  delegate :customer, :processor_id, to: :pay_payment_method
7
7
 
8
8
  def self.sync(id, object: nil, try: 0, retries: 1)
9
- object ||= gateway.payment_method.find(id)
9
+ object ||= Pay.braintree_gateway.payment_method.find(id)
10
10
 
11
11
  pay_customer = Pay::Customer.find_by(processor: :braintree, processor_id: object.customer_id)
12
12
  return unless pay_customer
@@ -37,10 +37,13 @@ module Pay
37
37
  trial_ends_at: (object.created_at + object.trial_duration.send(object.trial_duration_unit) if object.trial_period)
38
38
  }
39
39
 
40
- # Set ends at to paid through date
41
- # On trial, paid through date is nil, so fallback to updated_at
40
+ # Canceled subscriptions should have access through the paid_through_date or updated_at
42
41
  if object.status == "Canceled"
43
- attributes[:ends_at] = object.paid_through_date&.end_of_day || object.updated_at
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
44
47
  end
45
48
 
46
49
  pay_subscription = pay_customer.subscriptions.find_by(processor_id: object.id)
@@ -71,29 +74,21 @@ module Pay
71
74
  end
72
75
 
73
76
  def cancel(**options)
74
- subscription = processor_subscription
75
-
76
- if on_trial?
77
- gateway.subscription.cancel(processor_subscription.id)
78
- pay_subscription.update(status: :canceled, ends_at: trial_ends_at)
77
+ result = if on_trial?
78
+ gateway.subscription.cancel(processor_id)
79
79
  else
80
80
  gateway.subscription.update(subscription.id, {
81
81
  number_of_billing_cycles: subscription.current_billing_cycle
82
82
  })
83
- pay_subscription.update(status: :canceled, ends_at: subscription.billing_period_end_date.to_date)
84
83
  end
84
+ pay_subscription.sync!(object: result.subscription)
85
85
  rescue ::Braintree::BraintreeError => e
86
86
  raise Pay::Braintree::Error, e
87
87
  end
88
88
 
89
89
  def cancel_now!(**options)
90
- gateway.subscription.cancel(processor_subscription.id)
91
- ends_at = Time.current
92
- pay_subscription.update!(
93
- status: :canceled,
94
- trial_ends_at: (ends_at if pay_subscription.trial_ends_at?),
95
- ends_at: ends_at
96
- )
90
+ result = gateway.subscription.cancel(processor_id)
91
+ pay_subscription.sync!(object: result.subscription)
97
92
  rescue ::Braintree::BraintreeError => e
98
93
  raise Pay::Braintree::Error, e
99
94
  end
@@ -102,10 +97,6 @@ module Pay
102
97
  raise NotImplementedError, "Braintree does not support setting quantity on subscriptions"
103
98
  end
104
99
 
105
- def on_grace_period?
106
- canceled? && Time.current < ends_at
107
- end
108
-
109
100
  def paused?
110
101
  false
111
102
  end
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "6.2.1"
2
+ VERSION = "6.2.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: 6.2.1
4
+ version: 6.2.3
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: 2023-01-04 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