class PagSeguro::SubscriptionPaymentOrder::ResponseSerializer
Attributes
xml[R]
Public Class Methods
new(xml)
click to toggle source
# File lib/pagseguro/subscription_payment_order/response_serializer.rb, line 6 def initialize(xml) @xml = xml end
Public Instance Methods
serialize()
click to toggle source
# File lib/pagseguro/subscription_payment_order/response_serializer.rb, line 10 def serialize {}.tap do |data| data[:code] = xml.at_css('code').text data[:status] = SubscriptionPaymentOrder::STATUSES.key(xml.at_css('status').text.to_i) data[:amount] = to_amount xml.at_css('amount').text data[:gross_amount] = xml.at_css('grossAmount').text data[:scheduling_date] = Time.parse(xml.css('schedulingDate').text) data[:last_event_date] = Time.parse(xml.css('lastEventDate').text) data[:discount] = serialize_discount if xml.at_css('discount') data[:transactions] = serialize_transactions if xml.css('transactions').any? end end
Private Instance Methods
serialize_discount()
click to toggle source
# File lib/pagseguro/subscription_payment_order/response_serializer.rb, line 25 def serialize_discount {}.tap do |data| data[:type] = xml.css('discount > type').text data[:value] = xml.css('discount > value').text end end
serialize_transaction(node)
click to toggle source
# File lib/pagseguro/subscription_payment_order/response_serializer.rb, line 38 def serialize_transaction(node) {}.tap do |data| data[:code] = node.css('> code').text data[:date] = Time.parse(node.css('> date').text) data[:status] = SubscriptionTransaction::STATUSES.key(node.css('> status').text.to_i) end end
serialize_transactions()
click to toggle source
# File lib/pagseguro/subscription_payment_order/response_serializer.rb, line 32 def serialize_transactions xml.css('transactions').map do |node| serialize_transaction(node) end end
to_amount(amount)
click to toggle source
# File lib/pagseguro/subscription_payment_order/response_serializer.rb, line 46 def to_amount(amount) "%.2f" % BigDecimal(amount.to_s).round(2).to_s("F") if amount end