Sha256: f16bdda0ffd288ba3cee49b5ec142b455cc88b3922bfb40bff7f5959ca8510b1
Contents?: true
Size: 1.31 KB
Versions: 7
Compression:
Stored size: 1.31 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 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
7 entries across 7 versions & 1 rubygems