dineromail 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dineromail.rb +1 -0
- data/lib/dineromail/item.rb +15 -0
- data/lib/dineromail/notification.rb +9 -5
- data/lib/dineromail/status_report.rb +29 -18
- data/lib/dineromail/version.rb +1 -1
- data/spec/dineromail/status_report_spec.rb +20 -9
- metadata +5 -4
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'
|
@@ -4,7 +4,7 @@ module Dineromail
|
|
4
4
|
|
5
5
|
attr_reader :transaction_id, :tipo
|
6
6
|
|
7
|
-
def initialize(transaction_id, tipo =
|
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[
|
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[
|
25
|
-
transaction_id = operation[
|
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[
|
42
|
-
self.transaction_id = operation[
|
43
|
-
self.date = operation[
|
44
|
-
self.status = operation[
|
45
|
-
self.amount = operation[
|
46
|
-
self.net_amount = operation[
|
47
|
-
self.pay_method = operation[
|
48
|
-
self.pay_medium = operation[
|
49
|
-
buyer_data = operation[
|
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[
|
52
|
-
buyer.address = buyer_data[
|
53
|
-
buyer.comment = buyer_data[
|
54
|
-
buyer.name = buyer_data[
|
55
|
-
buyer.phone = buyer_data[
|
56
|
-
buyer.document_type = buyer_data[
|
57
|
-
buyer.document_number = buyer_data[
|
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
|
data/lib/dineromail/version.rb
CHANGED
@@ -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>
|
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
|
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.
|
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.
|
35
|
-
status_report.net_amount.should == 50.
|
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:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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-
|
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
|