Skip to content

Commit de626e8

Browse files
authored
Add support for setting pause_collection (stripe-ruby-mock#936)
1 parent ef2d453 commit de626e8

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/stripe_mock/request_handlers/subscriptions.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ def update_subscription(route, method_url, params, headers)
287287
end
288288
end
289289

290+
if params[:pause_collection]
291+
subscription[:pause_collection] = { resumes_at: nil }.merge(params[:pause_collection])
292+
end
293+
290294
if params[:trial_period_days]
291295
subscription[:status] = 'trialing'
292296
end

spec/shared_stripe_examples/subscription_examples.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,35 @@
11701170
expect(sub.billing_cycle_anchor).to be_a(Integer)
11711171
end
11721172

1173+
it "accepts pause_collection with an explicit resumes_at set" do
1174+
customer = Stripe::Customer.create(source: gen_card_tk, plan: plan.id)
1175+
subscription = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id)
1176+
resumes_at = Time.now.utc.to_i + 3600
1177+
1178+
subscription.pause_collection = {
1179+
behavior: 'mark_uncollectible',
1180+
resumes_at: resumes_at
1181+
}
1182+
1183+
subscription.save
1184+
1185+
expect(subscription.pause_collection.behavior).to eq('mark_uncollectible')
1186+
expect(subscription.pause_collection.resumes_at).to eq(resumes_at)
1187+
end
11731188

1189+
it "accepts pause_collection without an explicit resumes_at set" do
1190+
customer = Stripe::Customer.create(source: gen_card_tk, plan: plan.id)
1191+
subscription = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id)
1192+
1193+
subscription.pause_collection = {
1194+
behavior: 'mark_uncollectible'
1195+
}
1196+
1197+
subscription.save
1198+
1199+
expect(subscription.pause_collection.behavior).to eq('mark_uncollectible')
1200+
expect(subscription.pause_collection.resumes_at).to be_nil
1201+
end
11741202
end
11751203

11761204
context "cancelling a subscription" do

0 commit comments

Comments
 (0)