lib/xero_gateway/payment.rb in xero_gateway-2.1.0 vs lib/xero_gateway/payment.rb in xero_gateway-2.3.0

- old
+ new

@@ -5,11 +5,12 @@ # Any errors that occurred when the #valid? method called. attr_reader :errors # All accessible fields - attr_accessor :invoice_id, :invoice_number, :account_id, :code, :payment_id, :date, :amount, :reference, :currency_rate + attr_accessor :invoice_id, :invoice_number, :account_id, :code, :payment_id, :payment_type, :date, :amount, :reference, :currency_rate, :updated_at, :reconciled + alias_method :reconciled?, :reconciled def initialize(params = {}) @errors ||= [] params.each do |k,v| @@ -19,17 +20,22 @@ 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 '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.send("#{element.children.first.name.underscore}=", element.children.first.text) - when 'Account' then payment.send("#{element.children.first.name.underscore}=", element.children.first.text) + 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.account_id = element.elements["//AccountID"].text end end payment end @@ -41,10 +47,13 @@ end 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 @@ -59,12 +68,16 @@ 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 end -end \ No newline at end of file +end