braintree 2.84.0 → 2.85.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/lib/braintree.rb +3 -0
  3. data/lib/braintree/advanced_search.rb +8 -0
  4. data/lib/braintree/credit_card_verification_gateway.rb +1 -1
  5. data/lib/braintree/error_codes.rb +6 -0
  6. data/lib/braintree/gateway.rb +4 -0
  7. data/lib/braintree/payment_method_gateway.rb +3 -1
  8. data/lib/braintree/us_bank_account.rb +8 -0
  9. data/lib/braintree/us_bank_account_verification.rb +75 -0
  10. data/lib/braintree/us_bank_account_verification_gateway.rb +32 -0
  11. data/lib/braintree/us_bank_account_verification_search.rb +19 -0
  12. data/lib/braintree/version.rb +1 -1
  13. data/lib/braintree/webhook_notification.rb +3 -0
  14. data/lib/braintree/webhook_testing_gateway.rb +10 -0
  15. data/spec/httpsd.pid +1 -1
  16. data/spec/integration/braintree/client_api/spec_helper.rb +33 -5
  17. data/spec/integration/braintree/credit_card_spec.rb +2 -2
  18. data/spec/integration/braintree/customer_spec.rb +9 -4
  19. data/spec/integration/braintree/dispute_search_spec.rb +14 -3
  20. data/spec/integration/braintree/payment_method_spec.rb +0 -35
  21. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +412 -0
  22. data/spec/integration/braintree/transaction_search_spec.rb +49 -51
  23. data/spec/integration/braintree/transaction_spec.rb +3 -93
  24. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +432 -0
  25. data/spec/integration/braintree/us_bank_account_spec.rb +36 -15
  26. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +178 -0
  27. data/spec/integration/braintree/us_bank_account_verification_spec.rb +79 -0
  28. data/spec/spec_helper.rb +2 -1
  29. data/spec/unit/braintree/us_bank_account_verification_search_spec.rb +60 -0
  30. data/spec/unit/braintree/us_bank_account_verification_spec.rb +67 -0
  31. data/spec/unit/braintree/webhook_notification_spec.rb +13 -0
  32. metadata +12 -3
@@ -5,20 +5,23 @@ describe Braintree::UsBankAccount do
5
5
  describe "self.find" do
6
6
  it "returns a UsBankAccount" do
7
7
  customer = Braintree::Customer.create!
8
- nonce = generate_valid_us_bank_account_nonce
8
+ nonce = generate_non_plaid_us_bank_account_nonce
9
9
 
10
10
  result = Braintree::PaymentMethod.create(
11
11
  :payment_method_nonce => nonce,
12
- :customer_id => customer.id
12
+ :customer_id => customer.id,
13
+ :options => {
14
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
15
+ }
13
16
  )
14
17
  result.should be_success
15
18
 
16
19
  us_bank_account = Braintree::UsBankAccount.find(result.payment_method.token)
17
20
  us_bank_account.should be_a(Braintree::UsBankAccount)
18
21
  us_bank_account.routing_number.should == "021000021"
19
- us_bank_account.last_4.should == "1234"
22
+ us_bank_account.last_4.should == "0000"
20
23
  us_bank_account.account_type.should == "checking"
21
- us_bank_account.account_holder_name.should == "Dan Schulman"
24
+ us_bank_account.account_holder_name.should == "John Doe"
22
25
  us_bank_account.bank_name.should =~ /CHASE/
23
26
  us_bank_account.ach_mandate.text.should == "cl mandate text"
24
27
  us_bank_account.ach_mandate.accepted_at.should be_a Time
@@ -34,24 +37,31 @@ describe Braintree::UsBankAccount do
34
37
  context "self.sale" do
35
38
  it "creates a transaction using a us bank account and returns a result object" do
36
39
  customer = Braintree::Customer.create!
37
- nonce = generate_valid_us_bank_account_nonce
40
+ nonce = generate_non_plaid_us_bank_account_nonce
38
41
 
39
42
  result = Braintree::PaymentMethod.create(
40
43
  :payment_method_nonce => nonce,
41
- :customer_id => customer.id
44
+ :customer_id => customer.id,
45
+ :options => {
46
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
47
+ }
42
48
  )
43
49
  result.should be_success
44
50
 
45
- result = Braintree::UsBankAccount.sale(result.payment_method.token, :merchant_account_id => "us_bank_merchant_account", :amount => "100.00")
51
+ result = Braintree::UsBankAccount.sale(
52
+ result.payment_method.token,
53
+ :merchant_account_id => SpecHelper::UsBankMerchantAccountId,
54
+ :amount => "100.00"
55
+ )
46
56
 
47
57
  result.success?.should == true
48
58
  result.transaction.amount.should == BigDecimal.new("100.00")
49
59
  result.transaction.type.should == "sale"
50
60
  us_bank_account = result.transaction.us_bank_account_details
51
61
  us_bank_account.routing_number.should == "021000021"
52
- us_bank_account.last_4.should == "1234"
62
+ us_bank_account.last_4.should == "0000"
53
63
  us_bank_account.account_type.should == "checking"
54
- us_bank_account.account_holder_name.should == "Dan Schulman"
64
+ us_bank_account.account_holder_name.should == "John Doe"
55
65
  us_bank_account.bank_name.should =~ /CHASE/
56
66
  us_bank_account.ach_mandate.text.should == "cl mandate text"
57
67
  us_bank_account.ach_mandate.accepted_at.should be_a Time
@@ -61,23 +71,30 @@ describe Braintree::UsBankAccount do
61
71
  context "self.sale!" do
62
72
  it "creates a transaction using a us bank account and returns a result object" do
63
73
  customer = Braintree::Customer.create!
64
- nonce = generate_valid_us_bank_account_nonce
74
+ nonce = generate_non_plaid_us_bank_account_nonce
65
75
 
66
76
  result = Braintree::PaymentMethod.create(
67
77
  :payment_method_nonce => nonce,
68
- :customer_id => customer.id
78
+ :customer_id => customer.id,
79
+ :options => {
80
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
81
+ }
69
82
  )
70
83
  result.should be_success
71
84
 
72
- transaction = Braintree::UsBankAccount.sale!(result.payment_method.token, :merchant_account_id => "us_bank_merchant_account", :amount => "100.00")
85
+ transaction = Braintree::UsBankAccount.sale!(
86
+ result.payment_method.token,
87
+ :merchant_account_id => SpecHelper::UsBankMerchantAccountId,
88
+ :amount => "100.00"
89
+ )
73
90
 
74
91
  transaction.amount.should == BigDecimal.new("100.00")
75
92
  transaction.type.should == "sale"
76
93
  us_bank_account = transaction.us_bank_account_details
77
94
  us_bank_account.routing_number.should == "021000021"
78
- us_bank_account.last_4.should == "1234"
95
+ us_bank_account.last_4.should == "0000"
79
96
  us_bank_account.account_type.should == "checking"
80
- us_bank_account.account_holder_name.should == "Dan Schulman"
97
+ us_bank_account.account_holder_name.should == "John Doe"
81
98
  us_bank_account.bank_name.should =~ /CHASE/
82
99
  us_bank_account.ach_mandate.text.should == "cl mandate text"
83
100
  us_bank_account.ach_mandate.accepted_at.should be_a Time
@@ -85,7 +102,11 @@ describe Braintree::UsBankAccount do
85
102
 
86
103
  it "does not creates a transaction using a us bank account and returns raises an exception" do
87
104
  expect do
88
- Braintree::UsBankAccount.sale!(generate_invalid_us_bank_account_nonce, :merchant_account_id => "us_bank_merchant_account", :amount => "100.00")
105
+ Braintree::UsBankAccount.sale!(
106
+ generate_invalid_us_bank_account_nonce,
107
+ :merchant_account_id => SpecHelper::UsBankMerchantAccountId,
108
+ :amount => "100.00"
109
+ )
89
110
  end.to raise_error(Braintree::ValidationsFailed)
90
111
  end
91
112
  end
@@ -0,0 +1,178 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
3
+
4
+ describe Braintree::UsBankAccountVerification, "search" do
5
+ it "correctly returns a result with no matches" do
6
+ collection = Braintree::UsBankAccountVerification.search do |search|
7
+ search.account_holder_name.is "thisnameisnotreal"
8
+ end
9
+
10
+ collection.maximum_size.should == 0
11
+ end
12
+
13
+ let(:nonce) { generate_non_plaid_us_bank_account_nonce }
14
+
15
+ it "can search on text fields" do
16
+ customer = Braintree::Customer.create(
17
+ :email => "john.doe@example.com",
18
+ ).customer
19
+ payment_method = Braintree::PaymentMethod.create(
20
+ :payment_method_nonce => nonce,
21
+ :customer_id => customer.id,
22
+ :options => {
23
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
24
+ }
25
+ ).payment_method
26
+ verification = payment_method.verifications.first
27
+
28
+ search_criteria = {
29
+ :id => verification.id,
30
+ :account_holder_name => "John Doe",
31
+ :routing_number => "021000021",
32
+ :payment_method_token => payment_method.token,
33
+ :account_type => "checking",
34
+ :customer_id => customer.id,
35
+ :customer_email => "john.doe@example.com",
36
+ }
37
+
38
+ search_criteria.each do |criterion, value|
39
+ collection = Braintree::UsBankAccountVerification.search do |search|
40
+ search.id.is verification.id
41
+ search.send(criterion).is value
42
+ end
43
+ collection.maximum_size.should == 1
44
+ collection.first.id.should == verification.id
45
+
46
+ collection = Braintree::UsBankAccountVerification.search do |search|
47
+ search.id.is verification.id
48
+ search.send(criterion).is "invalid_attribute"
49
+ end
50
+ collection.should be_empty
51
+ end
52
+
53
+ collection = Braintree::UsBankAccountVerification.search do |search|
54
+ search.id.is verification.id
55
+ search_criteria.each do |criterion, value|
56
+ search.send(criterion).is value
57
+ end
58
+ end
59
+
60
+ collection.maximum_size.should == 1
61
+ collection.first.id.should == verification.id
62
+ end
63
+
64
+ describe "multiple value fields" do
65
+ it "searches on ids" do
66
+ customer = Braintree::Customer.create.customer
67
+
68
+ payment_method1 = Braintree::PaymentMethod.create(
69
+ :payment_method_nonce => generate_non_plaid_us_bank_account_nonce,
70
+ :customer_id => customer.id,
71
+ :options => {
72
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
73
+ }
74
+ ).payment_method
75
+ verification1 = payment_method1.verifications.first
76
+
77
+ payment_method2 = Braintree::PaymentMethod.create(
78
+ :payment_method_nonce => generate_non_plaid_us_bank_account_nonce,
79
+ :customer_id => customer.id,
80
+ :options => {
81
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
82
+ }
83
+ ).payment_method
84
+ verification2 = payment_method2.verifications.first
85
+
86
+ collection = Braintree::UsBankAccountVerification.search do |search|
87
+ search.ids.in verification1.id, verification2.id
88
+ end
89
+
90
+ collection.maximum_size.should == 2
91
+ end
92
+ end
93
+
94
+ context "range fields" do
95
+ it "searches on created_at" do
96
+ customer = Braintree::Customer.create.customer
97
+
98
+ payment_method = Braintree::PaymentMethod.create(
99
+ :payment_method_nonce => generate_non_plaid_us_bank_account_nonce,
100
+ :customer_id => customer.id,
101
+ :options => {
102
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
103
+ }
104
+ ).payment_method
105
+ verification = payment_method.verifications.first
106
+
107
+ created_at = verification.created_at
108
+
109
+ collection = Braintree::UsBankAccountVerification.search do |search|
110
+ search.id.is verification.id
111
+ search.created_at.between(
112
+ created_at - 60,
113
+ created_at + 60
114
+ )
115
+ end
116
+
117
+ collection.maximum_size.should == 1
118
+ collection.first.id.should == verification.id
119
+
120
+ collection = Braintree::UsBankAccountVerification.search do |search|
121
+ search.id.is verification.id
122
+ search.created_at >= created_at - 1
123
+ end
124
+
125
+ collection.maximum_size.should == 1
126
+ collection.first.id.should == verification.id
127
+
128
+ collection = Braintree::UsBankAccountVerification.search do |search|
129
+ search.id.is verification.id
130
+ search.created_at <= created_at + 1
131
+ end
132
+
133
+ collection.maximum_size.should == 1
134
+ collection.first.id.should == verification.id
135
+
136
+ collection = Braintree::UsBankAccountVerification.search do |search|
137
+ search.id.is verification.id
138
+ search.created_at.between(
139
+ created_at - 300,
140
+ created_at - 100
141
+ )
142
+ end
143
+
144
+ collection.maximum_size.should == 0
145
+
146
+ collection = Braintree::UsBankAccountVerification.search do |search|
147
+ search.id.is verification.id
148
+ search.created_at.is created_at
149
+ end
150
+
151
+ collection.maximum_size.should == 1
152
+ collection.first.id.should == verification.id
153
+ end
154
+ end
155
+
156
+ context "ends with fields" do
157
+ it "does ends_with search on account_number" do
158
+ customer = Braintree::Customer.create.customer
159
+
160
+ payment_method = Braintree::PaymentMethod.create(
161
+ :payment_method_nonce => nonce,
162
+ :customer_id => customer.id,
163
+ :options => {
164
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
165
+ }
166
+ ).payment_method
167
+ verification = payment_method.verifications.first
168
+
169
+ collection = Braintree::UsBankAccountVerification.search do |search|
170
+ search.id.is verification.id
171
+ search.account_number.ends_with "0000"
172
+ end
173
+
174
+ collection.maximum_size.should == 1
175
+ collection.first.id.should == verification.id
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,79 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
3
+
4
+ describe Braintree::UsBankAccountVerification, "search" do
5
+ let(:nonce) { generate_non_plaid_us_bank_account_nonce }
6
+ let(:customer) do
7
+ params = {
8
+ :first_name => "Tom",
9
+ :last_name => "Smith",
10
+ :email => "tom.smith@example.com",
11
+ }
12
+
13
+ Braintree::Customer.create(params).customer
14
+ end
15
+
16
+ describe "self.find" do
17
+ it "finds the verification with the given id" do
18
+ result = Braintree::PaymentMethod.create(
19
+ :payment_method_nonce => nonce,
20
+ :customer_id => customer.id,
21
+ :options => {
22
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
23
+ :us_bank_account_verification_method => Braintree::UsBankAccountVerification::VerificationMethod::NetworkCheck,
24
+ }
25
+ )
26
+
27
+ result.should be_success
28
+
29
+ created_verification = result.payment_method.verifications.first
30
+ found_verification = Braintree::UsBankAccountVerification.find(created_verification.id)
31
+
32
+ found_verification.should == created_verification
33
+ end
34
+
35
+ it "raises a NotFoundError exception if verification cannot be found" do
36
+ expect do
37
+ Braintree::UsBankAccountVerification.find("invalid-id")
38
+ end.to raise_error(Braintree::NotFoundError, 'verification with id "invalid-id" not found')
39
+ end
40
+ end
41
+
42
+ describe "self.search" do
43
+ let(:payment_method) do
44
+ Braintree::PaymentMethod.create(
45
+ :payment_method_nonce => nonce,
46
+ :customer_id => customer.id,
47
+ :options => {
48
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
49
+ :us_bank_account_verification_method => Braintree::UsBankAccountVerification::VerificationMethod::NetworkCheck,
50
+ }
51
+ ).payment_method
52
+ end
53
+
54
+ let(:created_verification) do
55
+ payment_method.verifications.first
56
+ end
57
+
58
+ it "searches and finds verification using verification fields" do
59
+ found_verifications = Braintree::UsBankAccountVerification.search do |search|
60
+ search.created_at >= (Time.now() - 120)
61
+ search.ids.in created_verification.id
62
+ search.status.in created_verification.status
63
+ search.verification_method.in created_verification.verification_method
64
+ end
65
+
66
+ found_verifications.should include(created_verification)
67
+ end
68
+
69
+ it "searches and finds verifications using customer fields" do
70
+ found_verifications = Braintree::UsBankAccountVerification.search do |search|
71
+ search.customer_email.is customer.email
72
+ search.customer_id.is customer.id
73
+ search.payment_method_token.is payment_method.token
74
+ end
75
+
76
+ found_verifications.count.should eq(1)
77
+ end
78
+ end
79
+ end
@@ -39,7 +39,8 @@ unless defined?(SPEC_HELPER_LOADED)
39
39
  ThreeDSecureMerchantAccountId = "three_d_secure_merchant_account"
40
40
  FakeAmexDirectMerchantAccountId = "fake_amex_direct_usd"
41
41
  FakeVenmoAccountMerchantAccountId = "fake_first_data_venmo_account"
42
- UsBankMerhantAccountId = "us_bank_merchant_account"
42
+ UsBankMerchantAccountId = "us_bank_merchant_account"
43
+ AnotherUsBankMerchantAccountId = "another_us_bank_merchant_account"
43
44
  IdealMerchantAccountId = "ideal_merchant_account"
44
45
 
45
46
  TrialPlan = {
@@ -0,0 +1,60 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ module Braintree
4
+ describe UsBankAccountVerificationSearch do
5
+ context "verification method" do
6
+ it "allows All verification methods" do
7
+ search = UsBankAccountVerificationSearch.new
8
+
9
+ lambda do
10
+ search.verification_method.in(
11
+ *Braintree::UsBankAccountVerification::VerificationMethod::All,
12
+ )
13
+ end.should_not raise_error
14
+ end
15
+ end
16
+
17
+ context "id" do
18
+ it "is" do
19
+ search = UsBankAccountVerificationSearch.new
20
+ search.id.is "v_id"
21
+
22
+ search.to_hash.should == {:id => {:is => "v_id"}}
23
+ end
24
+ end
25
+
26
+ context "ids" do
27
+ it "correctly builds a hash with ids" do
28
+ search = UsBankAccountVerificationSearch.new
29
+ search.ids.in("id1", "id2")
30
+
31
+ search.to_hash.should == {:ids => ["id1", "id2"]}
32
+ end
33
+ end
34
+
35
+ context "account_holder_name" do
36
+ it "is" do
37
+ search = UsBankAccountVerificationSearch.new
38
+ search.account_holder_name.is "v_account_holder_name"
39
+
40
+ search.to_hash.should == {:account_holder_name => {:is => "v_account_holder_name"}}
41
+ end
42
+ end
43
+
44
+ context "created_at" do
45
+ it "is a range node" do
46
+ search = UsBankAccountVerificationSearch.new
47
+ search.created_at.should be_kind_of(Braintree::AdvancedSearch::RangeNode)
48
+ end
49
+ end
50
+
51
+ context "account number" do
52
+ it "uses ends_with" do
53
+ search = UsBankAccountVerificationSearch.new
54
+ search.account_number.ends_with "1234"
55
+
56
+ search.to_hash.should == {:account_number => {:ends_with => "1234"}}
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,67 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Braintree::UsBankAccountVerification do
4
+ describe "inspect" do
5
+ let(:verification) do
6
+ Braintree::UsBankAccountVerification._new(
7
+ :id => "some_verification_id",
8
+ :status => Braintree::UsBankAccountVerification::Status::Verified,
9
+ :verification_method => Braintree::UsBankAccountVerification::VerificationMethod::IndependentCheck,
10
+ :verification_determined_at => "2018-02-28T12:01:01Z",
11
+ )
12
+ end
13
+
14
+ it "has a status" do
15
+ verification.status.should == Braintree::UsBankAccountVerification::Status::Verified
16
+ end
17
+ end
18
+
19
+ describe "self.find" do
20
+ it "raises error if passed empty string" do
21
+ expect do
22
+ Braintree::UsBankAccountVerification.find("")
23
+ end.to raise_error(ArgumentError)
24
+ end
25
+
26
+ it "raises error if passed empty string wth space" do
27
+ expect do
28
+ Braintree::UsBankAccountVerification.find(" ")
29
+ end.to raise_error(ArgumentError)
30
+ end
31
+
32
+ it "raises error if passed nil" do
33
+ expect do
34
+ Braintree::UsBankAccountVerification.find(nil)
35
+ end.to raise_error(ArgumentError)
36
+ end
37
+ end
38
+
39
+ describe "==" do
40
+ it "returns true for verifications with the same id" do
41
+ first = Braintree::UsBankAccountVerification._new(:id => "123")
42
+ second = Braintree::UsBankAccountVerification._new(:id => "123")
43
+
44
+ first.should == second
45
+ second.should == first
46
+ end
47
+
48
+ it "returns false for verifications with different ids" do
49
+ first = Braintree::UsBankAccountVerification._new(:id => "123")
50
+ second = Braintree::UsBankAccountVerification._new(:id => "124")
51
+
52
+ first.should_not == second
53
+ second.should_not == first
54
+ end
55
+
56
+ it "returns false when comparing to nil" do
57
+ Braintree::UsBankAccountVerification._new({}).should_not == nil
58
+ end
59
+
60
+ it "returns false when comparing to non-verifications" do
61
+ same_id_different_object = Object.new
62
+ def same_id_different_object.id; "123"; end
63
+ verification = Braintree::UsBankAccountVerification._new(:id => "123")
64
+ verification.should_not == same_id_different_object
65
+ end
66
+ end
67
+ end