tray-checkout 0.0.1 → 0.1.0
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/CHANGELOG.rdoc +4 -0
- data/README.rdoc +77 -49
- data/lib/tray/checkout/hash.rb +9 -15
- data/lib/tray/checkout/parser.rb +5 -88
- data/lib/tray/checkout/response.rb +19 -0
- data/lib/tray/checkout/response_parser.rb +114 -0
- data/lib/tray/checkout/transaction.rb +9 -5
- data/lib/tray/checkout/transaction_params_parser.rb +55 -0
- data/lib/tray/checkout/version.rb +1 -1
- data/lib/tray-checkout.rb +3 -0
- data/spec/support/mock_request.rb +1 -0
- data/spec/support/responses/create_failure_validation_errors.xml +1 -0
- data/spec/support/responses/create_success_boleto.xml +53 -236
- data/spec/support/responses/create_success_mastercard.xml +53 -224
- data/spec/support/responses/get_success_boleto.xml +56 -66
- data/spec/support/responses/get_success_mastercard.xml +101 -0
- data/spec/tray/checkout/hash_spec.rb +10 -9
- data/spec/tray/checkout/parser_spec.rb +29 -179
- data/spec/tray/checkout/response_parser_spec.rb +187 -0
- data/spec/tray/checkout/response_spec.rb +16 -0
- data/spec/tray/checkout/transaction_params_parser_spec.rb +126 -0
- data/spec/tray/checkout/transaction_spec.rb +34 -20
- metadata +24 -13
@@ -5,198 +5,48 @@ describe Tray::Checkout::Parser do
|
|
5
5
|
let(:parser) { Tray::Checkout::Parser.new }
|
6
6
|
|
7
7
|
describe "#response" do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
txn[:success].should be_true
|
14
|
-
end
|
15
|
-
|
16
|
-
context "returns transaction" do
|
17
|
-
{ transaction_token: "522045453u5uu32e0u8014f060uuu5uu",
|
18
|
-
transaction_id: 501,
|
19
|
-
payment_method: :boleto,
|
20
|
-
payment_method_id: 6,
|
21
|
-
payment_method_name: "Boleto Bancario",
|
22
|
-
status: :waiting_payment,
|
23
|
-
status_id: 4,
|
24
|
-
status_name: "Aguardando Pagamento",
|
25
|
-
order_number: "R1240",
|
26
|
-
price_original: 213.21,
|
27
|
-
price_payment: 213.21,
|
28
|
-
price_seller: 199.19,
|
29
|
-
price_additional: 0.00,
|
30
|
-
price_discount: 0.00,
|
31
|
-
shipping_type: "Sedex",
|
32
|
-
shipping_price: 1.23,
|
33
|
-
split: 1,
|
34
|
-
url_notification: "http://prodis.blog.br/tray_notification",
|
35
|
-
seller_token: "949u5uu9ef36f7u"
|
36
|
-
}.each do |param, value|
|
37
|
-
it param do
|
38
|
-
txn[param].should == value
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it "date_transaction" do
|
43
|
-
date_transaction = txn[:date_transaction]
|
44
|
-
date_transaction.should be_a(Time)
|
45
|
-
date_transaction.to_s.should == "2012-12-03 18:08:37 UTC"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "returns payment" do
|
50
|
-
{ payment_method: :boleto,
|
51
|
-
payment_method_id: 6,
|
52
|
-
payment_method_name: "Boleto Bancario",
|
53
|
-
price_payment: 213.21,
|
54
|
-
split: 1,
|
55
|
-
number_proccess: 718,
|
56
|
-
url_payment: "http://checkout.sandbox.tray.com.br/payment/billet/u9uuu8731319u59u3073u9011uu6u6uu"
|
57
|
-
}.each do |param, value|
|
58
|
-
it param do
|
59
|
-
txn[:payment][param].should == value
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it "date_approval" do
|
64
|
-
date_approval = txn[:payment][:date_approval]
|
65
|
-
date_approval.should be_a(Time)
|
66
|
-
date_approval.to_s.should == "2012-12-04 00:55:15 UTC"
|
67
|
-
end
|
68
|
-
end
|
8
|
+
before :each do
|
9
|
+
@xml = body_for(:get_success_boleto)
|
10
|
+
@response_parser = Tray::Checkout::ResponseParser.new(@xml)
|
11
|
+
@response = Tray::Checkout::Response.new
|
12
|
+
Tray::Checkout::ResponseParser.stub(:new).and_return(@response_parser)
|
69
13
|
end
|
70
14
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
it "does not return success" do
|
76
|
-
txn[:success].should be_false
|
77
|
-
end
|
78
|
-
|
79
|
-
context "returns error" do
|
80
|
-
{ code: "003042",
|
81
|
-
message: "Transação não encontrada"
|
82
|
-
}.each do |param, value|
|
83
|
-
it param do
|
84
|
-
txn[:errors].first[param].should == value
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
15
|
+
it "creates response parser" do
|
16
|
+
Tray::Checkout::ResponseParser.should_receive(:new).with(@xml)
|
17
|
+
parser.response(@xml)
|
88
18
|
end
|
89
19
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
it "does not return success" do
|
95
|
-
txn[:success].should be_false
|
96
|
-
end
|
97
|
-
|
98
|
-
context "returns error" do
|
99
|
-
{ code: "1",
|
100
|
-
message: "não pode ficar em branco",
|
101
|
-
message_complete: "Tipo não pode ficar em branco",
|
102
|
-
field: "person_addresses.type_address"
|
103
|
-
}.each do |param, value|
|
104
|
-
it param do
|
105
|
-
txn[:errors].first[param].should == value
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
20
|
+
it "parses response" do
|
21
|
+
@response_parser.should_receive(:parse).and_return(@response)
|
22
|
+
parser.response(@xml).should == @response
|
109
23
|
end
|
110
24
|
end
|
111
25
|
|
112
|
-
describe "#
|
113
|
-
|
114
|
-
{
|
26
|
+
describe "#transaction_params" do
|
27
|
+
before :each do
|
28
|
+
@params = {
|
115
29
|
token_account: "949u5uu9ef36f7u",
|
116
|
-
customer: {
|
117
|
-
|
118
|
-
cpf: "18565842673",
|
119
|
-
email: "pedro@bo.com.br",
|
120
|
-
sex: :male,
|
121
|
-
marital_status: :single,
|
122
|
-
contacts: [
|
123
|
-
{ contact_type: :home,
|
124
|
-
number_contact: "1142360873"
|
125
|
-
},
|
126
|
-
{ contact_type: :mobile,
|
127
|
-
number_contact: "11987654321"
|
128
|
-
},
|
129
|
-
{ contact_type: :work,
|
130
|
-
number_contact: "1134567890"
|
131
|
-
}
|
132
|
-
],
|
133
|
-
addresses: [
|
134
|
-
{ address_type: :billing,
|
135
|
-
street: "Avenida Pedro Alvares Cabral",
|
136
|
-
number: "123",
|
137
|
-
neighborhood: "Parque Ibirapuera",
|
138
|
-
postal_code: "04094050",
|
139
|
-
city: "São Paulo",
|
140
|
-
state: "SP"
|
141
|
-
},
|
142
|
-
{ address_type: :delivery,
|
143
|
-
street: "Avenida Pedro Alvares Cabral",
|
144
|
-
number: "123",
|
145
|
-
neighborhood: "Parque Ibirapuera",
|
146
|
-
postal_code: "04094050",
|
147
|
-
city: "São Paulo",
|
148
|
-
state: "SP"
|
149
|
-
}
|
150
|
-
]
|
151
|
-
},
|
152
|
-
transaction: {
|
153
|
-
order_number: "R1245",
|
154
|
-
shipping_type: "Sedex",
|
155
|
-
shipping_price: 13.94,
|
156
|
-
url_notification: "http://prodis.blog.br/tray_notification"
|
157
|
-
},
|
158
|
-
transaction_product: [
|
159
|
-
{ code: "LOGO-8278",
|
160
|
-
quantity: 2,
|
161
|
-
price_unit: 100.99,
|
162
|
-
description: "Logo Prodis"
|
163
|
-
}
|
164
|
-
],
|
165
|
-
payment: {
|
166
|
-
payment_method: :mastercard,
|
167
|
-
split: 3,
|
168
|
-
card_name: "ZEFINHA NOCEGA",
|
169
|
-
card_number: "5105105105105100",
|
170
|
-
card_expdate_month: "09",
|
171
|
-
card_expdate_year: "2015",
|
172
|
-
card_cvv: "123"
|
173
|
-
}
|
30
|
+
customer: { name: "Pedro Bonamides", sex: :male },
|
31
|
+
payment: { payment_method: :boleto_bancario }
|
174
32
|
}
|
33
|
+
@transaction_params = {
|
34
|
+
token_account: "949u5uu9ef36f7u",
|
35
|
+
customer: { name: "Pedro Bonamides", sex: :male, gender: "M" },
|
36
|
+
payment: { payment_method: :boleto, payment_method_id: "6" }
|
37
|
+
}
|
38
|
+
@transaction_params_parser = Tray::Checkout::TransactionParamsParser.new(@params)
|
39
|
+
Tray::Checkout::TransactionParamsParser.stub(:new).and_return(@transaction_params_parser)
|
175
40
|
end
|
176
41
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
txn[:customer][:gender].should == "M"
|
181
|
-
end
|
182
|
-
|
183
|
-
it "sets customer relationship expect API value" do
|
184
|
-
txn[:customer][:relationship].should == "S"
|
185
|
-
end
|
186
|
-
|
187
|
-
it "sets customer contact type expect API value" do
|
188
|
-
txn[:customer][:contacts][0][:type_contact].should == "H"
|
189
|
-
txn[:customer][:contacts][1][:type_contact].should == "M"
|
190
|
-
txn[:customer][:contacts][2][:type_contact].should == "W"
|
191
|
-
end
|
192
|
-
|
193
|
-
it "sets customer address type expect API value" do
|
194
|
-
txn[:customer][:addresses][0][:type_address].should == "B"
|
195
|
-
txn[:customer][:addresses][1][:type_address].should == "D"
|
42
|
+
it "creates transaction params parser" do
|
43
|
+
Tray::Checkout::TransactionParamsParser.should_receive(:new).with(@params)
|
44
|
+
parser.transaction_params(@params)
|
196
45
|
end
|
197
46
|
|
198
|
-
it "
|
199
|
-
|
47
|
+
it "parses params" do
|
48
|
+
@transaction_params_parser.should_receive(:parse).and_return(@transaction_params)
|
49
|
+
parser.transaction_params(@params).should == @transaction_params
|
200
50
|
end
|
201
51
|
end
|
202
52
|
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Tray::Checkout::ResponseParser do
|
5
|
+
describe "#parse" do
|
6
|
+
context "with success response" do
|
7
|
+
let(:xml) { body_for :get_success_boleto }
|
8
|
+
let(:parser) { Tray::Checkout::ResponseParser.new(xml) }
|
9
|
+
let(:response) { parser.parse }
|
10
|
+
|
11
|
+
it "returns success" do
|
12
|
+
response.success?.should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns empty errors" do
|
16
|
+
response.errors.should be_empty
|
17
|
+
end
|
18
|
+
|
19
|
+
context "returns transaction" do
|
20
|
+
{ token: "db9b3265af6e7e19af8dd70e00d77383x",
|
21
|
+
id: 530,
|
22
|
+
status: :approved,
|
23
|
+
status_name: "Aprovada",
|
24
|
+
order_number: "F2456",
|
25
|
+
price_original: 33.21,
|
26
|
+
price_payment: 33.21,
|
27
|
+
price_seller: 30.69,
|
28
|
+
price_additional: 0.00,
|
29
|
+
price_discount: 0.00,
|
30
|
+
shipping_type: "Sedex",
|
31
|
+
shipping_price: 1.23,
|
32
|
+
split: 1,
|
33
|
+
url_notification: "http://prodis.blog.br/tray_notification",
|
34
|
+
transaction_token: nil,
|
35
|
+
transaction_id: nil,
|
36
|
+
status_id: nil
|
37
|
+
}.each do |param, value|
|
38
|
+
it param do
|
39
|
+
response.transaction[param].should == value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "date_transaction" do
|
44
|
+
date_transaction = response.transaction[:date_transaction]
|
45
|
+
date_transaction.should be_a(Time)
|
46
|
+
date_transaction.to_s.should == "2012-12-13 02:49:42 UTC"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "returns payment" do
|
51
|
+
{ method: :boleto,
|
52
|
+
method_name: "Boleto Bancario",
|
53
|
+
price: 33.21,
|
54
|
+
split: 1,
|
55
|
+
number_proccess: 750,
|
56
|
+
response: "Texto de resposta fake.",
|
57
|
+
url: "http://checkout.sandbox.tray.com.br/payment/billet/d2baa84c13f23addde401c8e1426396e",
|
58
|
+
linha_digitavel: "34191.76007 00075.091140 53021.450001 1 55510000003321",
|
59
|
+
payment_method_id: nil,
|
60
|
+
payment_method_name: nil,
|
61
|
+
price_payment: nil,
|
62
|
+
url_payment: nil,
|
63
|
+
payment_response: nil
|
64
|
+
}.each do |param, value|
|
65
|
+
it param do
|
66
|
+
response.payment[param].should == value
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
{ date_approval: "2012-12-15 15:24:38 UTC",
|
71
|
+
date_payment: "2012-12-15 15:23:05 UTC"
|
72
|
+
}.each do |param, value|
|
73
|
+
it param do
|
74
|
+
response.payment[param].should be_a(Time)
|
75
|
+
response.payment[param].to_s.should == value
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "returns customer" do
|
81
|
+
{ name: "Pedro Bonamides",
|
82
|
+
email: "pedro@bo.com.br",
|
83
|
+
cpf: "18565842673"
|
84
|
+
}.each do |param, value|
|
85
|
+
it param do
|
86
|
+
response.customer[param].should == value
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "address with" do
|
91
|
+
{ street: "Avenida Pedro Alvares Cabral",
|
92
|
+
number: "123",
|
93
|
+
neighborhood: "Parque Ibirapuera",
|
94
|
+
postal_code: "04094050",
|
95
|
+
completion: nil,
|
96
|
+
city: "São Paulo",
|
97
|
+
state: "SP"
|
98
|
+
}.each do |param, value|
|
99
|
+
it param do
|
100
|
+
response.customer[:addresses].first[param].should == value
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "contacts with" do
|
106
|
+
[ { id: 345,
|
107
|
+
number: "1137654321",
|
108
|
+
type: :home,
|
109
|
+
primary: true,
|
110
|
+
contact_id: nil,
|
111
|
+
value: nil,
|
112
|
+
type_contact: nil
|
113
|
+
},
|
114
|
+
{ id: 348,
|
115
|
+
number: "11987654321",
|
116
|
+
type: :mobile,
|
117
|
+
primary: false,
|
118
|
+
contact_id: nil,
|
119
|
+
value: nil,
|
120
|
+
type_contact: nil
|
121
|
+
}
|
122
|
+
].each_with_index do |contacts, i|
|
123
|
+
contacts.each do |param, value|
|
124
|
+
it param do
|
125
|
+
response.customer[:contacts][i][param].should == value
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "with error response" do
|
134
|
+
let(:xml) { body_for :get_failure_not_found }
|
135
|
+
let(:parser) { Tray::Checkout::ResponseParser.new(xml) }
|
136
|
+
let(:response) { parser.parse }
|
137
|
+
|
138
|
+
it "does not return success" do
|
139
|
+
response.success?.should be_false
|
140
|
+
end
|
141
|
+
|
142
|
+
[:transaction, :payment, :customer].each do |info|
|
143
|
+
it "returns nil #{info}" do
|
144
|
+
response.send(info).should be_nil
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "returns error" do
|
149
|
+
{ code: "003042",
|
150
|
+
message: "Transação não encontrada"
|
151
|
+
}.each do |param, value|
|
152
|
+
it param do
|
153
|
+
response.errors.first[param].should == value
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context "with validation error response" do
|
160
|
+
let(:xml) { body_for :create_failure_validation_errors }
|
161
|
+
let(:parser) { Tray::Checkout::ResponseParser.new(xml) }
|
162
|
+
let(:response) { parser.parse }
|
163
|
+
|
164
|
+
it "does not return success" do
|
165
|
+
response.success?.should be_false
|
166
|
+
end
|
167
|
+
|
168
|
+
[:transaction, :payment, :customer].each do |info|
|
169
|
+
it "returns nil #{info}" do
|
170
|
+
response.send(info).should be_nil
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "returns error" do
|
175
|
+
{ code: "1",
|
176
|
+
message: "não pode ficar em branco",
|
177
|
+
message_complete: "Tipo não pode ficar em branco",
|
178
|
+
field: "person_addresses.type_address"
|
179
|
+
}.each do |param, value|
|
180
|
+
it param do
|
181
|
+
response.errors.first[param].should == value
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Tray::Checkout::Response do
|
5
|
+
let(:response) { Tray::Checkout::Response.new }
|
6
|
+
|
7
|
+
describe ".new" do
|
8
|
+
it "sets success to false" do
|
9
|
+
response.success?.should be_false
|
10
|
+
end
|
11
|
+
|
12
|
+
it "sets errors to empty" do
|
13
|
+
response.errors.should be_empty
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Tray::Checkout::TransactionParamsParser do
|
5
|
+
let :params do
|
6
|
+
{
|
7
|
+
token_account: "949u5uu9ef36f7u",
|
8
|
+
customer: {
|
9
|
+
name: "Pedro Bonamides",
|
10
|
+
cpf: "18565842673",
|
11
|
+
email: "pedro@bo.com.br",
|
12
|
+
sex: :male,
|
13
|
+
marital_status: :single,
|
14
|
+
contacts: [
|
15
|
+
{ type: :home, number: "1142360873" },
|
16
|
+
{ type: :mobile, number: "11987654321" },
|
17
|
+
{ type: :work, number: "1134567890" }
|
18
|
+
],
|
19
|
+
addresses: [
|
20
|
+
{ type: :billing,
|
21
|
+
street: "Avenida Pedro Alvares Cabral",
|
22
|
+
number: "123",
|
23
|
+
neighborhood: "Parque Ibirapuera",
|
24
|
+
postal_code: "04094050",
|
25
|
+
city: "São Paulo",
|
26
|
+
state: "SP"
|
27
|
+
},
|
28
|
+
{ type: :delivery,
|
29
|
+
street: "Avenida Pedro Alvares Cabral",
|
30
|
+
number: "123",
|
31
|
+
neighborhood: "Parque Ibirapuera",
|
32
|
+
postal_code: "04094050",
|
33
|
+
city: "São Paulo",
|
34
|
+
state: "SP"
|
35
|
+
}
|
36
|
+
]
|
37
|
+
},
|
38
|
+
transaction: {
|
39
|
+
order_number: "R1245",
|
40
|
+
shipping_type: "Sedex",
|
41
|
+
shipping_price: 13.94,
|
42
|
+
url_notification: "http://prodis.blog.br/tray_notification",
|
43
|
+
products: [
|
44
|
+
{ code: "LOGO-8278",
|
45
|
+
quantity: 2,
|
46
|
+
price_unit: 100.99,
|
47
|
+
description: "Logo Prodis"
|
48
|
+
},
|
49
|
+
{ code: "877",
|
50
|
+
quantity: 1,
|
51
|
+
price_unit: 10.00,
|
52
|
+
description: "Outro produto"
|
53
|
+
}
|
54
|
+
]
|
55
|
+
},
|
56
|
+
payment: {
|
57
|
+
method: :mastercard,
|
58
|
+
split: 3,
|
59
|
+
card: {
|
60
|
+
name: "ZEFINHA NOCEGA",
|
61
|
+
number: "5105105105105100",
|
62
|
+
expdate_month: "09",
|
63
|
+
expdate_year: "2015",
|
64
|
+
cvv: "123"
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
let(:parser) { Tray::Checkout::TransactionParamsParser.new(params) }
|
71
|
+
let(:transaction_params) { parser.parse }
|
72
|
+
|
73
|
+
describe "#parse" do
|
74
|
+
it "sets customer gender expect API value" do
|
75
|
+
transaction_params[:customer][:gender].should == "M"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "sets customer relationship expect API value" do
|
79
|
+
transaction_params[:customer][:relationship].should == "S"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "sets customer contact type expect API value" do
|
83
|
+
transaction_params[:customer][:contacts][0][:type_contact].should == "H"
|
84
|
+
transaction_params[:customer][:contacts][1][:type_contact].should == "M"
|
85
|
+
transaction_params[:customer][:contacts][2][:type_contact].should == "W"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "sets customer contact number expect API value" do
|
89
|
+
transaction_params[:customer][:contacts][0][:number_contact].should == "1142360873"
|
90
|
+
transaction_params[:customer][:contacts][1][:number_contact].should == "11987654321"
|
91
|
+
transaction_params[:customer][:contacts][2][:number_contact].should == "1134567890"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "sets customer address type expect API value" do
|
95
|
+
transaction_params[:customer][:addresses][0][:type_address].should == "B"
|
96
|
+
transaction_params[:customer][:addresses][1][:type_address].should == "D"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "sets payment method ID expect API value" do
|
100
|
+
transaction_params[:payment][:payment_method_id].should == 4
|
101
|
+
end
|
102
|
+
|
103
|
+
{ card_name: "ZEFINHA NOCEGA",
|
104
|
+
card_number: "5105105105105100",
|
105
|
+
card_expdate_month: "09",
|
106
|
+
card_expdate_year: "2015",
|
107
|
+
card_cvv: "123"
|
108
|
+
}.each do |param, value|
|
109
|
+
it "sets payment #{param}" do
|
110
|
+
transaction_params[:payment][param].should == value
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
it "sets products as expect API data structure" do
|
115
|
+
transaction_params[:transaction_product][0][:code].should == "LOGO-8278"
|
116
|
+
transaction_params[:transaction_product][0][:quantity].should == 2
|
117
|
+
transaction_params[:transaction_product][0][:price_unit].should == 100.99
|
118
|
+
transaction_params[:transaction_product][0][:description].should == "Logo Prodis"
|
119
|
+
|
120
|
+
transaction_params[:transaction_product][1][:code].should == "877"
|
121
|
+
transaction_params[:transaction_product][1][:quantity].should == 1
|
122
|
+
transaction_params[:transaction_product][1][:price_unit].should == 10.00
|
123
|
+
transaction_params[:transaction_product][1][:description].should == "Outro produto"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -8,37 +8,42 @@ describe Tray::Checkout::Transaction do
|
|
8
8
|
context "when transaction is found" do
|
9
9
|
before :each do
|
10
10
|
mock_request_for(:get_success_boleto)
|
11
|
-
@
|
11
|
+
@response = transaction.get("db9b3265af6e7e19af8dd70e00d77383x")
|
12
12
|
end
|
13
13
|
|
14
14
|
it "returns success" do
|
15
|
-
@
|
15
|
+
@response.success?.should be_true
|
16
16
|
end
|
17
17
|
|
18
18
|
it "returns transaction data" do
|
19
|
-
@
|
20
|
-
@
|
19
|
+
@response.transaction[:token].should == "db9b3265af6e7e19af8dd70e00d77383x"
|
20
|
+
@response.transaction[:id].should == 530
|
21
21
|
end
|
22
22
|
|
23
23
|
it "returns payment data" do
|
24
|
-
@
|
25
|
-
@
|
24
|
+
@response.payment[:method_name].should == "Boleto Bancario"
|
25
|
+
@response.payment[:url].should == "http://checkout.sandbox.tray.com.br/payment/billet/d2baa84c13f23addde401c8e1426396e"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns customer data" do
|
29
|
+
@response.customer[:name].should == "Pedro Bonamides"
|
30
|
+
@response.customer[:email].should == "pedro@bo.com.br"
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
29
34
|
context "when transaction is not found" do
|
30
35
|
before :each do
|
31
36
|
mock_request_for(:get_failure_not_found)
|
32
|
-
@
|
37
|
+
@response = transaction.get("987asd654lkj321qwe098poi")
|
33
38
|
end
|
34
39
|
|
35
40
|
it "does not return success" do
|
36
|
-
@
|
41
|
+
@response.success?.should be_false
|
37
42
|
end
|
38
43
|
|
39
44
|
it "returns errors" do
|
40
|
-
@
|
41
|
-
@
|
45
|
+
@response.errors.first[:code].should == "003042"
|
46
|
+
@response.errors.first[:message].should == "Transação não encontrada"
|
42
47
|
end
|
43
48
|
end
|
44
49
|
end
|
@@ -47,34 +52,43 @@ describe Tray::Checkout::Transaction do
|
|
47
52
|
context "successful" do
|
48
53
|
before :each do
|
49
54
|
mock_request_for(:create_success_mastercard)
|
50
|
-
@
|
55
|
+
@response = transaction.create(fake: "fake params")
|
51
56
|
end
|
52
57
|
|
53
58
|
it "returns success" do
|
54
|
-
@
|
59
|
+
@response.success?.should be_true
|
55
60
|
end
|
56
61
|
|
57
62
|
it "returns transaction data" do
|
58
|
-
@
|
59
|
-
@
|
60
|
-
|
63
|
+
@response.transaction[:token].should == "fc739f786425e34010481dcc2939e4bdx"
|
64
|
+
@response.transaction[:status].should == :approved
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns payment data" do
|
68
|
+
@response.payment[:method].should == :mastercard
|
69
|
+
@response.payment[:tid].should == "1355409331"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns customer data" do
|
73
|
+
@response.customer[:name].should == "Pedro Bonamides"
|
74
|
+
@response.customer[:email].should == "pedro@bo.com.br"
|
61
75
|
end
|
62
76
|
end
|
63
77
|
|
64
78
|
context "unsuccess" do
|
65
79
|
before :each do
|
66
80
|
mock_request_for(:create_failure_validation_errors)
|
67
|
-
@
|
81
|
+
@response = transaction.create(fake: "fake params")
|
68
82
|
end
|
69
83
|
|
70
84
|
it "does not return success" do
|
71
|
-
@
|
85
|
+
@response.success?.should be_false
|
72
86
|
end
|
73
87
|
|
74
88
|
it "returns error" do
|
75
|
-
@
|
76
|
-
@
|
77
|
-
@
|
89
|
+
@response.errors.first[:code].should == "1"
|
90
|
+
@response.errors.first[:message].should == "não pode ficar em branco"
|
91
|
+
@response.errors.first[:message_complete].should == "Tipo não pode ficar em branco"
|
78
92
|
end
|
79
93
|
end
|
80
94
|
end
|