braintree 2.104.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +6 -3
  4. data/lib/braintree.rb +3 -17
  5. data/lib/braintree/address.rb +0 -22
  6. data/lib/braintree/base_module.rb +6 -0
  7. data/lib/braintree/bin_data.rb +9 -2
  8. data/lib/braintree/configuration.rb +1 -1
  9. data/lib/braintree/credit_card.rb +0 -75
  10. data/lib/braintree/credit_card_gateway.rb +3 -32
  11. data/lib/braintree/credit_card_verification.rb +13 -0
  12. data/lib/braintree/customer.rb +3 -74
  13. data/lib/braintree/customer_gateway.rb +0 -23
  14. data/lib/braintree/dispute.rb +1 -7
  15. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  16. data/lib/braintree/dispute_gateway.rb +2 -7
  17. data/lib/braintree/error_codes.rb +139 -170
  18. data/lib/braintree/exceptions.rb +5 -3
  19. data/lib/braintree/gateway.rb +0 -14
  20. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +1 -2
  21. data/lib/braintree/local_payment_completed.rb +1 -1
  22. data/lib/braintree/merchant_account_gateway.rb +2 -0
  23. data/lib/braintree/payment_instrument_type.rb +1 -5
  24. data/lib/braintree/payment_method_gateway.rb +4 -9
  25. data/lib/braintree/payment_method_parser.rb +1 -8
  26. data/lib/braintree/subscription.rb +5 -5
  27. data/lib/braintree/successful_result.rb +0 -1
  28. data/lib/braintree/test/nonce.rb +4 -23
  29. data/lib/braintree/transaction.rb +4 -80
  30. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  31. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  32. data/lib/braintree/transaction/paypal_details.rb +1 -0
  33. data/lib/braintree/transaction/subscription_details.rb +2 -0
  34. data/lib/braintree/transaction_gateway.rb +12 -21
  35. data/lib/braintree/transaction_search.rb +0 -1
  36. data/lib/braintree/util.rb +17 -2
  37. data/lib/braintree/version.rb +2 -2
  38. data/lib/braintree/webhook_notification.rb +0 -10
  39. data/lib/braintree/webhook_testing_gateway.rb +0 -43
  40. data/lib/braintree/xml/libxml.rb +1 -0
  41. data/lib/braintree/xml/parser.rb +11 -34
  42. data/spec/integration/braintree/address_spec.rb +2 -89
  43. data/spec/integration/braintree/client_api/spec_helper.rb +0 -26
  44. data/spec/integration/braintree/credit_card_spec.rb +6 -471
  45. data/spec/integration/braintree/customer_spec.rb +22 -362
  46. data/spec/integration/braintree/dispute_search_spec.rb +3 -3
  47. data/spec/integration/braintree/dispute_spec.rb +1 -2
  48. data/spec/integration/braintree/payment_method_spec.rb +77 -120
  49. data/spec/integration/braintree/subscription_spec.rb +11 -16
  50. data/spec/integration/braintree/transaction_search_spec.rb +3 -3
  51. data/spec/integration/braintree/transaction_spec.rb +106 -511
  52. data/spec/integration/spec_helper.rb +1 -4
  53. data/spec/spec_helper.rb +1 -11
  54. data/spec/unit/braintree/address_spec.rb +0 -8
  55. data/spec/unit/braintree/credit_card_spec.rb +1 -20
  56. data/spec/unit/braintree/customer_spec.rb +0 -12
  57. data/spec/unit/braintree/dispute_spec.rb +1 -12
  58. data/spec/unit/braintree/http_spec.rb +3 -3
  59. data/spec/unit/braintree/local_payment_completed_spec.rb +14 -0
  60. data/spec/unit/braintree/transaction/paypal_details_spec.rb +2 -0
  61. data/spec/unit/braintree/transaction_spec.rb +1 -35
  62. data/spec/unit/braintree/util_spec.rb +37 -3
  63. data/spec/unit/braintree/webhook_notification_spec.rb +1 -1
  64. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  65. metadata +26 -30
  66. data/lib/braintree/amex_express_checkout_card.rb +0 -40
  67. data/lib/braintree/coinbase_account.rb +0 -34
  68. data/lib/braintree/europe_bank_account.rb +0 -36
  69. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  70. data/lib/braintree/ideal_payment.rb +0 -61
  71. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  72. data/lib/braintree/masterpass_card.rb +0 -83
  73. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  74. data/lib/braintree/transaction/coinbase_details.rb +0 -16
  75. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  76. data/lib/braintree/transaction/masterpass_card_details.rb +0 -49
  77. data/lib/braintree/transparent_redirect.rb +0 -40
  78. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  79. data/lib/braintree/xml/rexml.rb +0 -71
  80. data/spec/hacks/tcp_socket.rb +0 -18
  81. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  82. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  83. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  84. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
  85. data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
@@ -1,268 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
-
3
- describe Braintree::TransparentRedirect do
4
- it "raises a DownForMaintenanceError when app is in maintenance mode on TR requests" do
5
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge({}))
6
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Configuration.instantiate.base_merchant_url + "/test/maintenance")
7
- expect do
8
- Braintree::Customer.create_from_transparent_redirect(query_string_response)
9
- end.to raise_error(Braintree::DownForMaintenanceError)
10
- end
11
-
12
- it "raises a DownForMaintenanceError when the request times out", :if => ENV['UNICORN'] do
13
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge({}))
14
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Configuration.instantiate.base_merchant_url + "/test/die")
15
- expect do
16
- Braintree::Customer.create_from_transparent_redirect(query_string_response)
17
- end.to raise_error(Braintree::DownForMaintenanceError)
18
- end
19
-
20
- it "raises an AuthenticationError when authentication fails on TR requests" do
21
- SpecHelper.using_configuration(:private_key => "incorrect") do
22
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge({}))
23
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.create_customer_url)
24
- expect do
25
- Braintree::Customer.create_from_transparent_redirect(query_string_response)
26
- end.to raise_error(Braintree::AuthenticationError)
27
- end
28
- end
29
-
30
- describe "self.confirm" do
31
- context "transaction" do
32
- it "successfully confirms a transaction create" do
33
- params = {
34
- :transaction => {
35
- :amount => Braintree::Test::TransactionAmounts::Authorize,
36
- :credit_card => {
37
- :number => Braintree::Test::CreditCardNumbers::Visa,
38
- :expiration_date => "05/2009"
39
- }
40
- }
41
- }
42
- tr_data_params = {
43
- :transaction => {
44
- :type => "sale"
45
- }
46
- }
47
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
48
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
49
- result = Braintree::TransparentRedirect.confirm(query_string_response)
50
-
51
- result.success?.should == true
52
- transaction = result.transaction
53
- transaction.type.should == "sale"
54
- transaction.amount.should == BigDecimal("1000.00")
55
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
56
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
57
- transaction.credit_card_details.expiration_date.should == "05/2009"
58
- end
59
-
60
- it "allows specifying a service fee" do
61
- params = {
62
- :transaction => {
63
- :amount => Braintree::Test::TransactionAmounts::Authorize,
64
- :merchant_account_id => SpecHelper::NonDefaultSubMerchantAccountId,
65
- :credit_card => {
66
- :number => Braintree::Test::CreditCardNumbers::Visa,
67
- :expiration_date => "05/2009"
68
- },
69
- :service_fee_amount => "1.00"
70
- }
71
- }
72
- tr_data_params = {
73
- :transaction => {
74
- :type => "sale"
75
- }
76
- }
77
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
78
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
79
- result = Braintree::TransparentRedirect.confirm(query_string_response)
80
- result.success?.should == true
81
- result.transaction.service_fee_amount.should == BigDecimal("1.00")
82
- end
83
-
84
- it "returns an error when there's an error" do
85
- params = {
86
- :transaction => {
87
- :amount => Braintree::Test::TransactionAmounts::Authorize,
88
- :credit_card => {
89
- :number => "abc",
90
- :expiration_date => "05/2009"
91
- }
92
- }
93
- }
94
- tr_data_params = {
95
- :transaction => {
96
- :type => "sale"
97
- }
98
- }
99
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
100
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
101
- result = Braintree::TransparentRedirect.confirm(query_string_response)
102
-
103
- result.success?.should == false
104
- result.errors.for(:transaction).for(:credit_card).on(:number).size.should > 0
105
- end
106
- end
107
-
108
- context "customer" do
109
- it "successfully confirms a customer create" do
110
- params = {
111
- :customer => {
112
- :first_name => "John",
113
- }
114
- }
115
- tr_data_params = {
116
- :customer => {
117
- :last_name => "Doe",
118
- }
119
- }
120
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
121
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
122
- result = Braintree::TransparentRedirect.confirm(query_string_response)
123
-
124
- result.success?.should == true
125
- customer = result.customer
126
- customer.first_name.should == "John"
127
- customer.last_name.should == "Doe"
128
- end
129
-
130
- it "successfully confirms a customer update" do
131
- customer = Braintree::Customer.create(
132
- :first_name => "Joe",
133
- :last_name => "Cool"
134
- ).customer
135
-
136
- params = {
137
- :customer => {
138
- :first_name => "John",
139
- }
140
- }
141
- tr_data_params = {
142
- :customer_id => customer.id,
143
- :customer => {
144
- :last_name => "Uncool",
145
- }
146
- }
147
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
148
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
149
- result = Braintree::TransparentRedirect.confirm(query_string_response)
150
-
151
- result.success?.should == true
152
- customer = Braintree::Customer.find(customer.id)
153
- customer.first_name.should == "John"
154
- customer.last_name.should == "Uncool"
155
- end
156
-
157
- it "returns an error result when there are errors" do
158
- params = {
159
- :customer => {
160
- :first_name => "John",
161
- }
162
- }
163
- tr_data_params = {
164
- :customer => {
165
- :last_name => "Doe",
166
- :email => "invalid"
167
- }
168
- }
169
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
170
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
171
- result = Braintree::TransparentRedirect.confirm(query_string_response)
172
-
173
- result.success?.should == false
174
- result.errors.for(:customer).on(:email).size.should > 0
175
- end
176
- end
177
-
178
- context "credit_card" do
179
- it "successfully confirms a credit_card create" do
180
- customer = Braintree::Customer.create(:first_name => "John", :last_name => "Doe").customer
181
-
182
- params = {
183
- :credit_card => {
184
- :cardholder_name => "John Doe"
185
- }
186
- }
187
- tr_data_params = {
188
- :credit_card => {
189
- :customer_id => customer.id,
190
- :number => Braintree::Test::CreditCardNumbers::Visa,
191
- :expiration_date => "10/10"
192
- }
193
- }
194
- tr_data = Braintree::TransparentRedirect.create_credit_card_data(
195
- {:redirect_url => "http://example.com"}.merge(tr_data_params)
196
- )
197
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
198
- result = Braintree::TransparentRedirect.confirm(query_string_response)
199
-
200
- result.success?.should == true
201
- credit_card = result.credit_card
202
- credit_card.cardholder_name.should == "John Doe"
203
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
204
- credit_card.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
205
- credit_card.expiration_date.should == "10/2010"
206
- end
207
-
208
- it "successfully confirms a credit_card update" do
209
- customer = Braintree::Customer.create(:first_name => "John", :last_name => "Doe").customer
210
- credit_card = Braintree::CreditCard.create(
211
- :customer_id => customer.id,
212
- :number => Braintree::Test::CreditCardNumbers::Visa,
213
- :expiration_date => "10/10"
214
- ).credit_card
215
-
216
- params = {
217
- :credit_card => {
218
- :cardholder_name => "John Doe"
219
- }
220
- }
221
- tr_data_params = {
222
- :payment_method_token => credit_card.token,
223
- :credit_card => {
224
- :number => Braintree::Test::CreditCardNumbers::MasterCard,
225
- :expiration_date => "11/11"
226
- }
227
- }
228
- tr_data = Braintree::TransparentRedirect.update_credit_card_data(
229
- {:redirect_url => "http://example.com"}.merge(tr_data_params)
230
- )
231
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
232
- result = Braintree::TransparentRedirect.confirm(query_string_response)
233
-
234
- result.success?.should == true
235
- credit_card = result.credit_card
236
- credit_card.cardholder_name.should == "John Doe"
237
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
238
- credit_card.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
239
- credit_card.expiration_date.should == "11/2011"
240
- end
241
-
242
- it "returns an error result where there are errors" do
243
- customer = Braintree::Customer.create(:first_name => "John", :last_name => "Doe").customer
244
-
245
- params = {
246
- :credit_card => {
247
- :cardholder_name => "John Doe"
248
- }
249
- }
250
- tr_data_params = {
251
- :credit_card => {
252
- :customer_id => customer.id,
253
- :number => Braintree::Test::CreditCardNumbers::Visa,
254
- :expiration_date => "123"
255
- }
256
- }
257
- tr_data = Braintree::TransparentRedirect.create_credit_card_data(
258
- {:redirect_url => "http://example.com"}.merge(tr_data_params)
259
- )
260
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
261
- result = Braintree::TransparentRedirect.confirm(query_string_response)
262
-
263
- result.success?.should == false
264
- result.errors.for(:credit_card).size.should > 0
265
- end
266
- end
267
- end
268
- end
@@ -1,223 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
-
3
- describe Braintree::TransparentRedirect do
4
- describe "self.create_credit_card_data" do
5
- it "raises an exception if any keys are invalid" do
6
- expect do
7
- Braintree::TransparentRedirect.create_credit_card_data(
8
- :credit_card => {:number => "ok", :invalid_key => "bad"}
9
- )
10
- end.to raise_error(ArgumentError, "invalid keys: credit_card[invalid_key]")
11
- end
12
- end
13
-
14
- describe "self.create_customer_data" do
15
- it "raises an exception if any keys are invalid" do
16
- expect do
17
- Braintree::TransparentRedirect.create_customer_data(
18
- :customer => {:first_name => "ok", :invalid_key => "bad"}
19
- )
20
- end.to raise_error(ArgumentError, "invalid keys: customer[invalid_key]")
21
- end
22
- end
23
-
24
- describe "self.parse_and_validate_query_string" do
25
- it "returns the parsed query string params if the hash is valid" do
26
- query_string_without_hash = "one=1&two=2&http_status=200"
27
- hash = Braintree::Digest.hexdigest(Braintree::Configuration.private_key, query_string_without_hash)
28
-
29
- query_string_with_hash = "#{query_string_without_hash}&hash=#{hash}"
30
- result = Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string query_string_with_hash
31
- result.should == {:one => "1", :two => "2", :http_status => "200", :hash => hash}
32
- end
33
-
34
- it "returns the parsed query string params if the hash is valid and hash is first parameter" do
35
- query_string_without_hash = "one=1&two=2&http_status=200"
36
- hash = Braintree::Digest.hexdigest(Braintree::Configuration.private_key, query_string_without_hash)
37
-
38
- query_string_with_hash = "hash=#{hash}&#{query_string_without_hash}"
39
- result = Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string query_string_with_hash
40
- result.should == {:one => "1", :two => "2", :http_status => "200", :hash => hash}
41
- end
42
-
43
- it "returns the parsed query string params regardless of hash position if the hash is valid" do
44
- query_string_without_hash = "one=1&two=2&http_status=200"
45
- hash = Braintree::Digest.hexdigest(Braintree::Configuration.private_key, query_string_without_hash)
46
-
47
- query_string_with_hash = "one=1&hash=#{hash}&two=2&http_status=200"
48
- result = Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string query_string_with_hash
49
- result.should == {:one => "1", :two => "2", :http_status => "200", :hash => hash}
50
- end
51
-
52
- it "raises Braintree::ForgedQueryString if the hash param is not valid" do
53
- query_string_without_hash = "http_status=200&one=1&two=2"
54
- hash = Digest::SHA1.hexdigest("invalid#{query_string_without_hash}")
55
-
56
- query_string_with_hash = "#{query_string_without_hash}&hash=#{hash}"
57
- expect do
58
- Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string query_string_with_hash
59
- end.to raise_error(Braintree::ForgedQueryString)
60
- end
61
-
62
- it "raises Braintree::ForgedQueryString if hash is missing from the query string" do
63
- expect do
64
- Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string "http_status=200&query_string=without_a_hash"
65
- end.to raise_error(Braintree::ForgedQueryString)
66
- end
67
-
68
- it "does not raise Braintree::ForgedQueryString if query string is url encoded" do
69
- url_encoded_query_string_without_hash = "http_status%3D200%26nested_param%5Bsub_param%5D%3Dtesting"
70
- url_decoded_query_string_without_hash = Braintree::Util.url_decode(url_encoded_query_string_without_hash)
71
-
72
- hash = Braintree::Digest.hexdigest(Braintree::Configuration.private_key, url_decoded_query_string_without_hash)
73
-
74
- url_encoded_query_string = "#{url_encoded_query_string_without_hash}&hash=#{hash}"
75
-
76
- expect do
77
- Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string url_encoded_query_string
78
- end.to raise_error(Braintree::UnexpectedError)
79
- end
80
-
81
- it "does not raise Braintree::ForgedQueryString if query string is url decoded" do
82
- url_decoded_query_string_without_hash = "http_status=200&nested_param[sub_param]=testing"
83
- url_encoded_query_string_without_hash = Braintree::Util.url_encode(url_decoded_query_string_without_hash)
84
-
85
- hash = Braintree::Digest.hexdigest(Braintree::Configuration.private_key, url_encoded_query_string_without_hash)
86
-
87
- url_decoded_query_string = "#{url_decoded_query_string_without_hash}&hash=#{hash}"
88
-
89
- expect do
90
- Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string url_decoded_query_string
91
- end.to_not raise_error
92
- end
93
-
94
- it "does not raise Braintree::ForgedQueryString if the query string is partially encoded" do
95
- url_partially_encoded_query_string_without_hash = "http_status=200&nested_param%5Bsub_param%5D=testing"
96
-
97
- hash = Braintree::Digest.hexdigest(Braintree::Configuration.private_key, url_partially_encoded_query_string_without_hash)
98
-
99
- url_partially_encoded_query_string = "#{url_partially_encoded_query_string_without_hash}&hash=#{hash}"
100
-
101
- expect do
102
- Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string url_partially_encoded_query_string
103
- end.to_not raise_error
104
- end
105
-
106
- it "raises an AuthenticationError if authentication fails" do
107
- expect do
108
- Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string add_hash_to_query_string("http_status=401")
109
- end.to raise_error(Braintree::AuthenticationError)
110
- end
111
-
112
- it "raises an AuthorizationError if authorization fails" do
113
- expect do
114
- Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string add_hash_to_query_string("http_status=403")
115
- end.to raise_error(Braintree::AuthorizationError)
116
- end
117
-
118
- it "raises an UnexpectedError if http_status is not in query string" do
119
- expect do
120
- Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string add_hash_to_query_string("no_http_status=x")
121
- end.to raise_error(Braintree::UnexpectedError, "expected query string to have an http_status param")
122
- end
123
-
124
- it "raises a ServerError if the server 500's" do
125
- expect do
126
- Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string add_hash_to_query_string("http_status=500")
127
- end.to raise_error(Braintree::ServerError)
128
- end
129
-
130
- it "raises a DownForMaintenanceError if the server is down for maintenance" do
131
- expect do
132
- Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string add_hash_to_query_string("http_status=503")
133
- end.to raise_error(Braintree::DownForMaintenanceError)
134
- end
135
-
136
- it "raises an UnexpectedError if some other code is returned" do
137
- expect do
138
- Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string add_hash_to_query_string("http_status=600")
139
- end.to raise_error(Braintree::UnexpectedError, "Unexpected HTTP_RESPONSE 600")
140
- end
141
- end
142
-
143
- describe "self.transaction_data" do
144
- it "raises an exception if any keys are invalid" do
145
- expect do
146
- Braintree::TransparentRedirect.transaction_data(
147
- :transaction => {:amount => "100.00", :invalid_key => "bad"}
148
- )
149
- end.to raise_error(ArgumentError, "invalid keys: transaction[invalid_key]")
150
- end
151
-
152
- it "raises an exception if not given a type" do
153
- expect do
154
- Braintree::TransparentRedirect.transaction_data(
155
- :redirect_url => "http://example.com",
156
- :transaction => {:amount => "100.00"}
157
- )
158
- end.to raise_error(ArgumentError, "expected transaction[type] of sale or credit, was: nil")
159
- end
160
-
161
- it "raises an exception if not given a type of sale or credit" do
162
- expect do
163
- Braintree::TransparentRedirect.transaction_data(
164
- :redirect_url => "http://example.com",
165
- :transaction => {:amount => "100.00", :type => "auth"}
166
- )
167
- end.to raise_error(ArgumentError, "expected transaction[type] of sale or credit, was: \"auth\"")
168
- end
169
- end
170
-
171
- describe "self.update_credit_card_data" do
172
- it "raises an exception if any keys are invalid" do
173
- expect do
174
- Braintree::TransparentRedirect.update_credit_card_data(
175
- :credit_card => {:number => "ok", :invalid_key => "bad"}
176
- )
177
- end.to raise_error(ArgumentError, "invalid keys: credit_card[invalid_key]")
178
- end
179
-
180
- it "raises an exception if not given a payment_method_token" do
181
- expect do
182
- Braintree::TransparentRedirect.update_credit_card_data({})
183
- end.to raise_error(ArgumentError, "expected params to contain :payment_method_token of payment method to update")
184
- end
185
- end
186
-
187
- describe "self.update_customer_data" do
188
- it "raises an exception if any keys are invalid" do
189
- expect do
190
- Braintree::TransparentRedirect.update_customer_data(
191
- :customer => {:first_name => "ok", :invalid_key => "bad"}
192
- )
193
- end.to raise_error(ArgumentError, "invalid keys: customer[invalid_key]")
194
- end
195
-
196
- it "raises an exception if not given a customer_id" do
197
- expect do
198
- Braintree::TransparentRedirect.update_customer_data({})
199
- end.to raise_error(ArgumentError, "expected params to contain :customer_id of customer to update")
200
- end
201
- end
202
-
203
- describe "self._data" do
204
- it "raises an exception if :redirect_url isn't given" do
205
- expect do
206
- Braintree::TransparentRedirect.create_customer_data(:redirect_url => nil)
207
- end.to raise_error(ArgumentError, "expected params to contain :redirect_url")
208
- end
209
-
210
- it "only encodes tr data once" do
211
- tr_data = Braintree::TransparentRedirect.create_customer_data(:redirect_url => "example.com")
212
-
213
- tr_data.should include("|")
214
- tr_data.should include("&")
215
- end
216
- end
217
-
218
- def add_hash_to_query_string(query_string_without_hash)
219
- hash = Braintree::SignatureService.new(Braintree::Configuration.private_key).hash(query_string_without_hash)
220
- query_string_without_hash + "&hash=" + hash
221
- end
222
- end
223
-