braintree 2.4.0 → 2.5.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.
Files changed (66) hide show
  1. data/README.rdoc +4 -0
  2. data/lib/braintree.rb +43 -32
  3. data/lib/braintree/add_on.rb +4 -0
  4. data/lib/braintree/address.rb +18 -72
  5. data/lib/braintree/address_gateway.rb +76 -0
  6. data/lib/braintree/advanced_search.rb +31 -13
  7. data/lib/braintree/base_module.rb +6 -0
  8. data/lib/braintree/configuration.rb +57 -39
  9. data/lib/braintree/credit_card.rb +75 -129
  10. data/lib/braintree/credit_card_gateway.rb +133 -0
  11. data/lib/braintree/credit_card_verification.rb +8 -0
  12. data/lib/braintree/customer.rb +70 -123
  13. data/lib/braintree/customer_gateway.rb +121 -0
  14. data/lib/braintree/digest.rb +2 -2
  15. data/lib/braintree/discount.rb +4 -0
  16. data/lib/braintree/error_codes.rb +50 -5
  17. data/lib/braintree/error_result.rb +4 -18
  18. data/lib/braintree/errors.rb +1 -2
  19. data/lib/braintree/exceptions.rb +11 -16
  20. data/lib/braintree/gateway.rb +39 -0
  21. data/lib/braintree/http.rb +30 -26
  22. data/lib/braintree/modification.rb +23 -0
  23. data/lib/braintree/resource_collection.rb +1 -1
  24. data/lib/braintree/subscription.rb +29 -129
  25. data/lib/braintree/subscription_gateway.rb +122 -0
  26. data/lib/braintree/subscription_search.rb +6 -7
  27. data/lib/braintree/successful_result.rb +1 -12
  28. data/lib/braintree/test/credit_card_numbers.rb +4 -2
  29. data/lib/braintree/test/transaction_amounts.rb +3 -0
  30. data/lib/braintree/transaction.rb +83 -243
  31. data/lib/braintree/transaction/credit_card_details.rb +4 -4
  32. data/lib/braintree/transaction_gateway.rb +124 -0
  33. data/lib/braintree/transaction_search.rb +5 -3
  34. data/lib/braintree/transparent_redirect.rb +19 -112
  35. data/lib/braintree/transparent_redirect_gateway.rb +105 -0
  36. data/lib/braintree/util.rb +4 -0
  37. data/lib/braintree/validation_error.rb +1 -0
  38. data/lib/braintree/validation_error_collection.rb +5 -23
  39. data/lib/braintree/version.rb +2 -2
  40. data/lib/braintree/xml/parser.rb +1 -1
  41. data/lib/braintree/xml/rexml.rb +2 -2
  42. data/spec/integration/braintree/advanced_search_spec.rb +532 -0
  43. data/spec/integration/braintree/credit_card_spec.rb +5 -8
  44. data/spec/integration/braintree/http_spec.rb +53 -39
  45. data/spec/integration/braintree/subscription_spec.rb +678 -213
  46. data/spec/integration/braintree/transaction_search_spec.rb +318 -43
  47. data/spec/integration/braintree/transaction_spec.rb +134 -3
  48. data/spec/integration/braintree/transparent_redirect_spec.rb +1 -1
  49. data/spec/spec_helper.rb +55 -4
  50. data/spec/unit/braintree/address_spec.rb +8 -8
  51. data/spec/unit/braintree/base_module_spec.rb +1 -1
  52. data/spec/unit/braintree/configuration_spec.rb +34 -29
  53. data/spec/unit/braintree/credit_card_spec.rb +14 -12
  54. data/spec/unit/braintree/credit_card_verification_spec.rb +16 -0
  55. data/spec/unit/braintree/customer_spec.rb +10 -8
  56. data/spec/unit/braintree/digest_spec.rb +8 -17
  57. data/spec/unit/braintree/error_result_spec.rb +12 -2
  58. data/spec/unit/braintree/http_spec.rb +2 -2
  59. data/spec/unit/braintree/subscription_search_spec.rb +77 -0
  60. data/spec/unit/braintree/subscription_spec.rb +16 -8
  61. data/spec/unit/braintree/transaction_spec.rb +17 -12
  62. data/spec/unit/braintree/transparent_redirect_spec.rb +12 -12
  63. data/spec/unit/braintree/util_spec.rb +24 -0
  64. data/spec/unit/braintree/xml/parser_spec.rb +1 -1
  65. data/spec/unit/braintree_spec.rb +1 -1
  66. metadata +16 -5
@@ -3,12 +3,13 @@ require File.dirname(__FILE__) + "/../spec_helper"
3
3
  describe Braintree::Customer do
4
4
  describe "inspect" do
5
5
  it "includes the id first" do
6
- output = Braintree::Customer._new({:first_name => 'Dan', :id => '1234'}).inspect
6
+ output = Braintree::Customer._new(:gateway, {:first_name => 'Dan', :id => '1234'}).inspect
7
7
  output.should include("#<Braintree::Customer id: \"1234\",")
8
8
  end
9
9
 
10
10
  it "includes all customer attributes" do
11
11
  customer = Braintree::Customer._new(
12
+ :gateway,
12
13
  :company => "Company",
13
14
  :email => "e@mail.com",
14
15
  :fax => "483-438-5821",
@@ -50,7 +51,7 @@ describe Braintree::Customer do
50
51
 
51
52
  describe "self.create_signature" do
52
53
  it "should be what we expect" do
53
- Braintree::Customer._create_signature.should == [
54
+ Braintree::CustomerGateway._create_signature.should == [
54
55
  :company,
55
56
  :email,
56
57
  :fax,
@@ -90,7 +91,7 @@ describe Braintree::Customer do
90
91
 
91
92
  describe "self.update_signature" do
92
93
  it "should be what we expect" do
93
- Braintree::Customer._update_signature.should == [
94
+ Braintree::CustomerGateway._update_signature.should == [
94
95
  :company,
95
96
  :email,
96
97
  :fax,
@@ -144,23 +145,23 @@ describe Braintree::Customer do
144
145
 
145
146
  describe "==" do
146
147
  it "returns true when given a customer with the same id" do
147
- first = Braintree::Customer._new(:id => 123)
148
- second = Braintree::Customer._new(:id => 123)
148
+ first = Braintree::Customer._new(:gateway, :id => 123)
149
+ second = Braintree::Customer._new(:gateway, :id => 123)
149
150
 
150
151
  first.should == second
151
152
  second.should == first
152
153
  end
153
154
 
154
155
  it "returns false when given a customer with a different id" do
155
- first = Braintree::Customer._new(:id => 123)
156
- second = Braintree::Customer._new(:id => 124)
156
+ first = Braintree::Customer._new(:gateway, :id => 123)
157
+ second = Braintree::Customer._new(:gateway, :id => 124)
157
158
 
158
159
  first.should_not == second
159
160
  second.should_not == first
160
161
  end
161
162
 
162
163
  it "returns false when not given a customer" do
163
- customer = Braintree::Customer._new(:id => 123)
164
+ customer = Braintree::Customer._new(:gateway, :id => 123)
164
165
  customer.should_not == "not a customer"
165
166
  end
166
167
  end
@@ -168,6 +169,7 @@ describe Braintree::Customer do
168
169
  describe "initialize" do
169
170
  it "converts payment method hashes into payment method objects" do
170
171
  customer = Braintree::Customer._new(
172
+ :gateway,
171
173
  :credit_cards => [
172
174
  {:token => "pm1"},
173
175
  {:token => "pm2"}
@@ -3,29 +3,20 @@ require File.dirname(__FILE__) + "/../spec_helper"
3
3
  describe Braintree::Digest do
4
4
  describe "self.hexdigest" do
5
5
  it "returns the sha1 hmac of the input string (test case 6 from RFC 2202)" do
6
- begin
7
- original_key = Braintree::Configuration.private_key
8
- Braintree::Configuration.private_key = "\xaa" * 80
9
- data = "Test Using Larger Than Block-Size Key - Hash Key First"
10
- Braintree::Digest.hexdigest(data).should == "aa4ae5e15272d00e95705637ce8a3b55ed402112"
11
- ensure
12
- Braintree::Configuration.private_key = original_key
13
- end
6
+ original_key = Braintree::Configuration.private_key
7
+ private_key = "\xaa" * 80
8
+ data = "Test Using Larger Than Block-Size Key - Hash Key First"
9
+ Braintree::Digest.hexdigest(private_key, data).should == "aa4ae5e15272d00e95705637ce8a3b55ed402112"
14
10
  end
15
11
 
16
12
  it "returns the sha1 hmac of the input string (test case 7 from RFC 2202)" do
17
- begin
18
- original_key = Braintree::Configuration.private_key
19
- Braintree::Configuration.private_key = "\xaa" * 80
20
- data = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"
21
- Braintree::Digest.hexdigest(data).should == "e8e99d0f45237d786d6bbaa7965c7808bbff1a91"
22
- ensure
23
- Braintree::Configuration.private_key = original_key
24
- end
13
+ private_key = "\xaa" * 80
14
+ data = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"
15
+ Braintree::Digest.hexdigest(private_key, data).should == "e8e99d0f45237d786d6bbaa7965c7808bbff1a91"
25
16
  end
26
17
 
27
18
  it "doesn't blow up if message is nil" do
28
- expect { Braintree::Digest.hexdigest(nil) }.to_not raise_error
19
+ expect { Braintree::Digest.hexdigest("key", nil) }.to_not raise_error
29
20
  end
30
21
  end
31
22
  end
@@ -5,7 +5,13 @@ describe Braintree::ErrorResult do
5
5
  it "ignores data other than params, errors, and message" do
6
6
  # so that we can add more data into the response in the future without breaking the client lib
7
7
  expect do
8
- result = Braintree::ErrorResult.new(:params => "params", :errors => {:errors => []}, :extra => "is ignored", :message => "foo bar")
8
+ result = Braintree::ErrorResult.new(
9
+ :gateway,
10
+ :params => "params",
11
+ :errors => {:errors => []},
12
+ :extra => "is ignored",
13
+ :message => "foo bar"
14
+ )
9
15
  end.to_not raise_error
10
16
  end
11
17
  end
@@ -20,12 +26,13 @@ describe Braintree::ErrorResult do
20
26
  }
21
27
  }
22
28
  }
23
- result = Braintree::ErrorResult.new(:params => "params", :errors => errors)
29
+ result = Braintree::ErrorResult.new(:gateway, :params => "params", :errors => errors)
24
30
  result.inspect.should == "#<Braintree::ErrorResult params:{...} errors:<level1:[(code1) message], level1/level2:[(code2) message2]>>"
25
31
  end
26
32
 
27
33
  it "includes the credit_card_verification if there is one" do
28
34
  result = Braintree::ErrorResult.new(
35
+ :gateway,
29
36
  :params => "params",
30
37
  :errors => {},
31
38
  :verification => {},
@@ -36,6 +43,7 @@ describe Braintree::ErrorResult do
36
43
 
37
44
  it "does not include the credit_card_verification if there isn't one" do
38
45
  result = Braintree::ErrorResult.new(
46
+ :gateway,
39
47
  :params => "params",
40
48
  :errors => {},
41
49
  :verification => nil,
@@ -46,6 +54,7 @@ describe Braintree::ErrorResult do
46
54
 
47
55
  it "includes the transaction if there is one" do
48
56
  result = Braintree::ErrorResult.new(
57
+ :gateway,
49
58
  :params => "params",
50
59
  :errors => {},
51
60
  :verification => nil,
@@ -56,6 +65,7 @@ describe Braintree::ErrorResult do
56
65
 
57
66
  it "does not include the transaction if there isn't one" do
58
67
  result = Braintree::ErrorResult.new(
68
+ :gateway,
59
69
  :params => "params",
60
70
  :errors => {},
61
71
  :verification => nil,
@@ -15,7 +15,7 @@ END
15
15
  [Braintree] <last-name>Doe</last-name>
16
16
  [Braintree] </customer>
17
17
  END
18
- Braintree::Http._format_and_sanitize_body_for_log(input_xml).should == expected_xml
18
+ Braintree::Http.new(:config)._format_and_sanitize_body_for_log(input_xml).should == expected_xml
19
19
  end
20
20
 
21
21
  it "sanitizes credit card number and cvv" do
@@ -36,7 +36,7 @@ END
36
36
  [Braintree] <cvv>***</cvv>
37
37
  [Braintree] </customer>
38
38
  END
39
- Braintree::Http._format_and_sanitize_body_for_log(input_xml).should == expected_xml
39
+ Braintree::Http.new(:config)._format_and_sanitize_body_for_log(input_xml).should == expected_xml
40
40
  end
41
41
  end
42
42
  end
@@ -10,6 +10,7 @@ module Braintree
10
10
  search.status.in(
11
11
  Subscription::Status::Active,
12
12
  Subscription::Status::Canceled,
13
+ Subscription::Status::Expired,
13
14
  Subscription::Status::PastDue
14
15
  )
15
16
  end.should_not raise_error
@@ -31,5 +32,81 @@ module Braintree
31
32
  search.to_hash.should == {:days_past_due => {:is => "30"}}
32
33
  end
33
34
  end
35
+
36
+ context "merchant_account_id" do
37
+ it "builds a hash using the in operator" do
38
+ search = SubscriptionSearch.new
39
+ search.merchant_account_id.in "ma_id1", "ma_id2"
40
+
41
+ search.to_hash.should == {:merchant_account_id => ["ma_id1", "ma_id2"]}
42
+ end
43
+ end
44
+
45
+ context "plan_id" do
46
+ it "starts_with" do
47
+ search = SubscriptionSearch.new
48
+ search.plan_id.starts_with "plan_"
49
+
50
+ search.to_hash.should == {:plan_id => {:starts_with => "plan_"}}
51
+ end
52
+
53
+ it "ends_with" do
54
+ search = SubscriptionSearch.new
55
+ search.plan_id.ends_with "_id"
56
+
57
+ search.to_hash.should == {:plan_id => {:ends_with => "_id"}}
58
+ end
59
+
60
+ it "is" do
61
+ search = SubscriptionSearch.new
62
+ search.plan_id.is "p_id"
63
+
64
+ search.to_hash.should == {:plan_id => {:is => "p_id"}}
65
+ end
66
+
67
+ it "is_not" do
68
+ search = SubscriptionSearch.new
69
+ search.plan_id.is_not "p_id"
70
+
71
+ search.to_hash.should == {:plan_id => {:is_not => "p_id"}}
72
+ end
73
+
74
+ it "contains" do
75
+ search = SubscriptionSearch.new
76
+ search.plan_id.contains "p_id"
77
+
78
+ search.to_hash.should == {:plan_id => {:contains => "p_id"}}
79
+ end
80
+
81
+ it "in" do
82
+ search = SubscriptionSearch.new
83
+ search.plan_id.in ["plan1", "plan2"]
84
+
85
+ search.to_hash.should == {:plan_id => ["plan1", "plan2"]}
86
+ end
87
+ end
88
+
89
+ context "days_past_due" do
90
+ it "is a range node" do
91
+ search = SubscriptionSearch.new
92
+ search.days_past_due.should be_kind_of(Braintree::AdvancedSearch::RangeNode)
93
+ end
94
+ end
95
+
96
+ context "billing_cycles_remaining" do
97
+ it "is a range node" do
98
+ search = SubscriptionSearch.new
99
+ search.billing_cycles_remaining.should be_kind_of(Braintree::AdvancedSearch::RangeNode)
100
+ end
101
+ end
102
+
103
+ context "id" do
104
+ it "is" do
105
+ search = SubscriptionSearch.new
106
+ search.id.is "s_id"
107
+
108
+ search.to_hash.should == {:id => {:is => "s_id"}}
109
+ end
110
+ end
34
111
  end
35
112
  end
@@ -1,15 +1,23 @@
1
1
  require File.dirname(__FILE__) + "/../spec_helper"
2
2
 
3
3
  describe Braintree::Subscription do
4
+ def default_params
5
+ {
6
+ :add_ons => [],
7
+ :discounts => [],
8
+ :transactions => []
9
+ }
10
+ end
11
+
4
12
  context "price" do
5
13
  it "accepts price as either a String or a BigDecimal" do
6
- Braintree::Subscription._new(:price => "12.34", :transactions => []).price.should == BigDecimal.new("12.34")
7
- Braintree::Subscription._new(:price => BigDecimal.new("12.34"), :transactions => []).price.should == BigDecimal.new("12.34")
14
+ Braintree::Subscription._new(:gateway, default_params.merge(:price => "12.34")).price.should == BigDecimal.new("12.34")
15
+ Braintree::Subscription._new(:gateway, default_params.merge(:price => BigDecimal.new("12.34"))).price.should == BigDecimal.new("12.34")
8
16
  end
9
17
 
10
18
  it "blows up if price is not a string or BigDecimal" do
11
19
  expect {
12
- Braintree::Subscription._new(:price => 12.34, :transactions => [])
20
+ Braintree::Subscription._new(:gateway, default_params.merge(:price => 12.34))
13
21
  }.to raise_error(/Argument must be a String or BigDecimal/)
14
22
  end
15
23
  end
@@ -26,19 +34,19 @@ describe Braintree::Subscription do
26
34
 
27
35
  describe "==" do
28
36
  it "returns true for subscriptions with the same id" do
29
- subscription1 = Braintree::Subscription._new(:id => "123", :transactions => [])
30
- subscription2 = Braintree::Subscription._new(:id => "123", :transactions => [])
37
+ subscription1 = Braintree::Subscription._new(:gateway, default_params.merge(:id => "123"))
38
+ subscription2 = Braintree::Subscription._new(:gateway, default_params.merge(:id => "123"))
31
39
  subscription1.should == subscription2
32
40
  end
33
41
 
34
42
  it "returns false for subscriptions with different ids" do
35
- subscription1 = Braintree::Subscription._new(:id => "123", :transactions => [])
36
- subscription2 = Braintree::Subscription._new(:id => "not_123", :transactions => [])
43
+ subscription1 = Braintree::Subscription._new(:gateway, default_params.merge(:id => "123"))
44
+ subscription2 = Braintree::Subscription._new(:gateway, default_params.merge(:id => "not_123"))
37
45
  subscription1.should_not == subscription2
38
46
  end
39
47
 
40
48
  it "returns false if not comparing to a subscription" do
41
- subscription = Braintree::Subscription._new(:id => "123", :transactions => [])
49
+ subscription = Braintree::Subscription._new(:gateway, default_params.merge(:id => "123"))
42
50
  subscription.should_not == "not a subscription"
43
51
  end
44
52
  end
@@ -19,7 +19,7 @@ describe Braintree::Transaction do
19
19
 
20
20
  describe "self.create_transaction_url" do
21
21
  it "returns the url" do
22
- port = Braintree::Configuration.port
22
+ port = Braintree::Configuration.instantiate.port
23
23
  Braintree::Transaction.create_transaction_url.should == "http://localhost:#{port}/merchants/integration_merchant_id/transactions/all/create_via_transparent_redirect_request"
24
24
  end
25
25
  end
@@ -35,6 +35,7 @@ describe Braintree::Transaction do
35
35
  describe "initialize" do
36
36
  it "sets up customer attributes in customer_details" do
37
37
  transaction = Braintree::Transaction._new(
38
+ :gateway,
38
39
  :customer => {
39
40
  :id => "123",
40
41
  :first_name => "Adam",
@@ -58,6 +59,7 @@ describe Braintree::Transaction do
58
59
 
59
60
  it "sets up credit card attributes in credit_card_details" do
60
61
  transaction = Braintree::Transaction._new(
62
+ :gateway,
61
63
  :credit_card => {
62
64
  :token => "mzg2",
63
65
  :bin => "411111",
@@ -80,6 +82,7 @@ describe Braintree::Transaction do
80
82
  it "sets up history attributes in status_history" do
81
83
  time = Time.utc(2010,1,14)
82
84
  transaction = Braintree::Transaction._new(
85
+ :gateway,
83
86
  :status_history => [
84
87
  { :timestamp => time, :amount => "12.00", :transaction_source => "API",
85
88
  :user => "larry", :status => Braintree::Transaction::Status::Authorized },
@@ -97,18 +100,19 @@ describe Braintree::Transaction do
97
100
 
98
101
  it "handles receiving custom as an empty string" do
99
102
  transaction = Braintree::Transaction._new(
103
+ :gateway,
100
104
  :custom => "\n "
101
105
  )
102
106
  end
103
107
 
104
108
  it "accepts amount as either a String or a BigDecimal" do
105
- Braintree::Transaction._new(:amount => "12.34").amount.should == BigDecimal.new("12.34")
106
- Braintree::Transaction._new(:amount => BigDecimal.new("12.34")).amount.should == BigDecimal.new("12.34")
109
+ Braintree::Transaction._new(:gateway, :amount => "12.34").amount.should == BigDecimal.new("12.34")
110
+ Braintree::Transaction._new(:gateway, :amount => BigDecimal.new("12.34")).amount.should == BigDecimal.new("12.34")
107
111
  end
108
112
 
109
113
  it "blows up if amount is not a string or BigDecimal" do
110
114
  expect {
111
- Braintree::Transaction._new(:amount => 12.34)
115
+ Braintree::Transaction._new(:gateway, :amount => 12.34)
112
116
  }.to raise_error(/Argument must be a String or BigDecimal/)
113
117
  end
114
118
  end
@@ -116,6 +120,7 @@ describe Braintree::Transaction do
116
120
  describe "inspect" do
117
121
  it "includes the id, type, amount, and status first" do
118
122
  transaction = Braintree::Transaction._new(
123
+ :gateway,
119
124
  :id => "1234",
120
125
  :type => "sale",
121
126
  :amount => "100.00",
@@ -128,29 +133,29 @@ describe Braintree::Transaction do
128
133
 
129
134
  describe "==" do
130
135
  it "returns true for transactions with the same id" do
131
- first = Braintree::Transaction._new(:id => 123)
132
- second = Braintree::Transaction._new(:id => 123)
136
+ first = Braintree::Transaction._new(:gateway, :id => 123)
137
+ second = Braintree::Transaction._new(:gateway, :id => 123)
133
138
 
134
139
  first.should == second
135
140
  second.should == first
136
141
  end
137
142
 
138
143
  it "returns false for transactions with different ids" do
139
- first = Braintree::Transaction._new(:id => 123)
140
- second = Braintree::Transaction._new(:id => 124)
144
+ first = Braintree::Transaction._new(:gateway, :id => 123)
145
+ second = Braintree::Transaction._new(:gateway, :id => 124)
141
146
 
142
147
  first.should_not == second
143
148
  second.should_not == first
144
149
  end
145
150
 
146
151
  it "returns false when comparing to nil" do
147
- Braintree::Transaction._new({}).should_not == nil
152
+ Braintree::Transaction._new(:gateway, {}).should_not == nil
148
153
  end
149
154
 
150
155
  it "returns false when comparing to non-transactions" do
151
156
  same_id_different_object = Object.new
152
157
  def same_id_different_object.id; 123; end
153
- transaction = Braintree::Transaction._new(:id => 123)
158
+ transaction = Braintree::Transaction._new(:gateway, :id => 123)
154
159
  transaction.should_not == same_id_different_object
155
160
  end
156
161
  end
@@ -165,12 +170,12 @@ describe Braintree::Transaction do
165
170
 
166
171
  describe "refunded?" do
167
172
  it "is true if the transaciton has been refunded" do
168
- transaction = Braintree::Transaction._new(:refund_id => "123")
173
+ transaction = Braintree::Transaction._new(:gateway, :refund_id => "123")
169
174
  transaction.refunded?.should == true
170
175
  end
171
176
 
172
177
  it "is false if the transaciton has not been refunded" do
173
- transaction = Braintree::Transaction._new(:refund_id => nil)
178
+ transaction = Braintree::Transaction._new(:gateway, :refund_id => nil)
174
179
  transaction.refunded?.should == false
175
180
  end
176
181
  end
@@ -24,10 +24,10 @@ describe Braintree::TransparentRedirect do
24
24
  describe "self.parse_and_validate_query_string" do
25
25
  it "returns the parsed query string params if the hash is valid" do
26
26
  query_string_without_hash = "one=1&two=2&http_status=200"
27
- hash = Braintree::Digest.hexdigest(query_string_without_hash)
27
+ hash = Braintree::Digest.hexdigest(Braintree::Configuration.private_key, query_string_without_hash)
28
28
 
29
29
  query_string_with_hash = "#{query_string_without_hash}&hash=#{hash}"
30
- result = Braintree::TransparentRedirect.parse_and_validate_query_string query_string_with_hash
30
+ result = Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string query_string_with_hash
31
31
  result.should == {:one => "1", :two => "2", :http_status => "200", :hash => hash}
32
32
  end
33
33
 
@@ -37,49 +37,49 @@ describe Braintree::TransparentRedirect do
37
37
 
38
38
  query_string_with_hash = "#{query_string_without_hash}&hash=#{hash}"
39
39
  expect do
40
- Braintree::TransparentRedirect.parse_and_validate_query_string query_string_with_hash
40
+ Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string query_string_with_hash
41
41
  end.to raise_error(Braintree::ForgedQueryString)
42
42
  end
43
43
 
44
44
  it "raises Braintree::ForgedQueryString if hash is missing from the query string" do
45
45
  expect do
46
- Braintree::TransparentRedirect.parse_and_validate_query_string "http_status=200&query_string=without_a_hash"
46
+ Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string "http_status=200&query_string=without_a_hash"
47
47
  end.to raise_error(Braintree::ForgedQueryString)
48
48
  end
49
49
 
50
50
  it "raises an AuthenticationError if authentication fails" do
51
51
  expect do
52
- Braintree::TransparentRedirect.parse_and_validate_query_string add_hash_to_query_string("http_status=401")
52
+ Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string add_hash_to_query_string("http_status=401")
53
53
  end.to raise_error(Braintree::AuthenticationError)
54
54
  end
55
55
 
56
56
  it "raises an AuthorizationError if authorization fails" do
57
57
  expect do
58
- Braintree::TransparentRedirect.parse_and_validate_query_string add_hash_to_query_string("http_status=403")
58
+ Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string add_hash_to_query_string("http_status=403")
59
59
  end.to raise_error(Braintree::AuthorizationError)
60
60
  end
61
61
 
62
62
  it "raises an UnexpectedError if http_status is not in query string" do
63
63
  expect do
64
- Braintree::TransparentRedirect.parse_and_validate_query_string add_hash_to_query_string("no_http_status=x")
64
+ Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string add_hash_to_query_string("no_http_status=x")
65
65
  end.to raise_error(Braintree::UnexpectedError, "expected query string to have an http_status param")
66
66
  end
67
67
 
68
68
  it "raises a ServerError if the server 500's" do
69
69
  expect do
70
- Braintree::TransparentRedirect.parse_and_validate_query_string add_hash_to_query_string("http_status=500")
70
+ Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string add_hash_to_query_string("http_status=500")
71
71
  end.to raise_error(Braintree::ServerError)
72
72
  end
73
73
 
74
74
  it "raises a DownForMaintenanceError if the server is down for maintenance" do
75
75
  expect do
76
- Braintree::TransparentRedirect.parse_and_validate_query_string add_hash_to_query_string("http_status=503")
76
+ Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string add_hash_to_query_string("http_status=503")
77
77
  end.to raise_error(Braintree::DownForMaintenanceError)
78
78
  end
79
79
 
80
80
  it "raises an UnexpectedError if some other code is returned" do
81
81
  expect do
82
- Braintree::TransparentRedirect.parse_and_validate_query_string add_hash_to_query_string("http_status=600")
82
+ Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string add_hash_to_query_string("http_status=600")
83
83
  end.to raise_error(Braintree::UnexpectedError, "Unexpected HTTP_RESPONSE 600")
84
84
  end
85
85
  end
@@ -147,13 +147,13 @@ describe Braintree::TransparentRedirect do
147
147
  describe "self._data" do
148
148
  it "raises an exception if :redirect_url isn't given" do
149
149
  expect do
150
- Braintree::TransparentRedirect._data(:redirect_url => nil)
150
+ Braintree::TransparentRedirect.create_customer_data(:redirect_url => nil)
151
151
  end.to raise_error(ArgumentError, "expected params to contain :redirect_url")
152
152
  end
153
153
  end
154
154
 
155
155
  def add_hash_to_query_string(query_string_without_hash)
156
- hash = Braintree::TransparentRedirect._hash(query_string_without_hash)
156
+ hash = Braintree::Configuration.gateway.transparent_redirect._hash(query_string_without_hash)
157
157
  query_string_without_hash + "&hash=" + hash
158
158
  end
159
159
  end