Module: LolitaBankLink::Billing

Defined in:
lib/lolita-bank-link/billing.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lolita-bank-link/billing.rb', line 3

def self.included(base)
  base.has_many :bank_link_transactions, as: :paymentable, class_name: "LolitaBankLink::Transaction", dependent: :destroy
  base.class_eval do

    # Payment description
    def description
      raise NotImplementedError, 'Redefine this method in your billing model.'
    end

    # Price of payment in cents
    def price
      raise  NotImplementedError, 'Redefine this method in your billing model.'
    end

    # Currency as 3 letter code as in ISO 4217
    def currency
      raise  NotImplementedError, 'Redefine this method in your billing model.'
    end

    def bank_link_trx_saved trx
      raise  NotImplementedError, "Redefine this method in your billing model."
    end

    def bank_link_return_path
      raise  NotImplementedError, 'This should be inplemented on your paymentable class'
    end

    # Add this to your paid? method along with other payment methods
    # Example:
    #     def paid?
    #       bank_link_paid? || first_data_paid?
    #     end
    def bank_link_paid?
      self.bank_link_transactions.where(status: "completed").count >= 1
    end
  end
end