<commit_before># frozen_string_literal: true

class BalanceTransferMachine
  include Statesman::Machine

  state :pending, initial: true
  state :authorized
  state :processing
  state :transferred
  state :error
  state :gateway_error
  state :rejected

  transition from: :pending, to: %i[authorized rejected gateway_error]
  transition from: :authorized, to: %i[gateway_error error rejected processing pending]
  transition from: :processing, to: %i[error transferred gateway_error]
  transition from: :gateway_error, to: %i[processing transferred error]

  after_transition(to: :transferred) do |bt|
    Notification.notify(:balance_transferred, bt.user, {
      associations: { balance_transfer_id: bt.id } })
  end

  after_transition(to: :error) do |bt|
    Notification.notify(:balance_transfer_error, bt.user, {
      associations: { balance_transfer_id: bt.id } })
    bt.refund_balance
  end

  after_transition(to: :rejected) do |bt|
    Notification.notify(:balance_transfer_error, bt.user, {
      associations: { balance_transfer_id: bt.id } })
    bt.refund_balance
  end
end
<commit_msg>gateway_error can go back to authorized<commit_after># frozen_string_literal: true

class BalanceTransferMachine
  include Statesman::Machine

  state :pending, initial: true
  state :authorized
  state :processing
  state :transferred
  state :error
  state :gateway_error
  state :rejected

  transition from: :pending, to: %i[authorized rejected gateway_error]
  transition from: :authorized, to: %i[gateway_error error rejected processing pending]
  transition from: :processing, to: %i[error transferred gateway_error]
  transition from: :gateway_error, to: %i[authorized processing transferred error]

  after_transition(to: :transferred) do |bt|
    Notification.notify(:balance_transferred, bt.user, {
      associations: { balance_transfer_id: bt.id } })
  end

  after_transition(to: :error) do |bt|
    Notification.notify(:balance_transfer_error, bt.user, {
      associations: { balance_transfer_id: bt.id } })
    bt.refund_balance
  end

  after_transition(to: :rejected) do |bt|
    Notification.notify(:balance_transfer_error, bt.user, {
      associations: { balance_transfer_id: bt.id } })
    bt.refund_balance
  end
end

{'fraction_non_alphanumeric': 0.09443207126948774, 'fraction_numerical': 0.0, 'mean_word_length': 4.833766233766234, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2392613', 'n_tokens_mistral': 684, 'n_tokens_neox': 667, 'n_words': 178}