Class: XeroGateway::Payment
- Inherits:
-
Object
- Object
- XeroGateway::Payment
- Defined in:
- lib/xero_gateway/payment.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
All accessible fields.
-
#account_id ⇒ Object
All accessible fields.
-
#amount ⇒ Object
All accessible fields.
-
#code ⇒ Object
All accessible fields.
-
#currency_rate ⇒ Object
All accessible fields.
-
#date ⇒ Object
All accessible fields.
-
#errors ⇒ Object
readonly
Any errors that occurred when the #valid? method called.
-
#gateway ⇒ Object
Xero::Gateway associated with this contact.
-
#invoice ⇒ Object
All accessible fields.
-
#invoice_id ⇒ Object
All accessible fields.
-
#invoice_number ⇒ Object
All accessible fields.
-
#payment_id ⇒ Object
All accessible fields.
-
#payment_type ⇒ Object
All accessible fields.
-
#reference ⇒ Object
All accessible fields.
-
#status ⇒ Object
All accessible fields.
-
#updated_date_utc ⇒ Object
All accessible fields.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(params = {}) ⇒ Payment
constructor
A new instance of Payment.
- #to_xml(b = Builder::XmlMarkup.new) ⇒ Object
Methods included from Dates
Methods included from Money
Constructor Details
#initialize(params = {}) ⇒ Payment
Returns a new instance of Payment.
15 16 17 18 19 20 21 |
# File 'lib/xero_gateway/payment.rb', line 15 def initialize(params = {}) @errors ||= [] params.each do |k,v| self.send("#{k}=", v) end end |
Instance Attribute Details
#account ⇒ Object
All accessible fields
13 14 15 |
# File 'lib/xero_gateway/payment.rb', line 13 def account @account end |
#account_id ⇒ Object
All accessible fields
13 14 15 |
# File 'lib/xero_gateway/payment.rb', line 13 def account_id @account_id end |
#amount ⇒ Object
All accessible fields
13 14 15 |
# File 'lib/xero_gateway/payment.rb', line 13 def amount @amount end |
#code ⇒ Object
All accessible fields
13 14 15 |
# File 'lib/xero_gateway/payment.rb', line 13 def code @code end |
#currency_rate ⇒ Object
All accessible fields
13 14 15 |
# File 'lib/xero_gateway/payment.rb', line 13 def currency_rate @currency_rate end |
#date ⇒ Object
All accessible fields
13 14 15 |
# File 'lib/xero_gateway/payment.rb', line 13 def date @date end |
#errors ⇒ Object (readonly)
Any errors that occurred when the #valid? method called.
10 11 12 |
# File 'lib/xero_gateway/payment.rb', line 10 def errors @errors end |
#gateway ⇒ Object
Xero::Gateway associated with this contact.
7 8 9 |
# File 'lib/xero_gateway/payment.rb', line 7 def gateway @gateway end |
#invoice ⇒ Object
All accessible fields
13 14 15 |
# File 'lib/xero_gateway/payment.rb', line 13 def invoice @invoice end |
#invoice_id ⇒ Object
All accessible fields
13 14 15 |
# File 'lib/xero_gateway/payment.rb', line 13 def invoice_id @invoice_id end |
#invoice_number ⇒ Object
All accessible fields
13 14 15 |
# File 'lib/xero_gateway/payment.rb', line 13 def invoice_number @invoice_number end |
#payment_id ⇒ Object
All accessible fields
13 14 15 |
# File 'lib/xero_gateway/payment.rb', line 13 def payment_id @payment_id end |
#payment_type ⇒ Object
All accessible fields
13 14 15 |
# File 'lib/xero_gateway/payment.rb', line 13 def payment_type @payment_type end |
#reference ⇒ Object
All accessible fields
13 14 15 |
# File 'lib/xero_gateway/payment.rb', line 13 def reference @reference end |
#status ⇒ Object
All accessible fields
13 14 15 |
# File 'lib/xero_gateway/payment.rb', line 13 def status @status end |
#updated_date_utc ⇒ Object
All accessible fields
13 14 15 |
# File 'lib/xero_gateway/payment.rb', line 13 def updated_date_utc @updated_date_utc end |
Class Method Details
.from_xml(payment_element, gateway = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/xero_gateway/payment.rb', line 23 def self.from_xml(payment_element, gateway = nil) payment = Payment.new(:gateway => gateway) payment_element.children.each do | element | case element.name when 'PaymentID' then payment.payment_id = element.text when 'Date' then payment.date = 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' then payment.invoice = Invoice.from_xml(element) when 'Account' then payment.account = Account.from_xml(element) when "UpdatedDateUTC" then payment.updated_date_utc = parse_utc_date_time(element.text) when "PaymentType" then payment.payment_type = element.text end end payment end |
Instance Method Details
#==(other) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/xero_gateway/payment.rb', line 41 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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/xero_gateway/payment.rb', line 48 def to_xml(b = Builder::XmlMarkup.new) b.Payment do 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.account_id || self.code b.Account do |a| a.AccountID self.account_id if self.account_id 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 b.Date self.class.format_date(self.date || Date.today) end end |