Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check whether there's an active team for a renewable Stripe subscription #5

Open
dblock opened this issue May 28, 2020 · 1 comment

Comments

@dblock
Copy link
Contributor

dblock commented May 28, 2020

  • warn if there's a stripe subscription but no team
  • do not auto-renew subscriptions for teams that aren't active, avoid having a chargeback because customer realizes they were charged for something they don't use
  • automatically re-associate a team with a Stripe subscription if that was lost
@dblock
Copy link
Contributor Author

dblock commented May 29, 2020

      Stripe::Subscription.list(plan: 'slava-yearly').auto_paging_each do |subscription|
        team = Team.where(stripe_customer_id: subscription.customer).first
        next if team

        customer = Stripe::Customer.retrieve(subscription.customer)
        metadata = customer.metadata
        team = Team.where(team_id: metadata.team_id).first
        next if team&.subscribed?

        if team
          logger.warn "Re-associating customer_id for #{metadata.name} (#{metadata.team_id}) with #{team}."
          team.update_attributes!(stripe_customer_id: subscription.customer, subscribed: true)
        else
          logger.warn "Cannot find team for #{metadata.name} (#{metadata.team_id}), contact #{customer.email}."
        end
      rescue StandardError => e
        logger.warn "Error checking customer #{subscription.customer}, #{e.message}."
        NewRelic::Agent.notice_error(e, custom_params: { team: subscription.customer })
      end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant