Sha256: 922d01a450acd01b280e691e7f20ba5bafeb96af6f92d2c78d6e4434a04dbcf0

Contents?: true

Size: 832 Bytes

Versions: 1

Compression:

Stored size: 832 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
        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

1 entries across 1 versions & 1 rubygems

Version Path
opay-1.0.7 lib/opay/payable.rb