Sha256: 081311aff57b1fee8fb057db32e4c912a39cd564ae03205636181954f54cab6c
Contents?: true
Size: 1.78 KB
Versions: 1
Compression:
Stored size: 1.78 KB
Contents
module SlackRubyBotServer module Stripe module Commands class Unsubscribe < SlackRubyBot::Commands::Base command 'unsubscribe' do |client, data, match| team = ::Team.find(client.owner.id) if !team.active_stripe_subscription? client.say(channel: data.channel, text: "You don't have a paid subscription, all set.") logger.info "UNSUBSCRIBE: #{client.owner} - #{data.user} unsubscribe failed, no subscription" elsif data.user == team.activated_user_id subscription_info = [] subscription_id = match['expression'] active_subscription = team.active_stripe_subscription if active_subscription && active_subscription.id == subscription_id team.unsubscribe! amount = ActiveSupport::NumberHelper.number_to_currency(active_subscription.plan.amount.to_f / 100) subscription_info << "Successfully canceled auto-renew for #{active_subscription.plan.name} (#{amount})." logger.info "UNSUBSCRIBE: #{client.owner} - #{data.user}, canceled #{subscription_id}" elsif subscription_id subscription_info << "Sorry, I cannot find a subscription with \"#{subscription_id}\"." else subscription_info << "Send \"unsubscribe #{active_subscription.id}\" to confirm." end client.say(channel: data.channel, text: subscription_info.compact.join("\n")) logger.info "UNSUBSCRIBE: #{client.owner} - #{data.user}" else client.say(channel: data.channel, text: "Sorry, only <@#{team.activated_user_id}> can do that.") logger.info "UNSUBSCRIBE: #{client.owner} - #{data.user} unsubscribe failed, not admin" end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
slack-ruby-bot-server-stripe-0.1.0 | lib/slack-ruby-bot-server-stripe/commands/unsubscribe.rb |