lib/xero_gateway/payment.rb in xero_gateway-float-2.1.3 vs lib/xero_gateway/payment.rb in xero_gateway-float-2.1.4

- old
+ new

@@ -1,34 +1,37 @@ module XeroGateway class Payment include Money include Dates + # Xero::Gateway associated with this contact. + attr_accessor :gateway + # # 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, :invoice_number, :account, :code, :payment_id, :date, :amount, :reference, :currency_rate, :account_id def initialize(params = {}) @errors ||= [] params.each do |k,v| self.send("#{k}=", v) end end - def self.from_xml(payment_element) - payment = Payment.new + 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.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 'Invoice' then payment.invoice = Invoice.from_xml(element) + when 'Account' then payment.account = Account.from_xml(element) end end payment end