braintree 2.4.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -65,6 +65,10 @@ Example of using bang method:
65
65
  We recommend using the bang methods when you assume that the data is valid and do not expect validations to fail.
66
66
  Otherwise, we recommend using the non-bang methods.
67
67
 
68
+ == More Information
69
+
70
+ * Documentation[http://www.braintreepaymentsolutions.com/docs/ruby]
71
+
68
72
  == Tests
69
73
 
70
74
  The unit specs can be run by anyone on any system, but the integration specs are meant to be run against a local development
@@ -3,6 +3,7 @@ require "cgi"
3
3
  require "date"
4
4
  require "digest/sha1"
5
5
  require "enumerator"
6
+ require "forwardable"
6
7
  require "logger"
7
8
  require "net/http"
8
9
  require "net/https"
@@ -18,41 +19,51 @@ end
18
19
 
19
20
  require "braintree/exceptions"
20
21
  require "braintree/base_module"
22
+ require "braintree/modification"
21
23
 
22
- require "braintree/address.rb"
23
- require "braintree/advanced_search.rb"
24
- require "braintree/configuration.rb"
25
- require "braintree/credit_card.rb"
26
- require "braintree/credit_card_verification.rb"
27
- require "braintree/customer.rb"
28
- require "braintree/digest.rb"
29
- require "braintree/error_codes.rb"
30
- require "braintree/error_result.rb"
31
- require "braintree/errors.rb"
32
- require "braintree/http.rb"
33
- require "braintree/resource_collection.rb"
34
- require "braintree/ssl_expiration_check.rb"
24
+ require "braintree/add_on"
25
+ require "braintree/address"
26
+ require "braintree/address_gateway"
27
+ require "braintree/advanced_search"
28
+ require "braintree/configuration"
29
+ require "braintree/credit_card"
30
+ require "braintree/credit_card_gateway"
31
+ require "braintree/credit_card_verification"
32
+ require "braintree/customer"
33
+ require "braintree/customer_gateway"
34
+ require "braintree/digest"
35
+ require "braintree/discount"
36
+ require "braintree/error_codes"
37
+ require "braintree/error_result"
38
+ require "braintree/errors"
39
+ require "braintree/gateway"
40
+ require "braintree/http"
41
+ require "braintree/resource_collection"
42
+ require "braintree/ssl_expiration_check"
35
43
  require "braintree/subscription"
44
+ require "braintree/subscription_gateway"
36
45
  require "braintree/subscription_search"
37
- require "braintree/successful_result.rb"
38
- require "braintree/test/credit_card_numbers.rb"
39
- require "braintree/test/transaction_amounts.rb"
40
- require "braintree/transaction.rb"
41
- require "braintree/transaction_search.rb"
42
- require "braintree/transaction/address_details.rb"
43
- require "braintree/transaction/credit_card_details.rb"
44
- require "braintree/transaction/customer_details.rb"
45
- require "braintree/transaction/status_details.rb"
46
- require "braintree/transparent_redirect.rb"
47
- require "braintree/util.rb"
48
- require "braintree/validation_error.rb"
49
- require "braintree/validation_error_collection.rb"
50
- require "braintree/version.rb"
51
- require "braintree/xml.rb"
52
- require "braintree/xml/generator.rb"
53
- require "braintree/xml/libxml.rb"
54
- require "braintree/xml/rexml.rb"
55
- require "braintree/xml/parser.rb"
46
+ require "braintree/successful_result"
47
+ require "braintree/test/credit_card_numbers"
48
+ require "braintree/test/transaction_amounts"
49
+ require "braintree/transaction"
50
+ require "braintree/transaction/address_details"
51
+ require "braintree/transaction/credit_card_details"
52
+ require "braintree/transaction/customer_details"
53
+ require "braintree/transaction_gateway"
54
+ require "braintree/transaction_search"
55
+ require "braintree/transaction/status_details"
56
+ require "braintree/transparent_redirect"
57
+ require "braintree/transparent_redirect_gateway"
58
+ require "braintree/util"
59
+ require "braintree/validation_error"
60
+ require "braintree/validation_error_collection"
61
+ require "braintree/version"
62
+ require "braintree/xml"
63
+ require "braintree/xml/generator"
64
+ require "braintree/xml/libxml"
65
+ require "braintree/xml/rexml"
66
+ require "braintree/xml/parser"
56
67
 
57
68
  Braintree::SSLExpirationCheck.check_dates
58
69
 
@@ -0,0 +1,4 @@
1
+ module Braintree
2
+ class AddOn < Modification
3
+ end
4
+ end
@@ -1,7 +1,5 @@
1
1
  module Braintree
2
- # An Address belongs to a Customer. It can be associated to a
3
- # CreditCard as the billing address. It can also be used
4
- # as the shipping address when creating a Transaction.
2
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/addresses/details
5
3
  class Address
6
4
  include BaseModule # :nodoc:
7
5
 
@@ -10,21 +8,7 @@ module Braintree
10
8
  :country_code_alpha2, :country_code_alpha3, :country_code_numeric
11
9
 
12
10
  def self.create(attributes)
13
- Util.verify_keys(_create_signature, attributes)
14
- unless attributes[:customer_id]
15
- raise ArgumentError, "Expected hash to contain a :customer_id"
16
- end
17
- unless attributes[:customer_id] =~ /\A[0-9A-Za-z_-]+\z/
18
- raise ArgumentError, ":customer_id contains invalid characters"
19
- end
20
- response = Http.post "/customers/#{attributes.delete(:customer_id)}/addresses", :address => attributes
21
- if response[:address]
22
- SuccessfulResult.new(:address => new(response[:address]))
23
- elsif response[:api_error_response]
24
- ErrorResult.new(response[:api_error_response])
25
- else
26
- raise UnexpectedError, "expected :address or :api_error_response"
27
- end
11
+ Configuration.gateway.address.create(attributes)
28
12
  end
29
13
 
30
14
  def self.create!(attributes)
@@ -32,39 +16,23 @@ module Braintree
32
16
  end
33
17
 
34
18
  def self.delete(customer_or_customer_id, address_id)
35
- customer_id = _determine_customer_id(customer_or_customer_id)
36
- Http.delete("/customers/#{customer_id}/addresses/#{address_id}")
37
- SuccessfulResult.new
19
+ Configuration.gateway.address.delete(customer_or_customer_id, address_id)
38
20
  end
39
21
 
40
- # Finds the address with the given +address_id+ that is associated to the given +customer_or_customer_id+.
41
- # If the address cannot be found, a NotFoundError will be raised.
42
22
  def self.find(customer_or_customer_id, address_id)
43
- customer_id = _determine_customer_id(customer_or_customer_id)
44
- response = Http.get("/customers/#{customer_id}/addresses/#{address_id}")
45
- new(response[:address])
46
- rescue NotFoundError
47
- raise NotFoundError, "address for customer #{customer_id.inspect} with id #{address_id.inspect} not found"
23
+ Configuration.gateway.address.find(customer_or_customer_id, address_id)
48
24
  end
49
25
 
50
26
  def self.update(customer_or_customer_id, address_id, attributes)
51
- Util.verify_keys(_update_signature, attributes)
52
- customer_id = _determine_customer_id(customer_or_customer_id)
53
- response = Http.put "/customers/#{customer_id}/addresses/#{address_id}", :address => attributes
54
- if response[:address]
55
- SuccessfulResult.new(:address => new(response[:address]))
56
- elsif response[:api_error_response]
57
- ErrorResult.new(response[:api_error_response])
58
- else
59
- raise UnexpectedError, "expected :address or :api_error_response"
60
- end
27
+ Configuration.gateway.address.update(customer_or_customer_id, address_id, attributes)
61
28
  end
62
29
 
63
30
  def self.update!(customer_or_customer_id, address_id, attributes)
64
31
  return_object_or_raise(:address) { update(customer_or_customer_id, address_id, attributes) }
65
32
  end
66
33
 
67
- def initialize(attributes) # :nodoc:
34
+ def initialize(gateway, attributes) # :nodoc:
35
+ @gateway = gateway
68
36
  set_instance_variables_from_hash(attributes)
69
37
  end
70
38
 
@@ -73,25 +41,25 @@ module Braintree
73
41
  id == other.id && customer_id == other.customer_id
74
42
  end
75
43
 
76
- # Deletes the address.
44
+ # Deprecated. Use Braintree::Address.delete
77
45
  def delete
78
- Address.delete(customer_id, self.id)
46
+ warn "[DEPRECATED] delete as an instance method is deprecated. Please use CreditCard.delete"
47
+ @gateway.address.delete(customer_id, self.id)
79
48
  end
80
49
 
50
+ # Deprecated. Use Braintree::Address.update
81
51
  def update(attributes)
82
- Util.verify_keys(self.class._update_signature, attributes)
83
- response = Http.put "/customers/#{customer_id}/addresses/#{id}", :address => attributes
84
- if response[:address]
85
- set_instance_variables_from_hash response[:address]
86
- SuccessfulResult.new(:address => self)
87
- elsif response[:api_error_response]
88
- ErrorResult.new(response[:api_error_response])
89
- else
90
- raise UnexpectedError, "expected :address or :api_error_response"
52
+ warn "[DEPRECATED] update as an instance method is deprecated. Please use CreditCard.update"
53
+ result = @gateway.address.update(customer_id, id, attributes)
54
+ if result.success?
55
+ copy_instance_variables_from_object result.address
91
56
  end
57
+ result
92
58
  end
93
59
 
60
+ # Deprecated. Use Braintree::Address.update!
94
61
  def update!(attributes)
62
+ warn "[DEPRECATED] update! as an instance method is deprecated. Please use CreditCard.update!"
95
63
  return_object_or_raise(:address) { update(attributes) }
96
64
  end
97
65
 
@@ -99,30 +67,8 @@ module Braintree
99
67
  protected :new
100
68
  end
101
69
 
102
- def self._create_signature # :nodoc:
103
- _shared_signature + [:customer_id]
104
- end
105
-
106
- def self._determine_customer_id(customer_or_customer_id) # :nodoc:
107
- customer_id = customer_or_customer_id.is_a?(Customer) ? customer_or_customer_id.id : customer_or_customer_id
108
- unless customer_id =~ /\A[\w_-]+\z/
109
- raise ArgumentError, "customer_id contains invalid characters"
110
- end
111
- customer_id
112
- end
113
-
114
- def self._shared_signature # :nodoc:
115
- [:company, :country_code_alpha2, :country_code_alpha3, :country_code_numeric,
116
- :country_name, :extended_address, :first_name,
117
- :last_name, :locality, :postal_code, :region, :street_address]
118
- end
119
-
120
70
  def self._new(*args) # :nodoc:
121
71
  self.new *args
122
72
  end
123
-
124
- def self._update_signature # :nodoc:
125
- _create_signature
126
- end
127
73
  end
128
74
  end
@@ -0,0 +1,76 @@
1
+ module Braintree
2
+ class AddressGateway # :nodoc
3
+ def initialize(gateway)
4
+ @gateway = gateway
5
+ @config = gateway.config
6
+ end
7
+
8
+ def create(attributes)
9
+ Util.verify_keys(AddressGateway._create_signature, attributes)
10
+ unless attributes[:customer_id]
11
+ raise ArgumentError, "Expected hash to contain a :customer_id"
12
+ end
13
+ unless attributes[:customer_id] =~ /\A[0-9A-Za-z_-]+\z/
14
+ raise ArgumentError, ":customer_id contains invalid characters"
15
+ end
16
+ response = @config.http.post "/customers/#{attributes.delete(:customer_id)}/addresses", :address => attributes
17
+ if response[:address]
18
+ SuccessfulResult.new(:address => Address._new(@gateway, response[:address]))
19
+ elsif response[:api_error_response]
20
+ ErrorResult.new(@gateway, response[:api_error_response])
21
+ else
22
+ raise UnexpectedError, "expected :address or :api_error_response"
23
+ end
24
+ end
25
+
26
+ def delete(customer_or_customer_id, address_id)
27
+ customer_id = _determine_customer_id(customer_or_customer_id)
28
+ @config.http.delete("/customers/#{customer_id}/addresses/#{address_id}")
29
+ SuccessfulResult.new
30
+ end
31
+
32
+ def find(customer_or_customer_id, address_id)
33
+ customer_id = _determine_customer_id(customer_or_customer_id)
34
+ response = @config.http.get("/customers/#{customer_id}/addresses/#{address_id}")
35
+ Address._new(@gateway, response[:address])
36
+ rescue NotFoundError
37
+ raise NotFoundError, "address for customer #{customer_id.inspect} with id #{address_id.inspect} not found"
38
+ end
39
+
40
+ def update(customer_or_customer_id, address_id, attributes)
41
+ Util.verify_keys(AddressGateway._update_signature, attributes)
42
+ customer_id = _determine_customer_id(customer_or_customer_id)
43
+ response = @config.http.put "/customers/#{customer_id}/addresses/#{address_id}", :address => attributes
44
+ if response[:address]
45
+ SuccessfulResult.new(:address => Address._new(@gateway, response[:address]))
46
+ elsif response[:api_error_response]
47
+ ErrorResult.new(@gateway, response[:api_error_response])
48
+ else
49
+ raise UnexpectedError, "expected :address or :api_error_response"
50
+ end
51
+ end
52
+
53
+ def _determine_customer_id(customer_or_customer_id) # :nodoc:
54
+ customer_id = customer_or_customer_id.is_a?(Customer) ? customer_or_customer_id.id : customer_or_customer_id
55
+ unless customer_id =~ /\A[\w_-]+\z/
56
+ raise ArgumentError, "customer_id contains invalid characters"
57
+ end
58
+ customer_id
59
+ end
60
+
61
+ def self._create_signature # :nodoc:
62
+ _shared_signature + [:customer_id]
63
+ end
64
+
65
+ def self._shared_signature # :nodoc:
66
+ [:company, :country_code_alpha2, :country_code_alpha3, :country_code_numeric,
67
+ :country_name, :extended_address, :first_name,
68
+ :last_name, :locality, :postal_code, :region, :street_address]
69
+ end
70
+
71
+ def self._update_signature # :nodoc:
72
+ _create_signature
73
+ end
74
+ end
75
+ end
76
+
@@ -1,6 +1,6 @@
1
1
  module Braintree
2
- class AdvancedSearch
3
- class SearchNode
2
+ class AdvancedSearch # :nodoc:
3
+ class SearchNode # :nodoc:
4
4
  def self.operators(*operator_names)
5
5
  operator_names.each do |operator|
6
6
  define_method(operator) do |value|
@@ -14,25 +14,25 @@ module Braintree
14
14
  end
15
15
  end
16
16
 
17
- class EqualityNode < SearchNode
17
+ class EqualityNode < SearchNode # :nodoc:
18
18
  operators :is, :is_not
19
19
  end
20
20
 
21
- class PartialMatchNode < EqualityNode
21
+ class PartialMatchNode < EqualityNode # :nodoc:
22
22
  operators :ends_with, :starts_with
23
23
  end
24
24
 
25
- class TextNode < PartialMatchNode
25
+ class TextNode < PartialMatchNode # :nodoc:
26
26
  operators :contains
27
27
  end
28
28
 
29
- class KeyValueNode < SearchNode
29
+ class KeyValueNode < SearchNode # :nodoc:
30
30
  def is(value)
31
31
  @parent.add_criteria(@node_name, value)
32
32
  end
33
33
  end
34
34
 
35
- class MultipleValueNode < SearchNode
35
+ class MultipleValueNode < SearchNode # :nodoc:
36
36
  def in(*values)
37
37
  values.flatten!
38
38
 
@@ -44,10 +44,6 @@ module Braintree
44
44
  @parent.add_criteria(@node_name, values)
45
45
  end
46
46
 
47
- def is(value)
48
- self.in(value)
49
- end
50
-
51
47
  def initialize(name, parent, options)
52
48
  super(name, parent)
53
49
  @options = options
@@ -56,9 +52,25 @@ module Braintree
56
52
  def allowed_values
57
53
  @options[:allows]
58
54
  end
55
+
56
+ def is(value)
57
+ self.in(value)
58
+ end
59
+ end
60
+
61
+ class MultipleValueOrTextNode < MultipleValueNode
62
+ extend Forwardable
63
+ def_delegators :@text_node, :contains, :ends_with, :is, :is_not, :starts_with
64
+
65
+ def initialize(name, parent, options)
66
+ super
67
+ @text_node = TextNode.new(name, parent)
68
+ end
59
69
  end
60
70
 
61
- class RangeNode < SearchNode
71
+ class RangeNode < SearchNode # :nodoc:
72
+ operators :is
73
+
62
74
  def between(min, max)
63
75
  self >= min
64
76
  self <= max
@@ -73,7 +85,7 @@ module Braintree
73
85
  end
74
86
  end
75
87
 
76
- def self.search_fields(*fields)
88
+ def self.text_fields(*fields)
77
89
  _create_field_accessors(fields, TextNode)
78
90
  end
79
91
 
@@ -91,6 +103,12 @@ module Braintree
91
103
  end
92
104
  end
93
105
 
106
+ def self.multiple_value_or_text_field(field, options={})
107
+ define_method(field) do
108
+ MultipleValueOrTextNode.new(field, self, options)
109
+ end
110
+ end
111
+
94
112
  def self.key_value_fields(*fields)
95
113
  _create_field_accessors(fields, KeyValueNode)
96
114
  end
@@ -10,6 +10,12 @@ module Braintree
10
10
  end
11
11
  end
12
12
 
13
+ def copy_instance_variables_from_object(object)
14
+ object.instance_variables.each do |ivar|
15
+ instance_variable_set ivar, object.instance_variable_get(ivar)
16
+ end
17
+ end
18
+
13
19
  def set_instance_variables_from_hash(hash)
14
20
  hash.each do |key, value|
15
21
  instance_variable_set "@#{key}", value
@@ -1,19 +1,12 @@
1
1
  module Braintree
2
- # The following configuration attributes need to be set to use the gem:
3
- # * merchant_id
4
- # * public_key
5
- # * private_key
6
- # * environment
7
- #
8
- # By default, the logger will log to +STDOUT+. The log level is set to info.
9
- # The logger can be set to any Logger object.
10
- module Configuration
2
+ # See http://www.braintreepaymentsolutions.com/docs/ruby
3
+ class Configuration
11
4
  API_VERSION = "2" # :nodoc:
12
5
 
13
6
  class << self
14
- attr_accessor :logger
15
- attr_writer :merchant_id, :public_key, :private_key
7
+ attr_writer :custom_user_agent, :logger, :merchant_id, :public_key, :private_key
16
8
  end
9
+ attr_reader :logger, :merchant_id, :public_key, :private_key
17
10
 
18
11
  def self.expectant_reader(*attributes) # :nodoc:
19
12
  attributes.each do |attribute|
@@ -26,16 +19,53 @@ module Braintree
26
19
  end
27
20
  expectant_reader :environment, :merchant_id, :public_key, :private_key
28
21
 
29
- def self.base_merchant_url # :nodoc:
30
- "#{protocol}://#{server}:#{port}#{base_merchant_path}"
22
+ # Sets the Braintree environment to use. Valid values are <tt>:sandbox</tt> and <tt>:production</tt>
23
+ def self.environment=(env)
24
+ unless [:development, :qa, :sandbox, :production].include?(env)
25
+ raise ArgumentError, "#{env.inspect} is not a valid environment"
26
+ end
27
+ @environment = env
28
+ end
29
+
30
+ def self.gateway # :nodoc:
31
+ Braintree::Gateway.new(instantiate)
32
+ end
33
+
34
+ def self.instantiate # :nodoc:
35
+ config = new(
36
+ :custom_user_agent => @custom_user_agent,
37
+ :environment => environment,
38
+ :logger => logger,
39
+ :merchant_id => merchant_id,
40
+ :private_key => private_key,
41
+ :public_key => public_key
42
+ )
43
+ end
44
+
45
+ def self.logger
46
+ @logger ||= _default_logger
47
+ end
48
+
49
+ def initialize(options = {})
50
+ [:environment, :merchant_id, :public_key, :private_key, :custom_user_agent, :logger].each do |attr|
51
+ instance_variable_set "@#{attr}", options[attr]
52
+ end
31
53
  end
32
54
 
33
- def self.base_merchant_path # :nodoc:
34
- "/merchants/#{Braintree::Configuration.merchant_id}"
55
+ def api_version # :nodoc:
56
+ API_VERSION
35
57
  end
36
58
 
37
- def self.ca_file # :nodoc:
38
- case environment
59
+ def base_merchant_path # :nodoc:
60
+ "/merchants/#{merchant_id}"
61
+ end
62
+
63
+ def base_merchant_url # :nodoc:
64
+ "#{protocol}://#{server}:#{port}#{base_merchant_path}"
65
+ end
66
+
67
+ def ca_file # :nodoc:
68
+ case @environment
39
69
  when :qa, :sandbox
40
70
  File.expand_path(File.join(File.dirname(__FILE__), "..", "ssl", "sandbox_braintreegateway_com.ca.crt"))
41
71
  when :production
@@ -43,20 +73,12 @@ module Braintree
43
73
  end
44
74
  end
45
75
 
46
- # Sets the Braintree environment to use. Valid values are <tt>:sandbox</tt> and <tt>:production</tt>
47
- def self.environment=(env)
48
- unless [:development, :qa, :sandbox, :production].include?(env)
49
- raise ArgumentError, "#{env.inspect} is not a valid environment"
50
- end
51
- @environment = env
52
- end
53
-
54
- def self.logger # :nodoc:
55
- @logger ||= _default_logger
76
+ def http # :nodoc:
77
+ Http.new(self)
56
78
  end
57
79
 
58
- def self.port # :nodoc:
59
- case environment
80
+ def port # :nodoc:
81
+ case @environment
60
82
  when :development
61
83
  ENV['GATEWAY_PORT'] || 3000
62
84
  when :production, :qa, :sandbox
@@ -64,12 +86,12 @@ module Braintree
64
86
  end
65
87
  end
66
88
 
67
- def self.protocol # :nodoc:
89
+ def protocol # :nodoc:
68
90
  ssl? ? "https" : "http"
69
91
  end
70
92
 
71
- def self.server # :nodoc:
72
- case environment
93
+ def server # :nodoc:
94
+ case @environment
73
95
  when :development
74
96
  "localhost"
75
97
  when :production
@@ -81,8 +103,8 @@ module Braintree
81
103
  end
82
104
  end
83
105
 
84
- def self.ssl? # :nodoc:
85
- case environment
106
+ def ssl? # :nodoc:
107
+ case @environment
86
108
  when :development
87
109
  false
88
110
  when :production, :qa, :sandbox
@@ -90,11 +112,7 @@ module Braintree
90
112
  end
91
113
  end
92
114
 
93
- def self.custom_user_agent=(custom_user_agent)
94
- @custom_user_agent = custom_user_agent
95
- end
96
-
97
- def self.user_agent
115
+ def user_agent # :nodoc:
98
116
  base_user_agent = "Braintree Ruby Gem #{Braintree::Version::String}"
99
117
  @custom_user_agent ? "#{base_user_agent} (#{@custom_user_agent})" : base_user_agent
100
118
  end