tray-checkout 0.2.1 → 0.3.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/README.rdoc +123 -141
- data/lib/tray/checkout/base_transaction.rb +25 -0
- data/lib/tray/checkout/config.rb +10 -2
- data/lib/tray/checkout/response_parser.rb +22 -14
- data/lib/tray/checkout/temp_transaction.rb +22 -0
- data/lib/tray/checkout/transaction.rb +8 -18
- data/lib/tray/checkout/transaction_params_parser.rb +1 -0
- data/lib/tray/checkout/version.rb +1 -1
- data/lib/tray-checkout.rb +2 -0
- data/spec/spec_helper.rb +1 -2
- data/spec/support/mock_request.rb +2 -1
- data/spec/support/responses/create_failure_validation_errors.xml +10 -48
- data/spec/support/responses/create_success_boleto.xml +35 -75
- data/spec/support/responses/create_temp_transaction_with_token.xml +28 -0
- data/spec/support/responses/get_failure_not_found.xml +4 -4
- data/spec/support/responses/get_success_boleto.xml +36 -76
- data/spec/support/responses/get_success_boleto_without_contacts.xml +37 -67
- data/spec/support/responses/get_success_mastercard.xml +36 -76
- data/spec/support/vcr/model/create_cart.yml +59 -0
- data/spec/support/vcr/model/create_failure_validation_errors.yml +75 -0
- data/spec/support/vcr/model/create_success_boleto.yml +93 -0
- data/spec/support/vcr/model/create_success_mastercard.yml +90 -0
- data/spec/support/vcr/model/get_failure_not_found.yml +72 -0
- data/spec/support/vcr/model/get_success_boleto.yml +114 -0
- data/spec/support/vcr/model/update_cart.yml +59 -0
- data/spec/support/vcr_setup.rb +7 -0
- data/spec/tray/checkout/parser_spec.rb +1 -1
- data/spec/tray/checkout/response_parser_spec.rb +83 -67
- data/spec/tray/checkout/temp_transaction_spec.rb +94 -0
- data/spec/tray/checkout/transaction_spec.rb +146 -23
- data/spec/tray/checkout_spec.rb +2 -2
- data/tray-checkout.gemspec +1 -0
- metadata +77 -14
data/README.rdoc
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
= tray-checkout
|
2
2
|
|
3
|
-
|
3
|
+
Library to provide access to TrayCheckout's API.
|
4
|
+
|
5
|
+
Note: This version is not compatible with the 0.2.1, for the new API version (v2) is not compatible with the old (v1).
|
4
6
|
|
5
7
|
== Installing
|
6
8
|
|
@@ -130,6 +132,52 @@ Creating a successful transaction:
|
|
130
132
|
response.customer[:email] # => "pedro@bo.com.br"
|
131
133
|
response.customer[:cpf] # => "18565842673"
|
132
134
|
|
135
|
+
=== Temp Transactions (Carts)
|
136
|
+
|
137
|
+
You can create or update carts through the Tray::Checkout::TempTransaction class:
|
138
|
+
|
139
|
+
temp_transaction = Tray::Checkout::TempTransaction.new
|
140
|
+
temp_transaction.add_to_cart(
|
141
|
+
token_account: "8bfe5ddcb77107b",
|
142
|
+
postal_code_seller: "18524698",
|
143
|
+
transaction: {
|
144
|
+
order_number: "1234567",
|
145
|
+
free: "Texto Interno",
|
146
|
+
url_notification: "http://prodis.blog.br/tray_notification",
|
147
|
+
products: [
|
148
|
+
{
|
149
|
+
code: "teste",
|
150
|
+
description: "Notebook Branco",
|
151
|
+
quantity: "1",
|
152
|
+
price_unit: "2199.99",
|
153
|
+
weight: "300",
|
154
|
+
url_img: "http://catnross.com/wp-content/uploads/2011/08/product1.jpg"
|
155
|
+
}
|
156
|
+
]
|
157
|
+
}
|
158
|
+
)
|
159
|
+
response.success? # => true
|
160
|
+
|
161
|
+
response[:token] # => a906bf32cb59060dfc90769524f99d4a
|
162
|
+
response[:url_car] # => http://checkout.sandbox.tray.com.br/payment/car/v1/
|
163
|
+
|
164
|
+
# Products
|
165
|
+
response[:products].first[:code] # => teste
|
166
|
+
response[:products].first[:img] # => http://catnross.com/wp-content/uploads/2011/08/product1.jpg
|
167
|
+
response[:products].first[:sku_code] # => nil
|
168
|
+
response[:products].first[:description] # => Notebook Branco
|
169
|
+
response[:products].first[:extra] # => nil
|
170
|
+
response[:products].first[:price_unit] # => 2199.99
|
171
|
+
response[:products].first[:quantity] # => 1.0
|
172
|
+
response[:products].first[:weight] # => 300.0
|
173
|
+
response[:products].first[:id] # => 4502
|
174
|
+
response[:products].first[:type_product] # => nil
|
175
|
+
|
176
|
+
After creating a cart you can forward your client using the cart_url method:
|
177
|
+
|
178
|
+
temp_transaction = Tray::Checkout::TempTransaction.new
|
179
|
+
temp_transaction.add_to_cart # => http://checkout.sandbox.tray.com.br/payment/car/v1/a906bf32cb59060dfc90769524f99d4a
|
180
|
+
|
133
181
|
== Configurations
|
134
182
|
|
135
183
|
=== Environment
|
@@ -162,97 +210,63 @@ For default, each request to Tray Checkout API is logged to STDOUT, with <b>:inf
|
|
162
210
|
|
163
211
|
Log example:
|
164
212
|
I, [2013-01-11T00:55:10.531780 #22692] INFO -- : Tray-Checkout Request:
|
165
|
-
POST http://api.sandbox.
|
213
|
+
POST http://api.sandbox.traycheckout.com.br//v2/transactions/get_by_token
|
166
214
|
token=522045453u5uu32e0u8014f060uuu5uu
|
167
215
|
|
168
216
|
I, [2013-01-11T00:55:10.750308 #22692] INFO -- : Tray-Checkout Response:
|
169
217
|
HTTP/1.1 200 OK
|
170
218
|
<?xml version="1.0" encoding="UTF-8"?>
|
171
|
-
<
|
219
|
+
<response>
|
172
220
|
<data_response>
|
173
221
|
<transaction>
|
174
|
-
<order_number>
|
175
|
-
<free
|
176
|
-
<transaction_id type="integer">
|
177
|
-
<status_name>
|
178
|
-
<status_id type="integer">
|
179
|
-
<
|
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>
|
222
|
+
<order_number>1234567</order_number>
|
223
|
+
<free>Texto Interno</free>
|
224
|
+
<transaction_id type="integer">3856</transaction_id>
|
225
|
+
<status_name>Em Recupera\xC3\xA7\xC3\xA3o</status_name>
|
226
|
+
<status_id type="integer">88</status_id>
|
227
|
+
<token_transaction>522045453u5uu32e0u8014f060uuu5uu</token_transaction>
|
200
228
|
<payment>
|
201
|
-
<
|
229
|
+
<price_original type="decimal">2199.99</price_original>
|
230
|
+
<price_payment type="decimal">2199.99</price_payment>
|
202
231
|
<payment_response></payment_response>
|
203
|
-
<url_payment>http://
|
204
|
-
<
|
205
|
-
<tid></tid>
|
232
|
+
<url_payment>http://gtw.sandbox.checkout.tray.com.br/api/print/0b525e9dbef558690477b815118aa033</url_payment>
|
233
|
+
<tid nil="true"/>
|
206
234
|
<split type="integer">1</split>
|
207
|
-
<date_payment></date_payment>
|
208
235
|
<payment_method_id type="integer">6</payment_method_id>
|
209
236
|
<payment_method_name>Boleto Bancario</payment_method_name>
|
210
|
-
<
|
211
|
-
<number_proccess type="integer">869</number_proccess>
|
212
|
-
<linha_digitavel>34191.76007 00086.950144 50565.600009 1 55650000003786</linha_digitavel>
|
237
|
+
<linha_digitavel>34191.76007 00536.260144 50565.600009 6 58630000219999</linha_digitavel>
|
213
238
|
</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
239
|
<customer>
|
236
|
-
<name>
|
237
|
-
<cpf>
|
238
|
-
<email>
|
240
|
+
<name>Nome do Cliente</name>
|
241
|
+
<cpf>98489882380</cpf>
|
242
|
+
<email>emaildo@cliente.com.br</email>
|
243
|
+
<company_name></company_name>
|
244
|
+
<trade_name></trade_name>
|
245
|
+
<cnpj></cnpj>
|
239
246
|
<addresses type="array">
|
240
247
|
<address>
|
241
|
-
<street>
|
242
|
-
<number>
|
243
|
-
<neighborhood>
|
244
|
-
<postal_code>
|
248
|
+
<street>Av Paulista</street>
|
249
|
+
<number>1001</number>
|
250
|
+
<neighborhood>Centro</neighborhood>
|
251
|
+
<postal_code>04001001</postal_code>
|
252
|
+
<completion></completion>
|
253
|
+
<city>S\xC3\xA3o Paulo</city>
|
254
|
+
<state>SP</state>
|
255
|
+
</address>
|
256
|
+
<address>
|
257
|
+
<street>Av Paulista</street>
|
258
|
+
<number>1001</number>
|
259
|
+
<neighborhood>Centro</neighborhood>
|
260
|
+
<postal_code>04001001</postal_code>
|
245
261
|
<completion></completion>
|
246
|
-
<city>
|
262
|
+
<city>S\xC3\xA3o Paulo</city>
|
247
263
|
<state>SP</state>
|
248
264
|
</address>
|
249
265
|
</addresses>
|
250
266
|
<contacts type="array">
|
251
267
|
<contact>
|
252
|
-
<
|
253
|
-
<
|
254
|
-
<type_contact>H</type_contact>
|
255
|
-
<primary type="boolean">true</primary>
|
268
|
+
<value>11998761234</value>
|
269
|
+
<type_contact>M</type_contact>
|
256
270
|
</contact>
|
257
271
|
</contacts>
|
258
272
|
</customer>
|
@@ -261,11 +275,13 @@ Log example:
|
|
261
275
|
<message_response>
|
262
276
|
<message>success</message>
|
263
277
|
</message_response>
|
264
|
-
</
|
278
|
+
</response>
|
279
|
+
|
280
|
+
|
265
281
|
|
266
282
|
If you configure log level to <b>:debug</b>, request and response HTTP headers will be logged too.
|
267
283
|
D, [2013-01-11T00:58:56.226742 #22692] DEBUG -- : Tray-Checkout Request:
|
268
|
-
POST http://api.sandbox.
|
284
|
+
POST http://api.sandbox.traycheckout.com.br//v2/transactions/get_by_token
|
269
285
|
accept: */*
|
270
286
|
user-agent: Ruby
|
271
287
|
token=522045453u5uu32e0u8014f060uuu5uu
|
@@ -286,91 +302,57 @@ If you configure log level to <b>:debug</b>, request and response HTTP headers w
|
|
286
302
|
x-rack-cache: invalidate, pass
|
287
303
|
server: nginx/1.2.5 + Phusion Passenger 3.0.18 (mod_rails/mod_rack)
|
288
304
|
<?xml version="1.0" encoding="UTF-8"?>
|
289
|
-
<
|
305
|
+
<response>
|
290
306
|
<data_response>
|
291
307
|
<transaction>
|
292
|
-
<order_number>
|
293
|
-
<free
|
294
|
-
<transaction_id type="integer">
|
295
|
-
<status_name>
|
296
|
-
<status_id type="integer">
|
297
|
-
<
|
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>
|
308
|
+
<order_number>1234567</order_number>
|
309
|
+
<free>Texto Interno</free>
|
310
|
+
<transaction_id type="integer">3856</transaction_id>
|
311
|
+
<status_name>Em Recupera\xC3\xA7\xC3\xA3o</status_name>
|
312
|
+
<status_id type="integer">88</status_id>
|
313
|
+
<token_transaction>522045453u5uu32e0u8014f060uuu5uu</token_transaction>
|
318
314
|
<payment>
|
319
|
-
<
|
315
|
+
<price_original type="decimal">2199.99</price_original>
|
316
|
+
<price_payment type="decimal">2199.99</price_payment>
|
320
317
|
<payment_response></payment_response>
|
321
|
-
<url_payment>http://
|
322
|
-
<
|
323
|
-
<tid></tid>
|
318
|
+
<url_payment>http://gtw.sandbox.checkout.tray.com.br/api/print/0b525e9dbef558690477b815118aa033</url_payment>
|
319
|
+
<tid nil="true"/>
|
324
320
|
<split type="integer">1</split>
|
325
|
-
<date_payment></date_payment>
|
326
321
|
<payment_method_id type="integer">6</payment_method_id>
|
327
322
|
<payment_method_name>Boleto Bancario</payment_method_name>
|
328
|
-
<
|
329
|
-
<number_proccess type="integer">869</number_proccess>
|
330
|
-
<linha_digitavel>34191.76007 00086.950144 50565.600009 1 55650000003786</linha_digitavel>
|
323
|
+
<linha_digitavel>34191.76007 00536.260144 50565.600009 6 58630000219999</linha_digitavel>
|
331
324
|
</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
325
|
<customer>
|
354
|
-
<name>
|
355
|
-
<cpf>
|
356
|
-
<email>
|
326
|
+
<name>Nome do Cliente</name>
|
327
|
+
<cpf>98489882380</cpf>
|
328
|
+
<email>emaildo@cliente.com.br</email>
|
329
|
+
<company_name></company_name>
|
330
|
+
<trade_name></trade_name>
|
331
|
+
<cnpj></cnpj>
|
357
332
|
<addresses type="array">
|
358
333
|
<address>
|
359
|
-
<street>
|
360
|
-
<number>
|
361
|
-
<neighborhood>
|
362
|
-
<postal_code>
|
334
|
+
<street>Av Paulista</street>
|
335
|
+
<number>1001</number>
|
336
|
+
<neighborhood>Centro</neighborhood>
|
337
|
+
<postal_code>04001001</postal_code>
|
338
|
+
<completion></completion>
|
339
|
+
<city>S\xC3\xA3o Paulo</city>
|
340
|
+
<state>SP</state>
|
341
|
+
</address>
|
342
|
+
<address>
|
343
|
+
<street>Av Paulista</street>
|
344
|
+
<number>1001</number>
|
345
|
+
<neighborhood>Centro</neighborhood>
|
346
|
+
<postal_code>04001001</postal_code>
|
363
347
|
<completion></completion>
|
364
|
-
<city>
|
348
|
+
<city>S\xC3\xA3o Paulo</city>
|
365
349
|
<state>SP</state>
|
366
350
|
</address>
|
367
351
|
</addresses>
|
368
352
|
<contacts type="array">
|
369
353
|
<contact>
|
370
|
-
<
|
371
|
-
<
|
372
|
-
<type_contact>H</type_contact>
|
373
|
-
<primary type="boolean">true</primary>
|
354
|
+
<value>11998761234</value>
|
355
|
+
<type_contact>M</type_contact>
|
374
356
|
</contact>
|
375
357
|
</contacts>
|
376
358
|
</customer>
|
@@ -379,7 +361,7 @@ If you configure log level to <b>:debug</b>, request and response HTTP headers w
|
|
379
361
|
<message_response>
|
380
362
|
<message>success</message>
|
381
363
|
</message_response>
|
382
|
-
</
|
364
|
+
</response>
|
383
365
|
|
384
366
|
|
385
367
|
To disable the log, change log level and configure other log output, use <b>Tray::Checkout</b> module:
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Tray
|
3
|
+
module Checkout
|
4
|
+
class BaseTransaction
|
5
|
+
def api_url
|
6
|
+
"#{Tray::Checkout.api_url}"
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def request(path, params)
|
12
|
+
xml = web_service.request!("#{api_url}#{path}", params)
|
13
|
+
parser.response(xml)
|
14
|
+
end
|
15
|
+
|
16
|
+
def web_service
|
17
|
+
@web_service ||= Tray::Checkout::WebService.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def parser
|
21
|
+
@parser ||= Tray::Checkout::Parser.new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/tray/checkout/config.rb
CHANGED
@@ -15,9 +15,17 @@ module Tray
|
|
15
15
|
|
16
16
|
def api_url
|
17
17
|
if environment == :production
|
18
|
-
"https://api.
|
18
|
+
"https://api.traycheckout.com.br/"
|
19
19
|
else
|
20
|
-
"http://api.sandbox.
|
20
|
+
"http://api.sandbox.traycheckout.com.br/"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def cart_url
|
25
|
+
if environment == :production
|
26
|
+
"http://checkout.tray.com.br/"
|
27
|
+
else
|
28
|
+
"http://checkout.sandbox.tray.com.br/"
|
21
29
|
end
|
22
30
|
end
|
23
31
|
|
@@ -30,7 +30,8 @@ module Tray
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def create_response_hash
|
33
|
-
Hash.from_xml(@xml).symbolize_all_keys
|
33
|
+
hash = Hash.from_xml(@xml).symbolize_all_keys
|
34
|
+
hash[:response] || hash[:tmp_transaction]
|
34
35
|
end
|
35
36
|
|
36
37
|
def success?
|
@@ -57,7 +58,7 @@ module Tray
|
|
57
58
|
end
|
58
59
|
|
59
60
|
def create_data_response
|
60
|
-
data_response = response_hash[:data_response][:transaction]
|
61
|
+
data_response = response_hash[:data_response][:transaction] || response_hash[:data_response]
|
61
62
|
transaction_map! data_response
|
62
63
|
payment_map! data_response
|
63
64
|
customer_map! data_response
|
@@ -66,29 +67,34 @@ module Tray
|
|
66
67
|
end
|
67
68
|
|
68
69
|
def transaction_map!(transaction)
|
69
|
-
|
70
|
-
|
71
|
-
transaction[:
|
72
|
-
transaction[:
|
70
|
+
return {} unless transaction
|
71
|
+
|
72
|
+
transaction[:status] = TRANSACTION_STATUS.invert[transaction.delete(:status_id)] if transaction.has_key?(:status_id)
|
73
|
+
transaction[:id] = transaction.delete(:transaction_id) if transaction.has_key?(:transaction_id)
|
74
|
+
transaction[:token] = transaction.delete(:token_transaction) if transaction.has_key?(:token_transaction)
|
75
|
+
transaction[:products] = transaction.delete(:transaction_products) if transaction.has_key?(:transaction_products)
|
73
76
|
end
|
74
77
|
|
75
78
|
def payment_map!(transaction)
|
79
|
+
return {} if transaction.blank? || transaction[:payment].blank?
|
80
|
+
|
76
81
|
payment = transaction[:payment]
|
77
|
-
|
78
|
-
payment[:
|
79
|
-
payment[:
|
80
|
-
payment[:
|
81
|
-
payment[:url] = payment.delete(:url_payment)
|
82
|
+
|
83
|
+
payment[:method] = PAYMENT_METHOD.invert[payment.delete(:payment_method_id)] if payment.has_key?(:payment_method_id)
|
84
|
+
payment[:method_name] = payment.delete(:payment_method_name) if payment.has_key?(:payment_method_name)
|
85
|
+
payment[:price] = payment.delete(:price_payment) if payment.has_key?(:price_payment)
|
82
86
|
end
|
83
87
|
|
84
88
|
def customer_map!(transaction)
|
89
|
+
return {} if transaction.blank? || transaction[:customer].blank?
|
90
|
+
|
85
91
|
customer = transaction[:customer]
|
86
92
|
|
87
93
|
if customer[:contacts]
|
88
94
|
customer[:contacts].each do |contact|
|
89
|
-
contact[:type] = CONTACT_TYPE.invert[contact.delete(:type_contact)]
|
90
|
-
contact[:id] = contact.delete(:contact_id)
|
91
|
-
contact[:number] = contact.delete(:value)
|
95
|
+
contact[:type] = CONTACT_TYPE.invert[contact.delete(:type_contact)] if contact.has_key?(:type_contact)
|
96
|
+
contact[:id] = contact.delete(:contact_id) if contact.has_key?(:contact_id)
|
97
|
+
contact[:number] = contact.delete(:value) if contact.has_key?(:value)
|
92
98
|
end
|
93
99
|
else
|
94
100
|
customer[:contacts] = []
|
@@ -96,6 +102,8 @@ module Tray
|
|
96
102
|
end
|
97
103
|
|
98
104
|
def date_to_time!(hash)
|
105
|
+
return nil unless hash
|
106
|
+
|
99
107
|
hash.each do |key, value|
|
100
108
|
date_to_time!(value) if value.is_a?(Hash)
|
101
109
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Tray
|
3
|
+
module Checkout
|
4
|
+
class TempTransaction < Tray::Checkout::BaseTransaction
|
5
|
+
def api_url
|
6
|
+
"#{Tray::Checkout.api_url}/v1/tmp_transactions/"
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(token=nil)
|
10
|
+
@token = token || Tray::Checkout.token_account
|
11
|
+
end
|
12
|
+
|
13
|
+
def cart_url
|
14
|
+
"#{Tray::Checkout.cart_url}payment/car/v1/#{@token}" if @token
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_to_cart(params)
|
18
|
+
request("create", parser.transaction_params(params))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,28 +1,18 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module Tray
|
3
3
|
module Checkout
|
4
|
-
class Transaction
|
5
|
-
def
|
6
|
-
|
4
|
+
class Transaction < Tray::Checkout::BaseTransaction
|
5
|
+
def api_url
|
6
|
+
"#{Tray::Checkout.api_url}/v2/transactions/"
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def request(path, params)
|
16
|
-
xml = web_service.request!("#{Tray::Checkout.api_url}/#{path}", params)
|
17
|
-
parser.response(xml)
|
9
|
+
def get(token, account=nil)
|
10
|
+
account ||= Tray::Checkout.token_account
|
11
|
+
request("get_by_token", { token_account: account, token_transaction: token })
|
18
12
|
end
|
19
13
|
|
20
|
-
def
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def parser
|
25
|
-
@parser ||= Tray::Checkout::Parser.new
|
14
|
+
def create(params)
|
15
|
+
request("pay_complete", parser.transaction_params(params))
|
26
16
|
end
|
27
17
|
end
|
28
18
|
end
|
@@ -22,6 +22,7 @@ module Tray
|
|
22
22
|
|
23
23
|
def customer_map!(customer)
|
24
24
|
return unless customer
|
25
|
+
customer[:birth_date] = customer[:birth_date].strftime("%d/%m/%Y") if customer[:birth_date] && customer[:birth_date].is_a?(Date)
|
25
26
|
customer[:gender] = SEX[customer[:sex]] if customer[:sex]
|
26
27
|
customer[:relationship] = MARITAL_STATUS[customer[:marital_status]] if customer[:marital_status]
|
27
28
|
contacts_map! customer[:contacts]
|
data/lib/tray-checkout.rb
CHANGED
@@ -6,7 +6,9 @@ require 'tray/checkout/hash'
|
|
6
6
|
require 'tray/checkout/parser'
|
7
7
|
require 'tray/checkout/response'
|
8
8
|
require 'tray/checkout/response_parser'
|
9
|
+
require 'tray/checkout/base_transaction'
|
9
10
|
require 'tray/checkout/transaction'
|
11
|
+
require 'tray/checkout/temp_transaction'
|
10
12
|
require 'tray/checkout/transaction_params_parser'
|
11
13
|
require 'tray/checkout/uri'
|
12
14
|
require 'tray/checkout/web_service'
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'tray-checkout'
|
2
2
|
require 'webmock/rspec'
|
3
|
+
require 'vcr'
|
3
4
|
|
4
5
|
# Requires supporting files with custom matchers and macros, etc,
|
5
6
|
# in ./support/ and its subdirectories.
|
@@ -10,8 +11,6 @@ RSpec.configure do |config|
|
|
10
11
|
config.order = "random"
|
11
12
|
end
|
12
13
|
|
13
|
-
WebMock.disable_net_connect!
|
14
|
-
|
15
14
|
Tray::Checkout.configure do |config|
|
16
15
|
config.log_enabled = false
|
17
16
|
end
|
@@ -13,7 +13,8 @@ def body_for(response)
|
|
13
13
|
:get_failure_not_found,
|
14
14
|
:create_success_boleto,
|
15
15
|
:create_success_mastercard,
|
16
|
-
:create_failure_validation_errors
|
16
|
+
:create_failure_validation_errors,
|
17
|
+
:create_temp_transaction_with_token
|
17
18
|
read_file_for(response)
|
18
19
|
else
|
19
20
|
response
|
@@ -1,52 +1,14 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<
|
2
|
+
<response>
|
3
|
+
<error_response>
|
4
|
+
<errors type="array">
|
5
|
+
<error>
|
6
|
+
<message>Tipo de Contato não está incluído na lista</message>
|
7
|
+
<code>13</code>
|
8
|
+
</error>
|
9
|
+
</errors>
|
10
|
+
</error_response>
|
3
11
|
<message_response>
|
4
12
|
<message>error</message>
|
5
13
|
</message_response>
|
6
|
-
|
7
|
-
<validation_errors type="array">
|
8
|
-
<validation_error>
|
9
|
-
<code>1</code>
|
10
|
-
<message_complete>Tipo não pode ficar em branco</message_complete>
|
11
|
-
<message>não pode ficar em branco</message>
|
12
|
-
<field>person_addresses.type_address</field>
|
13
|
-
</validation_error>
|
14
|
-
<validation_error>
|
15
|
-
<code>1</code>
|
16
|
-
<message_complete>Logradouro (Rua, Av, Travessa...) não pode ficar em branco</message_complete>
|
17
|
-
<message>não pode ficar em branco</message>
|
18
|
-
<field>person_addresses.street</field>
|
19
|
-
</validation_error>
|
20
|
-
<validation_error>
|
21
|
-
<code>1</code>
|
22
|
-
<message_complete>Cep não pode ficar em branco</message_complete>
|
23
|
-
<message>não pode ficar em branco</message>
|
24
|
-
<field>person_addresses.postal_code</field>
|
25
|
-
</validation_error>
|
26
|
-
<validation_error>
|
27
|
-
<code>1</code>
|
28
|
-
<message_complete>Cidade não pode ficar em branco</message_complete>
|
29
|
-
<message>não pode ficar em branco</message>
|
30
|
-
<field>person_addresses.city</field>
|
31
|
-
</validation_error>
|
32
|
-
<validation_error>
|
33
|
-
<code>1</code>
|
34
|
-
<message_complete>UF não pode ficar em branco</message_complete>
|
35
|
-
<message>não pode ficar em branco</message>
|
36
|
-
<field>person_addresses.state</field>
|
37
|
-
</validation_error>
|
38
|
-
<validation_error>
|
39
|
-
<code>1</code>
|
40
|
-
<message_complete>Número, Lote não pode ficar em branco</message_complete>
|
41
|
-
<message>não pode ficar em branco</message>
|
42
|
-
<field>person_addresses.number</field>
|
43
|
-
</validation_error>
|
44
|
-
<validation_error>
|
45
|
-
<code>1</code>
|
46
|
-
<message_complete>Bairro não pode ficar em branco</message_complete>
|
47
|
-
<message>não pode ficar em branco</message>
|
48
|
-
<field>person_addresses.neighborhood</field>
|
49
|
-
</validation_error>
|
50
|
-
</validation_errors>
|
51
|
-
</error_response>
|
52
|
-
</transaction>
|
14
|
+
</response>
|