Permalink
Browse files

2.13.1

  • Loading branch information...
1 parent e5f9faa commit 7badb169bf630fcdf27c4eb78314bdb97432297d @braintreeps braintreeps committed Nov 16, 2011
View
@@ -1,3 +1,7 @@
+== 2.13.1
+
+* Made the production endpoint configurable
+
== 2.13.0
* Added new error code for merchant accounts that do not support refunds
@@ -2,9 +2,10 @@ module Braintree
# See http://www.braintreepayments.com/docs/ruby
class Configuration
API_VERSION = "2" # :nodoc:
+ DEFAULT_ENDPOINT = "www" # :nodoc:
class << self
- attr_writer :custom_user_agent, :logger, :merchant_id, :public_key, :private_key
+ attr_writer :custom_user_agent, :endpoint, :logger, :merchant_id, :public_key, :private_key
end
attr_reader :merchant_id, :public_key, :private_key
@@ -34,6 +35,7 @@ def self.gateway # :nodoc:
def self.instantiate # :nodoc:
config = new(
:custom_user_agent => @custom_user_agent,
+ :endpoint => @endpoint,
:environment => environment,
:logger => logger,
:merchant_id => merchant_id,
@@ -47,7 +49,7 @@ def self.logger
end
def initialize(options = {})
- [:environment, :merchant_id, :public_key, :private_key, :custom_user_agent, :logger].each do |attr|
+ [:endpoint, :environment, :merchant_id, :public_key, :private_key, :custom_user_agent, :logger].each do |attr|
instance_variable_set "@#{attr}", options[attr]
end
end
@@ -73,6 +75,10 @@ def ca_file # :nodoc:
end
end
+ def endpoint
+ @endpoint || DEFAULT_ENDPOINT
+ end
+
def http # :nodoc:
Http.new(self)
end
@@ -99,7 +105,7 @@ def server # :nodoc:
when :development
"localhost"
when :production
- "www.braintreegateway.com"
+ "#{endpoint}.braintreegateway.com"
when :qa
"qa.braintreegateway.com"
when :sandbox
@@ -108,6 +108,7 @@ def initialize(gateway, attributes) # :nodoc:
set_instance_variables_from_hash(attributes)
@credit_cards = (@credit_cards || []).map { |pm| CreditCard._new gateway, pm }
@addresses = (@addresses || []).map { |addr| Address._new gateway, addr }
+ @custom_fields = attributes[:custom_fields].is_a?(Hash) ? attributes[:custom_fields] : {}
end
# See http://www.braintreepayments.com/docs/ruby/transactions/create_from_vault
@@ -172,6 +172,7 @@ def initialize(gateway, attributes) # :nodoc:
@status_history = attributes[:status_history] ? attributes[:status_history].map { |s| StatusDetails.new(s) } : []
@tax_amount = Util.to_big_decimal(tax_amount)
@descriptor = Descriptor.new(@descriptor)
+ @custom_fields = attributes[:custom_fields].is_a?(Hash) ? attributes[:custom_fields] : {}
add_ons.map! { |attrs| AddOn._new(attrs) } if add_ons
discounts.map! { |attrs| Discount._new(attrs) } if discounts
end
View
@@ -2,7 +2,7 @@ module Braintree
module Version
Major = 2
Minor = 13
- Tiny = 0
+ Tiny = 1
String = "#{Major}.#{Minor}.#{Tiny}"
end
@@ -211,6 +211,16 @@
result.customer.custom_fields[:store_me].should == "custom value"
end
+ it "returns empty hash for custom fields when blank" do
+ result = Braintree::Customer.create(
+ :first_name => "Bill",
+ :last_name => "Gates",
+ :custom_fields => { :store_me => "" }
+ )
+ result.success?.should == true
+ result.customer.custom_fields.should == {}
+ end
+
it "returns nested errors if credit card and/or billing address are invalid" do
result = Braintree::Customer.create(
:email => "invalid",
@@ -396,6 +396,23 @@
result.transaction.custom_fields.should == {:store_me => "custom value"}
end
+ it "returns nil if a custom field is not defined" do
+ create_result = Braintree::Transaction.sale(
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
+ :credit_card => {
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "12/2012"
+ },
+ :custom_fields => {
+ :store_me => ""
+ }
+ )
+
+ result = Braintree::Transaction.find(create_result.transaction.id)
+
+ result.custom_fields.should == {}
+ end
+
it "returns an error if custom_field is not registered" do
result = Braintree::Transaction.create(
:type => "sale",
@@ -11,9 +11,10 @@
after do
Braintree::Configuration.merchant_id = @original_merchant_id
- Braintree::Configuration.public_key = @original_public_key
+ Braintree::Configuration.public_key = @original_public_key
Braintree::Configuration.private_key = @original_private_key
Braintree::Configuration.environment = @original_environment
+ Braintree::Configuration.endpoint = Braintree::Configuration::DEFAULT_ENDPOINT
end
describe "base_merchant_path" do
@@ -180,7 +181,7 @@
end
- describe "self.server" do
+ describe "server" do
it "is localhost for development" do
Braintree::Configuration.environment = :development
Braintree::Configuration.instantiate.server.should == "localhost"
@@ -200,6 +201,12 @@
Braintree::Configuration.environment = :qa
Braintree::Configuration.instantiate.server.should == "qa.braintreegateway.com"
end
+
+ it "can by changed by configuring the production endpoint" do
+ Braintree::Configuration.environment = :production
+ Braintree::Configuration.endpoint = "custom-endpoint"
+ Braintree::Configuration.instantiate.server.should == "custom-endpoint.braintreegateway.com"
+ end
end
describe "ssl?" do

0 comments on commit 7badb16

Please sign in to comment.