braintree 2.101.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/braintree.gemspec +6 -3
- data/lib/braintree.rb +3 -17
- data/lib/braintree/address.rb +0 -22
- data/lib/braintree/address_gateway.rb +2 -2
- data/lib/braintree/base_module.rb +6 -0
- data/lib/braintree/configuration.rb +1 -1
- data/lib/braintree/credit_card.rb +5 -76
- data/lib/braintree/credit_card_gateway.rb +16 -32
- data/lib/braintree/credit_card_verification.rb +14 -0
- data/lib/braintree/customer.rb +3 -72
- data/lib/braintree/customer_gateway.rb +0 -23
- data/lib/braintree/dispute.rb +1 -7
- data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
- data/lib/braintree/dispute/transaction.rb +2 -0
- data/lib/braintree/dispute_gateway.rb +2 -7
- data/lib/braintree/error_codes.rb +162 -157
- data/lib/braintree/exceptions.rb +5 -3
- data/lib/braintree/gateway.rb +0 -14
- data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +1 -1
- data/lib/braintree/local_payment_completed.rb +1 -1
- data/lib/braintree/merchant_account_gateway.rb +2 -0
- data/lib/braintree/payment_instrument_type.rb +1 -4
- data/lib/braintree/payment_method_gateway.rb +16 -8
- data/lib/braintree/payment_method_nonce.rb +2 -0
- data/lib/braintree/payment_method_nonce_gateway.rb +13 -2
- data/lib/braintree/payment_method_parser.rb +1 -7
- data/lib/braintree/risk_data.rb +4 -1
- data/lib/braintree/subscription.rb +5 -5
- data/lib/braintree/successful_result.rb +0 -1
- data/lib/braintree/test/authentication_id.rb +21 -0
- data/lib/braintree/test/credit_card.rb +1 -0
- data/lib/braintree/test/nonce.rb +19 -20
- data/lib/braintree/transaction.rb +8 -72
- data/lib/braintree/transaction/address_details.rb +11 -0
- data/lib/braintree/transaction/disbursement_details.rb +1 -0
- data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
- data/lib/braintree/transaction/paypal_details.rb +2 -0
- data/lib/braintree/transaction/subscription_details.rb +2 -0
- data/lib/braintree/transaction_gateway.rb +14 -21
- data/lib/braintree/transaction_search.rb +0 -1
- data/lib/braintree/util.rb +17 -2
- data/lib/braintree/version.rb +3 -3
- data/lib/braintree/webhook_notification.rb +3 -10
- data/lib/braintree/webhook_testing_gateway.rb +243 -43
- data/lib/braintree/xml/libxml.rb +1 -0
- data/lib/braintree/xml/parser.rb +11 -34
- data/spec/integration/braintree/address_spec.rb +2 -89
- data/spec/integration/braintree/client_api/spec_helper.rb +100 -67
- data/spec/integration/braintree/credit_card_spec.rb +119 -467
- data/spec/integration/braintree/credit_card_verification_spec.rb +1 -0
- data/spec/integration/braintree/customer_spec.rb +135 -362
- data/spec/integration/braintree/dispute_search_spec.rb +2 -2
- data/spec/integration/braintree/dispute_spec.rb +1 -2
- data/spec/integration/braintree/document_upload_spec.rb +12 -0
- data/spec/integration/braintree/merchant_spec.rb +2 -2
- data/spec/integration/braintree/payment_method_nonce_spec.rb +77 -0
- data/spec/integration/braintree/payment_method_spec.rb +186 -120
- data/spec/integration/braintree/paypal_account_spec.rb +1 -1
- data/spec/integration/braintree/subscription_spec.rb +11 -16
- data/spec/integration/braintree/transaction_search_spec.rb +3 -3
- data/spec/integration/braintree/transaction_spec.rb +252 -524
- data/spec/integration/spec_helper.rb +1 -4
- data/spec/spec_helper.rb +1 -11
- data/spec/unit/braintree/address_spec.rb +0 -8
- data/spec/unit/braintree/credit_card_spec.rb +50 -23
- data/spec/unit/braintree/credit_card_verification_spec.rb +7 -0
- data/spec/unit/braintree/customer_spec.rb +26 -14
- data/spec/unit/braintree/dispute_spec.rb +4 -12
- data/spec/unit/braintree/http_spec.rb +3 -3
- data/spec/unit/braintree/local_payment_completed_spec.rb +14 -0
- data/spec/unit/braintree/transaction/paypal_details_spec.rb +57 -0
- data/spec/unit/braintree/transaction_spec.rb +17 -37
- data/spec/unit/braintree/util_spec.rb +37 -3
- data/spec/unit/braintree/webhook_notification_spec.rb +49 -1
- data/spec/unit/braintree/xml/parser_spec.rb +21 -16
- metadata +29 -31
- data/lib/braintree/amex_express_checkout_card.rb +0 -38
- data/lib/braintree/coinbase_account.rb +0 -34
- data/lib/braintree/europe_bank_account.rb +0 -36
- data/lib/braintree/europe_bank_account_gateway.rb +0 -17
- data/lib/braintree/ideal_payment.rb +0 -61
- data/lib/braintree/ideal_payment_gateway.rb +0 -19
- data/lib/braintree/masterpass_card.rb +0 -81
- data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
- data/lib/braintree/transaction/coinbase_details.rb +0 -16
- data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
- data/lib/braintree/transaction/masterpass_card_details.rb +0 -47
- data/lib/braintree/transparent_redirect.rb +0 -40
- data/lib/braintree/transparent_redirect_gateway.rb +0 -105
- data/lib/braintree/xml/rexml.rb +0 -71
- data/spec/hacks/tcp_socket.rb +0 -18
- data/spec/integration/braintree/coinbase_spec.rb +0 -34
- data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
- data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
- data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
- data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
data/lib/braintree/xml/libxml.rb
CHANGED
data/lib/braintree/xml/parser.rb
CHANGED
@@ -11,23 +11,14 @@ module Braintree
|
|
11
11
|
"boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.strip) },
|
12
12
|
}
|
13
13
|
|
14
|
-
def self.hash_from_xml(xml
|
15
|
-
standardized_hash_structure =
|
16
|
-
|
17
|
-
|
18
|
-
Util.symbolize_keys(typecasted_xml)
|
14
|
+
def self.hash_from_xml(xml)
|
15
|
+
standardized_hash_structure = ::Braintree::Xml::Libxml.parse(xml)
|
16
|
+
transformed_xml = _transform_xml(standardized_hash_structure)
|
17
|
+
Util.symbolize_keys(transformed_xml)
|
19
18
|
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
if !RUBY_VERSION.start_with?("2.0") && defined?(::LibXML::XML) && ::LibXML::XML.respond_to?(:default_keep_blanks=)
|
24
|
-
::Braintree::Xml::Libxml
|
25
|
-
else
|
26
|
-
::Braintree::Xml::Rexml
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def self._typecast_xml_value(value)
|
20
|
+
# Transform into standard Ruby types and convert all keys to snake_case instead of dash-case
|
21
|
+
def self._transform_xml(value)
|
31
22
|
case value.class.to_s
|
32
23
|
when 'Hash'
|
33
24
|
if value['type'] == 'array'
|
@@ -37,9 +28,9 @@ module Braintree
|
|
37
28
|
else
|
38
29
|
case entries.class.to_s # something weird with classes not matching here. maybe singleton methods breaking is_a?
|
39
30
|
when "Array"
|
40
|
-
entries.collect { |v|
|
31
|
+
entries.collect { |v| _transform_xml(v) }
|
41
32
|
when "Hash"
|
42
|
-
[
|
33
|
+
[_transform_xml(entries)]
|
43
34
|
else
|
44
35
|
raise "can't typecast #{entries.inspect}"
|
45
36
|
end
|
@@ -65,13 +56,13 @@ module Braintree
|
|
65
56
|
nil
|
66
57
|
else
|
67
58
|
xml_value = value.inject({}) do |h,(k,v)|
|
68
|
-
h[k] =
|
59
|
+
h[k.to_s.tr("-", "_")] = _transform_xml(v) # convert dashes to underscores in keys
|
69
60
|
h
|
70
61
|
end
|
71
62
|
xml_value
|
72
63
|
end
|
73
64
|
when 'Array'
|
74
|
-
value.map! { |i|
|
65
|
+
value.map! { |i| _transform_xml(i) }
|
75
66
|
case value.length
|
76
67
|
when 0 then nil
|
77
68
|
when 1 then value.first
|
@@ -80,21 +71,7 @@ module Braintree
|
|
80
71
|
when 'String'
|
81
72
|
value
|
82
73
|
else
|
83
|
-
raise "can't
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def self._unrename_keys(params)
|
88
|
-
case params.class.to_s
|
89
|
-
when "Hash"
|
90
|
-
params.inject({}) do |h,(k,v)|
|
91
|
-
h[k.to_s.tr("-", "_")] = _unrename_keys(v)
|
92
|
-
h
|
93
|
-
end
|
94
|
-
when "Array"
|
95
|
-
params.map { |v| _unrename_keys(v) }
|
96
|
-
else
|
97
|
-
params
|
74
|
+
raise "can't transform #{value.class.name} - #{value.inspect}"
|
98
75
|
end
|
99
76
|
end
|
100
77
|
end
|
@@ -347,98 +347,11 @@ describe Braintree::Address do
|
|
347
347
|
it "deletes the address" do
|
348
348
|
customer = Braintree::Customer.create!(:last_name => "Wilson")
|
349
349
|
address = Braintree::Address.create!(:customer_id => customer.id, :street_address => "123 E Main St")
|
350
|
-
|
350
|
+
result = Braintree::Address.delete(customer.id, address.id)
|
351
|
+
result.success?.should == true
|
351
352
|
expect do
|
352
353
|
Braintree::Address.find(customer.id, address.id)
|
353
354
|
end.to raise_error(Braintree::NotFoundError)
|
354
355
|
end
|
355
356
|
end
|
356
|
-
|
357
|
-
describe "update" do
|
358
|
-
it "returns a success response and updates the address if valid" do
|
359
|
-
customer = Braintree::Customer.create!(:last_name => "Miller")
|
360
|
-
address = Braintree::Address.create!(
|
361
|
-
:customer_id => customer.id,
|
362
|
-
:street_address => "1812 E Old St",
|
363
|
-
:extended_address => "Suite Old 201",
|
364
|
-
:locality => "Old Chicago",
|
365
|
-
:region => "IL",
|
366
|
-
:postal_code => "60620",
|
367
|
-
:country_name => "United States of America"
|
368
|
-
)
|
369
|
-
result = address.update(
|
370
|
-
:street_address => "123 E New St",
|
371
|
-
:extended_address => "New Suite 3",
|
372
|
-
:locality => "Chicago",
|
373
|
-
:region => "Illinois",
|
374
|
-
:postal_code => "60621",
|
375
|
-
:country_name => "United States of America"
|
376
|
-
)
|
377
|
-
result.success?.should == true
|
378
|
-
result.address.should == address
|
379
|
-
address.street_address.should == "123 E New St"
|
380
|
-
address.extended_address.should == "New Suite 3"
|
381
|
-
address.locality.should == "Chicago"
|
382
|
-
address.region.should == "Illinois"
|
383
|
-
address.postal_code.should == "60621"
|
384
|
-
address.country_name.should == "United States of America"
|
385
|
-
end
|
386
|
-
|
387
|
-
it "returns an error response if invalid" do
|
388
|
-
customer = Braintree::Customer.create!(:last_name => "Miller")
|
389
|
-
address = Braintree::Address.create!(
|
390
|
-
:customer_id => customer.id,
|
391
|
-
:country_name => "United States of America"
|
392
|
-
)
|
393
|
-
result = address.update(
|
394
|
-
:street_address => "123 E New St",
|
395
|
-
:country_name => "United States of Invalid"
|
396
|
-
)
|
397
|
-
result.success?.should == false
|
398
|
-
result.errors.for(:address).on(:country_name)[0].message.should == "Country name is not an accepted country."
|
399
|
-
end
|
400
|
-
end
|
401
|
-
|
402
|
-
describe "update!" do
|
403
|
-
it "returns true and updates the address if valid" do
|
404
|
-
customer = Braintree::Customer.create!(:last_name => "Miller")
|
405
|
-
address = Braintree::Address.create!(
|
406
|
-
:customer_id => customer.id,
|
407
|
-
:street_address => "1812 E Old St",
|
408
|
-
:extended_address => "Suite Old 201",
|
409
|
-
:locality => "Old Chicago",
|
410
|
-
:region => "IL",
|
411
|
-
:postal_code => "60620",
|
412
|
-
:country_name => "United States of America"
|
413
|
-
)
|
414
|
-
address.update!(
|
415
|
-
:street_address => "123 E New St",
|
416
|
-
:extended_address => "New Suite 3",
|
417
|
-
:locality => "Chicago",
|
418
|
-
:region => "Illinois",
|
419
|
-
:postal_code => "60621",
|
420
|
-
:country_name => "United States of America"
|
421
|
-
).should == address
|
422
|
-
address.street_address.should == "123 E New St"
|
423
|
-
address.extended_address.should == "New Suite 3"
|
424
|
-
address.locality.should == "Chicago"
|
425
|
-
address.region.should == "Illinois"
|
426
|
-
address.postal_code.should == "60621"
|
427
|
-
address.country_name.should == "United States of America"
|
428
|
-
end
|
429
|
-
|
430
|
-
it "raises a ValidationsFailed invalid" do
|
431
|
-
customer = Braintree::Customer.create!(:last_name => "Miller")
|
432
|
-
address = Braintree::Address.create!(
|
433
|
-
:customer_id => customer.id,
|
434
|
-
:country_name => "United States of America"
|
435
|
-
)
|
436
|
-
expect do
|
437
|
-
address.update!(
|
438
|
-
:street_address => "123 E New St",
|
439
|
-
:country_name => "United States of Invalid"
|
440
|
-
)
|
441
|
-
end.to raise_error(Braintree::ValidationsFailed)
|
442
|
-
end
|
443
|
-
end
|
444
357
|
end
|
@@ -56,93 +56,84 @@ def nonce_for_paypal_account(paypal_account_details)
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def generate_non_plaid_us_bank_account_nonce(account_number="1000000000")
|
59
|
-
|
60
|
-
mutation TokenizeUsBankAccount($input: TokenizeUsBankAccountInput!) {
|
61
|
-
|
62
|
-
|
63
|
-
|
59
|
+
query = %{
|
60
|
+
mutation TokenizeUsBankAccount($input: TokenizeUsBankAccountInput!) {
|
61
|
+
tokenizeUsBankAccount(input: $input) {
|
62
|
+
paymentMethod {
|
63
|
+
id
|
64
|
+
}
|
65
|
+
}
|
64
66
|
}
|
65
67
|
}
|
66
|
-
|
67
|
-
GRAPHQL
|
68
|
+
|
68
69
|
variables = {
|
69
|
-
input
|
70
|
-
usBankAccount
|
71
|
-
|
72
|
-
routingNumber
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
lastName: "Doe",
|
70
|
+
:input => {
|
71
|
+
:usBankAccount => {
|
72
|
+
:accountNumber => account_number,
|
73
|
+
:routingNumber => "021000021",
|
74
|
+
:accountType => "CHECKING",
|
75
|
+
:individualOwner => {
|
76
|
+
:firstName => "John",
|
77
|
+
:lastName => "Doe",
|
78
78
|
},
|
79
|
-
billingAddress
|
80
|
-
streetAddress
|
81
|
-
|
82
|
-
|
83
|
-
zipCode
|
84
|
-
}
|
79
|
+
:billingAddress => {
|
80
|
+
:streetAddress => "123 Ave",
|
81
|
+
:state => "CA",
|
82
|
+
:city => "San Francisco",
|
83
|
+
:zipCode => "94112"
|
84
|
+
},
|
85
|
+
:achMandate => "cl mandate text"
|
85
86
|
}
|
86
87
|
}
|
87
88
|
}
|
88
|
-
response = Braintree::GraphQLClient.new(Braintree::Configuration.instantiate).query(definition, variables)
|
89
89
|
|
90
|
-
|
90
|
+
graphql_request = {
|
91
|
+
:query => query,
|
92
|
+
:variables => variables
|
93
|
+
}
|
94
|
+
|
95
|
+
json = _send_graphql_request(graphql_request)
|
96
|
+
json["data"]["tokenizeUsBankAccount"]["paymentMethod"]["id"]
|
91
97
|
end
|
92
98
|
|
93
99
|
def generate_valid_plaid_us_bank_account_nonce
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
definition = <<-GRAPHQL
|
102
|
-
mutation TokenizeUsBankLogin($input: TokenizeUsBankLoginInput!) {
|
103
|
-
tokenizeUsBankLogin(input: $input) {
|
104
|
-
paymentMethod {
|
105
|
-
id
|
100
|
+
query = %{
|
101
|
+
mutation TokenizeUsBankLogin($input: TokenizeUsBankLoginInput!) {
|
102
|
+
tokenizeUsBankLogin(input: $input) {
|
103
|
+
paymentMethod {
|
104
|
+
id
|
105
|
+
}
|
106
|
+
}
|
106
107
|
}
|
107
108
|
}
|
108
|
-
|
109
|
-
GRAPHQL
|
109
|
+
|
110
110
|
variables = {
|
111
|
-
input
|
112
|
-
usBankLogin
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
businessName: "PayPal, Inc."
|
111
|
+
:input => {
|
112
|
+
:usBankLogin => {
|
113
|
+
:publicToken => "good",
|
114
|
+
:accountId => "plaid_account_id",
|
115
|
+
:accountType => "CHECKING",
|
116
|
+
:businessOwner => {
|
117
|
+
:businessName => "PayPal, Inc.",
|
119
118
|
},
|
120
|
-
billingAddress
|
121
|
-
streetAddress
|
122
|
-
|
123
|
-
|
124
|
-
zipCode
|
125
|
-
}
|
119
|
+
:billingAddress => {
|
120
|
+
:streetAddress => "123 Ave",
|
121
|
+
:state => "CA",
|
122
|
+
:city => "San Francisco",
|
123
|
+
:zipCode => "94112"
|
124
|
+
},
|
125
|
+
:achMandate => "cl mandate text"
|
126
126
|
}
|
127
127
|
}
|
128
128
|
}
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
|
130
|
+
graphql_request = {
|
131
|
+
:query => query,
|
132
|
+
:variables => variables
|
132
133
|
}
|
133
|
-
uri = URI::parse(url)
|
134
|
-
connection = Net::HTTP.new(uri.host, uri.port)
|
135
|
-
connection.use_ssl = false
|
136
|
-
response = connection.start do |http|
|
137
|
-
request = Net::HTTP::Post.new(uri.path)
|
138
|
-
request["Content-Type"] = "application/json"
|
139
|
-
request["Braintree-Version"] = date
|
140
|
-
request["Authorization"] = "Bearer #{token}"
|
141
|
-
request.body = payload.to_json
|
142
|
-
http.request(request)
|
143
|
-
end
|
144
134
|
|
145
|
-
|
135
|
+
json = _send_graphql_request(graphql_request)
|
136
|
+
json["data"]["tokenizeUsBankLogin"]["paymentMethod"]["id"]
|
146
137
|
end
|
147
138
|
|
148
139
|
def sample(arr)
|
@@ -156,6 +147,48 @@ def generate_invalid_us_bank_account_nonce
|
|
156
147
|
nonce += "_xxx"
|
157
148
|
end
|
158
149
|
|
150
|
+
def _cosmos_post(token, url, payload)
|
151
|
+
uri = URI::parse(url)
|
152
|
+
connection = Net::HTTP.new(uri.host, uri.port)
|
153
|
+
if uri.scheme == "https"
|
154
|
+
connection.use_ssl = true
|
155
|
+
connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
156
|
+
end
|
157
|
+
resp = connection.start do |http|
|
158
|
+
request = Net::HTTP::Post.new(uri.path)
|
159
|
+
request["Content-Type"] = "application/json"
|
160
|
+
request["Braintree-Version"] = "2016-10-07"
|
161
|
+
request["Authorization"] = "Bearer #{token}"
|
162
|
+
request.body = payload.to_json
|
163
|
+
http.request(request)
|
164
|
+
end
|
165
|
+
|
166
|
+
JSON.parse(resp.body)
|
167
|
+
end
|
168
|
+
|
169
|
+
def _send_graphql_request(graphql_request)
|
170
|
+
raw_client_token = Braintree::ClientToken.generate
|
171
|
+
client_token = decode_client_token(raw_client_token)
|
172
|
+
uri = URI::parse("#{client_token["braintree_api"]["url"]}/graphql")
|
173
|
+
connection = Net::HTTP.new(uri.host, uri.port)
|
174
|
+
|
175
|
+
if uri.scheme == "https"
|
176
|
+
connection.use_ssl = true
|
177
|
+
connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
178
|
+
end
|
179
|
+
|
180
|
+
resp = connection.start do |http|
|
181
|
+
request = Net::HTTP::Post.new(uri.path)
|
182
|
+
request["Content-Type"] = "application/json"
|
183
|
+
request["Braintree-Version"] = "2016-10-07"
|
184
|
+
request["Authorization"] = "Bearer #{client_token["braintree_api"]["access_token"]}"
|
185
|
+
request.body = graphql_request.to_json
|
186
|
+
http.request(request)
|
187
|
+
end
|
188
|
+
|
189
|
+
JSON.parse(resp.body)
|
190
|
+
end
|
191
|
+
|
159
192
|
class ClientApiHttp
|
160
193
|
attr_reader :config, :options
|
161
194
|
|
@@ -15,7 +15,7 @@ describe Braintree::CreditCard do
|
|
15
15
|
:customer_id => customer.id,
|
16
16
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
17
17
|
:expiration_date => "05/2009",
|
18
|
-
:cvv => "100"
|
18
|
+
:cvv => "100",
|
19
19
|
)
|
20
20
|
result.success?.should == true
|
21
21
|
credit_card = result.credit_card
|
@@ -35,8 +35,7 @@ describe Braintree::CreditCard do
|
|
35
35
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
36
36
|
:expiration_date => "05/2009",
|
37
37
|
:cvv => "100",
|
38
|
-
:
|
39
|
-
:fraud_merchant_id => "7"
|
38
|
+
:device_data => "device_data",
|
40
39
|
)
|
41
40
|
result.success?.should == true
|
42
41
|
end
|
@@ -110,7 +109,7 @@ describe Braintree::CreditCard do
|
|
110
109
|
:options => {:verify_card => true}
|
111
110
|
)
|
112
111
|
result.success?.should == false
|
113
|
-
result.credit_card_verification.status.should == Braintree::
|
112
|
+
result.credit_card_verification.status.should == Braintree::CreditCardVerification::Status::ProcessorDeclined
|
114
113
|
result.credit_card_verification.processor_response_code.should == "2000"
|
115
114
|
result.credit_card_verification.processor_response_text.should == "Do Not Honor"
|
116
115
|
result.credit_card_verification.cvv_response_code.should == "I"
|
@@ -128,7 +127,7 @@ describe Braintree::CreditCard do
|
|
128
127
|
:options => {:verify_card => true, :verification_amount => "100.00"}
|
129
128
|
)
|
130
129
|
result.success?.should == false
|
131
|
-
result.credit_card_verification.status.should == Braintree::
|
130
|
+
result.credit_card_verification.status.should == Braintree::CreditCardVerification::Status::ProcessorDeclined
|
132
131
|
result.credit_card_verification.processor_response_code.should == "2000"
|
133
132
|
result.credit_card_verification.processor_response_text.should == "Do Not Honor"
|
134
133
|
result.credit_card_verification.cvv_response_code.should == "I"
|
@@ -175,7 +174,7 @@ describe Braintree::CreditCard do
|
|
175
174
|
:options => {:verify_card => true}
|
176
175
|
)
|
177
176
|
result.success?.should == false
|
178
|
-
result.credit_card_verification.gateway_rejection_reason.should == Braintree::
|
177
|
+
result.credit_card_verification.gateway_rejection_reason.should == Braintree::CreditCardVerification::GatewayRejectionReason::CVV
|
179
178
|
ensure
|
180
179
|
Braintree::Configuration.merchant_id = old_merchant
|
181
180
|
Braintree::Configuration.public_key = old_public_key
|
@@ -192,7 +191,7 @@ describe Braintree::CreditCard do
|
|
192
191
|
:options => {:verify_card => true, :verification_amount => "1.01"}
|
193
192
|
)
|
194
193
|
result.success?.should == false
|
195
|
-
result.credit_card_verification.status.should == Braintree::
|
194
|
+
result.credit_card_verification.status.should == Braintree::CreditCardVerification::Status::ProcessorDeclined
|
196
195
|
result.credit_card_verification.processor_response_code.should == "2000"
|
197
196
|
result.credit_card_verification.processor_response_text.should == "Do Not Honor"
|
198
197
|
result.credit_card_verification.cvv_response_code.should == "I"
|
@@ -227,6 +226,49 @@ describe Braintree::CreditCard do
|
|
227
226
|
result.success?.should == true
|
228
227
|
end
|
229
228
|
|
229
|
+
it "validates presence of three_d_secure_version in 3ds pass thru params" do
|
230
|
+
customer = Braintree::Customer.create!
|
231
|
+
result = Braintree::CreditCard.create(
|
232
|
+
:customer_id => customer.id,
|
233
|
+
:payment_method_nonce => Braintree::Test::Nonce::Transactable,
|
234
|
+
:three_d_secure_pass_thru => {
|
235
|
+
:eci_flag => '02',
|
236
|
+
:cavv => 'some_cavv',
|
237
|
+
:xid => 'some_xid',
|
238
|
+
:authentication_response => 'Y',
|
239
|
+
:directory_response => 'Y',
|
240
|
+
:cavv_algorithm => '2',
|
241
|
+
:ds_transaction_id => 'some_ds_transaction_id',
|
242
|
+
},
|
243
|
+
:options => {:verify_card => true}
|
244
|
+
)
|
245
|
+
expect(result).not_to be_success
|
246
|
+
error = result.errors.for(:verification).first
|
247
|
+
expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsRequired)
|
248
|
+
expect(error.message).to eq("ThreeDSecureVersion is required.")
|
249
|
+
end
|
250
|
+
|
251
|
+
it "accepts three_d_secure pass thru params in the request" do
|
252
|
+
customer = Braintree::Customer.create!
|
253
|
+
result = Braintree::CreditCard.create(
|
254
|
+
:customer_id => customer.id,
|
255
|
+
:payment_method_nonce => Braintree::Test::Nonce::Transactable,
|
256
|
+
:three_d_secure_pass_thru => {
|
257
|
+
:eci_flag => '02',
|
258
|
+
:cavv => 'some_cavv',
|
259
|
+
:xid => 'some_xid',
|
260
|
+
:three_d_secure_version => '1.0.2',
|
261
|
+
:authentication_response => 'Y',
|
262
|
+
:directory_response => 'Y',
|
263
|
+
:cavv_algorithm => '2',
|
264
|
+
:ds_transaction_id => 'some_ds_transaction_id',
|
265
|
+
},
|
266
|
+
:options => {:verify_card => true}
|
267
|
+
)
|
268
|
+
result.success?.should == true
|
269
|
+
|
270
|
+
end
|
271
|
+
|
230
272
|
it "returns 3DS info on cc verification" do
|
231
273
|
customer = Braintree::Customer.create!
|
232
274
|
result = Braintree::CreditCard.create(
|
@@ -730,95 +772,6 @@ describe Braintree::CreditCard do
|
|
730
772
|
end
|
731
773
|
end
|
732
774
|
|
733
|
-
describe "self.create_from_transparent_redirect" do
|
734
|
-
it "returns a successful result if successful" do
|
735
|
-
result = Braintree::Customer.create
|
736
|
-
result.success?.should == true
|
737
|
-
customer = result.customer
|
738
|
-
params = {
|
739
|
-
:credit_card => {
|
740
|
-
:cardholder_name => "Card Holder",
|
741
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
742
|
-
:expiration_date => "05/2012"
|
743
|
-
}
|
744
|
-
}
|
745
|
-
tr_data_params = {
|
746
|
-
:credit_card => {
|
747
|
-
:customer_id => customer.id
|
748
|
-
}
|
749
|
-
}
|
750
|
-
tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
751
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.create_credit_card_url)
|
752
|
-
result = Braintree::CreditCard.create_from_transparent_redirect(query_string_response)
|
753
|
-
result.success?.should == true
|
754
|
-
credit_card = result.credit_card
|
755
|
-
credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
756
|
-
credit_card.cardholder_name.should == "Card Holder"
|
757
|
-
credit_card.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
758
|
-
credit_card.expiration_month.should == "05"
|
759
|
-
credit_card.expiration_year.should == "2012"
|
760
|
-
credit_card.expiration_date.should == "05/2012"
|
761
|
-
credit_card.customer_id.should == customer.id
|
762
|
-
end
|
763
|
-
|
764
|
-
it "create card as default" do
|
765
|
-
customer = Braintree::Customer.create!(
|
766
|
-
:credit_card => {
|
767
|
-
:cardholder_name => "Old Cardholder Name",
|
768
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
769
|
-
:expiration_date => "05/2012"
|
770
|
-
}
|
771
|
-
)
|
772
|
-
card1 = customer.credit_cards[0]
|
773
|
-
|
774
|
-
params = {
|
775
|
-
:credit_card => {
|
776
|
-
:cardholder_name => "Card Holder",
|
777
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
778
|
-
:expiration_date => "05/2012",
|
779
|
-
:options => {:make_default => true}
|
780
|
-
}
|
781
|
-
}
|
782
|
-
tr_data_params = {
|
783
|
-
:credit_card => {
|
784
|
-
:customer_id => customer.id
|
785
|
-
}
|
786
|
-
}
|
787
|
-
tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
788
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.create_credit_card_url)
|
789
|
-
result = Braintree::CreditCard.create_from_transparent_redirect(query_string_response)
|
790
|
-
result.success?.should == true
|
791
|
-
card2 = result.credit_card
|
792
|
-
|
793
|
-
Braintree::CreditCard.find(card1.token).should_not be_default
|
794
|
-
card2.should be_default
|
795
|
-
end
|
796
|
-
|
797
|
-
it "returns xml with nested errors if validation errors" do
|
798
|
-
customer = Braintree::Customer.create.customer
|
799
|
-
params = {
|
800
|
-
:credit_card => {
|
801
|
-
:cardholder_name => "Card Holder",
|
802
|
-
:number => "eleventy",
|
803
|
-
:expiration_date => "y2k"
|
804
|
-
}
|
805
|
-
}
|
806
|
-
tr_data_params = {
|
807
|
-
:credit_card => {
|
808
|
-
:customer_id => customer.id
|
809
|
-
}
|
810
|
-
}
|
811
|
-
tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
812
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.create_credit_card_url)
|
813
|
-
result = Braintree::CreditCard.create_from_transparent_redirect(query_string_response)
|
814
|
-
result.success?.should == false
|
815
|
-
result.params[:customer_id] == customer.id
|
816
|
-
result.params[:credit_card]["cardholder_name"] == customer.id
|
817
|
-
result.params[:credit_card]["number"] == "eleventy"
|
818
|
-
result.params[:credit_card]["exipiration_date"] == "y2k"
|
819
|
-
end
|
820
|
-
end
|
821
|
-
|
822
775
|
describe "self.update" do
|
823
776
|
it "updates the credit card" do
|
824
777
|
customer = Braintree::Customer.create!
|
@@ -844,6 +797,62 @@ describe Braintree::CreditCard do
|
|
844
797
|
updated_credit_card.cardholder_name.should == "New Holder"
|
845
798
|
end
|
846
799
|
|
800
|
+
it "validates presence of three_d_secure_version in 3ds pass thru params" do
|
801
|
+
customer = Braintree::Customer.create!
|
802
|
+
credit_card = Braintree::CreditCard.create!(
|
803
|
+
:cardholder_name => "Original Holder",
|
804
|
+
:customer_id => customer.id,
|
805
|
+
:cvv => "123",
|
806
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
807
|
+
:expiration_date => "05/2012"
|
808
|
+
)
|
809
|
+
result = Braintree::CreditCard.update(credit_card.token,
|
810
|
+
:payment_method_nonce => Braintree::Test::Nonce::Transactable,
|
811
|
+
:three_d_secure_pass_thru => {
|
812
|
+
:eci_flag => '02',
|
813
|
+
:cavv => 'some_cavv',
|
814
|
+
:xid => 'some_xid',
|
815
|
+
:authentication_response => 'Y',
|
816
|
+
:directory_response => 'Y',
|
817
|
+
:cavv_algorithm => '2',
|
818
|
+
:ds_transaction_id => 'some_ds_transaction_id',
|
819
|
+
},
|
820
|
+
:options => {:verify_card => true}
|
821
|
+
)
|
822
|
+
expect(result).not_to be_success
|
823
|
+
error = result.errors.for(:verification).first
|
824
|
+
expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsRequired)
|
825
|
+
expect(error.message).to eq("ThreeDSecureVersion is required.")
|
826
|
+
end
|
827
|
+
|
828
|
+
it "accepts three_d_secure pass thru params in the request" do
|
829
|
+
customer = Braintree::Customer.create!
|
830
|
+
credit_card = Braintree::CreditCard.create!(
|
831
|
+
:cardholder_name => "Original Holder",
|
832
|
+
:customer_id => customer.id,
|
833
|
+
:cvv => "123",
|
834
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
835
|
+
:expiration_date => "05/2012"
|
836
|
+
)
|
837
|
+
result = Braintree::CreditCard.update(credit_card.token,
|
838
|
+
:payment_method_nonce => Braintree::Test::Nonce::Transactable,
|
839
|
+
:three_d_secure_pass_thru => {
|
840
|
+
:eci_flag => '02',
|
841
|
+
:cavv => 'some_cavv',
|
842
|
+
:three_d_secure_version=> "2.1.0",
|
843
|
+
:xid => 'some_xid',
|
844
|
+
:authentication_response => 'Y',
|
845
|
+
:directory_response => 'Y',
|
846
|
+
:cavv_algorithm => '2',
|
847
|
+
:ds_transaction_id => 'some_ds_transaction_id',
|
848
|
+
},
|
849
|
+
:options => {:verify_card => true}
|
850
|
+
)
|
851
|
+
|
852
|
+
result.success?.should == true
|
853
|
+
|
854
|
+
end
|
855
|
+
|
847
856
|
context "billing address" do
|
848
857
|
it "creates a new billing address by default" do
|
849
858
|
customer = Braintree::Customer.create!
|
@@ -954,7 +963,7 @@ describe Braintree::CreditCard do
|
|
954
963
|
:options => {:verify_card => true}
|
955
964
|
)
|
956
965
|
update_result.success?.should == false
|
957
|
-
update_result.credit_card_verification.status.should == Braintree::
|
966
|
+
update_result.credit_card_verification.status.should == Braintree::CreditCardVerification::Status::ProcessorDeclined
|
958
967
|
update_result.credit_card_verification.gateway_rejection_reason.should be_nil
|
959
968
|
end
|
960
969
|
|
@@ -1123,132 +1132,6 @@ describe Braintree::CreditCard do
|
|
1123
1132
|
end
|
1124
1133
|
end
|
1125
1134
|
|
1126
|
-
describe "self.update_from_transparent_redirect" do
|
1127
|
-
it "updates the credit card" do
|
1128
|
-
old_token = "token_#{rand(10**10)}"
|
1129
|
-
new_token = "token_#{rand(10**10)}"
|
1130
|
-
customer = Braintree::Customer.create!(
|
1131
|
-
:credit_card => {
|
1132
|
-
:cardholder_name => "Old Cardholder Name",
|
1133
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1134
|
-
:expiration_date => "05/2012",
|
1135
|
-
:token => old_token
|
1136
|
-
}
|
1137
|
-
)
|
1138
|
-
credit_card = customer.credit_cards[0]
|
1139
|
-
params = {
|
1140
|
-
:credit_card => {
|
1141
|
-
:cardholder_name => "New Cardholder Name",
|
1142
|
-
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1143
|
-
:expiration_date => "05/2014"
|
1144
|
-
}
|
1145
|
-
}
|
1146
|
-
tr_data_params = {
|
1147
|
-
:payment_method_token => old_token,
|
1148
|
-
:credit_card => {
|
1149
|
-
:token => new_token
|
1150
|
-
}
|
1151
|
-
}
|
1152
|
-
tr_data = Braintree::TransparentRedirect.update_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
1153
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.update_credit_card_url)
|
1154
|
-
result = Braintree::CreditCard.update_from_transparent_redirect(query_string_response)
|
1155
|
-
result.success?.should == true
|
1156
|
-
credit_card = result.credit_card
|
1157
|
-
credit_card.cardholder_name.should == "New Cardholder Name"
|
1158
|
-
credit_card.masked_number.should == "555555******4444"
|
1159
|
-
credit_card.expiration_date.should == "05/2014"
|
1160
|
-
credit_card.token.should == new_token
|
1161
|
-
end
|
1162
|
-
|
1163
|
-
it "updates the default credit card" do
|
1164
|
-
customer = Braintree::Customer.create!(
|
1165
|
-
:credit_card => {
|
1166
|
-
:cardholder_name => "Old Cardholder Name",
|
1167
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1168
|
-
:expiration_date => "05/2012"
|
1169
|
-
}
|
1170
|
-
)
|
1171
|
-
card1 = customer.credit_cards[0]
|
1172
|
-
|
1173
|
-
card2 = Braintree::CreditCard.create(
|
1174
|
-
:customer_id => customer.id,
|
1175
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1176
|
-
:expiration_date => "05/2009"
|
1177
|
-
).credit_card
|
1178
|
-
|
1179
|
-
card1.should be_default
|
1180
|
-
card2.should_not be_default
|
1181
|
-
|
1182
|
-
params = {
|
1183
|
-
:credit_card => {
|
1184
|
-
:options => {:make_default => true}
|
1185
|
-
}
|
1186
|
-
}
|
1187
|
-
tr_data_params = {
|
1188
|
-
:payment_method_token => card2.token
|
1189
|
-
}
|
1190
|
-
tr_data = Braintree::TransparentRedirect.update_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
1191
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.update_credit_card_url)
|
1192
|
-
result = Braintree::CreditCard.update_from_transparent_redirect(query_string_response)
|
1193
|
-
|
1194
|
-
Braintree::CreditCard.find(card1.token).should_not be_default
|
1195
|
-
Braintree::CreditCard.find(card2.token).should be_default
|
1196
|
-
end
|
1197
|
-
end
|
1198
|
-
|
1199
|
-
describe "credit" do
|
1200
|
-
it "creates a credit transaction using the customer, returning a result object" do
|
1201
|
-
customer = Braintree::Customer.create!(
|
1202
|
-
:credit_card => {
|
1203
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1204
|
-
:expiration_date => "05/2010"
|
1205
|
-
}
|
1206
|
-
)
|
1207
|
-
result = customer.credit_cards[0].credit(
|
1208
|
-
:amount => "100.00"
|
1209
|
-
)
|
1210
|
-
result.success?.should == true
|
1211
|
-
result.transaction.amount.should == BigDecimal("100.00")
|
1212
|
-
result.transaction.type.should == "credit"
|
1213
|
-
result.transaction.customer_details.id.should == customer.id
|
1214
|
-
result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
|
1215
|
-
result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
1216
|
-
result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
1217
|
-
result.transaction.credit_card_details.expiration_date.should == "05/2010"
|
1218
|
-
end
|
1219
|
-
end
|
1220
|
-
|
1221
|
-
describe "credit!" do
|
1222
|
-
it "returns the created credit tranaction if valid" do
|
1223
|
-
customer = Braintree::Customer.create!(
|
1224
|
-
:credit_card => {
|
1225
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1226
|
-
:expiration_date => "05/2010"
|
1227
|
-
}
|
1228
|
-
)
|
1229
|
-
transaction = customer.credit_cards[0].credit!(:amount => "100.00")
|
1230
|
-
transaction.amount.should == BigDecimal("100.00")
|
1231
|
-
transaction.type.should == "credit"
|
1232
|
-
transaction.customer_details.id.should == customer.id
|
1233
|
-
transaction.credit_card_details.token.should == customer.credit_cards[0].token
|
1234
|
-
transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
1235
|
-
transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
1236
|
-
transaction.credit_card_details.expiration_date.should == "05/2010"
|
1237
|
-
end
|
1238
|
-
|
1239
|
-
it "raises a ValidationsFailed if invalid" do
|
1240
|
-
customer = Braintree::Customer.create!(
|
1241
|
-
:credit_card => {
|
1242
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1243
|
-
:expiration_date => "05/2010"
|
1244
|
-
}
|
1245
|
-
)
|
1246
|
-
expect do
|
1247
|
-
customer.credit_cards[0].credit!(:amount => "invalid")
|
1248
|
-
end.to raise_error(Braintree::ValidationsFailed)
|
1249
|
-
end
|
1250
|
-
end
|
1251
|
-
|
1252
1135
|
describe "self.delete" do
|
1253
1136
|
it "deletes the credit card" do
|
1254
1137
|
customer = Braintree::Customer.create.customer
|
@@ -1490,266 +1373,35 @@ describe Braintree::CreditCard do
|
|
1490
1373
|
end
|
1491
1374
|
end
|
1492
1375
|
|
1493
|
-
describe "
|
1494
|
-
it "
|
1495
|
-
customer = Braintree::Customer.create!(
|
1496
|
-
:credit_card => {
|
1497
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1498
|
-
:expiration_date => "05/2010"
|
1499
|
-
}
|
1500
|
-
)
|
1501
|
-
result = customer.credit_cards[0].sale(
|
1502
|
-
:amount => "100.00"
|
1503
|
-
)
|
1504
|
-
result.success?.should == true
|
1505
|
-
result.transaction.amount.should == BigDecimal("100.00")
|
1506
|
-
result.transaction.type.should == "sale"
|
1507
|
-
result.transaction.customer_details.id.should == customer.id
|
1508
|
-
result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
|
1509
|
-
result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
1510
|
-
result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
1511
|
-
result.transaction.credit_card_details.expiration_date.should == "05/2010"
|
1512
|
-
end
|
1513
|
-
end
|
1514
|
-
|
1515
|
-
describe "sale!" do
|
1516
|
-
it "returns the created sale tranaction if valid" do
|
1517
|
-
customer = Braintree::Customer.create!(
|
1518
|
-
:credit_card => {
|
1519
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1520
|
-
:expiration_date => "05/2010"
|
1521
|
-
}
|
1522
|
-
)
|
1523
|
-
transaction = customer.credit_cards[0].sale!(:amount => "100.00")
|
1524
|
-
transaction.amount.should == BigDecimal("100.00")
|
1525
|
-
transaction.type.should == "sale"
|
1526
|
-
transaction.customer_details.id.should == customer.id
|
1527
|
-
transaction.credit_card_details.token.should == customer.credit_cards[0].token
|
1528
|
-
transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
1529
|
-
transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
1530
|
-
transaction.credit_card_details.expiration_date.should == "05/2010"
|
1531
|
-
end
|
1532
|
-
|
1533
|
-
it "raises a ValidationsFailed if invalid" do
|
1534
|
-
customer = Braintree::Customer.create!(
|
1535
|
-
:credit_card => {
|
1536
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1537
|
-
:expiration_date => "05/2010"
|
1538
|
-
}
|
1539
|
-
)
|
1540
|
-
expect do
|
1541
|
-
customer.credit_cards[0].sale!(:amount => "invalid")
|
1542
|
-
end.to raise_error(Braintree::ValidationsFailed)
|
1543
|
-
end
|
1544
|
-
end
|
1545
|
-
|
1546
|
-
describe "update" do
|
1547
|
-
it "updates the credit card" do
|
1548
|
-
customer = Braintree::Customer.create!
|
1549
|
-
credit_card = Braintree::CreditCard.create!(
|
1550
|
-
:cardholder_name => "Original Holder",
|
1551
|
-
:customer_id => customer.id,
|
1552
|
-
:cvv => "123",
|
1553
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1554
|
-
:expiration_date => "05/2012"
|
1555
|
-
)
|
1556
|
-
update_result = credit_card.update(
|
1557
|
-
:cardholder_name => "New Holder",
|
1558
|
-
:cvv => "456",
|
1559
|
-
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1560
|
-
:expiration_date => "06/2013"
|
1561
|
-
)
|
1562
|
-
update_result.success?.should == true
|
1563
|
-
update_result.credit_card.should == credit_card
|
1564
|
-
updated_credit_card = update_result.credit_card
|
1565
|
-
updated_credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
|
1566
|
-
updated_credit_card.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
|
1567
|
-
updated_credit_card.expiration_date.should == "06/2013"
|
1568
|
-
updated_credit_card.cardholder_name.should == "New Holder"
|
1569
|
-
end
|
1570
|
-
|
1571
|
-
it "verifies the update if options[verify_card]=true" do
|
1572
|
-
customer = Braintree::Customer.create!
|
1573
|
-
credit_card = Braintree::CreditCard.create!(
|
1574
|
-
:cardholder_name => "Original Holder",
|
1575
|
-
:customer_id => customer.id,
|
1576
|
-
:cvv => "123",
|
1577
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1578
|
-
:expiration_date => "05/2012"
|
1579
|
-
)
|
1580
|
-
update_result = credit_card.update(
|
1581
|
-
:cardholder_name => "New Holder",
|
1582
|
-
:cvv => "456",
|
1583
|
-
:number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
|
1584
|
-
:expiration_date => "06/2013",
|
1585
|
-
:options => {:verify_card => true}
|
1586
|
-
)
|
1587
|
-
update_result.success?.should == false
|
1588
|
-
update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
|
1589
|
-
end
|
1590
|
-
|
1591
|
-
it "fails on create if credit_card[options][fail_on_duplicate_payment_method]=true and there is a duplicated payment method" do
|
1592
|
-
customer = Braintree::Customer.create!
|
1593
|
-
Braintree::CreditCard.create(
|
1594
|
-
:customer_id => customer.id,
|
1595
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1596
|
-
:expiration_date => "05/2015"
|
1597
|
-
)
|
1598
|
-
|
1599
|
-
result = Braintree::CreditCard.create(
|
1600
|
-
:customer_id => customer.id,
|
1601
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1602
|
-
:expiration_date => "05/2015",
|
1603
|
-
:options => {:fail_on_duplicate_payment_method => true}
|
1604
|
-
)
|
1605
|
-
|
1606
|
-
result.success?.should == false
|
1607
|
-
result.errors.for(:credit_card).on(:number)[0].message.should == "Duplicate card exists in the vault."
|
1608
|
-
end
|
1609
|
-
|
1610
|
-
it "allows user to specify merchant account for verification" do
|
1376
|
+
describe "nonce" do
|
1377
|
+
it "returns the credit card nonce" do
|
1611
1378
|
customer = Braintree::Customer.create!
|
1612
1379
|
credit_card = Braintree::CreditCard.create!(
|
1613
1380
|
:cardholder_name => "Original Holder",
|
1614
1381
|
:customer_id => customer.id,
|
1615
|
-
:cvv => "123",
|
1616
1382
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1617
1383
|
:expiration_date => "05/2012"
|
1618
1384
|
)
|
1619
|
-
update_result = credit_card.update(
|
1620
|
-
:number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
|
1621
|
-
:expiration_date => "05/2009",
|
1622
|
-
:options => {
|
1623
|
-
:verify_card => true,
|
1624
|
-
:verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
|
1625
|
-
}
|
1626
|
-
)
|
1627
|
-
update_result.success?.should == false
|
1628
|
-
update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
|
1629
|
-
update_result.credit_card_verification.processor_response_code.should == "2000"
|
1630
|
-
update_result.credit_card_verification.processor_response_text.should == "Do Not Honor"
|
1631
|
-
update_result.credit_card_verification.cvv_response_code.should == "I"
|
1632
|
-
update_result.credit_card_verification.avs_error_response_code.should == nil
|
1633
|
-
update_result.credit_card_verification.avs_postal_code_response_code.should == "I"
|
1634
|
-
update_result.credit_card_verification.avs_street_address_response_code.should == "I"
|
1635
|
-
end
|
1636
|
-
|
1637
|
-
it "can update the billing address" do
|
1638
|
-
customer = Braintree::Customer.create!
|
1639
|
-
credit_card = Braintree::CreditCard.create!(
|
1640
|
-
:cardholder_name => "Original Holder",
|
1641
|
-
:customer_id => customer.id,
|
1642
|
-
:cvv => "123",
|
1643
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1644
|
-
:expiration_date => "05/2012",
|
1645
|
-
:billing_address => {
|
1646
|
-
:first_name => "Old First Name",
|
1647
|
-
:last_name => "Old Last Name",
|
1648
|
-
:company => "Old Company",
|
1649
|
-
:street_address => "123 Old St",
|
1650
|
-
:extended_address => "Apt Old",
|
1651
|
-
:locality => "Old City",
|
1652
|
-
:region => "Old State",
|
1653
|
-
:postal_code => "12345",
|
1654
|
-
:country_name => "Canada"
|
1655
|
-
}
|
1656
|
-
)
|
1657
|
-
result = credit_card.update(
|
1658
|
-
:options => {:verify_card => false},
|
1659
|
-
:billing_address => {
|
1660
|
-
:first_name => "New First Name",
|
1661
|
-
:last_name => "New Last Name",
|
1662
|
-
:company => "New Company",
|
1663
|
-
:street_address => "123 New St",
|
1664
|
-
:extended_address => "Apt New",
|
1665
|
-
:locality => "New City",
|
1666
|
-
:region => "New State",
|
1667
|
-
:postal_code => "56789",
|
1668
|
-
:country_name => "United States of America"
|
1669
|
-
}
|
1670
|
-
)
|
1671
|
-
result.success?.should == true
|
1672
|
-
address = result.credit_card.billing_address
|
1673
|
-
address.should == credit_card.billing_address # making sure credit card instance was updated
|
1674
|
-
address.first_name.should == "New First Name"
|
1675
|
-
address.last_name.should == "New Last Name"
|
1676
|
-
address.company.should == "New Company"
|
1677
|
-
address.street_address.should == "123 New St"
|
1678
|
-
address.extended_address.should == "Apt New"
|
1679
|
-
address.locality.should == "New City"
|
1680
|
-
address.region.should == "New State"
|
1681
|
-
address.postal_code.should == "56789"
|
1682
|
-
address.country_name.should == "United States of America"
|
1683
|
-
end
|
1684
1385
|
|
1685
|
-
|
1686
|
-
customer = Braintree::Customer.create!
|
1687
|
-
credit_card = Braintree::CreditCard.create!(
|
1688
|
-
:cardholder_name => "Original Holder",
|
1689
|
-
:customer_id => customer.id,
|
1690
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1691
|
-
:expiration_date => "05/2012"
|
1692
|
-
)
|
1693
|
-
update_result = credit_card.update(
|
1694
|
-
:cardholder_name => "New Holder",
|
1695
|
-
:number => "invalid",
|
1696
|
-
:expiration_date => "05/2014"
|
1697
|
-
)
|
1698
|
-
update_result.success?.should == false
|
1699
|
-
update_result.errors.for(:credit_card).on(:number)[0].message.should == "Credit card number must be 12-19 digits."
|
1386
|
+
credit_card.nonce.should_not be_nil
|
1700
1387
|
end
|
1701
1388
|
end
|
1702
1389
|
|
1703
|
-
describe "
|
1704
|
-
it "
|
1705
|
-
|
1706
|
-
credit_card
|
1707
|
-
:cardholder_name => "Original Holder",
|
1708
|
-
:customer_id => customer.id,
|
1709
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1710
|
-
:expiration_date => "05/2012"
|
1711
|
-
)
|
1712
|
-
credit_card.update!(
|
1713
|
-
:cardholder_name => "New Holder",
|
1714
|
-
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1715
|
-
:expiration_date => "06/2013"
|
1716
|
-
).should == credit_card
|
1717
|
-
credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
|
1718
|
-
credit_card.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
|
1719
|
-
credit_card.expiration_date.should == "06/2013"
|
1720
|
-
credit_card.cardholder_name.should == "New Holder"
|
1721
|
-
credit_card.updated_at.between?(Time.now - 60, Time.now).should == true
|
1390
|
+
describe "card on file network tokenization" do
|
1391
|
+
it "should find a network tokenized credit card" do
|
1392
|
+
credit_card = Braintree::CreditCard.find("network_tokenized_credit_card")
|
1393
|
+
credit_card.is_network_tokenized?.should == true
|
1722
1394
|
end
|
1723
1395
|
|
1724
|
-
it "
|
1396
|
+
it "should find a non-network tokenized credit card" do
|
1725
1397
|
customer = Braintree::Customer.create!
|
1726
|
-
credit_card = Braintree::CreditCard.create
|
1727
|
-
:cardholder_name => "Original Holder",
|
1728
|
-
:customer_id => customer.id,
|
1729
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1730
|
-
:expiration_date => "05/2012"
|
1731
|
-
)
|
1732
|
-
expect do
|
1733
|
-
credit_card.update!(
|
1734
|
-
:cardholder_name => "New Holder",
|
1735
|
-
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1736
|
-
:expiration_date => "invalid/date"
|
1737
|
-
)
|
1738
|
-
end.to raise_error(Braintree::ValidationsFailed)
|
1739
|
-
end
|
1740
|
-
end
|
1741
|
-
|
1742
|
-
describe "nonce" do
|
1743
|
-
it "returns the credit card nonce" do
|
1744
|
-
customer = Braintree::Customer.create!
|
1745
|
-
credit_card = Braintree::CreditCard.create!(
|
1746
|
-
:cardholder_name => "Original Holder",
|
1398
|
+
credit_card = Braintree::CreditCard.create(
|
1747
1399
|
:customer_id => customer.id,
|
1748
1400
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1749
|
-
:expiration_date => "05/
|
1750
|
-
)
|
1751
|
-
|
1752
|
-
|
1401
|
+
:expiration_date => "05/2009"
|
1402
|
+
).credit_card
|
1403
|
+
credit_card_vaulted = Braintree::CreditCard.find(credit_card.token)
|
1404
|
+
credit_card_vaulted.is_network_tokenized?.should == false
|
1753
1405
|
end
|
1754
1406
|
end
|
1755
1407
|
end
|