tray-checkout 0.3.2 → 0.4.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.
@@ -0,0 +1,183 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Tray::Checkout::TransactionResponseParser do
5
+ describe "#parse" do
6
+ context "with success response from temp_transaction" do
7
+ let(:xml) { body_for :create_temp_transaction_with_token }
8
+ let(:parser) { Tray::Checkout::TransactionResponseParser.new(xml) }
9
+ let(:response) { parser.parse }
10
+
11
+ it "returns success" do
12
+ response.success?.should be_true
13
+ end
14
+
15
+ context "returns transaction" do
16
+ {
17
+ token: "a906bf32cb59060dfc90769524f99d5a",
18
+ url_car: "\n\t\t\thttp://checkout.sandbox.tray.com.br/payment/car/v1/\n\t\t"
19
+ }.each do |param, value|
20
+ it param do
21
+ response.transaction[param].should == value
22
+ end
23
+ end
24
+ end
25
+
26
+ context "returns products" do
27
+ {
28
+ code: "teste",
29
+ img: "\n\t\t\t\t\thttp://catnross.com/wp-content/uploads/2011/08/product1.jpg\n\t\t\t\t",
30
+ sku_code: nil,
31
+ description: "produto teste",
32
+ extra: nil,
33
+ id: 4502,
34
+ type_product: nil
35
+ }.each do |param, value|
36
+ it param do
37
+ response.transaction[:products].first[param].should == value
38
+ end
39
+ end
40
+
41
+ {
42
+ price_unit: "10.0",
43
+ quantity: "5.0",
44
+ weight: "300.0"
45
+ }.each do |param, value|
46
+ it param do
47
+ response.transaction[:products].first[param].to_s.should == value
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ context "with success response" do
54
+ let(:xml) { body_for :get_success_boleto }
55
+ let(:parser) { Tray::Checkout::TransactionResponseParser.new(xml) }
56
+ let(:response) { parser.parse }
57
+
58
+ it "returns success" do
59
+ response.success?.should be_true
60
+ end
61
+
62
+ it "returns empty errors" do
63
+ response.errors.should be_empty
64
+ end
65
+
66
+ context "returns transaction" do
67
+ {
68
+ order_number: "1234567",
69
+ free: "Texto Interno",
70
+ status_name: "Em Recupera\\xC3\\xA7\\xC3\\xA3o",
71
+ status: :recovering,
72
+ id: 3856,
73
+ token: "4761d2e198ba6b60b45900a4d95482d5"
74
+ }.each do |param, value|
75
+ it param do
76
+ response.transaction[param].should == value
77
+ end
78
+ end
79
+ end
80
+
81
+ context "returns payment" do
82
+ {
83
+ tid: nil,
84
+ split: 1,
85
+ linha_digitavel: "34191.76007 00536.260144 50565.600009 6 58630000219999",
86
+ method: :boleto,
87
+ method_name: "Boleto Bancario"
88
+ }.each do |param, value|
89
+ it param do
90
+ response.payment[param].should == value
91
+ end
92
+ end
93
+
94
+ {
95
+ price_original: '2199.99',
96
+ price: '2199.99'
97
+ }.each do |param, value|
98
+ it param do
99
+ response.payment[param].to_s.should == value
100
+ end
101
+ end
102
+ end
103
+
104
+ context "returns customer" do
105
+ {
106
+ name: "Nome do Cliente",
107
+ cpf: "98489882380",
108
+ email: "emaildo@cliente.com.br",
109
+ company_name: nil,
110
+ trade_name: nil,
111
+ cnpj: nil
112
+ }.each do |param, value|
113
+ it param do
114
+ response.customer[param].should == value
115
+ end
116
+ end
117
+
118
+ context "address with" do
119
+ {
120
+ street: "Av Paulista",
121
+ number: "1001",
122
+ neighborhood: "Centro",
123
+ postal_code: "04001001",
124
+ completion: nil,
125
+ city: "S\\xC3\\xA3o Paulo",
126
+ state: "SP"
127
+ }.each do |param, value|
128
+ it param do
129
+ response.customer[:addresses].first[param].should == value
130
+ end
131
+ end
132
+ end
133
+
134
+ context "contacts with" do
135
+ [ {
136
+ number: "11998761234",
137
+ id: nil,
138
+ type: :mobile
139
+ }
140
+ ].each_with_index do |contacts, i|
141
+ contacts.each do |param, value|
142
+ it param do
143
+ response.customer[:contacts][i][param].should == value
144
+ end
145
+ end
146
+ end
147
+ end
148
+
149
+ context "without contacts" do
150
+ it "returns empty array" do
151
+ parser = Tray::Checkout::TransactionResponseParser.new(body_for(:get_success_boleto_without_contacts))
152
+ response = parser.parse
153
+ response.customer[:contacts].should == []
154
+ end
155
+ end
156
+ end
157
+ end
158
+
159
+ context "with error response" do
160
+ let(:xml) { body_for :get_failure_not_found }
161
+ let(:parser) { Tray::Checkout::ResponseParser.new(xml) }
162
+ let(:response) { parser.parse }
163
+
164
+ [:transaction, :payment, :customer].each do |info|
165
+ it "returns nil #{info}" do
166
+ response.send(info).should be_nil
167
+ end
168
+ end
169
+ end
170
+
171
+ context "with validation error response" do
172
+ let(:xml) { body_for :create_failure_validation_errors }
173
+ let(:parser) { Tray::Checkout::ResponseParser.new(xml) }
174
+ let(:response) { parser.parse }
175
+
176
+ [:transaction, :payment, :customer].each do |info|
177
+ it "returns nil #{info}" do
178
+ response.send(info).should be_nil
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
@@ -79,8 +79,13 @@ describe Tray::Checkout::Transaction do
79
79
 
80
80
  describe "#get" do
81
81
  context "token account is defined on the configuration" do
82
- before :each do
82
+ around do |example|
83
83
  Tray::Checkout.configure { |config| config.token_account = "8bfe5ddcb77207b" }
84
+ example.run
85
+ Tray::Checkout.configure { |config| config.token_account = nil }
86
+ end
87
+
88
+ before :each do
84
89
  VCR.use_cassette 'model/get_success_boleto' do
85
90
  @response = transaction.get("4761d2e198ba6b60b45900a4d95482d5")
86
91
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tray-checkout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-12 00:00:00.000000000 Z
12
+ date: 2013-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -122,16 +122,19 @@ files:
122
122
  - Rakefile
123
123
  - lib/tray-checkout.rb
124
124
  - lib/tray/checkout.rb
125
- - lib/tray/checkout/base_transaction.rb
125
+ - lib/tray/checkout/account.rb
126
+ - lib/tray/checkout/account_response_parser.rb
127
+ - lib/tray/checkout/base_service.rb
126
128
  - lib/tray/checkout/config.rb
127
129
  - lib/tray/checkout/constants.rb
128
130
  - lib/tray/checkout/hash.rb
131
+ - lib/tray/checkout/params_parser.rb
129
132
  - lib/tray/checkout/parser.rb
130
133
  - lib/tray/checkout/response.rb
131
134
  - lib/tray/checkout/response_parser.rb
132
135
  - lib/tray/checkout/temp_transaction.rb
133
136
  - lib/tray/checkout/transaction.rb
134
- - lib/tray/checkout/transaction_params_parser.rb
137
+ - lib/tray/checkout/transaction_response_parser.rb
135
138
  - lib/tray/checkout/uri.rb
136
139
  - lib/tray/checkout/version.rb
137
140
  - lib/tray/checkout/web_service.rb
@@ -141,6 +144,7 @@ files:
141
144
  - spec/support/responses/create_success_boleto.xml
142
145
  - spec/support/responses/create_success_mastercard.xml
143
146
  - spec/support/responses/create_temp_transaction_with_token.xml
147
+ - spec/support/responses/get_account_info.xml
144
148
  - spec/support/responses/get_failure_not_found.xml
145
149
  - spec/support/responses/get_success_boleto.xml
146
150
  - spec/support/responses/get_success_boleto_without_contacts.xml
@@ -151,14 +155,19 @@ files:
151
155
  - spec/support/vcr/model/create_success_mastercard.yml
152
156
  - spec/support/vcr/model/get_failure_not_found.yml
153
157
  - spec/support/vcr/model/get_success_boleto.yml
158
+ - spec/support/vcr/model/invalid_token.yml
154
159
  - spec/support/vcr/model/update_cart.yml
160
+ - spec/support/vcr/model/valid_token.yml
155
161
  - spec/support/vcr_setup.rb
162
+ - spec/tray/checkout/account_response_parser_spec.rb
163
+ - spec/tray/checkout/account_spec.rb
156
164
  - spec/tray/checkout/hash_spec.rb
165
+ - spec/tray/checkout/params_parser_spec.rb
157
166
  - spec/tray/checkout/parser_spec.rb
158
167
  - spec/tray/checkout/response_parser_spec.rb
159
168
  - spec/tray/checkout/response_spec.rb
160
169
  - spec/tray/checkout/temp_transaction_spec.rb
161
- - spec/tray/checkout/transaction_params_parser_spec.rb
170
+ - spec/tray/checkout/transaction_response_parser_spec.rb
162
171
  - spec/tray/checkout/transaction_spec.rb
163
172
  - spec/tray/checkout/uri_spec.rb
164
173
  - spec/tray/checkout/web_service_spec.rb
@@ -185,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
194
  version: '0'
186
195
  segments:
187
196
  - 0
188
- hash: -3269883588982628234
197
+ hash: -3900495863757727813
189
198
  requirements: []
190
199
  rubyforge_project:
191
200
  rubygems_version: 1.8.25
@@ -199,6 +208,7 @@ test_files:
199
208
  - spec/support/responses/create_success_boleto.xml
200
209
  - spec/support/responses/create_success_mastercard.xml
201
210
  - spec/support/responses/create_temp_transaction_with_token.xml
211
+ - spec/support/responses/get_account_info.xml
202
212
  - spec/support/responses/get_failure_not_found.xml
203
213
  - spec/support/responses/get_success_boleto.xml
204
214
  - spec/support/responses/get_success_boleto_without_contacts.xml
@@ -209,14 +219,19 @@ test_files:
209
219
  - spec/support/vcr/model/create_success_mastercard.yml
210
220
  - spec/support/vcr/model/get_failure_not_found.yml
211
221
  - spec/support/vcr/model/get_success_boleto.yml
222
+ - spec/support/vcr/model/invalid_token.yml
212
223
  - spec/support/vcr/model/update_cart.yml
224
+ - spec/support/vcr/model/valid_token.yml
213
225
  - spec/support/vcr_setup.rb
226
+ - spec/tray/checkout/account_response_parser_spec.rb
227
+ - spec/tray/checkout/account_spec.rb
214
228
  - spec/tray/checkout/hash_spec.rb
229
+ - spec/tray/checkout/params_parser_spec.rb
215
230
  - spec/tray/checkout/parser_spec.rb
216
231
  - spec/tray/checkout/response_parser_spec.rb
217
232
  - spec/tray/checkout/response_spec.rb
218
233
  - spec/tray/checkout/temp_transaction_spec.rb
219
- - spec/tray/checkout/transaction_params_parser_spec.rb
234
+ - spec/tray/checkout/transaction_response_parser_spec.rb
220
235
  - spec/tray/checkout/transaction_spec.rb
221
236
  - spec/tray/checkout/uri_spec.rb
222
237
  - spec/tray/checkout/web_service_spec.rb
@@ -1,152 +0,0 @@
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
-
126
- it "keeps token account supplied in params" do
127
- transaction_params[:token_account].should == params[:token_account]
128
- end
129
-
130
- context "when sets token account in configuration" do
131
- around do |example|
132
- Tray::Checkout.configure { |config| config.token_account = "1q2w3e4r5t6y7u8" }
133
- example.run
134
- Tray::Checkout.configure { |config| config.token_account = nil }
135
- end
136
-
137
- context "and token account is supplied in params" do
138
- it "keeps token account supplied in params" do
139
- transaction_params[:token_account].should == params[:token_account]
140
- end
141
- end
142
-
143
- context "and token account is not supplied in params" do
144
- it "uses token account from configuration" do
145
- params.delete(:token_account)
146
- transaction_params = Tray::Checkout::TransactionParamsParser.new(params).parse
147
- transaction_params[:token_account].should == "1q2w3e4r5t6y7u8"
148
- end
149
- end
150
- end
151
- end
152
- end