Sha256: e2a432346e04b418df0db9b933f0389aeddf7ecdc8fe2e9cc865cc6a240e4b28

Contents?: true

Size: 756 Bytes

Versions: 2

Compression:

Stored size: 756 Bytes

Contents

require "active_support/concern"

module PuntoPagosRails
  module Payable
    extend ActiveSupport::Concern

    PAYMENT_STATES = %w{pending completed rejected}

    included do
      extend Enumerize

      has_many :transactions, as: :payable, class_name: "PuntoPagosRails::Transaction"
      enumerize :payment_state, in: PAYMENT_STATES,
                                default: :pending,
                                predicates: true,
                                scope: true,
                                prefix: false

      def paid?
        completed?
      end
    end

    module ClassMethods
      def by_token(token)
        transaction = Transaction.find_by(token: token)
        transaction.try(:payable)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
punto_pagos_rails-1.3.1 lib/punto_pagos_rails/payable.rb
punto_pagos_rails-1.3.0 lib/punto_pagos_rails/payable.rb