braintree 2.104.0 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +7 -4
  4. data/lib/braintree/account_updater_daily_report.rb +1 -1
  5. data/lib/braintree/address.rb +2 -23
  6. data/lib/braintree/apple_pay.rb +1 -1
  7. data/lib/braintree/apple_pay_card.rb +11 -1
  8. data/lib/braintree/apple_pay_options.rb +1 -1
  9. data/lib/braintree/authorization_adjustment.rb +1 -1
  10. data/lib/braintree/base_module.rb +6 -0
  11. data/lib/braintree/bin_data.rb +9 -2
  12. data/lib/braintree/client_token.rb +1 -1
  13. data/lib/braintree/configuration.rb +12 -12
  14. data/lib/braintree/connected_merchant_paypal_status_changed.rb +1 -1
  15. data/lib/braintree/connected_merchant_status_transitioned.rb +1 -1
  16. data/lib/braintree/credit_card.rb +2 -77
  17. data/lib/braintree/credit_card_gateway.rb +17 -36
  18. data/lib/braintree/credit_card_verification.rb +18 -5
  19. data/lib/braintree/credit_card_verification_search.rb +1 -1
  20. data/lib/braintree/customer.rb +9 -78
  21. data/lib/braintree/customer_gateway.rb +2 -23
  22. data/lib/braintree/customer_search.rb +1 -1
  23. data/lib/braintree/disbursement.rb +1 -1
  24. data/lib/braintree/{transaction/coinbase_details.rb → dispute/paypal_message.rb} +5 -6
  25. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  26. data/lib/braintree/dispute.rb +32 -8
  27. data/lib/braintree/dispute_gateway.rb +4 -9
  28. data/lib/braintree/dispute_search.rb +6 -3
  29. data/lib/braintree/document_upload.rb +1 -1
  30. data/lib/braintree/enriched_customer_data.rb +21 -0
  31. data/lib/braintree/error_codes.rb +150 -171
  32. data/lib/braintree/exceptions.rb +5 -3
  33. data/lib/braintree/exchange_rate.rb +13 -0
  34. data/lib/braintree/exchange_rate_quote.rb +24 -0
  35. data/lib/braintree/exchange_rate_quote_gateway.rb +35 -0
  36. data/lib/braintree/exchange_rate_quote_input.rb +21 -0
  37. data/lib/braintree/exchange_rate_quote_request.rb +18 -0
  38. data/lib/braintree/exchange_rate_quote_response.rb +18 -0
  39. data/lib/braintree/gateway.rb +4 -14
  40. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +11 -3
  41. data/lib/braintree/granted_payment_instrument_update.rb +1 -1
  42. data/lib/braintree/graphql_client.rb +7 -7
  43. data/lib/braintree/http.rb +4 -3
  44. data/lib/braintree/local_payment_completed.rb +2 -2
  45. data/lib/braintree/local_payment_expired.rb +21 -0
  46. data/lib/braintree/local_payment_funded.rb +22 -0
  47. data/lib/braintree/local_payment_reversed.rb +19 -0
  48. data/lib/braintree/merchant.rb +1 -1
  49. data/lib/braintree/merchant_account.rb +1 -1
  50. data/lib/braintree/merchant_account_gateway.rb +3 -1
  51. data/lib/braintree/merchant_gateway.rb +1 -1
  52. data/lib/braintree/modification.rb +1 -1
  53. data/lib/braintree/oauth_credentials.rb +1 -1
  54. data/lib/braintree/oauth_gateway.rb +5 -5
  55. data/lib/braintree/payment_instrument_type.rb +10 -14
  56. data/lib/braintree/payment_method_customer_data_updated_metadata.rb +24 -0
  57. data/lib/braintree/payment_method_gateway.rb +15 -17
  58. data/lib/braintree/payment_method_nonce.rb +7 -4
  59. data/lib/braintree/payment_method_nonce_details.rb +37 -0
  60. data/lib/braintree/payment_method_nonce_details_payer_info.rb +32 -0
  61. data/lib/braintree/payment_method_nonce_gateway.rb +1 -1
  62. data/lib/braintree/payment_method_parser.rb +1 -8
  63. data/lib/braintree/plan.rb +21 -1
  64. data/lib/braintree/plan_gateway.rb +100 -0
  65. data/lib/braintree/processor_response_types.rb +3 -3
  66. data/lib/braintree/resource_collection.rb +8 -3
  67. data/lib/braintree/revoked_payment_method_metadata.rb +1 -1
  68. data/lib/braintree/risk_data/liability_shift.rb +22 -0
  69. data/lib/braintree/risk_data.rb +5 -1
  70. data/lib/braintree/samsung_pay_card.rb +1 -1
  71. data/lib/braintree/settlement_batch_summary.rb +2 -2
  72. data/lib/braintree/subscription.rb +11 -11
  73. data/lib/braintree/successful_result.rb +3 -2
  74. data/lib/braintree/test/credit_card.rb +1 -0
  75. data/lib/braintree/test/nonce.rb +4 -23
  76. data/lib/braintree/three_d_secure_info.rb +22 -12
  77. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  78. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  79. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  80. data/lib/braintree/transaction/installment.rb +28 -0
  81. data/lib/braintree/transaction/paypal_details.rb +3 -0
  82. data/lib/braintree/transaction/subscription_details.rb +2 -0
  83. data/lib/braintree/transaction.rb +65 -120
  84. data/lib/braintree/transaction_gateway.rb +39 -27
  85. data/lib/braintree/transaction_line_item.rb +1 -1
  86. data/lib/braintree/transaction_review.rb +18 -0
  87. data/lib/braintree/transaction_search.rb +5 -3
  88. data/lib/braintree/unknown_payment_method.rb +1 -1
  89. data/lib/braintree/us_bank_account.rb +3 -3
  90. data/lib/braintree/us_bank_account_verification.rb +1 -1
  91. data/lib/braintree/us_bank_account_verification_gateway.rb +1 -1
  92. data/lib/braintree/util.rb +21 -6
  93. data/lib/braintree/venmo_account.rb +1 -1
  94. data/lib/braintree/venmo_profile_data.rb +23 -0
  95. data/lib/braintree/version.rb +2 -2
  96. data/lib/braintree/visa_checkout_card.rb +2 -2
  97. data/lib/braintree/webhook_notification.rb +44 -30
  98. data/lib/braintree/webhook_notification_gateway.rb +5 -5
  99. data/lib/braintree/webhook_testing_gateway.rb +104 -43
  100. data/lib/braintree/xml/generator.rb +5 -4
  101. data/lib/braintree/xml/parser.rb +22 -35
  102. data/lib/braintree/xml/rexml.rb +4 -5
  103. data/lib/braintree.rb +28 -23
  104. data/spec/integration/braintree/add_on_spec.rb +1 -1
  105. data/spec/integration/braintree/address_spec.rb +30 -113
  106. data/spec/integration/braintree/advanced_search_spec.rb +45 -45
  107. data/spec/integration/braintree/apple_pay_spec.rb +3 -3
  108. data/spec/integration/braintree/braintree_gateway_spec.rb +2 -1
  109. data/spec/integration/braintree/client_api/client_token_spec.rb +14 -14
  110. data/spec/integration/braintree/client_api/spec_helper.rb +5 -31
  111. data/spec/integration/braintree/credit_card_spec.rb +219 -593
  112. data/spec/integration/braintree/credit_card_verification_search_spec.rb +2 -2
  113. data/spec/integration/braintree/credit_card_verification_spec.rb +1 -1
  114. data/spec/integration/braintree/customer_search_spec.rb +8 -8
  115. data/spec/integration/braintree/customer_spec.rb +484 -513
  116. data/spec/integration/braintree/dispute_search_spec.rb +35 -6
  117. data/spec/integration/braintree/dispute_spec.rb +6 -7
  118. data/spec/integration/braintree/error_codes_spec.rb +1 -1
  119. data/spec/integration/braintree/exchange_rate_quote_spec.rb +97 -0
  120. data/spec/integration/braintree/graphql_client_spec.rb +0 -2
  121. data/spec/integration/braintree/http_spec.rb +2 -2
  122. data/spec/integration/braintree/merchant_account_spec.rb +28 -29
  123. data/spec/integration/braintree/merchant_spec.rb +14 -14
  124. data/spec/integration/braintree/oauth_spec.rb +11 -11
  125. data/spec/integration/braintree/payment_method_nonce_spec.rb +29 -35
  126. data/spec/integration/braintree/payment_method_spec.rb +535 -270
  127. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +17 -13
  128. data/spec/integration/braintree/paypal_account_spec.rb +28 -28
  129. data/spec/integration/braintree/plan_spec.rb +82 -0
  130. data/spec/integration/braintree/samsung_pay_card_spec.rb +9 -9
  131. data/spec/integration/braintree/settlement_batch_summary_spec.rb +8 -8
  132. data/spec/integration/braintree/subscription_spec.rb +144 -149
  133. data/spec/integration/braintree/test/transaction_amounts_spec.rb +2 -2
  134. data/spec/integration/braintree/test_transaction_spec.rb +10 -10
  135. data/spec/integration/braintree/transaction_search_spec.rb +175 -70
  136. data/spec/integration/braintree/transaction_spec.rb +955 -894
  137. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +32 -26
  138. data/spec/integration/braintree/us_bank_account_spec.rb +6 -6
  139. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +7 -7
  140. data/spec/integration/braintree/us_bank_account_verification_spec.rb +8 -8
  141. data/spec/integration/braintree/visa_checkout_card_spec.rb +5 -5
  142. data/spec/integration/spec_helper.rb +16 -7
  143. data/spec/oauth_test_helper.rb +1 -1
  144. data/spec/script/httpsd.rb +6 -6
  145. data/spec/spec_helper.rb +8 -14
  146. data/spec/unit/braintree/address_spec.rb +1 -9
  147. data/spec/unit/braintree/apple_pay_card_spec.rb +7 -1
  148. data/spec/unit/braintree/client_token_spec.rb +2 -2
  149. data/spec/unit/braintree/configuration_spec.rb +42 -42
  150. data/spec/unit/braintree/credit_card_spec.rb +13 -32
  151. data/spec/unit/braintree/credit_card_verification_search_spec.rb +1 -1
  152. data/spec/unit/braintree/credit_card_verification_spec.rb +8 -4
  153. data/spec/unit/braintree/customer_spec.rb +21 -22
  154. data/spec/unit/braintree/disbursement_spec.rb +7 -7
  155. data/spec/unit/braintree/dispute_search_spec.rb +3 -0
  156. data/spec/unit/braintree/dispute_spec.rb +75 -21
  157. data/spec/unit/braintree/enriched_customer_data_spec.rb +32 -0
  158. data/spec/unit/braintree/error_result_spec.rb +5 -5
  159. data/spec/unit/braintree/errors_spec.rb +8 -8
  160. data/spec/unit/braintree/exchange_rate_quote_input_spec.rb +42 -0
  161. data/spec/unit/braintree/exchange_rate_quote_request_spec.rb +82 -0
  162. data/spec/unit/braintree/exchange_rate_quote_response_spec.rb +52 -0
  163. data/spec/unit/braintree/exchange_rate_quote_spec.rb +42 -0
  164. data/spec/unit/braintree/exchange_rate_spec.rb +23 -0
  165. data/spec/unit/braintree/http_spec.rb +10 -8
  166. data/spec/unit/braintree/local_payment_completed_spec.rb +14 -0
  167. data/spec/unit/braintree/local_payment_expired_spec.rb +24 -0
  168. data/spec/unit/braintree/local_payment_funded_spec.rb +34 -0
  169. data/spec/unit/braintree/merchant_account_spec.rb +1 -1
  170. data/spec/unit/braintree/payment_method_customer_data_updated_metadata_spec.rb +45 -0
  171. data/spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb +31 -0
  172. data/spec/unit/braintree/payment_method_nonce_details_spec.rb +43 -0
  173. data/spec/unit/braintree/payment_method_nonce_spec.rb +40 -0
  174. data/spec/unit/braintree/payment_method_spec.rb +1 -1
  175. data/spec/unit/braintree/paypal_account_spec.rb +2 -2
  176. data/spec/unit/braintree/resource_collection_spec.rb +30 -1
  177. data/spec/unit/braintree/risk_data/liability_shift.rb +26 -0
  178. data/spec/unit/braintree/risk_data_spec.rb +38 -8
  179. data/spec/unit/braintree/subscription_search_spec.rb +1 -1
  180. data/spec/unit/braintree/successful_result_spec.rb +1 -1
  181. data/spec/unit/braintree/three_d_secure_info_spec.rb +32 -14
  182. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +3 -3
  183. data/spec/unit/braintree/transaction/customer_details_spec.rb +1 -1
  184. data/spec/unit/braintree/transaction/deposit_details_spec.rb +2 -2
  185. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  186. data/spec/unit/braintree/transaction/paypal_details_spec.rb +7 -1
  187. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  188. data/spec/unit/braintree/transaction_spec.rb +36 -54
  189. data/spec/unit/braintree/util_spec.rb +55 -21
  190. data/spec/unit/braintree/validation_error_collection_spec.rb +36 -36
  191. data/spec/unit/braintree/venmo_profile_data_spec.rb +32 -0
  192. data/spec/unit/braintree/webhook_notification_spec.rb +166 -57
  193. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  194. data/spec/unit/braintree/xml_spec.rb +31 -31
  195. metadata +62 -30
  196. data/lib/braintree/amex_express_checkout_card.rb +0 -40
  197. data/lib/braintree/coinbase_account.rb +0 -34
  198. data/lib/braintree/europe_bank_account.rb +0 -36
  199. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  200. data/lib/braintree/ideal_payment.rb +0 -61
  201. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  202. data/lib/braintree/masterpass_card.rb +0 -83
  203. data/lib/braintree/settlement_batch.rb +0 -0
  204. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  205. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  206. data/lib/braintree/transaction/masterpass_card_details.rb +0 -49
  207. data/lib/braintree/transparent_redirect.rb +0 -40
  208. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  209. data/spec/hacks/tcp_socket.rb +0 -18
  210. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  211. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  212. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  213. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
@@ -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
@@ -99,89 +99,89 @@ describe Braintree::PaymentMethod do
99
99
  apple_pay_card.expiration_month.to_i.should > 0
100
100
  apple_pay_card.expiration_year.to_i.should > 0
101
101
  apple_pay_card.customer_id.should == customer.id
102
+ apple_pay_card.commercial.should_not be_nil
103
+ apple_pay_card.country_of_issuance.should_not be_nil
104
+ apple_pay_card.debit.should_not be_nil
105
+ apple_pay_card.durbin_regulated.should_not be_nil
106
+ apple_pay_card.healthcare.should_not be_nil
107
+ apple_pay_card.issuing_bank.should_not be_nil
108
+ apple_pay_card.payroll.should_not be_nil
109
+ apple_pay_card.prepaid.should_not be_nil
110
+ apple_pay_card.product_id.should_not be_nil
102
111
  end
103
112
 
104
- it "creates a payment method from a fake android pay proxy card nonce" do
105
- customer = Braintree::Customer.create.customer
106
- token = SecureRandom.hex(16)
107
- result = Braintree::PaymentMethod.create(
108
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover,
109
- :customer_id => customer.id,
110
- :token => token
111
- )
112
-
113
- result.should be_success
114
- android_pay_card = result.payment_method
115
- android_pay_card.should be_a(Braintree::AndroidPayCard)
116
- android_pay_card.should_not be_nil
117
- android_pay_card.token.should == token
118
- android_pay_card.card_type.should == Braintree::CreditCard::CardType::Discover
119
- android_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
120
- android_pay_card.expiration_month.to_i.should > 0
121
- android_pay_card.expiration_year.to_i.should > 0
122
- android_pay_card.default.should == true
123
- android_pay_card.image_url.should =~ /android_pay/
124
- android_pay_card.is_network_tokenized?.should == false
125
- android_pay_card.source_card_type.should == Braintree::CreditCard::CardType::Discover
126
- android_pay_card.source_card_last_4.should == "1111"
127
- android_pay_card.google_transaction_id.should == "google_transaction_id"
128
- android_pay_card.source_description.should == "Discover 1111"
129
- android_pay_card.customer_id.should == customer.id
130
- end
131
-
132
- it "creates a payment method from a android pay network token nonce" do
113
+ it "creates a payment method from a fake google pay proxy card nonce" do
133
114
  customer = Braintree::Customer.create.customer
134
115
  token = SecureRandom.hex(16)
135
116
  result = Braintree::PaymentMethod.create(
136
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayMasterCard,
117
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
137
118
  :customer_id => customer.id,
138
- :token => token
119
+ :token => token,
139
120
  )
140
121
 
141
122
  result.should be_success
142
- android_pay_card = result.payment_method
143
- android_pay_card.should be_a(Braintree::AndroidPayCard)
144
- android_pay_card.should_not be_nil
145
- android_pay_card.token.should == token
146
- android_pay_card.card_type.should == Braintree::CreditCard::CardType::MasterCard
147
- android_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
148
- android_pay_card.expiration_month.to_i.should > 0
149
- android_pay_card.expiration_year.to_i.should > 0
150
- android_pay_card.default.should == true
151
- android_pay_card.image_url.should =~ /android_pay/
152
- android_pay_card.is_network_tokenized?.should == true
153
- android_pay_card.source_card_type.should == Braintree::CreditCard::CardType::MasterCard
154
- android_pay_card.source_card_last_4.should == "4444"
155
- android_pay_card.google_transaction_id.should == "google_transaction_id"
156
- android_pay_card.source_description.should == "MasterCard 4444"
157
- android_pay_card.customer_id.should == customer.id
123
+ google_pay_card = result.payment_method
124
+ google_pay_card.should be_a(Braintree::GooglePayCard)
125
+ google_pay_card.should_not be_nil
126
+ google_pay_card.token.should == token
127
+ google_pay_card.card_type.should == Braintree::CreditCard::CardType::Discover
128
+ google_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
129
+ google_pay_card.expiration_month.to_i.should > 0
130
+ google_pay_card.expiration_year.to_i.should > 0
131
+ google_pay_card.default.should == true
132
+ google_pay_card.image_url.should =~ /android_pay/
133
+ google_pay_card.is_network_tokenized?.should == false
134
+ google_pay_card.source_card_type.should == Braintree::CreditCard::CardType::Discover
135
+ google_pay_card.source_card_last_4.should == "1111"
136
+ google_pay_card.google_transaction_id.should == "google_transaction_id"
137
+ google_pay_card.source_description.should == "Discover 1111"
138
+ google_pay_card.customer_id.should == customer.id
139
+ google_pay_card.commercial.should_not be_nil
140
+ google_pay_card.country_of_issuance.should_not be_nil
141
+ google_pay_card.debit.should_not be_nil
142
+ google_pay_card.durbin_regulated.should_not be_nil
143
+ google_pay_card.healthcare.should_not be_nil
144
+ google_pay_card.issuing_bank.should_not be_nil
145
+ google_pay_card.payroll.should_not be_nil
146
+ google_pay_card.prepaid.should_not be_nil
147
+ google_pay_card.product_id.should_not be_nil
158
148
  end
159
149
 
160
- it "creates a payment method from an amex express checkout card nonce" do
150
+ it "creates a payment method from a google pay network token nonce" do
161
151
  customer = Braintree::Customer.create.customer
162
152
  token = SecureRandom.hex(16)
163
153
  result = Braintree::PaymentMethod.create(
164
- :payment_method_nonce => Braintree::Test::Nonce::AmexExpressCheckout,
154
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
165
155
  :customer_id => customer.id,
166
- :token => token
156
+ :token => token,
167
157
  )
168
158
 
169
159
  result.should be_success
170
- amex_express_checkout_card = result.payment_method
171
- amex_express_checkout_card.should be_a(Braintree::AmexExpressCheckoutCard)
172
- amex_express_checkout_card.should_not be_nil
173
-
174
- amex_express_checkout_card.default.should == true
175
- amex_express_checkout_card.card_type.should == "American Express"
176
- amex_express_checkout_card.token.should == token
177
- amex_express_checkout_card.bin.should =~ /\A\d{6}\z/
178
- amex_express_checkout_card.expiration_month.should =~ /\A\d{2}\z/
179
- amex_express_checkout_card.expiration_year.should =~ /\A\d{4}\z/
180
- amex_express_checkout_card.card_member_number.should =~ /\A\d{4}\z/
181
- amex_express_checkout_card.card_member_expiry_date.should =~ /\A\d{2}\/\d{2}\z/
182
- amex_express_checkout_card.image_url.should include(".png")
183
- amex_express_checkout_card.source_description.should =~ /\AAmEx \d{4}\z/
184
- amex_express_checkout_card.customer_id.should == customer.id
160
+ google_pay_card = result.payment_method
161
+ google_pay_card.should be_a(Braintree::GooglePayCard)
162
+ google_pay_card.should_not be_nil
163
+ google_pay_card.token.should == token
164
+ google_pay_card.card_type.should == Braintree::CreditCard::CardType::MasterCard
165
+ google_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
166
+ google_pay_card.expiration_month.to_i.should > 0
167
+ google_pay_card.expiration_year.to_i.should > 0
168
+ google_pay_card.default.should == true
169
+ google_pay_card.image_url.should =~ /android_pay/
170
+ google_pay_card.is_network_tokenized?.should == true
171
+ google_pay_card.source_card_type.should == Braintree::CreditCard::CardType::MasterCard
172
+ google_pay_card.source_card_last_4.should == "4444"
173
+ google_pay_card.google_transaction_id.should == "google_transaction_id"
174
+ google_pay_card.source_description.should == "MasterCard 4444"
175
+ google_pay_card.customer_id.should == customer.id
176
+ google_pay_card.commercial.should_not be_nil
177
+ google_pay_card.country_of_issuance.should_not be_nil
178
+ google_pay_card.debit.should_not be_nil
179
+ google_pay_card.durbin_regulated.should_not be_nil
180
+ google_pay_card.healthcare.should_not be_nil
181
+ google_pay_card.issuing_bank.should_not be_nil
182
+ google_pay_card.payroll.should_not be_nil
183
+ google_pay_card.prepaid.should_not be_nil
184
+ google_pay_card.product_id.should_not be_nil
185
185
  end
186
186
 
187
187
  it "creates a payment method from venmo account nonce" do
@@ -190,7 +190,7 @@ describe Braintree::PaymentMethod do
190
190
  result = Braintree::PaymentMethod.create(
191
191
  :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
192
192
  :customer_id => customer.id,
193
- :token => token
193
+ :token => token,
194
194
  )
195
195
 
196
196
  result.should be_success
@@ -200,7 +200,7 @@ describe Braintree::PaymentMethod do
200
200
  venmo_account.default.should == true
201
201
  venmo_account.token.should == token
202
202
  venmo_account.username.should == "venmojoe"
203
- venmo_account.venmo_user_id.should == "Venmo-Joe-1"
203
+ venmo_account.venmo_user_id.should == "1234567891234567891"
204
204
  venmo_account.image_url.should include(".png")
205
205
  venmo_account.source_description.should == "Venmo Account: venmojoe"
206
206
  venmo_account.customer_id.should == customer.id
@@ -212,7 +212,7 @@ describe Braintree::PaymentMethod do
212
212
  :customer_id => customer.id,
213
213
  :number => Braintree::Test::CreditCardNumbers::Visa,
214
214
  :expiration_date => "05/2009",
215
- :cvv => "100"
215
+ :cvv => "100",
216
216
  )
217
217
  result.success?.should == true
218
218
  original_payment_method = result.credit_card
@@ -222,7 +222,7 @@ describe Braintree::PaymentMethod do
222
222
  result = Braintree::PaymentMethod.create(
223
223
  :payment_method_nonce => nonce,
224
224
  :customer_id => customer.id,
225
- :options => {:make_default => true}
225
+ :options => {:make_default => true},
226
226
  )
227
227
 
228
228
  result.should be_success
@@ -237,12 +237,12 @@ describe Braintree::PaymentMethod do
237
237
  second_token = make_token
238
238
  nonce = nonce_for_paypal_account(
239
239
  :consent_code => "PAYPAL_CONSENT_CODE",
240
- :token => first_token
240
+ :token => first_token,
241
241
  )
242
242
  result = Braintree::PaymentMethod.create(
243
243
  :payment_method_nonce => nonce,
244
244
  :customer_id => customer.id,
245
- :token => second_token
245
+ :token => second_token,
246
246
  )
247
247
 
248
248
  result.should be_success
@@ -256,7 +256,7 @@ describe Braintree::PaymentMethod do
256
256
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
257
257
  :expiration_month => "11",
258
258
  :expiration_year => "2099",
259
- }
259
+ },
260
260
  )
261
261
  customer = Braintree::Customer.create!
262
262
  result = Braintree::PaymentMethod.create(
@@ -265,7 +265,7 @@ describe Braintree::PaymentMethod do
265
265
  :options => {
266
266
  :verify_card => true,
267
267
  :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
268
- }
268
+ },
269
269
  )
270
270
 
271
271
  result.should_not be_success
@@ -281,7 +281,7 @@ describe Braintree::PaymentMethod do
281
281
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
282
282
  :expiration_month => "11",
283
283
  :expiration_year => "2099",
284
- }
284
+ },
285
285
  )
286
286
  customer = Braintree::Customer.create!
287
287
  result = Braintree::PaymentMethod.create(
@@ -290,7 +290,7 @@ describe Braintree::PaymentMethod do
290
290
  :options => {
291
291
  :verify_card => true,
292
292
  :verification_amount => "100.00"
293
- }
293
+ },
294
294
  )
295
295
 
296
296
  result.should_not be_success
@@ -306,16 +306,16 @@ describe Braintree::PaymentMethod do
306
306
  :customer_id => customer.id,
307
307
  :payment_method_nonce => Braintree::Test::Nonce::Transactable,
308
308
  :three_d_secure_pass_thru => {
309
- :eci_flag => '02',
310
- :cavv => 'some_cavv',
311
- :xid => 'some_xid',
312
- :three_d_secure_version => 'xx',
313
- :authentication_response => 'Y',
314
- :directory_response => 'Y',
315
- :cavv_algorithm => '2',
316
- :ds_transaction_id => 'some_ds_transaction_id',
309
+ :eci_flag => "02",
310
+ :cavv => "some_cavv",
311
+ :xid => "some_xid",
312
+ :three_d_secure_version => "xx",
313
+ :authentication_response => "Y",
314
+ :directory_response => "Y",
315
+ :cavv_algorithm => "2",
316
+ :ds_transaction_id => "some_ds_transaction_id",
317
317
  },
318
- :options => {:verify_card => true}
318
+ :options => {:verify_card => true},
319
319
  )
320
320
  expect(result).not_to be_success
321
321
  error = result.errors.for(:verification).first
@@ -329,16 +329,16 @@ describe Braintree::PaymentMethod do
329
329
  :customer_id => customer.id,
330
330
  :payment_method_nonce => Braintree::Test::Nonce::Transactable,
331
331
  :three_d_secure_pass_thru => {
332
- :eci_flag => '02',
333
- :cavv => 'some_cavv',
334
- :xid => 'some_xid',
335
- :three_d_secure_version => '1.0.2',
336
- :authentication_response => 'Y',
337
- :directory_response => 'Y',
338
- :cavv_algorithm => '2',
339
- :ds_transaction_id => 'some_ds_transaction_id',
332
+ :eci_flag => "02",
333
+ :cavv => "some_cavv",
334
+ :xid => "some_xid",
335
+ :three_d_secure_version => "1.0.2",
336
+ :authentication_response => "Y",
337
+ :directory_response => "Y",
338
+ :cavv_algorithm => "2",
339
+ :ds_transaction_id => "some_ds_transaction_id",
340
340
  },
341
- :options => {:verify_card => true}
341
+ :options => {:verify_card => true},
342
342
  )
343
343
 
344
344
  expect(result).to be_success
@@ -370,7 +370,7 @@ describe Braintree::PaymentMethod do
370
370
  result = Braintree::CreditCard.create(
371
371
  :customer_id => customer.id,
372
372
  :number => Braintree::Test::CreditCardNumbers::Visa,
373
- :expiration_date => "05/2012"
373
+ :expiration_date => "05/2012",
374
374
  )
375
375
  result.should be_success
376
376
 
@@ -378,14 +378,14 @@ describe Braintree::PaymentMethod do
378
378
  :credit_card => {
379
379
  :number => Braintree::Test::CreditCardNumbers::Visa,
380
380
  :expiration_date => "05/2012"
381
- }
381
+ },
382
382
  )
383
383
  result = Braintree::PaymentMethod.create(
384
384
  :payment_method_nonce => nonce,
385
385
  :customer_id => customer.id,
386
386
  :options => {
387
387
  :fail_on_duplicate_payment_method => true
388
- }
388
+ },
389
389
  )
390
390
 
391
391
  result.should_not be_success
@@ -402,14 +402,14 @@ describe Braintree::PaymentMethod do
402
402
  config,
403
403
  :authorization_fingerprint => authorization_fingerprint,
404
404
  :shared_customer_identifier => "fake_identifier",
405
- :shared_customer_identifier_type => "testing"
405
+ :shared_customer_identifier_type => "testing",
406
406
  )
407
407
 
408
408
  response = http.create_credit_card(
409
409
  :number => "4111111111111111",
410
410
  :expirationMonth => "12",
411
411
  :expirationYear => "2020",
412
- :options => {:validate => false}
412
+ :options => {:validate => false},
413
413
  )
414
414
  response.code.should == "202"
415
415
 
@@ -419,7 +419,7 @@ describe Braintree::PaymentMethod do
419
419
  :customer_id => customer.id,
420
420
  :billing_address => {
421
421
  :street_address => "123 Abc Way"
422
- }
422
+ },
423
423
  )
424
424
 
425
425
  result.should be_success
@@ -441,14 +441,14 @@ describe Braintree::PaymentMethod do
441
441
  config,
442
442
  :authorization_fingerprint => authorization_fingerprint,
443
443
  :shared_customer_identifier => "fake_identifier",
444
- :shared_customer_identifier_type => "testing"
444
+ :shared_customer_identifier_type => "testing",
445
445
  )
446
446
 
447
447
  response = http.create_credit_card(
448
448
  :number => "4111111111111111",
449
449
  :expirationMonth => "12",
450
450
  :expirationYear => "2020",
451
- :options => {:validate => false}
451
+ :options => {:validate => false},
452
452
  )
453
453
  response.code.should == "202"
454
454
 
@@ -458,7 +458,7 @@ describe Braintree::PaymentMethod do
458
458
  result = Braintree::PaymentMethod.create(
459
459
  :payment_method_nonce => nonce,
460
460
  :customer_id => customer.id,
461
- :billing_address_id => address.id
461
+ :billing_address_id => address.id,
462
462
  )
463
463
 
464
464
  result.should be_success
@@ -481,7 +481,7 @@ describe Braintree::PaymentMethod do
481
481
  config,
482
482
  :authorization_fingerprint => authorization_fingerprint,
483
483
  :shared_customer_identifier => "fake_identifier",
484
- :shared_customer_identifier_type => "testing"
484
+ :shared_customer_identifier_type => "testing",
485
485
  )
486
486
 
487
487
  response = http.create_credit_card(
@@ -491,7 +491,7 @@ describe Braintree::PaymentMethod do
491
491
  :options => {:validate => false},
492
492
  :billing_address => {
493
493
  :street_address => "456 Xyz Way"
494
- }
494
+ },
495
495
  )
496
496
  response.code.should == "202"
497
497
 
@@ -501,7 +501,7 @@ describe Braintree::PaymentMethod do
501
501
  :customer_id => customer.id,
502
502
  :billing_address => {
503
503
  :street_address => "123 Abc Way"
504
- }
504
+ },
505
505
  )
506
506
 
507
507
  result.should be_success
@@ -523,7 +523,7 @@ describe Braintree::PaymentMethod do
523
523
  config,
524
524
  :authorization_fingerprint => authorization_fingerprint,
525
525
  :shared_customer_identifier => "fake_identifier",
526
- :shared_customer_identifier_type => "testing"
526
+ :shared_customer_identifier_type => "testing",
527
527
  )
528
528
 
529
529
  response = http.create_credit_card(
@@ -532,7 +532,7 @@ describe Braintree::PaymentMethod do
532
532
  :expirationYear => 2020,
533
533
  :billing_address => {
534
534
  :street_address => "456 Xyz Way"
535
- }
535
+ },
536
536
  )
537
537
  response.code.should == "201"
538
538
 
@@ -542,7 +542,7 @@ describe Braintree::PaymentMethod do
542
542
  :customer_id => customer.id,
543
543
  :billing_address => {
544
544
  :street_address => "123 Abc Way"
545
- }
545
+ },
546
546
  )
547
547
 
548
548
  result.should be_success
@@ -554,6 +554,58 @@ describe Braintree::PaymentMethod do
554
554
  found_credit_card.billing_address.street_address.should == "456 Xyz Way"
555
555
  end
556
556
 
557
+ it "includes risk data when skip_advanced_fraud_checking is false" do
558
+ with_fraud_protection_enterprise_merchant do
559
+ customer = Braintree::Customer.create!
560
+
561
+ nonce = nonce_for_new_payment_method(
562
+ :credit_card => {
563
+ :cvv => "123",
564
+ :number => Braintree::Test::CreditCardNumbers::Visa,
565
+ :expiration_date => "05/2009",
566
+ },
567
+ )
568
+ result = Braintree::PaymentMethod.create(
569
+ :payment_method_nonce => nonce,
570
+ :customer_id => customer.id,
571
+ :options => {
572
+ :verify_card => true,
573
+ :skip_advanced_fraud_checking => false,
574
+ },
575
+ )
576
+
577
+ expect(result).to be_success
578
+ verification = result.payment_method.verification
579
+ expect(verification.risk_data).not_to be_nil
580
+ end
581
+ end
582
+
583
+ it "does not include risk data when skip_advanced_fraud_checking is true" do
584
+ with_fraud_protection_enterprise_merchant do
585
+ customer = Braintree::Customer.create!
586
+
587
+ nonce = nonce_for_new_payment_method(
588
+ :credit_card => {
589
+ :cvv => "123",
590
+ :number => Braintree::Test::CreditCardNumbers::Visa,
591
+ :expiration_date => "05/2009",
592
+ },
593
+ )
594
+ result = Braintree::PaymentMethod.create(
595
+ :payment_method_nonce => nonce,
596
+ :customer_id => customer.id,
597
+ :options => {
598
+ :verify_card => true,
599
+ :skip_advanced_fraud_checking => true,
600
+ },
601
+ )
602
+
603
+ expect(result).to be_success
604
+ verification = result.payment_method.verification
605
+ expect(verification.risk_data).to be_nil
606
+ end
607
+ end
608
+
557
609
  context "account_type" do
558
610
  it "verifies card with account_type debit" do
559
611
  nonce = nonce_for_new_payment_method(
@@ -561,7 +613,7 @@ describe Braintree::PaymentMethod do
561
613
  :number => Braintree::Test::CreditCardNumbers::Hiper,
562
614
  :expiration_month => "11",
563
615
  :expiration_year => "2099",
564
- }
616
+ },
565
617
  )
566
618
  customer = Braintree::Customer.create!
567
619
  result = Braintree::PaymentMethod.create(
@@ -571,7 +623,7 @@ describe Braintree::PaymentMethod do
571
623
  :verify_card => true,
572
624
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
573
625
  :verification_account_type => "debit",
574
- }
626
+ },
575
627
  )
576
628
 
577
629
  result.should be_success
@@ -584,7 +636,7 @@ describe Braintree::PaymentMethod do
584
636
  :number => Braintree::Test::CreditCardNumbers::Hiper,
585
637
  :expiration_month => "11",
586
638
  :expiration_year => "2099",
587
- }
639
+ },
588
640
  )
589
641
  customer = Braintree::Customer.create!
590
642
  result = Braintree::PaymentMethod.create(
@@ -594,7 +646,7 @@ describe Braintree::PaymentMethod do
594
646
  :verify_card => true,
595
647
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
596
648
  :verification_account_type => "credit",
597
- }
649
+ },
598
650
  )
599
651
 
600
652
  result.should be_success
@@ -607,7 +659,7 @@ describe Braintree::PaymentMethod do
607
659
  :number => Braintree::Test::CreditCardNumbers::Hiper,
608
660
  :expiration_month => "11",
609
661
  :expiration_year => "2099",
610
- }
662
+ },
611
663
  )
612
664
  customer = Braintree::Customer.create!
613
665
  result = Braintree::PaymentMethod.create(
@@ -617,7 +669,7 @@ describe Braintree::PaymentMethod do
617
669
  :verify_card => true,
618
670
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
619
671
  :verification_account_type => "ach",
620
- }
672
+ },
621
673
  )
622
674
 
623
675
  result.should_not be_success
@@ -630,7 +682,7 @@ describe Braintree::PaymentMethod do
630
682
  :number => Braintree::Test::CreditCardNumbers::Visa,
631
683
  :expiration_month => "11",
632
684
  :expiration_year => "2099",
633
- }
685
+ },
634
686
  )
635
687
  customer = Braintree::Customer.create!
636
688
  result = Braintree::PaymentMethod.create(
@@ -639,7 +691,7 @@ describe Braintree::PaymentMethod do
639
691
  :options => {
640
692
  :verify_card => true,
641
693
  :verification_account_type => "credit",
642
- }
694
+ },
643
695
  )
644
696
 
645
697
  result.should_not be_success
@@ -653,7 +705,7 @@ describe Braintree::PaymentMethod do
653
705
  :customer_id => customer.id,
654
706
  :cvv => "123",
655
707
  :number => Braintree::Test::CreditCardNumbers::Visa,
656
- :expiration_date => "05/2012"
708
+ :expiration_date => "05/2012",
657
709
  )
658
710
  update_result = Braintree::PaymentMethod.update(credit_card.token,
659
711
  :cardholder_name => "New Holder",
@@ -677,7 +729,7 @@ describe Braintree::PaymentMethod do
677
729
  :customer_id => customer.id,
678
730
  :cvv => "123",
679
731
  :number => Braintree::Test::CreditCardNumbers::Visa,
680
- :expiration_date => "05/2012"
732
+ :expiration_date => "05/2012",
681
733
  )
682
734
  update_result = Braintree::PaymentMethod.update(credit_card.token,
683
735
  :cardholder_name => "New Holder",
@@ -701,7 +753,7 @@ describe Braintree::PaymentMethod do
701
753
  customer = Braintree::Customer.create.customer
702
754
  result = Braintree::PaymentMethod.create(
703
755
  :payment_method_nonce => nonce,
704
- :customer_id => customer.id
756
+ :customer_id => customer.id,
705
757
  )
706
758
 
707
759
  result.should be_success
@@ -778,7 +830,7 @@ describe Braintree::PaymentMethod do
778
830
  nonce = nonce_for_paypal_account(:access_token => "PAYPAL_ACCESS_TOKEN")
779
831
  result = Braintree::PaymentMethod.create(
780
832
  :payment_method_nonce => nonce,
781
- :customer_id => customer.id
833
+ :customer_id => customer.id,
782
834
  )
783
835
 
784
836
  result.should_not be_success
@@ -793,7 +845,7 @@ describe Braintree::PaymentMethod do
793
845
  :customer_id => customer.id,
794
846
  :billing_address => {
795
847
  :street_address => "123 Abc Way"
796
- }
848
+ },
797
849
  )
798
850
 
799
851
  result.should be_success
@@ -811,7 +863,7 @@ describe Braintree::PaymentMethod do
811
863
  result = Braintree::PaymentMethod.create(
812
864
  :payment_method_nonce => nonce,
813
865
  :customer_id => customer.id,
814
- :billing_address_id => "address_id"
866
+ :billing_address_id => "address_id",
815
867
  )
816
868
 
817
869
  result.should be_success
@@ -828,7 +880,7 @@ describe Braintree::PaymentMethod do
828
880
  nonce = nonce_for_paypal_account(:token => "PAYPAL_TOKEN")
829
881
  result = Braintree::PaymentMethod.create(
830
882
  :payment_method_nonce => nonce,
831
- :customer_id => customer.id
883
+ :customer_id => customer.id,
832
884
  )
833
885
 
834
886
  result.should_not be_success
@@ -842,7 +894,7 @@ describe Braintree::PaymentMethod do
842
894
  original_token = random_payment_method_token
843
895
  nonce = nonce_for_paypal_account(
844
896
  :consent_code => "consent-code",
845
- :token => original_token
897
+ :token => original_token,
846
898
  )
847
899
 
848
900
  result = Braintree::PaymentMethod.create(
@@ -852,7 +904,7 @@ describe Braintree::PaymentMethod do
852
904
  :verify_card => true,
853
905
  :fail_on_duplicate_payment_method => true,
854
906
  :verification_merchant_account_id => "not_a_real_merchant_account_id"
855
- }
907
+ },
856
908
  )
857
909
 
858
910
  result.should be_success
@@ -866,7 +918,7 @@ describe Braintree::PaymentMethod do
866
918
  result = Braintree::PaymentMethod.create(
867
919
  :payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable,
868
920
  :customer_id => customer.id,
869
- :token => token
921
+ :token => token,
870
922
  )
871
923
 
872
924
  result.should be_success
@@ -876,6 +928,99 @@ describe Braintree::PaymentMethod do
876
928
  payment_method.should be_a Braintree::UnknownPaymentMethod
877
929
  end
878
930
  end
931
+
932
+ context "verification_currency_iso_code" do
933
+ it "validates verification_currency_iso_code against currency configured in default merchant account" do
934
+ nonce = nonce_for_new_payment_method(
935
+ :credit_card => {
936
+ :number => Braintree::Test::CreditCardNumbers::Visa,
937
+ :expiration_month => "11",
938
+ :expiration_year => "2099",
939
+ },
940
+ )
941
+ customer = Braintree::Customer.create!
942
+ result = Braintree::PaymentMethod.create(
943
+ :payment_method_nonce => nonce,
944
+ :customer_id => customer.id,
945
+ :options => {
946
+ :verify_card => true,
947
+ :verification_currency_iso_code => "USD"
948
+ },
949
+ )
950
+
951
+ result.should be_success
952
+ result.payment_method.verification.currency_iso_code == "USD"
953
+ end
954
+
955
+ it "validates verification_currency_iso_code against currency configured in verification_merchant_account_id" do
956
+ nonce = nonce_for_new_payment_method(
957
+ :credit_card => {
958
+ :number => Braintree::Test::CreditCardNumbers::Visa,
959
+ :expiration_month => "11",
960
+ :expiration_year => "2099",
961
+ },
962
+ )
963
+ customer = Braintree::Customer.create!
964
+ result = Braintree::PaymentMethod.create(
965
+ :payment_method_nonce => nonce,
966
+ :customer_id => customer.id,
967
+ :options => {
968
+ :verify_card => true,
969
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
970
+ :verification_currency_iso_code => "USD"
971
+ },
972
+ )
973
+
974
+ result.should be_success
975
+ result.payment_method.verification.currency_iso_code == "USD"
976
+ result.payment_method.verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
977
+ end
978
+
979
+
980
+ it "errors with invalid presentment currency due to verification_currency_iso_code not matching with currency configured in default merchant account" do
981
+ nonce = nonce_for_new_payment_method(
982
+ :credit_card => {
983
+ :number => Braintree::Test::CreditCardNumbers::Visa,
984
+ :expiration_month => "11",
985
+ :expiration_year => "2099",
986
+ },
987
+ )
988
+ customer = Braintree::Customer.create!
989
+ result = Braintree::PaymentMethod.create(
990
+ :payment_method_nonce => nonce,
991
+ :customer_id => customer.id,
992
+ :options => {
993
+ :verify_card => true,
994
+ :verification_currency_iso_code => "GBP"
995
+ },
996
+ )
997
+ result.should_not be_success
998
+ result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
999
+ end
1000
+
1001
+ it "errors with invalid presentment currency due to verification_currency_iso_code not matching with currency configured in verification_merchant_account_id" do
1002
+ nonce = nonce_for_new_payment_method(
1003
+ :credit_card => {
1004
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1005
+ :expiration_month => "11",
1006
+ :expiration_year => "2099",
1007
+ },
1008
+ )
1009
+ customer = Braintree::Customer.create!
1010
+ result = Braintree::PaymentMethod.create(
1011
+ :payment_method_nonce => nonce,
1012
+ :customer_id => customer.id,
1013
+ :options => {
1014
+ :verify_card => true,
1015
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
1016
+ :verification_currency_iso_code => "GBP"
1017
+ },
1018
+ )
1019
+
1020
+ result.should_not be_success
1021
+ result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1022
+ end
1023
+ end
879
1024
  end
880
1025
 
881
1026
  describe "self.create!" do
@@ -889,20 +1034,20 @@ describe Braintree::PaymentMethod do
889
1034
  config,
890
1035
  :authorization_fingerprint => authorization_fingerprint,
891
1036
  :shared_customer_identifier => "fake_identifier",
892
- :shared_customer_identifier_type => "testing"
1037
+ :shared_customer_identifier_type => "testing",
893
1038
  )
894
1039
 
895
1040
  response = http.create_credit_card(
896
1041
  :number => 4111111111111111,
897
1042
  :expirationMonth => 12,
898
- :expirationYear => 2020
1043
+ :expirationYear => 2020,
899
1044
  )
900
1045
  response.code.should == "201"
901
1046
 
902
1047
  nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
903
1048
  payment_method = Braintree::PaymentMethod.create!(
904
1049
  :payment_method_nonce => nonce,
905
- :customer_id => customer.id
1050
+ :customer_id => customer.id,
906
1051
  )
907
1052
 
908
1053
  payment_method.should be_a(Braintree::CreditCard)
@@ -920,7 +1065,7 @@ describe Braintree::PaymentMethod do
920
1065
  result = Braintree::CreditCard.create(
921
1066
  :customer_id => customer.id,
922
1067
  :number => Braintree::Test::CreditCardNumbers::Visa,
923
- :expiration_date => "05/2012"
1068
+ :expiration_date => "05/2012",
924
1069
  )
925
1070
  result.success?.should == true
926
1071
 
@@ -936,13 +1081,13 @@ describe Braintree::PaymentMethod do
936
1081
  credit_card = Braintree::CreditCard.create(
937
1082
  :customer_id => customer.id,
938
1083
  :number => Braintree::Test::CreditCardNumbers::Visa,
939
- :expiration_date => "05/2012"
1084
+ :expiration_date => "05/2012",
940
1085
  ).credit_card
941
1086
 
942
1087
  subscription = Braintree::Subscription.create(
943
1088
  :payment_method_token => credit_card.token,
944
1089
  :plan_id => "integration_trialless_plan",
945
- :price => "1.00"
1090
+ :price => "1.00",
946
1091
  ).subscription
947
1092
 
948
1093
  found_card = Braintree::PaymentMethod.find(credit_card.token)
@@ -959,11 +1104,11 @@ describe Braintree::PaymentMethod do
959
1104
  payment_method_token = make_token
960
1105
  nonce = nonce_for_paypal_account(
961
1106
  :consent_code => "consent-code",
962
- :token => payment_method_token
1107
+ :token => payment_method_token,
963
1108
  )
964
1109
  result = Braintree::PaymentMethod.create(
965
1110
  :payment_method_nonce => nonce,
966
- :customer_id => customer.id
1111
+ :customer_id => customer.id,
967
1112
  )
968
1113
  result.should be_success
969
1114
 
@@ -982,7 +1127,7 @@ describe Braintree::PaymentMethod do
982
1127
  result = Braintree::PaymentMethod.create(
983
1128
  :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
984
1129
  :customer_id => customer.id,
985
- :token => payment_method_token
1130
+ :token => payment_method_token,
986
1131
  )
987
1132
  result.should be_success
988
1133
 
@@ -1007,7 +1152,7 @@ describe Braintree::PaymentMethod do
1007
1152
  result = Braintree::PaymentMethod.create(
1008
1153
  :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
1009
1154
  :customer_id => customer.id,
1010
- :token => payment_method_token
1155
+ :token => payment_method_token,
1011
1156
  )
1012
1157
  result.should be_success
1013
1158
 
@@ -1017,68 +1162,68 @@ describe Braintree::PaymentMethod do
1017
1162
  venmo_account.token.should == payment_method_token
1018
1163
  venmo_account.default.should == true
1019
1164
  venmo_account.image_url.should =~ /venmo/
1020
- venmo_account.username.should == 'venmojoe'
1021
- venmo_account.venmo_user_id.should == 'Venmo-Joe-1'
1165
+ venmo_account.username.should == "venmojoe"
1166
+ venmo_account.venmo_user_id.should == "1234567891234567891"
1022
1167
  venmo_account.source_description.should == "Venmo Account: venmojoe"
1023
1168
  venmo_account.customer_id.should == customer.id
1024
1169
  end
1025
1170
  end
1026
1171
 
1027
- context "android pay cards" do
1172
+ context "google pay cards" do
1028
1173
  it "finds the proxy card payment method with the given token" do
1029
1174
  customer = Braintree::Customer.create!
1030
1175
  payment_method_token = make_token
1031
1176
  result = Braintree::PaymentMethod.create(
1032
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover,
1177
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
1033
1178
  :customer_id => customer.id,
1034
- :token => payment_method_token
1179
+ :token => payment_method_token,
1035
1180
  )
1036
1181
  result.should be_success
1037
1182
 
1038
- android_pay_card = Braintree::PaymentMethod.find(payment_method_token)
1039
- android_pay_card.should be_a(Braintree::AndroidPayCard)
1040
- android_pay_card.should_not be_nil
1041
- android_pay_card.token.should == payment_method_token
1042
- android_pay_card.card_type.should == Braintree::CreditCard::CardType::Discover
1043
- android_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1044
- android_pay_card.expiration_month.to_i.should > 0
1045
- android_pay_card.expiration_year.to_i.should > 0
1046
- android_pay_card.default.should == true
1047
- android_pay_card.image_url.should =~ /android_pay/
1048
- android_pay_card.is_network_tokenized?.should == false
1049
- android_pay_card.source_card_type.should == Braintree::CreditCard::CardType::Discover
1050
- android_pay_card.source_card_last_4.should == "1111"
1051
- android_pay_card.google_transaction_id.should == "google_transaction_id"
1052
- android_pay_card.source_description.should == "Discover 1111"
1053
- android_pay_card.customer_id.should == customer.id
1183
+ google_pay_card = Braintree::PaymentMethod.find(payment_method_token)
1184
+ google_pay_card.should be_a(Braintree::GooglePayCard)
1185
+ google_pay_card.should_not be_nil
1186
+ google_pay_card.token.should == payment_method_token
1187
+ google_pay_card.card_type.should == Braintree::CreditCard::CardType::Discover
1188
+ google_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1189
+ google_pay_card.expiration_month.to_i.should > 0
1190
+ google_pay_card.expiration_year.to_i.should > 0
1191
+ google_pay_card.default.should == true
1192
+ google_pay_card.image_url.should =~ /android_pay/
1193
+ google_pay_card.is_network_tokenized?.should == false
1194
+ google_pay_card.source_card_type.should == Braintree::CreditCard::CardType::Discover
1195
+ google_pay_card.source_card_last_4.should == "1111"
1196
+ google_pay_card.google_transaction_id.should == "google_transaction_id"
1197
+ google_pay_card.source_description.should == "Discover 1111"
1198
+ google_pay_card.customer_id.should == customer.id
1054
1199
  end
1055
1200
 
1056
1201
  it "finds the network token payment method with the given token" do
1057
1202
  customer = Braintree::Customer.create!
1058
1203
  payment_method_token = make_token
1059
1204
  result = Braintree::PaymentMethod.create(
1060
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayMasterCard,
1205
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
1061
1206
  :customer_id => customer.id,
1062
- :token => payment_method_token
1207
+ :token => payment_method_token,
1063
1208
  )
1064
1209
  result.should be_success
1065
1210
 
1066
- android_pay_card = Braintree::PaymentMethod.find(payment_method_token)
1067
- android_pay_card.should be_a(Braintree::AndroidPayCard)
1068
- android_pay_card.should_not be_nil
1069
- android_pay_card.token.should == payment_method_token
1070
- android_pay_card.card_type.should == Braintree::CreditCard::CardType::MasterCard
1071
- android_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
1072
- android_pay_card.expiration_month.to_i.should > 0
1073
- android_pay_card.expiration_year.to_i.should > 0
1074
- android_pay_card.default.should == true
1075
- android_pay_card.image_url.should =~ /android_pay/
1076
- android_pay_card.is_network_tokenized?.should == true
1077
- android_pay_card.source_card_type.should == Braintree::CreditCard::CardType::MasterCard
1078
- android_pay_card.source_card_last_4.should == "4444"
1079
- android_pay_card.google_transaction_id.should == "google_transaction_id"
1080
- android_pay_card.source_description.should == "MasterCard 4444"
1081
- android_pay_card.customer_id.should == customer.id
1211
+ google_pay_card = Braintree::PaymentMethod.find(payment_method_token)
1212
+ google_pay_card.should be_a(Braintree::GooglePayCard)
1213
+ google_pay_card.should_not be_nil
1214
+ google_pay_card.token.should == payment_method_token
1215
+ google_pay_card.card_type.should == Braintree::CreditCard::CardType::MasterCard
1216
+ google_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
1217
+ google_pay_card.expiration_month.to_i.should > 0
1218
+ google_pay_card.expiration_year.to_i.should > 0
1219
+ google_pay_card.default.should == true
1220
+ google_pay_card.image_url.should =~ /android_pay/
1221
+ google_pay_card.is_network_tokenized?.should == true
1222
+ google_pay_card.source_card_type.should == Braintree::CreditCard::CardType::MasterCard
1223
+ google_pay_card.source_card_last_4.should == "4444"
1224
+ google_pay_card.google_transaction_id.should == "google_transaction_id"
1225
+ google_pay_card.source_description.should == "MasterCard 4444"
1226
+ google_pay_card.customer_id.should == customer.id
1082
1227
  end
1083
1228
  end
1084
1229
 
@@ -1089,7 +1234,7 @@ describe Braintree::PaymentMethod do
1089
1234
  result = Braintree::PaymentMethod.create(
1090
1235
  :payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable,
1091
1236
  :customer_id => customer.id,
1092
- :token => payment_method_token
1237
+ :token => payment_method_token,
1093
1238
  )
1094
1239
  result.should be_success
1095
1240
 
@@ -1110,18 +1255,18 @@ describe Braintree::PaymentMethod do
1110
1255
  end
1111
1256
 
1112
1257
  describe "self.delete" do
1113
- it "deletes an android pay card" do
1258
+ it "deletes an google pay card" do
1114
1259
  customer = Braintree::Customer.create!
1115
1260
 
1116
1261
  create_result = Braintree::PaymentMethod.create(
1117
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover,
1118
- :customer_id => customer.id
1262
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
1263
+ :customer_id => customer.id,
1119
1264
  )
1120
1265
 
1121
1266
  token = create_result.payment_method.token
1122
1267
 
1123
- android_card = Braintree::PaymentMethod.find(token)
1124
- android_card.should be_a(Braintree::AndroidPayCard)
1268
+ google_card = Braintree::PaymentMethod.find(token)
1269
+ google_card.should be_a(Braintree::GooglePayCard)
1125
1270
 
1126
1271
  delete_result = Braintree::PaymentMethod.delete(token)
1127
1272
  delete_result.success?.should == true
@@ -1136,7 +1281,7 @@ describe Braintree::PaymentMethod do
1136
1281
 
1137
1282
  create_result = Braintree::PaymentMethod.create(
1138
1283
  :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
1139
- :customer_id => customer.id
1284
+ :customer_id => customer.id,
1140
1285
  )
1141
1286
  token = create_result.payment_method.token
1142
1287
 
@@ -1157,11 +1302,11 @@ describe Braintree::PaymentMethod do
1157
1302
 
1158
1303
  nonce = nonce_for_paypal_account(
1159
1304
  :consent_code => "PAYPAL_CONSENT_CODE",
1160
- :token => paypal_account_token
1305
+ :token => paypal_account_token,
1161
1306
  )
1162
1307
  Braintree::PaymentMethod.create(
1163
1308
  :payment_method_nonce => nonce,
1164
- :customer_id => customer.id
1309
+ :customer_id => customer.id,
1165
1310
  )
1166
1311
 
1167
1312
  paypal_account = Braintree::PaymentMethod.find(paypal_account_token)
@@ -1190,7 +1335,7 @@ describe Braintree::PaymentMethod do
1190
1335
 
1191
1336
  Braintree::PaymentMethod.create(
1192
1337
  :payment_method_nonce => nonce,
1193
- :customer_id => customer.id
1338
+ :customer_id => customer.id,
1194
1339
  )
1195
1340
 
1196
1341
  result = Braintree::PaymentMethod.delete(token)
@@ -1227,14 +1372,14 @@ describe Braintree::PaymentMethod do
1227
1372
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1228
1373
  :expiration_date => "06/2013",
1229
1374
  :three_d_secure_pass_thru => {
1230
- :eci_flag => '02',
1231
- :cavv => 'some_cavv',
1232
- :xid => 'some_xid',
1233
- :three_d_secure_version => 'xx',
1234
- :authentication_response => 'Y',
1235
- :directory_response => 'Y',
1236
- :cavv_algorithm => '2',
1237
- :ds_transaction_id => 'some_ds_transaction_id',
1375
+ :eci_flag => "02",
1376
+ :cavv => "some_cavv",
1377
+ :xid => "some_xid",
1378
+ :three_d_secure_version => "xx",
1379
+ :authentication_response => "Y",
1380
+ :directory_response => "Y",
1381
+ :cavv_algorithm => "2",
1382
+ :ds_transaction_id => "some_ds_transaction_id",
1238
1383
  },
1239
1384
  :options => {:verify_card => true},
1240
1385
  )
@@ -1258,14 +1403,14 @@ describe Braintree::PaymentMethod do
1258
1403
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1259
1404
  :expiration_date => "06/2013",
1260
1405
  :three_d_secure_pass_thru => {
1261
- :eci_flag => '02',
1262
- :cavv => 'some_cavv',
1263
- :xid => 'some_xid',
1264
- :three_d_secure_version => '1.0.2',
1265
- :authentication_response => 'Y',
1266
- :directory_response => 'Y',
1267
- :cavv_algorithm => '2',
1268
- :ds_transaction_id => 'some_ds_transaction_id',
1406
+ :eci_flag => "02",
1407
+ :cavv => "some_cavv",
1408
+ :xid => "some_xid",
1409
+ :three_d_secure_version => "1.0.2",
1410
+ :authentication_response => "Y",
1411
+ :directory_response => "Y",
1412
+ :cavv_algorithm => "2",
1413
+ :ds_transaction_id => "some_ds_transaction_id",
1269
1414
  },
1270
1415
  :options => {:verify_card => true},
1271
1416
  )
@@ -1285,13 +1430,13 @@ describe Braintree::PaymentMethod do
1285
1430
  :customer_id => customer.id,
1286
1431
  :cvv => "123",
1287
1432
  :number => Braintree::Test::CreditCardNumbers::Visa,
1288
- :expiration_date => "05/2012"
1433
+ :expiration_date => "05/2012",
1289
1434
  )
1290
1435
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1291
1436
  :cardholder_name => "New Holder",
1292
1437
  :cvv => "456",
1293
1438
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1294
- :expiration_date => "06/2013"
1439
+ :expiration_date => "06/2013",
1295
1440
  )
1296
1441
  update_result.success?.should == true
1297
1442
  update_result.payment_method.should == credit_card
@@ -1302,6 +1447,142 @@ describe Braintree::PaymentMethod do
1302
1447
  updated_credit_card.expiration_date.should == "06/2013"
1303
1448
  end
1304
1449
 
1450
+ it "includes risk data when skip_advanced_fraud_checking is false" do
1451
+ with_fraud_protection_enterprise_merchant do
1452
+ customer = Braintree::Customer.create!
1453
+ credit_card = Braintree::CreditCard.create!(
1454
+ :customer_id => customer.id,
1455
+ :cvv => "123",
1456
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1457
+ :expiration_date => "05/2012",
1458
+ )
1459
+ update_result = Braintree::PaymentMethod.update(
1460
+ credit_card.token,
1461
+ :cvv => "456",
1462
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1463
+ :expiration_date => "06/2013",
1464
+ :options => {
1465
+ :verify_card => true,
1466
+ :skip_advanced_fraud_checking => false
1467
+ },
1468
+ )
1469
+
1470
+ expect(update_result).to be_success
1471
+ verification = update_result.payment_method.verification
1472
+ expect(verification.risk_data).not_to be_nil
1473
+ end
1474
+ end
1475
+
1476
+ it "does not include risk data when skip_advanced_fraud_checking is true" do
1477
+ with_fraud_protection_enterprise_merchant do
1478
+ customer = Braintree::Customer.create!
1479
+ credit_card = Braintree::CreditCard.create!(
1480
+ :customer_id => customer.id,
1481
+ :cvv => "123",
1482
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1483
+ :expiration_date => "05/2012",
1484
+ )
1485
+ update_result = Braintree::PaymentMethod.update(
1486
+ credit_card.token,
1487
+ :cvv => "456",
1488
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1489
+ :expiration_date => "06/2013",
1490
+ :options => {
1491
+ :verify_card => true,
1492
+ :skip_advanced_fraud_checking => true
1493
+ },
1494
+ )
1495
+
1496
+ expect(update_result).to be_success
1497
+ verification = update_result.payment_method.verification
1498
+ expect(verification.risk_data).to be_nil
1499
+ end
1500
+ end
1501
+
1502
+ context "verification_currency_iso_code" do
1503
+ it "validates verification_currency_iso_code and updates the credit card " do
1504
+ customer = Braintree::Customer.create!
1505
+ credit_card = Braintree::CreditCard.create!(
1506
+ :cardholder_name => "Original Holder",
1507
+ :customer_id => customer.id,
1508
+ :cvv => "123",
1509
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1510
+ :expiration_date => "05/2012",
1511
+ )
1512
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1513
+ :cardholder_name => "New Holder",
1514
+ :cvv => "456",
1515
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1516
+ :expiration_date => "06/2013",
1517
+ :options => {:verify_card => true, :verification_currency_iso_code => "USD"},
1518
+ )
1519
+ update_result.success?.should == true
1520
+ update_result.payment_method.verification.currency_iso_code == "USD"
1521
+ end
1522
+
1523
+ it "validates verification_currency_iso_code against the given verification_merchant_account_id and updates the credit card " do
1524
+ customer = Braintree::Customer.create!
1525
+ credit_card = Braintree::CreditCard.create!(
1526
+ :cardholder_name => "Original Holder",
1527
+ :customer_id => customer.id,
1528
+ :cvv => "123",
1529
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1530
+ :expiration_date => "05/2012",
1531
+ )
1532
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1533
+ :cardholder_name => "New Holder",
1534
+ :cvv => "456",
1535
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1536
+ :expiration_date => "06/2013",
1537
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "USD"},
1538
+ )
1539
+ update_result.success?.should == true
1540
+ update_result.payment_method.verification.currency_iso_code == "USD"
1541
+ update_result.payment_method.verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
1542
+ end
1543
+
1544
+ it "throws validation error when passing invalid verification_currency_iso_code" do
1545
+ customer = Braintree::Customer.create!
1546
+ credit_card = Braintree::CreditCard.create!(
1547
+ :cardholder_name => "Original Holder",
1548
+ :customer_id => customer.id,
1549
+ :cvv => "123",
1550
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1551
+ :expiration_date => "05/2012",
1552
+ )
1553
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1554
+ :cardholder_name => "New Holder",
1555
+ :cvv => "456",
1556
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1557
+ :expiration_date => "06/2013",
1558
+ :options => {:verify_card => true, :verification_currency_iso_code => "GBP"},
1559
+ )
1560
+ expect(update_result).to_not be_success
1561
+ update_result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1562
+ end
1563
+
1564
+ it "throws validation error when passing invalid verification_currency_iso_code of the given verification merchant account id" do
1565
+ customer = Braintree::Customer.create!
1566
+ credit_card = Braintree::CreditCard.create!(
1567
+ :cardholder_name => "Original Holder",
1568
+ :customer_id => customer.id,
1569
+ :cvv => "123",
1570
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1571
+ :expiration_date => "05/2012",
1572
+ )
1573
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1574
+ :cardholder_name => "New Holder",
1575
+ :cvv => "456",
1576
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1577
+ :expiration_date => "06/2013",
1578
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "GBP"},
1579
+ )
1580
+ expect(update_result).to_not be_success
1581
+ update_result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1582
+ end
1583
+ end
1584
+
1585
+
1305
1586
  context "billing address" do
1306
1587
  it "creates a new billing address by default" do
1307
1588
  customer = Braintree::Customer.create!
@@ -1311,12 +1592,12 @@ describe Braintree::PaymentMethod do
1311
1592
  :expiration_date => "05/2012",
1312
1593
  :billing_address => {
1313
1594
  :street_address => "123 Nigeria Ave"
1314
- }
1595
+ },
1315
1596
  )
1316
1597
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1317
1598
  :billing_address => {
1318
1599
  :region => "IL"
1319
- }
1600
+ },
1320
1601
  )
1321
1602
  update_result.success?.should == true
1322
1603
  updated_credit_card = update_result.payment_method
@@ -1333,13 +1614,13 @@ describe Braintree::PaymentMethod do
1333
1614
  :expiration_date => "05/2012",
1334
1615
  :billing_address => {
1335
1616
  :street_address => "123 Nigeria Ave"
1336
- }
1617
+ },
1337
1618
  )
1338
1619
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1339
1620
  :billing_address => {
1340
1621
  :region => "IL",
1341
1622
  :options => {:update_existing => true}
1342
- }
1623
+ },
1343
1624
  )
1344
1625
  update_result.success?.should == true
1345
1626
  updated_credit_card = update_result.payment_method
@@ -1356,7 +1637,7 @@ describe Braintree::PaymentMethod do
1356
1637
  :expiration_date => "05/2012",
1357
1638
  :billing_address => {
1358
1639
  :street_address => "123 Nigeria Ave"
1359
- }
1640
+ },
1360
1641
  )
1361
1642
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1362
1643
  :billing_address => {
@@ -1365,7 +1646,7 @@ describe Braintree::PaymentMethod do
1365
1646
  :country_code_alpha3 => "ASM",
1366
1647
  :country_code_numeric => "016",
1367
1648
  :options => {:update_existing => true}
1368
- }
1649
+ },
1369
1650
  )
1370
1651
  update_result.success?.should == true
1371
1652
  updated_credit_card = update_result.payment_method
@@ -1381,12 +1662,12 @@ describe Braintree::PaymentMethod do
1381
1662
  credit_card = Braintree::CreditCard.create!(
1382
1663
  :customer_id => customer.id,
1383
1664
  :number => Braintree::Test::CreditCardNumbers::Visa,
1384
- :expiration_date => "05/2012"
1665
+ :expiration_date => "05/2012",
1385
1666
  )
1386
1667
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1387
1668
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1388
1669
  :expiration_month => "07",
1389
- :expiration_year => "2011"
1670
+ :expiration_year => "2011",
1390
1671
  )
1391
1672
  update_result.success?.should == true
1392
1673
  update_result.payment_method.should == credit_card
@@ -1402,14 +1683,14 @@ describe Braintree::PaymentMethod do
1402
1683
  :customer_id => customer.id,
1403
1684
  :cvv => "123",
1404
1685
  :number => Braintree::Test::CreditCardNumbers::Visa,
1405
- :expiration_date => "05/2012"
1686
+ :expiration_date => "05/2012",
1406
1687
  )
1407
1688
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1408
1689
  :cardholder_name => "New Holder",
1409
1690
  :cvv => "456",
1410
1691
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
1411
1692
  :expiration_date => "06/2013",
1412
- :options => {:verify_card => true}
1693
+ :options => {:verify_card => true},
1413
1694
  )
1414
1695
  update_result.success?.should == false
1415
1696
  update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
@@ -1423,11 +1704,11 @@ describe Braintree::PaymentMethod do
1423
1704
  :customer_id => customer.id,
1424
1705
  :cvv => "123",
1425
1706
  :number => Braintree::Test::CreditCardNumbers::Visa,
1426
- :expiration_date => "05/2020"
1707
+ :expiration_date => "05/2020",
1427
1708
  )
1428
1709
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1429
1710
  :payment_method_nonce => Braintree::Test::Nonce::ProcessorDeclinedMasterCard,
1430
- :options => {:verify_card => true, :verification_amount => "2.34"}
1711
+ :options => {:verify_card => true, :verification_amount => "2.34"},
1431
1712
  )
1432
1713
  update_result.success?.should == false
1433
1714
  update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
@@ -1453,7 +1734,7 @@ describe Braintree::PaymentMethod do
1453
1734
  :region => "Old State",
1454
1735
  :postal_code => "12345",
1455
1736
  :country_name => "Canada"
1456
- }
1737
+ },
1457
1738
  )
1458
1739
  result = Braintree::PaymentMethod.update(credit_card.token,
1459
1740
  :options => {:verify_card => false},
@@ -1467,7 +1748,7 @@ describe Braintree::PaymentMethod do
1467
1748
  :region => "New State",
1468
1749
  :postal_code => "56789",
1469
1750
  :country_name => "United States of America"
1470
- }
1751
+ },
1471
1752
  )
1472
1753
  result.success?.should == true
1473
1754
  address = result.payment_method.billing_address
@@ -1488,12 +1769,12 @@ describe Braintree::PaymentMethod do
1488
1769
  :cardholder_name => "Original Holder",
1489
1770
  :customer_id => customer.id,
1490
1771
  :number => Braintree::Test::CreditCardNumbers::Visa,
1491
- :expiration_date => "05/2012"
1772
+ :expiration_date => "05/2012",
1492
1773
  )
1493
1774
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1494
1775
  :cardholder_name => "New Holder",
1495
1776
  :number => "invalid",
1496
- :expiration_date => "05/2014"
1777
+ :expiration_date => "05/2014",
1497
1778
  )
1498
1779
  update_result.success?.should == false
1499
1780
  update_result.errors.for(:credit_card).on(:number)[0].message.should == "Credit card number must be 12-19 digits."
@@ -1504,12 +1785,12 @@ describe Braintree::PaymentMethod do
1504
1785
  card1 = Braintree::CreditCard.create(
1505
1786
  :customer_id => customer.id,
1506
1787
  :number => Braintree::Test::CreditCardNumbers::Visa,
1507
- :expiration_date => "05/2009"
1788
+ :expiration_date => "05/2009",
1508
1789
  ).credit_card
1509
1790
  card2 = Braintree::CreditCard.create(
1510
1791
  :customer_id => customer.id,
1511
1792
  :number => Braintree::Test::CreditCardNumbers::Visa,
1512
- :expiration_date => "05/2009"
1793
+ :expiration_date => "05/2009",
1513
1794
  ).credit_card
1514
1795
 
1515
1796
  card1.should be_default
@@ -1522,39 +1803,23 @@ describe Braintree::PaymentMethod do
1522
1803
  end
1523
1804
  end
1524
1805
 
1525
- context "coinbase accounts" do
1526
- it "cannot create a payment method token with Coinbase" do
1527
- customer = Braintree::Customer.create!
1528
-
1529
- nonce = Braintree::Test::Nonce::Coinbase
1530
- result = Braintree::PaymentMethod.create(
1531
- :payment_method_nonce => nonce,
1532
- :customer_id => customer.id
1533
- )
1534
-
1535
- result.should_not be_success
1536
-
1537
- result.errors.for(:coinbase_account).first.code.should == Braintree::ErrorCodes::PaymentMethod::PaymentMethodNoLongerSupported
1538
- end
1539
- end
1540
-
1541
1806
  context "paypal accounts" do
1542
1807
  it "updates a paypal account's token" do
1543
1808
  customer = Braintree::Customer.create!
1544
1809
  original_token = random_payment_method_token
1545
1810
  nonce = nonce_for_paypal_account(
1546
1811
  :consent_code => "consent-code",
1547
- :token => original_token
1812
+ :token => original_token,
1548
1813
  )
1549
1814
  original_result = Braintree::PaymentMethod.create(
1550
1815
  :payment_method_nonce => nonce,
1551
- :customer_id => customer.id
1816
+ :customer_id => customer.id,
1552
1817
  )
1553
1818
 
1554
1819
  updated_token = make_token
1555
1820
  updated_result = Braintree::PaymentMethod.update(
1556
1821
  original_token,
1557
- :token => updated_token
1822
+ :token => updated_token,
1558
1823
  )
1559
1824
 
1560
1825
  updated_paypal_account = Braintree::PayPalAccount.find(updated_token)
@@ -1571,19 +1836,19 @@ describe Braintree::PaymentMethod do
1571
1836
  :customer_id => customer.id,
1572
1837
  :number => Braintree::Test::CreditCardNumbers::Visa,
1573
1838
  :expiration_date => "05/2009",
1574
- :options => {:make_default => true}
1839
+ :options => {:make_default => true},
1575
1840
  )
1576
1841
  result.should be_success
1577
1842
 
1578
1843
  nonce = nonce_for_paypal_account(:consent_code => "consent-code")
1579
1844
  original_token = Braintree::PaymentMethod.create(
1580
1845
  :payment_method_nonce => nonce,
1581
- :customer_id => customer.id
1846
+ :customer_id => customer.id,
1582
1847
  ).payment_method.token
1583
1848
 
1584
1849
  updated_result = Braintree::PaymentMethod.update(
1585
1850
  original_token,
1586
- :options => {:make_default => true}
1851
+ :options => {:make_default => true},
1587
1852
  )
1588
1853
 
1589
1854
  updated_paypal_account = Braintree::PayPalAccount.find(original_token)
@@ -1597,25 +1862,25 @@ describe Braintree::PaymentMethod do
1597
1862
 
1598
1863
  first_nonce = nonce_for_paypal_account(
1599
1864
  :consent_code => "consent-code",
1600
- :token => first_token
1865
+ :token => first_token,
1601
1866
  )
1602
1867
  first_result = Braintree::PaymentMethod.create(
1603
1868
  :payment_method_nonce => first_nonce,
1604
- :customer_id => customer.id
1869
+ :customer_id => customer.id,
1605
1870
  )
1606
1871
 
1607
1872
  second_nonce = nonce_for_paypal_account(
1608
1873
  :consent_code => "consent-code",
1609
- :token => second_token
1874
+ :token => second_token,
1610
1875
  )
1611
1876
  second_result = Braintree::PaymentMethod.create(
1612
1877
  :payment_method_nonce => second_nonce,
1613
- :customer_id => customer.id
1878
+ :customer_id => customer.id,
1614
1879
  )
1615
1880
 
1616
1881
  updated_result = Braintree::PaymentMethod.update(
1617
1882
  first_token,
1618
- :token => second_token
1883
+ :token => second_token,
1619
1884
  )
1620
1885
 
1621
1886
  updated_result.should_not be_success
@@ -1632,13 +1897,13 @@ describe Braintree::PaymentMethod do
1632
1897
  :customer_id => customer.id,
1633
1898
  :cvv => "123",
1634
1899
  :number => Braintree::Test::CreditCardNumbers::Visa,
1635
- :expiration_date => "05/2012"
1900
+ :expiration_date => "05/2012",
1636
1901
  )
1637
1902
  payment_method = Braintree::PaymentMethod.update!(credit_card.token,
1638
1903
  :cardholder_name => "New Holder",
1639
1904
  :cvv => "456",
1640
1905
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1641
- :expiration_date => "06/2013"
1906
+ :expiration_date => "06/2013",
1642
1907
  )
1643
1908
  payment_method.should == credit_card
1644
1909
  payment_method.cardholder_name.should == "New Holder"
@@ -1655,7 +1920,7 @@ describe Braintree::PaymentMethod do
1655
1920
  :public_key => "oauth_app_partner_user_public_key",
1656
1921
  :private_key => "oauth_app_partner_user_private_key",
1657
1922
  :environment => Braintree::Configuration.environment,
1658
- :logger => Logger.new("/dev/null")
1923
+ :logger => Logger.new("/dev/null"),
1659
1924
  )
1660
1925
  customer = @partner_merchant_gateway.customer.create(
1661
1926
  :first_name => "Joe",
@@ -1664,19 +1929,19 @@ describe Braintree::PaymentMethod do
1664
1929
  :email => "joe@example.com",
1665
1930
  :phone => "312.555.1234",
1666
1931
  :fax => "614.555.5678",
1667
- :website => "www.example.com"
1932
+ :website => "www.example.com",
1668
1933
  ).customer
1669
1934
  @credit_card = @partner_merchant_gateway.credit_card.create(
1670
1935
  :customer_id => customer.id,
1671
1936
  :cardholder_name => "Adam Davis",
1672
1937
  :number => Braintree::Test::CreditCardNumbers::Visa,
1673
- :expiration_date => "05/2009"
1938
+ :expiration_date => "05/2009",
1674
1939
  ).credit_card
1675
1940
 
1676
1941
  @oauth_gateway = Braintree::Gateway.new(
1677
1942
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
1678
1943
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
1679
- :logger => Logger.new("/dev/null")
1944
+ :logger => Logger.new("/dev/null"),
1680
1945
  )
1681
1946
  access_token = Braintree::OAuthTestHelper.create_token(@oauth_gateway, {
1682
1947
  :merchant_public_id => "integration_merchant_id",
@@ -1685,7 +1950,7 @@ describe Braintree::PaymentMethod do
1685
1950
 
1686
1951
  @granting_gateway = Braintree::Gateway.new(
1687
1952
  :access_token => access_token,
1688
- :logger => Logger.new("/dev/null")
1953
+ :logger => Logger.new("/dev/null"),
1689
1954
  )
1690
1955
  end
1691
1956
 
@@ -1701,13 +1966,13 @@ describe Braintree::PaymentMethod do
1701
1966
 
1702
1967
  result = Braintree::Transaction.sale(
1703
1968
  :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1704
- :amount => Braintree::Test::TransactionAmounts::Authorize
1969
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
1705
1970
  )
1706
1971
  result.should be_success
1707
1972
 
1708
1973
  result2 = Braintree::Transaction.sale(
1709
1974
  :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1710
- :amount => Braintree::Test::TransactionAmounts::Authorize
1975
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
1711
1976
  )
1712
1977
  result2.should_not be_success
1713
1978
  end
@@ -1719,7 +1984,7 @@ describe Braintree::PaymentMethod do
1719
1984
 
1720
1985
  result = Braintree::PaymentMethod.create(
1721
1986
  :customer_id => customer_result.customer.id,
1722
- :payment_method_nonce => grant_result.payment_method_nonce.nonce
1987
+ :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1723
1988
  )
1724
1989
  result.should_not be_success
1725
1990
  end
@@ -1731,7 +1996,7 @@ describe Braintree::PaymentMethod do
1731
1996
 
1732
1997
  result = Braintree::PaymentMethod.create(
1733
1998
  :customer_id => customer_result.customer.id,
1734
- :payment_method_nonce => grant_result.payment_method_nonce.nonce
1999
+ :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1735
2000
  )
1736
2001
  result.should be_success
1737
2002
  end
@@ -1739,7 +2004,7 @@ describe Braintree::PaymentMethod do
1739
2004
  it "raises an error if the token isn't found" do
1740
2005
  expect do
1741
2006
  @granting_gateway.payment_method.grant("not_a_real_token", false)
1742
- end.to raise_error
2007
+ end.to raise_error(Braintree::NotFoundError)
1743
2008
  end
1744
2009
 
1745
2010
  it "returns a valid nonce with no options set" do
@@ -1754,7 +2019,7 @@ describe Braintree::PaymentMethod do
1754
2019
  it "raises an error if the token isn't found" do
1755
2020
  expect do
1756
2021
  @granting_gateway.payment_method.revoke("not_a_real_token")
1757
- end.to raise_error
2022
+ end.to raise_error(Braintree::NotFoundError)
1758
2023
  end
1759
2024
 
1760
2025
  it "renders a granted nonce useless" do
@@ -1766,7 +2031,7 @@ describe Braintree::PaymentMethod do
1766
2031
 
1767
2032
  result = Braintree::PaymentMethod.create(
1768
2033
  :customer_id => customer_result.customer.id,
1769
- :payment_method_nonce => grant_result.payment_method_nonce.nonce
2034
+ :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1770
2035
  )
1771
2036
  result.should_not be_success
1772
2037
  end
@@ -1780,7 +2045,7 @@ describe Braintree::PaymentMethod do
1780
2045
 
1781
2046
  result = Braintree::PaymentMethod.create(
1782
2047
  :customer_id => customer_result.customer.id,
1783
- :payment_method_nonce => grant_result.payment_method_nonce.nonce
2048
+ :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1784
2049
  )
1785
2050
  result.should_not be_success
1786
2051
  end