Skip to content

Commit

Permalink
Raise Pay::Error instead of StandardError
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Oct 29, 2024
1 parent 3f8a1f0 commit 2579d2c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/models/pay/braintree/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def resumable?

def resume
unless resumable?
raise StandardError, "You can only resume subscriptions within their grace period."
raise Error, "You can only resume subscriptions within their grace period."
end

if canceled? && on_trial?
Expand Down
2 changes: 1 addition & 1 deletion app/models/pay/fake_processor/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def resumable?

def resume
unless resumable?
raise StandardError, "You can only resume subscriptions within their grace period."
raise Error, "You can only resume subscriptions within their grace period."
end

update(status: :active, trial_ends_at: nil, ends_at: nil)
Expand Down
6 changes: 3 additions & 3 deletions app/models/pay/lemon_squeezy/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def resumable?

def resume
unless resumable?
raise StandardError, "You can only resume paused or cancelled subscriptions"
raise Error, "You can only resume paused or cancelled subscriptions"
end

if paused? && pause_starts_at? && Time.current < pause_starts_at
Expand All @@ -117,8 +117,8 @@ def resume
# Lemon Squeezy requires both the Product ID and Variant ID.
# The Variant ID will be saved as the processor_plan
def swap(plan, **options)
raise StandardError, "A plan_id is required to swap a subscription" unless plan
raise StandardError, "A variant_id is required to swap a subscription" unless options[:variant_id]
raise Error, "A plan_id is required to swap a subscription" unless plan
raise Error, "A variant_id is required to swap a subscription" unless options[:variant_id]

::LemonSqueezy::Subscription.change_plan id: processor_id, plan_id: plan, variant_id: options[:variant_id]

Expand Down
2 changes: 1 addition & 1 deletion app/models/pay/paddle_billing/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def resumable?

def resume
unless resumable?
raise StandardError, "You can only resume paused subscriptions."
raise Error, "You can only resume paused subscriptions."
end

# Paddle Billing API only allows "resuming" subscriptions when they are paused
Expand Down
2 changes: 1 addition & 1 deletion app/models/pay/paddle_classic/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def resumable?

def resume
unless resumable?
raise StandardError, "You can only resume paused subscriptions."
raise Error, "You can only resume paused subscriptions."
end

PaddleClassic.client.users.unpause(subscription_id: processor_id)
Expand Down
2 changes: 1 addition & 1 deletion app/models/pay/stripe/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def resumable?

def resume
unless resumable?
raise StandardError, "You can only resume subscriptions within their grace period."
raise Error, "You can only resume subscriptions within their grace period."
end

if paused?
Expand Down
9 changes: 9 additions & 0 deletions test/pay/stripe/subscription_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ class Pay::Stripe::SubscriptionTest < ActiveSupport::TestCase
end
end

test "it will throw an error if subscription cannot be resumed" do
Pay::Stripe::Subscription.sync("123", object: fake_stripe_subscription)

refute @pay_customer.subscription.resumable?
assert_raises Pay::Error do
@pay_customer.subscription.resume
end
end

test "syncing multiple subscription items" do
pay_subscription = Pay::Stripe::Subscription.sync("123", object: fake_stripe_subscription(items: {
object: "list",
Expand Down

0 comments on commit 2579d2c

Please sign in to comment.