braintree 1.0.0

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.
Files changed (65) hide show
  1. data/LICENSE +22 -0
  2. data/README.rdoc +62 -0
  3. data/lib/braintree.rb +66 -0
  4. data/lib/braintree/address.rb +122 -0
  5. data/lib/braintree/base_module.rb +29 -0
  6. data/lib/braintree/configuration.rb +99 -0
  7. data/lib/braintree/credit_card.rb +231 -0
  8. data/lib/braintree/credit_card_verification.rb +31 -0
  9. data/lib/braintree/customer.rb +231 -0
  10. data/lib/braintree/digest.rb +20 -0
  11. data/lib/braintree/error_codes.rb +95 -0
  12. data/lib/braintree/error_result.rb +39 -0
  13. data/lib/braintree/errors.rb +29 -0
  14. data/lib/braintree/http.rb +105 -0
  15. data/lib/braintree/paged_collection.rb +55 -0
  16. data/lib/braintree/ssl_expiration_check.rb +28 -0
  17. data/lib/braintree/successful_result.rb +38 -0
  18. data/lib/braintree/test/credit_card_numbers.rb +50 -0
  19. data/lib/braintree/test/transaction_amounts.rb +10 -0
  20. data/lib/braintree/transaction.rb +360 -0
  21. data/lib/braintree/transaction/address_details.rb +15 -0
  22. data/lib/braintree/transaction/credit_card_details.rb +22 -0
  23. data/lib/braintree/transaction/customer_details.rb +13 -0
  24. data/lib/braintree/transparent_redirect.rb +110 -0
  25. data/lib/braintree/util.rb +94 -0
  26. data/lib/braintree/validation_error.rb +15 -0
  27. data/lib/braintree/validation_error_collection.rb +80 -0
  28. data/lib/braintree/version.rb +9 -0
  29. data/lib/braintree/xml.rb +12 -0
  30. data/lib/braintree/xml/generator.rb +80 -0
  31. data/lib/braintree/xml/libxml.rb +69 -0
  32. data/lib/braintree/xml/parser.rb +93 -0
  33. data/lib/ssl/securetrust_ca.crt +44 -0
  34. data/lib/ssl/valicert_ca.crt +18 -0
  35. data/spec/integration/braintree/address_spec.rb +352 -0
  36. data/spec/integration/braintree/credit_card_spec.rb +676 -0
  37. data/spec/integration/braintree/customer_spec.rb +664 -0
  38. data/spec/integration/braintree/http_spec.rb +201 -0
  39. data/spec/integration/braintree/test/transaction_amounts_spec.rb +29 -0
  40. data/spec/integration/braintree/transaction_spec.rb +900 -0
  41. data/spec/integration/spec_helper.rb +38 -0
  42. data/spec/script/httpsd.rb +27 -0
  43. data/spec/spec_helper.rb +41 -0
  44. data/spec/unit/braintree/address_spec.rb +86 -0
  45. data/spec/unit/braintree/configuration_spec.rb +190 -0
  46. data/spec/unit/braintree/credit_card_spec.rb +137 -0
  47. data/spec/unit/braintree/credit_card_verification_spec.rb +17 -0
  48. data/spec/unit/braintree/customer_spec.rb +103 -0
  49. data/spec/unit/braintree/digest_spec.rb +28 -0
  50. data/spec/unit/braintree/error_result_spec.rb +42 -0
  51. data/spec/unit/braintree/errors_spec.rb +81 -0
  52. data/spec/unit/braintree/http_spec.rb +42 -0
  53. data/spec/unit/braintree/paged_collection_spec.rb +128 -0
  54. data/spec/unit/braintree/ssl_expiration_check_spec.rb +92 -0
  55. data/spec/unit/braintree/successful_result_spec.rb +27 -0
  56. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +22 -0
  57. data/spec/unit/braintree/transaction_spec.rb +136 -0
  58. data/spec/unit/braintree/transparent_redirect_spec.rb +154 -0
  59. data/spec/unit/braintree/util_spec.rb +142 -0
  60. data/spec/unit/braintree/validation_error_collection_spec.rb +128 -0
  61. data/spec/unit/braintree/validation_error_spec.rb +19 -0
  62. data/spec/unit/braintree/xml/libxml_spec.rb +51 -0
  63. data/spec/unit/braintree/xml_spec.rb +122 -0
  64. data/spec/unit/spec_helper.rb +1 -0
  65. metadata +118 -0
@@ -0,0 +1,128 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Braintree::ValidationErrorCollection do
4
+
5
+ describe "initialize" do
6
+ it "builds an error object given an array of hashes" do
7
+ hash = {:errors => [{ :attribute => "some model attribute", :code => 1, :message => "bad juju" }]}
8
+ collection = Braintree::ValidationErrorCollection.new(hash)
9
+ error = collection[0]
10
+ error.attribute.should == "some model attribute"
11
+ error.code.should == 1
12
+ error.message.should == "bad juju"
13
+ end
14
+ end
15
+
16
+ describe "for" do
17
+ it "provides access to nested errors" do
18
+ hash = {
19
+ :errors => [{ :attribute => "some model attribute", :code => 1, :message => "bad juju" }],
20
+ :nested => {
21
+ :errors => [{ :attribute => "number", :code => 2, :message => "badder juju"}]
22
+ }
23
+ }
24
+ errors = Braintree::ValidationErrorCollection.new(hash)
25
+ errors.for(:nested).on(:number)[0].code.should == 2
26
+ errors.for(:nested).on(:number)[0].message.should == "badder juju"
27
+ errors.for(:nested).on(:number)[0].attribute.should == "number"
28
+ end
29
+ end
30
+
31
+ describe "inspect" do
32
+ it "shows the errors at the current level" do
33
+ errors = Braintree::ValidationErrorCollection.new(:errors => [
34
+ {:attribute => "name", :code => "code1", :message => "message1"},
35
+ {:attribute => "name", :code => "code2", :message => "message2"}
36
+ ])
37
+ errors.inspect.should == "#<Braintree::ValidationErrorCollection errors:[(code1) message1, (code2) message2]>"
38
+ end
39
+
40
+ it "shows errors 1 level deep" do
41
+ errors = Braintree::ValidationErrorCollection.new(
42
+ :errors => [
43
+ {:attribute => "name", :code => "code1", :message => "message1"},
44
+ ],
45
+ :level1 => {
46
+ :errors => [{:attribute => "name", :code => "code2", :message => "message2"}]
47
+ }
48
+ )
49
+ errors.inspect.should == "#<Braintree::ValidationErrorCollection errors:[(code1) message1], level1:[(code2) message2]>"
50
+ end
51
+
52
+ it "shows errors 2 levels deep" do
53
+ errors = Braintree::ValidationErrorCollection.new(
54
+ :errors => [
55
+ {:attribute => "name", :code => "code1", :message => "message1"},
56
+ ],
57
+ :level1 => {
58
+ :errors => [{:attribute => "name", :code => "code2", :message => "message2"}],
59
+ :level2 => {
60
+ :errors => [{:attribute => "name", :code => "code3", :message => "message3"}],
61
+ }
62
+ }
63
+ )
64
+ errors.inspect.should == "#<Braintree::ValidationErrorCollection errors:[(code1) message1], level1:[(code2) message2], level1/level2:[(code3) message3]>"
65
+ end
66
+ end
67
+
68
+ describe "on" do
69
+ it "returns an array of errors on the given attribute" do
70
+ errors = Braintree::ValidationErrorCollection.new(:errors => [
71
+ {:attribute => "name", :code => 1, :message => "is too long"},
72
+ {:attribute => "name", :code => 2, :message => "contains invalid chars"},
73
+ {:attribute => "not name", :code => 3, :message => "is invalid"}
74
+ ])
75
+ errors.on("name").size.should == 2
76
+ errors.on("name").map{ |e| e.code }.should == [1, 2]
77
+ end
78
+
79
+ it "has indifferent access" do
80
+ errors = Braintree::ValidationErrorCollection.new(:errors => [
81
+ { :attribute => "name", :code => 3, :message => "is too long" },
82
+ ])
83
+ errors.on(:name).size.should == 1
84
+ errors.on(:name)[0].code.should == 3
85
+
86
+ end
87
+ end
88
+
89
+ describe "deep_size" do
90
+ it "returns the size for a non-nested collection" do
91
+ errors = Braintree::ValidationErrorCollection.new(:errors => [
92
+ {:attribute => "one", :code => 1, :message => "is too long"},
93
+ {:attribute => "two", :code => 2, :message => "contains invalid chars"},
94
+ {:attribute => "thr", :code => 3, :message => "is invalid"}
95
+ ])
96
+ errors.deep_size.should == 3
97
+ end
98
+
99
+ it "returns the size of nested errors as well" do
100
+ errors = Braintree::ValidationErrorCollection.new(
101
+ :errors => [{ :attribute => "some model attribute", :code => 1, :message => "bad juju" }],
102
+ :nested => {
103
+ :errors => [{ :attribute => "number", :code => 2, :message => "badder juju"}]
104
+ }
105
+ )
106
+ errors.deep_size.should == 2
107
+ end
108
+
109
+ it "returns the size of multiple nestings of errors" do
110
+ errors = Braintree::ValidationErrorCollection.new(
111
+ :errors => [
112
+ { :attribute => "one", :code => 1, :message => "bad juju" },
113
+ { :attribute => "two", :code => 1, :message => "bad juju" }],
114
+ :nested => {
115
+ :errors => [{ :attribute => "three", :code => 2, :message => "badder juju"}],
116
+ :nested_again => {
117
+ :errors => [{ :attribute => "four", :code => 2, :message => "badder juju"}]
118
+ }
119
+ },
120
+ :same_level => {
121
+ :errors => [{ :attribute => "five", :code => 2, :message => "badder juju"}],
122
+ }
123
+ )
124
+ errors.deep_size.should == 5
125
+ end
126
+ end
127
+
128
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Braintree::ValidationError do
4
+ describe "initialize" do
5
+ it "works" do
6
+ error = Braintree::ValidationError.new :attribute => "some model attribute", :code => 1, :message => "bad juju"
7
+ error.attribute.should == "some model attribute"
8
+ error.code.should == 1
9
+ error.message.should == "bad juju"
10
+ end
11
+ end
12
+
13
+ describe "inspect" do
14
+ it "is pretty" do
15
+ error = Braintree::ValidationError.new :attribute => "number", :code => "123456", :message => "Number is bad juju."
16
+ error.inspect.should == "#<Braintree::ValidationError (123456) Number is bad juju.>"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+
3
+ describe Braintree::Xml::Libxml do
4
+ describe "self.parse" do
5
+ it "typecasts integers" do
6
+ xml = "<root><foo type=\"integer\">123</foo></root>"
7
+ Braintree::Xml::Libxml.parse(xml).should == {"root"=>{"foo"=>{"__content__"=>"123", "type"=>"integer"}}}
8
+ end
9
+
10
+ it "works with dashes or underscores" do
11
+ xml = <<-END
12
+ <root>
13
+ <dash-es />
14
+ <under_scores />
15
+ </root>
16
+ END
17
+ Braintree::Xml::Libxml.parse(xml).should == {"root"=>{"dash-es"=>{}, "under_scores"=>{}}}
18
+ end
19
+
20
+ it "uses nil if nil=true, otherwise uses empty string" do
21
+ xml = <<-END
22
+ <root>
23
+ <a_nil_value nil="true"></a_nil_value>
24
+ <an_empty_string></an_empty_string>
25
+ </root>
26
+ END
27
+ Braintree::Xml::Libxml.parse(xml).should == {"root"=>{"a_nil_value"=>{"nil"=>"true"}, "an_empty_string"=>{}}}
28
+ end
29
+
30
+ it "typecasts dates and times" do
31
+ xml = <<-END
32
+ <root>
33
+ <created-at type="datetime">2009-10-28T10:19:49Z</created-at>
34
+ </root>
35
+ END
36
+ Braintree::Xml::Libxml.parse(xml).should == {"root"=>{"created-at"=>{"__content__"=>"2009-10-28T10:19:49Z", "type"=>"datetime"}}}
37
+ end
38
+
39
+ it "builds an array if type=array" do
40
+ xml = <<-END
41
+ <root>
42
+ <customers type="array">
43
+ <customer><name>Adam</name></customer>
44
+ <customer><name>Ben</name></customer>
45
+ </customers>
46
+ </root>
47
+ END
48
+ Braintree::Xml::Libxml.parse(xml).should == {"root"=>{"customers"=>{"type"=>"array", "customer"=>[{"name"=>{"__content__"=>"Adam"}}, {"name"=>{"__content__"=>"Ben"}}]}}}
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,122 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Braintree::Xml do
4
+ describe "self.hash_from_xml" do
5
+ it "typecasts integers" do
6
+ hash = Braintree::Xml.hash_from_xml("<root><foo type=\"integer\">123</foo></root>")
7
+ hash.should == {:root => {:foo => 123}}
8
+ end
9
+
10
+ it "works with dashes or underscores" do
11
+ xml = <<-END
12
+ <root>
13
+ <dash-es />
14
+ <under_scores />
15
+ </root>
16
+ END
17
+
18
+ hash = Braintree::Xml.hash_from_xml(xml)
19
+ hash.should == {:root => {:dash_es => "", :under_scores => ""}}
20
+ end
21
+
22
+ it "uses nil if nil=true, otherwise uses empty string" do
23
+ xml = <<-END
24
+ <root>
25
+ <a_nil_value nil="true"></a_nil_value>
26
+ <an_empty_string></an_empty_string>
27
+ </root>
28
+ END
29
+ hash = Braintree::Xml.hash_from_xml(xml)
30
+ hash.should == {:root => {:a_nil_value => nil, :an_empty_string => ""}}
31
+ end
32
+
33
+ it "typecasts dates and times" do
34
+ hash = Braintree::Xml.hash_from_xml <<-END
35
+ <root>
36
+ <created-at type="datetime">2009-10-28T10:19:49Z</created-at>
37
+ </root>
38
+ END
39
+ hash.should == {:root => {:created_at => Time.utc(2009, 10, 28, 10, 19, 49)}}
40
+ end
41
+
42
+ it "builds an array if type=array" do
43
+ hash = Braintree::Xml.hash_from_xml <<-END
44
+ <root>
45
+ <customers type="array">
46
+ <customer><name>Adam</name></customer>
47
+ <customer><name>Ben</name></customer>
48
+ </customers>
49
+ </root>
50
+ END
51
+ hash.should == {:root => {:customers => [{:name => "Adam"}, {:name => "Ben"}]}}
52
+ end
53
+
54
+ it "turns 1 and true to boolean if type = boolean" do
55
+ hash = Braintree::Xml.hash_from_xml <<-END
56
+ <root>
57
+ <casted-true type="boolean">true</casted-true>
58
+ <casted-one type="boolean">1</casted-one>
59
+ <casted-false type="boolean">false</casted-false>
60
+ <casted-anything type="boolean">anything</casted-anything>
61
+ <uncasted-true>true</uncasted-true>
62
+ </root>
63
+ END
64
+ hash.should == {:root => {
65
+ :casted_true => true, :casted_one => true, :casted_anything => false, :casted_false => false,
66
+ :uncasted_true => "true"
67
+ }}
68
+ end
69
+
70
+ it "handles values that are arrays of hashes" do
71
+ hash = Braintree::Xml.hash_from_xml("
72
+ <container>
73
+ <elem><value>one</value></elem>
74
+ <elem><value>two</value></elem>
75
+ <elem><value>three</value></elem>
76
+ </container>
77
+ ")
78
+ hash.should == {:container => {:elem => [{:value => "one"}, {:value => "two"}, {:value => "three"}]}}
79
+ end
80
+ end
81
+
82
+ describe "self.hash_to_xml" do
83
+ def verify_to_xml_and_back(hash)
84
+ Braintree::Xml.hash_from_xml(Braintree::Xml.hash_to_xml(hash)).should == hash
85
+ end
86
+
87
+ it "works for a simple case" do
88
+ hash = {:root => {:foo => "foo_value", :bar => "bar_value"}}
89
+ verify_to_xml_and_back hash
90
+ end
91
+
92
+ it "works for arrays" do
93
+ hash = {:root => {:items => [{:name => "first"}, {:name => "second"}]}}
94
+ verify_to_xml_and_back hash
95
+ end
96
+
97
+ it "type casts booleans" do
98
+ hash = {:root => {:string_true => "true", :bool_true => true, :bool_false => false, :string_false => "false"}}
99
+ verify_to_xml_and_back hash
100
+ end
101
+
102
+ it "type casts time" do
103
+ hash = {:root => {:a_time => Time.utc(2009, 10, 28, 1, 2, 3), :a_string_that_looks_like_time => "2009-10-28T10:19:49Z"}}
104
+ verify_to_xml_and_back hash
105
+ end
106
+
107
+ it "can distinguish nil from empty string" do
108
+ hash = {:root => {:an_empty_string => "", :a_nil_value => nil}}
109
+ verify_to_xml_and_back hash
110
+ end
111
+
112
+ it "includes the encoding" do
113
+ xml = Braintree::Xml.hash_to_xml(:root => {:root => "bar"})
114
+ xml.should include("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
115
+ end
116
+
117
+ it "works for only a root node and a string" do
118
+ hash = {:id => "123"}
119
+ verify_to_xml_and_back hash
120
+ end
121
+ end
122
+ end
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: braintree
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Braintree Payment Solutions
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-18 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Ruby library for integrating with the Braintree Gateway
17
+ email: devs@getbraintree.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README.rdoc
26
+ - LICENSE
27
+ - lib/braintree/address.rb
28
+ - lib/braintree/base_module.rb
29
+ - lib/braintree/configuration.rb
30
+ - lib/braintree/credit_card.rb
31
+ - lib/braintree/credit_card_verification.rb
32
+ - lib/braintree/customer.rb
33
+ - lib/braintree/digest.rb
34
+ - lib/braintree/error_codes.rb
35
+ - lib/braintree/error_result.rb
36
+ - lib/braintree/errors.rb
37
+ - lib/braintree/http.rb
38
+ - lib/braintree/paged_collection.rb
39
+ - lib/braintree/ssl_expiration_check.rb
40
+ - lib/braintree/successful_result.rb
41
+ - lib/braintree/test/credit_card_numbers.rb
42
+ - lib/braintree/test/transaction_amounts.rb
43
+ - lib/braintree/transaction/address_details.rb
44
+ - lib/braintree/transaction/credit_card_details.rb
45
+ - lib/braintree/transaction/customer_details.rb
46
+ - lib/braintree/transaction.rb
47
+ - lib/braintree/transparent_redirect.rb
48
+ - lib/braintree/util.rb
49
+ - lib/braintree/validation_error.rb
50
+ - lib/braintree/validation_error_collection.rb
51
+ - lib/braintree/version.rb
52
+ - lib/braintree/xml/generator.rb
53
+ - lib/braintree/xml/libxml.rb
54
+ - lib/braintree/xml/parser.rb
55
+ - lib/braintree/xml.rb
56
+ - lib/braintree.rb
57
+ - spec/integration/braintree/address_spec.rb
58
+ - spec/integration/braintree/credit_card_spec.rb
59
+ - spec/integration/braintree/customer_spec.rb
60
+ - spec/integration/braintree/http_spec.rb
61
+ - spec/integration/braintree/test/transaction_amounts_spec.rb
62
+ - spec/integration/braintree/transaction_spec.rb
63
+ - spec/integration/spec_helper.rb
64
+ - spec/script/httpsd.rb
65
+ - spec/spec_helper.rb
66
+ - spec/unit/braintree/address_spec.rb
67
+ - spec/unit/braintree/configuration_spec.rb
68
+ - spec/unit/braintree/credit_card_spec.rb
69
+ - spec/unit/braintree/credit_card_verification_spec.rb
70
+ - spec/unit/braintree/customer_spec.rb
71
+ - spec/unit/braintree/digest_spec.rb
72
+ - spec/unit/braintree/error_result_spec.rb
73
+ - spec/unit/braintree/errors_spec.rb
74
+ - spec/unit/braintree/http_spec.rb
75
+ - spec/unit/braintree/paged_collection_spec.rb
76
+ - spec/unit/braintree/ssl_expiration_check_spec.rb
77
+ - spec/unit/braintree/successful_result_spec.rb
78
+ - spec/unit/braintree/transaction/credit_card_details_spec.rb
79
+ - spec/unit/braintree/transaction_spec.rb
80
+ - spec/unit/braintree/transparent_redirect_spec.rb
81
+ - spec/unit/braintree/util_spec.rb
82
+ - spec/unit/braintree/validation_error_collection_spec.rb
83
+ - spec/unit/braintree/validation_error_spec.rb
84
+ - spec/unit/braintree/xml/libxml_spec.rb
85
+ - spec/unit/braintree/xml_spec.rb
86
+ - spec/unit/spec_helper.rb
87
+ - lib/ssl/securetrust_ca.crt
88
+ - lib/ssl/valicert_ca.crt
89
+ has_rdoc: true
90
+ homepage: http://www.braintreepaymentsolutions.com/gateway
91
+ licenses: []
92
+
93
+ post_install_message:
94
+ rdoc_options: []
95
+
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ version:
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: "0"
109
+ version:
110
+ requirements: []
111
+
112
+ rubyforge_project: braintree
113
+ rubygems_version: 1.3.5
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Braintree Gateway Ruby Client Library
117
+ test_files: []
118
+