braintree 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -192,7 +192,7 @@ module Braintree
192
192
 
193
193
  def self._create_signature # :nodoc:
194
194
  [
195
- :customer_id, :cardholder_name, :cvv, :number, :expiration_date, :token,
195
+ :customer_id, :cardholder_name, :cvv, :number, :expiration_date, :expiration_month, :expiration_year, :token,
196
196
  {:options => [:verify_card]},
197
197
  {:billing_address => [:first_name, :last_name, :company, :country_name, :extended_address, :locality, :region, :postal_code, :street_address]}
198
198
  ]
@@ -226,7 +226,7 @@ module Braintree
226
226
 
227
227
  def self._update_signature # :nodoc:
228
228
  [
229
- :cardholder_name, :cvv, :number, :expiration_date, :token,
229
+ :cardholder_name, :cvv, :number, :expiration_date, :expiration_month, :expiration_year, :token,
230
230
  {:options => [:verify_card]},
231
231
  {:billing_address => [:first_name, :last_name, :company, :country_name, :extended_address, :locality, :region, :postal_code, :street_address]}
232
232
  ]
@@ -79,6 +79,8 @@ 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)
83
+ raise ArgumentError, "customer_id cannot be blank" if customer_id.to_s == ""
82
84
  response = Http.get("/customers/#{customer_id}")
83
85
  new(response[:customer])
84
86
  rescue NotFoundError
@@ -79,6 +79,7 @@ module Braintree
79
79
  AmountCannotBeNegative = "81501"
80
80
  AmountIsRequired = "81502"
81
81
  AmountIsInvalid = "81503"
82
+ AmountIsTooLarge = "81528"
82
83
  CannotBeVoided = "91504"
83
84
  CannotRefundCredit = "91505"
84
85
  CannotRefundUnlessSettled = "91506"
@@ -1,10 +1,16 @@
1
1
  module Braintree
2
2
  # Provides access to errors from an ErrorResult.
3
3
  class Errors
4
+ include Enumerable
5
+
4
6
  def initialize(data = {}) # :nodoc:
5
7
  @errors = ValidationErrorCollection.new(data.merge(:errors => []))
6
8
  end
7
9
 
10
+ def each(&block)
11
+ @errors.deep_errors.each(&block)
12
+ end
13
+
8
14
  # Accesses validation errors for the given +scope+.
9
15
  def for(scope)
10
16
  @errors.for(scope)
@@ -127,9 +127,12 @@ module Braintree
127
127
  attr_reader :avs_error_response_code, :avs_postal_code_response_code, :avs_street_address_response_code
128
128
  attr_reader :amount, :created_at, :credit_card_details, :customer_details, :id, :status
129
129
  attr_reader :custom_fields
130
+ attr_reader :cvv_response_code
130
131
  attr_reader :order_id
131
132
  attr_reader :billing_details, :shipping_details
132
133
  attr_reader :status_history
134
+ # The authorization code from the processor.
135
+ attr_reader :processor_authorization_code
133
136
  # The response code from the processor.
134
137
  attr_reader :processor_response_code
135
138
  # The response text from the processor.
@@ -245,7 +248,7 @@ module Braintree
245
248
  nice_attributes = order.map do |attr|
246
249
  if attr == :amount
247
250
  self.amount ? "amount: #{self.amount.to_s("F").inspect}" : "amount: nil"
248
- else
251
+ else
249
252
  "#{attr}: #{send(attr).inspect}"
250
253
  end
251
254
  end
@@ -381,7 +384,7 @@ module Braintree
381
384
  def self._create_signature # :nodoc:
382
385
  [
383
386
  :amount, :customer_id, :order_id, :payment_method_token, :type,
384
- {:credit_card => [:token, :cvv, :expiration_date, :number]},
387
+ {:credit_card => [:token, :cvv, :expiration_date, :expiration_month, :expiration_year, :number]},
385
388
  {:customer => [:id, :company, :email, :fax, :first_name, :last_name, :phone, :website]},
386
389
  {:billing => [:first_name, :last_name, :company, :country_name, :extended_address, :locality, :postal_code, :region, :street_address]},
387
390
  {:shipping => [:first_name, :last_name, :company, :country_name, :extended_address, :locality, :postal_code, :region, :street_address]},
@@ -35,7 +35,11 @@ module Braintree
35
35
  @errors[index]
36
36
  end
37
37
 
38
- def deep_size # :nodoc:
38
+ def deep_errors
39
+ ([@errors] + @nested.values.map { |error_collection| error_collection.deep_errors }).flatten
40
+ end
41
+
42
+ def deep_size
39
43
  size + @nested.values.inject(0) { |count, error_collection| count + error_collection.deep_size }
40
44
  end
41
45
 
@@ -2,7 +2,7 @@ module Braintree
2
2
  module Version
3
3
  Major = 1
4
4
  Minor = 1
5
- Tiny = 1
5
+ Tiny = 2
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Tiny}"
8
8
  end
@@ -25,6 +25,21 @@ describe Braintree::CreditCard do
25
25
  credit_card.expiration_date.should == "05/2009"
26
26
  end
27
27
 
28
+ it "can provide expiration month and year separately" do
29
+ customer = Braintree::Customer.create!
30
+ result = Braintree::CreditCard.create(
31
+ :customer_id => customer.id,
32
+ :number => Braintree::Test::CreditCardNumbers::Visa,
33
+ :expiration_month => "05",
34
+ :expiration_year => "2012"
35
+ )
36
+ result.success?.should == true
37
+ credit_card = result.credit_card
38
+ credit_card.expiration_month.should == "05"
39
+ credit_card.expiration_year.should == "2012"
40
+ credit_card.expiration_date.should == "05/2012"
41
+ end
42
+
28
43
  it "can specify the desired token" do
29
44
  token = "token_#{rand(1_000_000)}"
30
45
  customer = Braintree::Customer.create!
@@ -254,6 +269,25 @@ describe Braintree::CreditCard do
254
269
  updated_credit_card.cardholder_name.should == "New Holder"
255
270
  end
256
271
 
272
+ it "can pass expiration_month and expiration_year" do
273
+ customer = Braintree::Customer.create!
274
+ credit_card = Braintree::CreditCard.create!(
275
+ :customer_id => customer.id,
276
+ :number => Braintree::Test::CreditCardNumbers::Visa,
277
+ :expiration_date => "05/2012"
278
+ )
279
+ update_result = Braintree::CreditCard.update(credit_card.token,
280
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
281
+ :expiration_month => "07",
282
+ :expiration_year => "2011"
283
+ )
284
+ update_result.success?.should == true
285
+ update_result.credit_card.should == credit_card
286
+ update_result.credit_card.expiration_month.should == "07"
287
+ update_result.credit_card.expiration_year.should == "2011"
288
+ update_result.credit_card.expiration_date.should == "07/2011"
289
+ end
290
+
257
291
  it "verifies the update if options[verify_card]=true" do
258
292
  customer = Braintree::Customer.create!
259
293
  credit_card = Braintree::CreditCard.create!(
@@ -61,6 +61,18 @@ describe Braintree::Customer do
61
61
  result.success?.should == true
62
62
  end
63
63
 
64
+ it "supports utf-8" do
65
+ first_name = "Jos\303\251"
66
+ last_name = "Mu\303\261oz"
67
+ result = Braintree::Customer.create(:first_name => first_name, :last_name => last_name)
68
+ result.success?.should == true
69
+ result.customer.first_name.should == first_name
70
+ result.customer.last_name.should == last_name
71
+ found_customer = Braintree::Customer.find(result.customer.id)
72
+ found_customer.first_name.should == first_name
73
+ found_customer.last_name.should == last_name
74
+ end
75
+
64
76
  it "returns an error response if invalid" do
65
77
  result = Braintree::Customer.create(
66
78
  :email => "@invalid.com"
@@ -477,6 +489,24 @@ describe Braintree::Customer do
477
489
  customer.last_name.should == "Cool"
478
490
  end
479
491
 
492
+ it "works for a blank customer" do
493
+ created_customer = Braintree::Customer.create!
494
+ found_customer = Braintree::Customer.find(created_customer.id)
495
+ found_customer.id.should == created_customer.id
496
+ end
497
+
498
+ it "raises an ArgumentError if customer_id is not a string" do
499
+ expect do
500
+ Braintree::Customer.find(Object.new)
501
+ end.to raise_error(ArgumentError, "customer_id should be a string")
502
+ end
503
+
504
+ it "raises an ArgumentError if customer_id is blank" do
505
+ expect do
506
+ Braintree::Customer.find("")
507
+ end.to raise_error(ArgumentError, "customer_id cannot be blank")
508
+ end
509
+
480
510
  it "raises a NotFoundError exception if customer cannot be found" do
481
511
  expect do
482
512
  Braintree::Customer.find("invalid-id")
@@ -15,6 +15,7 @@ describe Braintree::Transaction do
15
15
  result.transaction.id.should =~ /^\w{6}$/
16
16
  result.transaction.type.should == "sale"
17
17
  result.transaction.amount.should == BigDecimal.new(Braintree::Test::TransactionAmounts::Authorize)
18
+ result.transaction.processor_authorization_code.should_not be_nil
18
19
  result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
19
20
  result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
20
21
  result.transaction.credit_card_details.expiration_date.should == "05/2009"
@@ -38,6 +39,32 @@ describe Braintree::Transaction do
38
39
  result.transaction.processor_response_text.should == "Do Not Honor"
39
40
  end
40
41
 
42
+ it "accepts credit card expiration month and expiration year" do
43
+ result = Braintree::Transaction.create(
44
+ :type => "sale",
45
+ :amount => Braintree::Test::TransactionAmounts::Decline,
46
+ :credit_card => {
47
+ :number => Braintree::Test::CreditCardNumbers::Visa,
48
+ :expiration_month => "05",
49
+ :expiration_year => "2011"
50
+ }
51
+ )
52
+ result.success?.should == true
53
+ result.transaction.credit_card_details.expiration_month.should == "05"
54
+ result.transaction.credit_card_details.expiration_year.should == "2011"
55
+ result.transaction.credit_card_details.expiration_date.should == "05/2011"
56
+ end
57
+
58
+ it "returns some error if customer_id is invalid" do
59
+ result = Braintree::Transaction.create(
60
+ :type => "sale",
61
+ :amount => Braintree::Test::TransactionAmounts::Decline,
62
+ :customer_id => 123456789
63
+ )
64
+ result.success?.should == false
65
+ result.errors.for(:transaction).on(:customer_id)[0].code.should == "91510"
66
+ end
67
+
41
68
  it "can create custom fields" do
42
69
  result = Braintree::Transaction.create(
43
70
  :type => "sale",
@@ -192,7 +219,7 @@ describe Braintree::Transaction do
192
219
  transaction.credit_card_details.expiration_date.should == "05/2009"
193
220
  end
194
221
 
195
- it "raises a ValidationsFailed if invalid" do
222
+ it "raises a validationsfailed if invalid" do
196
223
  expect do
197
224
  Braintree::Transaction.create!(
198
225
  :type => "sale",
@@ -282,6 +309,7 @@ describe Braintree::Transaction do
282
309
  transaction.avs_error_response_code.should == nil
283
310
  transaction.avs_postal_code_response_code.should == "M"
284
311
  transaction.avs_street_address_response_code.should == "M"
312
+ transaction.cvv_response_code.should == "M"
285
313
  transaction.customer_details.first_name.should == "Dan"
286
314
  transaction.customer_details.last_name.should == "Smith"
287
315
  transaction.customer_details.company.should == "Braintree Payment Solutions"
@@ -745,8 +773,8 @@ describe Braintree::Transaction do
745
773
  transaction.amount.should == BigDecimal.new("100.00")
746
774
  transaction.order_id.should == "123"
747
775
  transaction.processor_response_code.should == "1000"
748
- transaction.created_at.between?(Time.now - 5, Time.now).should == true
749
- transaction.updated_at.between?(Time.now - 5, Time.now).should == true
776
+ transaction.created_at.between?(Time.now - 60, Time.now).should == true
777
+ transaction.updated_at.between?(Time.now - 60, Time.now).should == true
750
778
  transaction.credit_card_details.bin.should == "510510"
751
779
  transaction.credit_card_details.last_4.should == "5100"
752
780
  transaction.credit_card_details.masked_number.should == "510510******5100"
@@ -754,6 +782,7 @@ describe Braintree::Transaction do
754
782
  transaction.avs_error_response_code.should == nil
755
783
  transaction.avs_postal_code_response_code.should == "M"
756
784
  transaction.avs_street_address_response_code.should == "M"
785
+ transaction.cvv_response_code.should == "M"
757
786
  transaction.customer_details.first_name.should == "Dan"
758
787
  transaction.customer_details.last_name.should == "Smith"
759
788
  transaction.customer_details.company.should == "Braintree Payment Solutions"
@@ -7,7 +7,6 @@ unless defined?(INTEGRATION_SPEC_HELPER_LOADED)
7
7
  Spec::Runner.configure do |config|
8
8
  CLIENT_LIB_ROOT = File.expand_path(File.dirname(__FILE__) + "/../..")
9
9
  GATEWAY_ROOT = File.expand_path("#{CLIENT_LIB_ROOT}/../gateway")
10
- GATEWAY_SERVER_PORT = 3000
11
10
  GATEWAY_PID_FILE = "/tmp/gateway_server_#{Braintree::Configuration.port}.pid"
12
11
  SPHINX_PID_FILE = "#{GATEWAY_ROOT}/log/searchd.integration.pid"
13
12
 
@@ -25,7 +25,8 @@ describe Braintree::Configuration do
25
25
  describe "self.base_merchant_url" do
26
26
  it "returns the expected url for the development env" do
27
27
  Braintree::Configuration.environment = :development
28
- Braintree::Configuration.base_merchant_url.should == "http://localhost:3000/merchants/integration_merchant_id"
28
+ port = Braintree::Configuration.port
29
+ Braintree::Configuration.base_merchant_url.should == "http://localhost:#{port}/merchants/integration_merchant_id"
29
30
  end
30
31
 
31
32
  it "returns the expected url for the sandbox env" do
@@ -129,9 +130,18 @@ describe Braintree::Configuration do
129
130
  Braintree::Configuration.port.should == 443
130
131
  end
131
132
 
132
- it "is 3000 for development" do
133
+ it "is 3000 or GATEWAY_PORT environment variable for development" do
133
134
  Braintree::Configuration.environment = :development
134
- Braintree::Configuration.port.should == 3000
135
+ old_gateway_port = ENV['GATEWAY_PORT']
136
+ begin
137
+ ENV['GATEWAY_PORT'] = nil
138
+ Braintree::Configuration.port.should == 3000
139
+
140
+ ENV['GATEWAY_PORT'] = '1234'
141
+ Braintree::Configuration.port.should == '1234'
142
+ ensure
143
+ ENV['GATEWAY_PORT'] = old_gateway_port
144
+ end
135
145
  end
136
146
  end
137
147
 
@@ -19,7 +19,8 @@ describe Braintree::CreditCard do
19
19
 
20
20
  describe "self.create_credit_card_url" do
21
21
  it "returns the url" do
22
- Braintree::CreditCard.create_credit_card_url.should == "http://localhost:3000/merchants/integration_merchant_id/payment_methods/all/create_via_transparent_redirect_request"
22
+ port = Braintree::Configuration.port
23
+ Braintree::CreditCard.create_credit_card_url.should == "http://localhost:#{port}/merchants/integration_merchant_id/payment_methods/all/create_via_transparent_redirect_request"
23
24
  end
24
25
  end
25
26
 
@@ -54,6 +54,23 @@ describe Braintree::Errors do
54
54
  end
55
55
  end
56
56
 
57
+ describe "each" do
58
+ it "yields errors at all levels" do
59
+ errors = Braintree::Errors.new(
60
+ :level1 => {
61
+ :errors => [{:code => "1", :attribute => "attr", :message => "message"}],
62
+ :level2 => {
63
+ :errors => [
64
+ {:code => "2", :attribute => "attr2", :message => "message2"},
65
+ {:code => "3", :attribute => "attr3", :message => "message3"}
66
+ ],
67
+ }
68
+ }
69
+ )
70
+ errors.map { |e| e.code }.sort.should == %w[1 2 3]
71
+ end
72
+ end
73
+
57
74
  describe "size" do
58
75
  it "returns the number of validation errors at the first level if only has one level" do
59
76
  errors = Braintree::Errors.new(
@@ -19,7 +19,8 @@ describe Braintree::Transaction do
19
19
 
20
20
  describe "self.create_transaction_url" do
21
21
  it "returns the url" do
22
- Braintree::Transaction.create_transaction_url.should == "http://localhost:3000/merchants/integration_merchant_id/transactions/all/create_via_transparent_redirect_request"
22
+ port = Braintree::Configuration.port
23
+ Braintree::Transaction.create_transaction_url.should == "http://localhost:#{port}/merchants/integration_merchant_id/transactions/all/create_via_transparent_redirect_request"
23
24
  end
24
25
  end
25
26
 
@@ -125,4 +125,24 @@ describe Braintree::ValidationErrorCollection do
125
125
  end
126
126
  end
127
127
 
128
+ describe "deep_errors" do
129
+ it "returns errors from all levels" do
130
+ errors = Braintree::ValidationErrorCollection.new(
131
+ :errors => [
132
+ { :attribute => "one", :code => 1, :message => "bad juju" },
133
+ { :attribute => "two", :code => 2, :message => "bad juju" }],
134
+ :nested => {
135
+ :errors => [{ :attribute => "three", :code => 3, :message => "badder juju"}],
136
+ :nested_again => {
137
+ :errors => [{ :attribute => "four", :code => 4, :message => "badder juju"}]
138
+ }
139
+ },
140
+ :same_level => {
141
+ :errors => [{ :attribute => "five", :code => 5, :message => "badder juju"}],
142
+ }
143
+ )
144
+ errors.deep_errors.map { |e| e.code }.sort.should == [1, 2, 3, 4, 5]
145
+ end
146
+ end
147
+
128
148
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: braintree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Braintree Payment Solutions
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-26 00:00:00 -06:00
12
+ date: 2010-03-19 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15