<commit_before>class StripeWebhooksController < ApplicationController
  skip_forgery_protection

  def account
    begin
      event = construct_event(ENV['STRIPE_ACCOUNT_ENDPOINT_SECRET'])
    rescue JSON::ParserError => e
      Rollbar.warn(e)
      head :not_acceptable
      return
    end

    # case event.type
    # This is where handlers would go if we had any yet
    # else
    Rollbar.warn("Unhandled event type for account webhook listener: #{event.type}")
    # end

    head :ok
  end

  def connect
    begin
      event = construct_event(ENV['STRIPE_CONNECT_ENDPOINT_SECRET'])
    rescue JSON::ParserError => e
      Rollbar.warn(e)
      head :not_acceptable
      return
    end

    case event.type
    when 'account.application.deauthorized'
      account = event.data.object
      convention = Convention.find_by(stripe_account_id: account.id)
      if convention
        convention.update!(stripe_account_id: nil, stripe_account_ready_to_charge: false)
      end
    when 'account.application.authorized', 'account.updated'
      account = event.data.object
      convention = Convention.find_by(stripe_account_id: account.id)
      if convention && !convention.stripe_account_ready_to_charge
        ConnectStripeAccountService.new(convention: convention, account: acct).call!<commit_msg>A stripe account can be linked to more than one convention; handle that<commit_after>class StripeWebhooksController < ApplicationController
  skip_forgery_protection

  def account
    begin
      event = construct_event(ENV['STRIPE_ACCOUNT_ENDPOINT_SECRET'])
    rescue JSON::ParserError => e
      Rollbar.warn(e)
      head :not_acceptable
      return
    end

    # case event.type
    # This is where handlers would go if we had any yet
    # else
    Rollbar.warn("Unhandled event type for account webhook listener: #{event.type}")
    # end

    head :ok
  end

  def connect
    begin
      event = construct_event(ENV['STRIPE_CONNECT_ENDPOINT_SECRET'])
    rescue JSON::ParserError => e
      Rollbar.warn(e)
      head :not_acceptable
      return
    end

    case event.type
    when 'account.application.deauthorized'
      account = event.data.object
      conventions = Convention.where(stripe_account_id: account.id)
      conventions.update_all(stripe_account_id: nil, stripe_account_ready_to_charge: false)
    when 'account.application.authorized', 'account.updated'
      account = event.data.object
      conventions = Convention.where(stripe_account_id: account.id)
      conventions.each do |convention|
        if convention && !convention.stripe_account_ready_to_charge
          ConnectStripeAccountService.new(convention: convention, account: acct).call!
        end
{'fraction_non_alphanumeric': 0.07504621072088724, 'fraction_numerical': 0.0, 'mean_word_length': 3.3434991974317816, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2641420', 'n_tokens_mistral': 797, 'n_tokens_neox': 782, 'n_words': 186}