braintree 2.104.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +7 -4
  4. data/lib/braintree.rb +7 -18
  5. data/lib/braintree/account_updater_daily_report.rb +1 -1
  6. data/lib/braintree/address.rb +1 -23
  7. data/lib/braintree/apple_pay.rb +1 -1
  8. data/lib/braintree/apple_pay_card.rb +1 -1
  9. data/lib/braintree/apple_pay_options.rb +1 -1
  10. data/lib/braintree/authorization_adjustment.rb +1 -1
  11. data/lib/braintree/base_module.rb +6 -0
  12. data/lib/braintree/bin_data.rb +9 -2
  13. data/lib/braintree/client_token.rb +1 -1
  14. data/lib/braintree/configuration.rb +12 -12
  15. data/lib/braintree/connected_merchant_paypal_status_changed.rb +1 -1
  16. data/lib/braintree/connected_merchant_status_transitioned.rb +1 -1
  17. data/lib/braintree/credit_card.rb +2 -77
  18. data/lib/braintree/credit_card_gateway.rb +7 -36
  19. data/lib/braintree/credit_card_verification.rb +18 -5
  20. data/lib/braintree/credit_card_verification_search.rb +1 -1
  21. data/lib/braintree/customer.rb +5 -76
  22. data/lib/braintree/customer_gateway.rb +0 -23
  23. data/lib/braintree/customer_search.rb +1 -1
  24. data/lib/braintree/disbursement.rb +1 -1
  25. data/lib/braintree/dispute.rb +2 -8
  26. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  27. data/lib/braintree/dispute_gateway.rb +4 -9
  28. data/lib/braintree/dispute_search.rb +2 -2
  29. data/lib/braintree/document_upload.rb +1 -1
  30. data/lib/braintree/error_codes.rb +151 -170
  31. data/lib/braintree/exceptions.rb +5 -3
  32. data/lib/braintree/gateway.rb +0 -14
  33. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +2 -3
  34. data/lib/braintree/granted_payment_instrument_update.rb +1 -1
  35. data/lib/braintree/graphql_client.rb +7 -7
  36. data/lib/braintree/http.rb +3 -3
  37. data/lib/braintree/local_payment_completed.rb +1 -1
  38. data/lib/braintree/local_payment_reversed.rb +19 -0
  39. data/lib/braintree/merchant.rb +1 -1
  40. data/lib/braintree/merchant_account.rb +1 -1
  41. data/lib/braintree/merchant_account_gateway.rb +3 -1
  42. data/lib/braintree/merchant_gateway.rb +1 -1
  43. data/lib/braintree/modification.rb +1 -1
  44. data/lib/braintree/oauth_credentials.rb +1 -1
  45. data/lib/braintree/oauth_gateway.rb +5 -5
  46. data/lib/braintree/payment_instrument_type.rb +10 -14
  47. data/lib/braintree/payment_method_gateway.rb +8 -13
  48. data/lib/braintree/payment_method_nonce_gateway.rb +1 -1
  49. data/lib/braintree/payment_method_parser.rb +1 -8
  50. data/lib/braintree/plan.rb +1 -1
  51. data/lib/braintree/processor_response_types.rb +3 -3
  52. data/lib/braintree/resource_collection.rb +8 -3
  53. data/lib/braintree/revoked_payment_method_metadata.rb +1 -1
  54. data/lib/braintree/risk_data.rb +3 -1
  55. data/lib/braintree/samsung_pay_card.rb +1 -1
  56. data/lib/braintree/settlement_batch_summary.rb +2 -2
  57. data/lib/braintree/subscription.rb +11 -11
  58. data/lib/braintree/successful_result.rb +0 -1
  59. data/lib/braintree/test/credit_card.rb +1 -0
  60. data/lib/braintree/test/nonce.rb +4 -23
  61. data/lib/braintree/three_d_secure_info.rb +22 -12
  62. data/lib/braintree/transaction.rb +44 -104
  63. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  64. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  65. data/lib/braintree/transaction/installment.rb +28 -0
  66. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  67. data/lib/braintree/transaction/paypal_details.rb +1 -0
  68. data/lib/braintree/transaction/subscription_details.rb +2 -0
  69. data/lib/braintree/transaction_gateway.rb +37 -25
  70. data/lib/braintree/transaction_line_item.rb +1 -1
  71. data/lib/braintree/transaction_search.rb +3 -2
  72. data/lib/braintree/unknown_payment_method.rb +1 -1
  73. data/lib/braintree/us_bank_account.rb +3 -3
  74. data/lib/braintree/us_bank_account_verification.rb +1 -1
  75. data/lib/braintree/us_bank_account_verification_gateway.rb +1 -1
  76. data/lib/braintree/util.rb +21 -6
  77. data/lib/braintree/venmo_account.rb +1 -1
  78. data/lib/braintree/version.rb +3 -3
  79. data/lib/braintree/visa_checkout_card.rb +2 -2
  80. data/lib/braintree/webhook_notification.rb +28 -29
  81. data/lib/braintree/webhook_notification_gateway.rb +5 -5
  82. data/lib/braintree/webhook_testing_gateway.rb +10 -43
  83. data/lib/braintree/xml/generator.rb +5 -4
  84. data/lib/braintree/xml/libxml.rb +1 -0
  85. data/lib/braintree/xml/parser.rb +21 -44
  86. data/spec/integration/braintree/add_on_spec.rb +1 -1
  87. data/spec/integration/braintree/address_spec.rb +26 -113
  88. data/spec/integration/braintree/advanced_search_spec.rb +45 -45
  89. data/spec/integration/braintree/apple_pay_spec.rb +3 -3
  90. data/spec/integration/braintree/braintree_gateway_spec.rb +2 -1
  91. data/spec/integration/braintree/client_api/client_token_spec.rb +14 -14
  92. data/spec/integration/braintree/client_api/spec_helper.rb +5 -31
  93. data/spec/integration/braintree/credit_card_spec.rb +130 -593
  94. data/spec/integration/braintree/credit_card_verification_search_spec.rb +2 -2
  95. data/spec/integration/braintree/credit_card_verification_spec.rb +1 -1
  96. data/spec/integration/braintree/customer_search_spec.rb +8 -8
  97. data/spec/integration/braintree/customer_spec.rb +336 -509
  98. data/spec/integration/braintree/dispute_search_spec.rb +6 -6
  99. data/spec/integration/braintree/dispute_spec.rb +6 -7
  100. data/spec/integration/braintree/error_codes_spec.rb +1 -1
  101. data/spec/integration/braintree/http_spec.rb +2 -2
  102. data/spec/integration/braintree/merchant_account_spec.rb +25 -26
  103. data/spec/integration/braintree/merchant_spec.rb +14 -14
  104. data/spec/integration/braintree/oauth_spec.rb +11 -11
  105. data/spec/integration/braintree/payment_method_nonce_spec.rb +12 -12
  106. data/spec/integration/braintree/payment_method_spec.rb +403 -269
  107. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +17 -13
  108. data/spec/integration/braintree/paypal_account_spec.rb +28 -28
  109. data/spec/integration/braintree/samsung_pay_card_spec.rb +9 -9
  110. data/spec/integration/braintree/settlement_batch_summary_spec.rb +8 -8
  111. data/spec/integration/braintree/subscription_spec.rb +144 -149
  112. data/spec/integration/braintree/test/transaction_amounts_spec.rb +2 -2
  113. data/spec/integration/braintree/test_transaction_spec.rb +10 -10
  114. data/spec/integration/braintree/transaction_search_spec.rb +96 -70
  115. data/spec/integration/braintree/transaction_spec.rb +832 -904
  116. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +32 -26
  117. data/spec/integration/braintree/us_bank_account_spec.rb +6 -6
  118. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +7 -7
  119. data/spec/integration/braintree/us_bank_account_verification_spec.rb +8 -8
  120. data/spec/integration/braintree/visa_checkout_card_spec.rb +5 -5
  121. data/spec/integration/spec_helper.rb +10 -7
  122. data/spec/oauth_test_helper.rb +1 -1
  123. data/spec/script/httpsd.rb +6 -6
  124. data/spec/spec_helper.rb +6 -14
  125. data/spec/unit/braintree/address_spec.rb +1 -9
  126. data/spec/unit/braintree/apple_pay_card_spec.rb +1 -1
  127. data/spec/unit/braintree/client_token_spec.rb +2 -2
  128. data/spec/unit/braintree/configuration_spec.rb +42 -42
  129. data/spec/unit/braintree/credit_card_spec.rb +9 -28
  130. data/spec/unit/braintree/credit_card_verification_search_spec.rb +1 -1
  131. data/spec/unit/braintree/credit_card_verification_spec.rb +8 -4
  132. data/spec/unit/braintree/customer_spec.rb +5 -16
  133. data/spec/unit/braintree/disbursement_spec.rb +7 -7
  134. data/spec/unit/braintree/dispute_spec.rb +9 -20
  135. data/spec/unit/braintree/error_result_spec.rb +5 -5
  136. data/spec/unit/braintree/errors_spec.rb +8 -8
  137. data/spec/unit/braintree/http_spec.rb +8 -8
  138. data/spec/unit/braintree/merchant_account_spec.rb +1 -1
  139. data/spec/unit/braintree/payment_method_spec.rb +1 -1
  140. data/spec/unit/braintree/paypal_account_spec.rb +2 -2
  141. data/spec/unit/braintree/resource_collection_spec.rb +30 -1
  142. data/spec/unit/braintree/risk_data_spec.rb +9 -5
  143. data/spec/unit/braintree/subscription_search_spec.rb +1 -1
  144. data/spec/unit/braintree/successful_result_spec.rb +1 -1
  145. data/spec/unit/braintree/three_d_secure_info_spec.rb +32 -14
  146. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +3 -3
  147. data/spec/unit/braintree/transaction/customer_details_spec.rb +1 -1
  148. data/spec/unit/braintree/transaction/deposit_details_spec.rb +2 -2
  149. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  150. data/spec/unit/braintree/transaction/paypal_details_spec.rb +3 -1
  151. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  152. data/spec/unit/braintree/transaction_spec.rb +25 -51
  153. data/spec/unit/braintree/util_spec.rb +55 -21
  154. data/spec/unit/braintree/validation_error_collection_spec.rb +36 -36
  155. data/spec/unit/braintree/webhook_notification_spec.rb +73 -57
  156. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  157. data/spec/unit/braintree/xml_spec.rb +31 -31
  158. metadata +30 -31
  159. data/lib/braintree/amex_express_checkout_card.rb +0 -40
  160. data/lib/braintree/coinbase_account.rb +0 -34
  161. data/lib/braintree/europe_bank_account.rb +0 -36
  162. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  163. data/lib/braintree/ideal_payment.rb +0 -61
  164. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  165. data/lib/braintree/masterpass_card.rb +0 -83
  166. data/lib/braintree/settlement_batch.rb +0 -0
  167. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  168. data/lib/braintree/transaction/coinbase_details.rb +0 -16
  169. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  170. data/lib/braintree/transaction/masterpass_card_details.rb +0 -49
  171. data/lib/braintree/transparent_redirect.rb +0 -40
  172. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  173. data/lib/braintree/xml/rexml.rb +0 -71
  174. data/spec/hacks/tcp_socket.rb +0 -18
  175. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  176. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  177. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  178. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
  179. data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require "json"
2
2
 
3
3
  def decode_client_token(raw_client_token)
4
4
  decoded_client_token_string = Base64.decode64(raw_client_token)
@@ -20,7 +20,7 @@ def _initialize_client(options)
20
20
  ClientApiHttp.new(Braintree::Configuration.instantiate,
21
21
  :authorization_fingerprint => client_token["authorizationFingerprint"],
22
22
  :shared_customer_identifier => "fake_identifier",
23
- :shared_customer_identifier_type => "testing"
23
+ :shared_customer_identifier_type => "testing",
24
24
  )
25
25
  end
26
26
 
@@ -42,7 +42,7 @@ def nonce_for_paypal_account(paypal_account_details)
42
42
  raw_client_token = Braintree::ClientToken.generate
43
43
  client_token = decode_client_token(raw_client_token)
44
44
  client = ClientApiHttp.new(Braintree::Configuration.instantiate,
45
- :authorization_fingerprint => client_token["authorizationFingerprint"]
45
+ :authorization_fingerprint => client_token["authorizationFingerprint"],
46
46
  )
47
47
 
48
48
  response = client.create_paypal_account(paypal_account_details)
@@ -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
@@ -309,7 +283,7 @@ class ClientApiHttp
309
283
  params.merge!(
310
284
  :authorization_fingerprint => @options[:authorization_fingerprint],
311
285
  :shared_customer_identifier => "fake_identifier",
312
- :shared_customer_identifier_type => "testing"
286
+ :shared_customer_identifier_type => "testing",
313
287
  )
314
288
 
315
289
  post("/merchants/#{config.merchant_id}/client_api/v1/payment_methods/credit_cards", params)
@@ -318,7 +292,7 @@ class ClientApiHttp
318
292
  def create_paypal_account(params)
319
293
  params = {:paypal_account => params}
320
294
  params.merge!(
321
- :authorization_fingerprint => @options[:authorization_fingerprint]
295
+ :authorization_fingerprint => @options[:authorization_fingerprint],
322
296
  )
323
297
 
324
298
  post("/merchants/#{config.merchant_id}/client_api/v1/payment_methods/paypal_accounts", params)
@@ -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
@@ -47,7 +46,7 @@ describe Braintree::CreditCard do
47
46
  :customer_id => customer.id,
48
47
  :number => Braintree::Test::CreditCardNumbers::Visa,
49
48
  :expiration_month => "05",
50
- :expiration_year => "2012"
49
+ :expiration_year => "2012",
51
50
  )
52
51
  result.success?.should == true
53
52
  credit_card = result.credit_card
@@ -64,7 +63,7 @@ describe Braintree::CreditCard do
64
63
  :number => Braintree::Test::CreditCardNumbers::Visa,
65
64
  :expiration_date => "05/2009",
66
65
  :cvv => "100",
67
- :token => token
66
+ :token => token,
68
67
  )
69
68
  result.success?.should == true
70
69
  credit_card = result.credit_card
@@ -82,7 +81,7 @@ describe Braintree::CreditCard do
82
81
  :customer_id => customer.id,
83
82
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
84
83
  :expiration_date => "05/2009",
85
- :billing_address_id => address.id
84
+ :billing_address_id => address.id,
86
85
  ).credit_card
87
86
 
88
87
  credit_card.billing_address.id.should == address.id
@@ -96,7 +95,7 @@ describe Braintree::CreditCard do
96
95
  :customer_id => customer.id,
97
96
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
98
97
  :expiration_date => "05/2009",
99
- :options => {}
98
+ :options => {},
100
99
  )
101
100
  result.success?.should == true
102
101
  end
@@ -107,10 +106,10 @@ describe Braintree::CreditCard do
107
106
  :customer_id => customer.id,
108
107
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
109
108
  :expiration_date => "05/2009",
110
- :options => {:verify_card => true}
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"
@@ -125,10 +124,10 @@ describe Braintree::CreditCard do
125
124
  :customer_id => customer.id,
126
125
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
127
126
  :expiration_date => "05/2009",
128
- :options => {:verify_card => true, :verification_amount => "100.00"}
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"
@@ -138,7 +137,7 @@ describe Braintree::CreditCard do
138
137
  end
139
138
 
140
139
  it "returns risk data on verification on credit_card create" do
141
- with_advanced_fraud_integration_merchant do
140
+ with_fraud_protection_enterprise_merchant do
142
141
  customer = Braintree::Customer.create!
143
142
  credit_card = Braintree::CreditCard.create!(
144
143
  :cardholder_name => "Original Holder",
@@ -146,13 +145,15 @@ describe Braintree::CreditCard do
146
145
  :cvv => "123",
147
146
  :number => Braintree::Test::CreditCardNumbers::Visa,
148
147
  :expiration_date => "05/2020",
149
- :options => {:verify_card => true}
148
+ :options => {:verify_card => true},
150
149
  )
151
150
  verification = credit_card.verification
152
- verification.risk_data.should respond_to(:id)
153
- verification.risk_data.should respond_to(:decision)
154
- verification.risk_data.should respond_to(:device_data_captured)
155
- verification.risk_data.should respond_to(:fraud_service_provider)
151
+ verification.risk_data.id.should_not be_nil
152
+ verification.risk_data.decision.should_not be_nil
153
+ verification.risk_data.decision_reasons.should_not be_nil
154
+ expect(verification.risk_data).to respond_to(:device_data_captured)
155
+ expect(verification.risk_data).to respond_to(:fraud_service_provider)
156
+ expect(verification.risk_data).to respond_to(:transaction_risk_score)
156
157
  end
157
158
  end
158
159
 
@@ -172,10 +173,10 @@ describe Braintree::CreditCard do
172
173
  :number => Braintree::Test::CreditCardNumbers::Visa,
173
174
  :expiration_date => "05/2009",
174
175
  :cvv => "200",
175
- :options => {:verify_card => true}
176
+ :options => {:verify_card => true},
176
177
  )
177
178
  result.success?.should == false
178
- result.credit_card_verification.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::CVV
179
+ result.credit_card_verification.gateway_rejection_reason.should == Braintree::CreditCardVerification::GatewayRejectionReason::CVV
179
180
  ensure
180
181
  Braintree::Configuration.merchant_id = old_merchant
181
182
  Braintree::Configuration.public_key = old_public_key
@@ -189,10 +190,10 @@ describe Braintree::CreditCard do
189
190
  :customer_id => customer.id,
190
191
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
191
192
  :expiration_date => "05/2009",
192
- :options => {:verify_card => true, :verification_amount => "1.01"}
193
+ :options => {:verify_card => true, :verification_amount => "1.01"},
193
194
  )
194
195
  result.success?.should == false
195
- result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
196
+ result.credit_card_verification.status.should == Braintree::CreditCardVerification::Status::ProcessorDeclined
196
197
  result.credit_card_verification.processor_response_code.should == "2000"
197
198
  result.credit_card_verification.processor_response_text.should == "Do Not Honor"
198
199
  result.credit_card_verification.cvv_response_code.should == "I"
@@ -210,7 +211,7 @@ describe Braintree::CreditCard do
210
211
  :options => {
211
212
  :verify_card => true,
212
213
  :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
213
- }
214
+ },
214
215
  )
215
216
  result.success?.should == false
216
217
  result.credit_card_verification.merchant_account_id.should == SpecHelper::NonDefaultMerchantAccountId
@@ -222,7 +223,7 @@ describe Braintree::CreditCard do
222
223
  :customer_id => customer.id,
223
224
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
224
225
  :expiration_date => "05/2009",
225
- :options => {:verify_card => false}
226
+ :options => {:verify_card => false},
226
227
  )
227
228
  result.success?.should == true
228
229
  end
@@ -233,15 +234,15 @@ describe Braintree::CreditCard do
233
234
  :customer_id => customer.id,
234
235
  :payment_method_nonce => Braintree::Test::Nonce::Transactable,
235
236
  :three_d_secure_pass_thru => {
236
- :eci_flag => '02',
237
- :cavv => 'some_cavv',
238
- :xid => 'some_xid',
239
- :authentication_response => 'Y',
240
- :directory_response => 'Y',
241
- :cavv_algorithm => '2',
242
- :ds_transaction_id => 'some_ds_transaction_id',
237
+ :eci_flag => "02",
238
+ :cavv => "some_cavv",
239
+ :xid => "some_xid",
240
+ :authentication_response => "Y",
241
+ :directory_response => "Y",
242
+ :cavv_algorithm => "2",
243
+ :ds_transaction_id => "some_ds_transaction_id",
243
244
  },
244
- :options => {:verify_card => true}
245
+ :options => {:verify_card => true},
245
246
  )
246
247
  expect(result).not_to be_success
247
248
  error = result.errors.for(:verification).first
@@ -255,16 +256,16 @@ describe Braintree::CreditCard do
255
256
  :customer_id => customer.id,
256
257
  :payment_method_nonce => Braintree::Test::Nonce::Transactable,
257
258
  :three_d_secure_pass_thru => {
258
- :eci_flag => '02',
259
- :cavv => 'some_cavv',
260
- :xid => 'some_xid',
261
- :three_d_secure_version => '1.0.2',
262
- :authentication_response => 'Y',
263
- :directory_response => 'Y',
264
- :cavv_algorithm => '2',
265
- :ds_transaction_id => 'some_ds_transaction_id',
259
+ :eci_flag => "02",
260
+ :cavv => "some_cavv",
261
+ :xid => "some_xid",
262
+ :three_d_secure_version => "1.0.2",
263
+ :authentication_response => "Y",
264
+ :directory_response => "Y",
265
+ :cavv_algorithm => "2",
266
+ :ds_transaction_id => "some_ds_transaction_id",
266
267
  },
267
- :options => {:verify_card => true}
268
+ :options => {:verify_card => true},
268
269
  )
269
270
  result.success?.should == true
270
271
 
@@ -275,7 +276,7 @@ describe Braintree::CreditCard do
275
276
  result = Braintree::CreditCard.create(
276
277
  :customer_id => customer.id,
277
278
  :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
278
- :options => {:verify_card => true}
279
+ :options => {:verify_card => true},
279
280
  )
280
281
  result.success?.should == true
281
282
 
@@ -303,7 +304,7 @@ describe Braintree::CreditCard do
303
304
  :locality => "Chicago",
304
305
  :region => "Illinois",
305
306
  :postal_code => "60622"
306
- }
307
+ },
307
308
  )
308
309
  result.success?.should == true
309
310
  credit_card = result.credit_card
@@ -322,7 +323,7 @@ describe Braintree::CreditCard do
322
323
  :country_code_alpha2 => "US",
323
324
  :country_code_alpha3 => "USA",
324
325
  :country_code_numeric => "840"
325
- }
326
+ },
326
327
  )
327
328
  result.success?.should == true
328
329
  credit_card = result.credit_card
@@ -341,7 +342,7 @@ describe Braintree::CreditCard do
341
342
  :billing_address => {
342
343
  :country_name => "Mexico",
343
344
  :country_code_alpha2 => "US"
344
- }
345
+ },
345
346
  )
346
347
  result.success?.should == false
347
348
  result.errors.for(:credit_card).for(:billing_address).on(:base).map { |e| e.code }.should include(Braintree::ErrorCodes::Address::InconsistentCountry)
@@ -352,7 +353,7 @@ describe Braintree::CreditCard do
352
353
  result = Braintree::CreditCard.create(
353
354
  :customer_id => customer.id,
354
355
  :number => Braintree::Test::CreditCardNumbers::Visa,
355
- :expiration_date => "invalid_date"
356
+ :expiration_date => "invalid_date",
356
357
  )
357
358
  result.success?.should == false
358
359
  result.errors.for(:credit_card).on(:expiration_date)[0].message.should == "Expiration date is invalid."
@@ -363,7 +364,7 @@ describe Braintree::CreditCard do
363
364
  card1 = Braintree::CreditCard.create(
364
365
  :customer_id => customer.id,
365
366
  :number => Braintree::Test::CreditCardNumbers::Visa,
366
- :expiration_date => "05/2009"
367
+ :expiration_date => "05/2009",
367
368
  ).credit_card
368
369
  card1.should be_default
369
370
 
@@ -373,7 +374,7 @@ describe Braintree::CreditCard do
373
374
  :expiration_date => "05/2009",
374
375
  :options => {
375
376
  :make_default => true
376
- }
377
+ },
377
378
  ).credit_card
378
379
  card2.should be_default
379
380
 
@@ -402,7 +403,7 @@ describe Braintree::CreditCard do
402
403
  :customer_id => customer.id,
403
404
  :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Prepaid,
404
405
  :expiration_date => "05/2014",
405
- :options => {:verify_card => true}
406
+ :options => {:verify_card => true},
406
407
  )
407
408
  credit_card = result.credit_card
408
409
  credit_card.prepaid.should == Braintree::CreditCard::Prepaid::Yes
@@ -414,7 +415,7 @@ describe Braintree::CreditCard do
414
415
  :customer_id => customer.id,
415
416
  :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Healthcare,
416
417
  :expiration_date => "05/2014",
417
- :options => {:verify_card => true}
418
+ :options => {:verify_card => true},
418
419
  )
419
420
  credit_card = result.credit_card
420
421
  credit_card.healthcare.should == Braintree::CreditCard::Healthcare::Yes
@@ -427,7 +428,7 @@ describe Braintree::CreditCard do
427
428
  :customer_id => customer.id,
428
429
  :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::DurbinRegulated,
429
430
  :expiration_date => "05/2014",
430
- :options => {:verify_card => true}
431
+ :options => {:verify_card => true},
431
432
  )
432
433
  credit_card = result.credit_card
433
434
  credit_card.durbin_regulated.should == Braintree::CreditCard::DurbinRegulated::Yes
@@ -439,7 +440,7 @@ describe Braintree::CreditCard do
439
440
  :customer_id => customer.id,
440
441
  :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::CountryOfIssuance,
441
442
  :expiration_date => "05/2014",
442
- :options => {:verify_card => true}
443
+ :options => {:verify_card => true},
443
444
  )
444
445
  credit_card = result.credit_card
445
446
  credit_card.country_of_issuance.should == Braintree::Test::CreditCardDefaults::CountryOfIssuance
@@ -451,7 +452,7 @@ describe Braintree::CreditCard do
451
452
  :customer_id => customer.id,
452
453
  :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::IssuingBank,
453
454
  :expiration_date => "05/2014",
454
- :options => {:verify_card => true}
455
+ :options => {:verify_card => true},
455
456
  )
456
457
  credit_card = result.credit_card
457
458
  credit_card.issuing_bank.should == Braintree::Test::CreditCardDefaults::IssuingBank
@@ -463,7 +464,7 @@ describe Braintree::CreditCard do
463
464
  :customer_id => customer.id,
464
465
  :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Payroll,
465
466
  :expiration_date => "05/2014",
466
- :options => {:verify_card => true}
467
+ :options => {:verify_card => true},
467
468
  )
468
469
  credit_card = result.credit_card
469
470
  credit_card.payroll.should == Braintree::CreditCard::Payroll::Yes
@@ -476,7 +477,7 @@ describe Braintree::CreditCard do
476
477
  :customer_id => customer.id,
477
478
  :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Debit,
478
479
  :expiration_date => "05/2014",
479
- :options => {:verify_card => true}
480
+ :options => {:verify_card => true},
480
481
  )
481
482
  credit_card = result.credit_card
482
483
  credit_card.debit.should == Braintree::CreditCard::Debit::Yes
@@ -488,7 +489,7 @@ describe Braintree::CreditCard do
488
489
  :customer_id => customer.id,
489
490
  :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Commercial,
490
491
  :expiration_date => "05/2014",
491
- :options => {:verify_card => true}
492
+ :options => {:verify_card => true},
492
493
  )
493
494
  credit_card = result.credit_card
494
495
  credit_card.commercial.should == Braintree::CreditCard::Commercial::Yes
@@ -500,7 +501,7 @@ describe Braintree::CreditCard do
500
501
  :customer_id => customer.id,
501
502
  :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::No,
502
503
  :expiration_date => "05/2014",
503
- :options => {:verify_card => true}
504
+ :options => {:verify_card => true},
504
505
  )
505
506
  credit_card = result.credit_card
506
507
  credit_card.prepaid.should == Braintree::CreditCard::Prepaid::No
@@ -518,7 +519,7 @@ describe Braintree::CreditCard do
518
519
  :customer_id => customer.id,
519
520
  :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Unknown,
520
521
  :expiration_date => "05/2014",
521
- :options => {:verify_card => true}
522
+ :options => {:verify_card => true},
522
523
  )
523
524
  credit_card = result.credit_card
524
525
  credit_card.prepaid.should == Braintree::CreditCard::Prepaid::Unknown
@@ -539,7 +540,7 @@ describe Braintree::CreditCard do
539
540
  customer = Braintree::Customer.create!
540
541
  result = Braintree::CreditCard.create(
541
542
  :customer_id => customer.id,
542
- :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::VisaPaymentMethodCode
543
+ :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::VisaPaymentMethodCode,
543
544
  )
544
545
  result.success?.should == true
545
546
  result.credit_card.venmo_sdk?.should == false
@@ -551,7 +552,7 @@ describe Braintree::CreditCard do
551
552
  customer = Braintree::Customer.create!
552
553
  result = Braintree::CreditCard.create(
553
554
  :customer_id => customer.id,
554
- :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::InvalidPaymentMethodCode
555
+ :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::InvalidPaymentMethodCode,
555
556
  )
556
557
 
557
558
  result.success?.should == false
@@ -570,7 +571,7 @@ describe Braintree::CreditCard do
570
571
  :cvv => "100",
571
572
  :options => {
572
573
  :venmo_sdk_session => Braintree::Test::VenmoSDK::Session
573
- }
574
+ },
574
575
  )
575
576
  result.success?.should == true
576
577
  result.credit_card.venmo_sdk?.should == false
@@ -585,7 +586,7 @@ describe Braintree::CreditCard do
585
586
  :cvv => "100",
586
587
  :options => {
587
588
  :venmo_sdk_session => Braintree::Test::VenmoSDK::InvalidSession
588
- }
589
+ },
589
590
  )
590
591
  result.success?.should == true
591
592
  result.credit_card.venmo_sdk?.should == false
@@ -601,12 +602,12 @@ describe Braintree::CreditCard do
601
602
  :expiration_month => "11",
602
603
  :expiration_year => "2099",
603
604
  },
604
- :share => true
605
+ :share => true,
605
606
  )
606
607
  customer = Braintree::Customer.create!
607
608
  result = Braintree::CreditCard.create(
608
609
  :customer_id => customer.id,
609
- :payment_method_nonce => nonce
610
+ :payment_method_nonce => nonce,
610
611
  )
611
612
 
612
613
  result.success?.should == true
@@ -643,7 +644,7 @@ describe Braintree::CreditCard do
643
644
  :verify_card => true,
644
645
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
645
646
  :verification_account_type => "debit",
646
- }
647
+ },
647
648
  )
648
649
 
649
650
  expect(result).to be_success
@@ -660,7 +661,7 @@ describe Braintree::CreditCard do
660
661
  :verify_card => true,
661
662
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
662
663
  :verification_account_type => "credit",
663
- }
664
+ },
664
665
  )
665
666
 
666
667
  expect(result).to be_success
@@ -676,7 +677,7 @@ describe Braintree::CreditCard do
676
677
  :verify_card => true,
677
678
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
678
679
  :verification_account_type => "ach",
679
- }
680
+ },
680
681
  )
681
682
 
682
683
  expect(result).to_not be_success
@@ -692,7 +693,7 @@ describe Braintree::CreditCard do
692
693
  :options => {
693
694
  :verify_card => true,
694
695
  :verification_account_type => "credit",
695
- }
696
+ },
696
697
  )
697
698
 
698
699
  expect(result).to_not be_success
@@ -708,7 +709,7 @@ describe Braintree::CreditCard do
708
709
  :customer_id => customer.id,
709
710
  :cardholder_name => "Adam Davis",
710
711
  :number => Braintree::Test::CreditCardNumbers::Visa,
711
- :expiration_date => "05/2009"
712
+ :expiration_date => "05/2009",
712
713
  )
713
714
  credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
714
715
  credit_card.cardholder_name.should == "Adam Davis"
@@ -722,7 +723,7 @@ describe Braintree::CreditCard do
722
723
  Braintree::CreditCard.create!(
723
724
  :customer_id => customer.id,
724
725
  :number => Braintree::Test::CreditCardNumbers::Visa,
725
- :expiration_date => "invalid_date"
726
+ :expiration_date => "invalid_date",
726
727
  )
727
728
  end.to raise_error(Braintree::ValidationsFailed)
728
729
  end
@@ -734,11 +735,11 @@ describe Braintree::CreditCard do
734
735
  :credit_card => {
735
736
  :number => Braintree::Test::CreditCardNumbers::Visa,
736
737
  :expiration_date => "05/2010"
737
- }
738
+ },
738
739
  )
739
740
  result = Braintree::CreditCard.credit(
740
741
  customer.credit_cards[0].token,
741
- :amount => "100.00"
742
+ :amount => "100.00",
742
743
  )
743
744
  result.success?.should == true
744
745
  result.transaction.amount.should == BigDecimal("100.00")
@@ -757,11 +758,11 @@ describe Braintree::CreditCard do
757
758
  :credit_card => {
758
759
  :number => Braintree::Test::CreditCardNumbers::Visa,
759
760
  :expiration_date => "05/2010"
760
- }
761
+ },
761
762
  )
762
763
  transaction = Braintree::CreditCard.credit!(
763
764
  customer.credit_cards[0].token,
764
- :amount => "100.00"
765
+ :amount => "100.00",
765
766
  )
766
767
  transaction.amount.should == BigDecimal("100.00")
767
768
  transaction.type.should == "credit"
@@ -773,95 +774,6 @@ describe Braintree::CreditCard do
773
774
  end
774
775
  end
775
776
 
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
777
  describe "self.update" do
866
778
  it "updates the credit card" do
867
779
  customer = Braintree::Customer.create!
@@ -870,13 +782,13 @@ describe Braintree::CreditCard do
870
782
  :customer_id => customer.id,
871
783
  :cvv => "123",
872
784
  :number => Braintree::Test::CreditCardNumbers::Visa,
873
- :expiration_date => "05/2012"
785
+ :expiration_date => "05/2012",
874
786
  )
875
787
  update_result = Braintree::CreditCard.update(credit_card.token,
876
788
  :cardholder_name => "New Holder",
877
789
  :cvv => "456",
878
790
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
879
- :expiration_date => "06/2013"
791
+ :expiration_date => "06/2013",
880
792
  )
881
793
  update_result.success?.should == true
882
794
  update_result.credit_card.should == credit_card
@@ -894,20 +806,20 @@ describe Braintree::CreditCard do
894
806
  :customer_id => customer.id,
895
807
  :cvv => "123",
896
808
  :number => Braintree::Test::CreditCardNumbers::Visa,
897
- :expiration_date => "05/2012"
809
+ :expiration_date => "05/2012",
898
810
  )
899
811
  result = Braintree::CreditCard.update(credit_card.token,
900
812
  :payment_method_nonce => Braintree::Test::Nonce::Transactable,
901
813
  :three_d_secure_pass_thru => {
902
- :eci_flag => '02',
903
- :cavv => 'some_cavv',
904
- :xid => 'some_xid',
905
- :authentication_response => 'Y',
906
- :directory_response => 'Y',
907
- :cavv_algorithm => '2',
908
- :ds_transaction_id => 'some_ds_transaction_id',
814
+ :eci_flag => "02",
815
+ :cavv => "some_cavv",
816
+ :xid => "some_xid",
817
+ :authentication_response => "Y",
818
+ :directory_response => "Y",
819
+ :cavv_algorithm => "2",
820
+ :ds_transaction_id => "some_ds_transaction_id",
909
821
  },
910
- :options => {:verify_card => true}
822
+ :options => {:verify_card => true},
911
823
  )
912
824
  expect(result).not_to be_success
913
825
  error = result.errors.for(:verification).first
@@ -922,21 +834,21 @@ describe Braintree::CreditCard do
922
834
  :customer_id => customer.id,
923
835
  :cvv => "123",
924
836
  :number => Braintree::Test::CreditCardNumbers::Visa,
925
- :expiration_date => "05/2012"
837
+ :expiration_date => "05/2012",
926
838
  )
927
839
  result = Braintree::CreditCard.update(credit_card.token,
928
840
  :payment_method_nonce => Braintree::Test::Nonce::Transactable,
929
841
  :three_d_secure_pass_thru => {
930
- :eci_flag => '02',
931
- :cavv => 'some_cavv',
842
+ :eci_flag => "02",
843
+ :cavv => "some_cavv",
932
844
  :three_d_secure_version=> "2.1.0",
933
- :xid => 'some_xid',
934
- :authentication_response => 'Y',
935
- :directory_response => 'Y',
936
- :cavv_algorithm => '2',
937
- :ds_transaction_id => 'some_ds_transaction_id',
845
+ :xid => "some_xid",
846
+ :authentication_response => "Y",
847
+ :directory_response => "Y",
848
+ :cavv_algorithm => "2",
849
+ :ds_transaction_id => "some_ds_transaction_id",
938
850
  },
939
- :options => {:verify_card => true}
851
+ :options => {:verify_card => true},
940
852
  )
941
853
 
942
854
  result.success?.should == true
@@ -952,12 +864,12 @@ describe Braintree::CreditCard do
952
864
  :expiration_date => "05/2012",
953
865
  :billing_address => {
954
866
  :street_address => "123 Nigeria Ave"
955
- }
867
+ },
956
868
  )
957
869
  update_result = Braintree::CreditCard.update(credit_card.token,
958
870
  :billing_address => {
959
871
  :region => "IL"
960
- }
872
+ },
961
873
  )
962
874
  update_result.success?.should == true
963
875
  updated_credit_card = update_result.credit_card
@@ -974,13 +886,13 @@ describe Braintree::CreditCard do
974
886
  :expiration_date => "05/2012",
975
887
  :billing_address => {
976
888
  :street_address => "123 Nigeria Ave"
977
- }
889
+ },
978
890
  )
979
891
  update_result = Braintree::CreditCard.update(credit_card.token,
980
892
  :billing_address => {
981
893
  :region => "IL",
982
894
  :options => {:update_existing => true}
983
- }
895
+ },
984
896
  )
985
897
  update_result.success?.should == true
986
898
  updated_credit_card = update_result.credit_card
@@ -997,7 +909,7 @@ describe Braintree::CreditCard do
997
909
  :expiration_date => "05/2012",
998
910
  :billing_address => {
999
911
  :street_address => "123 Nigeria Ave"
1000
- }
912
+ },
1001
913
  )
1002
914
  update_result = Braintree::CreditCard.update(credit_card.token,
1003
915
  :billing_address => {
@@ -1006,7 +918,7 @@ describe Braintree::CreditCard do
1006
918
  :country_code_alpha3 => "ASM",
1007
919
  :country_code_numeric => "016",
1008
920
  :options => {:update_existing => true}
1009
- }
921
+ },
1010
922
  )
1011
923
  update_result.success?.should == true
1012
924
  updated_credit_card = update_result.credit_card
@@ -1022,12 +934,12 @@ describe Braintree::CreditCard do
1022
934
  credit_card = Braintree::CreditCard.create!(
1023
935
  :customer_id => customer.id,
1024
936
  :number => Braintree::Test::CreditCardNumbers::Visa,
1025
- :expiration_date => "05/2012"
937
+ :expiration_date => "05/2012",
1026
938
  )
1027
939
  update_result = Braintree::CreditCard.update(credit_card.token,
1028
940
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1029
941
  :expiration_month => "07",
1030
- :expiration_year => "2011"
942
+ :expiration_year => "2011",
1031
943
  )
1032
944
  update_result.success?.should == true
1033
945
  update_result.credit_card.should == credit_card
@@ -1043,17 +955,17 @@ describe Braintree::CreditCard do
1043
955
  :customer_id => customer.id,
1044
956
  :cvv => "123",
1045
957
  :number => Braintree::Test::CreditCardNumbers::Visa,
1046
- :expiration_date => "05/2012"
958
+ :expiration_date => "05/2012",
1047
959
  )
1048
960
  update_result = Braintree::CreditCard.update(credit_card.token,
1049
961
  :cardholder_name => "New Holder",
1050
962
  :cvv => "456",
1051
963
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
1052
964
  :expiration_date => "06/2013",
1053
- :options => {:verify_card => true}
965
+ :options => {:verify_card => true},
1054
966
  )
1055
967
  update_result.success?.should == false
1056
- update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
968
+ update_result.credit_card_verification.status.should == Braintree::CreditCardVerification::Status::ProcessorDeclined
1057
969
  update_result.credit_card_verification.gateway_rejection_reason.should be_nil
1058
970
  end
1059
971
 
@@ -1075,7 +987,7 @@ describe Braintree::CreditCard do
1075
987
  :region => "Old State",
1076
988
  :postal_code => "12345",
1077
989
  :country_name => "Canada"
1078
- }
990
+ },
1079
991
  )
1080
992
  result = Braintree::CreditCard.update(credit_card.token,
1081
993
  :options => {:verify_card => false},
@@ -1089,7 +1001,7 @@ describe Braintree::CreditCard do
1089
1001
  :region => "New State",
1090
1002
  :postal_code => "56789",
1091
1003
  :country_name => "United States of America"
1092
- }
1004
+ },
1093
1005
  )
1094
1006
  result.success?.should == true
1095
1007
  address = result.credit_card.billing_address
@@ -1110,12 +1022,12 @@ describe Braintree::CreditCard do
1110
1022
  :cardholder_name => "Original Holder",
1111
1023
  :customer_id => customer.id,
1112
1024
  :number => Braintree::Test::CreditCardNumbers::Visa,
1113
- :expiration_date => "05/2012"
1025
+ :expiration_date => "05/2012",
1114
1026
  )
1115
1027
  update_result = Braintree::CreditCard.update(credit_card.token,
1116
1028
  :cardholder_name => "New Holder",
1117
1029
  :number => "invalid",
1118
- :expiration_date => "05/2014"
1030
+ :expiration_date => "05/2014",
1119
1031
  )
1120
1032
  update_result.success?.should == false
1121
1033
  update_result.errors.for(:credit_card).on(:number)[0].message.should == "Credit card number must be 12-19 digits."
@@ -1126,12 +1038,12 @@ describe Braintree::CreditCard do
1126
1038
  card1 = Braintree::CreditCard.create(
1127
1039
  :customer_id => customer.id,
1128
1040
  :number => Braintree::Test::CreditCardNumbers::Visa,
1129
- :expiration_date => "05/2009"
1041
+ :expiration_date => "05/2009",
1130
1042
  ).credit_card
1131
1043
  card2 = Braintree::CreditCard.create(
1132
1044
  :customer_id => customer.id,
1133
1045
  :number => Braintree::Test::CreditCardNumbers::Visa,
1134
- :expiration_date => "05/2009"
1046
+ :expiration_date => "05/2009",
1135
1047
  ).credit_card
1136
1048
 
1137
1049
  card1.should be_default
@@ -1189,12 +1101,12 @@ describe Braintree::CreditCard do
1189
1101
  :cardholder_name => "Original Holder",
1190
1102
  :customer_id => customer.id,
1191
1103
  :number => Braintree::Test::CreditCardNumbers::Visa,
1192
- :expiration_date => "05/2012"
1104
+ :expiration_date => "05/2012",
1193
1105
  )
1194
1106
  updated_credit_card = Braintree::CreditCard.update!(credit_card.token,
1195
1107
  :cardholder_name => "New Holder",
1196
1108
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1197
- :expiration_date => "06/2013"
1109
+ :expiration_date => "06/2013",
1198
1110
  )
1199
1111
  updated_credit_card.token.should == credit_card.token
1200
1112
  updated_credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
@@ -1210,151 +1122,25 @@ describe Braintree::CreditCard do
1210
1122
  :cardholder_name => "Original Holder",
1211
1123
  :customer_id => customer.id,
1212
1124
  :number => Braintree::Test::CreditCardNumbers::Visa,
1213
- :expiration_date => "05/2012"
1125
+ :expiration_date => "05/2012",
1214
1126
  )
1215
1127
  expect do
1216
1128
  Braintree::CreditCard.update!(credit_card.token,
1217
1129
  :cardholder_name => "New Holder",
1218
1130
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1219
- :expiration_date => "invalid/date"
1131
+ :expiration_date => "invalid/date",
1220
1132
  )
1221
1133
  end.to raise_error(Braintree::ValidationsFailed)
1222
1134
  end
1223
1135
  end
1224
1136
 
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
1137
  describe "self.delete" do
1352
1138
  it "deletes the credit card" do
1353
1139
  customer = Braintree::Customer.create.customer
1354
1140
  result = Braintree::CreditCard.create(
1355
1141
  :customer_id => customer.id,
1356
1142
  :number => Braintree::Test::CreditCardNumbers::Visa,
1357
- :expiration_date => "05/2012"
1143
+ :expiration_date => "05/2012",
1358
1144
  )
1359
1145
 
1360
1146
  result.success?.should == true
@@ -1374,7 +1160,7 @@ describe Braintree::CreditCard do
1374
1160
  Braintree::CreditCard.create!(
1375
1161
  :customer_id => customer.id,
1376
1162
  :number => Braintree::Test::CreditCardNumbers::Visa,
1377
- :expiration_date => "01/#{Time.now.year - 3}"
1163
+ :expiration_date => "01/#{Time.now.year - 3}",
1378
1164
  )
1379
1165
  end
1380
1166
 
@@ -1405,14 +1191,14 @@ describe Braintree::CreditCard do
1405
1191
  Braintree::CreditCard.create!(
1406
1192
  :customer_id => customer.id,
1407
1193
  :number => Braintree::Test::CreditCardNumbers::Visa,
1408
- :expiration_date => "01/2010"
1194
+ :expiration_date => "01/2010",
1409
1195
  )
1410
1196
  end
1411
1197
 
1412
1198
  collection = Braintree::CreditCard.expiring_between(Time.mktime(2010, 1, 1), Time.mktime(2010,3, 1))
1413
1199
  collection.maximum_size.should > 100
1414
1200
 
1415
- credit_card_ids = collection.map {|c| c.token }.uniq.compact
1201
+ credit_card_ids = collection.map { |c| c.token }.uniq.compact
1416
1202
  credit_card_ids.size.should == collection.maximum_size
1417
1203
  end
1418
1204
  end
@@ -1423,7 +1209,7 @@ describe Braintree::CreditCard do
1423
1209
  result = Braintree::CreditCard.create(
1424
1210
  :customer_id => customer.id,
1425
1211
  :number => Braintree::Test::CreditCardNumbers::Visa,
1426
- :expiration_date => "05/2012"
1212
+ :expiration_date => "05/2012",
1427
1213
  )
1428
1214
  result.success?.should == true
1429
1215
  credit_card = Braintree::CreditCard.find(result.credit_card.token)
@@ -1438,13 +1224,13 @@ describe Braintree::CreditCard do
1438
1224
  credit_card = Braintree::CreditCard.create(
1439
1225
  :customer_id => customer.id,
1440
1226
  :number => Braintree::Test::CreditCardNumbers::Visa,
1441
- :expiration_date => "05/2012"
1227
+ :expiration_date => "05/2012",
1442
1228
  ).credit_card
1443
1229
 
1444
1230
  subscription = Braintree::Subscription.create(
1445
1231
  :payment_method_token => credit_card.token,
1446
1232
  :plan_id => "integration_trialless_plan",
1447
- :price => "1.00"
1233
+ :price => "1.00",
1448
1234
  ).subscription
1449
1235
 
1450
1236
  found_card = Braintree::CreditCard.find(credit_card.token)
@@ -1488,7 +1274,7 @@ describe Braintree::CreditCard do
1488
1274
  :expiration_month => "11",
1489
1275
  :expiration_year => "2099",
1490
1276
  },
1491
- :client_token_options => {:customer_id => customer.id}
1277
+ :client_token_options => {:customer_id => customer.id},
1492
1278
  )
1493
1279
 
1494
1280
  credit_card = Braintree::CreditCard.from_nonce(nonce)
@@ -1502,7 +1288,7 @@ describe Braintree::CreditCard do
1502
1288
  :number => "4111111111111111",
1503
1289
  :expiration_month => "11",
1504
1290
  :expiration_year => "2099",
1505
- }
1291
+ },
1506
1292
  )
1507
1293
  expect do
1508
1294
  Braintree::CreditCard.from_nonce(nonce)
@@ -1517,7 +1303,7 @@ describe Braintree::CreditCard do
1517
1303
  :expiration_month => "11",
1518
1304
  :expiration_year => "2099",
1519
1305
  },
1520
- :client_token_options => {:customer_id => customer.id}
1306
+ :client_token_options => {:customer_id => customer.id},
1521
1307
  )
1522
1308
 
1523
1309
  Braintree::CreditCard.from_nonce(nonce)
@@ -1533,7 +1319,7 @@ describe Braintree::CreditCard do
1533
1319
  :credit_card => {
1534
1320
  :number => Braintree::Test::CreditCardNumbers::Visa,
1535
1321
  :expiration_date => "05/2010"
1536
- }
1322
+ },
1537
1323
  )
1538
1324
  result = Braintree::CreditCard.sale(customer.credit_cards[0].token, :amount => "100.00")
1539
1325
 
@@ -1552,13 +1338,13 @@ describe Braintree::CreditCard do
1552
1338
  :credit_card => {
1553
1339
  :number => Braintree::Test::CreditCardNumbers::Visa,
1554
1340
  :expiration_date => "05/2010"
1555
- }
1341
+ },
1556
1342
  )
1557
1343
  result = Braintree::CreditCard.sale(customer.credit_cards[0].token,
1558
1344
  :amount => "100.00",
1559
1345
  :credit_card => {
1560
1346
  :cvv => "301"
1561
- }
1347
+ },
1562
1348
  )
1563
1349
 
1564
1350
  result.success?.should == true
@@ -1576,7 +1362,7 @@ describe Braintree::CreditCard do
1576
1362
  :credit_card => {
1577
1363
  :number => Braintree::Test::CreditCardNumbers::Visa,
1578
1364
  :expiration_date => "05/2010"
1579
- }
1365
+ },
1580
1366
  )
1581
1367
  transaction = Braintree::CreditCard.sale!(customer.credit_cards[0].token, :amount => "100.00")
1582
1368
  transaction.amount.should == BigDecimal("100.00")
@@ -1589,255 +1375,6 @@ describe Braintree::CreditCard do
1589
1375
  end
1590
1376
  end
1591
1377
 
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
1378
  describe "nonce" do
1842
1379
  it "returns the credit card nonce" do
1843
1380
  customer = Braintree::Customer.create!
@@ -1845,7 +1382,7 @@ describe Braintree::CreditCard do
1845
1382
  :cardholder_name => "Original Holder",
1846
1383
  :customer_id => customer.id,
1847
1384
  :number => Braintree::Test::CreditCardNumbers::Visa,
1848
- :expiration_date => "05/2012"
1385
+ :expiration_date => "05/2012",
1849
1386
  )
1850
1387
 
1851
1388
  credit_card.nonce.should_not be_nil
@@ -1863,7 +1400,7 @@ describe Braintree::CreditCard do
1863
1400
  credit_card = Braintree::CreditCard.create(
1864
1401
  :customer_id => customer.id,
1865
1402
  :number => Braintree::Test::CreditCardNumbers::Visa,
1866
- :expiration_date => "05/2009"
1403
+ :expiration_date => "05/2009",
1867
1404
  ).credit_card
1868
1405
  credit_card_vaulted = Braintree::CreditCard.find(credit_card.token)
1869
1406
  credit_card_vaulted.is_network_tokenized?.should == false