Sha256: d9756fc097ed6aedcedde7ebf7a4c7a8bcf6de855a03c30cb9a02b75636573e4

Contents?: true

Size: 890 Bytes

Versions: 3

Compression:

Stored size: 890 Bytes

Contents

module Opay
  module Payable
    extend ActiveSupport::Concern
    extend ActiveModel::Callbacks

    included do
      has_one :payment, as: :payable, class_name: 'Opay::Payment'
      define_model_callbacks :payment, only: :after
    end

    def finished?
      payment.present? && payment.finished?
    end

    def finish
      run_callbacks :payment do
        payment.update_attribute(:finished, true)
      end
    end

    def prepare_payment
      if payment.blank?
        create_payment!(provider: 'payu', amount: amount)
      else
        raise 'Payment was finished' if payment.finished?
        payment.update_attribute(:session_id, Payment.generate_session_id)
        payment
      end
    end

    def payment_session_id
      raise 'Resource must be prepared before payment' if payment.blank?
      payment.session_id
    end

    module ClassMethods
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
opay-1.1.0 lib/opay/payable.rb
opay-1.0.9 lib/opay/payable.rb
opay-1.0.8 lib/opay/payable.rb