Skip to content

Commit

Permalink
Validate Stripe subscription is paused and resumed successfully. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed May 29, 2024
1 parent 474229e commit 21a0749
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 143 deletions.
4 changes: 4 additions & 0 deletions lib/pay/stripe/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def paused?
#
# pause_behavior of `void` is considered active until the end of the current period and not active after that. The current_period_end is stored as `pause_starts_at`
# Other pause_behaviors do not set `pause_starts_at` because they are used for offering free services
#
# https://docs.stripe.com/billing/subscriptions/pause-payment
def pause(**options)
attributes = {pause_collection: options.reverse_merge(behavior: "void")}
@stripe_subscription = ::Stripe::Subscription.update(processor_id, attributes.merge(expand_options), stripe_options)
Expand All @@ -273,6 +275,8 @@ def pause(**options)
end

# Unpauses a subscription
#
# https://docs.stripe.com/billing/subscriptions/pause-payment#unpausing
def unpause
@stripe_subscription = ::Stripe::Subscription.update(processor_id, {pause_collection: ""}.merge(expand_options), stripe_options)
pay_subscription.update(
Expand Down
8 changes: 6 additions & 2 deletions test/pay/stripe/billable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,20 @@ class Pay::Stripe::BillableTest < ActiveSupport::TestCase
@pay_subscription = @pay_customer.subscribe(name: "default", plan: "small-monthly")

@pay_subscription.pause(behavior: "void", resumes_at: 1.month.from_now.to_i)

assert @pay_subscription.paused?
assert_equal "void", @pay_subscription.pause_behavior
assert @pay_subscription.pause_resumes_at > 21.days.from_now

@pay_subscription.resume
# Ensure Stripe record is paused
assert_equal "void", @pay_subscription.processor_subscription.pause_collection.behavior

@pay_subscription.resume
refute @pay_subscription.paused?
assert_nil @pay_subscription.pause_behavior
assert_nil @pay_subscription.pause_resumes_at

# Ensure Stripe record is unpaused
assert_nil @pay_subscription.processor_subscription.pause_collection
end
end

Expand Down
Loading

0 comments on commit 21a0749

Please sign in to comment.