dineromail 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dineromail/status_report.rb +49 -21
- data/lib/dineromail/version.rb +1 -1
- data/spec/dineromail/status_report_spec.rb +3 -1
- metadata +3 -3
@@ -3,12 +3,20 @@ 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, :items
|
6
|
+
attr_accessor :transaction_id, :date,:report_status, :status, :amount, :net_amount, :pay_method, :pay_medium, :buyer, :items
|
7
7
|
|
8
8
|
PENDING_STATUS = 1
|
9
|
-
|
9
|
+
COMPLETED_STATUS = 2
|
10
10
|
CANCELLED_STATUS = 3
|
11
11
|
|
12
|
+
VALID_REPORT_STATUS = 1
|
13
|
+
MALFORMED_REPORT_STATUS = 2
|
14
|
+
INVALID_ACCOUNT_NUMBER_REPORT_STATUS = 3
|
15
|
+
INVALID_PASSWORD_REPORT_STATUS = 4
|
16
|
+
INVALID_REQUEST_TYPE_STATUS = 5
|
17
|
+
INVALID_TRANSACTION_ID_REQUEST_STATUS = 6
|
18
|
+
INVALID_PASSWORD_OR_ACCOUNT_NUMBER_REQUEST_STATUS = 7
|
19
|
+
TRANSACTION_NOT_FOUND_REQUEST_STATUS = 8
|
12
20
|
|
13
21
|
def initialize(transaction_id = nil)
|
14
22
|
@items = []
|
@@ -17,6 +25,22 @@ module Dineromail
|
|
17
25
|
end
|
18
26
|
end
|
19
27
|
|
28
|
+
def valid_report?
|
29
|
+
report_status == VALID_REPORT_STATUS
|
30
|
+
end
|
31
|
+
|
32
|
+
def pending?
|
33
|
+
status == PENDING_STATUS
|
34
|
+
end
|
35
|
+
|
36
|
+
def completed?
|
37
|
+
status == ACCREDITED_STATUS
|
38
|
+
end
|
39
|
+
|
40
|
+
def cancelled?
|
41
|
+
status == CANCELLED_STATUS
|
42
|
+
end
|
43
|
+
|
20
44
|
def obtain_status_report_data_for(transaction_id)
|
21
45
|
self.transaction_id = transaction_id
|
22
46
|
account_number = Dineromail.configuration.account_number
|
@@ -40,31 +64,35 @@ module Dineromail
|
|
40
64
|
|
41
65
|
def parse_response(response)
|
42
66
|
response_data = XmlSimple.xml_in(response,'KeyToSymbol' => true )
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
67
|
+
self.report_status = response_data[:estadoreporte].first.to_i
|
68
|
+
operations = response_data[:detalle].first[:operaciones].first
|
69
|
+
if operations
|
70
|
+
operation = operations[:operacion].first
|
71
|
+
self.transaction_id = operation[:id].first.to_i
|
72
|
+
self.date = DateTime.parse operation[:fecha].first
|
73
|
+
self.status = operation[:estado].first.to_i
|
74
|
+
self.amount = operation[:monto].first.to_f
|
75
|
+
self.net_amount = operation[:montoneto].first.to_f
|
76
|
+
self.pay_method = operation[:metodopago].first
|
77
|
+
self.pay_medium = operation[:mediopago].first
|
78
|
+
buyer_data = operation[:comprador].first
|
79
|
+
self.buyer = Buyer.new
|
80
|
+
buyer.email = buyer_data[:email].first
|
81
|
+
buyer.address = buyer_data[:direccion].first
|
82
|
+
buyer.comment = buyer_data[:comentario].first
|
83
|
+
buyer.name = buyer_data[:nombre].first
|
84
|
+
buyer.phone = buyer_data[:telefono].first
|
85
|
+
buyer.document_type = buyer_data[:tipodoc].first
|
86
|
+
buyer.document_number = buyer_data[:numerodoc].first
|
87
|
+
items_data = operation[:items].first[:item]
|
88
|
+
items_data.each do |item_data|
|
62
89
|
item = Item.new
|
63
90
|
item.description = item_data[:descripcion].first
|
64
91
|
item.currency = item_data[:moneda].first.to_i
|
65
92
|
item.unit_price = item_data[:preciounitario].first.to_f
|
66
93
|
item.count = item_data[:cantidad].first.to_i
|
67
94
|
self.items << item
|
95
|
+
end
|
68
96
|
end
|
69
97
|
end
|
70
98
|
|
data/lib/dineromail/version.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Dineromail::StatusReport do
|
4
4
|
it 'should load the status report from xml' do
|
5
|
-
xml = '<REPORTE><ESTADOREPORTE
|
5
|
+
xml = '<REPORTE><ESTADOREPORTE>1</ESTADOREPORTE><DETALLE><OPERACIONES><OPERACION>
|
6
6
|
<ID>1889</ID>
|
7
7
|
<FECHA>01/28/2011 12:02:01 PM</FECHA>
|
8
8
|
<ESTADO>1</ESTADO>
|
@@ -35,6 +35,8 @@ describe Dineromail::StatusReport do
|
|
35
35
|
buyer = status_report.buyer
|
36
36
|
item = status_report.items.first
|
37
37
|
|
38
|
+
status_report.report_status.should == 1
|
39
|
+
status_report.valid_report?.should be_true
|
38
40
|
status_report.transaction_id.should == 1889
|
39
41
|
status_report.date.should == DateTime.ordinal(2011,28,12,2,1)
|
40
42
|
status_report.status.should == Dineromail::StatusReport::PENDING_STATUS
|
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: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nicolas Mosconi
|