Skip to content

Commit

Permalink
Fix: display info from past due subscriptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Aug 7, 2023
1 parent 5165883 commit 182511b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion slack-gamebot/commands/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Subscription < SlackRubyBot::Commands::Base
user = ::User.find_create_or_update_by_slack_id!(client, data.user)
team = ::Team.find(client.owner.id)
subscription_info = []
if team.active_stripe_subscription?
if team.stripe_subcriptions&.any?
subscription_info << team.stripe_customer_text
subscription_info.concat(team.stripe_customer_subscriptions_info)
if user.captain?
Expand Down
18 changes: 14 additions & 4 deletions slack-gamebot/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,24 @@ def subscriber_text
"Subscriber since #{subscribed_at.strftime('%B %d, %Y')}."
end

def stripe_subcriptions
return unless stripe_customer

stripe_customer.subscriptions
end

def stripe_customer_subscriptions_info(with_unsubscribe = false)
stripe_customer.subscriptions.map do |subscription|
amount = ActiveSupport::NumberHelper.number_to_currency(subscription.plan.amount.to_f / 100)
current_period_end = Time.at(subscription.current_period_end).strftime('%B %d, %Y')
[
"Subscribed to #{subscription.plan.name} (#{amount}), will#{subscription.cancel_at_period_end ? ' not' : ''} auto-renew on #{current_period_end}.",
!subscription.cancel_at_period_end && with_unsubscribe ? "Send `unsubscribe #{subscription.id}` to unsubscribe." : nil
].compact.join("\n")
if subscription.status == 'active'
[
"Subscribed to #{subscription.plan.name} (#{amount}), will#{subscription.cancel_at_period_end ? ' not' : ''} auto-renew on #{current_period_end}.",
!subscription.cancel_at_period_end && with_unsubscribe ? "Send `unsubscribe #{subscription.id}` to unsubscribe." : nil
].compact.join("\n")
else
"#{subscription.status.titleize} subscription created #{Time.at(subscription.created).strftime('%B %d, %Y')} to #{subscription.plan.name} (#{amount})."
end
end
end

Expand Down
14 changes: 14 additions & 0 deletions spec/slack-gamebot/commands/subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@
].join("\n")
expect(message: "#{SlackRubyBot.config.user} subscription").to respond_with_slack_message customer_info
end
context 'past due subscription' do
before do
customer.subscriptions.data.first['status'] = 'past_due'
allow(Stripe::Customer).to receive(:retrieve).and_return(customer)
end
it 'displays subscription info' do
customer_info = "Customer since #{Time.at(customer.created).strftime('%B %d, %Y')}."
customer_info += "\nPast Due subscription created November 03, 2016 to Plan ($29.99)."
card = customer.sources.first
customer_info += "\nOn file Visa card, #{card.name} ending with #{card.last4}, expires #{card.exp_month}/#{card.exp_year}."
customer_info += "\n#{team.update_cc_text}"
expect(message: "#{SlackRubyBot.config.user} subscription").to respond_with_slack_message customer_info
end
end
end
end
end
Expand Down

0 comments on commit 182511b

Please sign in to comment.