braintree 2.104.1 → 3.0.1

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 (80) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +6 -3
  4. data/lib/braintree.rb +3 -17
  5. data/lib/braintree/address.rb +0 -22
  6. data/lib/braintree/base_module.rb +6 -0
  7. data/lib/braintree/configuration.rb +1 -1
  8. data/lib/braintree/credit_card.rb +0 -75
  9. data/lib/braintree/credit_card_gateway.rb +3 -32
  10. data/lib/braintree/credit_card_verification.rb +13 -0
  11. data/lib/braintree/customer.rb +3 -74
  12. data/lib/braintree/customer_gateway.rb +0 -23
  13. data/lib/braintree/dispute.rb +1 -7
  14. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  15. data/lib/braintree/dispute_gateway.rb +2 -7
  16. data/lib/braintree/error_codes.rb +139 -170
  17. data/lib/braintree/exceptions.rb +5 -3
  18. data/lib/braintree/gateway.rb +0 -14
  19. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +1 -2
  20. data/lib/braintree/merchant_account_gateway.rb +2 -0
  21. data/lib/braintree/payment_instrument_type.rb +1 -5
  22. data/lib/braintree/payment_method_gateway.rb +4 -9
  23. data/lib/braintree/payment_method_parser.rb +1 -8
  24. data/lib/braintree/subscription.rb +5 -5
  25. data/lib/braintree/successful_result.rb +0 -1
  26. data/lib/braintree/test/nonce.rb +4 -23
  27. data/lib/braintree/transaction.rb +2 -79
  28. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  29. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  30. data/lib/braintree/transaction/subscription_details.rb +2 -0
  31. data/lib/braintree/transaction_gateway.rb +12 -21
  32. data/lib/braintree/transaction_search.rb +0 -1
  33. data/lib/braintree/util.rb +17 -2
  34. data/lib/braintree/version.rb +2 -2
  35. data/lib/braintree/webhook_notification.rb +0 -10
  36. data/lib/braintree/webhook_testing_gateway.rb +0 -43
  37. data/lib/braintree/xml/libxml.rb +1 -0
  38. data/lib/braintree/xml/parser.rb +11 -34
  39. data/spec/integration/braintree/address_spec.rb +2 -89
  40. data/spec/integration/braintree/client_api/spec_helper.rb +0 -26
  41. data/spec/integration/braintree/credit_card_spec.rb +6 -471
  42. data/spec/integration/braintree/customer_spec.rb +22 -362
  43. data/spec/integration/braintree/dispute_search_spec.rb +2 -2
  44. data/spec/integration/braintree/dispute_spec.rb +1 -2
  45. data/spec/integration/braintree/payment_method_spec.rb +77 -120
  46. data/spec/integration/braintree/subscription_spec.rb +11 -16
  47. data/spec/integration/braintree/transaction_search_spec.rb +3 -3
  48. data/spec/integration/braintree/transaction_spec.rb +83 -511
  49. data/spec/integration/spec_helper.rb +1 -4
  50. data/spec/spec_helper.rb +1 -11
  51. data/spec/unit/braintree/address_spec.rb +0 -8
  52. data/spec/unit/braintree/credit_card_spec.rb +1 -20
  53. data/spec/unit/braintree/customer_spec.rb +0 -12
  54. data/spec/unit/braintree/dispute_spec.rb +1 -12
  55. data/spec/unit/braintree/http_spec.rb +3 -3
  56. data/spec/unit/braintree/transaction_spec.rb +1 -35
  57. data/spec/unit/braintree/util_spec.rb +37 -3
  58. data/spec/unit/braintree/webhook_notification_spec.rb +1 -1
  59. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  60. metadata +26 -30
  61. data/lib/braintree/amex_express_checkout_card.rb +0 -40
  62. data/lib/braintree/coinbase_account.rb +0 -34
  63. data/lib/braintree/europe_bank_account.rb +0 -36
  64. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  65. data/lib/braintree/ideal_payment.rb +0 -61
  66. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  67. data/lib/braintree/masterpass_card.rb +0 -83
  68. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  69. data/lib/braintree/transaction/coinbase_details.rb +0 -16
  70. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  71. data/lib/braintree/transaction/masterpass_card_details.rb +0 -49
  72. data/lib/braintree/transparent_redirect.rb +0 -40
  73. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  74. data/lib/braintree/xml/rexml.rb +0 -71
  75. data/spec/hacks/tcp_socket.rb +0 -18
  76. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  77. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  78. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  79. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
  80. data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
@@ -28,7 +28,6 @@ module Braintree
28
28
  :paypal_authorization_id,
29
29
  :paypal_payer_email,
30
30
  :processor_authorization_code,
31
- :europe_bank_account_iban,
32
31
  :settlement_batch_id,
33
32
  :shipping_company,
34
33
  :shipping_country_name,
@@ -53,6 +53,8 @@ module Braintree
53
53
  raise AuthorizationError, message
54
54
  when 404
55
55
  raise NotFoundError
56
+ when 408
57
+ raise RequestTimeoutError
56
58
  when 426
57
59
  raise UpgradeRequiredError, "Please upgrade your client library."
58
60
  when 429
@@ -60,7 +62,9 @@ module Braintree
60
62
  when 500
61
63
  raise ServerError
62
64
  when 503
63
- raise DownForMaintenanceError
65
+ raise ServiceUnavailableError
66
+ when 504
67
+ raise GatewayTimeoutError
64
68
  else
65
69
  raise UnexpectedError, "Unexpected HTTP_RESPONSE #{status_code.to_i}"
66
70
  end
@@ -87,7 +91,7 @@ module Braintree
87
91
  when "INTERNAL"
88
92
  raise ServerError
89
93
  when "SERVICE_AVAILABILITY"
90
- raise DownForMaintenanceError
94
+ raise ServiceUnavailableError
91
95
  else
92
96
  raise UnexpectedError, "Unexpected Response: #{error[:message]}"
93
97
  end
@@ -126,6 +130,17 @@ module Braintree
126
130
  !invalid_keys.any?
127
131
  end
128
132
 
133
+ def self.replace_key(hash, target_key, replacement_key)
134
+ hash.inject({}) do |new_hash, (key, value)|
135
+ if value.is_a?(Hash)
136
+ value = replace_key(value, target_key, replacement_key)
137
+ end
138
+
139
+ key = replacement_key if key == target_key
140
+ new_hash.merge(key => value)
141
+ end
142
+ end
143
+
129
144
  def self._flatten_valid_keys(valid_keys, namespace = nil)
130
145
  valid_keys.inject([]) do |result, key|
131
146
  if key.is_a?(Hash)
@@ -1,7 +1,7 @@
1
1
  module Braintree
2
2
  module Version
3
- Major = 2
4
- Minor = 104
3
+ Major = 3
4
+ Minor = 0
5
5
  Tiny = 1
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Tiny}"
@@ -36,18 +36,10 @@ module Braintree
36
36
 
37
37
  AccountUpdaterDailyReport = "account_updater_daily_report"
38
38
 
39
- # NEXT_MAJOR_VERSION Remove this class as legacy Ideal has been removed/disabled in the Braintree Gateway
40
- # DEPRECATED If you're looking to accept iDEAL as a payment method contact accounts@braintreepayments.com for a solution.
41
- IdealPaymentComplete = "ideal_payment_complete"
42
- IdealPaymentFailed = "ideal_payment_failed"
43
-
44
39
  OAuthAccessRevoked = "oauth_access_revoked"
45
40
  ConnectedMerchantStatusTransitioned = "connected_merchant_status_transitioned"
46
41
  ConnectedMerchantPayPalStatusChanged = "connected_merchant_paypal_status_changed"
47
42
 
48
- # NEXT_MAJOR_VERSION remove GrantedPaymentInstrumentUpdate. Kind is not sent by Braintree Gateway.
49
- # Kind will either be GrantorUpdatedGrantedPaymentMethod or RecipientUpdatedGrantedPaymentMethod.
50
- GrantedPaymentInstrumentUpdate = "granted_payment_instrument_update"
51
43
  GrantorUpdatedGrantedPaymentMethod = "grantor_updated_granted_payment_method"
52
44
  RecipientUpdatedGrantedPaymentMethod = "recipient_updated_granted_payment_method"
53
45
  GrantedPaymentInstrumentRevoked = "granted_payment_instrument_revoked"
@@ -63,7 +55,6 @@ module Braintree
63
55
  attr_reader :dispute
64
56
  attr_reader :granted_payment_instrument_update
65
57
  attr_reader :revoked_payment_method_metadata
66
- attr_reader :ideal_payment
67
58
  attr_reader :kind
68
59
  attr_reader :local_payment_completed
69
60
  attr_reader :oauth_access_revocation
@@ -93,7 +84,6 @@ module Braintree
93
84
  @disbursement = Disbursement._new(gateway, @subject[:disbursement]) if @subject.has_key?(:disbursement)
94
85
  @dispute = Dispute._new(@subject[:dispute]) if @subject.has_key?(:dispute)
95
86
  @account_updater_daily_report = AccountUpdaterDailyReport._new(@subject[:account_updater_daily_report]) if @subject.has_key?(:account_updater_daily_report)
96
- @ideal_payment = Braintree::IdealPayment._new(gateway, @subject[:ideal_payment]) if @subject.has_key?(:ideal_payment)
97
87
  @connected_merchant_status_transitioned = ConnectedMerchantStatusTransitioned._new(@subject[:connected_merchant_status_transitioned]) if @subject.has_key?(:connected_merchant_status_transitioned)
98
88
  @connected_merchant_paypal_status_changed = ConnectedMerchantPayPalStatusChanged._new(@subject[:connected_merchant_paypal_status_changed]) if @subject.has_key?(:connected_merchant_paypal_status_changed)
99
89
  @granted_payment_instrument_update = GrantedPaymentInstrumentUpdate._new(@subject[:granted_payment_instrument_update]) if @subject.has_key?(:granted_payment_instrument_update)
@@ -78,17 +78,6 @@ module Braintree
78
78
  _auth_status_transitioned_sample_xml(id)
79
79
  when Braintree::WebhookNotification::Kind::ConnectedMerchantPayPalStatusChanged
80
80
  _auth_paypal_status_changed_sample_xml(id)
81
- # NEXT_MAJOR_VERSION Remove this class as legacy Ideal has been removed/disabled in the Braintree Gateway
82
- # DEPRECATED If you're looking to accept iDEAL as a payment method contact accounts@braintreepayments.com for a solution.
83
- when Braintree::WebhookNotification::Kind::IdealPaymentComplete
84
- _ideal_payment_complete_sample_xml(id)
85
- # NEXT_MAJOR_VERSION Remove this class as legacy Ideal has been removed/disabled in the Braintree Gateway
86
- # DEPRECATED If you're looking to accept iDEAL as a payment method contact accounts@braintreepayments.com for a solution.
87
- when Braintree::WebhookNotification::Kind::IdealPaymentFailed
88
- _ideal_payment_failed_sample_xml(id)
89
- # NEXT_MAJOR_VERSION remove GrantedPaymentInstrumentUpdate
90
- when Braintree::WebhookNotification::Kind::GrantedPaymentInstrumentUpdate
91
- _granted_payment_instrument_update_sample_xml(id)
92
81
  when Braintree::WebhookNotification::Kind::GrantorUpdatedGrantedPaymentMethod
93
82
  _granted_payment_instrument_update_sample_xml(id)
94
83
  when Braintree::WebhookNotification::Kind::RecipientUpdatedGrantedPaymentMethod
@@ -867,38 +856,6 @@ module Braintree
867
856
  XML
868
857
  end
869
858
 
870
- def _ideal_payment_complete_sample_xml(id)
871
- <<-XML
872
- <ideal-payment>
873
- <id>#{id}</id>
874
- <status>COMPLETE</status>
875
- <issuer>ABCISSUER</issuer>
876
- <order-id>ORDERABC</order-id>
877
- <currency>EUR</currency>
878
- <amount>10.00</amount>
879
- <created-at>2016-11-29T23:27:34.547Z</created-at>
880
- <approval-url>https://example.com</approval-url>
881
- <ideal-transaction-id>1234567890</ideal-transaction-id>
882
- </ideal-payment>
883
- XML
884
- end
885
-
886
- def _ideal_payment_failed_sample_xml(id)
887
- <<-XML
888
- <ideal-payment>
889
- <id>#{id}</id>
890
- <status>FAILED</status>
891
- <issuer>ABCISSUER</issuer>
892
- <order-id>ORDERABC</order-id>
893
- <currency>EUR</currency>
894
- <amount>10.00</amount>
895
- <created-at>2016-11-29T23:27:34.547Z</created-at>
896
- <approval-url>https://example.com</approval-url>
897
- <ideal-transaction-id>1234567890</ideal-transaction-id>
898
- </ideal-payment>
899
- XML
900
- end
901
-
902
859
  def _granted_payment_instrument_update_sample_xml(id)
903
860
  <<-XML
904
861
  <granted-payment-instrument-update>
@@ -1,3 +1,4 @@
1
+ require 'libxml'
1
2
  # Portions of this code were copied and modified from Ruby on Rails, released
2
3
  # under the MIT license, copyright (c) 2005-2009 David Heinemeier Hansson
3
4
  module Braintree
@@ -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, parser = _determine_parser)
15
- standardized_hash_structure = parser.parse(xml)
16
- with_underscores_in_keys = _unrename_keys(standardized_hash_structure)
17
- typecasted_xml = _typecast_xml_value(with_underscores_in_keys)
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
- def self._determine_parser
22
- # LibXML causes a segfault in Ruby 2.0.0. We need to fall back to Rexml to prevent this segfault.
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| _typecast_xml_value(v) }
31
+ entries.collect { |v| _transform_xml(v) }
41
32
  when "Hash"
42
- [_typecast_xml_value(entries)]
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] = _typecast_xml_value(v)
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| _typecast_xml_value(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 typecast #{value.class.name} - #{value.inspect}"
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
- address.delete.success?.should == true
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
@@ -136,32 +136,6 @@ def generate_valid_plaid_us_bank_account_nonce
136
136
  json["data"]["tokenizeUsBankLogin"]["paymentMethod"]["id"]
137
137
  end
138
138
 
139
- def generate_valid_ideal_payment_nonce(amount = Braintree::Test::TransactionAmounts::Authorize)
140
- raw_client_token = Braintree::ClientToken.generate(:merchant_account_id => "ideal_merchant_account")
141
- client_token = decode_client_token(raw_client_token)
142
- client = ClientApiHttp.new(
143
- Braintree::Configuration.instantiate,
144
- :authorization_fingerprint => client_token["authorizationFingerprint"],
145
- )
146
- config = JSON.parse(client.get_configuration.body)
147
-
148
- braintree_api = client_token["braintree_api"]
149
- url = braintree_api["url"] + "/ideal-payments"
150
-
151
- token = braintree_api["access_token"]
152
- payload = {
153
- :issuer => "RABONL2U",
154
- :order_id => SpecHelper::DefaultOrderId,
155
- :amount => amount,
156
- :currency => "EUR",
157
- :redirect_url => "https://braintree-api.com",
158
- :route_id => config["ideal"]["routeId"]
159
- }
160
-
161
- json = _cosmos_post(token, url, payload)
162
- json["data"]["id"]
163
- end
164
-
165
139
  def sample(arr)
166
140
  6.times.map { arr[rand(arr.length)] }.join
167
141
  end
@@ -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
- :device_session_id => "abc123",
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::Transaction::Status::ProcessorDeclined
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::Transaction::Status::ProcessorDeclined
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::Transaction::GatewayRejectionReason::CVV
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::Transaction::Status::ProcessorDeclined
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"
@@ -773,95 +772,6 @@ describe Braintree::CreditCard do
773
772
  end
774
773
  end
775
774
 
776
- describe "self.create_from_transparent_redirect" do
777
- it "returns a successful result if successful" do
778
- result = Braintree::Customer.create
779
- result.success?.should == true
780
- customer = result.customer
781
- params = {
782
- :credit_card => {
783
- :cardholder_name => "Card Holder",
784
- :number => Braintree::Test::CreditCardNumbers::Visa,
785
- :expiration_date => "05/2012"
786
- }
787
- }
788
- tr_data_params = {
789
- :credit_card => {
790
- :customer_id => customer.id
791
- }
792
- }
793
- tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
794
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.create_credit_card_url)
795
- result = Braintree::CreditCard.create_from_transparent_redirect(query_string_response)
796
- result.success?.should == true
797
- credit_card = result.credit_card
798
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
799
- credit_card.cardholder_name.should == "Card Holder"
800
- credit_card.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
801
- credit_card.expiration_month.should == "05"
802
- credit_card.expiration_year.should == "2012"
803
- credit_card.expiration_date.should == "05/2012"
804
- credit_card.customer_id.should == customer.id
805
- end
806
-
807
- it "create card as default" do
808
- customer = Braintree::Customer.create!(
809
- :credit_card => {
810
- :cardholder_name => "Old Cardholder Name",
811
- :number => Braintree::Test::CreditCardNumbers::Visa,
812
- :expiration_date => "05/2012"
813
- }
814
- )
815
- card1 = customer.credit_cards[0]
816
-
817
- params = {
818
- :credit_card => {
819
- :cardholder_name => "Card Holder",
820
- :number => Braintree::Test::CreditCardNumbers::Visa,
821
- :expiration_date => "05/2012",
822
- :options => {:make_default => true}
823
- }
824
- }
825
- tr_data_params = {
826
- :credit_card => {
827
- :customer_id => customer.id
828
- }
829
- }
830
- tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
831
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.create_credit_card_url)
832
- result = Braintree::CreditCard.create_from_transparent_redirect(query_string_response)
833
- result.success?.should == true
834
- card2 = result.credit_card
835
-
836
- Braintree::CreditCard.find(card1.token).should_not be_default
837
- card2.should be_default
838
- end
839
-
840
- it "returns xml with nested errors if validation errors" do
841
- customer = Braintree::Customer.create.customer
842
- params = {
843
- :credit_card => {
844
- :cardholder_name => "Card Holder",
845
- :number => "eleventy",
846
- :expiration_date => "y2k"
847
- }
848
- }
849
- tr_data_params = {
850
- :credit_card => {
851
- :customer_id => customer.id
852
- }
853
- }
854
- tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
855
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.create_credit_card_url)
856
- result = Braintree::CreditCard.create_from_transparent_redirect(query_string_response)
857
- result.success?.should == false
858
- result.params[:customer_id] == customer.id
859
- result.params[:credit_card]["cardholder_name"] == customer.id
860
- result.params[:credit_card]["number"] == "eleventy"
861
- result.params[:credit_card]["exipiration_date"] == "y2k"
862
- end
863
- end
864
-
865
775
  describe "self.update" do
866
776
  it "updates the credit card" do
867
777
  customer = Braintree::Customer.create!
@@ -1053,7 +963,7 @@ describe Braintree::CreditCard do
1053
963
  :options => {:verify_card => true}
1054
964
  )
1055
965
  update_result.success?.should == false
1056
- update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
966
+ update_result.credit_card_verification.status.should == Braintree::CreditCardVerification::Status::ProcessorDeclined
1057
967
  update_result.credit_card_verification.gateway_rejection_reason.should be_nil
1058
968
  end
1059
969
 
@@ -1222,132 +1132,6 @@ describe Braintree::CreditCard do
1222
1132
  end
1223
1133
  end
1224
1134
 
1225
- describe "self.update_from_transparent_redirect" do
1226
- it "updates the credit card" do
1227
- old_token = "token_#{rand(10**10)}"
1228
- new_token = "token_#{rand(10**10)}"
1229
- customer = Braintree::Customer.create!(
1230
- :credit_card => {
1231
- :cardholder_name => "Old Cardholder Name",
1232
- :number => Braintree::Test::CreditCardNumbers::Visa,
1233
- :expiration_date => "05/2012",
1234
- :token => old_token
1235
- }
1236
- )
1237
- credit_card = customer.credit_cards[0]
1238
- params = {
1239
- :credit_card => {
1240
- :cardholder_name => "New Cardholder Name",
1241
- :number => Braintree::Test::CreditCardNumbers::MasterCard,
1242
- :expiration_date => "05/2014"
1243
- }
1244
- }
1245
- tr_data_params = {
1246
- :payment_method_token => old_token,
1247
- :credit_card => {
1248
- :token => new_token
1249
- }
1250
- }
1251
- tr_data = Braintree::TransparentRedirect.update_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1252
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.update_credit_card_url)
1253
- result = Braintree::CreditCard.update_from_transparent_redirect(query_string_response)
1254
- result.success?.should == true
1255
- credit_card = result.credit_card
1256
- credit_card.cardholder_name.should == "New Cardholder Name"
1257
- credit_card.masked_number.should == "555555******4444"
1258
- credit_card.expiration_date.should == "05/2014"
1259
- credit_card.token.should == new_token
1260
- end
1261
-
1262
- it "updates the default credit card" do
1263
- customer = Braintree::Customer.create!(
1264
- :credit_card => {
1265
- :cardholder_name => "Old Cardholder Name",
1266
- :number => Braintree::Test::CreditCardNumbers::Visa,
1267
- :expiration_date => "05/2012"
1268
- }
1269
- )
1270
- card1 = customer.credit_cards[0]
1271
-
1272
- card2 = Braintree::CreditCard.create(
1273
- :customer_id => customer.id,
1274
- :number => Braintree::Test::CreditCardNumbers::Visa,
1275
- :expiration_date => "05/2009"
1276
- ).credit_card
1277
-
1278
- card1.should be_default
1279
- card2.should_not be_default
1280
-
1281
- params = {
1282
- :credit_card => {
1283
- :options => {:make_default => true}
1284
- }
1285
- }
1286
- tr_data_params = {
1287
- :payment_method_token => card2.token
1288
- }
1289
- tr_data = Braintree::TransparentRedirect.update_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1290
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.update_credit_card_url)
1291
- result = Braintree::CreditCard.update_from_transparent_redirect(query_string_response)
1292
-
1293
- Braintree::CreditCard.find(card1.token).should_not be_default
1294
- Braintree::CreditCard.find(card2.token).should be_default
1295
- end
1296
- end
1297
-
1298
- describe "credit" do
1299
- it "creates a credit transaction using the customer, returning a result object" do
1300
- customer = Braintree::Customer.create!(
1301
- :credit_card => {
1302
- :number => Braintree::Test::CreditCardNumbers::Visa,
1303
- :expiration_date => "05/2010"
1304
- }
1305
- )
1306
- result = customer.credit_cards[0].credit(
1307
- :amount => "100.00"
1308
- )
1309
- result.success?.should == true
1310
- result.transaction.amount.should == BigDecimal("100.00")
1311
- result.transaction.type.should == "credit"
1312
- result.transaction.customer_details.id.should == customer.id
1313
- result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
1314
- result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
1315
- result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
1316
- result.transaction.credit_card_details.expiration_date.should == "05/2010"
1317
- end
1318
- end
1319
-
1320
- describe "credit!" do
1321
- it "returns the created credit tranaction if valid" do
1322
- customer = Braintree::Customer.create!(
1323
- :credit_card => {
1324
- :number => Braintree::Test::CreditCardNumbers::Visa,
1325
- :expiration_date => "05/2010"
1326
- }
1327
- )
1328
- transaction = customer.credit_cards[0].credit!(:amount => "100.00")
1329
- transaction.amount.should == BigDecimal("100.00")
1330
- transaction.type.should == "credit"
1331
- transaction.customer_details.id.should == customer.id
1332
- transaction.credit_card_details.token.should == customer.credit_cards[0].token
1333
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
1334
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
1335
- transaction.credit_card_details.expiration_date.should == "05/2010"
1336
- end
1337
-
1338
- it "raises a ValidationsFailed if invalid" do
1339
- customer = Braintree::Customer.create!(
1340
- :credit_card => {
1341
- :number => Braintree::Test::CreditCardNumbers::Visa,
1342
- :expiration_date => "05/2010"
1343
- }
1344
- )
1345
- expect do
1346
- customer.credit_cards[0].credit!(:amount => "invalid")
1347
- end.to raise_error(Braintree::ValidationsFailed)
1348
- end
1349
- end
1350
-
1351
1135
  describe "self.delete" do
1352
1136
  it "deletes the credit card" do
1353
1137
  customer = Braintree::Customer.create.customer
@@ -1589,255 +1373,6 @@ describe Braintree::CreditCard do
1589
1373
  end
1590
1374
  end
1591
1375
 
1592
- describe "sale" do
1593
- it "creates a sale transaction using the credit card, returning a result object" do
1594
- customer = Braintree::Customer.create!(
1595
- :credit_card => {
1596
- :number => Braintree::Test::CreditCardNumbers::Visa,
1597
- :expiration_date => "05/2010"
1598
- }
1599
- )
1600
- result = customer.credit_cards[0].sale(
1601
- :amount => "100.00"
1602
- )
1603
- result.success?.should == true
1604
- result.transaction.amount.should == BigDecimal("100.00")
1605
- result.transaction.type.should == "sale"
1606
- result.transaction.customer_details.id.should == customer.id
1607
- result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
1608
- result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
1609
- result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
1610
- result.transaction.credit_card_details.expiration_date.should == "05/2010"
1611
- end
1612
- end
1613
-
1614
- describe "sale!" do
1615
- it "returns the created sale tranaction if valid" do
1616
- customer = Braintree::Customer.create!(
1617
- :credit_card => {
1618
- :number => Braintree::Test::CreditCardNumbers::Visa,
1619
- :expiration_date => "05/2010"
1620
- }
1621
- )
1622
- transaction = customer.credit_cards[0].sale!(:amount => "100.00")
1623
- transaction.amount.should == BigDecimal("100.00")
1624
- transaction.type.should == "sale"
1625
- transaction.customer_details.id.should == customer.id
1626
- transaction.credit_card_details.token.should == customer.credit_cards[0].token
1627
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
1628
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
1629
- transaction.credit_card_details.expiration_date.should == "05/2010"
1630
- end
1631
-
1632
- it "raises a ValidationsFailed if invalid" do
1633
- customer = Braintree::Customer.create!(
1634
- :credit_card => {
1635
- :number => Braintree::Test::CreditCardNumbers::Visa,
1636
- :expiration_date => "05/2010"
1637
- }
1638
- )
1639
- expect do
1640
- customer.credit_cards[0].sale!(:amount => "invalid")
1641
- end.to raise_error(Braintree::ValidationsFailed)
1642
- end
1643
- end
1644
-
1645
- describe "update" do
1646
- it "updates the credit card" do
1647
- customer = Braintree::Customer.create!
1648
- credit_card = Braintree::CreditCard.create!(
1649
- :cardholder_name => "Original Holder",
1650
- :customer_id => customer.id,
1651
- :cvv => "123",
1652
- :number => Braintree::Test::CreditCardNumbers::Visa,
1653
- :expiration_date => "05/2012"
1654
- )
1655
- update_result = credit_card.update(
1656
- :cardholder_name => "New Holder",
1657
- :cvv => "456",
1658
- :number => Braintree::Test::CreditCardNumbers::MasterCard,
1659
- :expiration_date => "06/2013"
1660
- )
1661
- update_result.success?.should == true
1662
- update_result.credit_card.should == credit_card
1663
- updated_credit_card = update_result.credit_card
1664
- updated_credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
1665
- updated_credit_card.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
1666
- updated_credit_card.expiration_date.should == "06/2013"
1667
- updated_credit_card.cardholder_name.should == "New Holder"
1668
- end
1669
-
1670
- it "verifies the update if options[verify_card]=true" do
1671
- customer = Braintree::Customer.create!
1672
- credit_card = Braintree::CreditCard.create!(
1673
- :cardholder_name => "Original Holder",
1674
- :customer_id => customer.id,
1675
- :cvv => "123",
1676
- :number => Braintree::Test::CreditCardNumbers::Visa,
1677
- :expiration_date => "05/2012"
1678
- )
1679
- update_result = credit_card.update(
1680
- :cardholder_name => "New Holder",
1681
- :cvv => "456",
1682
- :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
1683
- :expiration_date => "06/2013",
1684
- :options => {:verify_card => true}
1685
- )
1686
- update_result.success?.should == false
1687
- update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
1688
- end
1689
-
1690
- it "fails on create if credit_card[options][fail_on_duplicate_payment_method]=true and there is a duplicated payment method" do
1691
- customer = Braintree::Customer.create!
1692
- Braintree::CreditCard.create(
1693
- :customer_id => customer.id,
1694
- :number => Braintree::Test::CreditCardNumbers::Visa,
1695
- :expiration_date => "05/2015"
1696
- )
1697
-
1698
- result = Braintree::CreditCard.create(
1699
- :customer_id => customer.id,
1700
- :number => Braintree::Test::CreditCardNumbers::Visa,
1701
- :expiration_date => "05/2015",
1702
- :options => {:fail_on_duplicate_payment_method => true}
1703
- )
1704
-
1705
- result.success?.should == false
1706
- result.errors.for(:credit_card).on(:number)[0].message.should == "Duplicate card exists in the vault."
1707
- end
1708
-
1709
- it "allows user to specify merchant account for verification" do
1710
- customer = Braintree::Customer.create!
1711
- credit_card = Braintree::CreditCard.create!(
1712
- :cardholder_name => "Original Holder",
1713
- :customer_id => customer.id,
1714
- :cvv => "123",
1715
- :number => Braintree::Test::CreditCardNumbers::Visa,
1716
- :expiration_date => "05/2012"
1717
- )
1718
- update_result = credit_card.update(
1719
- :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
1720
- :expiration_date => "05/2009",
1721
- :options => {
1722
- :verify_card => true,
1723
- :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
1724
- }
1725
- )
1726
- update_result.success?.should == false
1727
- update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
1728
- update_result.credit_card_verification.processor_response_code.should == "2000"
1729
- update_result.credit_card_verification.processor_response_text.should == "Do Not Honor"
1730
- update_result.credit_card_verification.cvv_response_code.should == "I"
1731
- update_result.credit_card_verification.avs_error_response_code.should == nil
1732
- update_result.credit_card_verification.avs_postal_code_response_code.should == "I"
1733
- update_result.credit_card_verification.avs_street_address_response_code.should == "I"
1734
- end
1735
-
1736
- it "can update the billing address" do
1737
- customer = Braintree::Customer.create!
1738
- credit_card = Braintree::CreditCard.create!(
1739
- :cardholder_name => "Original Holder",
1740
- :customer_id => customer.id,
1741
- :cvv => "123",
1742
- :number => Braintree::Test::CreditCardNumbers::Visa,
1743
- :expiration_date => "05/2012",
1744
- :billing_address => {
1745
- :first_name => "Old First Name",
1746
- :last_name => "Old Last Name",
1747
- :company => "Old Company",
1748
- :street_address => "123 Old St",
1749
- :extended_address => "Apt Old",
1750
- :locality => "Old City",
1751
- :region => "Old State",
1752
- :postal_code => "12345",
1753
- :country_name => "Canada"
1754
- }
1755
- )
1756
- result = credit_card.update(
1757
- :options => {:verify_card => false},
1758
- :billing_address => {
1759
- :first_name => "New First Name",
1760
- :last_name => "New Last Name",
1761
- :company => "New Company",
1762
- :street_address => "123 New St",
1763
- :extended_address => "Apt New",
1764
- :locality => "New City",
1765
- :region => "New State",
1766
- :postal_code => "56789",
1767
- :country_name => "United States of America"
1768
- }
1769
- )
1770
- result.success?.should == true
1771
- address = result.credit_card.billing_address
1772
- address.should == credit_card.billing_address # making sure credit card instance was updated
1773
- address.first_name.should == "New First Name"
1774
- address.last_name.should == "New Last Name"
1775
- address.company.should == "New Company"
1776
- address.street_address.should == "123 New St"
1777
- address.extended_address.should == "Apt New"
1778
- address.locality.should == "New City"
1779
- address.region.should == "New State"
1780
- address.postal_code.should == "56789"
1781
- address.country_name.should == "United States of America"
1782
- end
1783
-
1784
- it "returns an error response if invalid" do
1785
- customer = Braintree::Customer.create!
1786
- credit_card = Braintree::CreditCard.create!(
1787
- :cardholder_name => "Original Holder",
1788
- :customer_id => customer.id,
1789
- :number => Braintree::Test::CreditCardNumbers::Visa,
1790
- :expiration_date => "05/2012"
1791
- )
1792
- update_result = credit_card.update(
1793
- :cardholder_name => "New Holder",
1794
- :number => "invalid",
1795
- :expiration_date => "05/2014"
1796
- )
1797
- update_result.success?.should == false
1798
- update_result.errors.for(:credit_card).on(:number)[0].message.should == "Credit card number must be 12-19 digits."
1799
- end
1800
- end
1801
-
1802
- describe "update!" do
1803
- it "updates the credit card and returns true if valid" do
1804
- customer = Braintree::Customer.create!
1805
- credit_card = Braintree::CreditCard.create!(
1806
- :cardholder_name => "Original Holder",
1807
- :customer_id => customer.id,
1808
- :number => Braintree::Test::CreditCardNumbers::Visa,
1809
- :expiration_date => "05/2012"
1810
- )
1811
- credit_card.update!(
1812
- :cardholder_name => "New Holder",
1813
- :number => Braintree::Test::CreditCardNumbers::MasterCard,
1814
- :expiration_date => "06/2013"
1815
- ).should == credit_card
1816
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
1817
- credit_card.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
1818
- credit_card.expiration_date.should == "06/2013"
1819
- credit_card.cardholder_name.should == "New Holder"
1820
- credit_card.updated_at.between?(Time.now - 60, Time.now).should == true
1821
- end
1822
-
1823
- it "raises a ValidationsFailed if invalid" do
1824
- customer = Braintree::Customer.create!
1825
- credit_card = Braintree::CreditCard.create!(
1826
- :cardholder_name => "Original Holder",
1827
- :customer_id => customer.id,
1828
- :number => Braintree::Test::CreditCardNumbers::Visa,
1829
- :expiration_date => "05/2012"
1830
- )
1831
- expect do
1832
- credit_card.update!(
1833
- :cardholder_name => "New Holder",
1834
- :number => Braintree::Test::CreditCardNumbers::MasterCard,
1835
- :expiration_date => "invalid/date"
1836
- )
1837
- end.to raise_error(Braintree::ValidationsFailed)
1838
- end
1839
- end
1840
-
1841
1376
  describe "nonce" do
1842
1377
  it "returns the credit card nonce" do
1843
1378
  customer = Braintree::Customer.create!