braintree 2.102.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) 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/address_gateway.rb +2 -2
  7. data/lib/braintree/base_module.rb +6 -0
  8. data/lib/braintree/bin_data.rb +9 -2
  9. data/lib/braintree/configuration.rb +1 -1
  10. data/lib/braintree/credit_card.rb +5 -76
  11. data/lib/braintree/credit_card_gateway.rb +3 -32
  12. data/lib/braintree/credit_card_verification.rb +14 -0
  13. data/lib/braintree/customer.rb +3 -72
  14. data/lib/braintree/customer_gateway.rb +0 -23
  15. data/lib/braintree/dispute.rb +1 -7
  16. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  17. data/lib/braintree/dispute/transaction.rb +2 -0
  18. data/lib/braintree/dispute_gateway.rb +2 -7
  19. data/lib/braintree/error_codes.rb +152 -170
  20. data/lib/braintree/exceptions.rb +5 -3
  21. data/lib/braintree/gateway.rb +0 -14
  22. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +1 -1
  23. data/lib/braintree/local_payment_completed.rb +1 -1
  24. data/lib/braintree/merchant_account_gateway.rb +2 -0
  25. data/lib/braintree/payment_instrument_type.rb +1 -4
  26. data/lib/braintree/payment_method_gateway.rb +4 -8
  27. data/lib/braintree/payment_method_parser.rb +1 -7
  28. data/lib/braintree/risk_data.rb +4 -1
  29. data/lib/braintree/subscription.rb +5 -5
  30. data/lib/braintree/successful_result.rb +0 -1
  31. data/lib/braintree/test/credit_card.rb +1 -0
  32. data/lib/braintree/test/nonce.rb +5 -20
  33. data/lib/braintree/transaction.rb +9 -73
  34. data/lib/braintree/transaction/address_details.rb +11 -0
  35. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  36. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  37. data/lib/braintree/transaction/paypal_details.rb +3 -0
  38. data/lib/braintree/transaction/subscription_details.rb +2 -0
  39. data/lib/braintree/transaction_gateway.rb +14 -21
  40. data/lib/braintree/transaction_search.rb +0 -1
  41. data/lib/braintree/util.rb +17 -2
  42. data/lib/braintree/version.rb +2 -2
  43. data/lib/braintree/webhook_notification.rb +0 -10
  44. data/lib/braintree/webhook_testing_gateway.rb +0 -43
  45. data/lib/braintree/xml/libxml.rb +1 -0
  46. data/lib/braintree/xml/parser.rb +11 -34
  47. data/spec/integration/braintree/address_spec.rb +2 -89
  48. data/spec/integration/braintree/client_api/spec_helper.rb +92 -66
  49. data/spec/integration/braintree/credit_card_spec.rb +20 -467
  50. data/spec/integration/braintree/credit_card_verification_spec.rb +1 -0
  51. data/spec/integration/braintree/customer_spec.rb +22 -362
  52. data/spec/integration/braintree/dispute_search_spec.rb +3 -3
  53. data/spec/integration/braintree/dispute_spec.rb +1 -2
  54. data/spec/integration/braintree/merchant_spec.rb +2 -2
  55. data/spec/integration/braintree/payment_method_spec.rb +77 -120
  56. data/spec/integration/braintree/paypal_account_spec.rb +1 -1
  57. data/spec/integration/braintree/subscription_spec.rb +11 -16
  58. data/spec/integration/braintree/transaction_search_spec.rb +3 -3
  59. data/spec/integration/braintree/transaction_spec.rb +274 -524
  60. data/spec/integration/spec_helper.rb +1 -4
  61. data/spec/spec_helper.rb +1 -11
  62. data/spec/unit/braintree/address_spec.rb +0 -8
  63. data/spec/unit/braintree/credit_card_spec.rb +28 -21
  64. data/spec/unit/braintree/credit_card_verification_spec.rb +7 -0
  65. data/spec/unit/braintree/customer_spec.rb +4 -12
  66. data/spec/unit/braintree/dispute_spec.rb +4 -12
  67. data/spec/unit/braintree/http_spec.rb +3 -3
  68. data/spec/unit/braintree/local_payment_completed_spec.rb +14 -0
  69. data/spec/unit/braintree/transaction/paypal_details_spec.rb +59 -0
  70. data/spec/unit/braintree/transaction_spec.rb +17 -37
  71. data/spec/unit/braintree/util_spec.rb +37 -3
  72. data/spec/unit/braintree/webhook_notification_spec.rb +1 -1
  73. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  74. metadata +28 -32
  75. data/lib/braintree/amex_express_checkout_card.rb +0 -38
  76. data/lib/braintree/coinbase_account.rb +0 -34
  77. data/lib/braintree/europe_bank_account.rb +0 -36
  78. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  79. data/lib/braintree/ideal_payment.rb +0 -61
  80. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  81. data/lib/braintree/masterpass_card.rb +0 -81
  82. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  83. data/lib/braintree/transaction/coinbase_details.rb +0 -16
  84. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  85. data/lib/braintree/transaction/masterpass_card_details.rb +0 -47
  86. data/lib/braintree/transparent_redirect.rb +0 -40
  87. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  88. data/lib/braintree/xml/rexml.rb +0 -71
  89. data/spec/hacks/tcp_socket.rb +0 -18
  90. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  91. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  92. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  93. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
  94. data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
@@ -56,83 +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
- raw_client_token = Braintree::ClientToken.generate
60
- client_token = decode_client_token(raw_client_token)
59
+ query = %{
60
+ mutation TokenizeUsBankAccount($input: TokenizeUsBankAccountInput!) {
61
+ tokenizeUsBankAccount(input: $input) {
62
+ paymentMethod {
63
+ id
64
+ }
65
+ }
66
+ }
67
+ }
61
68
 
62
- url = client_token["braintree_api"]["url"] + "/tokens"
63
- token = client_token["braintree_api"]["access_token"]
64
- payload = {
65
- :type => "us_bank_account",
66
- :billing_address => {
67
- :street_address => "123 Ave",
68
- :region => "CA",
69
- :locality => "San Francisco",
70
- :postal_code => "94112"
71
- },
72
- :account_type => "checking",
73
- :routing_number => "021000021",
74
- :account_number => account_number,
75
- :first_name => "John",
76
- :last_name => "Doe",
77
- :ownership_type => "personal",
78
- :ach_mandate => {
79
- :text => "cl mandate text"
69
+ variables = {
70
+ :input => {
71
+ :usBankAccount => {
72
+ :accountNumber => account_number,
73
+ :routingNumber => "021000021",
74
+ :accountType => "CHECKING",
75
+ :individualOwner => {
76
+ :firstName => "John",
77
+ :lastName => "Doe",
78
+ },
79
+ :billingAddress => {
80
+ :streetAddress => "123 Ave",
81
+ :state => "CA",
82
+ :city => "San Francisco",
83
+ :zipCode => "94112"
84
+ },
85
+ :achMandate => "cl mandate text"
86
+ }
80
87
  }
81
88
  }
82
89
 
83
- json = _cosmos_post(token, url, payload)
84
- json["data"]["id"]
90
+ graphql_request = {
91
+ :query => query,
92
+ :variables => variables
93
+ }
94
+
95
+ json = _send_graphql_request(graphql_request)
96
+ json["data"]["tokenizeUsBankAccount"]["paymentMethod"]["id"]
85
97
  end
86
98
 
87
99
  def generate_valid_plaid_us_bank_account_nonce
88
- raw_client_token = Braintree::ClientToken.generate
89
- client_token = decode_client_token(raw_client_token)
90
-
91
- url = client_token["braintree_api"]["url"] + "/tokens"
92
- token = client_token["braintree_api"]["access_token"]
93
- payload = {
94
- :type => "plaid_public_token",
95
- :public_token => "good",
96
- :account_id => "plaid_account_id",
97
- :ownership_type => "business",
98
- :business_name => "PayPal, Inc.",
99
- :billing_address => {
100
- :street_address => "123 Ave",
101
- :region => "CA",
102
- :locality => "San Francisco",
103
- :postal_code => "94112"
104
- },
105
- :ach_mandate => {
106
- :text => "cl mandate text"
100
+ query = %{
101
+ mutation TokenizeUsBankLogin($input: TokenizeUsBankLoginInput!) {
102
+ tokenizeUsBankLogin(input: $input) {
103
+ paymentMethod {
104
+ id
105
+ }
106
+ }
107
107
  }
108
108
  }
109
109
 
110
- json = _cosmos_post(token, url, payload)
111
- json["data"]["id"]
112
- end
110
+ variables = {
111
+ :input => {
112
+ :usBankLogin => {
113
+ :publicToken => "good",
114
+ :accountId => "plaid_account_id",
115
+ :accountType => "CHECKING",
116
+ :businessOwner => {
117
+ :businessName => "PayPal, Inc.",
118
+ },
119
+ :billingAddress => {
120
+ :streetAddress => "123 Ave",
121
+ :state => "CA",
122
+ :city => "San Francisco",
123
+ :zipCode => "94112"
124
+ },
125
+ :achMandate => "cl mandate text"
126
+ }
127
+ }
128
+ }
113
129
 
114
- def generate_valid_ideal_payment_nonce(amount = Braintree::Test::TransactionAmounts::Authorize)
115
- raw_client_token = Braintree::ClientToken.generate(:merchant_account_id => "ideal_merchant_account")
116
- client_token = decode_client_token(raw_client_token)
117
- client = ClientApiHttp.new(
118
- Braintree::Configuration.instantiate,
119
- :authorization_fingerprint => client_token["authorizationFingerprint"],
120
- )
121
- config = JSON.parse(client.get_configuration.body)
122
-
123
- token = client_token["braintree_api"]["access_token"]
124
- url = client_token["braintree_api"]["url"] + "/ideal-payments"
125
- payload = {
126
- :issuer => "RABONL2U",
127
- :order_id => SpecHelper::DefaultOrderId,
128
- :amount => amount,
129
- :currency => "EUR",
130
- :redirect_url => "https://braintree-api.com",
131
- :route_id => config["ideal"]["routeId"]
130
+ graphql_request = {
131
+ :query => query,
132
+ :variables => variables
132
133
  }
133
134
 
134
- json = _cosmos_post(token, url, payload)
135
- json["data"]["id"]
135
+ json = _send_graphql_request(graphql_request)
136
+ json["data"]["tokenizeUsBankLogin"]["paymentMethod"]["id"]
136
137
  end
137
138
 
138
139
  def sample(arr)
@@ -149,8 +150,10 @@ end
149
150
  def _cosmos_post(token, url, payload)
150
151
  uri = URI::parse(url)
151
152
  connection = Net::HTTP.new(uri.host, uri.port)
152
- connection.use_ssl = true
153
- connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
153
+ if uri.scheme == "https"
154
+ connection.use_ssl = true
155
+ connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
156
+ end
154
157
  resp = connection.start do |http|
155
158
  request = Net::HTTP::Post.new(uri.path)
156
159
  request["Content-Type"] = "application/json"
@@ -163,6 +166,29 @@ def _cosmos_post(token, url, payload)
163
166
  JSON.parse(resp.body)
164
167
  end
165
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
+
166
192
  class ClientApiHttp
167
193
  attr_reader :config, :options
168
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
- :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,266 +1373,35 @@ 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
1376
+ describe "nonce" do
1377
+ it "returns the credit card nonce" do
1710
1378
  customer = Braintree::Customer.create!
1711
1379
  credit_card = Braintree::CreditCard.create!(
1712
1380
  :cardholder_name => "Original Holder",
1713
1381
  :customer_id => customer.id,
1714
- :cvv => "123",
1715
1382
  :number => Braintree::Test::CreditCardNumbers::Visa,
1716
1383
  :expiration_date => "05/2012"
1717
1384
  )
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
1385
 
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."
1386
+ credit_card.nonce.should_not be_nil
1799
1387
  end
1800
1388
  end
1801
1389
 
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)
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
1838
1394
  end
1839
- end
1840
1395
 
1841
- describe "nonce" do
1842
- it "returns the credit card nonce" do
1396
+ it "should find a non-network tokenized credit card" do
1843
1397
  customer = Braintree::Customer.create!
1844
- credit_card = Braintree::CreditCard.create!(
1845
- :cardholder_name => "Original Holder",
1398
+ credit_card = Braintree::CreditCard.create(
1846
1399
  :customer_id => customer.id,
1847
1400
  :number => Braintree::Test::CreditCardNumbers::Visa,
1848
- :expiration_date => "05/2012"
1849
- )
1850
-
1851
- credit_card.nonce.should_not be_nil
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
1852
1405
  end
1853
1406
  end
1854
1407
  end