lib/request_result.rb in webmoney-0.0.8 vs lib/request_result.rb in webmoney-0.0.9
- old
+ new
@@ -26,16 +26,55 @@
:wmid => (doc.at('//testwmpurse/wmid').inner_html rescue nil),
:purse => (doc.at('//testwmpurse/purse').inner_html rescue nil)
}
end
+ def result_create_invoice(doc)
+ res = {
+ :retval => doc.at('//retval').inner_html.to_i,
+ :retdesc => (doc.at('//testwmpurse/retdesc').inner_html rescue nil),
+ :orderid => (doc.at('//invoice/orderid').inner_html.to_i),
+ }
+ if res[:retval] == 0
+ res[:id] = (doc.at('//invoice').attributes['id'].value.to_i)
+ res[:ts] = (doc.at('//invoice').attributes['ts'].value.to_i)
+ res[:state] = (doc.at('//invoice/state').inner_html.to_i)
+ res[:created_at] = (DateTime.strptime(doc.at('//invoice/datecrt').inner_html, "%Y%m%d %H:%M:%S"))
+ end
+ res
+ end
+
def result_create_transaction(doc)
op = doc.at('//operation')
{
:operation_id => op['id'],
:operation_ts => op['ts']
}.merge( op.children.inject({}) do |memo, elm|
memo.merge!(elm.name.to_sym => elm.text)
end )
end
-end
\ No newline at end of file
+ def result_outgoing_invoices(doc)
+ res = {
+ :retval => doc.at('//retval').inner_html.to_i,
+ :retdesc => (doc.at('//testwmpurse/retdesc').inner_html rescue nil),
+ }
+ if res[:retval] == 0
+ res[:invoices] = doc.at('//outinvoices').elements.collect do |invoice|
+ r = {
+ :id => invoice.attributes['id'].value.to_i,
+ :ts => invoice.attributes['ts'].value.to_i,
+ }
+ invoice.elements.each do |tag|
+ name = tag.name.to_sym
+ value = tag.inner_html
+ value = value.to_i if [:orderid, :tranid, :period, :expiration, :wmtranid, :state].include?(name)
+ value = value.to_f if [:rest, :amount, :comiss].include?(name)
+ value = DateTime.strptime(value, "%Y%m%d %H:%M:%S") if [:datecrt, :dateupd].include?(name)
+ r[name] = value
+ end
+ r
+ end
+ end
+ res
+ end
+end