braintree 2.12.0 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.
data/braintree.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require 'braintree/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "braintree"
6
+ s.summary = "Braintree Gateway Ruby Client Library"
7
+ s.description = "Ruby library for integrating with the Braintree Gateway"
8
+ s.version = Braintree::Version::String
9
+ s.author = "Braintree"
10
+ s.email = "code@getbraintree.com"
11
+ s.homepage = "http://www.braintreepayments.com/"
12
+ s.rubyforge_project = "braintree"
13
+ s.has_rdoc = false
14
+ s.files = Dir.glob ["README.rdoc", "LICENSE", "{lib,spec}/**/*.rb", "lib/**/*.crt", "*.gemspec"]
15
+ s.add_dependency "builder", ">= 2.0.0"
16
+ end
17
+
data/lib/braintree.rb CHANGED
@@ -14,60 +14,60 @@ require "zlib"
14
14
 
15
15
  require "builder"
16
16
 
17
- require File.dirname(__FILE__) + "/braintree/exceptions"
17
+ require "braintree/exceptions"
18
18
 
19
- require File.dirname(__FILE__) + "/braintree/base_module"
20
- require File.dirname(__FILE__) + "/braintree/modification"
19
+ require "braintree/base_module"
20
+ require "braintree/modification"
21
21
 
22
- require File.dirname(__FILE__) + "/braintree/add_on"
23
- require File.dirname(__FILE__) + "/braintree/add_on_gateway"
24
- require File.dirname(__FILE__) + "/braintree/address/country_names"
25
- require File.dirname(__FILE__) + "/braintree/address"
26
- require File.dirname(__FILE__) + "/braintree/address_gateway"
27
- require File.dirname(__FILE__) + "/braintree/advanced_search"
28
- require File.dirname(__FILE__) + "/braintree/configuration"
29
- require File.dirname(__FILE__) + "/braintree/credit_card"
30
- require File.dirname(__FILE__) + "/braintree/credit_card_gateway"
31
- require File.dirname(__FILE__) + "/braintree/credit_card_verification"
32
- require File.dirname(__FILE__) + "/braintree/customer"
33
- require File.dirname(__FILE__) + "/braintree/customer_gateway"
34
- require File.dirname(__FILE__) + "/braintree/customer_search"
35
- require File.dirname(__FILE__) + "/braintree/descriptor"
36
- require File.dirname(__FILE__) + "/braintree/digest"
37
- require File.dirname(__FILE__) + "/braintree/discount"
38
- require File.dirname(__FILE__) + "/braintree/discount_gateway"
39
- require File.dirname(__FILE__) + "/braintree/error_codes"
40
- require File.dirname(__FILE__) + "/braintree/error_result"
41
- require File.dirname(__FILE__) + "/braintree/errors"
42
- require File.dirname(__FILE__) + "/braintree/gateway"
43
- require File.dirname(__FILE__) + "/braintree/http"
44
- require File.dirname(__FILE__) + "/braintree/plan"
45
- require File.dirname(__FILE__) + "/braintree/plan_gateway"
46
- require File.dirname(__FILE__) + "/braintree/settlement_batch_summary"
47
- require File.dirname(__FILE__) + "/braintree/settlement_batch_summary_gateway"
48
- require File.dirname(__FILE__) + "/braintree/resource_collection"
49
- require File.dirname(__FILE__) + "/braintree/subscription"
50
- require File.dirname(__FILE__) + "/braintree/subscription_gateway"
51
- require File.dirname(__FILE__) + "/braintree/subscription_search"
52
- require File.dirname(__FILE__) + "/braintree/successful_result"
53
- require File.dirname(__FILE__) + "/braintree/test/credit_card_numbers"
54
- require File.dirname(__FILE__) + "/braintree/test/transaction_amounts"
55
- require File.dirname(__FILE__) + "/braintree/transaction"
56
- require File.dirname(__FILE__) + "/braintree/transaction/address_details"
57
- require File.dirname(__FILE__) + "/braintree/transaction/credit_card_details"
58
- require File.dirname(__FILE__) + "/braintree/transaction/customer_details"
59
- require File.dirname(__FILE__) + "/braintree/transaction/subscription_details"
60
- require File.dirname(__FILE__) + "/braintree/transaction_gateway"
61
- require File.dirname(__FILE__) + "/braintree/transaction_search"
62
- require File.dirname(__FILE__) + "/braintree/transaction/status_details"
63
- require File.dirname(__FILE__) + "/braintree/transparent_redirect"
64
- require File.dirname(__FILE__) + "/braintree/transparent_redirect_gateway"
65
- require File.dirname(__FILE__) + "/braintree/util"
66
- require File.dirname(__FILE__) + "/braintree/validation_error"
67
- require File.dirname(__FILE__) + "/braintree/validation_error_collection"
68
- require File.dirname(__FILE__) + "/braintree/version"
69
- require File.dirname(__FILE__) + "/braintree/xml"
70
- require File.dirname(__FILE__) + "/braintree/xml/generator"
71
- require File.dirname(__FILE__) + "/braintree/xml/libxml"
72
- require File.dirname(__FILE__) + "/braintree/xml/rexml"
73
- require File.dirname(__FILE__) + "/braintree/xml/parser"
22
+ require "braintree/add_on"
23
+ require "braintree/add_on_gateway"
24
+ require "braintree/address/country_names"
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/customer_search"
35
+ require "braintree/descriptor"
36
+ require "braintree/digest"
37
+ require "braintree/discount"
38
+ require "braintree/discount_gateway"
39
+ require "braintree/error_codes"
40
+ require "braintree/error_result"
41
+ require "braintree/errors"
42
+ require "braintree/gateway"
43
+ require "braintree/http"
44
+ require "braintree/plan"
45
+ require "braintree/plan_gateway"
46
+ require "braintree/settlement_batch_summary"
47
+ require "braintree/settlement_batch_summary_gateway"
48
+ require "braintree/resource_collection"
49
+ require "braintree/subscription"
50
+ require "braintree/subscription_gateway"
51
+ require "braintree/subscription_search"
52
+ require "braintree/successful_result"
53
+ require "braintree/test/credit_card_numbers"
54
+ require "braintree/test/transaction_amounts"
55
+ require "braintree/transaction"
56
+ require "braintree/transaction/address_details"
57
+ require "braintree/transaction/credit_card_details"
58
+ require "braintree/transaction/customer_details"
59
+ require "braintree/transaction/subscription_details"
60
+ require "braintree/transaction_gateway"
61
+ require "braintree/transaction_search"
62
+ require "braintree/transaction/status_details"
63
+ require "braintree/transparent_redirect"
64
+ require "braintree/transparent_redirect_gateway"
65
+ require "braintree/util"
66
+ require "braintree/validation_error"
67
+ require "braintree/validation_error_collection"
68
+ require "braintree/version"
69
+ require "braintree/xml"
70
+ require "braintree/xml/generator"
71
+ require "braintree/xml/libxml"
72
+ require "braintree/xml/rexml"
73
+ require "braintree/xml/parser"
@@ -31,6 +31,7 @@ module Braintree
31
31
 
32
32
  def find(customer_or_customer_id, address_id)
33
33
  customer_id = _determine_customer_id(customer_or_customer_id)
34
+ raise ArgumentError if address_id.nil? || address_id.strip.to_s == ""
34
35
  response = @config.http.get("/customers/#{customer_id}/addresses/#{address_id}")
35
36
  Address._new(@gateway, response[:address])
36
37
  rescue NotFoundError
@@ -101,7 +101,7 @@ module Braintree
101
101
  when :production
102
102
  "www.braintreegateway.com"
103
103
  when :qa
104
- "qa-master.braintreegateway.com"
104
+ "qa.braintreegateway.com"
105
105
  when :sandbox
106
106
  "sandbox.braintreegateway.com"
107
107
  end
@@ -41,6 +41,7 @@ module Braintree
41
41
  end
42
42
 
43
43
  def find(token)
44
+ raise ArgumentError if token.nil? || token.strip.to_s == ""
44
45
  response = @config.http.get "/payment_methods/#{token}"
45
46
  CreditCard._new(@gateway, response[:credit_card])
46
47
  rescue NotFoundError
@@ -33,7 +33,7 @@ module Braintree
33
33
 
34
34
  def find(customer_id)
35
35
  raise ArgumentError, "customer_id contains invalid characters" unless customer_id.to_s =~ /\A[\w-]+\z/
36
- raise ArgumentError, "customer_id cannot be blank" if customer_id.to_s == ""
36
+ raise ArgumentError, "customer_id cannot be blank" if customer_id.nil?|| customer_id.strip.to_s == ""
37
37
  response = @config.http.get("/customers/#{customer_id}")
38
38
  Customer._new(@gateway, response[:customer])
39
39
  rescue NotFoundError
@@ -174,7 +174,8 @@ module Braintree
174
174
  CustomerIdIsInvalid = "91510"
175
175
  HasAlreadyBeenRefunded = "91512"
176
176
  MerchantAccountIdIsInvalid = "91513"
177
- MerchantAccountIsSuspended = "91514"
177
+ MerchantAccountIsSuspended = "91515"
178
+ MerchantAccountDoesNotSupportRefunds = "91547"
178
179
  MerchantAccountNameIsInvalid = "91513" # Deprecated
179
180
  OrderIdIsTooLong = "91501"
180
181
  PaymentMethodConflict = "91515"
@@ -24,6 +24,7 @@ module Braintree
24
24
  end
25
25
 
26
26
  def find(id)
27
+ raise ArgumentError if id.nil? || id.strip.to_s == ""
27
28
  response = @config.http.get "/subscriptions/#{id}"
28
29
  Subscription._new(@gateway, response[:subscription])
29
30
  rescue NotFoundError
@@ -39,6 +39,8 @@ module Braintree
39
39
  module Type # :nodoc:
40
40
  Credit = "credit" # :nodoc:
41
41
  Sale = "sale" # :nodoc:
42
+
43
+ All = constants.map { |c| const_get(c) }
42
44
  end
43
45
 
44
46
  attr_reader :avs_error_response_code, :avs_postal_code_response_code, :avs_street_address_response_code
@@ -31,6 +31,7 @@ module Braintree
31
31
  end
32
32
 
33
33
  def find(id)
34
+ raise ArgumentError if id.nil? || id.strip.to_s == ""
34
35
  response = @config.http.get "/transactions/#{id}"
35
36
  Transaction._new(@gateway, response[:transaction])
36
37
  rescue NotFoundError
@@ -56,7 +56,7 @@ module Braintree
56
56
  Transaction::Source::ControlPanel,
57
57
  Transaction::Source::Recurring
58
58
  ]
59
- multiple_value_field :type
59
+ multiple_value_field :type, :allows => Transaction::Type::All
60
60
 
61
61
  key_value_fields :refund
62
62
 
@@ -1,7 +1,7 @@
1
1
  module Braintree
2
2
  module Version
3
3
  Major = 2
4
- Minor = 12
4
+ Minor = 13
5
5
  Tiny = 0
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Tiny}"
@@ -88,7 +88,7 @@ describe Braintree::Http do
88
88
  it "rejects when the certificate isn't verified by our certificate authority (self-signed)" do
89
89
  config = Braintree::Configuration.instantiate
90
90
  config.stub(:ssl?).and_return(true)
91
- config.stub(:port).and_return(8443)
91
+ config.stub(:port).and_return(SSL_TEST_PORT)
92
92
 
93
93
  start_ssl_server do
94
94
  expect do
@@ -104,7 +104,7 @@ describe Braintree::Http do
104
104
  File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "ssl", "geotrust_global.crt"))
105
105
  )
106
106
  config.stub(:ssl?).and_return(true)
107
- config.stub(:port).and_return(8443)
107
+ config.stub(:port).and_return(SSL_TEST_PORT)
108
108
 
109
109
  start_ssl_server do
110
110
  expect do
@@ -381,6 +381,17 @@ describe Braintree::Transaction, "search" do
381
381
  end
382
382
  end
383
383
 
384
+ context "invalid search" do
385
+ it "raises an exception on invalid transaction type" do
386
+ expect do
387
+ collection = Braintree::Transaction.search do |search|
388
+ search.customer_id.is "9171566"
389
+ search.type.is "settled"
390
+ end
391
+ end.to raise_error(ArgumentError)
392
+ end
393
+ end
394
+
384
395
  context "range fields" do
385
396
  context "amount" do
386
397
  it "searches on amount" do
@@ -1,5 +1,6 @@
1
1
  unless defined?(INTEGRATION_SPEC_HELPER_LOADED)
2
2
  INTEGRATION_SPEC_HELPER_LOADED = true
3
+ SSL_TEST_PORT = ENV['SSL_TEST_PORT'] || 8443
3
4
 
4
5
  require File.dirname(__FILE__) + "/../spec_helper"
5
6
  require File.dirname(__FILE__) + "/../hacks/tcp_socket"
@@ -10,11 +11,12 @@ unless defined?(INTEGRATION_SPEC_HELPER_LOADED)
10
11
  FileUtils.rm(web_server_pid_file) if File.exist?(web_server_pid_file)
11
12
  command = File.expand_path(File.join(File.dirname(__FILE__), "..", "script", "httpsd.rb"))
12
13
  `#{command} #{web_server_pid_file}`
13
- TCPSocket.wait_for_service :host => "127.0.0.1", :port => 8443
14
+ TCPSocket.wait_for_service :host => "127.0.0.1", :port => SSL_TEST_PORT
14
15
 
15
16
  yield
16
17
 
17
18
  10.times { unless File.exists?(web_server_pid_file); sleep 1; end }
19
+ ensure
18
20
  Process.kill "INT", File.read(web_server_pid_file).to_i
19
21
  end
20
22
 
@@ -12,7 +12,7 @@ cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
12
12
  pid_file = ARGV[0]
13
13
 
14
14
  s = WEBrick::HTTPServer.new(
15
- :Port => 8443,
15
+ :Port => (ENV['SSL_TEST_PORT'] || 8443),
16
16
  :Logger => WEBrick::Log::new(nil, WEBrick::Log::ERROR),
17
17
  :DocumentRoot => File.join(File.dirname(__FILE__)),
18
18
  :ServerType => WEBrick::Daemon,
@@ -66,6 +66,18 @@ describe Braintree::Address do
66
66
  Braintree::Address.find("spaces not allowed", "address_id")
67
67
  end.to raise_error(ArgumentError, "customer_id contains invalid characters")
68
68
  end
69
+
70
+ it "raises an error if address_id is blank" do
71
+ expect do
72
+ Braintree::Address.find("customer_id", "")
73
+ end.to raise_error(ArgumentError)
74
+ end
75
+
76
+ it "raises an error if address_id is blank" do
77
+ expect do
78
+ Braintree::Address.find("customer_id", nil)
79
+ end.to raise_error(ArgumentError)
80
+ end
69
81
  end
70
82
 
71
83
  describe "self.new" do
@@ -195,6 +195,11 @@ describe Braintree::Configuration do
195
195
  Braintree::Configuration.environment = :sandbox
196
196
  Braintree::Configuration.instantiate.server.should == "sandbox.braintreegateway.com"
197
197
  end
198
+
199
+ it "is qa.braintreegateway.com for qa" do
200
+ Braintree::Configuration.environment = :qa
201
+ Braintree::Configuration.instantiate.server.should == "qa.braintreegateway.com"
202
+ end
198
203
  end
199
204
 
200
205
  describe "ssl?" do
@@ -119,6 +119,26 @@ describe Braintree::CreditCard do
119
119
  end
120
120
  end
121
121
 
122
+ describe "self.find" do
123
+ it "raises error if passed empty string" do
124
+ expect do
125
+ Braintree::CreditCard.find("")
126
+ end.to raise_error(ArgumentError)
127
+ end
128
+
129
+ it "raises error if passed invalid string" do
130
+ expect do
131
+ Braintree::CreditCard.find("\t")
132
+ end.to raise_error(ArgumentError)
133
+ end
134
+
135
+ it "raises error if passed nil" do
136
+ expect do
137
+ Braintree::CreditCard.find(nil)
138
+ end.to raise_error(ArgumentError)
139
+ end
140
+ end
141
+
122
142
  describe "inspect" do
123
143
  it "includes the token first" do
124
144
  output = Braintree::CreditCard._new(:gateway, :token => "cc123").inspect
@@ -41,6 +41,20 @@ describe Braintree::Customer do
41
41
  end
42
42
  end
43
43
 
44
+ describe "self.find" do
45
+ it "raises an exception if the id is blank" do
46
+ expect do
47
+ Braintree::Customer.find(" ")
48
+ end.to raise_error(ArgumentError)
49
+ end
50
+
51
+ it "raises an exception if the id is nil" do
52
+ expect do
53
+ Braintree::Customer.find(nil)
54
+ end.to raise_error(ArgumentError)
55
+ end
56
+ end
57
+
44
58
  describe "self.update" do
45
59
  it "raises an exception if hash includes an invalid key" do
46
60
  expect do
@@ -22,6 +22,26 @@ describe Braintree::Subscription do
22
22
  end
23
23
  end
24
24
 
25
+ describe "self.find" do
26
+ it "raises error if passed empty string" do
27
+ expect do
28
+ Braintree::Subscription.find("")
29
+ end.to raise_error(ArgumentError)
30
+ end
31
+
32
+ it "raises error if passed empty string wth space" do
33
+ expect do
34
+ Braintree::Subscription.find(" ")
35
+ end.to raise_error(ArgumentError)
36
+ end
37
+
38
+ it "raises error if passed nil" do
39
+ expect do
40
+ Braintree::Subscription.find(nil)
41
+ end.to raise_error(ArgumentError)
42
+ end
43
+ end
44
+
25
45
  describe "self.search" do
26
46
  it "only allows specified values for status" do
27
47
  lambda do
@@ -25,6 +25,26 @@ describe Braintree::Transaction do
25
25
  end
26
26
  end
27
27
 
28
+ describe "self.find" do
29
+ it "raises error if passed empty string" do
30
+ expect do
31
+ Braintree::Transaction.find("")
32
+ end.to raise_error(ArgumentError)
33
+ end
34
+
35
+ it "raises error if passed empty string wth space" do
36
+ expect do
37
+ Braintree::Transaction.find(" ")
38
+ end.to raise_error(ArgumentError)
39
+ end
40
+
41
+ it "raises error if passed nil" do
42
+ expect do
43
+ Braintree::Transaction.find(nil)
44
+ end.to raise_error(ArgumentError)
45
+ end
46
+ end
47
+
28
48
  describe "self.create_transaction_url" do
29
49
  it "returns the url" do
30
50
  port = Braintree::Configuration.instantiate.port
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: 63
5
- prerelease:
4
+ hash: 59
5
+ prerelease: false
6
6
  segments:
7
7
  - 2
8
- - 12
8
+ - 13
9
9
  - 0
10
- version: 2.12.0
10
+ version: 2.13.0
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-10-06 00:00:00 -05:00
18
+ date: 2011-11-03 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -154,6 +154,7 @@ files:
154
154
  - lib/ssl/sandbox_braintreegateway_com.ca.crt
155
155
  - lib/ssl/securetrust_ca.crt
156
156
  - lib/ssl/www_braintreegateway_com.ca.crt
157
+ - braintree.gemspec
157
158
  has_rdoc: true
158
159
  homepage: http://www.braintreepayments.com/
159
160
  licenses: []
@@ -184,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
185
  requirements: []
185
186
 
186
187
  rubyforge_project: braintree
187
- rubygems_version: 1.6.2
188
+ rubygems_version: 1.3.7
188
189
  signing_key:
189
190
  specification_version: 3
190
191
  summary: Braintree Gateway Ruby Client Library