Class: Clearbooks::Payment

Inherits:
Base
  • Object
show all
Defined in:
lib/clearbooks/model/payment.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

build, create

Constructor Details

#initialize(data) ⇒ Payment

Returns a new instance of Payment.

Parameters:



68
69
70
71
72
73
74
75
76
77
# File 'lib/clearbooks/model/payment.rb', line 68

def initialize data
  @accounting_date  = parse_date data.savon :accounting_date
  @type = data.savon :type
  @description = data.savon :description
  @amount = BigDecimal.new data.savon :amount
  @entity_id = data.savon(:entity_id).to_i
  @payment_method = data.savon(:payment_method).to_i
  @bank_account = data.savon :bank_account
  @invoices = data.savon :invoices
end

Instance Attribute Details

#accounting_dateDateTime (readonly)

Optional. Date the payment was made.



24
25
26
# File 'lib/clearbooks/model/payment.rb', line 24

def accounting_date
  @accounting_date
end

#amountBigDecimal (readonly)

Optional. The total amount paid in pounds.



39
40
41
# File 'lib/clearbooks/model/payment.rb', line 39

def amount
  @amount
end

#bank_accountString (readonly)

Optional. The account code of the bank account being paid into.



54
55
56
# File 'lib/clearbooks/model/payment.rb', line 54

def 
  @bank_account
end

#descriptionString (readonly)

Optional.



34
35
36
# File 'lib/clearbooks/model/payment.rb', line 34

def description
  @description
end

#entity_idFixnum (readonly)

Optional. The id of the customer or supplier.



44
45
46
# File 'lib/clearbooks/model/payment.rb', line 44

def entity_id
  @entity_id
end

#invoicesArray (readonly)

Optional. An array of invoice elements.



59
60
61
# File 'lib/clearbooks/model/payment.rb', line 59

def invoices
  @invoices
end

#payment_methodFixnum (readonly)

Optional. The id of the payment method.



49
50
51
# File 'lib/clearbooks/model/payment.rb', line 49

def payment_method
  @payment_method
end

#typeString (readonly)

Optional. String identifying the type of the payment. Value one of: purchases, sales.



29
30
31
# File 'lib/clearbooks/model/payment.rb', line 29

def type
  @type
end

Instance Method Details

#to_savonHash

Returns self as Savon readable Hash

Returns:

  • (Hash)

    Returns self as Savon readable Hash



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/clearbooks/model/payment.rb', line 83

def to_savon
  {
      payment: {
          :@accountingDate => @accounting_date.strftime('%F'),
          :@type            => @type,
          :@amount          => @amount.to_f,
          :@entityId       => @entity_id,
          :@paymentMethod  => @payment_method,
          :@bankAccount    => @bank_account,
          :description     => @description,
          :invoices        => { invoice: savon_invoices }
      }
  }
end