Skip to content

Commit

Permalink
Subscription expired without any active subscriptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Nov 15, 2023
1 parent ab1aa18 commit f416852
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#### 0.2.0 (Next)

* [#16](https://github.com/slack-ruby/slack-ruby-bot-server-stripe/pull/16): Subscription expired without any active subscriptions - [@dblock](https://github.com/dblock).
* [#15](https://github.com/slack-ruby/slack-ruby-bot-server-stripe/pull/15): Fix: display past due subscriptions - [@dblock](https://github.com/dblock).
* [#14](https://github.com/slack-ruby/slack-ruby-bot-server-stripe/pull/14): Migrate to GHA - [@duffn](https://github.com/duffn).
* Your contribution here.
Expand Down
32 changes: 20 additions & 12 deletions lib/slack-ruby-bot-server-stripe/models/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ def trial_expired?

def subscription_text(options = { include_admin_info: false })
subscription_text = []
if stripe_subscriptions&.any?
if stripe_customer
subscription_text << stripe_customer_text
subscription_text.concat(stripe_customer_subscriptions_info)
if options[:include_admin_info]
subscription_text.concat(stripe_customer_invoices_info)
subscription_text.concat(stripe_customer_sources_info)
subscription_text << update_cc_text
if stripe_subscriptions&.any?
subscription_text.concat(stripe_customer_subscriptions_info)
if options[:include_admin_info]
subscription_text.concat(stripe_customer_invoices_info)
subscription_text.concat(stripe_customer_sources_info)
subscription_text << update_cc_text
end
else
subscription_text << 'No active subscriptions.'
end
elsif subscribed && subscribed_at
subscription_text << subscriber_text
Expand Down Expand Up @@ -184,12 +188,16 @@ def check_subscription!
raise Errors::NotSubscribedError unless subscribed?
raise Errors::MissingStripeCustomerError unless stripe_customer

stripe_customer.subscriptions.each do |subscription|
case subscription.status
when 'past_due'
subscription_past_due!
when 'canceled', 'unpaid'
subscription_expired!
if stripe_customer.subscriptions.none?
subscription_expired!
else
stripe_customer.subscriptions.each do |subscription|
case subscription.status
when 'past_due'
subscription_past_due!
when 'canceled', 'unpaid'
subscription_expired!
end
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/slack-ruby-bot-server-stripe/commands/subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@
expect(message: "#{SlackRubyBot.config.user} subscription", user: 'U007').to respond_with_slack_message subscription_text
end
end
context 'no active subscription' do
before do
customer.subscriptions.data = []
allow(Stripe::Customer).to receive(:retrieve).and_return(customer)
end
it 'displays subscription info' do
customer_since = Time.at(customer.created).strftime('%B %d, %Y')
subscription_text = [
"Customer since #{customer_since}.",
'No active subscriptions.'
].join("\n")
expect(message: "#{SlackRubyBot.config.user} subscription", user: 'U007').to respond_with_slack_message subscription_text
end
end
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/slack-ruby-bot-server-stripe/team_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,16 @@
team.check_subscription!
end
end
context 'with no active subscription' do
before do
team.send(:stripe_customer).subscriptions = []
end
it 'invokes' do
expect(team).to_not receive(:subscription_past_due!)
expect(team).to receive(:subscription_expired!).and_call_original
team.check_subscription!
end
end
end
end
context 'recommended text' do
Expand Down

0 comments on commit f416852

Please sign in to comment.