tray-checkout 0.1.0 → 0.2.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 +5 -0
- data/README.rdoc +271 -1
- data/lib/tray/checkout/config.rb +29 -0
- data/lib/tray/checkout/transaction.rb +1 -4
- data/lib/tray/checkout/transaction_params_parser.rb +5 -0
- data/lib/tray/checkout/uri.rb +6 -0
- data/lib/tray/checkout/version.rb +1 -1
- data/lib/tray/checkout/web_service.rb +43 -1
- data/lib/tray/checkout.rb +1 -10
- data/lib/tray-checkout.rb +3 -1
- data/spec/spec_helper.rb +4 -0
- data/spec/support/mock_request.rb +1 -1
- data/spec/tray/checkout/transaction_params_parser_spec.rb +26 -0
- data/spec/tray/checkout/uri_spec.rb +20 -0
- data/spec/tray/checkout/web_service_spec.rb +1 -1
- data/spec/tray/checkout_spec.rb +40 -0
- metadata +17 -13
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -130,6 +130,276 @@ Creating a successful transaction:
|
|
130
130
|
response.customer[:email] # => "pedro@bo.com.br"
|
131
131
|
response.customer[:cpf] # => "18565842673"
|
132
132
|
|
133
|
+
== Configurations
|
134
|
+
|
135
|
+
=== Environment
|
136
|
+
Tray Checkout API works with two environments: <b>production</b> and <b>sandbox</b>. To config the environment use <b>Tray::Checkout</b> module.
|
137
|
+
Default environment is <b>:production</b>.
|
138
|
+
|
139
|
+
Tray::Checkout.configure do |config|
|
140
|
+
config.environment = :sandbox
|
141
|
+
end
|
142
|
+
|
143
|
+
=== Token Account
|
144
|
+
To create transactions is necessary to provide a <b>token account</b>. You can supply it in Tray::Checkout::Transaction#create method params, for each method call, or to config token account once using <b>Tray::Checkout</b> module.
|
145
|
+
|
146
|
+
Tray::Checkout.configure do |config|
|
147
|
+
config.token_account = "123u5uu9ef36f7u"
|
148
|
+
end
|
149
|
+
|
150
|
+
=== Timeout
|
151
|
+
|
152
|
+
For default, the timeout for a request to Tray Checkout API is <b>5 seconds</b>. If Tray Checkout API does not respond, a <b>Timeout::Error</b> exception will be raised.
|
153
|
+
You can configure this timeout using <b>Tray::Checkout</b> module.
|
154
|
+
|
155
|
+
Tray::Checkout.configure do |config|
|
156
|
+
config.request_timeout = 3 # It configures timeout to 3 seconds
|
157
|
+
end
|
158
|
+
|
159
|
+
=== Log
|
160
|
+
|
161
|
+
For default, each request to Tray Checkout API is logged to STDOUT, with <b>:info</b> log level, using the gem {LogMe}[http://github.com/prodis/log-me].
|
162
|
+
|
163
|
+
Log example:
|
164
|
+
I, [2013-01-11T00:55:10.531780 #22692] INFO -- : Tray-Checkout Request:
|
165
|
+
POST http://api.sandbox.checkout.tray.com.br/api/v1/transactions/get_by_token
|
166
|
+
token=522045453u5uu32e0u8014f060uuu5uu
|
167
|
+
|
168
|
+
I, [2013-01-11T00:55:10.750308 #22692] INFO -- : Tray-Checkout Response:
|
169
|
+
HTTP/1.1 200 OK
|
170
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
171
|
+
<transaction>
|
172
|
+
<data_response>
|
173
|
+
<transaction>
|
174
|
+
<order_number>F4326</order_number>
|
175
|
+
<free nil="true"/>
|
176
|
+
<transaction_id type="integer">632</transaction_id>
|
177
|
+
<status_name>Aguardando Pagamento</status_name>
|
178
|
+
<status_id type="integer">4</status_id>
|
179
|
+
<date_transaction>2012-12-27T10:26:21</date_transaction>
|
180
|
+
<split type="integer">1</split>
|
181
|
+
<price_payment type="decimal">37.86</price_payment>
|
182
|
+
<date_payment></date_payment>
|
183
|
+
<transaction_token>522045453u5uu32e0u8014f060uuu5uu</transaction_token>
|
184
|
+
<sub_store nil="true"/>
|
185
|
+
<available_payment_methods nil="true"/>
|
186
|
+
<url_notification>http://prodis.blog.br/tray_notification</url_notification>
|
187
|
+
<url_css nil="true"/>
|
188
|
+
<url_shipping nil="true"/>
|
189
|
+
<url_stock nil="true"/>
|
190
|
+
<url_success nil="true"/>
|
191
|
+
<url_process nil="true"/>
|
192
|
+
<url_cancel nil="true"/>
|
193
|
+
<schedule_credit></schedule_credit>
|
194
|
+
<price_seller type="decimal">35.05</price_seller>
|
195
|
+
<price_original type="decimal">37.86</price_original>
|
196
|
+
<price_additional type="decimal">0.0</price_additional>
|
197
|
+
<price_discount type="decimal">0.0</price_discount>
|
198
|
+
<shipping_price type="decimal">5.88</shipping_price>
|
199
|
+
<shipping_type>PAC</shipping_type>
|
200
|
+
<payment>
|
201
|
+
<price_payment type="decimal">37.86</price_payment>
|
202
|
+
<payment_response></payment_response>
|
203
|
+
<url_payment>http://checkout.sandbox.tray.com.br/payment/billet/u9uuu8731319u59u3073u9011uu6u6uu</url_payment>
|
204
|
+
<date_approval></date_approval>
|
205
|
+
<tid></tid>
|
206
|
+
<split type="integer">1</split>
|
207
|
+
<date_payment></date_payment>
|
208
|
+
<payment_method_id type="integer">6</payment_method_id>
|
209
|
+
<payment_method_name>Boleto Bancario</payment_method_name>
|
210
|
+
<card_id nil="true"/>
|
211
|
+
<number_proccess type="integer">869</number_proccess>
|
212
|
+
<linha_digitavel>34191.76007 00086.950144 50565.600009 1 55650000003786</linha_digitavel>
|
213
|
+
</payment>
|
214
|
+
<products type="array">
|
215
|
+
<product>
|
216
|
+
<code>LOGO-8278</code>
|
217
|
+
<description>Logo Prodis</description>
|
218
|
+
<extra nil="true"/>
|
219
|
+
<price_unit type="decimal">10.99</price_unit>
|
220
|
+
<quantity type="decimal">2.0</quantity>
|
221
|
+
<sku_code nil="true"/>
|
222
|
+
<url_img nil="true"/>
|
223
|
+
</product>
|
224
|
+
<product>
|
225
|
+
<code>877</code>
|
226
|
+
<description>Outro produto</description>
|
227
|
+
<extra nil="true"/>
|
228
|
+
<price_unit type="decimal">10.0</price_unit>
|
229
|
+
<quantity type="decimal">1.0</quantity>
|
230
|
+
<sku_code nil="true"/>
|
231
|
+
<url_img nil="true"/>
|
232
|
+
</product>
|
233
|
+
</products>
|
234
|
+
<transaction_affiliates type="array"/>
|
235
|
+
<customer>
|
236
|
+
<name>Pedro Bonamides</name>
|
237
|
+
<cpf>18565842673</cpf>
|
238
|
+
<email>pedro@bo.com.br</email>
|
239
|
+
<addresses type="array">
|
240
|
+
<address>
|
241
|
+
<street>Avenida Pedro Alvares Cabral</street>
|
242
|
+
<number>123</number>
|
243
|
+
<neighborhood>Parque Ibirapuera</neighborhood>
|
244
|
+
<postal_code>04094050</postal_code>
|
245
|
+
<completion></completion>
|
246
|
+
<city>São Paulo</city>
|
247
|
+
<state>SP</state>
|
248
|
+
</address>
|
249
|
+
</addresses>
|
250
|
+
<contacts type="array">
|
251
|
+
<contact>
|
252
|
+
<contact_id type="integer">345</contact_id>
|
253
|
+
<value>1137654321</value>
|
254
|
+
<type_contact>H</type_contact>
|
255
|
+
<primary type="boolean">true</primary>
|
256
|
+
</contact>
|
257
|
+
</contacts>
|
258
|
+
</customer>
|
259
|
+
</transaction>
|
260
|
+
</data_response>
|
261
|
+
<message_response>
|
262
|
+
<message>success</message>
|
263
|
+
</message_response>
|
264
|
+
</transaction>
|
265
|
+
|
266
|
+
If you configure log level to <b>:debug</b>, request and response HTTP headers will be logged too.
|
267
|
+
D, [2013-01-11T00:58:56.226742 #22692] DEBUG -- : Tray-Checkout Request:
|
268
|
+
POST http://api.sandbox.checkout.tray.com.br/api/v1/transactions/get_by_token
|
269
|
+
accept: */*
|
270
|
+
user-agent: Ruby
|
271
|
+
token=522045453u5uu32e0u8014f060uuu5uu
|
272
|
+
|
273
|
+
D, [2013-01-11T00:58:56.495131 #22692] DEBUG -- : Tray-Checkout Response:
|
274
|
+
HTTP/1.1 200 OK
|
275
|
+
content-type: application/xml; charset=utf-8
|
276
|
+
transfer-encoding: chunked
|
277
|
+
connection: close
|
278
|
+
status: 200
|
279
|
+
x-powered-by: Phusion Passenger (mod_rails/mod_rack) 3.0.18
|
280
|
+
x-ua-compatible: IE=Edge,chrome=1
|
281
|
+
etag: "f5466d3294e177f5bb5331d326283294"
|
282
|
+
cache-control: max-age=0, private, must-revalidate
|
283
|
+
x-request-id: 9d8b635650e69237a6a875971ead3bbb
|
284
|
+
x-runtime: 0.238734
|
285
|
+
date: Fri, 11 Jan 2013 03:58:56 GMT
|
286
|
+
x-rack-cache: invalidate, pass
|
287
|
+
server: nginx/1.2.5 + Phusion Passenger 3.0.18 (mod_rails/mod_rack)
|
288
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
289
|
+
<transaction>
|
290
|
+
<data_response>
|
291
|
+
<transaction>
|
292
|
+
<order_number>F4326</order_number>
|
293
|
+
<free nil="true"/>
|
294
|
+
<transaction_id type="integer">632</transaction_id>
|
295
|
+
<status_name>Aguardando Pagamento</status_name>
|
296
|
+
<status_id type="integer">4</status_id>
|
297
|
+
<date_transaction>2012-12-27T10:26:21</date_transaction>
|
298
|
+
<split type="integer">1</split>
|
299
|
+
<price_payment type="decimal">37.86</price_payment>
|
300
|
+
<date_payment></date_payment>
|
301
|
+
<transaction_token>522045453u5uu32e0u8014f060uuu5uu</transaction_token>
|
302
|
+
<sub_store nil="true"/>
|
303
|
+
<available_payment_methods nil="true"/>
|
304
|
+
<url_notification>http://prodis.blog.br/tray_notification</url_notification>
|
305
|
+
<url_css nil="true"/>
|
306
|
+
<url_shipping nil="true"/>
|
307
|
+
<url_stock nil="true"/>
|
308
|
+
<url_success nil="true"/>
|
309
|
+
<url_process nil="true"/>
|
310
|
+
<url_cancel nil="true"/>
|
311
|
+
<schedule_credit></schedule_credit>
|
312
|
+
<price_seller type="decimal">35.05</price_seller>
|
313
|
+
<price_original type="decimal">37.86</price_original>
|
314
|
+
<price_additional type="decimal">0.0</price_additional>
|
315
|
+
<price_discount type="decimal">0.0</price_discount>
|
316
|
+
<shipping_price type="decimal">5.88</shipping_price>
|
317
|
+
<shipping_type>PAC</shipping_type>
|
318
|
+
<payment>
|
319
|
+
<price_payment type="decimal">37.86</price_payment>
|
320
|
+
<payment_response></payment_response>
|
321
|
+
<url_payment>http://checkout.sandbox.tray.com.br/payment/billet/u9uuu8731319u59u3073u9011uu6u6uu</url_payment>
|
322
|
+
<date_approval></date_approval>
|
323
|
+
<tid></tid>
|
324
|
+
<split type="integer">1</split>
|
325
|
+
<date_payment></date_payment>
|
326
|
+
<payment_method_id type="integer">6</payment_method_id>
|
327
|
+
<payment_method_name>Boleto Bancario</payment_method_name>
|
328
|
+
<card_id nil="true"/>
|
329
|
+
<number_proccess type="integer">869</number_proccess>
|
330
|
+
<linha_digitavel>34191.76007 00086.950144 50565.600009 1 55650000003786</linha_digitavel>
|
331
|
+
</payment>
|
332
|
+
<products type="array">
|
333
|
+
<product>
|
334
|
+
<code>LOGO-8278</code>
|
335
|
+
<description>Logo Prodis</description>
|
336
|
+
<extra nil="true"/>
|
337
|
+
<price_unit type="decimal">10.99</price_unit>
|
338
|
+
<quantity type="decimal">2.0</quantity>
|
339
|
+
<sku_code nil="true"/>
|
340
|
+
<url_img nil="true"/>
|
341
|
+
</product>
|
342
|
+
<product>
|
343
|
+
<code>877</code>
|
344
|
+
<description>Outro produto</description>
|
345
|
+
<extra nil="true"/>
|
346
|
+
<price_unit type="decimal">10.0</price_unit>
|
347
|
+
<quantity type="decimal">1.0</quantity>
|
348
|
+
<sku_code nil="true"/>
|
349
|
+
<url_img nil="true"/>
|
350
|
+
</product>
|
351
|
+
</products>
|
352
|
+
<transaction_affiliates type="array"/>
|
353
|
+
<customer>
|
354
|
+
<name>Pedro Bonamides</name>
|
355
|
+
<cpf>18565842673</cpf>
|
356
|
+
<email>pedro@bo.com.br</email>
|
357
|
+
<addresses type="array">
|
358
|
+
<address>
|
359
|
+
<street>Avenida Pedro Alvares Cabral</street>
|
360
|
+
<number>123</number>
|
361
|
+
<neighborhood>Parque Ibirapuera</neighborhood>
|
362
|
+
<postal_code>04094050</postal_code>
|
363
|
+
<completion></completion>
|
364
|
+
<city>São Paulo</city>
|
365
|
+
<state>SP</state>
|
366
|
+
</address>
|
367
|
+
</addresses>
|
368
|
+
<contacts type="array">
|
369
|
+
<contact>
|
370
|
+
<contact_id type="integer">345</contact_id>
|
371
|
+
<value>1137654321</value>
|
372
|
+
<type_contact>H</type_contact>
|
373
|
+
<primary type="boolean">true</primary>
|
374
|
+
</contact>
|
375
|
+
</contacts>
|
376
|
+
</customer>
|
377
|
+
</transaction>
|
378
|
+
</data_response>
|
379
|
+
<message_response>
|
380
|
+
<message>success</message>
|
381
|
+
</message_response>
|
382
|
+
</transaction>
|
383
|
+
|
384
|
+
|
385
|
+
To disable the log, change log level and configure other log output, use <b>Tray::Checkout</b> module:
|
386
|
+
|
387
|
+
Tray::Checkout.configure do |config|
|
388
|
+
config.log_enabled = false # It disables the log
|
389
|
+
config.log_level = :debug # It changes log level
|
390
|
+
config.logger = Rails.logger # It uses Rails logger
|
391
|
+
end
|
392
|
+
|
393
|
+
=== A configuration example
|
394
|
+
|
395
|
+
Tray::Checkout.configure do |config|
|
396
|
+
config.environment = :sandbox
|
397
|
+
config.token_account = "123u5uu9ef36f7u"
|
398
|
+
config.request_timeout = 3
|
399
|
+
config.log_level = :debug
|
400
|
+
config.logger = Rails.logger
|
401
|
+
end
|
402
|
+
|
133
403
|
|
134
404
|
== Author
|
135
405
|
- {Fernando Hamasaki (prodis)}[http://prodis.blog.br]
|
@@ -155,7 +425,7 @@ Creating a successful transaction:
|
|
155
425
|
|
156
426
|
http://prodis.net.br/images/prodis_150.gif
|
157
427
|
|
158
|
-
Copyright (c) 2012 Prodis
|
428
|
+
Copyright (c) 2012-2013 Prodis
|
159
429
|
|
160
430
|
Permission is hereby granted, free of charge, to any person obtaining
|
161
431
|
a copy of this software and associated documentation files (the
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Tray
|
3
|
+
module Checkout
|
4
|
+
module Config
|
5
|
+
DEFAULT_REQUEST_TIMEOUT = 5 #seconds
|
6
|
+
DEFAULT_ENVIRONMENT = :production
|
7
|
+
|
8
|
+
attr_accessor :token_account
|
9
|
+
attr_writer :environment
|
10
|
+
attr_writer :request_timeout
|
11
|
+
|
12
|
+
def environment
|
13
|
+
@environment ||= DEFAULT_ENVIRONMENT
|
14
|
+
end
|
15
|
+
|
16
|
+
def api_url
|
17
|
+
if environment == :production
|
18
|
+
"https://api.checkout.tray.com.br/api/transactions"
|
19
|
+
else
|
20
|
+
"http://api.sandbox.checkout.tray.com.br/api/v1/transactions"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def request_timeout
|
25
|
+
(@request_timeout ||= DEFAULT_REQUEST_TIMEOUT).to_i
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -2,8 +2,6 @@
|
|
2
2
|
module Tray
|
3
3
|
module Checkout
|
4
4
|
class Transaction
|
5
|
-
URL = "http://api.sandbox.checkout.tray.com.br/api/v1/transactions"
|
6
|
-
|
7
5
|
def get(token)
|
8
6
|
request("get_by_token", { token: token })
|
9
7
|
end
|
@@ -15,8 +13,7 @@ module Tray
|
|
15
13
|
private
|
16
14
|
|
17
15
|
def request(path, params)
|
18
|
-
xml = web_service.request!("#{
|
19
|
-
#puts xml
|
16
|
+
xml = web_service.request!("#{Tray::Checkout.api_url}/#{path}", params)
|
20
17
|
parser.response(xml)
|
21
18
|
end
|
22
19
|
|
@@ -7,6 +7,7 @@ module Tray
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def parse
|
10
|
+
token_account! @params
|
10
11
|
customer_map! @params[:customer]
|
11
12
|
payment_map! @params[:payment]
|
12
13
|
products_map! @params
|
@@ -15,6 +16,10 @@ module Tray
|
|
15
16
|
|
16
17
|
private
|
17
18
|
|
19
|
+
def token_account!(params)
|
20
|
+
params[:token_account] = Tray::Checkout.token_account if params[:token_account].nil?
|
21
|
+
end
|
22
|
+
|
18
23
|
def customer_map!(customer)
|
19
24
|
return unless customer
|
20
25
|
customer[:gender] = SEX[customer[:sex]] if customer[:sex]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'active_support/core_ext'
|
3
|
-
require 'net/
|
3
|
+
require 'net/https'
|
4
4
|
require 'uri'
|
5
5
|
|
6
6
|
module Tray
|
@@ -9,9 +9,13 @@ module Tray
|
|
9
9
|
def request!(url, params)
|
10
10
|
uri = URI.parse(url)
|
11
11
|
http = build_http(uri)
|
12
|
+
|
12
13
|
request = build_request(uri, params)
|
14
|
+
log_request(request, url)
|
13
15
|
|
14
16
|
response = http.request(request)
|
17
|
+
log_response(response)
|
18
|
+
|
15
19
|
response.body
|
16
20
|
end
|
17
21
|
|
@@ -20,6 +24,12 @@ module Tray
|
|
20
24
|
def build_http(uri)
|
21
25
|
http = Net::HTTP.new(uri.host, uri.port)
|
22
26
|
http.open_timeout = Tray::Checkout.request_timeout
|
27
|
+
|
28
|
+
if uri.ssl?
|
29
|
+
http.use_ssl = true
|
30
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
31
|
+
end
|
32
|
+
|
23
33
|
http
|
24
34
|
end
|
25
35
|
|
@@ -28,6 +38,38 @@ module Tray
|
|
28
38
|
request.body = params.to_param
|
29
39
|
request
|
30
40
|
end
|
41
|
+
|
42
|
+
def log_request(request, url)
|
43
|
+
message = format_message(request) do
|
44
|
+
message = with_line_break { "Tray-Checkout Request:" }
|
45
|
+
message << with_line_break { "POST #{url}" }
|
46
|
+
end
|
47
|
+
|
48
|
+
Tray::Checkout.log(message)
|
49
|
+
end
|
50
|
+
|
51
|
+
def log_response(response)
|
52
|
+
message = format_message(response) do
|
53
|
+
message = with_line_break { "Tray-Checkout Response:" }
|
54
|
+
message << with_line_break { "HTTP/#{response.http_version} #{response.code} #{response.message}" }
|
55
|
+
end
|
56
|
+
|
57
|
+
Tray::Checkout.log(message)
|
58
|
+
end
|
59
|
+
|
60
|
+
def format_message(http)
|
61
|
+
message = yield
|
62
|
+
message << with_line_break { format_headers_for(http) } if Tray::Checkout.log_level == :debug
|
63
|
+
message << with_line_break { http.body }
|
64
|
+
end
|
65
|
+
|
66
|
+
def format_headers_for(http)
|
67
|
+
http.each_header.map { |name, value| "#{name}: #{value}" }.join("\n")
|
68
|
+
end
|
69
|
+
|
70
|
+
def with_line_break
|
71
|
+
"#{yield}\n"
|
72
|
+
end
|
31
73
|
end
|
32
74
|
end
|
33
75
|
end
|
data/lib/tray/checkout.rb
CHANGED
@@ -3,17 +3,8 @@ require 'log-me'
|
|
3
3
|
|
4
4
|
module Tray
|
5
5
|
module Checkout
|
6
|
+
extend Config
|
6
7
|
extend LogMe
|
7
|
-
|
8
|
-
module Timeout
|
9
|
-
DEFAULT_REQUEST_TIMEOUT = 5 #seconds
|
10
|
-
attr_writer :request_timeout
|
11
|
-
|
12
|
-
def request_timeout
|
13
|
-
(@request_timeout ||= DEFAULT_REQUEST_TIMEOUT).to_i
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
8
|
extend Timeout
|
18
9
|
end
|
19
10
|
end
|
data/lib/tray-checkout.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'rubygems'
|
3
|
-
require 'tray/checkout'
|
3
|
+
require 'tray/checkout/config'
|
4
4
|
require 'tray/checkout/constants'
|
5
5
|
require 'tray/checkout/hash'
|
6
6
|
require 'tray/checkout/parser'
|
@@ -8,4 +8,6 @@ require 'tray/checkout/response'
|
|
8
8
|
require 'tray/checkout/response_parser'
|
9
9
|
require 'tray/checkout/transaction'
|
10
10
|
require 'tray/checkout/transaction_params_parser'
|
11
|
+
require 'tray/checkout/uri'
|
11
12
|
require 'tray/checkout/web_service'
|
13
|
+
require 'tray/checkout'
|
data/spec/spec_helper.rb
CHANGED
@@ -122,5 +122,31 @@ describe Tray::Checkout::TransactionParamsParser do
|
|
122
122
|
transaction_params[:transaction_product][1][:price_unit].should == 10.00
|
123
123
|
transaction_params[:transaction_product][1][:description].should == "Outro produto"
|
124
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
|
125
151
|
end
|
126
152
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe URI do
|
5
|
+
describe "#ssl?" do
|
6
|
+
context "when is SSL" do
|
7
|
+
it "returns true" do
|
8
|
+
uri = URI.parse("https://prodis.webstorelw.com.br")
|
9
|
+
uri.ssl?.should be_true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when is not SSL" do
|
14
|
+
it "returns false" do
|
15
|
+
uri = URI.parse("http://prodis.blog.br")
|
16
|
+
uri.ssl?.should be_false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -7,7 +7,7 @@ describe Tray::Checkout::WebService do
|
|
7
7
|
|
8
8
|
it "returns XML response" do
|
9
9
|
mock_request_for("<xml><fake></fake>")
|
10
|
-
url = Tray::Checkout
|
10
|
+
url = Tray::Checkout.api_url
|
11
11
|
params = { token: "qwe123asd456poi098lkj765" }
|
12
12
|
web_service.request!(url, params).should eql "<xml><fake></fake>"
|
13
13
|
end
|
data/spec/tray/checkout_spec.rb
CHANGED
@@ -19,4 +19,44 @@ describe Tray::Checkout do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
describe "#token_account" do
|
24
|
+
it "default is nil" do
|
25
|
+
Tray::Checkout.token_account.should be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when set token account" do
|
29
|
+
around do |example|
|
30
|
+
Tray::Checkout.configure { |config| config.token_account = "123u5uu9ef36f7u" }
|
31
|
+
example.run
|
32
|
+
Tray::Checkout.configure { |config| config.token_account = nil }
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns token account" do
|
36
|
+
Tray::Checkout.token_account.should == "123u5uu9ef36f7u"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#environment" do
|
42
|
+
it "default is production" do
|
43
|
+
Tray::Checkout.environment.should == :production
|
44
|
+
end
|
45
|
+
|
46
|
+
{ production: "https://api.checkout.tray.com.br/api/transactions",
|
47
|
+
sandbox: "http://api.sandbox.checkout.tray.com.br/api/v1/transactions"
|
48
|
+
}.each do |environment, url|
|
49
|
+
context "when environment is #{environment}" do
|
50
|
+
around do |example|
|
51
|
+
Tray::Checkout.configure { |config| config.environment = environment }
|
52
|
+
example.run
|
53
|
+
Tray::Checkout.configure { |config| config.environment = :production }
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns correct API URL" do
|
57
|
+
Tray::Checkout.api_url.should == url
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
22
62
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &14772580 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *14772580
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: log-me
|
27
|
-
requirement: &
|
27
|
+
requirement: &14772350 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.0.4
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *14772350
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &14772160 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *14772160
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &14771890 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '2.12'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *14771890
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: webmock
|
60
|
-
requirement: &
|
60
|
+
requirement: &14771640 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '1.9'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *14771640
|
69
69
|
description: Tray Checkout API
|
70
70
|
email:
|
71
71
|
- prodis@gmail.com
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- lib/tray-checkout.rb
|
83
83
|
- lib/tray/checkout.rb
|
84
|
+
- lib/tray/checkout/config.rb
|
84
85
|
- lib/tray/checkout/constants.rb
|
85
86
|
- lib/tray/checkout/hash.rb
|
86
87
|
- lib/tray/checkout/parser.rb
|
@@ -88,6 +89,7 @@ files:
|
|
88
89
|
- lib/tray/checkout/response_parser.rb
|
89
90
|
- lib/tray/checkout/transaction.rb
|
90
91
|
- lib/tray/checkout/transaction_params_parser.rb
|
92
|
+
- lib/tray/checkout/uri.rb
|
91
93
|
- lib/tray/checkout/version.rb
|
92
94
|
- lib/tray/checkout/web_service.rb
|
93
95
|
- spec/spec_helper.rb
|
@@ -104,6 +106,7 @@ files:
|
|
104
106
|
- spec/tray/checkout/response_spec.rb
|
105
107
|
- spec/tray/checkout/transaction_params_parser_spec.rb
|
106
108
|
- spec/tray/checkout/transaction_spec.rb
|
109
|
+
- spec/tray/checkout/uri_spec.rb
|
107
110
|
- spec/tray/checkout/web_service_spec.rb
|
108
111
|
- spec/tray/checkout_spec.rb
|
109
112
|
- tray-checkout.gemspec
|
@@ -128,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
131
|
version: '0'
|
129
132
|
segments:
|
130
133
|
- 0
|
131
|
-
hash:
|
134
|
+
hash: -922153133
|
132
135
|
requirements: []
|
133
136
|
rubyforge_project:
|
134
137
|
rubygems_version: 1.8.16
|
@@ -150,5 +153,6 @@ test_files:
|
|
150
153
|
- spec/tray/checkout/response_spec.rb
|
151
154
|
- spec/tray/checkout/transaction_params_parser_spec.rb
|
152
155
|
- spec/tray/checkout/transaction_spec.rb
|
156
|
+
- spec/tray/checkout/uri_spec.rb
|
153
157
|
- spec/tray/checkout/web_service_spec.rb
|
154
158
|
- spec/tray/checkout_spec.rb
|