braintree 2.13.1 → 2.13.2

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.
@@ -188,6 +188,7 @@ module Braintree
188
188
  ProcessorDoesNotSupportCredits = "91546"
189
189
  ProcessorDoesNotSupportVoiceAuthorizations = "91545"
190
190
  PurchaseOrderNumberIsTooLong = "91537"
191
+ PurchaseOrderNumberIsInvalid = "91548"
191
192
  RefundAmountIsTooLarge = "91521"
192
193
  SettlementAmountIsTooLarge = "91522"
193
194
  SubscriptionDoesNotBelongToCustomer = "91529"
@@ -39,7 +39,7 @@ module Braintree
39
39
 
40
40
  def parse_and_validate_query_string(query_string) # :nodoc:
41
41
  params = Util.symbolize_keys(Util.parse_query_string(query_string))
42
- query_string_without_hash = query_string[/(.*)&hash=.*/, 1]
42
+ query_string_without_hash = query_string.split("&").reject{|param| param =~ /\Ahash=/}.join("&")
43
43
 
44
44
  if params[:http_status] == nil
45
45
  raise UnexpectedError, "expected query string to have an http_status param"
@@ -2,7 +2,7 @@ module Braintree
2
2
  module Version
3
3
  Major = 2
4
4
  Minor = 13
5
- Tiny = 1
5
+ Tiny = 2
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Tiny}"
8
8
  end
@@ -713,19 +713,45 @@ describe Braintree::Transaction do
713
713
  result.transaction.purchase_order_number.should be_nil
714
714
  end
715
715
 
716
- it "has validation errors" do
717
- result = Braintree::Transaction.sale(
718
- :amount => Braintree::Test::TransactionAmounts::Authorize,
719
- :credit_card => {
716
+ context "validations" do
717
+ it "tax_amount" do
718
+ result = Braintree::Transaction.sale(
719
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
720
+ :credit_card => {
720
721
  :number => Braintree::Test::CreditCardNumbers::Visa,
721
722
  :expiration_date => "05/2009"
722
723
  },
723
- :tax_amount => 'abcd',
724
- :purchase_order_number => 'a' * 18
725
- )
726
- result.success?.should == false
727
- result.errors.for(:transaction).on(:tax_amount)[0].code.should == Braintree::ErrorCodes::Transaction::TaxAmountFormatIsInvalid
728
- result.errors.for(:transaction).on(:purchase_order_number)[0].code.should == Braintree::ErrorCodes::Transaction::PurchaseOrderNumberIsTooLong
724
+ :tax_amount => 'abcd'
725
+ )
726
+ result.success?.should == false
727
+ result.errors.for(:transaction).on(:tax_amount)[0].code.should == Braintree::ErrorCodes::Transaction::TaxAmountFormatIsInvalid
728
+ end
729
+
730
+ it "purchase_order_number length" do
731
+ result = Braintree::Transaction.sale(
732
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
733
+ :credit_card => {
734
+ :number => Braintree::Test::CreditCardNumbers::Visa,
735
+ :expiration_date => "05/2009"
736
+ },
737
+ :purchase_order_number => 'a' * 18
738
+ )
739
+ result.success?.should == false
740
+ result.errors.for(:transaction).on(:purchase_order_number)[0].code.should == Braintree::ErrorCodes::Transaction::PurchaseOrderNumberIsTooLong
741
+ end
742
+
743
+ it "purchase_order_number format" do
744
+ result = Braintree::Transaction.sale(
745
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
746
+ :credit_card => {
747
+ :number => Braintree::Test::CreditCardNumbers::Visa,
748
+ :expiration_date => "05/2009"
749
+ },
750
+ :purchase_order_number => "\303\237\303\245\342\210\202"
751
+ )
752
+ result.success?.should == false
753
+ result.errors.for(:transaction).on(:purchase_order_number)[0].code.should == Braintree::ErrorCodes::Transaction::PurchaseOrderNumberIsInvalid
754
+ end
729
755
  end
730
756
  end
731
757
 
@@ -31,6 +31,24 @@ describe Braintree::TransparentRedirect do
31
31
  result.should == {:one => "1", :two => "2", :http_status => "200", :hash => hash}
32
32
  end
33
33
 
34
+ it "returns the parsed query string params if the hash is valid and hash is first parameter" do
35
+ query_string_without_hash = "one=1&two=2&http_status=200"
36
+ hash = Braintree::Digest.hexdigest(Braintree::Configuration.private_key, query_string_without_hash)
37
+
38
+ query_string_with_hash = "hash=#{hash}&#{query_string_without_hash}"
39
+ result = Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string query_string_with_hash
40
+ result.should == {:one => "1", :two => "2", :http_status => "200", :hash => hash}
41
+ end
42
+
43
+ it "returns the parsed query string params regardless of hash position if the hash is valid" do
44
+ query_string_without_hash = "one=1&two=2&http_status=200"
45
+ hash = Braintree::Digest.hexdigest(Braintree::Configuration.private_key, query_string_without_hash)
46
+
47
+ query_string_with_hash = "one=1&hash=#{hash}&two=2&http_status=200"
48
+ result = Braintree::Configuration.gateway.transparent_redirect.parse_and_validate_query_string query_string_with_hash
49
+ result.should == {:one => "1", :two => "2", :http_status => "200", :hash => hash}
50
+ end
51
+
34
52
  it "raises Braintree::ForgedQueryString if the hash param is not valid" do
35
53
  query_string_without_hash = "http_status=200&one=1&two=2"
36
54
  hash = Digest::SHA1.hexdigest("invalid#{query_string_without_hash}")
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: 57
5
- prerelease:
4
+ hash: 63
5
+ prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 13
9
- - 1
10
- version: 2.13.1
9
+ - 2
10
+ version: 2.13.2
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-11-16 00:00:00 -06:00
18
+ date: 2012-01-03 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  requirements: []
186
186
 
187
187
  rubyforge_project: braintree
188
- rubygems_version: 1.4.2
188
+ rubygems_version: 1.3.7
189
189
  signing_key:
190
190
  specification_version: 3
191
191
  summary: Braintree Gateway Ruby Client Library