braintree 1.1.2 → 1.1.3

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.
@@ -90,6 +90,15 @@ module Braintree
90
90
  end
91
91
  end
92
92
 
93
+ def self.custom_user_agent=(custom_user_agent)
94
+ @custom_user_agent = custom_user_agent
95
+ end
96
+
97
+ def self.user_agent
98
+ base_user_agent = "Braintree Ruby Gem #{Braintree::Version::String}"
99
+ @custom_user_agent ? "#{base_user_agent} (#{@custom_user_agent})" : base_user_agent
100
+ end
101
+
93
102
  def self._default_logger # :nodoc:
94
103
  logger = Logger.new(STDOUT)
95
104
  logger.level = Logger::INFO
@@ -191,11 +191,7 @@ module Braintree
191
191
  end
192
192
 
193
193
  def self._create_signature # :nodoc:
194
- [
195
- :customer_id, :cardholder_name, :cvv, :number, :expiration_date, :expiration_month, :expiration_year, :token,
196
- {:options => [:verify_card]},
197
- {:billing_address => [:first_name, :last_name, :company, :country_name, :extended_address, :locality, :region, :postal_code, :street_address]}
198
- ]
194
+ _update_signature + [:customer_id]
199
195
  end
200
196
 
201
197
  def self._new(*args) # :nodoc:
@@ -226,9 +222,9 @@ module Braintree
226
222
 
227
223
  def self._update_signature # :nodoc:
228
224
  [
229
- :cardholder_name, :cvv, :number, :expiration_date, :expiration_month, :expiration_year, :token,
225
+ :cardholder_name, :cvv, :expiration_date, :expiration_month, :expiration_year, :number, :token,
230
226
  {:options => [:verify_card]},
231
- {:billing_address => [:first_name, :last_name, :company, :country_name, :extended_address, :locality, :region, :postal_code, :street_address]}
227
+ {:billing_address => [:company, :country_name, :extended_address, :first_name, :last_name, :locality, :postal_code, :region, :street_address]}
232
228
  ]
233
229
  end
234
230
 
@@ -79,7 +79,7 @@ module Braintree
79
79
  end
80
80
 
81
81
  def self.find(customer_id)
82
- raise ArgumentError, "customer_id should be a string" unless customer_id.is_a?(String)
82
+ raise ArgumentError, "customer_id contains invalid characters" unless customer_id.to_s =~ /\A[\w-]+\z/
83
83
  raise ArgumentError, "customer_id cannot be blank" if customer_id.to_s == ""
84
84
  response = Http.get("/customers/#{customer_id}")
85
85
  new(response[:customer])
@@ -53,7 +53,7 @@ module Braintree
53
53
  connection.start do |http|
54
54
  request = http_verb.new("#{Configuration.base_merchant_path}#{path}")
55
55
  request["Accept"] = "application/xml"
56
- request["User-Agent"] = "Braintree Ruby Gem #{Braintree::Version::String}"
56
+ request["User-Agent"] = Configuration.user_agent
57
57
  request["Accept-Encoding"] = "gzip"
58
58
  request["X-ApiVersion"] = Configuration::API_VERSION
59
59
  request.basic_auth Configuration.public_key, Configuration.private_key
@@ -1,7 +1,7 @@
1
1
  module Braintree
2
2
  module Util # :nodoc:
3
3
  def self.extract_attribute_as_array(hash, attribute)
4
- value = hash.delete(attribute)
4
+ value = hash.has_key?(attribute) ? hash.delete(attribute) : []
5
5
  value.is_a?(Array) ? value : [value]
6
6
  end
7
7
 
@@ -2,7 +2,7 @@ module Braintree
2
2
  module Version
3
3
  Major = 1
4
4
  Minor = 1
5
- Tiny = 2
5
+ Tiny = 3
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Tiny}"
8
8
  end
@@ -498,13 +498,13 @@ describe Braintree::Customer do
498
498
  it "raises an ArgumentError if customer_id is not a string" do
499
499
  expect do
500
500
  Braintree::Customer.find(Object.new)
501
- end.to raise_error(ArgumentError, "customer_id should be a string")
501
+ end.to raise_error(ArgumentError, "customer_id contains invalid characters")
502
502
  end
503
503
 
504
504
  it "raises an ArgumentError if customer_id is blank" do
505
505
  expect do
506
506
  Braintree::Customer.find("")
507
- end.to raise_error(ArgumentError, "customer_id cannot be blank")
507
+ end.to raise_error(ArgumentError, "customer_id contains invalid characters")
508
508
  end
509
509
 
510
510
  it "raises a NotFoundError exception if customer cannot be found" do
@@ -198,10 +198,11 @@ describe Braintree::Subscription do
198
198
  :payment_method_token => @credit_card.token,
199
199
  :plan_id => TrialPlan[:id],
200
200
  :trial_period => true,
201
+ :trial_duration => 2,
201
202
  :trial_duration_unit => nil
202
203
  )
203
204
  result.success?.should == false
204
- result.errors.for(:subscription)[0].message.should == "Trial Duration Unit is invalid."
205
+ result.errors.for(:subscription).on(:trial_duration_unit)[0].message.should == "Trial Duration Unit is invalid."
205
206
  end
206
207
 
207
208
  end
@@ -197,4 +197,19 @@ describe Braintree::Configuration do
197
197
  end
198
198
  end
199
199
 
200
+ describe "self.user_agent" do
201
+ after :each do
202
+ Braintree::Configuration.custom_user_agent = nil
203
+ end
204
+
205
+ it "appends the default user_agent with the given value" do
206
+ 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)"
208
+ end
209
+
210
+ it "does not append anything if there is no custom_user_agent" do
211
+ Braintree::Configuration.custom_user_agent = nil
212
+ Braintree::Configuration.user_agent.should == "Braintree Ruby Gem #{Braintree::Version::String}"
213
+ end
214
+ end
200
215
  end
@@ -9,6 +9,18 @@ describe Braintree::CreditCard do
9
9
  end
10
10
  end
11
11
 
12
+ describe "self.create_signature" do
13
+ it "should include customer_id" do
14
+ Braintree::CreditCard._create_signature.should include(:customer_id)
15
+ end
16
+ end
17
+
18
+ describe "self.update_signature" do
19
+ it "should not include customer_id" do
20
+ Braintree::CreditCard._update_signature.should_not include(:customer_id)
21
+ end
22
+ end
23
+
12
24
  describe "self.create_from_transparent_redirect" do
13
25
  it "raises an exception if the query string is forged" do
14
26
  expect do
@@ -137,6 +137,12 @@ describe Braintree::Util do
137
137
  result = Braintree::Util.extract_attribute_as_array(hash, :foo)
138
138
  result.should == ["one", "two"]
139
139
  end
140
+
141
+ it "returns empty array if the attribute is not in the hash" do
142
+ hash = {:foo => ["one", "two"], :bar => :baz}
143
+ result = Braintree::Util.extract_attribute_as_array(hash, :quz)
144
+ result.should == []
145
+ end
140
146
  end
141
147
 
142
148
  describe "self.hash_to_query_string" do
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: braintree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 1
8
+ - 3
9
+ version: 1.1.3
5
10
  platform: ruby
6
11
  authors:
7
12
  - Braintree Payment Solutions
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-03-19 00:00:00 -05:00
17
+ date: 2010-04-01 00:00:00 -05:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -109,18 +114,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
114
  requirements:
110
115
  - - ">="
111
116
  - !ruby/object:Gem::Version
117
+ segments:
118
+ - 0
112
119
  version: "0"
113
- version:
114
120
  required_rubygems_version: !ruby/object:Gem::Requirement
115
121
  requirements:
116
122
  - - ">="
117
123
  - !ruby/object:Gem::Version
124
+ segments:
125
+ - 0
118
126
  version: "0"
119
- version:
120
127
  requirements: []
121
128
 
122
129
  rubyforge_project: braintree
123
- rubygems_version: 1.3.5
130
+ rubygems_version: 1.3.6
124
131
  signing_key:
125
132
  specification_version: 3
126
133
  summary: Braintree Gateway Ruby Client Library