braintree 2.4.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -0
- data/lib/braintree.rb +43 -32
- data/lib/braintree/add_on.rb +4 -0
- data/lib/braintree/address.rb +18 -72
- data/lib/braintree/address_gateway.rb +76 -0
- data/lib/braintree/advanced_search.rb +31 -13
- data/lib/braintree/base_module.rb +6 -0
- data/lib/braintree/configuration.rb +57 -39
- data/lib/braintree/credit_card.rb +75 -129
- data/lib/braintree/credit_card_gateway.rb +133 -0
- data/lib/braintree/credit_card_verification.rb +8 -0
- data/lib/braintree/customer.rb +70 -123
- data/lib/braintree/customer_gateway.rb +121 -0
- data/lib/braintree/digest.rb +2 -2
- data/lib/braintree/discount.rb +4 -0
- data/lib/braintree/error_codes.rb +50 -5
- data/lib/braintree/error_result.rb +4 -18
- data/lib/braintree/errors.rb +1 -2
- data/lib/braintree/exceptions.rb +11 -16
- data/lib/braintree/gateway.rb +39 -0
- data/lib/braintree/http.rb +30 -26
- data/lib/braintree/modification.rb +23 -0
- data/lib/braintree/resource_collection.rb +1 -1
- data/lib/braintree/subscription.rb +29 -129
- data/lib/braintree/subscription_gateway.rb +122 -0
- data/lib/braintree/subscription_search.rb +6 -7
- data/lib/braintree/successful_result.rb +1 -12
- data/lib/braintree/test/credit_card_numbers.rb +4 -2
- data/lib/braintree/test/transaction_amounts.rb +3 -0
- data/lib/braintree/transaction.rb +83 -243
- data/lib/braintree/transaction/credit_card_details.rb +4 -4
- data/lib/braintree/transaction_gateway.rb +124 -0
- data/lib/braintree/transaction_search.rb +5 -3
- data/lib/braintree/transparent_redirect.rb +19 -112
- data/lib/braintree/transparent_redirect_gateway.rb +105 -0
- data/lib/braintree/util.rb +4 -0
- data/lib/braintree/validation_error.rb +1 -0
- data/lib/braintree/validation_error_collection.rb +5 -23
- data/lib/braintree/version.rb +2 -2
- data/lib/braintree/xml/parser.rb +1 -1
- data/lib/braintree/xml/rexml.rb +2 -2
- data/spec/integration/braintree/advanced_search_spec.rb +532 -0
- data/spec/integration/braintree/credit_card_spec.rb +5 -8
- data/spec/integration/braintree/http_spec.rb +53 -39
- data/spec/integration/braintree/subscription_spec.rb +678 -213
- data/spec/integration/braintree/transaction_search_spec.rb +318 -43
- data/spec/integration/braintree/transaction_spec.rb +134 -3
- data/spec/integration/braintree/transparent_redirect_spec.rb +1 -1
- data/spec/spec_helper.rb +55 -4
- data/spec/unit/braintree/address_spec.rb +8 -8
- data/spec/unit/braintree/base_module_spec.rb +1 -1
- data/spec/unit/braintree/configuration_spec.rb +34 -29
- data/spec/unit/braintree/credit_card_spec.rb +14 -12
- data/spec/unit/braintree/credit_card_verification_spec.rb +16 -0
- data/spec/unit/braintree/customer_spec.rb +10 -8
- data/spec/unit/braintree/digest_spec.rb +8 -17
- data/spec/unit/braintree/error_result_spec.rb +12 -2
- data/spec/unit/braintree/http_spec.rb +2 -2
- data/spec/unit/braintree/subscription_search_spec.rb +77 -0
- data/spec/unit/braintree/subscription_spec.rb +16 -8
- data/spec/unit/braintree/transaction_spec.rb +17 -12
- data/spec/unit/braintree/transparent_redirect_spec.rb +12 -12
- data/spec/unit/braintree/util_spec.rb +24 -0
- data/spec/unit/braintree/xml/parser_spec.rb +1 -1
- data/spec/unit/braintree_spec.rb +1 -1
- metadata +16 -5
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + "/../spec_helper"
|
|
3
3
|
describe Braintree::TransparentRedirect do
|
4
4
|
it "raises a DownForMaintenanceError when app is in maintenance mode on TR requests" do
|
5
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.base_merchant_url + "/test/maintenance")
|
6
|
+
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Configuration.instantiate.base_merchant_url + "/test/maintenance")
|
7
7
|
expect do
|
8
8
|
Braintree::Customer.create_from_transparent_redirect(query_string_response)
|
9
9
|
end.to raise_error(Braintree::DownForMaintenanceError)
|
data/spec/spec_helper.rb
CHANGED
@@ -14,8 +14,9 @@ unless defined?(SPEC_HELPER_LOADED)
|
|
14
14
|
Braintree::Configuration.merchant_id = "integration_merchant_id"
|
15
15
|
Braintree::Configuration.public_key = "integration_public_key"
|
16
16
|
Braintree::Configuration.private_key = "integration_private_key"
|
17
|
-
|
18
|
-
|
17
|
+
logger = Logger.new("/dev/null")
|
18
|
+
logger.level = Logger::INFO
|
19
|
+
Braintree::Configuration.logger = logger
|
19
20
|
|
20
21
|
module Kernel
|
21
22
|
alias_method :original_warn, :warn
|
@@ -30,6 +31,56 @@ unless defined?(SPEC_HELPER_LOADED)
|
|
30
31
|
DefaultMerchantAccountId = "sandbox_credit_card"
|
31
32
|
NonDefaultMerchantAccountId = "sandbox_credit_card_non_default"
|
32
33
|
|
34
|
+
TrialPlan = {
|
35
|
+
:description => "Plan for integration tests -- with trial",
|
36
|
+
:id => "integration_trial_plan",
|
37
|
+
:price => BigDecimal.new("43.21"),
|
38
|
+
:trial_period => true,
|
39
|
+
:trial_duration => 2,
|
40
|
+
:trial_duration_unit => Braintree::Subscription::TrialDurationUnit::Day
|
41
|
+
}
|
42
|
+
|
43
|
+
TriallessPlan = {
|
44
|
+
:description => "Plan for integration tests -- without a trial",
|
45
|
+
:id => "integration_trialless_plan",
|
46
|
+
:price => BigDecimal.new("12.34"),
|
47
|
+
:trial_period => false
|
48
|
+
}
|
49
|
+
|
50
|
+
AddOnDiscountPlan = {
|
51
|
+
:description => "Plan for integration tests -- with add-ons and discounts",
|
52
|
+
:id => "integration_plan_with_add_ons_and_discounts",
|
53
|
+
:price => BigDecimal.new("9.99"),
|
54
|
+
:trial_period => true,
|
55
|
+
:trial_duration => 2,
|
56
|
+
:trial_duration_unit => Braintree::Subscription::TrialDurationUnit::Day
|
57
|
+
}
|
58
|
+
|
59
|
+
BillingDayOfMonthPlan = {
|
60
|
+
:description => "Plan for integration tests -- with billing day of month",
|
61
|
+
:id => "integration_plan_with_billing_day_of_month",
|
62
|
+
:price => BigDecimal.new("8.88"),
|
63
|
+
:billing_day_of_month => 5
|
64
|
+
}
|
65
|
+
|
66
|
+
AddOnIncrease10 = "increase_10"
|
67
|
+
AddOnIncrease20 = "increase_20"
|
68
|
+
AddOnIncrease30 = "increase_30"
|
69
|
+
|
70
|
+
Discount7 = "discount_7"
|
71
|
+
Discount11 = "discount_11"
|
72
|
+
Discount15 = "discount_15"
|
73
|
+
|
74
|
+
def self.make_past_due(subscription, number_of_days_past_due = 1)
|
75
|
+
Braintree::Configuration.instantiate.http.put(
|
76
|
+
"/subscriptions/#{subscription.id}/make_past_due?days_past_due=#{number_of_days_past_due}"
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.settle_transaction(transaction_id)
|
81
|
+
Braintree::Configuration.instantiate.http.put("/transactions/#{transaction_id}/settle")
|
82
|
+
end
|
83
|
+
|
33
84
|
def self.stub_time_dot_now(desired_time)
|
34
85
|
Time.class_eval do
|
35
86
|
class << self
|
@@ -48,9 +99,9 @@ unless defined?(SPEC_HELPER_LOADED)
|
|
48
99
|
end
|
49
100
|
end
|
50
101
|
|
51
|
-
def self.simulate_form_post_for_tr(tr_data_string, form_data_hash, url=Braintree::TransparentRedirect.url)
|
102
|
+
def self.simulate_form_post_for_tr(tr_data_string, form_data_hash, url = Braintree::TransparentRedirect.url)
|
52
103
|
response = nil
|
53
|
-
Net::HTTP.start("localhost", Braintree::Configuration.port) do |http|
|
104
|
+
Net::HTTP.start("localhost", Braintree::Configuration.instantiate.port) do |http|
|
54
105
|
request = Net::HTTP::Post.new("/" + url.split("/", 4)[3])
|
55
106
|
request.add_field "Content-Type", "application/x-www-form-urlencoded"
|
56
107
|
request.body = Braintree::Util.hash_to_query_string({:tr_data => tr_data_string}.merge(form_data_hash))
|
@@ -3,31 +3,31 @@ require File.dirname(__FILE__) + "/../spec_helper"
|
|
3
3
|
describe Braintree::Address do
|
4
4
|
describe "==" do
|
5
5
|
it "returns true if given an address with the same id and customer_id" do
|
6
|
-
first = Braintree::Address._new(:customer_id => "c1", :id => 'a1')
|
7
|
-
second = Braintree::Address._new(:customer_id => "c1", :id => "a1")
|
6
|
+
first = Braintree::Address._new(:gateway, :customer_id => "c1", :id => 'a1')
|
7
|
+
second = Braintree::Address._new(:gateway, :customer_id => "c1", :id => "a1")
|
8
8
|
|
9
9
|
first.should == second
|
10
10
|
second.should == first
|
11
11
|
end
|
12
12
|
|
13
13
|
it "returns false if given an address with a different id and the same customer_id" do
|
14
|
-
first = Braintree::Address._new(:customer_id => "c1", :id => "a1")
|
15
|
-
second = Braintree::Address._new(:customer_id => "c1", :id => "not a1")
|
14
|
+
first = Braintree::Address._new(:gateway, :customer_id => "c1", :id => "a1")
|
15
|
+
second = Braintree::Address._new(:gateway, :customer_id => "c1", :id => "not a1")
|
16
16
|
|
17
17
|
first.should_not == second
|
18
18
|
second.should_not == first
|
19
19
|
end
|
20
20
|
|
21
21
|
it "returns false if given an address with a different customer_id and the same id" do
|
22
|
-
first = Braintree::Address._new(:customer_id => "c1", :id => "a1")
|
23
|
-
second = Braintree::Address._new(:customer_id => "not c1", :id => "a1")
|
22
|
+
first = Braintree::Address._new(:gateway, :customer_id => "c1", :id => "a1")
|
23
|
+
second = Braintree::Address._new(:gateway, :customer_id => "not c1", :id => "a1")
|
24
24
|
|
25
25
|
first.should_not == second
|
26
26
|
second.should_not == first
|
27
27
|
end
|
28
28
|
|
29
29
|
it "returns false when not given an address" do
|
30
|
-
address = Braintree::Address._new(:id => "a1")
|
30
|
+
address = Braintree::Address._new(:gateway, :id => "a1")
|
31
31
|
address.should_not == "not an address"
|
32
32
|
end
|
33
33
|
end
|
@@ -79,7 +79,7 @@ describe Braintree::Address do
|
|
79
79
|
describe "update" do
|
80
80
|
it "raises an exception if hash includes an invalid key" do
|
81
81
|
expect do
|
82
|
-
Braintree::Address._new({}).update(:street_address => "456 E Main", :invalid_key2 => "foo")
|
82
|
+
Braintree::Address._new(Braintree::Configuration.gateway, {}).update(:street_address => "456 E Main", :invalid_key2 => "foo")
|
83
83
|
end.to raise_error(ArgumentError, "invalid keys: invalid_key2")
|
84
84
|
end
|
85
85
|
end
|
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + "/../spec_helper"
|
|
3
3
|
describe Braintree::BaseModule do
|
4
4
|
describe "return_object_or_raise" do
|
5
5
|
it "inspects the error_result when inspecting the exception" do
|
6
|
-
result = Braintree::ErrorResult.new(:errors => {})
|
6
|
+
result = Braintree::ErrorResult.new(:gateway, :errors => {})
|
7
7
|
begin
|
8
8
|
klass = Class.new { include Braintree::BaseModule }
|
9
9
|
klass.return_object_or_raise(:obj) { result }
|
@@ -16,48 +16,48 @@ describe Braintree::Configuration do
|
|
16
16
|
Braintree::Configuration.environment = @original_environment
|
17
17
|
end
|
18
18
|
|
19
|
-
describe "
|
19
|
+
describe "base_merchant_path" do
|
20
20
|
it "returns /merchants/{merchant_id}" do
|
21
|
-
Braintree::Configuration.base_merchant_path.should == "/merchants/integration_merchant_id"
|
21
|
+
Braintree::Configuration.instantiate.base_merchant_path.should == "/merchants/integration_merchant_id"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
describe "
|
25
|
+
describe "base_merchant_url" do
|
26
26
|
it "returns the expected url for the development env" do
|
27
27
|
Braintree::Configuration.environment = :development
|
28
|
-
port = Braintree::Configuration.port
|
29
|
-
Braintree::Configuration.base_merchant_url.should == "http://localhost:#{port}/merchants/integration_merchant_id"
|
28
|
+
port = Braintree::Configuration.instantiate.port
|
29
|
+
Braintree::Configuration.instantiate.base_merchant_url.should == "http://localhost:#{port}/merchants/integration_merchant_id"
|
30
30
|
end
|
31
31
|
|
32
32
|
it "returns the expected url for the sandbox env" do
|
33
33
|
Braintree::Configuration.environment = :sandbox
|
34
|
-
Braintree::Configuration.base_merchant_url.should == "https://sandbox.braintreegateway.com:443/merchants/integration_merchant_id"
|
34
|
+
Braintree::Configuration.instantiate.base_merchant_url.should == "https://sandbox.braintreegateway.com:443/merchants/integration_merchant_id"
|
35
35
|
end
|
36
36
|
|
37
37
|
it "returns the expected url for the production env" do
|
38
38
|
Braintree::Configuration.environment = :production
|
39
|
-
Braintree::Configuration.base_merchant_url.should == "https://www.braintreegateway.com:443/merchants/integration_merchant_id"
|
39
|
+
Braintree::Configuration.instantiate.base_merchant_url.should == "https://www.braintreegateway.com:443/merchants/integration_merchant_id"
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
describe "
|
43
|
+
describe "ca_file" do
|
44
44
|
it "qa" do
|
45
45
|
Braintree::Configuration.environment = :qa
|
46
|
-
ca_file = Braintree::Configuration.ca_file
|
46
|
+
ca_file = Braintree::Configuration.instantiate.ca_file
|
47
47
|
ca_file.should match(/sandbox_braintreegateway_com.ca.crt$/)
|
48
48
|
File.exists?(ca_file).should == true
|
49
49
|
end
|
50
50
|
|
51
51
|
it "sandbox" do
|
52
52
|
Braintree::Configuration.environment = :sandbox
|
53
|
-
ca_file = Braintree::Configuration.ca_file
|
53
|
+
ca_file = Braintree::Configuration.instantiate.ca_file
|
54
54
|
ca_file.should match(/sandbox_braintreegateway_com.ca.crt$/)
|
55
55
|
File.exists?(ca_file).should == true
|
56
56
|
end
|
57
57
|
|
58
58
|
it "production" do
|
59
59
|
Braintree::Configuration.environment = :production
|
60
|
-
ca_file = Braintree::Configuration.ca_file
|
60
|
+
ca_file = Braintree::Configuration.instantiate.ca_file
|
61
61
|
ca_file.should match(/www_braintreegateway_com.ca.crt$/)
|
62
62
|
File.exists?(ca_file).should == true
|
63
63
|
end
|
@@ -85,11 +85,16 @@ describe Braintree::Configuration do
|
|
85
85
|
begin
|
86
86
|
old_logger = Braintree::Configuration.logger
|
87
87
|
Braintree::Configuration.logger = nil
|
88
|
-
Braintree::Configuration.logger.level.should == Logger::INFO
|
88
|
+
Braintree::Configuration.instantiate.logger.level.should == Logger::INFO
|
89
89
|
ensure
|
90
90
|
Braintree::Configuration.logger = old_logger
|
91
91
|
end
|
92
92
|
end
|
93
|
+
|
94
|
+
it "lazily initializes so that you can do Braintree::Configuration.logger.level = when configuring the client lib" do
|
95
|
+
Braintree::Configuration.logger = nil
|
96
|
+
Braintree::Configuration.logger.should_not == nil
|
97
|
+
end
|
93
98
|
end
|
94
99
|
|
95
100
|
describe "self.merchant_id" do
|
@@ -122,12 +127,12 @@ describe Braintree::Configuration do
|
|
122
127
|
describe "self.port" do
|
123
128
|
it "is 443 for production" do
|
124
129
|
Braintree::Configuration.environment = :production
|
125
|
-
Braintree::Configuration.port.should == 443
|
130
|
+
Braintree::Configuration.instantiate.port.should == 443
|
126
131
|
end
|
127
132
|
|
128
133
|
it "is 443 for sandbox" do
|
129
134
|
Braintree::Configuration.environment = :sandbox
|
130
|
-
Braintree::Configuration.port.should == 443
|
135
|
+
Braintree::Configuration.instantiate.port.should == 443
|
131
136
|
end
|
132
137
|
|
133
138
|
it "is 3000 or GATEWAY_PORT environment variable for development" do
|
@@ -135,10 +140,10 @@ describe Braintree::Configuration do
|
|
135
140
|
old_gateway_port = ENV['GATEWAY_PORT']
|
136
141
|
begin
|
137
142
|
ENV['GATEWAY_PORT'] = nil
|
138
|
-
Braintree::Configuration.port.should == 3000
|
143
|
+
Braintree::Configuration.instantiate.port.should == 3000
|
139
144
|
|
140
145
|
ENV['GATEWAY_PORT'] = '1234'
|
141
|
-
Braintree::Configuration.port.should == '1234'
|
146
|
+
Braintree::Configuration.instantiate.port.should == '1234'
|
142
147
|
ensure
|
143
148
|
ENV['GATEWAY_PORT'] = old_gateway_port
|
144
149
|
end
|
@@ -148,17 +153,17 @@ describe Braintree::Configuration do
|
|
148
153
|
describe "self.protocol" do
|
149
154
|
it "is http for development" do
|
150
155
|
Braintree::Configuration.environment = :development
|
151
|
-
Braintree::Configuration.protocol.should == "http"
|
156
|
+
Braintree::Configuration.instantiate.protocol.should == "http"
|
152
157
|
end
|
153
158
|
|
154
159
|
it "is https for production" do
|
155
160
|
Braintree::Configuration.environment = :production
|
156
|
-
Braintree::Configuration.protocol.should == "https"
|
161
|
+
Braintree::Configuration.instantiate.protocol.should == "https"
|
157
162
|
end
|
158
163
|
|
159
164
|
it "is https for sandbox" do
|
160
165
|
Braintree::Configuration.environment = :sandbox
|
161
|
-
Braintree::Configuration.protocol.should == "https"
|
166
|
+
Braintree::Configuration.instantiate.protocol.should == "https"
|
162
167
|
end
|
163
168
|
|
164
169
|
end
|
@@ -166,50 +171,50 @@ describe Braintree::Configuration do
|
|
166
171
|
describe "self.server" do
|
167
172
|
it "is localhost for development" do
|
168
173
|
Braintree::Configuration.environment = :development
|
169
|
-
Braintree::Configuration.server.should == "localhost"
|
174
|
+
Braintree::Configuration.instantiate.server.should == "localhost"
|
170
175
|
end
|
171
176
|
|
172
177
|
it "is www.braintreegateway.com for production" do
|
173
178
|
Braintree::Configuration.environment = :production
|
174
|
-
Braintree::Configuration.server.should == "www.braintreegateway.com"
|
179
|
+
Braintree::Configuration.instantiate.server.should == "www.braintreegateway.com"
|
175
180
|
end
|
176
181
|
|
177
182
|
it "is sandbox.braintreegateway.com for sandbox" do
|
178
183
|
Braintree::Configuration.environment = :sandbox
|
179
|
-
Braintree::Configuration.server.should == "sandbox.braintreegateway.com"
|
184
|
+
Braintree::Configuration.instantiate.server.should == "sandbox.braintreegateway.com"
|
180
185
|
end
|
181
186
|
end
|
182
187
|
|
183
|
-
describe "
|
188
|
+
describe "ssl?" do
|
184
189
|
it "returns false for development" do
|
185
190
|
Braintree::Configuration.environment = :development
|
186
|
-
Braintree::Configuration.ssl?.should == false
|
191
|
+
Braintree::Configuration.instantiate.ssl?.should == false
|
187
192
|
end
|
188
193
|
|
189
194
|
it "returns true for production" do
|
190
195
|
Braintree::Configuration.environment = :production
|
191
|
-
Braintree::Configuration.ssl?.should == true
|
196
|
+
Braintree::Configuration.instantiate.ssl?.should == true
|
192
197
|
end
|
193
198
|
|
194
199
|
it "returns true for sandbox" do
|
195
200
|
Braintree::Configuration.environment = :sandbox
|
196
|
-
Braintree::Configuration.ssl?.should == true
|
201
|
+
Braintree::Configuration.instantiate.ssl?.should == true
|
197
202
|
end
|
198
203
|
end
|
199
204
|
|
200
|
-
describe "
|
205
|
+
describe "user_agent" do
|
201
206
|
after :each do
|
202
207
|
Braintree::Configuration.custom_user_agent = nil
|
203
208
|
end
|
204
209
|
|
205
210
|
it "appends the default user_agent with the given value" do
|
206
211
|
Braintree::Configuration.custom_user_agent = "ActiveMerchant 1.2.3"
|
207
|
-
Braintree::Configuration.user_agent.should == "Braintree Ruby Gem #{Braintree::Version::String} (ActiveMerchant 1.2.3)"
|
212
|
+
Braintree::Configuration.instantiate.user_agent.should == "Braintree Ruby Gem #{Braintree::Version::String} (ActiveMerchant 1.2.3)"
|
208
213
|
end
|
209
214
|
|
210
215
|
it "does not append anything if there is no custom_user_agent" do
|
211
216
|
Braintree::Configuration.custom_user_agent = nil
|
212
|
-
Braintree::Configuration.user_agent.should == "Braintree Ruby Gem #{Braintree::Version::String}"
|
217
|
+
Braintree::Configuration.instantiate.user_agent.should == "Braintree Ruby Gem #{Braintree::Version::String}"
|
213
218
|
end
|
214
219
|
end
|
215
220
|
end
|
@@ -11,7 +11,7 @@ describe Braintree::CreditCard do
|
|
11
11
|
|
12
12
|
describe "self.create_signature" do
|
13
13
|
it "should be what we expect" do
|
14
|
-
Braintree::
|
14
|
+
Braintree::CreditCardGateway._create_signature.should == [
|
15
15
|
:cardholder_name,
|
16
16
|
:cvv,
|
17
17
|
:expiration_date,
|
@@ -41,7 +41,7 @@ describe Braintree::CreditCard do
|
|
41
41
|
|
42
42
|
describe "self.update_signature" do
|
43
43
|
it "should be what we expect" do
|
44
|
-
Braintree::
|
44
|
+
Braintree::CreditCardGateway._update_signature.should == [
|
45
45
|
:cardholder_name,
|
46
46
|
:cvv,
|
47
47
|
:expiration_date,
|
@@ -79,52 +79,53 @@ describe Braintree::CreditCard do
|
|
79
79
|
|
80
80
|
describe "self.create_credit_card_url" do
|
81
81
|
it "returns the url" do
|
82
|
-
port = Braintree::Configuration.port
|
82
|
+
port = Braintree::Configuration.instantiate.port
|
83
83
|
Braintree::CreditCard.create_credit_card_url.should == "http://localhost:#{port}/merchants/integration_merchant_id/payment_methods/all/create_via_transparent_redirect_request"
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
87
|
describe "==" do
|
88
88
|
it "returns true if given a credit card with the same token" do
|
89
|
-
first = Braintree::CreditCard._new(:token => 123)
|
90
|
-
second = Braintree::CreditCard._new(:token => 123)
|
89
|
+
first = Braintree::CreditCard._new(:gateway, :token => 123)
|
90
|
+
second = Braintree::CreditCard._new(:gateway, :token => 123)
|
91
91
|
|
92
92
|
first.should == second
|
93
93
|
second.should == first
|
94
94
|
end
|
95
95
|
|
96
96
|
it "returns false if given a credit card with a different token" do
|
97
|
-
first = Braintree::CreditCard._new(:token => 123)
|
98
|
-
second = Braintree::CreditCard._new(:token => 124)
|
97
|
+
first = Braintree::CreditCard._new(:gateway, :token => 123)
|
98
|
+
second = Braintree::CreditCard._new(:gateway, :token => 124)
|
99
99
|
|
100
100
|
first.should_not == second
|
101
101
|
second.should_not == first
|
102
102
|
end
|
103
103
|
|
104
104
|
it "returns false if not given a credit card" do
|
105
|
-
credit_card = Braintree::CreditCard._new(:token => 123)
|
105
|
+
credit_card = Braintree::CreditCard._new(:gateway, :token => 123)
|
106
106
|
credit_card.should_not == "not a credit card"
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
110
|
describe "default?" do
|
111
111
|
it "is true if the credit card is the default credit card for the customer" do
|
112
|
-
Braintree::CreditCard._new(:default => true).default?.should == true
|
112
|
+
Braintree::CreditCard._new(:gateway, :default => true).default?.should == true
|
113
113
|
end
|
114
114
|
|
115
115
|
it "is false if the credit card is not the default credit card for the customer" do
|
116
|
-
Braintree::CreditCard._new(:default => false).default?.should == false
|
116
|
+
Braintree::CreditCard._new(:gateway, :default => false).default?.should == false
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
describe "inspect" do
|
121
121
|
it "includes the token first" do
|
122
|
-
output = Braintree::CreditCard._new(:token => "cc123").inspect
|
122
|
+
output = Braintree::CreditCard._new(:gateway, :token => "cc123").inspect
|
123
123
|
output.should include("#<Braintree::CreditCard token: \"cc123\",")
|
124
124
|
end
|
125
125
|
|
126
126
|
it "includes all customer attributes" do
|
127
127
|
credit_card = Braintree::CreditCard._new(
|
128
|
+
:gateway,
|
128
129
|
:bin => "411111",
|
129
130
|
:card_type => "Visa",
|
130
131
|
:cardholder_name => "John Miller",
|
@@ -154,6 +155,7 @@ describe Braintree::CreditCard do
|
|
154
155
|
describe "masked_number" do
|
155
156
|
it "uses the bin and last_4 to build the masked number" do
|
156
157
|
credit_card = Braintree::CreditCard._new(
|
158
|
+
:gateway,
|
157
159
|
:bin => "510510",
|
158
160
|
:last_4 => "5100"
|
159
161
|
)
|
@@ -164,7 +166,7 @@ describe Braintree::CreditCard do
|
|
164
166
|
describe "self.update" do
|
165
167
|
it "raises an exception if attributes contain an invalid key" do
|
166
168
|
expect do
|
167
|
-
Braintree::CreditCard._new({}).update(:invalid_key => 'val')
|
169
|
+
Braintree::CreditCard._new(Braintree::Configuration.gateway, {}).update(:invalid_key => 'val')
|
168
170
|
end.to raise_error(ArgumentError, "invalid keys: invalid_key")
|
169
171
|
end
|
170
172
|
end
|
@@ -13,8 +13,24 @@ describe Braintree::CreditCardVerification do
|
|
13
13
|
:processor_response_text => "Do Not Honor",
|
14
14
|
:merchant_account_id => "some_id"
|
15
15
|
)
|
16
|
+
|
16
17
|
verification.inspect.should == %(#<Braintree::CreditCardVerification status: "verified", processor_response_code: "2000", processor_response_text: "Do Not Honor", cvv_response_code: "I", avs_error_response_code: "I", avs_postal_code_response_code: "I", avs_street_address_response_code: "I", merchant_account_id: "some_id", gateway_rejection_reason: nil>)
|
17
18
|
end
|
19
|
+
|
20
|
+
it "has a status" do
|
21
|
+
verification = Braintree::CreditCardVerification._new(
|
22
|
+
:status => "verified",
|
23
|
+
:avs_error_response_code => "I",
|
24
|
+
:avs_postal_code_response_code => "I",
|
25
|
+
:avs_street_address_response_code => "I",
|
26
|
+
:cvv_response_code => "I",
|
27
|
+
:processor_response_code => "2000",
|
28
|
+
:processor_response_text => "Do Not Honor",
|
29
|
+
:merchant_account_id => "some_id"
|
30
|
+
)
|
31
|
+
|
32
|
+
verification.status.should == Braintree::CreditCardVerification::Status::VERIFIED
|
33
|
+
end
|
18
34
|
end
|
19
35
|
end
|
20
36
|
|