braintree 3.0.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/braintree.gemspec +2 -3
  3. data/lib/braintree.rb +8 -1
  4. data/lib/braintree/account_updater_daily_report.rb +1 -1
  5. data/lib/braintree/address.rb +2 -1
  6. data/lib/braintree/apple_pay.rb +1 -1
  7. data/lib/braintree/apple_pay_card.rb +1 -1
  8. data/lib/braintree/apple_pay_options.rb +1 -1
  9. data/lib/braintree/authorization_adjustment.rb +1 -1
  10. data/lib/braintree/bin_data.rb +9 -2
  11. data/lib/braintree/client_token.rb +1 -1
  12. data/lib/braintree/configuration.rb +11 -11
  13. data/lib/braintree/connected_merchant_paypal_status_changed.rb +1 -1
  14. data/lib/braintree/connected_merchant_status_transitioned.rb +1 -1
  15. data/lib/braintree/credit_card.rb +2 -2
  16. data/lib/braintree/credit_card_gateway.rb +4 -4
  17. data/lib/braintree/credit_card_verification.rb +5 -5
  18. data/lib/braintree/credit_card_verification_search.rb +1 -1
  19. data/lib/braintree/customer.rb +6 -4
  20. data/lib/braintree/customer_gateway.rb +2 -0
  21. data/lib/braintree/customer_search.rb +1 -1
  22. data/lib/braintree/disbursement.rb +1 -1
  23. data/lib/braintree/dispute.rb +15 -1
  24. data/lib/braintree/dispute/paypal_message.rb +15 -0
  25. data/lib/braintree/dispute_gateway.rb +2 -2
  26. data/lib/braintree/dispute_search.rb +3 -2
  27. data/lib/braintree/document_upload.rb +1 -1
  28. data/lib/braintree/error_codes.rb +10 -2
  29. data/lib/braintree/google_pay_card.rb +1 -1
  30. data/lib/braintree/granted_payment_instrument_update.rb +1 -1
  31. data/lib/braintree/graphql_client.rb +7 -7
  32. data/lib/braintree/http.rb +3 -3
  33. data/lib/braintree/local_payment_completed.rb +1 -1
  34. data/lib/braintree/local_payment_reversed.rb +19 -0
  35. data/lib/braintree/merchant.rb +1 -1
  36. data/lib/braintree/merchant_account.rb +1 -1
  37. data/lib/braintree/merchant_account_gateway.rb +1 -1
  38. data/lib/braintree/merchant_gateway.rb +1 -1
  39. data/lib/braintree/modification.rb +1 -1
  40. data/lib/braintree/oauth_credentials.rb +1 -1
  41. data/lib/braintree/oauth_gateway.rb +5 -5
  42. data/lib/braintree/payment_instrument_type.rb +10 -10
  43. data/lib/braintree/payment_method_gateway.rb +4 -6
  44. data/lib/braintree/payment_method_nonce.rb +1 -1
  45. data/lib/braintree/payment_method_nonce_details.rb +37 -0
  46. data/lib/braintree/payment_method_nonce_details_payer_info.rb +32 -0
  47. data/lib/braintree/payment_method_nonce_gateway.rb +1 -1
  48. data/lib/braintree/plan.rb +1 -1
  49. data/lib/braintree/processor_response_types.rb +3 -3
  50. data/lib/braintree/resource_collection.rb +8 -3
  51. data/lib/braintree/revoked_payment_method_metadata.rb +1 -1
  52. data/lib/braintree/risk_data.rb +3 -1
  53. data/lib/braintree/samsung_pay_card.rb +1 -1
  54. data/lib/braintree/settlement_batch_summary.rb +2 -2
  55. data/lib/braintree/subscription.rb +6 -6
  56. data/lib/braintree/test/credit_card.rb +1 -0
  57. data/lib/braintree/three_d_secure_info.rb +22 -12
  58. data/lib/braintree/transaction.rb +43 -26
  59. data/lib/braintree/transaction/installment.rb +28 -0
  60. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  61. data/lib/braintree/transaction/paypal_details.rb +1 -0
  62. data/lib/braintree/transaction_gateway.rb +26 -5
  63. data/lib/braintree/transaction_line_item.rb +1 -1
  64. data/lib/braintree/transaction_search.rb +3 -1
  65. data/lib/braintree/unknown_payment_method.rb +1 -1
  66. data/lib/braintree/us_bank_account.rb +3 -3
  67. data/lib/braintree/us_bank_account_verification.rb +1 -1
  68. data/lib/braintree/us_bank_account_verification_gateway.rb +1 -1
  69. data/lib/braintree/util.rb +4 -4
  70. data/lib/braintree/venmo_account.rb +1 -1
  71. data/lib/braintree/version.rb +2 -2
  72. data/lib/braintree/visa_checkout_card.rb +2 -2
  73. data/lib/braintree/webhook_notification.rb +28 -19
  74. data/lib/braintree/webhook_notification_gateway.rb +5 -5
  75. data/lib/braintree/webhook_testing_gateway.rb +10 -0
  76. data/lib/braintree/xml/generator.rb +5 -4
  77. data/lib/braintree/xml/libxml.rb +0 -1
  78. data/lib/braintree/xml/parser.rb +22 -12
  79. data/lib/braintree/xml/rexml.rb +70 -0
  80. data/spec/integration/braintree/add_on_spec.rb +1 -1
  81. data/spec/integration/braintree/address_spec.rb +28 -24
  82. data/spec/integration/braintree/advanced_search_spec.rb +45 -45
  83. data/spec/integration/braintree/apple_pay_spec.rb +3 -3
  84. data/spec/integration/braintree/braintree_gateway_spec.rb +2 -1
  85. data/spec/integration/braintree/client_api/client_token_spec.rb +14 -14
  86. data/spec/integration/braintree/client_api/spec_helper.rb +5 -5
  87. data/spec/integration/braintree/credit_card_spec.rb +124 -122
  88. data/spec/integration/braintree/credit_card_verification_search_spec.rb +2 -2
  89. data/spec/integration/braintree/credit_card_verification_spec.rb +1 -1
  90. data/spec/integration/braintree/customer_search_spec.rb +8 -8
  91. data/spec/integration/braintree/customer_spec.rb +343 -149
  92. data/spec/integration/braintree/dispute_search_spec.rb +29 -4
  93. data/spec/integration/braintree/dispute_spec.rb +6 -6
  94. data/spec/integration/braintree/error_codes_spec.rb +1 -1
  95. data/spec/integration/braintree/http_spec.rb +2 -2
  96. data/spec/integration/braintree/merchant_account_spec.rb +25 -26
  97. data/spec/integration/braintree/merchant_spec.rb +14 -14
  98. data/spec/integration/braintree/oauth_spec.rb +11 -11
  99. data/spec/integration/braintree/payment_method_nonce_spec.rb +26 -35
  100. data/spec/integration/braintree/payment_method_spec.rb +326 -149
  101. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +17 -13
  102. data/spec/integration/braintree/paypal_account_spec.rb +28 -28
  103. data/spec/integration/braintree/samsung_pay_card_spec.rb +9 -9
  104. data/spec/integration/braintree/settlement_batch_summary_spec.rb +8 -8
  105. data/spec/integration/braintree/subscription_spec.rb +133 -133
  106. data/spec/integration/braintree/test/transaction_amounts_spec.rb +2 -2
  107. data/spec/integration/braintree/test_transaction_spec.rb +10 -10
  108. data/spec/integration/braintree/transaction_search_spec.rb +93 -67
  109. data/spec/integration/braintree/transaction_spec.rb +736 -380
  110. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +32 -26
  111. data/spec/integration/braintree/us_bank_account_spec.rb +6 -6
  112. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +7 -7
  113. data/spec/integration/braintree/us_bank_account_verification_spec.rb +8 -8
  114. data/spec/integration/braintree/visa_checkout_card_spec.rb +5 -5
  115. data/spec/integration/spec_helper.rb +9 -3
  116. data/spec/oauth_test_helper.rb +1 -1
  117. data/spec/script/httpsd.rb +6 -6
  118. data/spec/spec_helper.rb +6 -3
  119. data/spec/unit/braintree/address_spec.rb +1 -1
  120. data/spec/unit/braintree/apple_pay_card_spec.rb +1 -1
  121. data/spec/unit/braintree/client_token_spec.rb +2 -2
  122. data/spec/unit/braintree/configuration_spec.rb +42 -42
  123. data/spec/unit/braintree/credit_card_spec.rb +9 -9
  124. data/spec/unit/braintree/credit_card_verification_search_spec.rb +1 -1
  125. data/spec/unit/braintree/credit_card_verification_spec.rb +8 -4
  126. data/spec/unit/braintree/customer_spec.rb +14 -4
  127. data/spec/unit/braintree/disbursement_spec.rb +7 -7
  128. data/spec/unit/braintree/dispute_search_spec.rb +1 -0
  129. data/spec/unit/braintree/dispute_spec.rb +34 -9
  130. data/spec/unit/braintree/error_result_spec.rb +5 -5
  131. data/spec/unit/braintree/errors_spec.rb +8 -8
  132. data/spec/unit/braintree/http_spec.rb +5 -5
  133. data/spec/unit/braintree/merchant_account_spec.rb +1 -1
  134. data/spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb +31 -0
  135. data/spec/unit/braintree/payment_method_nonce_details_spec.rb +43 -0
  136. data/spec/unit/braintree/payment_method_spec.rb +1 -1
  137. data/spec/unit/braintree/paypal_account_spec.rb +2 -2
  138. data/spec/unit/braintree/resource_collection_spec.rb +30 -1
  139. data/spec/unit/braintree/risk_data_spec.rb +9 -5
  140. data/spec/unit/braintree/subscription_search_spec.rb +1 -1
  141. data/spec/unit/braintree/successful_result_spec.rb +1 -1
  142. data/spec/unit/braintree/three_d_secure_info_spec.rb +32 -14
  143. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +3 -3
  144. data/spec/unit/braintree/transaction/customer_details_spec.rb +1 -1
  145. data/spec/unit/braintree/transaction/deposit_details_spec.rb +2 -2
  146. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  147. data/spec/unit/braintree/transaction/paypal_details_spec.rb +3 -1
  148. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  149. data/spec/unit/braintree/transaction_spec.rb +25 -17
  150. data/spec/unit/braintree/util_spec.rb +18 -18
  151. data/spec/unit/braintree/validation_error_collection_spec.rb +36 -36
  152. data/spec/unit/braintree/webhook_notification_spec.rb +72 -56
  153. data/spec/unit/braintree/xml/rexml_spec.rb +51 -0
  154. data/spec/unit/braintree/xml_spec.rb +31 -31
  155. metadata +15 -19
  156. data/lib/braintree/settlement_batch.rb +0 -0
@@ -12,12 +12,12 @@ describe Braintree::PaymentMethodNonce do
12
12
  :number => "4111111111111111",
13
13
  :expiration_month => "11",
14
14
  :expiration_year => "2099",
15
- }
15
+ },
16
16
  )
17
17
 
18
18
  result = Braintree::PaymentMethod.create(
19
19
  :payment_method_nonce => nonce,
20
- :customer_id => customer.id
20
+ :customer_id => customer.id,
21
21
  )
22
22
 
23
23
  result.should be_success
@@ -49,12 +49,12 @@ describe Braintree::PaymentMethodNonce do
49
49
  :number => "4111111111111111",
50
50
  :expiration_month => "11",
51
51
  :expiration_year => "2099",
52
- }
52
+ },
53
53
  )
54
54
 
55
55
  payment_method = Braintree::PaymentMethod.create!(
56
56
  :payment_method_nonce => nonce,
57
- :customer_id => customer.id
57
+ :customer_id => customer.id,
58
58
  )
59
59
 
60
60
  payment_method.should be_a(Braintree::CreditCard)
@@ -79,33 +79,24 @@ describe Braintree::PaymentMethodNonce do
79
79
  result.should be_success
80
80
  nonce.nonce.should == "fake-valid-nonce"
81
81
  nonce.type.should == "CreditCard"
82
- nonce.details.fetch(:last_two).should == "81"
83
- nonce.details.fetch(:card_type).should == "Visa"
82
+ nonce.details.bin.should == "401288"
83
+ nonce.details.card_type.should == "Visa"
84
+ nonce.details.expiration_month.should == "12"
85
+ nonce.details.expiration_year.should == "2022"
86
+ nonce.details.is_network_tokenized?.should be_nil
87
+ nonce.details.last_two.should == "81"
88
+ nonce.details.payer_info.should be_nil
84
89
  end
85
90
 
86
91
  it "return paypal details if details exist" do
87
92
  result = Braintree::PaymentMethodNonce.find("fake-paypal-one-time-nonce")
88
93
  nonce = result.payment_method_nonce
89
-
90
- nonce.details.fetch(:cobranded_card_label).should_not be_nil
91
- nonce.details.fetch(:shipping_option_id).should_not be_nil
92
- nonce.details.fetch(:billing_address).fetch(:recipient_name).should_not be_nil
93
- nonce.details.fetch(:shipping_address).fetch(:recipient_name).should_not be_nil
94
-
95
- nonce.details.fetch(:payer_info).fetch(:first_name).should_not be_nil
96
- nonce.details.fetch(:payer_info).fetch(:last_name).should_not be_nil
97
- nonce.details.fetch(:payer_info).fetch(:email).should_not be_nil
98
- nonce.details.fetch(:payer_info).fetch(:payer_id).should_not be_nil
99
- end
100
-
101
- it "return venmo details if details exist" do
102
- result = Braintree::PaymentMethodNonce.find("fake-venmo-account-nonce")
103
-
104
- nonce = result.payment_method_nonce
105
-
106
- nonce.details.fetch(:last_two).should == "99"
107
- nonce.details.fetch(:username).should == "venmojoe"
108
- nonce.details.fetch(:venmo_user_id).should == "Venmo-Joe-1"
94
+ nonce.details.payer_info.billing_agreement_id.should be_nil
95
+ nonce.details.payer_info.country_code.should be_nil
96
+ nonce.details.payer_info.email.should_not be_nil
97
+ nonce.details.payer_info.first_name.should_not be_nil
98
+ nonce.details.payer_info.last_name.should_not be_nil
99
+ nonce.details.payer_info.payer_id.should_not be_nil
109
100
  end
110
101
 
111
102
  it "returns null 3ds_info if there isn't any" do
@@ -114,7 +105,7 @@ describe Braintree::PaymentMethodNonce do
114
105
  :number => "4111111111111111",
115
106
  :expiration_month => "11",
116
107
  :expiration_year => "2099",
117
- }
108
+ },
118
109
  )
119
110
 
120
111
  result = Braintree::PaymentMethodNonce.find(nonce)
@@ -131,7 +122,7 @@ describe Braintree::PaymentMethodNonce do
131
122
  nonce = result.payment_method_nonce
132
123
  result.should be_success
133
124
  nonce.details.should_not be_nil
134
- nonce.details[:bin].should == "401288"
125
+ nonce.details.bin.should == "401288"
135
126
  end
136
127
 
137
128
  it "returns bin_data with commercial set to Yes" do
@@ -257,19 +248,19 @@ describe Braintree::PaymentMethodNonce do
257
248
  context "regulation environments" do
258
249
  it "can get unregulated" do
259
250
  expect(
260
- request_authentication_insights(european_merchant_token, indian_payment_token)[:regulation_environment]
251
+ request_authentication_insights(european_merchant_token, indian_payment_token)[:regulation_environment],
261
252
  ).to eq "unregulated"
262
253
  end
263
254
 
264
255
  it "can get psd2" do
265
256
  expect(
266
- request_authentication_insights(european_merchant_token, european_payment_token)[:regulation_environment]
257
+ request_authentication_insights(european_merchant_token, european_payment_token)[:regulation_environment],
267
258
  ).to eq "psd2"
268
259
  end
269
260
 
270
261
  it "can get rbi" do
271
262
  expect(
272
- request_authentication_insights(indian_merchant_token, indian_payment_token)[:regulation_environment]
263
+ request_authentication_insights(indian_merchant_token, indian_payment_token)[:regulation_environment],
273
264
  ).to eq "rbi"
274
265
  end
275
266
  end
@@ -277,19 +268,19 @@ describe Braintree::PaymentMethodNonce do
277
268
  context "sca_indicator" do
278
269
  it "can get unavailable" do
279
270
  expect(
280
- request_authentication_insights(indian_merchant_token, indian_payment_token)[:sca_indicator]
271
+ request_authentication_insights(indian_merchant_token, indian_payment_token)[:sca_indicator],
281
272
  ).to eq "unavailable"
282
273
  end
283
274
 
284
275
  it "can get sca_required" do
285
276
  expect(
286
- request_authentication_insights(indian_merchant_token, indian_payment_token, {amount: 2001})[:sca_indicator]
277
+ request_authentication_insights(indian_merchant_token, indian_payment_token, {amount: 2001})[:sca_indicator],
287
278
  ).to eq "sca_required"
288
279
  end
289
280
 
290
281
  it "can get sca_optional" do
291
282
  expect(
292
- request_authentication_insights(indian_merchant_token, indian_payment_token, {amount: 2000, recurring_customer_consent: true, recurring_max_amount: 2000})[:sca_indicator]
283
+ request_authentication_insights(indian_merchant_token, indian_payment_token, {amount: 2000, recurring_customer_consent: true, recurring_max_amount: 2000})[:sca_indicator],
293
284
 
294
285
  ).to eq "sca_optional"
295
286
  end
@@ -309,7 +300,7 @@ describe Braintree::PaymentMethodNonce do
309
300
 
310
301
  result = Braintree::PaymentMethodNonce.create(
311
302
  payment_method_token,
312
- payment_method_nonce: nonce_request
303
+ payment_method_nonce: nonce_request,
313
304
  )
314
305
  result.should be_success
315
306
 
@@ -17,20 +17,20 @@ describe Braintree::PaymentMethod do
17
17
  config,
18
18
  :authorization_fingerprint => authorization_fingerprint,
19
19
  :shared_customer_identifier => "fake_identifier",
20
- :shared_customer_identifier_type => "testing"
20
+ :shared_customer_identifier_type => "testing",
21
21
  )
22
22
 
23
23
  response = http.create_credit_card(
24
24
  :number => 4111111111111111,
25
25
  :expirationMonth => 12,
26
- :expirationYear => 2020
26
+ :expirationYear => 2020,
27
27
  )
28
28
  response.code.should == "201"
29
29
 
30
30
  nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
31
31
  result = Braintree::PaymentMethod.create(
32
32
  :payment_method_nonce => nonce,
33
- :customer_id => customer.id
33
+ :customer_id => customer.id,
34
34
  )
35
35
 
36
36
  result.should be_success
@@ -51,21 +51,21 @@ describe Braintree::PaymentMethod do
51
51
  config,
52
52
  :authorization_fingerprint => authorization_fingerprint,
53
53
  :shared_customer_identifier => "fake_identifier",
54
- :shared_customer_identifier_type => "testing"
54
+ :shared_customer_identifier_type => "testing",
55
55
  )
56
56
 
57
57
  response = http.create_credit_card(
58
58
  :number => "4111111111111111",
59
59
  :expirationMonth => "12",
60
60
  :expirationYear => "2020",
61
- :options => {:validate => false}
61
+ :options => {:validate => false},
62
62
  )
63
63
  response.code.should == "202"
64
64
 
65
65
  nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
66
66
  result = Braintree::PaymentMethod.create(
67
67
  :payment_method_nonce => nonce,
68
- :customer_id => customer.id
68
+ :customer_id => customer.id,
69
69
  )
70
70
 
71
71
  result.should be_success
@@ -82,7 +82,7 @@ describe Braintree::PaymentMethod do
82
82
  result = Braintree::PaymentMethod.create(
83
83
  :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
84
84
  :customer_id => customer.id,
85
- :token => token
85
+ :token => token,
86
86
  )
87
87
 
88
88
  result.should be_success
@@ -107,7 +107,7 @@ describe Braintree::PaymentMethod do
107
107
  result = Braintree::PaymentMethod.create(
108
108
  :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
109
109
  :customer_id => customer.id,
110
- :token => token
110
+ :token => token,
111
111
  )
112
112
 
113
113
  result.should be_success
@@ -135,7 +135,7 @@ describe Braintree::PaymentMethod do
135
135
  result = Braintree::PaymentMethod.create(
136
136
  :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
137
137
  :customer_id => customer.id,
138
- :token => token
138
+ :token => token,
139
139
  )
140
140
 
141
141
  result.should be_success
@@ -163,7 +163,7 @@ describe Braintree::PaymentMethod do
163
163
  result = Braintree::PaymentMethod.create(
164
164
  :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
165
165
  :customer_id => customer.id,
166
- :token => token
166
+ :token => token,
167
167
  )
168
168
 
169
169
  result.should be_success
@@ -185,7 +185,7 @@ describe Braintree::PaymentMethod do
185
185
  :customer_id => customer.id,
186
186
  :number => Braintree::Test::CreditCardNumbers::Visa,
187
187
  :expiration_date => "05/2009",
188
- :cvv => "100"
188
+ :cvv => "100",
189
189
  )
190
190
  result.success?.should == true
191
191
  original_payment_method = result.credit_card
@@ -195,7 +195,7 @@ describe Braintree::PaymentMethod do
195
195
  result = Braintree::PaymentMethod.create(
196
196
  :payment_method_nonce => nonce,
197
197
  :customer_id => customer.id,
198
- :options => {:make_default => true}
198
+ :options => {:make_default => true},
199
199
  )
200
200
 
201
201
  result.should be_success
@@ -210,12 +210,12 @@ describe Braintree::PaymentMethod do
210
210
  second_token = make_token
211
211
  nonce = nonce_for_paypal_account(
212
212
  :consent_code => "PAYPAL_CONSENT_CODE",
213
- :token => first_token
213
+ :token => first_token,
214
214
  )
215
215
  result = Braintree::PaymentMethod.create(
216
216
  :payment_method_nonce => nonce,
217
217
  :customer_id => customer.id,
218
- :token => second_token
218
+ :token => second_token,
219
219
  )
220
220
 
221
221
  result.should be_success
@@ -229,7 +229,7 @@ describe Braintree::PaymentMethod do
229
229
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
230
230
  :expiration_month => "11",
231
231
  :expiration_year => "2099",
232
- }
232
+ },
233
233
  )
234
234
  customer = Braintree::Customer.create!
235
235
  result = Braintree::PaymentMethod.create(
@@ -238,7 +238,7 @@ describe Braintree::PaymentMethod do
238
238
  :options => {
239
239
  :verify_card => true,
240
240
  :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
241
- }
241
+ },
242
242
  )
243
243
 
244
244
  result.should_not be_success
@@ -254,7 +254,7 @@ describe Braintree::PaymentMethod do
254
254
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
255
255
  :expiration_month => "11",
256
256
  :expiration_year => "2099",
257
- }
257
+ },
258
258
  )
259
259
  customer = Braintree::Customer.create!
260
260
  result = Braintree::PaymentMethod.create(
@@ -263,7 +263,7 @@ describe Braintree::PaymentMethod do
263
263
  :options => {
264
264
  :verify_card => true,
265
265
  :verification_amount => "100.00"
266
- }
266
+ },
267
267
  )
268
268
 
269
269
  result.should_not be_success
@@ -279,16 +279,16 @@ describe Braintree::PaymentMethod do
279
279
  :customer_id => customer.id,
280
280
  :payment_method_nonce => Braintree::Test::Nonce::Transactable,
281
281
  :three_d_secure_pass_thru => {
282
- :eci_flag => '02',
283
- :cavv => 'some_cavv',
284
- :xid => 'some_xid',
285
- :three_d_secure_version => 'xx',
286
- :authentication_response => 'Y',
287
- :directory_response => 'Y',
288
- :cavv_algorithm => '2',
289
- :ds_transaction_id => 'some_ds_transaction_id',
282
+ :eci_flag => "02",
283
+ :cavv => "some_cavv",
284
+ :xid => "some_xid",
285
+ :three_d_secure_version => "xx",
286
+ :authentication_response => "Y",
287
+ :directory_response => "Y",
288
+ :cavv_algorithm => "2",
289
+ :ds_transaction_id => "some_ds_transaction_id",
290
290
  },
291
- :options => {:verify_card => true}
291
+ :options => {:verify_card => true},
292
292
  )
293
293
  expect(result).not_to be_success
294
294
  error = result.errors.for(:verification).first
@@ -302,16 +302,16 @@ describe Braintree::PaymentMethod do
302
302
  :customer_id => customer.id,
303
303
  :payment_method_nonce => Braintree::Test::Nonce::Transactable,
304
304
  :three_d_secure_pass_thru => {
305
- :eci_flag => '02',
306
- :cavv => 'some_cavv',
307
- :xid => 'some_xid',
308
- :three_d_secure_version => '1.0.2',
309
- :authentication_response => 'Y',
310
- :directory_response => 'Y',
311
- :cavv_algorithm => '2',
312
- :ds_transaction_id => 'some_ds_transaction_id',
305
+ :eci_flag => "02",
306
+ :cavv => "some_cavv",
307
+ :xid => "some_xid",
308
+ :three_d_secure_version => "1.0.2",
309
+ :authentication_response => "Y",
310
+ :directory_response => "Y",
311
+ :cavv_algorithm => "2",
312
+ :ds_transaction_id => "some_ds_transaction_id",
313
313
  },
314
- :options => {:verify_card => true}
314
+ :options => {:verify_card => true},
315
315
  )
316
316
 
317
317
  expect(result).to be_success
@@ -343,7 +343,7 @@ describe Braintree::PaymentMethod do
343
343
  result = Braintree::CreditCard.create(
344
344
  :customer_id => customer.id,
345
345
  :number => Braintree::Test::CreditCardNumbers::Visa,
346
- :expiration_date => "05/2012"
346
+ :expiration_date => "05/2012",
347
347
  )
348
348
  result.should be_success
349
349
 
@@ -351,14 +351,14 @@ describe Braintree::PaymentMethod do
351
351
  :credit_card => {
352
352
  :number => Braintree::Test::CreditCardNumbers::Visa,
353
353
  :expiration_date => "05/2012"
354
- }
354
+ },
355
355
  )
356
356
  result = Braintree::PaymentMethod.create(
357
357
  :payment_method_nonce => nonce,
358
358
  :customer_id => customer.id,
359
359
  :options => {
360
360
  :fail_on_duplicate_payment_method => true
361
- }
361
+ },
362
362
  )
363
363
 
364
364
  result.should_not be_success
@@ -375,14 +375,14 @@ describe Braintree::PaymentMethod do
375
375
  config,
376
376
  :authorization_fingerprint => authorization_fingerprint,
377
377
  :shared_customer_identifier => "fake_identifier",
378
- :shared_customer_identifier_type => "testing"
378
+ :shared_customer_identifier_type => "testing",
379
379
  )
380
380
 
381
381
  response = http.create_credit_card(
382
382
  :number => "4111111111111111",
383
383
  :expirationMonth => "12",
384
384
  :expirationYear => "2020",
385
- :options => {:validate => false}
385
+ :options => {:validate => false},
386
386
  )
387
387
  response.code.should == "202"
388
388
 
@@ -392,7 +392,7 @@ describe Braintree::PaymentMethod do
392
392
  :customer_id => customer.id,
393
393
  :billing_address => {
394
394
  :street_address => "123 Abc Way"
395
- }
395
+ },
396
396
  )
397
397
 
398
398
  result.should be_success
@@ -414,14 +414,14 @@ describe Braintree::PaymentMethod do
414
414
  config,
415
415
  :authorization_fingerprint => authorization_fingerprint,
416
416
  :shared_customer_identifier => "fake_identifier",
417
- :shared_customer_identifier_type => "testing"
417
+ :shared_customer_identifier_type => "testing",
418
418
  )
419
419
 
420
420
  response = http.create_credit_card(
421
421
  :number => "4111111111111111",
422
422
  :expirationMonth => "12",
423
423
  :expirationYear => "2020",
424
- :options => {:validate => false}
424
+ :options => {:validate => false},
425
425
  )
426
426
  response.code.should == "202"
427
427
 
@@ -431,7 +431,7 @@ describe Braintree::PaymentMethod do
431
431
  result = Braintree::PaymentMethod.create(
432
432
  :payment_method_nonce => nonce,
433
433
  :customer_id => customer.id,
434
- :billing_address_id => address.id
434
+ :billing_address_id => address.id,
435
435
  )
436
436
 
437
437
  result.should be_success
@@ -454,7 +454,7 @@ describe Braintree::PaymentMethod do
454
454
  config,
455
455
  :authorization_fingerprint => authorization_fingerprint,
456
456
  :shared_customer_identifier => "fake_identifier",
457
- :shared_customer_identifier_type => "testing"
457
+ :shared_customer_identifier_type => "testing",
458
458
  )
459
459
 
460
460
  response = http.create_credit_card(
@@ -464,7 +464,7 @@ describe Braintree::PaymentMethod do
464
464
  :options => {:validate => false},
465
465
  :billing_address => {
466
466
  :street_address => "456 Xyz Way"
467
- }
467
+ },
468
468
  )
469
469
  response.code.should == "202"
470
470
 
@@ -474,7 +474,7 @@ describe Braintree::PaymentMethod do
474
474
  :customer_id => customer.id,
475
475
  :billing_address => {
476
476
  :street_address => "123 Abc Way"
477
- }
477
+ },
478
478
  )
479
479
 
480
480
  result.should be_success
@@ -496,7 +496,7 @@ describe Braintree::PaymentMethod do
496
496
  config,
497
497
  :authorization_fingerprint => authorization_fingerprint,
498
498
  :shared_customer_identifier => "fake_identifier",
499
- :shared_customer_identifier_type => "testing"
499
+ :shared_customer_identifier_type => "testing",
500
500
  )
501
501
 
502
502
  response = http.create_credit_card(
@@ -505,7 +505,7 @@ describe Braintree::PaymentMethod do
505
505
  :expirationYear => 2020,
506
506
  :billing_address => {
507
507
  :street_address => "456 Xyz Way"
508
- }
508
+ },
509
509
  )
510
510
  response.code.should == "201"
511
511
 
@@ -515,7 +515,7 @@ describe Braintree::PaymentMethod do
515
515
  :customer_id => customer.id,
516
516
  :billing_address => {
517
517
  :street_address => "123 Abc Way"
518
- }
518
+ },
519
519
  )
520
520
 
521
521
  result.should be_success
@@ -534,7 +534,7 @@ describe Braintree::PaymentMethod do
534
534
  :number => Braintree::Test::CreditCardNumbers::Hiper,
535
535
  :expiration_month => "11",
536
536
  :expiration_year => "2099",
537
- }
537
+ },
538
538
  )
539
539
  customer = Braintree::Customer.create!
540
540
  result = Braintree::PaymentMethod.create(
@@ -544,7 +544,7 @@ describe Braintree::PaymentMethod do
544
544
  :verify_card => true,
545
545
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
546
546
  :verification_account_type => "debit",
547
- }
547
+ },
548
548
  )
549
549
 
550
550
  result.should be_success
@@ -557,7 +557,7 @@ describe Braintree::PaymentMethod do
557
557
  :number => Braintree::Test::CreditCardNumbers::Hiper,
558
558
  :expiration_month => "11",
559
559
  :expiration_year => "2099",
560
- }
560
+ },
561
561
  )
562
562
  customer = Braintree::Customer.create!
563
563
  result = Braintree::PaymentMethod.create(
@@ -567,7 +567,7 @@ describe Braintree::PaymentMethod do
567
567
  :verify_card => true,
568
568
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
569
569
  :verification_account_type => "credit",
570
- }
570
+ },
571
571
  )
572
572
 
573
573
  result.should be_success
@@ -580,7 +580,7 @@ describe Braintree::PaymentMethod do
580
580
  :number => Braintree::Test::CreditCardNumbers::Hiper,
581
581
  :expiration_month => "11",
582
582
  :expiration_year => "2099",
583
- }
583
+ },
584
584
  )
585
585
  customer = Braintree::Customer.create!
586
586
  result = Braintree::PaymentMethod.create(
@@ -590,7 +590,7 @@ describe Braintree::PaymentMethod do
590
590
  :verify_card => true,
591
591
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
592
592
  :verification_account_type => "ach",
593
- }
593
+ },
594
594
  )
595
595
 
596
596
  result.should_not be_success
@@ -603,7 +603,7 @@ describe Braintree::PaymentMethod do
603
603
  :number => Braintree::Test::CreditCardNumbers::Visa,
604
604
  :expiration_month => "11",
605
605
  :expiration_year => "2099",
606
- }
606
+ },
607
607
  )
608
608
  customer = Braintree::Customer.create!
609
609
  result = Braintree::PaymentMethod.create(
@@ -612,7 +612,7 @@ describe Braintree::PaymentMethod do
612
612
  :options => {
613
613
  :verify_card => true,
614
614
  :verification_account_type => "credit",
615
- }
615
+ },
616
616
  )
617
617
 
618
618
  result.should_not be_success
@@ -626,7 +626,7 @@ describe Braintree::PaymentMethod do
626
626
  :customer_id => customer.id,
627
627
  :cvv => "123",
628
628
  :number => Braintree::Test::CreditCardNumbers::Visa,
629
- :expiration_date => "05/2012"
629
+ :expiration_date => "05/2012",
630
630
  )
631
631
  update_result = Braintree::PaymentMethod.update(credit_card.token,
632
632
  :cardholder_name => "New Holder",
@@ -650,7 +650,7 @@ describe Braintree::PaymentMethod do
650
650
  :customer_id => customer.id,
651
651
  :cvv => "123",
652
652
  :number => Braintree::Test::CreditCardNumbers::Visa,
653
- :expiration_date => "05/2012"
653
+ :expiration_date => "05/2012",
654
654
  )
655
655
  update_result = Braintree::PaymentMethod.update(credit_card.token,
656
656
  :cardholder_name => "New Holder",
@@ -674,7 +674,7 @@ describe Braintree::PaymentMethod do
674
674
  customer = Braintree::Customer.create.customer
675
675
  result = Braintree::PaymentMethod.create(
676
676
  :payment_method_nonce => nonce,
677
- :customer_id => customer.id
677
+ :customer_id => customer.id,
678
678
  )
679
679
 
680
680
  result.should be_success
@@ -751,7 +751,7 @@ describe Braintree::PaymentMethod do
751
751
  nonce = nonce_for_paypal_account(:access_token => "PAYPAL_ACCESS_TOKEN")
752
752
  result = Braintree::PaymentMethod.create(
753
753
  :payment_method_nonce => nonce,
754
- :customer_id => customer.id
754
+ :customer_id => customer.id,
755
755
  )
756
756
 
757
757
  result.should_not be_success
@@ -766,7 +766,7 @@ describe Braintree::PaymentMethod do
766
766
  :customer_id => customer.id,
767
767
  :billing_address => {
768
768
  :street_address => "123 Abc Way"
769
- }
769
+ },
770
770
  )
771
771
 
772
772
  result.should be_success
@@ -784,7 +784,7 @@ describe Braintree::PaymentMethod do
784
784
  result = Braintree::PaymentMethod.create(
785
785
  :payment_method_nonce => nonce,
786
786
  :customer_id => customer.id,
787
- :billing_address_id => "address_id"
787
+ :billing_address_id => "address_id",
788
788
  )
789
789
 
790
790
  result.should be_success
@@ -801,7 +801,7 @@ describe Braintree::PaymentMethod do
801
801
  nonce = nonce_for_paypal_account(:token => "PAYPAL_TOKEN")
802
802
  result = Braintree::PaymentMethod.create(
803
803
  :payment_method_nonce => nonce,
804
- :customer_id => customer.id
804
+ :customer_id => customer.id,
805
805
  )
806
806
 
807
807
  result.should_not be_success
@@ -815,7 +815,7 @@ describe Braintree::PaymentMethod do
815
815
  original_token = random_payment_method_token
816
816
  nonce = nonce_for_paypal_account(
817
817
  :consent_code => "consent-code",
818
- :token => original_token
818
+ :token => original_token,
819
819
  )
820
820
 
821
821
  result = Braintree::PaymentMethod.create(
@@ -825,7 +825,7 @@ describe Braintree::PaymentMethod do
825
825
  :verify_card => true,
826
826
  :fail_on_duplicate_payment_method => true,
827
827
  :verification_merchant_account_id => "not_a_real_merchant_account_id"
828
- }
828
+ },
829
829
  )
830
830
 
831
831
  result.should be_success
@@ -839,7 +839,7 @@ describe Braintree::PaymentMethod do
839
839
  result = Braintree::PaymentMethod.create(
840
840
  :payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable,
841
841
  :customer_id => customer.id,
842
- :token => token
842
+ :token => token,
843
843
  )
844
844
 
845
845
  result.should be_success
@@ -849,6 +849,99 @@ describe Braintree::PaymentMethod do
849
849
  payment_method.should be_a Braintree::UnknownPaymentMethod
850
850
  end
851
851
  end
852
+
853
+ context "verification_currency_iso_code" do
854
+ it "validates verification_currency_iso_code against currency configured in default merchant account" do
855
+ nonce = nonce_for_new_payment_method(
856
+ :credit_card => {
857
+ :number => Braintree::Test::CreditCardNumbers::Visa,
858
+ :expiration_month => "11",
859
+ :expiration_year => "2099",
860
+ },
861
+ )
862
+ customer = Braintree::Customer.create!
863
+ result = Braintree::PaymentMethod.create(
864
+ :payment_method_nonce => nonce,
865
+ :customer_id => customer.id,
866
+ :options => {
867
+ :verify_card => true,
868
+ :verification_currency_iso_code => "USD"
869
+ },
870
+ )
871
+
872
+ result.should be_success
873
+ result.payment_method.verification.currency_iso_code == "USD"
874
+ end
875
+
876
+ it "validates verification_currency_iso_code against currency configured in verification_merchant_account_id" do
877
+ nonce = nonce_for_new_payment_method(
878
+ :credit_card => {
879
+ :number => Braintree::Test::CreditCardNumbers::Visa,
880
+ :expiration_month => "11",
881
+ :expiration_year => "2099",
882
+ },
883
+ )
884
+ customer = Braintree::Customer.create!
885
+ result = Braintree::PaymentMethod.create(
886
+ :payment_method_nonce => nonce,
887
+ :customer_id => customer.id,
888
+ :options => {
889
+ :verify_card => true,
890
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
891
+ :verification_currency_iso_code => "USD"
892
+ },
893
+ )
894
+
895
+ result.should be_success
896
+ result.payment_method.verification.currency_iso_code == "USD"
897
+ result.payment_method.verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
898
+ end
899
+
900
+
901
+ it "errors with invalid presentment currency due to verification_currency_iso_code not matching with currency configured in default merchant account" do
902
+ nonce = nonce_for_new_payment_method(
903
+ :credit_card => {
904
+ :number => Braintree::Test::CreditCardNumbers::Visa,
905
+ :expiration_month => "11",
906
+ :expiration_year => "2099",
907
+ },
908
+ )
909
+ customer = Braintree::Customer.create!
910
+ result = Braintree::PaymentMethod.create(
911
+ :payment_method_nonce => nonce,
912
+ :customer_id => customer.id,
913
+ :options => {
914
+ :verify_card => true,
915
+ :verification_currency_iso_code => "GBP"
916
+ },
917
+ )
918
+ result.should_not be_success
919
+ result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
920
+ end
921
+
922
+ it "errors with invalid presentment currency due to verification_currency_iso_code not matching with currency configured in verification_merchant_account_id" do
923
+ nonce = nonce_for_new_payment_method(
924
+ :credit_card => {
925
+ :number => Braintree::Test::CreditCardNumbers::Visa,
926
+ :expiration_month => "11",
927
+ :expiration_year => "2099",
928
+ },
929
+ )
930
+ customer = Braintree::Customer.create!
931
+ result = Braintree::PaymentMethod.create(
932
+ :payment_method_nonce => nonce,
933
+ :customer_id => customer.id,
934
+ :options => {
935
+ :verify_card => true,
936
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
937
+ :verification_currency_iso_code => "GBP"
938
+ },
939
+ )
940
+
941
+ result.should_not be_success
942
+ result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
943
+ end
944
+ end
852
945
  end
853
946
 
854
947
  describe "self.create!" do
@@ -862,20 +955,20 @@ describe Braintree::PaymentMethod do
862
955
  config,
863
956
  :authorization_fingerprint => authorization_fingerprint,
864
957
  :shared_customer_identifier => "fake_identifier",
865
- :shared_customer_identifier_type => "testing"
958
+ :shared_customer_identifier_type => "testing",
866
959
  )
867
960
 
868
961
  response = http.create_credit_card(
869
962
  :number => 4111111111111111,
870
963
  :expirationMonth => 12,
871
- :expirationYear => 2020
964
+ :expirationYear => 2020,
872
965
  )
873
966
  response.code.should == "201"
874
967
 
875
968
  nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
876
969
  payment_method = Braintree::PaymentMethod.create!(
877
970
  :payment_method_nonce => nonce,
878
- :customer_id => customer.id
971
+ :customer_id => customer.id,
879
972
  )
880
973
 
881
974
  payment_method.should be_a(Braintree::CreditCard)
@@ -893,7 +986,7 @@ describe Braintree::PaymentMethod do
893
986
  result = Braintree::CreditCard.create(
894
987
  :customer_id => customer.id,
895
988
  :number => Braintree::Test::CreditCardNumbers::Visa,
896
- :expiration_date => "05/2012"
989
+ :expiration_date => "05/2012",
897
990
  )
898
991
  result.success?.should == true
899
992
 
@@ -909,13 +1002,13 @@ describe Braintree::PaymentMethod do
909
1002
  credit_card = Braintree::CreditCard.create(
910
1003
  :customer_id => customer.id,
911
1004
  :number => Braintree::Test::CreditCardNumbers::Visa,
912
- :expiration_date => "05/2012"
1005
+ :expiration_date => "05/2012",
913
1006
  ).credit_card
914
1007
 
915
1008
  subscription = Braintree::Subscription.create(
916
1009
  :payment_method_token => credit_card.token,
917
1010
  :plan_id => "integration_trialless_plan",
918
- :price => "1.00"
1011
+ :price => "1.00",
919
1012
  ).subscription
920
1013
 
921
1014
  found_card = Braintree::PaymentMethod.find(credit_card.token)
@@ -932,11 +1025,11 @@ describe Braintree::PaymentMethod do
932
1025
  payment_method_token = make_token
933
1026
  nonce = nonce_for_paypal_account(
934
1027
  :consent_code => "consent-code",
935
- :token => payment_method_token
1028
+ :token => payment_method_token,
936
1029
  )
937
1030
  result = Braintree::PaymentMethod.create(
938
1031
  :payment_method_nonce => nonce,
939
- :customer_id => customer.id
1032
+ :customer_id => customer.id,
940
1033
  )
941
1034
  result.should be_success
942
1035
 
@@ -955,7 +1048,7 @@ describe Braintree::PaymentMethod do
955
1048
  result = Braintree::PaymentMethod.create(
956
1049
  :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
957
1050
  :customer_id => customer.id,
958
- :token => payment_method_token
1051
+ :token => payment_method_token,
959
1052
  )
960
1053
  result.should be_success
961
1054
 
@@ -980,7 +1073,7 @@ describe Braintree::PaymentMethod do
980
1073
  result = Braintree::PaymentMethod.create(
981
1074
  :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
982
1075
  :customer_id => customer.id,
983
- :token => payment_method_token
1076
+ :token => payment_method_token,
984
1077
  )
985
1078
  result.should be_success
986
1079
 
@@ -990,8 +1083,8 @@ describe Braintree::PaymentMethod do
990
1083
  venmo_account.token.should == payment_method_token
991
1084
  venmo_account.default.should == true
992
1085
  venmo_account.image_url.should =~ /venmo/
993
- venmo_account.username.should == 'venmojoe'
994
- venmo_account.venmo_user_id.should == 'Venmo-Joe-1'
1086
+ venmo_account.username.should == "venmojoe"
1087
+ venmo_account.venmo_user_id.should == "Venmo-Joe-1"
995
1088
  venmo_account.source_description.should == "Venmo Account: venmojoe"
996
1089
  venmo_account.customer_id.should == customer.id
997
1090
  end
@@ -1004,7 +1097,7 @@ describe Braintree::PaymentMethod do
1004
1097
  result = Braintree::PaymentMethod.create(
1005
1098
  :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
1006
1099
  :customer_id => customer.id,
1007
- :token => payment_method_token
1100
+ :token => payment_method_token,
1008
1101
  )
1009
1102
  result.should be_success
1010
1103
 
@@ -1032,7 +1125,7 @@ describe Braintree::PaymentMethod do
1032
1125
  result = Braintree::PaymentMethod.create(
1033
1126
  :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
1034
1127
  :customer_id => customer.id,
1035
- :token => payment_method_token
1128
+ :token => payment_method_token,
1036
1129
  )
1037
1130
  result.should be_success
1038
1131
 
@@ -1062,7 +1155,7 @@ describe Braintree::PaymentMethod do
1062
1155
  result = Braintree::PaymentMethod.create(
1063
1156
  :payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable,
1064
1157
  :customer_id => customer.id,
1065
- :token => payment_method_token
1158
+ :token => payment_method_token,
1066
1159
  )
1067
1160
  result.should be_success
1068
1161
 
@@ -1088,7 +1181,7 @@ describe Braintree::PaymentMethod do
1088
1181
 
1089
1182
  create_result = Braintree::PaymentMethod.create(
1090
1183
  :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
1091
- :customer_id => customer.id
1184
+ :customer_id => customer.id,
1092
1185
  )
1093
1186
 
1094
1187
  token = create_result.payment_method.token
@@ -1109,7 +1202,7 @@ describe Braintree::PaymentMethod do
1109
1202
 
1110
1203
  create_result = Braintree::PaymentMethod.create(
1111
1204
  :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
1112
- :customer_id => customer.id
1205
+ :customer_id => customer.id,
1113
1206
  )
1114
1207
  token = create_result.payment_method.token
1115
1208
 
@@ -1130,11 +1223,11 @@ describe Braintree::PaymentMethod do
1130
1223
 
1131
1224
  nonce = nonce_for_paypal_account(
1132
1225
  :consent_code => "PAYPAL_CONSENT_CODE",
1133
- :token => paypal_account_token
1226
+ :token => paypal_account_token,
1134
1227
  )
1135
1228
  Braintree::PaymentMethod.create(
1136
1229
  :payment_method_nonce => nonce,
1137
- :customer_id => customer.id
1230
+ :customer_id => customer.id,
1138
1231
  )
1139
1232
 
1140
1233
  paypal_account = Braintree::PaymentMethod.find(paypal_account_token)
@@ -1163,7 +1256,7 @@ describe Braintree::PaymentMethod do
1163
1256
 
1164
1257
  Braintree::PaymentMethod.create(
1165
1258
  :payment_method_nonce => nonce,
1166
- :customer_id => customer.id
1259
+ :customer_id => customer.id,
1167
1260
  )
1168
1261
 
1169
1262
  result = Braintree::PaymentMethod.delete(token)
@@ -1200,14 +1293,14 @@ describe Braintree::PaymentMethod do
1200
1293
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1201
1294
  :expiration_date => "06/2013",
1202
1295
  :three_d_secure_pass_thru => {
1203
- :eci_flag => '02',
1204
- :cavv => 'some_cavv',
1205
- :xid => 'some_xid',
1206
- :three_d_secure_version => 'xx',
1207
- :authentication_response => 'Y',
1208
- :directory_response => 'Y',
1209
- :cavv_algorithm => '2',
1210
- :ds_transaction_id => 'some_ds_transaction_id',
1296
+ :eci_flag => "02",
1297
+ :cavv => "some_cavv",
1298
+ :xid => "some_xid",
1299
+ :three_d_secure_version => "xx",
1300
+ :authentication_response => "Y",
1301
+ :directory_response => "Y",
1302
+ :cavv_algorithm => "2",
1303
+ :ds_transaction_id => "some_ds_transaction_id",
1211
1304
  },
1212
1305
  :options => {:verify_card => true},
1213
1306
  )
@@ -1231,14 +1324,14 @@ describe Braintree::PaymentMethod do
1231
1324
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1232
1325
  :expiration_date => "06/2013",
1233
1326
  :three_d_secure_pass_thru => {
1234
- :eci_flag => '02',
1235
- :cavv => 'some_cavv',
1236
- :xid => 'some_xid',
1237
- :three_d_secure_version => '1.0.2',
1238
- :authentication_response => 'Y',
1239
- :directory_response => 'Y',
1240
- :cavv_algorithm => '2',
1241
- :ds_transaction_id => 'some_ds_transaction_id',
1327
+ :eci_flag => "02",
1328
+ :cavv => "some_cavv",
1329
+ :xid => "some_xid",
1330
+ :three_d_secure_version => "1.0.2",
1331
+ :authentication_response => "Y",
1332
+ :directory_response => "Y",
1333
+ :cavv_algorithm => "2",
1334
+ :ds_transaction_id => "some_ds_transaction_id",
1242
1335
  },
1243
1336
  :options => {:verify_card => true},
1244
1337
  )
@@ -1258,13 +1351,13 @@ describe Braintree::PaymentMethod do
1258
1351
  :customer_id => customer.id,
1259
1352
  :cvv => "123",
1260
1353
  :number => Braintree::Test::CreditCardNumbers::Visa,
1261
- :expiration_date => "05/2012"
1354
+ :expiration_date => "05/2012",
1262
1355
  )
1263
1356
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1264
1357
  :cardholder_name => "New Holder",
1265
1358
  :cvv => "456",
1266
1359
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1267
- :expiration_date => "06/2013"
1360
+ :expiration_date => "06/2013",
1268
1361
  )
1269
1362
  update_result.success?.should == true
1270
1363
  update_result.payment_method.should == credit_card
@@ -1275,6 +1368,90 @@ describe Braintree::PaymentMethod do
1275
1368
  updated_credit_card.expiration_date.should == "06/2013"
1276
1369
  end
1277
1370
 
1371
+ context "verification_currency_iso_code" do
1372
+ it "validates verification_currency_iso_code and updates the credit card " do
1373
+ customer = Braintree::Customer.create!
1374
+ credit_card = Braintree::CreditCard.create!(
1375
+ :cardholder_name => "Original Holder",
1376
+ :customer_id => customer.id,
1377
+ :cvv => "123",
1378
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1379
+ :expiration_date => "05/2012",
1380
+ )
1381
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1382
+ :cardholder_name => "New Holder",
1383
+ :cvv => "456",
1384
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1385
+ :expiration_date => "06/2013",
1386
+ :options => {:verify_card => true, :verification_currency_iso_code => "USD"},
1387
+ )
1388
+ update_result.success?.should == true
1389
+ update_result.payment_method.verification.currency_iso_code == "USD"
1390
+ end
1391
+
1392
+ it "validates verification_currency_iso_code against the given verification_merchant_account_id and updates the credit card " do
1393
+ customer = Braintree::Customer.create!
1394
+ credit_card = Braintree::CreditCard.create!(
1395
+ :cardholder_name => "Original Holder",
1396
+ :customer_id => customer.id,
1397
+ :cvv => "123",
1398
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1399
+ :expiration_date => "05/2012",
1400
+ )
1401
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1402
+ :cardholder_name => "New Holder",
1403
+ :cvv => "456",
1404
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1405
+ :expiration_date => "06/2013",
1406
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "USD"},
1407
+ )
1408
+ update_result.success?.should == true
1409
+ update_result.payment_method.verification.currency_iso_code == "USD"
1410
+ update_result.payment_method.verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
1411
+ end
1412
+
1413
+ it "throws validation error when passing invalid verification_currency_iso_code" do
1414
+ customer = Braintree::Customer.create!
1415
+ credit_card = Braintree::CreditCard.create!(
1416
+ :cardholder_name => "Original Holder",
1417
+ :customer_id => customer.id,
1418
+ :cvv => "123",
1419
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1420
+ :expiration_date => "05/2012",
1421
+ )
1422
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1423
+ :cardholder_name => "New Holder",
1424
+ :cvv => "456",
1425
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1426
+ :expiration_date => "06/2013",
1427
+ :options => {:verify_card => true, :verification_currency_iso_code => "GBP"},
1428
+ )
1429
+ expect(update_result).to_not be_success
1430
+ update_result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1431
+ end
1432
+
1433
+ it "throws validation error when passing invalid verification_currency_iso_code of the given verification merchant account id" do
1434
+ customer = Braintree::Customer.create!
1435
+ credit_card = Braintree::CreditCard.create!(
1436
+ :cardholder_name => "Original Holder",
1437
+ :customer_id => customer.id,
1438
+ :cvv => "123",
1439
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1440
+ :expiration_date => "05/2012",
1441
+ )
1442
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1443
+ :cardholder_name => "New Holder",
1444
+ :cvv => "456",
1445
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1446
+ :expiration_date => "06/2013",
1447
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "GBP"},
1448
+ )
1449
+ expect(update_result).to_not be_success
1450
+ update_result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1451
+ end
1452
+ end
1453
+
1454
+
1278
1455
  context "billing address" do
1279
1456
  it "creates a new billing address by default" do
1280
1457
  customer = Braintree::Customer.create!
@@ -1284,12 +1461,12 @@ describe Braintree::PaymentMethod do
1284
1461
  :expiration_date => "05/2012",
1285
1462
  :billing_address => {
1286
1463
  :street_address => "123 Nigeria Ave"
1287
- }
1464
+ },
1288
1465
  )
1289
1466
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1290
1467
  :billing_address => {
1291
1468
  :region => "IL"
1292
- }
1469
+ },
1293
1470
  )
1294
1471
  update_result.success?.should == true
1295
1472
  updated_credit_card = update_result.payment_method
@@ -1306,13 +1483,13 @@ describe Braintree::PaymentMethod do
1306
1483
  :expiration_date => "05/2012",
1307
1484
  :billing_address => {
1308
1485
  :street_address => "123 Nigeria Ave"
1309
- }
1486
+ },
1310
1487
  )
1311
1488
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1312
1489
  :billing_address => {
1313
1490
  :region => "IL",
1314
1491
  :options => {:update_existing => true}
1315
- }
1492
+ },
1316
1493
  )
1317
1494
  update_result.success?.should == true
1318
1495
  updated_credit_card = update_result.payment_method
@@ -1329,7 +1506,7 @@ describe Braintree::PaymentMethod do
1329
1506
  :expiration_date => "05/2012",
1330
1507
  :billing_address => {
1331
1508
  :street_address => "123 Nigeria Ave"
1332
- }
1509
+ },
1333
1510
  )
1334
1511
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1335
1512
  :billing_address => {
@@ -1338,7 +1515,7 @@ describe Braintree::PaymentMethod do
1338
1515
  :country_code_alpha3 => "ASM",
1339
1516
  :country_code_numeric => "016",
1340
1517
  :options => {:update_existing => true}
1341
- }
1518
+ },
1342
1519
  )
1343
1520
  update_result.success?.should == true
1344
1521
  updated_credit_card = update_result.payment_method
@@ -1354,12 +1531,12 @@ describe Braintree::PaymentMethod do
1354
1531
  credit_card = Braintree::CreditCard.create!(
1355
1532
  :customer_id => customer.id,
1356
1533
  :number => Braintree::Test::CreditCardNumbers::Visa,
1357
- :expiration_date => "05/2012"
1534
+ :expiration_date => "05/2012",
1358
1535
  )
1359
1536
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1360
1537
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1361
1538
  :expiration_month => "07",
1362
- :expiration_year => "2011"
1539
+ :expiration_year => "2011",
1363
1540
  )
1364
1541
  update_result.success?.should == true
1365
1542
  update_result.payment_method.should == credit_card
@@ -1375,14 +1552,14 @@ describe Braintree::PaymentMethod do
1375
1552
  :customer_id => customer.id,
1376
1553
  :cvv => "123",
1377
1554
  :number => Braintree::Test::CreditCardNumbers::Visa,
1378
- :expiration_date => "05/2012"
1555
+ :expiration_date => "05/2012",
1379
1556
  )
1380
1557
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1381
1558
  :cardholder_name => "New Holder",
1382
1559
  :cvv => "456",
1383
1560
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
1384
1561
  :expiration_date => "06/2013",
1385
- :options => {:verify_card => true}
1562
+ :options => {:verify_card => true},
1386
1563
  )
1387
1564
  update_result.success?.should == false
1388
1565
  update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
@@ -1396,11 +1573,11 @@ describe Braintree::PaymentMethod do
1396
1573
  :customer_id => customer.id,
1397
1574
  :cvv => "123",
1398
1575
  :number => Braintree::Test::CreditCardNumbers::Visa,
1399
- :expiration_date => "05/2020"
1576
+ :expiration_date => "05/2020",
1400
1577
  )
1401
1578
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1402
1579
  :payment_method_nonce => Braintree::Test::Nonce::ProcessorDeclinedMasterCard,
1403
- :options => {:verify_card => true, :verification_amount => "2.34"}
1580
+ :options => {:verify_card => true, :verification_amount => "2.34"},
1404
1581
  )
1405
1582
  update_result.success?.should == false
1406
1583
  update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
@@ -1426,7 +1603,7 @@ describe Braintree::PaymentMethod do
1426
1603
  :region => "Old State",
1427
1604
  :postal_code => "12345",
1428
1605
  :country_name => "Canada"
1429
- }
1606
+ },
1430
1607
  )
1431
1608
  result = Braintree::PaymentMethod.update(credit_card.token,
1432
1609
  :options => {:verify_card => false},
@@ -1440,7 +1617,7 @@ describe Braintree::PaymentMethod do
1440
1617
  :region => "New State",
1441
1618
  :postal_code => "56789",
1442
1619
  :country_name => "United States of America"
1443
- }
1620
+ },
1444
1621
  )
1445
1622
  result.success?.should == true
1446
1623
  address = result.payment_method.billing_address
@@ -1461,12 +1638,12 @@ describe Braintree::PaymentMethod do
1461
1638
  :cardholder_name => "Original Holder",
1462
1639
  :customer_id => customer.id,
1463
1640
  :number => Braintree::Test::CreditCardNumbers::Visa,
1464
- :expiration_date => "05/2012"
1641
+ :expiration_date => "05/2012",
1465
1642
  )
1466
1643
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1467
1644
  :cardholder_name => "New Holder",
1468
1645
  :number => "invalid",
1469
- :expiration_date => "05/2014"
1646
+ :expiration_date => "05/2014",
1470
1647
  )
1471
1648
  update_result.success?.should == false
1472
1649
  update_result.errors.for(:credit_card).on(:number)[0].message.should == "Credit card number must be 12-19 digits."
@@ -1477,12 +1654,12 @@ describe Braintree::PaymentMethod do
1477
1654
  card1 = Braintree::CreditCard.create(
1478
1655
  :customer_id => customer.id,
1479
1656
  :number => Braintree::Test::CreditCardNumbers::Visa,
1480
- :expiration_date => "05/2009"
1657
+ :expiration_date => "05/2009",
1481
1658
  ).credit_card
1482
1659
  card2 = Braintree::CreditCard.create(
1483
1660
  :customer_id => customer.id,
1484
1661
  :number => Braintree::Test::CreditCardNumbers::Visa,
1485
- :expiration_date => "05/2009"
1662
+ :expiration_date => "05/2009",
1486
1663
  ).credit_card
1487
1664
 
1488
1665
  card1.should be_default
@@ -1501,17 +1678,17 @@ describe Braintree::PaymentMethod do
1501
1678
  original_token = random_payment_method_token
1502
1679
  nonce = nonce_for_paypal_account(
1503
1680
  :consent_code => "consent-code",
1504
- :token => original_token
1681
+ :token => original_token,
1505
1682
  )
1506
1683
  original_result = Braintree::PaymentMethod.create(
1507
1684
  :payment_method_nonce => nonce,
1508
- :customer_id => customer.id
1685
+ :customer_id => customer.id,
1509
1686
  )
1510
1687
 
1511
1688
  updated_token = make_token
1512
1689
  updated_result = Braintree::PaymentMethod.update(
1513
1690
  original_token,
1514
- :token => updated_token
1691
+ :token => updated_token,
1515
1692
  )
1516
1693
 
1517
1694
  updated_paypal_account = Braintree::PayPalAccount.find(updated_token)
@@ -1528,19 +1705,19 @@ describe Braintree::PaymentMethod do
1528
1705
  :customer_id => customer.id,
1529
1706
  :number => Braintree::Test::CreditCardNumbers::Visa,
1530
1707
  :expiration_date => "05/2009",
1531
- :options => {:make_default => true}
1708
+ :options => {:make_default => true},
1532
1709
  )
1533
1710
  result.should be_success
1534
1711
 
1535
1712
  nonce = nonce_for_paypal_account(:consent_code => "consent-code")
1536
1713
  original_token = Braintree::PaymentMethod.create(
1537
1714
  :payment_method_nonce => nonce,
1538
- :customer_id => customer.id
1715
+ :customer_id => customer.id,
1539
1716
  ).payment_method.token
1540
1717
 
1541
1718
  updated_result = Braintree::PaymentMethod.update(
1542
1719
  original_token,
1543
- :options => {:make_default => true}
1720
+ :options => {:make_default => true},
1544
1721
  )
1545
1722
 
1546
1723
  updated_paypal_account = Braintree::PayPalAccount.find(original_token)
@@ -1554,25 +1731,25 @@ describe Braintree::PaymentMethod do
1554
1731
 
1555
1732
  first_nonce = nonce_for_paypal_account(
1556
1733
  :consent_code => "consent-code",
1557
- :token => first_token
1734
+ :token => first_token,
1558
1735
  )
1559
1736
  first_result = Braintree::PaymentMethod.create(
1560
1737
  :payment_method_nonce => first_nonce,
1561
- :customer_id => customer.id
1738
+ :customer_id => customer.id,
1562
1739
  )
1563
1740
 
1564
1741
  second_nonce = nonce_for_paypal_account(
1565
1742
  :consent_code => "consent-code",
1566
- :token => second_token
1743
+ :token => second_token,
1567
1744
  )
1568
1745
  second_result = Braintree::PaymentMethod.create(
1569
1746
  :payment_method_nonce => second_nonce,
1570
- :customer_id => customer.id
1747
+ :customer_id => customer.id,
1571
1748
  )
1572
1749
 
1573
1750
  updated_result = Braintree::PaymentMethod.update(
1574
1751
  first_token,
1575
- :token => second_token
1752
+ :token => second_token,
1576
1753
  )
1577
1754
 
1578
1755
  updated_result.should_not be_success
@@ -1589,13 +1766,13 @@ describe Braintree::PaymentMethod do
1589
1766
  :customer_id => customer.id,
1590
1767
  :cvv => "123",
1591
1768
  :number => Braintree::Test::CreditCardNumbers::Visa,
1592
- :expiration_date => "05/2012"
1769
+ :expiration_date => "05/2012",
1593
1770
  )
1594
1771
  payment_method = Braintree::PaymentMethod.update!(credit_card.token,
1595
1772
  :cardholder_name => "New Holder",
1596
1773
  :cvv => "456",
1597
1774
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1598
- :expiration_date => "06/2013"
1775
+ :expiration_date => "06/2013",
1599
1776
  )
1600
1777
  payment_method.should == credit_card
1601
1778
  payment_method.cardholder_name.should == "New Holder"
@@ -1612,7 +1789,7 @@ describe Braintree::PaymentMethod do
1612
1789
  :public_key => "oauth_app_partner_user_public_key",
1613
1790
  :private_key => "oauth_app_partner_user_private_key",
1614
1791
  :environment => Braintree::Configuration.environment,
1615
- :logger => Logger.new("/dev/null")
1792
+ :logger => Logger.new("/dev/null"),
1616
1793
  )
1617
1794
  customer = @partner_merchant_gateway.customer.create(
1618
1795
  :first_name => "Joe",
@@ -1621,19 +1798,19 @@ describe Braintree::PaymentMethod do
1621
1798
  :email => "joe@example.com",
1622
1799
  :phone => "312.555.1234",
1623
1800
  :fax => "614.555.5678",
1624
- :website => "www.example.com"
1801
+ :website => "www.example.com",
1625
1802
  ).customer
1626
1803
  @credit_card = @partner_merchant_gateway.credit_card.create(
1627
1804
  :customer_id => customer.id,
1628
1805
  :cardholder_name => "Adam Davis",
1629
1806
  :number => Braintree::Test::CreditCardNumbers::Visa,
1630
- :expiration_date => "05/2009"
1807
+ :expiration_date => "05/2009",
1631
1808
  ).credit_card
1632
1809
 
1633
1810
  @oauth_gateway = Braintree::Gateway.new(
1634
1811
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
1635
1812
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
1636
- :logger => Logger.new("/dev/null")
1813
+ :logger => Logger.new("/dev/null"),
1637
1814
  )
1638
1815
  access_token = Braintree::OAuthTestHelper.create_token(@oauth_gateway, {
1639
1816
  :merchant_public_id => "integration_merchant_id",
@@ -1642,7 +1819,7 @@ describe Braintree::PaymentMethod do
1642
1819
 
1643
1820
  @granting_gateway = Braintree::Gateway.new(
1644
1821
  :access_token => access_token,
1645
- :logger => Logger.new("/dev/null")
1822
+ :logger => Logger.new("/dev/null"),
1646
1823
  )
1647
1824
  end
1648
1825
 
@@ -1658,13 +1835,13 @@ describe Braintree::PaymentMethod do
1658
1835
 
1659
1836
  result = Braintree::Transaction.sale(
1660
1837
  :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1661
- :amount => Braintree::Test::TransactionAmounts::Authorize
1838
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
1662
1839
  )
1663
1840
  result.should be_success
1664
1841
 
1665
1842
  result2 = Braintree::Transaction.sale(
1666
1843
  :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1667
- :amount => Braintree::Test::TransactionAmounts::Authorize
1844
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
1668
1845
  )
1669
1846
  result2.should_not be_success
1670
1847
  end
@@ -1676,7 +1853,7 @@ describe Braintree::PaymentMethod do
1676
1853
 
1677
1854
  result = Braintree::PaymentMethod.create(
1678
1855
  :customer_id => customer_result.customer.id,
1679
- :payment_method_nonce => grant_result.payment_method_nonce.nonce
1856
+ :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1680
1857
  )
1681
1858
  result.should_not be_success
1682
1859
  end
@@ -1688,7 +1865,7 @@ describe Braintree::PaymentMethod do
1688
1865
 
1689
1866
  result = Braintree::PaymentMethod.create(
1690
1867
  :customer_id => customer_result.customer.id,
1691
- :payment_method_nonce => grant_result.payment_method_nonce.nonce
1868
+ :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1692
1869
  )
1693
1870
  result.should be_success
1694
1871
  end
@@ -1723,7 +1900,7 @@ describe Braintree::PaymentMethod do
1723
1900
 
1724
1901
  result = Braintree::PaymentMethod.create(
1725
1902
  :customer_id => customer_result.customer.id,
1726
- :payment_method_nonce => grant_result.payment_method_nonce.nonce
1903
+ :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1727
1904
  )
1728
1905
  result.should_not be_success
1729
1906
  end
@@ -1737,7 +1914,7 @@ describe Braintree::PaymentMethod do
1737
1914
 
1738
1915
  result = Braintree::PaymentMethod.create(
1739
1916
  :customer_id => customer_result.customer.id,
1740
- :payment_method_nonce => grant_result.payment_method_nonce.nonce
1917
+ :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1741
1918
  )
1742
1919
  result.should_not be_success
1743
1920
  end