Sha256: 520d90b09ef0b46afd6d4b06c5a676996f6f41ce3842d6296202fd91872e94ae

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

class Payment < ActiveRecord::Base
  has_many :payment_notifications
  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

  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 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 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

2 entries across 2 versions & 1 rubygems

Version Path
catarse_pagarme-2.6.7 spec/dummy/app/models/payment.rb
catarse_pagarme-2.6.6 spec/dummy/app/models/payment.rb