Class: XeroGateway::Payment

Inherits:
Object
  • Object
show all
Includes:
Dates, Money
Defined in:
lib/xero_gateway/payment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Dates

included

Methods included from Money

included

Constructor Details

#initialize(params = {}) ⇒ Payment

Returns a new instance of Payment.



13
14
15
16
17
18
19
# File 'lib/xero_gateway/payment.rb', line 13

def initialize(params = {})
  @errors ||= []

  params.each do |k,v|
    self.send("#{k}=", v)
  end
end

Instance Attribute Details

#account_idObject

All accessible fields



10
11
12
# File 'lib/xero_gateway/payment.rb', line 10

def 
  @account_id
end

#amountObject

All accessible fields



10
11
12
# File 'lib/xero_gateway/payment.rb', line 10

def amount
  @amount
end

#codeObject

All accessible fields



10
11
12
# File 'lib/xero_gateway/payment.rb', line 10

def code
  @code
end

#currency_rateObject

All accessible fields



10
11
12
# File 'lib/xero_gateway/payment.rb', line 10

def currency_rate
  @currency_rate
end

#dateObject

All accessible fields



10
11
12
# File 'lib/xero_gateway/payment.rb', line 10

def date
  @date
end

#errorsObject (readonly)

Any errors that occurred when the #valid? method called.



7
8
9
# File 'lib/xero_gateway/payment.rb', line 7

def errors
  @errors
end

#invoice_idObject

All accessible fields



10
11
12
# File 'lib/xero_gateway/payment.rb', line 10

def invoice_id
  @invoice_id
end

#invoice_numberObject

All accessible fields



10
11
12
# File 'lib/xero_gateway/payment.rb', line 10

def invoice_number
  @invoice_number
end

#payment_idObject

All accessible fields



10
11
12
# File 'lib/xero_gateway/payment.rb', line 10

def payment_id
  @payment_id
end

#payment_typeObject

All accessible fields



10
11
12
# File 'lib/xero_gateway/payment.rb', line 10

def payment_type
  @payment_type
end

#reconciledObject Also known as: reconciled?

All accessible fields



10
11
12
# File 'lib/xero_gateway/payment.rb', line 10

def reconciled
  @reconciled
end

#referenceObject

All accessible fields



10
11
12
# File 'lib/xero_gateway/payment.rb', line 10

def reference
  @reference
end

#updated_atObject

All accessible fields



10
11
12
# File 'lib/xero_gateway/payment.rb', line 10

def updated_at
  @updated_at
end

Class Method Details

.from_xml(payment_element) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/xero_gateway/payment.rb', line 21

def self.from_xml(payment_element)
  payment = Payment.new
  payment_element.children.each do | element |
    case element.name
      when 'PaymentID'      then payment.payment_id = element.text
      when 'PaymentType'    then payment.payment_type = element.text
      when 'Date'           then payment.date = parse_date_time(element.text)
      when 'UpdatedDateUTC' then payment.updated_at = parse_date_time(element.text)
      when 'Amount'         then payment.amount = BigDecimal.new(element.text)
      when 'Reference'      then payment.reference = element.text
      when 'CurrencyRate'   then payment.currency_rate = BigDecimal.new(element.text)
      when 'Invoice'
        payment.invoice_id = element.elements["//InvoiceID"].text
        payment.invoice_number = element.elements["//InvoiceNumber"].text
      when 'IsReconciled'   then payment.reconciled = (element.text == "true")
      when 'Account'        then payment. = element.elements["//AccountID"].text
    end
  end
  payment
end

Instance Method Details

#==(other) ⇒ Object



42
43
44
45
46
47
# File 'lib/xero_gateway/payment.rb', line 42

def ==(other)
  [:payment_id, :date, :amount].each do |field|
    return false if send(field) != other.send(field)
  end
  return true
end

#to_xml(b = Builder::XmlMarkup.new) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/xero_gateway/payment.rb', line 49

def to_xml(b = Builder::XmlMarkup.new)
  b.Payment do

    b.PaymentID          self.payment_id        if self.payment_id
    b.PaymentType        self.payment_type      if self.payment_type

    if self.invoice_id || self.invoice_number
      b.Invoice do |i|
        i.InvoiceID         self.invoice_id     if self.invoice_id
        i.InvoiceNumber     self.invoice_number if self.invoice_number
      end
    end

    if self. || self.code
      b.Account do |a|
        a.AccountID         self.     if self.
        a.Code              self.code           if self.code
      end
    end

    b.Amount            self.amount         if self.amount
    b.CurrencyRate      self.currency_rate  if self.currency_rate
    b.Reference         self.reference      if self.reference

    if self.reconciled?
      b.IsReconciled true
    end

    b.Date              self.class.format_date(self.date || Date.today)
  end
end