braintree 2.13.0 → 2.13.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.
@@ -2,9 +2,10 @@ module Braintree
2
2
  # See http://www.braintreepayments.com/docs/ruby
3
3
  class Configuration
4
4
  API_VERSION = "2" # :nodoc:
5
+ DEFAULT_ENDPOINT = "www" # :nodoc:
5
6
 
6
7
  class << self
7
- attr_writer :custom_user_agent, :logger, :merchant_id, :public_key, :private_key
8
+ attr_writer :custom_user_agent, :endpoint, :logger, :merchant_id, :public_key, :private_key
8
9
  end
9
10
  attr_reader :merchant_id, :public_key, :private_key
10
11
 
@@ -34,6 +35,7 @@ module Braintree
34
35
  def self.instantiate # :nodoc:
35
36
  config = new(
36
37
  :custom_user_agent => @custom_user_agent,
38
+ :endpoint => @endpoint,
37
39
  :environment => environment,
38
40
  :logger => logger,
39
41
  :merchant_id => merchant_id,
@@ -47,7 +49,7 @@ module Braintree
47
49
  end
48
50
 
49
51
  def initialize(options = {})
50
- [:environment, :merchant_id, :public_key, :private_key, :custom_user_agent, :logger].each do |attr|
52
+ [:endpoint, :environment, :merchant_id, :public_key, :private_key, :custom_user_agent, :logger].each do |attr|
51
53
  instance_variable_set "@#{attr}", options[attr]
52
54
  end
53
55
  end
@@ -73,6 +75,10 @@ module Braintree
73
75
  end
74
76
  end
75
77
 
78
+ def endpoint
79
+ @endpoint || DEFAULT_ENDPOINT
80
+ end
81
+
76
82
  def http # :nodoc:
77
83
  Http.new(self)
78
84
  end
@@ -99,7 +105,7 @@ module Braintree
99
105
  when :development
100
106
  "localhost"
101
107
  when :production
102
- "www.braintreegateway.com"
108
+ "#{endpoint}.braintreegateway.com"
103
109
  when :qa
104
110
  "qa.braintreegateway.com"
105
111
  when :sandbox
@@ -108,6 +108,7 @@ module Braintree
108
108
  set_instance_variables_from_hash(attributes)
109
109
  @credit_cards = (@credit_cards || []).map { |pm| CreditCard._new gateway, pm }
110
110
  @addresses = (@addresses || []).map { |addr| Address._new gateway, addr }
111
+ @custom_fields = attributes[:custom_fields].is_a?(Hash) ? attributes[:custom_fields] : {}
111
112
  end
112
113
 
113
114
  # See http://www.braintreepayments.com/docs/ruby/transactions/create_from_vault
@@ -172,6 +172,7 @@ module Braintree
172
172
  @status_history = attributes[:status_history] ? attributes[:status_history].map { |s| StatusDetails.new(s) } : []
173
173
  @tax_amount = Util.to_big_decimal(tax_amount)
174
174
  @descriptor = Descriptor.new(@descriptor)
175
+ @custom_fields = attributes[:custom_fields].is_a?(Hash) ? attributes[:custom_fields] : {}
175
176
  add_ons.map! { |attrs| AddOn._new(attrs) } if add_ons
176
177
  discounts.map! { |attrs| Discount._new(attrs) } if discounts
177
178
  end
@@ -2,7 +2,7 @@ module Braintree
2
2
  module Version
3
3
  Major = 2
4
4
  Minor = 13
5
- Tiny = 0
5
+ Tiny = 1
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Tiny}"
8
8
  end
@@ -211,6 +211,16 @@ describe Braintree::Customer do
211
211
  result.customer.custom_fields[:store_me].should == "custom value"
212
212
  end
213
213
 
214
+ it "returns empty hash for custom fields when blank" do
215
+ result = Braintree::Customer.create(
216
+ :first_name => "Bill",
217
+ :last_name => "Gates",
218
+ :custom_fields => { :store_me => "" }
219
+ )
220
+ result.success?.should == true
221
+ result.customer.custom_fields.should == {}
222
+ end
223
+
214
224
  it "returns nested errors if credit card and/or billing address are invalid" do
215
225
  result = Braintree::Customer.create(
216
226
  :email => "invalid",
@@ -396,6 +396,23 @@ describe Braintree::Transaction do
396
396
  result.transaction.custom_fields.should == {:store_me => "custom value"}
397
397
  end
398
398
 
399
+ it "returns nil if a custom field is not defined" do
400
+ create_result = Braintree::Transaction.sale(
401
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
402
+ :credit_card => {
403
+ :number => Braintree::Test::CreditCardNumbers::Visa,
404
+ :expiration_date => "12/2012"
405
+ },
406
+ :custom_fields => {
407
+ :store_me => ""
408
+ }
409
+ )
410
+
411
+ result = Braintree::Transaction.find(create_result.transaction.id)
412
+
413
+ result.custom_fields.should == {}
414
+ end
415
+
399
416
  it "returns an error if custom_field is not registered" do
400
417
  result = Braintree::Transaction.create(
401
418
  :type => "sale",
@@ -11,9 +11,10 @@ describe Braintree::Configuration do
11
11
 
12
12
  after do
13
13
  Braintree::Configuration.merchant_id = @original_merchant_id
14
- Braintree::Configuration.public_key = @original_public_key
14
+ Braintree::Configuration.public_key = @original_public_key
15
15
  Braintree::Configuration.private_key = @original_private_key
16
16
  Braintree::Configuration.environment = @original_environment
17
+ Braintree::Configuration.endpoint = Braintree::Configuration::DEFAULT_ENDPOINT
17
18
  end
18
19
 
19
20
  describe "base_merchant_path" do
@@ -180,7 +181,7 @@ describe Braintree::Configuration do
180
181
 
181
182
  end
182
183
 
183
- describe "self.server" do
184
+ describe "server" do
184
185
  it "is localhost for development" do
185
186
  Braintree::Configuration.environment = :development
186
187
  Braintree::Configuration.instantiate.server.should == "localhost"
@@ -200,6 +201,12 @@ describe Braintree::Configuration do
200
201
  Braintree::Configuration.environment = :qa
201
202
  Braintree::Configuration.instantiate.server.should == "qa.braintreegateway.com"
202
203
  end
204
+
205
+ it "can by changed by configuring the production endpoint" do
206
+ Braintree::Configuration.environment = :production
207
+ Braintree::Configuration.endpoint = "custom-endpoint"
208
+ Braintree::Configuration.instantiate.server.should == "custom-endpoint.braintreegateway.com"
209
+ end
203
210
  end
204
211
 
205
212
  describe "ssl?" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: braintree
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
5
- prerelease: false
4
+ hash: 57
5
+ prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 13
9
- - 0
10
- version: 2.13.0
9
+ - 1
10
+ version: 2.13.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Braintree
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-03 00:00:00 -05:00
18
+ date: 2011-11-16 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  requirements: []
186
186
 
187
187
  rubyforge_project: braintree
188
- rubygems_version: 1.3.7
188
+ rubygems_version: 1.4.2
189
189
  signing_key:
190
190
  specification_version: 3
191
191
  summary: Braintree Gateway Ruby Client Library