lib/dineromail/status_report.rb in dineromail-0.0.2 vs lib/dineromail/status_report.rb in dineromail-0.0.3

- old
+ new

@@ -1,17 +1,19 @@ require 'xmlsimple' require 'httparty' require 'dineromail/buyer' module Dineromail class StatusReport - attr_accessor :transaction_id, :date, :status, :amount, :net_amount, :pay_method, :pay_medium, :buyer + attr_accessor :transaction_id, :date, :status, :amount, :net_amount, :pay_method, :pay_medium, :buyer, :items PENDING_STATUS = 1 ACCREDITED_STATUS = 2 CANCELLED_STATUS = 3 + def initialize(transaction_id = nil) + @items = [] if transaction_id obtain_status_report_data_for transaction_id end end @@ -35,27 +37,36 @@ response = HTTParty.get ipn_url , :query => {:data => request_data} parse_response response.body end def parse_response(response) - response_data = XmlSimple.xml_in(response) - operation = response_data['DETALLE'].first['OPERACIONES'].first['OPERACION'].first - self.transaction_id = operation['ID'].first - self.date = operation['FECHA'].first - self.status = operation['ESTADO'].first.to_i - self.amount = operation['MONTO'].first.to_f - self.net_amount = operation['MONTONETO'].first.to_f - self.pay_method = operation['METODOPAGO'].first - self.pay_medium = operation['MEDIOPAGO'].first - buyer_data = operation['COMPRADOR'].first + response_data = XmlSimple.xml_in(response,'KeyToSymbol' => true ) + operation = response_data[:detalle].first[:operaciones].first[:operacion].first + self.transaction_id = operation[:id].first.to_i + self.date = DateTime.parse operation[:fecha].first + self.status = operation[:estado].first.to_i + self.amount = operation[:monto].first.to_f + self.net_amount = operation[:montoneto].first.to_f + self.pay_method = operation[:metodopago].first + self.pay_medium = operation[:mediopago].first + buyer_data = operation[:comprador].first self.buyer = Buyer.new - buyer.email = buyer_data['EMAIL'].first - buyer.address = buyer_data['DIRECCION'].first - buyer.comment = buyer_data['COMENTARIO'].first - buyer.name = buyer_data['NOMBRE'].first - buyer.phone = buyer_data['TELEFONO'].first - buyer.document_type = buyer_data['TIPODOC'].first - buyer.document_number = buyer_data['NUMERODOC'].first + buyer.email = buyer_data[:email].first + buyer.address = buyer_data[:direccion].first + buyer.comment = buyer_data[:comentario].first + buyer.name = buyer_data[:nombre].first + buyer.phone = buyer_data[:telefono].first + buyer.document_type = buyer_data[:tipodoc].first + buyer.document_number = buyer_data[:numerodoc].first + items_data = operation[:items].first[:item] + items_data.each do |item_data| + item = Item.new + item.description = item_data[:descripcion].first + item.currency = item_data[:moneda].first.to_i + item.unit_price = item_data[:preciounitario].first.to_f + item.count = item_data[:cantidad].first.to_i + self.items << item + end end end end \ No newline at end of file