dineromail 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/dineromail.rb CHANGED
@@ -2,6 +2,7 @@ require 'dineromail/version'
2
2
  require 'dineromail/notification'
3
3
  require 'dineromail/status_report'
4
4
  require 'dineromail/buyer'
5
+ require 'dineromail/item'
5
6
  require 'dineromail/configuration'
6
7
  require 'dineromail/app/helpers/dineromail_helper'
7
8
  require 'action_controller'
@@ -0,0 +1,15 @@
1
+ module Dineromail
2
+ class Item
3
+ attr_accessor :description, :currency, :unit_price, :count
4
+
5
+ DOLLAR = 2
6
+ PESO = 1
7
+
8
+ def initialize(attributes = {})
9
+ attributes.each do |name, value|
10
+ send("#{name}=", value)
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -4,7 +4,7 @@ module Dineromail
4
4
 
5
5
  attr_reader :transaction_id, :tipo
6
6
 
7
- def initialize(transaction_id, tipo = null)
7
+ def initialize(transaction_id, tipo = nil)
8
8
  @transaction_id = transaction_id
9
9
  @tipo = tipo
10
10
  end
@@ -18,15 +18,19 @@ module Dineromail
18
18
 
19
19
  def self.from_xml(notification_xml)
20
20
  notifications = []
21
- notificaction_data = XmlSimple.xml_in(notification_xml)
22
- operations = notificaction_data['operaciones'].first['operacion']
21
+ notificaction_data = XmlSimple.xml_in(notification_xml,'KeyToSymbol' => true)
22
+ operations = notificaction_data[:operaciones].first[:operacion]
23
23
  operations.each do |operation|
24
- tipo = operation['tipo'].first
25
- transaction_id = operation['id'].first
24
+ tipo = operation[:tipo].first
25
+ transaction_id = operation[:id].first
26
26
  notifications << self.new(transaction_id, tipo)
27
27
  end
28
28
  notifications
29
29
  end
30
30
 
31
+ def self.method_missing(symbol, *args)
32
+ status_report.send(symbol, *args)
33
+ end
34
+
31
35
  end
32
36
  end
@@ -3,13 +3,15 @@ require 'httparty'
3
3
  require 'dineromail/buyer'
4
4
  module Dineromail
5
5
  class StatusReport
6
- attr_accessor :transaction_id, :date, :status, :amount, :net_amount, :pay_method, :pay_medium, :buyer
6
+ attr_accessor :transaction_id, :date, :status, :amount, :net_amount, :pay_method, :pay_medium, :buyer, :items
7
7
 
8
8
  PENDING_STATUS = 1
9
9
  ACCREDITED_STATUS = 2
10
10
  CANCELLED_STATUS = 3
11
11
 
12
+
12
13
  def initialize(transaction_id = nil)
14
+ @items = []
13
15
  if transaction_id
14
16
  obtain_status_report_data_for transaction_id
15
17
  end
@@ -37,24 +39,33 @@ module Dineromail
37
39
  end
38
40
 
39
41
  def parse_response(response)
40
- response_data = XmlSimple.xml_in(response)
41
- operation = response_data['DETALLE'].first['OPERACIONES'].first['OPERACION'].first
42
- self.transaction_id = operation['ID'].first
43
- self.date = operation['FECHA'].first
44
- self.status = operation['ESTADO'].first.to_i
45
- self.amount = operation['MONTO'].first.to_f
46
- self.net_amount = operation['MONTONETO'].first.to_f
47
- self.pay_method = operation['METODOPAGO'].first
48
- self.pay_medium = operation['MEDIOPAGO'].first
49
- buyer_data = operation['COMPRADOR'].first
42
+ response_data = XmlSimple.xml_in(response,'KeyToSymbol' => true )
43
+ operation = response_data[:detalle].first[:operaciones].first[:operacion].first
44
+ self.transaction_id = operation[:id].first.to_i
45
+ self.date = DateTime.parse operation[:fecha].first
46
+ self.status = operation[:estado].first.to_i
47
+ self.amount = operation[:monto].first.to_f
48
+ self.net_amount = operation[:montoneto].first.to_f
49
+ self.pay_method = operation[:metodopago].first
50
+ self.pay_medium = operation[:mediopago].first
51
+ buyer_data = operation[:comprador].first
50
52
  self.buyer = Buyer.new
51
- buyer.email = buyer_data['EMAIL'].first
52
- buyer.address = buyer_data['DIRECCION'].first
53
- buyer.comment = buyer_data['COMENTARIO'].first
54
- buyer.name = buyer_data['NOMBRE'].first
55
- buyer.phone = buyer_data['TELEFONO'].first
56
- buyer.document_type = buyer_data['TIPODOC'].first
57
- buyer.document_number = buyer_data['NUMERODOC'].first
53
+ buyer.email = buyer_data[:email].first
54
+ buyer.address = buyer_data[:direccion].first
55
+ buyer.comment = buyer_data[:comentario].first
56
+ buyer.name = buyer_data[:nombre].first
57
+ buyer.phone = buyer_data[:telefono].first
58
+ buyer.document_type = buyer_data[:tipodoc].first
59
+ buyer.document_number = buyer_data[:numerodoc].first
60
+ items_data = operation[:items].first[:item]
61
+ items_data.each do |item_data|
62
+ item = Item.new
63
+ item.description = item_data[:descripcion].first
64
+ item.currency = item_data[:moneda].first.to_i
65
+ item.unit_price = item_data[:preciounitario].first.to_f
66
+ item.count = item_data[:cantidad].first.to_i
67
+ self.items << item
68
+ end
58
69
  end
59
70
 
60
71
  end
@@ -1,3 +1,3 @@
1
1
  module Dineromail
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -4,7 +4,7 @@ describe Dineromail::StatusReport do
4
4
  it 'should load the status report from xml' do
5
5
  xml = '<REPORTE><ESTADOREPORTE></ESTADOREPORTE><DETALLE><OPERACIONES><OPERACION>
6
6
  <ID>1889</ID>
7
- <FECHA>17/01/2011</FECHA>
7
+ <FECHA>01/28/2011 12:02:01 PM</FECHA>
8
8
  <ESTADO>1</ESTADO>
9
9
  <NUMTRANSACCION>67777</NUMTRANSACCION>
10
10
  <COMPRADOR>
@@ -16,23 +16,30 @@ describe Dineromail::StatusReport do
16
16
  <TIPODOC>DNI</TIPODOC>
17
17
  <NUMERODOC>222222222</NUMERODOC>
18
18
  </COMPRADOR>
19
- <MONTO>60</MONTO>
20
- <MONTONETO>50</MONTONETO>
19
+ <MONTO>60.2</MONTO>
20
+ <MONTONETO>50.3</MONTONETO>
21
21
  <METODOPAGO>TARJETA DE CREDITO</METODOPAGO>
22
22
  <MEDIOPAGO>VISA</MEDIOPAGO>
23
23
  <CUOTAS>1</CUOTAS>
24
- <ITEMS><ITEM><DESCRIPCION></DESCRIPCION><MONEDA></MONEDA><PRECIOUNITARIO></PRECIOUNITARIO><CANTIDAD></CANTIDAD></ITEM></ITEMS><VENDEDOR><TIPODOC></TIPODOC><NUMERODOC></NUMERODOC></VENDEDOR></OPERACION></OPERACIONES></DETALLE></REPORTE>'
24
+ <ITEMS>
25
+ <ITEM>
26
+ <DESCRIPCION>Libro</DESCRIPCION>
27
+ <MONEDA>1</MONEDA>
28
+ <PRECIOUNITARIO>6.90</PRECIOUNITARIO>
29
+ <CANTIDAD>2</CANTIDAD>
30
+ </ITEM>
31
+ </ITEMS><VENDEDOR><TIPODOC></TIPODOC><NUMERODOC></NUMERODOC></VENDEDOR></OPERACION></OPERACIONES></DETALLE></REPORTE>'
25
32
 
26
33
  status_report = Dineromail::StatusReport.new
27
34
  status_report.parse_response(xml)
28
35
  buyer = status_report.buyer
36
+ item = status_report.items.first
29
37
 
30
-
31
- status_report.transaction_id.should == '1889'
32
- status_report.date.should == '17/01/2011'
38
+ status_report.transaction_id.should == 1889
39
+ status_report.date.should == DateTime.ordinal(2011,28,12,2,1)
33
40
  status_report.status.should == Dineromail::StatusReport::PENDING_STATUS
34
- status_report.amount.should == 60.0
35
- status_report.net_amount.should == 50.0
41
+ status_report.amount.should == 60.2
42
+ status_report.net_amount.should == 50.3
36
43
  status_report.pay_method.should == 'TARJETA DE CREDITO'
37
44
  status_report.pay_medium.should == 'VISA'
38
45
  buyer.email.should == 'comprador@email.com'
@@ -42,5 +49,9 @@ describe Dineromail::StatusReport do
42
49
  buyer.phone.should == '4444444'
43
50
  buyer.document_type.should == 'DNI'
44
51
  buyer.document_number.should == '222222222'
52
+ item.description.should == 'Libro'
53
+ item.currency.should == 1
54
+ item.count.should == 2
55
+ item.unit_price.should == 6.9
45
56
  end
46
57
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dineromail
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nicolas Mosconi
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-05-28 00:00:00 -03:00
20
+ date: 2011-06-02 00:00:00 -03:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -111,6 +111,7 @@ files:
111
111
  - lib/dineromail/app/helpers/dineromail_helper.rb
112
112
  - lib/dineromail/buyer.rb
113
113
  - lib/dineromail/configuration.rb
114
+ - lib/dineromail/item.rb
114
115
  - lib/dineromail/notification.rb
115
116
  - lib/dineromail/status_report.rb
116
117
  - lib/dineromail/version.rb