tray-checkout 0.0.0 → 0.0.1

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,111 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <transaction>
3
+ <data_response>
4
+ <transaction>
5
+ <transaction_token>522045453u5uu32e0u8014f060uuu5uu</transaction_token>
6
+ <transaction_id type="integer">501</transaction_id>
7
+ <payment_method_id type="integer">6</payment_method_id>
8
+ <payment_method_name>Boleto Bancario</payment_method_name>
9
+ <status_id type="integer">4</status_id>
10
+ <status_name>Aguardando Pagamento</status_name>
11
+ <order_number>R1240</order_number>
12
+ <price_original type="decimal">213.21</price_original>
13
+ <price_payment type="decimal">213.21</price_payment>
14
+ <price_seller type="decimal">199.19</price_seller>
15
+ <price_additional type="decimal">0.0</price_additional>
16
+ <price_discount type="decimal">0.0</price_discount>
17
+ <shipping_type>Sedex</shipping_type>
18
+ <shipping_price type="decimal">1.23</shipping_price>
19
+ <split type="integer">1</split>
20
+ <date_transaction>2012-12-03T18:08:37</date_transaction>
21
+ <url_notification>http://prodis.blog.br/tray_notification</url_notification>
22
+ <seller_token>949u5uu9ef36f7u</seller_token>
23
+ <free nil="true"></free>
24
+ <date_payment>xxx</date_payment>
25
+ <transaction_affiliates type="array"/>
26
+ <schedule_credit></schedule_credit>
27
+ <url_shipping nil="true"></url_shipping>
28
+ <url_process nil="true"></url_process>
29
+ <url_cancel nil="true"></url_cancel>
30
+ <url_stock nil="true"></url_stock>
31
+ <url_success nil="true"></url_success>
32
+ <url_css nil="true"></url_css>
33
+ <available_payment_methods nil="true"></available_payment_methods>
34
+ <sub_store nil="true"></sub_store>
35
+ <payment>
36
+ <payment_method_id type="integer">6</payment_method_id>
37
+ <payment_method_name>Boleto Bancario</payment_method_name>
38
+ <price_payment type="decimal">213.21</price_payment>
39
+ <split type="integer">1</split>
40
+ <number_proccess type="integer">718</number_proccess>
41
+ <url_payment>http://checkout.sandbox.tray.com.br/payment/billet/u9uuu8731319u59u3073u9011uu6u6uu</url_payment>
42
+ <date_approval>2012-12-04T00:55:15</date_approval>
43
+ <selling_message></selling_message>
44
+ <payment_response></payment_response>
45
+ <date_payment>xxx</date_payment>
46
+ <number_of_voucher_sales></number_of_voucher_sales>
47
+ <card_id nil="true"></card_id>
48
+ </payment>
49
+ <products type="array">
50
+ <product>
51
+ <code>LOGO-8278</code>
52
+ <url_img nil="true"></url_img>
53
+ <quantity type="decimal">2.0</quantity>
54
+ <description>Logo Prodis</description>
55
+ <extra nil="true"></extra>
56
+ <sku_code nil="true"></sku_code>
57
+ <price_unit type="decimal">100.99</price_unit>
58
+ </product>
59
+ <product>
60
+ <code>877</code>
61
+ <url_img nil="true"></url_img>
62
+ <quantity type="decimal">1.0</quantity>
63
+ <description>Outro produto</description>
64
+ <extra nil="true"></extra>
65
+ <sku_code nil="true"></sku_code>
66
+ <price_unit type="decimal">10.0</price_unit>
67
+ </product>
68
+ </products>
69
+ <company>
70
+ <cnpj>22132477000163</cnpj>
71
+ <trade_name>Bo Company</trade_name>
72
+ <cpf>12345678909</cpf>
73
+ <url></url>
74
+ <company_name>Bo Company</company_name>
75
+ <token>949u5uu9ef36f7u</token>
76
+ <contact>1152360873</contact>
77
+ <name>Bo Company</name>
78
+ <business_name>Bo Company</business_name>
79
+ </company>
80
+ <customer>
81
+ <address>
82
+ <number>123</number>
83
+ <completion></completion>
84
+ <city>S&#227;o Paulo</city>
85
+ <postal_code>04094050</postal_code>
86
+ <state>SP</state>
87
+ <street>Avenida Pedro Alvares Cabral</street>
88
+ <neighborhood>Parque Ibirapuera</neighborhood>
89
+ </address>
90
+ <cpf>18565842673</cpf>
91
+ <addresses type="array">
92
+ <address>
93
+ <number>123</number>
94
+ <completion></completion>
95
+ <city>S&#227;o Paulo</city>
96
+ <postal_code>04094050</postal_code>
97
+ <state>SP</state>
98
+ <street>Avenida Pedro Alvares Cabral</street>
99
+ <neighborhood>Parque Ibirapuera</neighborhood>
100
+ </address>
101
+ </addresses>
102
+ <email>pedro@bo.com.br</email>
103
+ <token>6buu8f3uu85u567</token>
104
+ <name>Pedro Bonamides</name>
105
+ </customer>
106
+ </transaction>
107
+ </data_response>
108
+ <message_response>
109
+ <message>success</message>
110
+ </message_response>
111
+ </transaction>
@@ -0,0 +1,66 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Hash do
5
+ describe "#symbolize_all_keys!" do
6
+ it "symbolize keys" do
7
+ hash = { "text" => "Um texto", "number" => 456 }
8
+ hash.symbolize_all_keys!
9
+ hash.should == { text: "Um texto", number: 456 }
10
+ end
11
+
12
+ context "when hash has nested hashes" do
13
+ it "symbolize keys in nested hashes too" do
14
+ hash = {
15
+ "customer" => {
16
+ "name" => "Pedro Bonamides",
17
+ "email" => "pedro@bo.com.br",
18
+ "address" => {
19
+ "street" => "Avenida Pedro Álvares Cabral",
20
+ "number" => "123",
21
+ "city" => "São Paulo",
22
+ "state" => "SP",
23
+ "postal_code" => "04094050",
24
+ },
25
+ }
26
+ }
27
+ hash.symbolize_all_keys!
28
+ hash.should == {
29
+ customer: {
30
+ name: "Pedro Bonamides",
31
+ email: "pedro@bo.com.br",
32
+ address: {
33
+ street: "Avenida Pedro Álvares Cabral",
34
+ number: "123",
35
+ city: "São Paulo",
36
+ state: "SP",
37
+ postal_code: "04094050",
38
+ },
39
+ }
40
+ }
41
+ end
42
+ end
43
+
44
+ context "when hash value is Array with hash elements" do
45
+ it "symbolize keys in array elements too" do
46
+ hash = {
47
+ "error_response" => {
48
+ "errors" => [
49
+ { "code" => 3042, "message" => "Transação não encontrada" },
50
+ { "code" => 9999, "message" => "Qualquer outra mensagem" }
51
+ ]
52
+ }
53
+ }
54
+ hash.symbolize_all_keys!
55
+ hash.should == {
56
+ error_response: {
57
+ errors: [
58
+ { code: 3042, message: "Transação não encontrada" },
59
+ { code: 9999, message: "Qualquer outra mensagem" }
60
+ ]
61
+ }
62
+ }
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,202 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Tray::Checkout::Parser do
5
+ let(:parser) { Tray::Checkout::Parser.new }
6
+
7
+ describe "#response" do
8
+ context "with success response" do
9
+ let(:xml) { body_for :get_success_boleto }
10
+ let(:txn) { parser.response(xml) }
11
+
12
+ it "returns success" do
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
69
+ end
70
+
71
+ context "with error response" do
72
+ let(:xml) { body_for :get_failure_not_found }
73
+ let(:txn) { parser.response(xml) }
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
88
+ end
89
+
90
+ context "with validation error response" do
91
+ let(:xml) { body_for :create_failure_validation_errors }
92
+ let(:txn) { parser.response(xml) }
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
109
+ end
110
+ end
111
+
112
+ describe "#payment_params!" do
113
+ let :params do
114
+ {
115
+ token_account: "949u5uu9ef36f7u",
116
+ customer: {
117
+ name: "Pedro Bonamides",
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
+ }
174
+ }
175
+ end
176
+
177
+ let(:txn) { parser.payment_params!(params) }
178
+
179
+ it "sets customer gender expect API value" do
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"
196
+ end
197
+
198
+ it "sets payment method ID expect API value" do
199
+ txn[:payment][:payment_method_id].should == 4
200
+ end
201
+ end
202
+ end
@@ -0,0 +1,81 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Tray::Checkout::Transaction do
5
+ let(:transaction) { Tray::Checkout::Transaction.new }
6
+
7
+ describe "#get" do
8
+ context "when transaction is found" do
9
+ before :each do
10
+ mock_request_for(:get_success_boleto)
11
+ @txn = transaction.get("522045453u5uu32e0u8014f060uuu5uu")
12
+ end
13
+
14
+ it "returns success" do
15
+ @txn[:success].should be_true
16
+ end
17
+
18
+ it "returns transaction data" do
19
+ @txn[:transaction_token].should == "522045453u5uu32e0u8014f060uuu5uu"
20
+ @txn[:transaction_id].should == 501
21
+ end
22
+
23
+ it "returns payment data" do
24
+ @txn[:payment][:payment_method_name].should == "Boleto Bancario"
25
+ @txn[:payment][:url_payment].should == "http://checkout.sandbox.tray.com.br/payment/billet/u9uuu8731319u59u3073u9011uu6u6uu"
26
+ end
27
+ end
28
+
29
+ context "when transaction is not found" do
30
+ before :each do
31
+ mock_request_for(:get_failure_not_found)
32
+ @txn = transaction.get("987asd654lkj321qwe098poi")
33
+ end
34
+
35
+ it "does not return success" do
36
+ @txn[:success].should be_false
37
+ end
38
+
39
+ it "returns errors" do
40
+ @txn[:errors].first[:code].should == "003042"
41
+ @txn[:errors].first[:message].should == "Transação não encontrada"
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "#create" do
47
+ context "successful" do
48
+ before :each do
49
+ mock_request_for(:create_success_mastercard)
50
+ @txn = transaction.create(fake: "fake params")
51
+ end
52
+
53
+ it "returns success" do
54
+ @txn[:success].should be_true
55
+ end
56
+
57
+ it "returns transaction data" do
58
+ @txn[:transaction_token].should == "u522169ce59763uu717160u4u1183u43"
59
+ @txn[:status].should == :approved
60
+ @txn[:payment_method].should == :mastercard
61
+ end
62
+ end
63
+
64
+ context "unsuccess" do
65
+ before :each do
66
+ mock_request_for(:create_failure_validation_errors)
67
+ @txn = transaction.create(fake: "fake params")
68
+ end
69
+
70
+ it "does not return success" do
71
+ @txn[:success].should be_false
72
+ end
73
+
74
+ it "returns error" do
75
+ @txn[:errors].first[:code].should == "1"
76
+ @txn[:errors].first[:message].should == "não pode ficar em branco"
77
+ @txn[:errors].first[:message_complete].should == "Tipo não pode ficar em branco"
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Tray::Checkout::WebService do
5
+ describe "#request!" do
6
+ let(:web_service) { Tray::Checkout::WebService.new() }
7
+
8
+ it "returns XML response" do
9
+ mock_request_for("<xml><fake></fake>")
10
+ url = Tray::Checkout::Transaction::URL
11
+ params = { token: "qwe123asd456poi098lkj765" }
12
+ web_service.request!(url, params).should eql "<xml><fake></fake>"
13
+ end
14
+ end
15
+ end
16
+
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.0.0
4
+ version: 0.0.1
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: 2012-12-03 00:00:00.000000000 Z
12
+ date: 2012-12-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &14773020 !ruby/object:Gem::Requirement
16
+ requirement: &14772780 !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: *14773020
24
+ version_requirements: *14772780
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: log-me
27
- requirement: &14772790 !ruby/object:Gem::Requirement
27
+ requirement: &14772550 !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: *14772790
35
+ version_requirements: *14772550
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &14772600 !ruby/object:Gem::Requirement
38
+ requirement: &14772360 !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: *14772600
46
+ version_requirements: *14772360
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &14772330 !ruby/object:Gem::Requirement
49
+ requirement: &14772090 !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: *14772330
57
+ version_requirements: *14772090
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: webmock
60
- requirement: &14772080 !ruby/object:Gem::Requirement
60
+ requirement: &14771840 !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: *14772080
68
+ version_requirements: *14771840
69
69
  description: Tray Checkout API
70
70
  email:
71
71
  - prodis@gmail.com
@@ -81,11 +81,23 @@ files:
81
81
  - Rakefile
82
82
  - lib/tray-checkout.rb
83
83
  - lib/tray/checkout.rb
84
+ - lib/tray/checkout/constants.rb
85
+ - lib/tray/checkout/hash.rb
84
86
  - lib/tray/checkout/parser.rb
85
87
  - lib/tray/checkout/transaction.rb
86
88
  - lib/tray/checkout/version.rb
87
89
  - lib/tray/checkout/web_service.rb
88
90
  - spec/spec_helper.rb
91
+ - spec/support/mock_request.rb
92
+ - spec/support/responses/create_failure_validation_errors.xml
93
+ - spec/support/responses/create_success_boleto.xml
94
+ - spec/support/responses/create_success_mastercard.xml
95
+ - spec/support/responses/get_failure_not_found.xml
96
+ - spec/support/responses/get_success_boleto.xml
97
+ - spec/tray/checkout/hash_spec.rb
98
+ - spec/tray/checkout/parser_spec.rb
99
+ - spec/tray/checkout/transaction_spec.rb
100
+ - spec/tray/checkout/web_service_spec.rb
89
101
  - spec/tray/checkout_spec.rb
90
102
  - tray-checkout.gemspec
91
103
  homepage: https://github.com/prodis/tray-checkout
@@ -109,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
121
  version: '0'
110
122
  segments:
111
123
  - 0
112
- hash: 255298765
124
+ hash: -671685741
113
125
  requirements: []
114
126
  rubyforge_project:
115
127
  rubygems_version: 1.8.16
@@ -118,4 +130,14 @@ specification_version: 3
118
130
  summary: Tray Checkout API
119
131
  test_files:
120
132
  - spec/spec_helper.rb
133
+ - spec/support/mock_request.rb
134
+ - spec/support/responses/create_failure_validation_errors.xml
135
+ - spec/support/responses/create_success_boleto.xml
136
+ - spec/support/responses/create_success_mastercard.xml
137
+ - spec/support/responses/get_failure_not_found.xml
138
+ - spec/support/responses/get_success_boleto.xml
139
+ - spec/tray/checkout/hash_spec.rb
140
+ - spec/tray/checkout/parser_spec.rb
141
+ - spec/tray/checkout/transaction_spec.rb
142
+ - spec/tray/checkout/web_service_spec.rb
121
143
  - spec/tray/checkout_spec.rb