<commit_before>class Payment < ActiveRecord::Base
  belongs_to :order
  belongs_to :source, :polymorphic => true
  belongs_to :payment_method

  has_many :transactions
  alias :txns :transactions
  has_many :offsets, :class_name => 'Payment', :foreign_key => 'source_id', :conditions => "source_type = 'Payment' AND amount < 0"

  after_save :create_payment_profile, :if => :payment_profiles_supported?

  # update the order totals, etc.
  after_save {order.try(:update!)}

  #after_save :check_payments
  #after_destroy :check_payments

  accepts_nested_attributes_for :source

  #validate :amount_is_valid_for_outstanding_balance_or_credit
  validates :payment_method, :presence => true, :if => Proc.new { |payable| payable.is_a? Checkout }

  scope :from_creditcard, where(:source_type => 'Creditcard')
  scope :with_state, lambda {|s| where(:state => s)}
  scope :completed, with_state('completed')



  # order state machine (see http://github.com/pluginaweek/state_machine/tree/master for details)
  state_machine :initial => 'checkout' do
    # With card payments, happens before purchase or authorization happens
    event :started_processing do
      transition :from => ['checkout', 'pending', 'completed'], :to => 'processing'
    end
    # When processing during checkout fails
    event :fail do
      transition :from => 'processing', :to => 'failed'
    end
    # With card payments this represents authorizing the payment
    event :pend do
      transition :from => 'processing', :to => 'pending'
    end
    # With card payments this represents completing a purchase or capture transaction
    event :complete do
      transition :from => ['processing', 'pending'], :to => 'completed'
    end<commit_msg>Add new pending scope for Payment.<commit_after>class Payment < ActiveRecord::Base
  belongs_to :order
  belongs_to :source, :polymorphic => true
  belongs_to :payment_method

  has_many :transactions
  alias :txns :transactions
  has_many :offsets, :class_name => 'Payment', :foreign_key => 'source_id', :conditions => "source_type = 'Payment' AND amount < 0"

  after_save :create_payment_profile, :if => :payment_profiles_supported?

  # update the order totals, etc.
  after_save {order.try(:update!)}

  #after_save :check_payments
  #after_destroy :check_payments

  accepts_nested_attributes_for :source

  #validate :amount_is_valid_for_outstanding_balance_or_credit
  validates :payment_method, :presence => true, :if => Proc.new { |payable| payable.is_a? Checkout }

  scope :from_creditcard, where(:source_type => 'Creditcard')
  scope :with_state, lambda {|s| where(:state => s)}
  scope :completed, with_state('completed')
  scope :pending, with_state('pending')


  # order state machine (see http://github.com/pluginaweek/state_machine/tree/master for details)
  state_machine :initial => 'checkout' do
    # With card payments, happens before purchase or authorization happens
    event :started_processing do
      transition :from => ['checkout', 'pending', 'completed'], :to => 'processing'
    end
    # When processing during checkout fails
    event :fail do
      transition :from => 'processing', :to => 'failed'
    end
    # With card payments this represents authorizing the payment
    event :pend do
      transition :from => 'processing', :to => 'pending'
    end
    # With card payments this represents completing a purchase or capture transaction
    event :complete do
      transition :from => ['processing', 'pending'], :to => 'completed'
    end
{'fraction_non_alphanumeric': 0.10873287671232877, 'fraction_numerical': 0.0005707762557077625, 'mean_word_length': 4.5371248025276465, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 39, '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': '1044400', 'n_tokens_mistral': 1041, 'n_tokens_neox': 997, 'n_words': 311}