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
@@ -5,7 +5,6 @@ unless defined?(INTEGRATION_SPEC_HELPER_LOADED)
5
5
  SSL_TEST_PORT = ENV['SSL_TEST_PORT'] || 8444
6
6
 
7
7
  require File.dirname(__FILE__) + "/../spec_helper"
8
- require File.dirname(__FILE__) + "/../hacks/tcp_socket"
9
8
 
10
9
  def start_ssl_server
11
10
  web_server_pid_file = File.expand_path(File.join(File.dirname(__FILE__), "..", "httpsd.pid"))
@@ -13,9 +12,7 @@ unless defined?(INTEGRATION_SPEC_HELPER_LOADED)
13
12
  FileUtils.rm(web_server_pid_file) if File.exist?(web_server_pid_file)
14
13
  command = File.expand_path(File.join(File.dirname(__FILE__), "..", "script", "httpsd.rb"))
15
14
  `#{command} #{web_server_pid_file}`
16
- TCPSocket.wait_for_service :host => "127.0.0.1", :port => SSL_TEST_PORT
17
-
18
- yield
15
+ TCPSocket.new("127.0.0.1",SSL_TEST_PORT)
19
16
 
20
17
  10.times { unless File.exists?(web_server_pid_file); sleep 1; end }
21
18
  ensure
@@ -4,7 +4,6 @@ unless defined?(SPEC_HELPER_LOADED)
4
4
  require "rubygems"
5
5
  require "bundler/setup"
6
6
  require "rspec"
7
- require "libxml"
8
7
  require "pry"
9
8
 
10
9
  braintree_lib = "#{project_root}/lib"
@@ -28,10 +27,6 @@ unless defined?(SPEC_HELPER_LOADED)
28
27
  end
29
28
  end
30
29
 
31
- def now_in_eastern
32
- (Time.now.utc - 5*60*60).strftime("%Y-%m-%d")
33
- end
34
-
35
30
  module SpecHelper
36
31
 
37
32
  DefaultMerchantAccountId = "sandbox_credit_card"
@@ -188,16 +183,11 @@ unless defined?(SPEC_HELPER_LOADED)
188
183
  end
189
184
 
190
185
  def matches?(xml_string)
191
- @libxml_parse = Braintree::Xml::Parser.hash_from_xml(xml_string, Braintree::Xml::Libxml)
192
- @rexml_parse = Braintree::Xml::Parser.hash_from_xml(xml_string, Braintree::Xml::Rexml)
186
+ @libxml_parse = Braintree::Xml::Parser.hash_from_xml(xml_string)
193
187
  if @libxml_parse != @expected_hash
194
188
  @results = @libxml_parse
195
189
  @failed_parser = "libxml"
196
190
  false
197
- elsif @rexml_parse != @expected_hash
198
- @results = @rexml_parse
199
- @failed_parser = "rexml"
200
- false
201
191
  else
202
192
  true
203
193
  end
@@ -94,12 +94,4 @@ describe Braintree::Address do
94
94
  end.to raise_error(NoMethodError, /protected method .new/)
95
95
  end
96
96
  end
97
-
98
- describe "update" do
99
- it "raises an exception if hash includes an invalid key" do
100
- expect do
101
- Braintree::Address._new(Braintree::Configuration.gateway, {}).update(:street_address => "456 E Main", :invalid_key2 => "foo")
102
- end.to raise_error(ArgumentError, "invalid keys: invalid_key2")
103
- end
104
- end
105
97
  end
@@ -15,7 +15,6 @@ describe Braintree::CreditCard do
15
15
  :billing_address_id,
16
16
  :cardholder_name,
17
17
  :cvv,
18
- :device_session_id,
19
18
  :expiration_date,
20
19
  :expiration_month,
21
20
  :expiration_year,
@@ -23,7 +22,6 @@ describe Braintree::CreditCard do
23
22
  :token,
24
23
  :venmo_sdk_payment_method_code,
25
24
  :device_data,
26
- :fraud_merchant_id,
27
25
  :payment_method_nonce,
28
26
  {:external_vault=>[:network_transaction_id]},
29
27
  {:options => [:make_default, :verification_merchant_account_id, :verify_card, :verification_amount, :venmo_sdk_session, :fail_on_duplicate_payment_method, :verification_account_type]},
@@ -63,7 +61,6 @@ describe Braintree::CreditCard do
63
61
  :billing_address_id,
64
62
  :cardholder_name,
65
63
  :cvv,
66
- :device_session_id,
67
64
  :expiration_date,
68
65
  :expiration_month,
69
66
  :expiration_year,
@@ -71,7 +68,6 @@ describe Braintree::CreditCard do
71
68
  :token,
72
69
  :venmo_sdk_payment_method_code,
73
70
  :device_data,
74
- :fraud_merchant_id,
75
71
  :payment_method_nonce,
76
72
  {:external_vault=>[:network_transaction_id]},
77
73
  {:options => [:make_default, :verification_merchant_account_id, :verify_card, :verification_amount, :venmo_sdk_session, :fail_on_duplicate_payment_method, :verification_account_type]},
@@ -105,21 +101,6 @@ describe Braintree::CreditCard do
105
101
  end
106
102
  end
107
103
 
108
- describe "self.create_from_transparent_redirect" do
109
- it "raises an exception if the query string is forged" do
110
- expect do
111
- Braintree::CreditCard.create_from_transparent_redirect("http_status=200&forged=query_string")
112
- end.to raise_error(Braintree::ForgedQueryString)
113
- end
114
- end
115
-
116
- describe "self.create_credit_card_url" do
117
- it "returns the url" do
118
- config = Braintree::Configuration.instantiate
119
- Braintree::CreditCard.create_credit_card_url.should == "http#{config.ssl? ? 's' : ''}://#{config.server}:#{config.port}/merchants/integration_merchant_id/payment_methods/all/create_via_transparent_redirect_request"
120
- end
121
- end
122
-
123
104
  describe "==" do
124
105
  it "returns true if given a credit card with the same token" do
125
106
  first = Braintree::CreditCard._new(:gateway, :token => 123)
@@ -253,7 +234,7 @@ describe Braintree::CreditCard do
253
234
  describe "self.update" do
254
235
  it "raises an exception if attributes contain an invalid key" do
255
236
  expect do
256
- Braintree::CreditCard._new(Braintree::Configuration.gateway, {}).update(:invalid_key => 'val')
237
+ Braintree::CreditCard.update(:gateway, :invalid_key => 'val')
257
238
  end.to raise_error(ArgumentError, "invalid keys: invalid_key")
258
239
  end
259
240
  end
@@ -91,7 +91,6 @@ describe Braintree::Customer do
91
91
  :billing_address_id,
92
92
  :cardholder_name,
93
93
  :cvv,
94
- :device_session_id,
95
94
  :expiration_date,
96
95
  :expiration_month,
97
96
  :expiration_year,
@@ -99,7 +98,6 @@ describe Braintree::Customer do
99
98
  :token,
100
99
  :venmo_sdk_payment_method_code,
101
100
  :device_data,
102
- :fraud_merchant_id,
103
101
  :payment_method_nonce,
104
102
  {:external_vault=>[:network_transaction_id]},
105
103
  {:options => [:make_default, :verification_merchant_account_id, :verify_card, :verification_amount, :venmo_sdk_session, :fail_on_duplicate_payment_method, :verification_account_type]},
@@ -182,7 +180,6 @@ describe Braintree::Customer do
182
180
  :billing_address_id,
183
181
  :cardholder_name,
184
182
  :cvv,
185
- :device_session_id,
186
183
  :expiration_date,
187
184
  :expiration_month,
188
185
  :expiration_year,
@@ -190,7 +187,6 @@ describe Braintree::Customer do
190
187
  :token,
191
188
  :venmo_sdk_payment_method_code,
192
189
  :device_data,
193
- :fraud_merchant_id,
194
190
  :payment_method_nonce,
195
191
  {:external_vault=>[:network_transaction_id]},
196
192
  {:options => [
@@ -259,14 +255,6 @@ describe Braintree::Customer do
259
255
  end
260
256
  end
261
257
 
262
- describe "self.create_from_transparent_redirect" do
263
- it "raises an exception if the query string is forged" do
264
- expect do
265
- Braintree::Customer.create_from_transparent_redirect("http_status=200&forged=query_string")
266
- end.to raise_error(Braintree::ForgedQueryString)
267
- end
268
- end
269
-
270
258
  describe "==" do
271
259
  it "returns true when given a customer with the same id" do
272
260
  first = Braintree::Customer._new(:gateway, :id => 123)
@@ -198,13 +198,6 @@ describe Braintree::Dispute do
198
198
 
199
199
  describe "with optional params" do
200
200
  it "does not raise an exception if the optional parameters are valid" do
201
- Braintree::Http.stub(:new).and_return double.as_null_object
202
- expect do
203
- Braintree::Dispute.add_text_evidence("dispute_id", { content: "a", tag: "", sequence_number: 3 })
204
- end.to_not raise_error
205
- end
206
-
207
- it "does not raise an exception if the category parameter is provided" do
208
201
  Braintree::Http.stub(:new).and_return double.as_null_object
209
202
  expect do
210
203
  Braintree::Dispute.add_text_evidence("dispute_id", { content: "a", category: "", sequence_number: 3 })
@@ -327,7 +320,7 @@ describe Braintree::Dispute do
327
320
  dispute.transaction.payment_instrument_subtype.should == "Visa"
328
321
  end
329
322
 
330
- it "converts status_history hash into an array of Dispute::HistoryEvent objects" do
323
+ it "converts status_history hash into an array of Dispute::StatusHistory objects" do
331
324
  dispute = Braintree::Dispute._new(attributes)
332
325
 
333
326
  dispute.status_history.length.should == 1
@@ -398,10 +391,6 @@ describe Braintree::Dispute do
398
391
  describe "comments" do
399
392
  let(:dispute) { Braintree::Dispute._new(attributes) }
400
393
 
401
- it "#forwarded_comments returns `processor_comments`" do
402
- expect(dispute.forwarded_comments).to eq(dispute.processor_comments)
403
- end
404
-
405
394
  it "#processor_comments" do
406
395
  expect(dispute.processor_comments).to eq(attributes[:processor_comments])
407
396
  end
@@ -130,7 +130,7 @@ END
130
130
  expect(default_headers["Accept-Encoding"]).to eq("gzip")
131
131
  expect(default_headers["Content-Type"]).to eq("application/xml")
132
132
  expect(default_headers["User-Agent"]).to match(/Braintree Ruby Gem .*/)
133
- expect(default_headers["X-ApiVersion"]).to eq("5")
133
+ expect(default_headers["X-ApiVersion"]).to eq("6")
134
134
  end
135
135
 
136
136
  it "overwrites defaults with override headers" do
@@ -144,7 +144,7 @@ END
144
144
  expect(headers["Authorization"]).to eq("token")
145
145
  expect(headers["Content-Type"]).to eq("application/xml")
146
146
  expect(headers["User-Agent"]).to match(/Braintree Ruby Gem .*/)
147
- expect(headers["X-ApiVersion"]).to eq("5")
147
+ expect(headers["X-ApiVersion"]).to eq("6")
148
148
  end
149
149
 
150
150
  it "extends default headers when new headers are specified" do
@@ -156,7 +156,7 @@ END
156
156
  expect(headers["Accept-Encoding"]).to eq("gzip")
157
157
  expect(headers["Content-Type"]).to eq("application/xml")
158
158
  expect(headers["User-Agent"]).to match(/Braintree Ruby Gem .*/)
159
- expect(headers["X-ApiVersion"]).to eq("5")
159
+ expect(headers["X-ApiVersion"]).to eq("6")
160
160
  expect(headers["New-Header"]).to eq("New Value")
161
161
  end
162
162
  end
@@ -32,5 +32,19 @@ describe Braintree::LocalPaymentCompleted do
32
32
  local_payment_completed.transaction.order_id.should eq("an-order-id")
33
33
  local_payment_completed.transaction.status.should eq(Braintree::Transaction::Status::Authorized)
34
34
  end
35
+
36
+ it "initializes the object with the appropriate attributes set if no transaction is provided" do
37
+ params = {
38
+ payment_id: "a-payment-id",
39
+ payer_id: "a-payer-id",
40
+ payment_method_nonce: "a-nonce",
41
+ }
42
+ local_payment_completed = Braintree::LocalPaymentCompleted._new(params)
43
+
44
+ local_payment_completed.payment_id.should eq("a-payment-id")
45
+ local_payment_completed.payer_id.should eq("a-payer-id")
46
+ local_payment_completed.payment_method_nonce.should eq("a-nonce")
47
+ local_payment_completed.transaction.should be_nil
48
+ end
35
49
  end
36
50
  end
@@ -5,6 +5,7 @@ describe Braintree::Transaction::PayPalDetails do
5
5
  it "sets all fields" do
6
6
  details = Braintree::Transaction::PayPalDetails.new(
7
7
  :authorization_id => "id",
8
+ :billing_agreement_id => "billing-agreement-id",
8
9
  :capture_id => "capture-id",
9
10
  :custom_field => "custom-field",
10
11
  :debug_id => "debug-id",
@@ -30,6 +31,7 @@ describe Braintree::Transaction::PayPalDetails do
30
31
  )
31
32
 
32
33
  expect(details.authorization_id).to eq("id")
34
+ expect(details.billing_agreement_id).to eq("billing-agreement-id")
33
35
  expect(details.capture_id).to eq("capture-id")
34
36
  expect(details.custom_field).to eq("custom-field")
35
37
  expect(details.debug_id).to eq("debug-id")
@@ -17,14 +17,6 @@ describe Braintree::Transaction do
17
17
  end
18
18
  end
19
19
 
20
- describe "self.create_from_transparent_redirect" do
21
- it "raises an exception if the query string is forged" do
22
- expect do
23
- Braintree::Transaction.create_from_transparent_redirect("http_status=200&forged=query_string")
24
- end.to raise_error(Braintree::ForgedQueryString)
25
- end
26
- end
27
-
28
20
  describe "self.find" do
29
21
  it "raises error if passed empty string" do
30
22
  expect do
@@ -45,13 +37,6 @@ describe Braintree::Transaction do
45
37
  end
46
38
  end
47
39
 
48
- describe "self.create_transaction_url" do
49
- it "returns the url" do
50
- config = Braintree::Configuration.instantiate
51
- Braintree::Transaction.create_transaction_url.should == "http#{config.ssl? ? 's' : ''}://#{config.server}:#{config.port}/merchants/integration_merchant_id/transactions/all/create_via_transparent_redirect_request"
52
- end
53
- end
54
-
55
40
  describe "self.submit_for_settlement" do
56
41
  it "raises an ArgumentError if transaction_id is an invalid format" do
57
42
  expect do
@@ -106,7 +91,7 @@ describe Braintree::Transaction do
106
91
  }
107
92
  )
108
93
  disbursement = transaction.disbursement_details
109
- disbursement.disbursement_date.should == "2013-04-03"
94
+ disbursement.disbursement_date.should == Date.parse("2013-04-03")
110
95
  disbursement.settlement_amount.should == "120.00"
111
96
  disbursement.settlement_currency_iso_code.should == "USD"
112
97
  disbursement.settlement_currency_exchange_rate.should == "1"
@@ -171,25 +156,6 @@ describe Braintree::Transaction do
171
156
  transaction.three_d_secure_info.liability_shift_possible.should == true
172
157
  end
173
158
 
174
- it "sets up ideal_payment_details" do
175
- transaction = Braintree::Transaction._new(
176
- :gateway,
177
- :ideal_payment => {
178
- :ideal_payment_id => "idealpayment_abc_123",
179
- :ideal_transaction_id => "1150000008857321",
180
- :masked_iban => "12************7890",
181
- :bic => "RABONL2U",
182
- :image_url => "http://www.example.com/ideal.png"
183
- }
184
- )
185
-
186
- transaction.ideal_payment_details.ideal_payment_id.should == "idealpayment_abc_123"
187
- transaction.ideal_payment_details.ideal_transaction_id.should == "1150000008857321"
188
- transaction.ideal_payment_details.masked_iban.should == "12************7890"
189
- transaction.ideal_payment_details.bic.should == "RABONL2U"
190
- transaction.ideal_payment_details.image_url.should == "http://www.example.com/ideal.png"
191
- end
192
-
193
159
  it "sets up history attributes in status_history" do
194
160
  time = Time.utc(2010,1,14)
195
161
  transaction = Braintree::Transaction._new(
@@ -171,6 +171,22 @@ describe Braintree::Util do
171
171
  end
172
172
  end
173
173
 
174
+ describe "self.replace_key" do
175
+ it "replaces the target key with the replacement key" do
176
+ Braintree::Util.replace_key(
177
+ {:a => {:b => "some value"}},
178
+ :b,
179
+ :c).should == {:a => {:c => "some value"}}
180
+ end
181
+
182
+ it "returns hash with all of the original keys if the target key does not exist" do
183
+ Braintree::Util.replace_key(
184
+ {:some_key => "some value"},
185
+ :not_found,
186
+ :new_key).should == {:some_key => "some value"}
187
+ end
188
+ end
189
+
174
190
  describe "self._flatten_hash_keys" do
175
191
  it "flattens hash keys" do
176
192
  Braintree::Util._flatten_hash_keys(:nested => {
@@ -259,7 +275,7 @@ describe Braintree::Util do
259
275
  "UNSUPPORTED_CLIENT" => Braintree::UpgradeRequiredError,
260
276
  "RESOURCE_LIMIT" => Braintree::TooManyRequestsError,
261
277
  "INTERNAL" => Braintree::ServerError,
262
- "SERVICE_AVAILABILITY" => Braintree::DownForMaintenanceError,
278
+ "SERVICE_AVAILABILITY" => Braintree::ServiceUnavailableError,
263
279
  }
264
280
 
265
281
  errors.each do |graphQLError, exception|
@@ -321,6 +337,18 @@ describe Braintree::Util do
321
337
  end.to raise_error(Braintree::AuthorizationError)
322
338
  end
323
339
 
340
+ it "raises a NotFoundError if resource is not found" do
341
+ expect do
342
+ Braintree::Util.raise_exception_for_status_code(404)
343
+ end.to raise_error(Braintree::NotFoundError)
344
+ end
345
+
346
+ it "raises a RequestTimeoutError if the request times out" do
347
+ expect do
348
+ Braintree::Util.raise_exception_for_status_code(408)
349
+ end.to raise_error(Braintree::RequestTimeoutError)
350
+ end
351
+
324
352
  it "raises an UpgradeRequired if the client library is EOL'd" do
325
353
  expect do
326
354
  Braintree::Util.raise_exception_for_status_code(426)
@@ -339,10 +367,16 @@ describe Braintree::Util do
339
367
  end.to raise_error(Braintree::ServerError)
340
368
  end
341
369
 
342
- it "raises a DownForMaintenanceError if the server is down for maintenance" do
370
+ it "raises a ServiceUnavailableError if the server is unavailable" do
343
371
  expect do
344
372
  Braintree::Util.raise_exception_for_status_code(503)
345
- end.to raise_error(Braintree::DownForMaintenanceError)
373
+ end.to raise_error(Braintree::ServiceUnavailableError)
374
+ end
375
+
376
+ it "raises a GatewayTimeoutError if the gateway times out" do
377
+ expect do
378
+ Braintree::Util.raise_exception_for_status_code(504)
379
+ end.to raise_error(Braintree::GatewayTimeoutError)
346
380
  end
347
381
 
348
382
  it "raises an UnexpectedError if some other code is returned" do
@@ -275,7 +275,7 @@ describe Braintree::WebhookNotification do
275
275
  notification.kind.should == Braintree::WebhookNotification::Kind::TransactionDisbursed
276
276
  notification.transaction.id.should == "my_id"
277
277
  notification.transaction.amount.should == 1_00
278
- notification.transaction.disbursement_details.disbursement_date.should == "2013-07-09"
278
+ notification.transaction.disbursement_details.disbursement_date.should == Date.parse("2013-07-09")
279
279
  end
280
280
 
281
281
  it "builds a sample notification for a disbursement_exception webhook" do
@@ -57,24 +57,29 @@ describe Braintree::Xml::Parser do
57
57
  xml.should parse_to(:root => {:customers => [{:name => "Adam"}, {:name => "Ben"}]})
58
58
  end
59
59
 
60
- it "parses using libxml when not using ruby 2.0" do
61
- xml = "<root><foo type=\"integer\">123</foo></root>"
62
- stub_const("RUBY_VERSION", "2.1.1")
63
- ::Braintree::Xml::Libxml.should_receive(:parse).and_call_original
64
-
65
- Braintree::Xml::Parser.hash_from_xml(xml)
60
+ it "parses an array" do
61
+ xml = <<-END
62
+ <root>
63
+ <customers type="array">
64
+ <customer><name>Adam</name><customer-id>1</customer-id></customer>
65
+ <customer><name>Ben</name><customer-id>2</customer-id></customer>
66
+ </customers>
67
+ </root>
68
+ END
69
+ xml.should parse_to(:root => {:customers => [{:name => "Adam", :customer_id => "1"}, {:name => "Ben", :customer_id => "2"}]})
66
70
  end
67
71
 
68
- it "parses using rexml when using ruby 2.0 to avoid Libxml segfault" do
69
- segfault_prone_library_in_ruby_2_0 = ::Braintree::Xml::Libxml
70
-
71
- xml = "<root><foo type=\"integer\">123</foo></root>"
72
- stub_const("RUBY_VERSION", "2.0.0")
73
-
74
- ::Braintree::Xml::Rexml.should_receive(:parse).and_call_original
75
- segfault_prone_library_in_ruby_2_0.should_not_receive(:parse)
76
-
77
- Braintree::Xml::Parser.hash_from_xml(xml)
72
+ it "parses nested objects" do
73
+ xml = <<-END
74
+ <root>
75
+ <paypal-details>
76
+ <deets type="array"><super-secrets><secret-code>1234</secret-code></super-secrets></deets>
77
+ <payer-email>abc@test.com</payer-email>
78
+ <payment-id>1234567890</payment-id>
79
+ </paypal-details>
80
+ </root>
81
+ END
82
+ xml.should parse_to(:root => {:paypal_details => {:deets => [{:secret_code => "1234"}], :payer_email => "abc@test.com", :payment_id => "1234567890"}})
78
83
  end
79
84
  end
80
85
  end