Sha256: 8a7a08596435c807589774f89b77f0821ae8b2226dc6728e8c17abca8945d4a6

Contents?: true

Size: 1.35 KB

Versions: 9

Compression:

Stored size: 1.35 KB

Contents

class Payment < ActiveRecord::Base
  has_many :payment_notifications
  has_many :payment_transfers
  belongs_to :contribution
  delegate :user, :project, to: :contribution

  validates_presence_of :state, :key, :gateway, :payment_method, :value, :installments
  validate :value_should_be_equal_or_greater_than_pledge

  attr_accessor :generating_second_slip

  before_validation do
    generate_key
    self.value ||= self.contribution.try(:value)
    self.state ||= 'pending' # mock initial state for here we do not include the stat machine
  end

  def slip_expiration_date
    2.weekdays_from_now
  end

  def generate_key
    self.key ||= SecureRandom.uuid
  end

  def value_should_be_equal_or_greater_than_pledge
    errors.add(:value, I18n.t("activerecord.errors.models.payment.attributes.value.invalid")) if self.contribution && self.value < self.contribution.value
  end

  def notification_template_for_failed_project
    if slip_payment?
      :contribution_project_unsuccessful_slip
    else
      :contribution_project_unsuccessful_credit_card
    end
  end

  def invalid_refund
    true
  end

  def refunded?
    true
  end

  def paid?
    true
  end

  def refused?
    true
  end

  def refuse
  end

  def pay
  end

  def refund
  end

  def credits?
    self.gateway == 'Credits'
  end

  def slip_payment?
    self.payment_method == 'BoletoBancario'
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
catarse_pagarme-2.13.0 spec/dummy/app/models/payment.rb
catarse_pagarme-2.12.0 spec/dummy/app/models/payment.rb
catarse_pagarme-2.11.0 spec/dummy/app/models/payment.rb
catarse_pagarme-2.10.15 spec/dummy/app/models/payment.rb
catarse_pagarme-2.10.14 spec/dummy/app/models/payment.rb
catarse_pagarme-2.10.13 spec/dummy/app/models/payment.rb
catarse_pagarme-2.10.12 spec/dummy/app/models/payment.rb
catarse_pagarme-2.10.11 spec/dummy/app/models/payment.rb
catarse_pagarme-2.10.10 spec/dummy/app/models/payment.rb