braintree 2.74.0 → 4.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (286) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +13 -7
  4. data/lib/braintree/account_updater_daily_report.rb +2 -2
  5. data/lib/braintree/ach_mandate.rb +2 -1
  6. data/lib/braintree/address/country_names.rb +4 -1
  7. data/lib/braintree/address.rb +30 -38
  8. data/lib/braintree/address_gateway.rb +12 -2
  9. data/lib/braintree/advanced_search.rb +8 -0
  10. data/lib/braintree/apple_pay.rb +29 -0
  11. data/lib/braintree/apple_pay_card.rb +28 -4
  12. data/lib/braintree/apple_pay_gateway.rb +37 -0
  13. data/lib/braintree/apple_pay_options.rb +19 -0
  14. data/lib/braintree/authorization_adjustment.rb +23 -0
  15. data/lib/braintree/base_module.rb +10 -0
  16. data/lib/braintree/bin_data.rb +33 -0
  17. data/lib/braintree/client_token.rb +3 -3
  18. data/lib/braintree/client_token_gateway.rb +3 -1
  19. data/lib/braintree/configuration.rb +57 -10
  20. data/lib/braintree/connected_merchant_paypal_status_changed.rb +6 -2
  21. data/lib/braintree/connected_merchant_status_transitioned.rb +6 -2
  22. data/lib/braintree/credentials_parser.rb +5 -1
  23. data/lib/braintree/credit_card.rb +53 -107
  24. data/lib/braintree/credit_card_gateway.rb +43 -30
  25. data/lib/braintree/credit_card_verification.rb +61 -21
  26. data/lib/braintree/credit_card_verification_gateway.rb +19 -6
  27. data/lib/braintree/credit_card_verification_search.rb +1 -1
  28. data/lib/braintree/customer.rb +51 -98
  29. data/lib/braintree/customer_gateway.rb +30 -23
  30. data/lib/braintree/customer_search.rb +1 -1
  31. data/lib/braintree/descriptor.rb +3 -1
  32. data/lib/braintree/disbursement.rb +24 -2
  33. data/lib/braintree/dispute/evidence.rb +24 -0
  34. data/lib/braintree/{transaction/coinbase_details.rb → dispute/paypal_message.rb} +5 -3
  35. data/lib/braintree/dispute/status_history.rb +18 -0
  36. data/lib/braintree/dispute/transaction.rb +20 -0
  37. data/lib/braintree/dispute/transaction_details.rb +2 -1
  38. data/lib/braintree/dispute.rb +114 -10
  39. data/lib/braintree/dispute_gateway.rb +142 -0
  40. data/lib/braintree/dispute_search.rb +31 -0
  41. data/lib/braintree/document_upload.rb +37 -0
  42. data/lib/braintree/document_upload_gateway.rb +38 -0
  43. data/lib/braintree/enriched_customer_data.rb +21 -0
  44. data/lib/braintree/error_codes.rb +328 -109
  45. data/lib/braintree/error_result.rb +8 -1
  46. data/lib/braintree/exceptions.rb +5 -3
  47. data/lib/braintree/exchange_rate.rb +13 -0
  48. data/lib/braintree/exchange_rate_quote.rb +24 -0
  49. data/lib/braintree/exchange_rate_quote_gateway.rb +35 -0
  50. data/lib/braintree/exchange_rate_quote_input.rb +21 -0
  51. data/lib/braintree/exchange_rate_quote_request.rb +18 -0
  52. data/lib/braintree/exchange_rate_quote_response.rb +18 -0
  53. data/lib/braintree/facilitated_details.rb +21 -0
  54. data/lib/braintree/facilitator_details.rb +2 -1
  55. data/lib/braintree/gateway.rb +29 -11
  56. data/lib/braintree/google_pay_card.rb +61 -0
  57. data/lib/braintree/granted_payment_instrument_update.rb +23 -0
  58. data/lib/braintree/graphql_client.rb +34 -0
  59. data/lib/braintree/http.rb +81 -20
  60. data/lib/braintree/local_payment_completed.rb +23 -0
  61. data/lib/braintree/local_payment_expired.rb +21 -0
  62. data/lib/braintree/local_payment_funded.rb +22 -0
  63. data/lib/braintree/local_payment_reversed.rb +19 -0
  64. data/lib/braintree/merchant.rb +11 -4
  65. data/lib/braintree/merchant_account/address_details.rb +4 -1
  66. data/lib/braintree/merchant_account/business_details.rb +4 -1
  67. data/lib/braintree/merchant_account/funding_details.rb +6 -1
  68. data/lib/braintree/merchant_account/individual_details.rb +7 -2
  69. data/lib/braintree/merchant_account.rb +23 -10
  70. data/lib/braintree/merchant_account_gateway.rb +13 -1
  71. data/lib/braintree/merchant_gateway.rb +2 -2
  72. data/lib/braintree/modification.rb +1 -1
  73. data/lib/braintree/oauth_credentials.rb +5 -2
  74. data/lib/braintree/oauth_gateway.rb +8 -14
  75. data/lib/braintree/paginated_result.rb +3 -1
  76. data/lib/braintree/payment_instrument_type.rb +11 -11
  77. data/lib/braintree/payment_method.rb +20 -12
  78. data/lib/braintree/payment_method_customer_data_updated_metadata.rb +24 -0
  79. data/lib/braintree/payment_method_gateway.rb +82 -54
  80. data/lib/braintree/payment_method_nonce.rb +22 -8
  81. data/lib/braintree/payment_method_nonce_details.rb +40 -0
  82. data/lib/braintree/payment_method_nonce_details_payer_info.rb +32 -0
  83. data/lib/braintree/payment_method_nonce_gateway.rb +19 -2
  84. data/lib/braintree/payment_method_parser.rb +28 -0
  85. data/lib/braintree/paypal_account.rb +10 -1
  86. data/lib/braintree/plan.rb +25 -5
  87. data/lib/braintree/plan_gateway.rb +100 -0
  88. data/lib/braintree/processor_response_types.rb +7 -0
  89. data/lib/braintree/resource_collection.rb +8 -3
  90. data/lib/braintree/revoked_payment_method_metadata.rb +22 -0
  91. data/lib/braintree/risk_data/liability_shift.rb +22 -0
  92. data/lib/braintree/risk_data.rb +12 -2
  93. data/lib/braintree/samsung_pay_card.rb +83 -0
  94. data/lib/braintree/sepa_direct_debit_account.rb +60 -0
  95. data/lib/braintree/sepa_direct_debit_account_gateway.rb +25 -0
  96. data/lib/braintree/sepa_direct_debit_account_nonce_details.rb +28 -0
  97. data/lib/braintree/settlement_batch_summary.rb +2 -1
  98. data/lib/braintree/settlement_batch_summary_gateway.rb +2 -0
  99. data/lib/braintree/subscription/status_details.rb +8 -1
  100. data/lib/braintree/subscription.rb +56 -41
  101. data/lib/braintree/subscription_gateway.rb +25 -2
  102. data/lib/braintree/successful_result.rb +23 -1
  103. data/lib/braintree/test/authentication_id.rb +21 -0
  104. data/lib/braintree/test/credit_card.rb +13 -0
  105. data/lib/braintree/test/nonce.rb +28 -20
  106. data/lib/braintree/test/transaction_amounts.rb +1 -0
  107. data/lib/braintree/three_d_secure_info.rb +34 -2
  108. data/lib/braintree/transaction/address_details.rb +24 -4
  109. data/lib/braintree/transaction/apple_pay_details.rb +20 -2
  110. data/lib/braintree/transaction/credit_card_details.rb +45 -6
  111. data/lib/braintree/transaction/customer_details.rb +8 -1
  112. data/lib/braintree/transaction/disbursement_details.rb +6 -1
  113. data/lib/braintree/transaction/google_pay_details.rb +41 -0
  114. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  115. data/lib/braintree/transaction/installment.rb +28 -0
  116. data/lib/braintree/transaction/local_payment_details.rb +24 -0
  117. data/lib/braintree/transaction/paypal_details.rb +26 -4
  118. data/lib/braintree/transaction/paypal_here_details.rb +23 -0
  119. data/lib/braintree/transaction/{masterpass_card_details.rb → samsung_pay_card_details.rb} +21 -6
  120. data/lib/braintree/transaction/sepa_direct_debit_account_details.rb +27 -0
  121. data/lib/braintree/transaction/status_details.rb +5 -1
  122. data/lib/braintree/transaction/subscription_details.rb +4 -1
  123. data/lib/braintree/transaction/us_bank_account_details.rb +8 -1
  124. data/lib/braintree/transaction/venmo_account_details.rb +5 -1
  125. data/lib/braintree/transaction/visa_checkout_card_details.rb +19 -4
  126. data/lib/braintree/transaction.rb +201 -188
  127. data/lib/braintree/transaction_gateway.rb +124 -30
  128. data/lib/braintree/transaction_line_item.rb +40 -0
  129. data/lib/braintree/transaction_line_item_gateway.rb +19 -0
  130. data/lib/braintree/transaction_review.rb +18 -0
  131. data/lib/braintree/transaction_search.rb +6 -3
  132. data/lib/braintree/unknown_payment_method.rb +3 -2
  133. data/lib/braintree/us_bank_account.rb +24 -8
  134. data/lib/braintree/us_bank_account_gateway.rb +0 -1
  135. data/lib/braintree/us_bank_account_verification.rb +81 -0
  136. data/lib/braintree/us_bank_account_verification_gateway.rb +51 -0
  137. data/lib/braintree/us_bank_account_verification_search.rb +19 -0
  138. data/lib/braintree/util.rb +79 -9
  139. data/lib/braintree/validation_error.rb +13 -3
  140. data/lib/braintree/validation_error_collection.rb +2 -1
  141. data/lib/braintree/venmo_account.rb +11 -4
  142. data/lib/braintree/venmo_profile_data.rb +23 -0
  143. data/lib/braintree/version.rb +2 -2
  144. data/lib/braintree/visa_checkout_card.rb +29 -13
  145. data/lib/braintree/webhook_notification.rb +66 -26
  146. data/lib/braintree/webhook_notification_gateway.rb +5 -3
  147. data/lib/braintree/webhook_testing.rb +2 -2
  148. data/lib/braintree/webhook_testing_gateway.rb +721 -55
  149. data/lib/braintree/xml/generator.rb +6 -4
  150. data/lib/braintree/xml/parser.rb +22 -35
  151. data/lib/braintree/xml/rexml.rb +4 -5
  152. data/lib/braintree.rb +60 -22
  153. data/lib/ssl/api_braintreegateway_com.ca.crt +50 -0
  154. data/spec/fixtures/files/bt_logo.png +0 -0
  155. data/spec/fixtures/files/gif_extension_bt_logo.gif +0 -0
  156. data/spec/fixtures/files/malformed_pdf.pdf +1 -0
  157. data/spec/fixtures/files/too_long.pdf +0 -0
  158. data/spec/integration/braintree/add_on_spec.rb +3 -3
  159. data/spec/integration/braintree/address_spec.rb +30 -113
  160. data/spec/integration/braintree/advanced_search_spec.rb +45 -45
  161. data/spec/integration/braintree/apple_pay_spec.rb +63 -0
  162. data/spec/integration/braintree/braintree_gateway_spec.rb +72 -0
  163. data/spec/integration/braintree/client_api/client_token_spec.rb +14 -32
  164. data/spec/integration/braintree/client_api/spec_helper.rb +104 -65
  165. data/spec/integration/braintree/credit_card_spec.rb +460 -615
  166. data/spec/integration/braintree/credit_card_verification_search_spec.rb +2 -2
  167. data/spec/integration/braintree/credit_card_verification_spec.rb +222 -6
  168. data/spec/integration/braintree/customer_search_spec.rb +8 -8
  169. data/spec/integration/braintree/customer_spec.rb +810 -498
  170. data/spec/integration/braintree/discount_spec.rb +1 -1
  171. data/spec/integration/braintree/dispute_search_spec.rb +167 -0
  172. data/spec/integration/braintree/dispute_spec.rb +333 -0
  173. data/spec/integration/braintree/document_upload_spec.rb +87 -0
  174. data/spec/integration/braintree/error_codes_spec.rb +1 -1
  175. data/spec/integration/braintree/exchange_rate_quote_spec.rb +97 -0
  176. data/spec/integration/braintree/graphql_client_spec.rb +72 -0
  177. data/spec/integration/braintree/http_spec.rb +12 -4
  178. data/spec/integration/braintree/merchant_account_spec.rb +74 -26
  179. data/spec/integration/braintree/merchant_spec.rb +39 -13
  180. data/spec/integration/braintree/oauth_spec.rb +18 -25
  181. data/spec/integration/braintree/payment_method_nonce_spec.rb +239 -5
  182. data/spec/integration/braintree/payment_method_spec.rb +882 -300
  183. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +416 -0
  184. data/spec/integration/braintree/paypal_account_spec.rb +32 -31
  185. data/spec/integration/braintree/plan_spec.rb +82 -0
  186. data/spec/integration/braintree/samsung_pay_card_spec.rb +144 -0
  187. data/spec/integration/braintree/sepa_direct_debit_account_spec.rb +196 -0
  188. data/spec/integration/braintree/settlement_batch_summary_spec.rb +8 -8
  189. data/spec/integration/braintree/subscription_spec.rb +274 -180
  190. data/spec/integration/braintree/test/transaction_amounts_spec.rb +2 -2
  191. data/spec/integration/braintree/test_transaction_spec.rb +18 -18
  192. data/spec/integration/braintree/transaction_line_item_spec.rb +38 -0
  193. data/spec/integration/braintree/transaction_search_spec.rb +280 -152
  194. data/spec/integration/braintree/transaction_spec.rb +3709 -1175
  195. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +438 -0
  196. data/spec/integration/braintree/us_bank_account_spec.rb +38 -17
  197. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +178 -0
  198. data/spec/integration/braintree/us_bank_account_verification_spec.rb +240 -0
  199. data/spec/integration/braintree/visa_checkout_card_spec.rb +5 -5
  200. data/spec/integration/spec_helper.rb +27 -6
  201. data/spec/oauth_test_helper.rb +1 -1
  202. data/spec/script/httpsd.rb +6 -6
  203. data/spec/spec_helper.rb +26 -23
  204. data/spec/unit/braintree/address_spec.rb +1 -9
  205. data/spec/unit/braintree/apple_pay_card_spec.rb +104 -4
  206. data/spec/unit/braintree/client_token_spec.rb +2 -2
  207. data/spec/unit/braintree/configuration_spec.rb +108 -33
  208. data/spec/unit/braintree/credit_card_spec.rb +62 -33
  209. data/spec/unit/braintree/credit_card_verification_gateway_spec.rb +51 -0
  210. data/spec/unit/braintree/credit_card_verification_search_spec.rb +1 -1
  211. data/spec/unit/braintree/credit_card_verification_spec.rb +39 -6
  212. data/spec/unit/braintree/customer_spec.rb +107 -27
  213. data/spec/unit/braintree/disbursement_spec.rb +59 -7
  214. data/spec/unit/braintree/dispute_search_spec.rb +66 -0
  215. data/spec/unit/braintree/dispute_spec.rb +472 -8
  216. data/spec/unit/braintree/document_upload_spec.rb +35 -0
  217. data/spec/unit/braintree/enriched_customer_data_spec.rb +32 -0
  218. data/spec/unit/braintree/error_result_spec.rb +5 -5
  219. data/spec/unit/braintree/errors_spec.rb +8 -8
  220. data/spec/unit/braintree/exchange_rate_quote_input_spec.rb +42 -0
  221. data/spec/unit/braintree/exchange_rate_quote_request_spec.rb +82 -0
  222. data/spec/unit/braintree/exchange_rate_quote_response_spec.rb +52 -0
  223. data/spec/unit/braintree/exchange_rate_quote_spec.rb +42 -0
  224. data/spec/unit/braintree/exchange_rate_spec.rb +23 -0
  225. data/spec/unit/braintree/http_spec.rb +93 -5
  226. data/spec/unit/braintree/local_payment_completed_spec.rb +50 -0
  227. data/spec/unit/braintree/local_payment_expired_spec.rb +24 -0
  228. data/spec/unit/braintree/local_payment_funded_spec.rb +34 -0
  229. data/spec/unit/braintree/merchant_account_spec.rb +1 -1
  230. data/spec/unit/braintree/modification_spec.rb +1 -1
  231. data/spec/unit/braintree/payment_method_customer_data_updated_metadata_spec.rb +45 -0
  232. data/spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb +31 -0
  233. data/spec/unit/braintree/payment_method_nonce_details_spec.rb +51 -0
  234. data/spec/unit/braintree/payment_method_nonce_spec.rb +40 -0
  235. data/spec/unit/braintree/payment_method_spec.rb +1 -1
  236. data/spec/unit/braintree/paypal_account_spec.rb +2 -2
  237. data/spec/unit/braintree/resource_collection_spec.rb +30 -1
  238. data/spec/unit/braintree/risk_data/liability_shift.rb +26 -0
  239. data/spec/unit/braintree/risk_data_spec.rb +40 -6
  240. data/spec/unit/braintree/sepa_debit_account_nonce_details_spec.rb +29 -0
  241. data/spec/unit/braintree/sepa_debit_account_spec.rb +86 -0
  242. data/spec/unit/braintree/subscription_search_spec.rb +1 -1
  243. data/spec/unit/braintree/subscription_spec.rb +2 -2
  244. data/spec/unit/braintree/successful_result_spec.rb +1 -1
  245. data/spec/unit/braintree/three_d_secure_info_spec.rb +34 -6
  246. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +19 -3
  247. data/spec/unit/braintree/transaction/customer_details_spec.rb +1 -1
  248. data/spec/unit/braintree/transaction/deposit_details_spec.rb +2 -2
  249. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  250. data/spec/unit/braintree/transaction/paypal_details_spec.rb +63 -0
  251. data/spec/unit/braintree/transaction/sepa_direct_debit_account_details_spec.rb +33 -0
  252. data/spec/unit/braintree/transaction_gateway_spec.rb +111 -0
  253. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  254. data/spec/unit/braintree/transaction_spec.rb +171 -55
  255. data/spec/unit/braintree/us_bank_account_verification_search_spec.rb +60 -0
  256. data/spec/unit/braintree/us_bank_account_verification_spec.rb +93 -0
  257. data/spec/unit/braintree/util_spec.rb +162 -19
  258. data/spec/unit/braintree/validation_error_collection_spec.rb +336 -133
  259. data/spec/unit/braintree/venmo_profile_data_spec.rb +32 -0
  260. data/spec/unit/braintree/webhook_notification_spec.rb +546 -114
  261. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  262. data/spec/unit/braintree/xml_spec.rb +31 -24
  263. data/spec/unit/braintree_spec.rb +1 -0
  264. metadata +290 -198
  265. data/README.rdoc +0 -93
  266. data/lib/braintree/amex_express_checkout_card.rb +0 -26
  267. data/lib/braintree/android_pay_card.rb +0 -35
  268. data/lib/braintree/coinbase_account.rb +0 -25
  269. data/lib/braintree/europe_bank_account.rb +0 -34
  270. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  271. data/lib/braintree/ideal_payment.rb +0 -46
  272. data/lib/braintree/ideal_payment_gateway.rb +0 -18
  273. data/lib/braintree/masterpass_card.rb +0 -66
  274. data/lib/braintree/settlement_batch.rb +0 -0
  275. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -14
  276. data/lib/braintree/transaction/android_pay_details.rb +0 -17
  277. data/lib/braintree/transaction/ideal_payment_details.rb +0 -13
  278. data/lib/braintree/transparent_redirect.rb +0 -40
  279. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  280. data/spec/hacks/tcp_socket.rb +0 -18
  281. data/spec/httpsd.pid +0 -1
  282. data/spec/integration/braintree/coinbase_spec.rb +0 -31
  283. data/spec/integration/braintree/ideal_payment_spec.rb +0 -87
  284. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  285. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  286. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
@@ -8,7 +8,7 @@ describe Braintree::Customer do
8
8
  customers = Braintree::Customer.all
9
9
  customers.maximum_size.should > 100
10
10
 
11
- customer_ids = customers.map {|c| c.id }.uniq.compact
11
+ customer_ids = customers.map { |c| c.id }.uniq.compact
12
12
  customer_ids.size.should == customers.maximum_size
13
13
  end
14
14
  end
@@ -17,7 +17,7 @@ describe Braintree::Customer do
17
17
  it "deletes the customer with the given id" do
18
18
  create_result = Braintree::Customer.create(
19
19
  :first_name => "Joe",
20
- :last_name => "Cool"
20
+ :last_name => "Cool",
21
21
  )
22
22
  create_result.success?.should == true
23
23
  customer = create_result.customer
@@ -39,7 +39,8 @@ describe Braintree::Customer do
39
39
  :email => "bill@microsoft.com",
40
40
  :phone => "312.555.1234",
41
41
  :fax => "614.555.5678",
42
- :website => "www.microsoft.com"
42
+ :website => "www.microsoft.com",
43
+ :tax_identifiers => [{:country_code => "US", :identifier => "987654321"}],
43
44
  )
44
45
  result.success?.should == true
45
46
  result.customer.id.should =~ /^\d{6,}$/
@@ -58,7 +59,7 @@ describe Braintree::Customer do
58
59
  oauth_gateway = Braintree::Gateway.new(
59
60
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
60
61
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
61
- :logger => Logger.new("/dev/null")
62
+ :logger => Logger.new("/dev/null"),
62
63
  )
63
64
  access_token = Braintree::OAuthTestHelper.create_token(oauth_gateway, {
64
65
  :merchant_public_id => "integration_merchant_id",
@@ -67,7 +68,7 @@ describe Braintree::Customer do
67
68
 
68
69
  gateway = Braintree::Gateway.new(
69
70
  :access_token => access_token,
70
- :logger => Logger.new("/dev/null")
71
+ :logger => Logger.new("/dev/null"),
71
72
  )
72
73
 
73
74
  result = gateway.customer.create(
@@ -77,7 +78,7 @@ describe Braintree::Customer do
77
78
  :email => "joe@example.com",
78
79
  :phone => "312.555.1234",
79
80
  :fax => "614.555.5678",
80
- :website => "www.example.com"
81
+ :website => "www.example.com",
81
82
  )
82
83
  result.success?.should == true
83
84
  result.customer.id.should =~ /^\d{6,}$/
@@ -85,15 +86,14 @@ describe Braintree::Customer do
85
86
  result.customer.last_name.should == "Brown"
86
87
  end
87
88
 
88
- it "supports creation with a device session ID and (optional) fraud_merchant_id" do
89
+ it "supports creation with device_data" do
89
90
  result = Braintree::Customer.create(
90
91
  :credit_card => {
91
92
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
92
93
  :expiration_date => "05/2010",
93
94
  :cvv => "100",
94
- :device_session_id => "abc123",
95
- :fraud_merchant_id => "7"
96
- }
95
+ :device_data => "device_data",
96
+ },
97
97
  )
98
98
 
99
99
  result.should be_success
@@ -109,7 +109,58 @@ describe Braintree::Customer do
109
109
  :risk_data => {
110
110
  :customer_browser => "IE5",
111
111
  :customer_ip => "192.168.0.1"
112
- }
112
+ },
113
+ )
114
+
115
+ result.should be_success
116
+ end
117
+
118
+ it "includes risk data when skip_advanced_fraud_checking is false" do
119
+ with_fraud_protection_enterprise_merchant do
120
+ result = Braintree::Customer.create(
121
+ :credit_card => {
122
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
123
+ :expiration_date => "05/2010",
124
+ :cvv => "100",
125
+ :options => {
126
+ :skip_advanced_fraud_checking => false,
127
+ :verify_card => true,
128
+ },
129
+ },
130
+ )
131
+
132
+ expect(result).to be_success
133
+ verification = result.customer.credit_cards.first.verification
134
+ expect(verification.risk_data).not_to be_nil
135
+ end
136
+ end
137
+
138
+ it "does not include risk data when skip_advanced_fraud_checking is true" do
139
+ with_fraud_protection_enterprise_merchant do
140
+ result = Braintree::Customer.create(
141
+ :credit_card => {
142
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
143
+ :expiration_date => "05/2010",
144
+ :cvv => "100",
145
+ :options => {
146
+ :skip_advanced_fraud_checking => true,
147
+ :verify_card => true,
148
+ },
149
+ },
150
+ )
151
+
152
+ expect(result).to be_success
153
+ verification = result.customer.credit_cards.first.verification
154
+ expect(verification.risk_data).to be_nil
155
+ end
156
+ end
157
+
158
+ it "supports creation with tax_identifiers" do
159
+ result = Braintree::Customer.create(
160
+ :tax_identifiers => [
161
+ {:country_code => "US", :identifier => "987654321"},
162
+ {:country_code => "CL", :identifier => "123456789"}
163
+ ],
113
164
  )
114
165
 
115
166
  result.should be_success
@@ -135,21 +186,21 @@ describe Braintree::Customer do
135
186
  found_customer.last_name.should == last_name
136
187
  else
137
188
  result.customer.first_name.should == "José"
138
- result.customer.first_name.bytes.map {|b| b.to_s(8)}.should == ["112", "157", "163", "303", "251"]
189
+ result.customer.first_name.bytes.map { |b| b.to_s(8) }.should == ["112", "157", "163", "303", "251"]
139
190
  result.customer.last_name.should == "Muñoz"
140
- result.customer.last_name.bytes.map {|b| b.to_s(8)}.should == ["115", "165", "303", "261", "157", "172"]
191
+ result.customer.last_name.bytes.map { |b| b.to_s(8) }.should == ["115", "165", "303", "261", "157", "172"]
141
192
 
142
193
  found_customer = Braintree::Customer.find(result.customer.id)
143
194
  found_customer.first_name.should == "José"
144
- found_customer.first_name.bytes.map {|b| b.to_s(8)}.should == ["112", "157", "163", "303", "251"]
195
+ found_customer.first_name.bytes.map { |b| b.to_s(8) }.should == ["112", "157", "163", "303", "251"]
145
196
  found_customer.last_name.should == "Muñoz"
146
- found_customer.last_name.bytes.map {|b| b.to_s(8)}.should == ["115", "165", "303", "261", "157", "172"]
197
+ found_customer.last_name.bytes.map { |b| b.to_s(8) }.should == ["115", "165", "303", "261", "157", "172"]
147
198
  end
148
199
  end
149
200
 
150
201
  it "returns an error response if invalid" do
151
202
  result = Braintree::Customer.create(
152
- :email => "@invalid.com"
203
+ :email => "@invalid.com",
153
204
  )
154
205
  result.success?.should == false
155
206
  result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
@@ -163,7 +214,7 @@ describe Braintree::Customer do
163
214
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
164
215
  :expiration_date => "05/2010",
165
216
  :cvv => "100"
166
- }
217
+ },
167
218
  )
168
219
 
169
220
  result.success?.should == true
@@ -183,7 +234,7 @@ describe Braintree::Customer do
183
234
  :email => "other@example.com",
184
235
  :billing_agreement_id => "B-123456",
185
236
  :options => {:make_default => true}
186
- }
237
+ },
187
238
  )
188
239
 
189
240
  result.success?.should == true
@@ -201,7 +252,7 @@ describe Braintree::Customer do
201
252
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
202
253
  :expiration_date => "05/2010",
203
254
  :options => {:verify_card => true}
204
- }
255
+ },
205
256
  )
206
257
  result.success?.should == false
207
258
  result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
@@ -215,7 +266,7 @@ describe Braintree::Customer do
215
266
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
216
267
  :expiration_date => "05/2019",
217
268
  :options => {:verify_card => true, :verification_amount => "2.00"}
218
- }
269
+ },
219
270
  )
220
271
  result.success?.should == true
221
272
  end
@@ -225,7 +276,7 @@ describe Braintree::Customer do
225
276
  Braintree::CreditCard.create(
226
277
  :customer_id => customer.id,
227
278
  :number => Braintree::Test::CreditCardNumbers::Visa,
228
- :expiration_date => "05/2015"
279
+ :expiration_date => "05/2015",
229
280
  )
230
281
 
231
282
  result = Braintree::Customer.create(
@@ -235,7 +286,7 @@ describe Braintree::Customer do
235
286
  :number => Braintree::Test::CreditCardNumbers::Visa,
236
287
  :expiration_date => "05/2015",
237
288
  :options => {:fail_on_duplicate_payment_method => true}
238
- }
289
+ },
239
290
  )
240
291
  result.success?.should == false
241
292
  result.errors.for(:customer).for(:credit_card).on(:number)[0].message.should == "Duplicate card exists in the vault."
@@ -252,12 +303,98 @@ describe Braintree::Customer do
252
303
  :verify_card => true,
253
304
  :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
254
305
  }
255
- }
306
+ },
256
307
  )
257
308
  result.success?.should == false
258
309
  result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
259
310
  end
260
311
 
312
+ it "can create a customer and a payment method at the same time after validating verification_currency_iso_code" do
313
+ result = Braintree::Customer.create(
314
+ :first_name => "Mike",
315
+ :last_name => "Jones",
316
+ :credit_card => {
317
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
318
+ :expiration_date => "05/2010",
319
+ :cvv => "100",
320
+ :options => {
321
+ :verify_card => true,
322
+ :verification_currency_iso_code => "USD"
323
+ }
324
+ },
325
+ )
326
+
327
+ result.success?.should == true
328
+ result.customer.first_name.should == "Mike"
329
+ result.customer.last_name.should == "Jones"
330
+ result.customer.credit_cards[0].bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
331
+ result.customer.credit_cards[0].last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
332
+ result.customer.credit_cards[0].expiration_date.should == "05/2010"
333
+ result.customer.credit_cards[0].unique_number_identifier.should =~ /\A\w{32}\z/
334
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
335
+ end
336
+
337
+ it "errors when verification_currency_iso_code is not supported by merchant account" do
338
+ result = Braintree::Customer.create(
339
+ :first_name => "Mike",
340
+ :last_name => "Jones",
341
+ :credit_card => {
342
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
343
+ :expiration_date => "05/2010",
344
+ :cvv => "100",
345
+ :options => {
346
+ :verify_card => true,
347
+ :verification_currency_iso_code => "GBP"
348
+ }
349
+ },
350
+ )
351
+ expect(result).to_not be_success
352
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
353
+ end
354
+
355
+ it "validates verification_currency_iso_code of the given verification_merchant_account_id and creates customer" do
356
+ result = Braintree::Customer.create(
357
+ :first_name => "Mike",
358
+ :last_name => "Jones",
359
+ :credit_card => {
360
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
361
+ :expiration_date => "05/2010",
362
+ :options => {
363
+ :verify_card => true,
364
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
365
+ :verification_currency_iso_code => "USD"
366
+ }
367
+ },
368
+ )
369
+ result.success?.should == true
370
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
371
+ result.customer.first_name.should == "Mike"
372
+ result.customer.last_name.should == "Jones"
373
+ result.customer.credit_cards[0].bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
374
+ result.customer.credit_cards[0].last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
375
+ result.customer.credit_cards[0].expiration_date.should == "05/2010"
376
+ result.customer.credit_cards[0].unique_number_identifier.should =~ /\A\w{32}\z/
377
+ end
378
+
379
+ it "validates verification_currency_iso_code of the given verification_merchant_account_id and returns error" do
380
+ result = Braintree::Customer.create(
381
+ :first_name => "Mike",
382
+ :last_name => "Jones",
383
+ :credit_card => {
384
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
385
+ :expiration_date => "05/2010",
386
+ :options => {
387
+ :verify_card => true,
388
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
389
+ :verification_currency_iso_code => "GBP"
390
+ }
391
+ },
392
+ )
393
+ expect(result).to_not be_success
394
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
395
+ end
396
+
397
+
261
398
  it "can create a customer, payment method, and billing address at the same time" do
262
399
  result = Braintree::Customer.create(
263
400
  :first_name => "Mike",
@@ -273,7 +410,7 @@ describe Braintree::Customer do
273
410
  :postal_code => "60622",
274
411
  :country_name => "United States of America"
275
412
  }
276
- }
413
+ },
277
414
  )
278
415
  result.success?.should == true
279
416
  result.customer.first_name.should == "Mike"
@@ -304,7 +441,7 @@ describe Braintree::Customer do
304
441
  :country_code_alpha3 => "COM",
305
442
  :country_code_numeric => "174"
306
443
  }
307
- }
444
+ },
308
445
  )
309
446
  result.success?.should == true
310
447
  result.customer.addresses[0].country_name.should == "Comoros"
@@ -319,7 +456,7 @@ describe Braintree::Customer do
319
456
  :last_name => "Gates",
320
457
  :custom_fields => {
321
458
  :store_me => "custom value"
322
- }
459
+ },
323
460
  )
324
461
  result.success?.should == true
325
462
  result.customer.custom_fields[:store_me].should == "custom value"
@@ -329,7 +466,7 @@ describe Braintree::Customer do
329
466
  result = Braintree::Customer.create(
330
467
  :first_name => "Bill",
331
468
  :last_name => "Gates",
332
- :custom_fields => { :store_me => "" }
469
+ :custom_fields => {:store_me => ""},
333
470
  )
334
471
  result.success?.should == true
335
472
  result.customer.custom_fields.should == {}
@@ -343,7 +480,7 @@ describe Braintree::Customer do
343
480
  :billing_address => {
344
481
  :country_name => "invalid"
345
482
  }
346
- }
483
+ },
347
484
  )
348
485
  result.success?.should == false
349
486
  result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
@@ -363,10 +500,10 @@ describe Braintree::Customer do
363
500
  :country_code_alpha2 => "US",
364
501
  :country_code_alpha3 => "COM",
365
502
  }
366
- }
503
+ },
367
504
  )
368
505
  result.success?.should == false
369
- result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:base).map {|e| e.code}.should include(Braintree::ErrorCodes::Address::InconsistentCountry)
506
+ result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:base).map { |e| e.code }.should include(Braintree::ErrorCodes::Address::InconsistentCountry)
370
507
  end
371
508
 
372
509
  it "returns an error if country code alpha2 is invalid" do
@@ -379,10 +516,10 @@ describe Braintree::Customer do
379
516
  :billing_address => {
380
517
  :country_code_alpha2 => "zz",
381
518
  }
382
- }
519
+ },
383
520
  )
384
521
  result.success?.should == false
385
- result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_alpha2).map {|e| e.code}.should include(Braintree::ErrorCodes::Address::CountryCodeAlpha2IsNotAccepted)
522
+ result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_alpha2).map { |e| e.code }.should include(Braintree::ErrorCodes::Address::CountryCodeAlpha2IsNotAccepted)
386
523
  end
387
524
 
388
525
  it "returns an error if country code alpha3 is invalid" do
@@ -395,10 +532,10 @@ describe Braintree::Customer do
395
532
  :billing_address => {
396
533
  :country_code_alpha3 => "zzz",
397
534
  }
398
- }
535
+ },
399
536
  )
400
537
  result.success?.should == false
401
- result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_alpha3).map {|e| e.code}.should include(Braintree::ErrorCodes::Address::CountryCodeAlpha3IsNotAccepted)
538
+ result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_alpha3).map { |e| e.code }.should include(Braintree::ErrorCodes::Address::CountryCodeAlpha3IsNotAccepted)
402
539
  end
403
540
 
404
541
  it "returns an error if country code numeric is invalid" do
@@ -411,10 +548,10 @@ describe Braintree::Customer do
411
548
  :billing_address => {
412
549
  :country_code_numeric => "zzz",
413
550
  }
414
- }
551
+ },
415
552
  )
416
553
  result.success?.should == false
417
- result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_numeric).map {|e| e.code}.should include(Braintree::ErrorCodes::Address::CountryCodeNumericIsNotAccepted)
554
+ result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_numeric).map { |e| e.code }.should include(Braintree::ErrorCodes::Address::CountryCodeNumericIsNotAccepted)
418
555
  end
419
556
 
420
557
  it "returns errors if custom_fields are not registered" do
@@ -423,43 +560,12 @@ describe Braintree::Customer do
423
560
  :last_name => "Kennedy",
424
561
  :custom_fields => {
425
562
  :spouse_name => "Jacqueline"
426
- }
563
+ },
427
564
  )
428
565
  result.success?.should == false
429
566
  result.errors.for(:customer).on(:custom_fields)[0].message.should == "Custom field is invalid: spouse_name."
430
567
  end
431
568
 
432
- describe "venmo_sdk" do
433
- it "can create a customer with a venmo sdk payment method code" do
434
- result = Braintree::Customer.create(
435
- :first_name => "Steve",
436
- :last_name => "Hamlin",
437
- :credit_card => {
438
- :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::VisaPaymentMethodCode
439
- }
440
- )
441
- result.success?.should == true
442
- result.customer.credit_cards.first.bin.should == "400934"
443
- result.customer.credit_cards.first.last_4.should == "1881"
444
- end
445
-
446
- it "can create a customer with a venmo sdk session" do
447
- result = Braintree::Customer.create(
448
- :first_name => "Steve",
449
- :last_name => "Hamlin",
450
- :credit_card => {
451
- :number => Braintree::Test::CreditCardNumbers::MasterCard,
452
- :expiration_date => "05/2010",
453
- :options => {
454
- :venmo_sdk_session => Braintree::Test::VenmoSDK::Session
455
- }
456
- }
457
- )
458
- result.success?.should == true
459
- result.customer.credit_cards.first.venmo_sdk?.should == true
460
- end
461
- end
462
-
463
569
  context "client API" do
464
570
  it "can create a customer with a payment method nonce" do
465
571
  nonce = nonce_for_new_payment_method(
@@ -468,13 +574,13 @@ describe Braintree::Customer do
468
574
  :expiration_month => "11",
469
575
  :expiration_year => "2099",
470
576
  },
471
- :share => true
577
+ :share => true,
472
578
  )
473
579
 
474
580
  result = Braintree::Customer.create(
475
581
  :credit_card => {
476
582
  :payment_method_nonce => nonce
477
- }
583
+ },
478
584
  )
479
585
 
480
586
  result.success?.should == true
@@ -496,13 +602,104 @@ describe Braintree::Customer do
496
602
 
497
603
  result.success?.should == true
498
604
  end
605
+
606
+ context "verification_account_type" do
607
+ it "verifies card with account_type debit" do
608
+ nonce = nonce_for_new_payment_method(
609
+ :credit_card => {
610
+ :number => Braintree::Test::CreditCardNumbers::Hiper,
611
+ :expiration_month => "11",
612
+ :expiration_year => "2099",
613
+ },
614
+ )
615
+ result = Braintree::Customer.create(
616
+ :payment_method_nonce => nonce,
617
+ :credit_card => {
618
+ :options => {
619
+ :verify_card => true,
620
+ :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
621
+ :verification_account_type => "debit",
622
+ }
623
+ },
624
+ )
625
+
626
+ expect(result).to be_success
627
+ end
628
+
629
+ it "verifies card with account_type credit" do
630
+ nonce = nonce_for_new_payment_method(
631
+ :credit_card => {
632
+ :number => Braintree::Test::CreditCardNumbers::Hiper,
633
+ :expiration_month => "11",
634
+ :expiration_year => "2099",
635
+ },
636
+ )
637
+ result = Braintree::Customer.create(
638
+ :payment_method_nonce => nonce,
639
+ :credit_card => {
640
+ :options => {
641
+ :verify_card => true,
642
+ :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
643
+ :verification_account_type => "credit",
644
+ }
645
+ },
646
+ )
647
+
648
+ expect(result).to be_success
649
+ end
650
+
651
+ it "errors with invalid account_type" do
652
+ nonce = nonce_for_new_payment_method(
653
+ :credit_card => {
654
+ :number => Braintree::Test::CreditCardNumbers::Hiper,
655
+ :expiration_month => "11",
656
+ :expiration_year => "2099",
657
+ },
658
+ )
659
+ result = Braintree::Customer.create(
660
+ :payment_method_nonce => nonce,
661
+ :credit_card => {
662
+ :options => {
663
+ :verify_card => true,
664
+ :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
665
+ :verification_account_type => "ach",
666
+ }
667
+ },
668
+ )
669
+
670
+ expect(result).to_not be_success
671
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_account_type)[0].code).to eq Braintree::ErrorCodes::CreditCard::VerificationAccountTypeIsInvalid
672
+ end
673
+
674
+ it "errors when account_type not supported by merchant" do
675
+ nonce = nonce_for_new_payment_method(
676
+ :credit_card => {
677
+ :number => Braintree::Test::CreditCardNumbers::Visa,
678
+ :expiration_month => "11",
679
+ :expiration_year => "2099",
680
+ },
681
+ )
682
+ result = Braintree::Customer.create(
683
+ :payment_method_nonce => nonce,
684
+ :credit_card => {
685
+ :options => {
686
+ :verify_card => true,
687
+ :verification_account_type => "credit",
688
+ }
689
+ },
690
+ )
691
+
692
+ expect(result).to_not be_success
693
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_account_type)[0].code).to eq Braintree::ErrorCodes::CreditCard::VerificationAccountTypeNotSupported
694
+ end
695
+ end
499
696
  end
500
697
 
501
698
  describe "self.create!" do
502
699
  it "returns the customer if successful" do
503
700
  customer = Braintree::Customer.create!(
504
701
  :first_name => "Jim",
505
- :last_name => "Smith"
702
+ :last_name => "Smith",
506
703
  )
507
704
  customer.id.should =~ /\d+/
508
705
  customer.first_name.should == "Jim"
@@ -527,11 +724,11 @@ describe Braintree::Customer do
527
724
  :credit_card => {
528
725
  :number => Braintree::Test::CreditCardNumbers::Visa,
529
726
  :expiration_date => "05/2010"
530
- }
727
+ },
531
728
  )
532
729
  result = Braintree::Customer.credit(customer.id, :amount => "100.00")
533
730
  result.success?.should == true
534
- result.transaction.amount.should == BigDecimal.new("100.00")
731
+ result.transaction.amount.should == BigDecimal("100.00")
535
732
  result.transaction.type.should == "credit"
536
733
  result.transaction.customer_details.id.should == customer.id
537
734
  result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
@@ -547,10 +744,10 @@ describe Braintree::Customer do
547
744
  :credit_card => {
548
745
  :number => Braintree::Test::CreditCardNumbers::Visa,
549
746
  :expiration_date => "05/2010"
550
- }
747
+ },
551
748
  )
552
749
  transaction = Braintree::Customer.credit!(customer.id, :amount => "100.00")
553
- transaction.amount.should == BigDecimal.new("100.00")
750
+ transaction.amount.should == BigDecimal("100.00")
554
751
  transaction.type.should == "credit"
555
752
  transaction.customer_details.id.should == customer.id
556
753
  transaction.credit_card_details.token.should == customer.credit_cards[0].token
@@ -566,11 +763,11 @@ describe Braintree::Customer do
566
763
  :credit_card => {
567
764
  :number => Braintree::Test::CreditCardNumbers::Visa,
568
765
  :expiration_date => "05/2010"
569
- }
766
+ },
570
767
  )
571
768
  result = Braintree::Customer.sale(customer.id, :amount => "100.00")
572
769
  result.success?.should == true
573
- result.transaction.amount.should == BigDecimal.new("100.00")
770
+ result.transaction.amount.should == BigDecimal("100.00")
574
771
  result.transaction.type.should == "sale"
575
772
  result.transaction.customer_details.id.should == customer.id
576
773
  result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
@@ -586,10 +783,10 @@ describe Braintree::Customer do
586
783
  :credit_card => {
587
784
  :number => Braintree::Test::CreditCardNumbers::Visa,
588
785
  :expiration_date => "05/2010"
589
- }
786
+ },
590
787
  )
591
788
  transaction = Braintree::Customer.sale!(customer.id, :amount => "100.00")
592
- transaction.amount.should == BigDecimal.new("100.00")
789
+ transaction.amount.should == BigDecimal("100.00")
593
790
  transaction.type.should == "sale"
594
791
  transaction.customer_details.id.should == customer.id
595
792
  transaction.credit_card_details.token.should == customer.credit_cards[0].token
@@ -605,83 +802,27 @@ describe Braintree::Customer do
605
802
  :credit_card => {
606
803
  :number => Braintree::Test::CreditCardNumbers::Visa,
607
804
  :expiration_date => "05/2010"
608
- }
805
+ },
609
806
  )
610
- transaction = customer.sale!(:amount => "100.00")
807
+ transaction = Braintree::Customer.sale!(customer.id, :amount => "100.00")
611
808
  collection = Braintree::Customer.transactions(customer.id)
612
809
  collection.first.should == transaction
613
810
  end
614
811
  end
615
812
 
616
-
617
- describe "sale" do
618
- it "creates a sale transaction using the customer, returning a result object" do
619
- customer = Braintree::Customer.create!(
620
- :credit_card => {
621
- :number => Braintree::Test::CreditCardNumbers::Visa,
622
- :expiration_date => "05/2010"
623
- }
624
- )
625
- result = customer.sale(
626
- :amount => "100.00"
627
- )
628
- result.success?.should == true
629
- result.transaction.amount.should == BigDecimal.new("100.00")
630
- result.transaction.type.should == "sale"
631
- result.transaction.customer_details.id.should == customer.id
632
- result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
633
- result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
634
- result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
635
- result.transaction.credit_card_details.expiration_date.should == "05/2010"
636
- end
637
- end
638
-
639
- describe "sale!" do
640
- it "returns the created sale tranaction if valid" do
641
- customer = Braintree::Customer.create!(
642
- :credit_card => {
643
- :number => Braintree::Test::CreditCardNumbers::Visa,
644
- :expiration_date => "05/2010"
645
- }
646
- )
647
- transaction = customer.sale!(:amount => "100.00")
648
- transaction.amount.should == BigDecimal.new("100.00")
649
- transaction.type.should == "sale"
650
- transaction.customer_details.id.should == customer.id
651
- transaction.credit_card_details.token.should == customer.credit_cards[0].token
652
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
653
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
654
- transaction.credit_card_details.expiration_date.should == "05/2010"
655
- end
656
- end
657
-
658
- describe "transactions" do
659
- it "finds transactions for the customer" do
660
- customer = Braintree::Customer.create!(
661
- :credit_card => {
662
- :number => Braintree::Test::CreditCardNumbers::Visa,
663
- :expiration_date => "05/2010"
664
- }
665
- )
666
- transaction = customer.sale!(:amount => "100.00")
667
- collection = customer.transactions
668
- collection.first.should == transaction
669
- end
670
- end
671
-
672
813
  describe "credit" do
673
814
  it "creates a credit transaction using the customer, returning a result object" do
674
815
  customer = Braintree::Customer.create!(
675
816
  :credit_card => {
676
817
  :number => Braintree::Test::CreditCardNumbers::Visa,
677
818
  :expiration_date => "05/2010"
678
- }
819
+ },
679
820
  )
680
821
  result = customer.credit(
681
- :amount => "100.00"
822
+ :amount => "100.00",
682
823
  )
683
824
  result.success?.should == true
684
- result.transaction.amount.should == BigDecimal.new("100.00")
825
+ result.transaction.amount.should == BigDecimal("100.00")
685
826
  result.transaction.type.should == "credit"
686
827
  result.transaction.customer_details.id.should == customer.id
687
828
  result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
@@ -697,10 +838,10 @@ describe Braintree::Customer do
697
838
  :credit_card => {
698
839
  :number => Braintree::Test::CreditCardNumbers::Visa,
699
840
  :expiration_date => "05/2010"
700
- }
841
+ },
701
842
  )
702
843
  transaction = customer.credit!(:amount => "100.00")
703
- transaction.amount.should == BigDecimal.new("100.00")
844
+ transaction.amount.should == BigDecimal("100.00")
704
845
  transaction.type.should == "credit"
705
846
  transaction.customer_details.id.should == customer.id
706
847
  transaction.credit_card_details.token.should == customer.credit_cards[0].token
@@ -710,72 +851,11 @@ describe Braintree::Customer do
710
851
  end
711
852
  end
712
853
 
713
- describe "create_from_transparent_redirect" do
714
- it "returns a successful result if successful" do
715
- params = {
716
- :customer => {
717
- :first_name => "John",
718
- :last_name => "Doe",
719
- :company => "Doe Co",
720
- :email => "john@doe.com",
721
- :phone => "312.555.2323",
722
- :fax => "614.555.5656",
723
- :website => "www.johndoe.com"
724
- }
725
- }
726
-
727
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge({}))
728
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Customer.create_customer_url)
729
- result = Braintree::Customer.create_from_transparent_redirect(query_string_response)
730
-
731
- result.success?.should == true
732
- customer = result.customer
733
- customer.first_name.should == "John"
734
- customer.last_name.should == "Doe"
735
- customer.company.should == "Doe Co"
736
- customer.email.should == "john@doe.com"
737
- customer.phone.should == "312.555.2323"
738
- customer.fax.should == "614.555.5656"
739
- customer.website.should == "www.johndoe.com"
740
- end
741
-
742
- it "can pass any attribute through tr_data" do
743
- customer_id = "customer_#{rand(1_000_000)}"
744
- tr_data_params = {
745
- :customer => {
746
- :id => customer_id,
747
- :first_name => "John",
748
- :last_name => "Doe",
749
- :company => "Doe Co",
750
- :email => "john@doe.com",
751
- :phone => "312.555.2323",
752
- :fax => "614.555.5656",
753
- :website => "www.johndoe.com"
754
- }
755
- }
756
-
757
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
758
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.create_customer_url)
759
- result = Braintree::Customer.create_from_transparent_redirect(query_string_response)
760
-
761
- result.success?.should == true
762
- customer = result.customer
763
- customer.id.should == customer_id
764
- customer.first_name.should == "John"
765
- customer.last_name.should == "Doe"
766
- customer.company.should == "Doe Co"
767
- customer.email.should == "john@doe.com"
768
- customer.phone.should == "312.555.2323"
769
- customer.fax.should == "614.555.5656"
770
- customer.website.should == "www.johndoe.com"
771
- end
772
- end
773
-
774
854
  describe "delete" do
775
855
  it "deletes the customer" do
776
856
  result = Braintree::Customer.create(
777
857
  :first_name => "Joe",
778
- :last_name => "Cool"
858
+ :last_name => "Cool",
779
859
  )
780
860
  result.success?.should == true
781
861
 
@@ -792,12 +872,13 @@ describe Braintree::Customer do
792
872
  it "finds the customer with the given id" do
793
873
  result = Braintree::Customer.create(
794
874
  :first_name => "Joe",
795
- :last_name => "Cool"
875
+ :last_name => "Cool",
796
876
  )
797
877
  result.success?.should == true
798
878
 
799
879
  customer = Braintree::Customer.find(result.customer.id)
800
880
  customer.id.should == result.customer.id
881
+ customer.graphql_id.should_not be_nil
801
882
  customer.first_name.should == "Joe"
802
883
  customer.last_name.should == "Cool"
803
884
  end
@@ -807,25 +888,98 @@ describe Braintree::Customer do
807
888
  credit_card = Braintree::CreditCard.create(
808
889
  :customer_id => customer.id,
809
890
  :number => Braintree::Test::CreditCardNumbers::Visa,
810
- :expiration_date => "05/2012"
891
+ :expiration_date => "05/2012",
811
892
  ).credit_card
812
893
 
813
894
  subscription = Braintree::Subscription.create(
814
895
  :payment_method_token => credit_card.token,
815
896
  :plan_id => "integration_trialless_plan",
816
- :price => "1.00"
897
+ :price => "1.00",
817
898
  ).subscription
818
899
 
819
900
  found_customer = Braintree::Customer.find(customer.id)
820
901
  found_customer.credit_cards.first.subscriptions.first.id.should == subscription.id
821
902
  found_customer.credit_cards.first.subscriptions.first.plan_id.should == "integration_trialless_plan"
822
903
  found_customer.credit_cards.first.subscriptions.first.payment_method_token.should == credit_card.token
823
- found_customer.credit_cards.first.subscriptions.first.price.should == BigDecimal.new("1.00")
904
+ found_customer.credit_cards.first.subscriptions.first.price.should == BigDecimal("1.00")
905
+ end
906
+
907
+ context "when given an association filter id" do
908
+ it "filters out all filterable associations" do
909
+ customer = Braintree::Customer.create(
910
+ :custom_fields => {
911
+ :store_me => "custom value"
912
+ },
913
+ ).customer
914
+ credit_card = Braintree::CreditCard.create(
915
+ :customer_id => customer.id,
916
+ :number => Braintree::Test::CreditCardNumbers::Visa,
917
+ :expiration_date => "05/2012",
918
+ :billing_address => {
919
+ :street_address => "1 E Main St",
920
+ :locality => "Chicago",
921
+ :region => "Illinois",
922
+ :postal_code => "60622",
923
+ :country_name => "United States of America"
924
+ },
925
+ ).credit_card
926
+
927
+ subscription = Braintree::Subscription.create(
928
+ :payment_method_token => credit_card.token,
929
+ :plan_id => "integration_trialless_plan",
930
+ :price => "1.00",
931
+ ).subscription
932
+
933
+ found_customer = Braintree::Customer.find(customer.id, {
934
+ :association_filter_id => "customernoassociations"
935
+ })
936
+ found_customer.credit_cards.length.should == 0
937
+ found_customer.payment_methods.length.should == 0
938
+ found_customer.addresses.length.should == 0
939
+ found_customer.custom_fields.should == {}
940
+ end
941
+
942
+ it "filters out nested filterable associations" do
943
+ customer = Braintree::Customer.create(
944
+ :custom_fields => {
945
+ :store_me => "custom value"
946
+ },
947
+ ).customer
948
+ credit_card = Braintree::CreditCard.create(
949
+ :customer_id => customer.id,
950
+ :number => Braintree::Test::CreditCardNumbers::Visa,
951
+ :expiration_date => "05/2012",
952
+ :billing_address => {
953
+ :street_address => "1 E Main St",
954
+ :locality => "Chicago",
955
+ :region => "Illinois",
956
+ :postal_code => "60622",
957
+ :country_name => "United States of America"
958
+ },
959
+ ).credit_card
960
+
961
+ subscription = Braintree::Subscription.create(
962
+ :payment_method_token => credit_card.token,
963
+ :plan_id => "integration_trialless_plan",
964
+ :price => "1.00",
965
+ ).subscription
966
+
967
+ found_customer = Braintree::Customer.find(customer.id, {
968
+ :association_filter_id => "customertoplevelassociations"
969
+ })
970
+
971
+ found_customer.credit_cards.length.should == 1
972
+ found_customer.credit_cards.first.subscriptions.length.should == 0
973
+ found_customer.payment_methods.length.should == 1
974
+ found_customer.payment_methods.first.subscriptions.length.should == 0
975
+ found_customer.addresses.length.should == 1
976
+ found_customer.custom_fields.length.should == 1
977
+ end
824
978
  end
825
979
 
826
980
  it "returns associated ApplePayCards" do
827
981
  result = Braintree::Customer.create(
828
- :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx
982
+ :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
829
983
  )
830
984
  result.success?.should == true
831
985
 
@@ -836,56 +990,70 @@ describe Braintree::Customer do
836
990
  apple_pay_card.token.should_not be_nil
837
991
  apple_pay_card.expiration_year.should_not be_nil
838
992
  apple_pay_card.payment_instrument_name.should == "AmEx 41002"
839
- end
840
-
841
- it "returns associated android pay proxy cards" do
842
- result = Braintree::Customer.create(
843
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover
844
- )
845
- result.success?.should == true
846
-
847
- found_customer = Braintree::Customer.find(result.customer.id)
848
- found_customer.android_pay_cards.size.should == 1
849
- found_customer.payment_methods.size.should == 1
850
- android_pay_card = found_customer.android_pay_cards.first
851
- android_pay_card.should be_a Braintree::AndroidPayCard
852
- android_pay_card.token.should_not be_nil
853
- android_pay_card.expiration_year.should_not be_nil
854
- end
855
-
856
- it "returns associated android pay network tokens" do
993
+ apple_pay_card.commercial.should_not be_nil
994
+ apple_pay_card.country_of_issuance.should_not be_nil
995
+ apple_pay_card.debit.should_not be_nil
996
+ apple_pay_card.durbin_regulated.should_not be_nil
997
+ apple_pay_card.healthcare.should_not be_nil
998
+ apple_pay_card.issuing_bank.should_not be_nil
999
+ apple_pay_card.payroll.should_not be_nil
1000
+ apple_pay_card.prepaid.should_not be_nil
1001
+ apple_pay_card.product_id.should_not be_nil
1002
+ end
1003
+
1004
+ it "returns associated google pay proxy cards" do
857
1005
  result = Braintree::Customer.create(
858
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayMasterCard
1006
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
859
1007
  )
860
1008
  result.success?.should == true
861
1009
 
862
1010
  found_customer = Braintree::Customer.find(result.customer.id)
863
- found_customer.android_pay_cards.size.should == 1
1011
+ found_customer.google_pay_cards.size.should == 1
864
1012
  found_customer.payment_methods.size.should == 1
865
- android_pay_card = found_customer.android_pay_cards.first
866
- android_pay_card.should be_a Braintree::AndroidPayCard
867
- android_pay_card.token.should_not be_nil
868
- android_pay_card.expiration_year.should_not be_nil
869
- end
870
-
871
- it "returns associated amex express checkout cards" do
1013
+ google_pay_card = found_customer.google_pay_cards.first
1014
+ google_pay_card.should be_a Braintree::GooglePayCard
1015
+ google_pay_card.token.should_not be_nil
1016
+ google_pay_card.expiration_year.should_not be_nil
1017
+ google_pay_card.is_network_tokenized?.should == false
1018
+ google_pay_card.commercial.should_not be_nil
1019
+ google_pay_card.country_of_issuance.should_not be_nil
1020
+ google_pay_card.debit.should_not be_nil
1021
+ google_pay_card.durbin_regulated.should_not be_nil
1022
+ google_pay_card.healthcare.should_not be_nil
1023
+ google_pay_card.issuing_bank.should_not be_nil
1024
+ google_pay_card.payroll.should_not be_nil
1025
+ google_pay_card.prepaid.should_not be_nil
1026
+ google_pay_card.product_id.should_not be_nil
1027
+ end
1028
+
1029
+ it "returns associated google pay network tokens" do
872
1030
  result = Braintree::Customer.create(
873
- :payment_method_nonce => Braintree::Test::Nonce::AmexExpressCheckout
1031
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
874
1032
  )
875
1033
  result.success?.should == true
876
1034
 
877
1035
  found_customer = Braintree::Customer.find(result.customer.id)
878
- found_customer.amex_express_checkout_cards.size.should == 1
1036
+ found_customer.google_pay_cards.size.should == 1
879
1037
  found_customer.payment_methods.size.should == 1
880
- amex_express_checkout_card = found_customer.amex_express_checkout_cards.first
881
- amex_express_checkout_card.should be_a Braintree::AmexExpressCheckoutCard
882
- amex_express_checkout_card.token.should_not be_nil
883
- amex_express_checkout_card.expiration_year.should_not be_nil
1038
+ google_pay_card = found_customer.google_pay_cards.first
1039
+ google_pay_card.should be_a Braintree::GooglePayCard
1040
+ google_pay_card.token.should_not be_nil
1041
+ google_pay_card.expiration_year.should_not be_nil
1042
+ google_pay_card.is_network_tokenized?.should == true
1043
+ google_pay_card.commercial.should_not be_nil
1044
+ google_pay_card.country_of_issuance.should_not be_nil
1045
+ google_pay_card.debit.should_not be_nil
1046
+ google_pay_card.durbin_regulated.should_not be_nil
1047
+ google_pay_card.healthcare.should_not be_nil
1048
+ google_pay_card.issuing_bank.should_not be_nil
1049
+ google_pay_card.payroll.should_not be_nil
1050
+ google_pay_card.prepaid.should_not be_nil
1051
+ google_pay_card.product_id.should_not be_nil
884
1052
  end
885
1053
 
886
1054
  it "returns associated venmo accounts" do
887
1055
  result = Braintree::Customer.create(
888
- :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount
1056
+ :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
889
1057
  )
890
1058
  result.success?.should == true
891
1059
 
@@ -898,9 +1066,14 @@ describe Braintree::Customer do
898
1066
  venmo_account.username.should_not be_nil
899
1067
  end
900
1068
 
901
- it "returns associated us bank accounts" do
1069
+ xit "returns associated us bank accounts" do
902
1070
  result = Braintree::Customer.create(
903
- :payment_method_nonce => generate_valid_us_bank_account_nonce
1071
+ :payment_method_nonce => generate_non_plaid_us_bank_account_nonce,
1072
+ :credit_card => {
1073
+ :options => {
1074
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
1075
+ }
1076
+ },
904
1077
  )
905
1078
  result.should be_success
906
1079
 
@@ -911,9 +1084,9 @@ describe Braintree::Customer do
911
1084
  us_bank_account = found_customer.us_bank_accounts.first
912
1085
  us_bank_account.should be_a(Braintree::UsBankAccount)
913
1086
  us_bank_account.routing_number.should == "021000021"
914
- us_bank_account.last_4.should == "1234"
1087
+ us_bank_account.last_4.should == "0000"
915
1088
  us_bank_account.account_type.should == "checking"
916
- us_bank_account.account_holder_name.should == "Dan Schulman"
1089
+ us_bank_account.account_holder_name.should == "John Doe"
917
1090
  us_bank_account.bank_name.should =~ /CHASE/
918
1091
  end
919
1092
 
@@ -943,10 +1116,78 @@ describe Braintree::Customer do
943
1116
  end
944
1117
 
945
1118
  describe "self.update" do
1119
+ it "updates the credit card with three_d_secure pass thru params" do
1120
+ customer = Braintree::Customer.create!(
1121
+ :first_name => "Joe",
1122
+ :last_name => "Cool",
1123
+ )
1124
+ result = Braintree::Customer.update(
1125
+ customer.id,
1126
+ :first_name => "Mr. Joe",
1127
+ :last_name => "Super Cool",
1128
+ :custom_fields => {
1129
+ :store_me => "a value"
1130
+ },
1131
+ :credit_card => {
1132
+ :number => 4111111111111111,
1133
+ :expiration_date => "05/2060",
1134
+ :three_d_secure_pass_thru => {
1135
+ :eci_flag => "02",
1136
+ :cavv => "some_cavv",
1137
+ :xid => "some_xid",
1138
+ :three_d_secure_version => "1.0.2",
1139
+ :authentication_response => "Y",
1140
+ :directory_response => "Y",
1141
+ :cavv_algorithm => "2",
1142
+ :ds_transaction_id => "some_ds_transaction_id",
1143
+ },
1144
+ :options => {:verify_card => true},
1145
+ },
1146
+ )
1147
+ result.success?.should == true
1148
+ result.customer.id.should == customer.id
1149
+ result.customer.first_name.should == "Mr. Joe"
1150
+ result.customer.last_name.should == "Super Cool"
1151
+ result.customer.custom_fields[:store_me].should == "a value"
1152
+ end
1153
+
1154
+ it "validates the presence of three_d_secure_version while passing three_d_secure_pass_thru in update" do
1155
+ customer = Braintree::Customer.create!(
1156
+ :first_name => "Joe",
1157
+ :last_name => "Cool",
1158
+ )
1159
+ result = Braintree::Customer.update(
1160
+ customer.id,
1161
+ :first_name => "Mr. Joe",
1162
+ :last_name => "Super Cool",
1163
+ :custom_fields => {
1164
+ :store_me => "a value"
1165
+ },
1166
+ :credit_card => {
1167
+ :number => 4111111111111111,
1168
+ :expiration_date => "05/2060",
1169
+ :three_d_secure_pass_thru => {
1170
+ :eci_flag => "02",
1171
+ :cavv => "some_cavv",
1172
+ :xid => "some_xid",
1173
+ :authentication_response => "Y",
1174
+ :directory_response => "Y",
1175
+ :cavv_algorithm => "2",
1176
+ :ds_transaction_id => "some_ds_transaction_id",
1177
+ },
1178
+ options: {:verify_card => true}
1179
+ },
1180
+ )
1181
+ expect(result).to_not be_success
1182
+ error = result.errors.for(:verification).first
1183
+ expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsRequired)
1184
+ expect(error.message).to eq("ThreeDSecureVersion is required.")
1185
+ end
1186
+
946
1187
  it "updates the customer with the given id if successful" do
947
1188
  customer = Braintree::Customer.create!(
948
1189
  :first_name => "Joe",
949
- :last_name => "Cool"
1190
+ :last_name => "Cool",
950
1191
  )
951
1192
  result = Braintree::Customer.update(
952
1193
  customer.id,
@@ -954,7 +1195,7 @@ describe Braintree::Customer do
954
1195
  :last_name => "Super Cool",
955
1196
  :custom_fields => {
956
1197
  :store_me => "a value"
957
- }
1198
+ },
958
1199
  )
959
1200
  result.success?.should == true
960
1201
  result.customer.id.should == customer.id
@@ -968,7 +1209,7 @@ describe Braintree::Customer do
968
1209
  :credit_card => {
969
1210
  :number => 4111111111111111,
970
1211
  :expiration_date => "05/2010",
971
- }
1212
+ },
972
1213
  )
973
1214
  result = Braintree::Customer.update(
974
1215
  customer.id,
@@ -978,7 +1219,7 @@ describe Braintree::Customer do
978
1219
  :options=> {
979
1220
  :fail_on_duplicate_payment_method => true
980
1221
  }
981
- }
1222
+ },
982
1223
  )
983
1224
  result.success?.should == false
984
1225
  result.errors.for(:customer).for(:credit_card).on(:number)[0].message.should == "Duplicate card exists in the vault."
@@ -987,7 +1228,7 @@ describe Braintree::Customer do
987
1228
  it "updates the default payment method" do
988
1229
  customer = Braintree::Customer.create!(
989
1230
  :first_name => "Joe",
990
- :last_name => "Brown"
1231
+ :last_name => "Brown",
991
1232
  )
992
1233
 
993
1234
  token1 = random_payment_method_token
@@ -995,7 +1236,7 @@ describe Braintree::Customer do
995
1236
  payment_method1 = Braintree::PaymentMethod.create(
996
1237
  :customer_id => customer.id,
997
1238
  :payment_method_nonce => Braintree::Test::Nonce::TransactableVisa,
998
- :token => token1
1239
+ :token => token1,
999
1240
  )
1000
1241
 
1001
1242
  payment_method1 = Braintree::PaymentMethod.find(token1)
@@ -1006,11 +1247,11 @@ describe Braintree::Customer do
1006
1247
  payment_method2 = Braintree::PaymentMethod.create(
1007
1248
  :customer_id => customer.id,
1008
1249
  :payment_method_nonce => Braintree::Test::Nonce::TransactableMasterCard,
1009
- :token => token2
1250
+ :token => token2,
1010
1251
  )
1011
1252
 
1012
1253
  Braintree::Customer.update(customer.id,
1013
- :default_payment_method_token => token2
1254
+ :default_payment_method_token => token2,
1014
1255
  )
1015
1256
 
1016
1257
  payment_method2 = Braintree::PaymentMethod.find(token2)
@@ -1020,7 +1261,7 @@ describe Braintree::Customer do
1020
1261
  it "updates the default payment method in the options" do
1021
1262
  customer = Braintree::Customer.create!(
1022
1263
  :first_name => "Joe",
1023
- :last_name => "Brown"
1264
+ :last_name => "Brown",
1024
1265
  )
1025
1266
 
1026
1267
  token1 = random_payment_method_token
@@ -1028,7 +1269,7 @@ describe Braintree::Customer do
1028
1269
  payment_method1 = Braintree::PaymentMethod.create(
1029
1270
  :customer_id => customer.id,
1030
1271
  :payment_method_nonce => Braintree::Test::Nonce::TransactableVisa,
1031
- :token => token1
1272
+ :token => token1,
1032
1273
  )
1033
1274
 
1034
1275
  payment_method1 = Braintree::PaymentMethod.find(token1)
@@ -1039,7 +1280,7 @@ describe Braintree::Customer do
1039
1280
  payment_method2 = Braintree::PaymentMethod.create(
1040
1281
  :customer_id => customer.id,
1041
1282
  :payment_method_nonce => Braintree::Test::Nonce::TransactableMasterCard,
1042
- :token => token2
1283
+ :token => token2,
1043
1284
  )
1044
1285
 
1045
1286
  Braintree::Customer.update(customer.id,
@@ -1048,7 +1289,7 @@ describe Braintree::Customer do
1048
1289
  :update_existing_token => token2,
1049
1290
  :make_default => true
1050
1291
  }
1051
- }
1292
+ },
1052
1293
  )
1053
1294
 
1054
1295
  payment_method2 = Braintree::PaymentMethod.find(token2)
@@ -1058,7 +1299,7 @@ describe Braintree::Customer do
1058
1299
  it "can use any country code" do
1059
1300
  customer = Braintree::Customer.create!(
1060
1301
  :first_name => "Alex",
1061
- :last_name => "Matterson"
1302
+ :last_name => "Matterson",
1062
1303
  )
1063
1304
  result = Braintree::Customer.update(
1064
1305
  customer.id,
@@ -1073,7 +1314,7 @@ describe Braintree::Customer do
1073
1314
  :country_code_alpha3 => "FJI",
1074
1315
  :country_code_numeric => "242"
1075
1316
  }
1076
- }
1317
+ },
1077
1318
  )
1078
1319
  result.success?.should == true
1079
1320
  result.customer.addresses[0].country_name.should == "Fiji"
@@ -1092,7 +1333,7 @@ describe Braintree::Customer do
1092
1333
  :first_name => "Joe",
1093
1334
  :postal_code => "60622"
1094
1335
  }
1095
- }
1336
+ },
1096
1337
  )
1097
1338
 
1098
1339
  result = Braintree::Customer.update(
@@ -1100,13 +1341,13 @@ describe Braintree::Customer do
1100
1341
  :first_name => "New Joe",
1101
1342
  :credit_card => {
1102
1343
  :cardholder_name => "New Joe Cardholder",
1103
- :options => { :update_existing_token => customer.credit_cards.first.token },
1344
+ :options => {:update_existing_token => customer.credit_cards.first.token},
1104
1345
  :billing_address => {
1105
1346
  :last_name => "Cool",
1106
1347
  :postal_code => "60666",
1107
- :options => { :update_existing => true }
1348
+ :options => {:update_existing => true}
1108
1349
  }
1109
- }
1350
+ },
1110
1351
  )
1111
1352
  result.success?.should == true
1112
1353
  result.customer.id.should == customer.id
@@ -1124,7 +1365,7 @@ describe Braintree::Customer do
1124
1365
 
1125
1366
  it "can update the customer and verify_card with a specific verification_amount" do
1126
1367
  customer = Braintree::Customer.create!(
1127
- :first_name => "Joe"
1368
+ :first_name => "Joe",
1128
1369
  )
1129
1370
 
1130
1371
  result = Braintree::Customer.update(
@@ -1134,19 +1375,150 @@ describe Braintree::Customer do
1134
1375
  :cardholder_name => "New Joe Cardholder",
1135
1376
  :number => Braintree::Test::CreditCardNumbers::Visa,
1136
1377
  :expiration_date => "12/2009",
1137
- :options => { :verify_card => true, :verification_amount => "2.00" }
1138
- }
1378
+ :options => {:verify_card => true, :verification_amount => "2.00"}
1379
+ },
1139
1380
  )
1140
1381
  result.success?.should == true
1141
1382
  end
1142
1383
 
1384
+ it "includes risk data when skip_advanced_fraud_checking is false" do
1385
+ with_fraud_protection_enterprise_merchant do
1386
+ customer = Braintree::Customer.create!(
1387
+ :first_name => "Joe",
1388
+ )
1389
+
1390
+ updated_result = Braintree::Customer.update(
1391
+ customer.id,
1392
+ :credit_card => {
1393
+ :cardholder_name => "New Joe Cardholder",
1394
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1395
+ :expiration_date => "12/2009",
1396
+ :options => {
1397
+ :skip_advanced_fraud_checking => false,
1398
+ :verify_card => true,
1399
+ },
1400
+ },
1401
+ )
1402
+
1403
+ expect(updated_result).to be_success
1404
+ verification = updated_result.customer.credit_cards.first.verification
1405
+ expect(verification.risk_data).not_to be_nil
1406
+ end
1407
+ end
1408
+
1409
+ it "does not include risk data when skip_advanced_fraud_checking is true" do
1410
+ with_fraud_protection_enterprise_merchant do
1411
+ customer = Braintree::Customer.create!(
1412
+ :first_name => "Joe",
1413
+ )
1414
+
1415
+ updated_result = Braintree::Customer.update(
1416
+ customer.id,
1417
+ :credit_card => {
1418
+ :cardholder_name => "New Joe Cardholder",
1419
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1420
+ :expiration_date => "12/2009",
1421
+ :options => {
1422
+ :skip_advanced_fraud_checking => true,
1423
+ :verify_card => true,
1424
+ },
1425
+ },
1426
+ )
1427
+
1428
+ expect(updated_result).to be_success
1429
+ verification = updated_result.customer.credit_cards.first.verification
1430
+ expect(verification.risk_data).to be_nil
1431
+ end
1432
+ end
1433
+
1434
+ it "can update a tax_identifier" do
1435
+ customer = Braintree::Customer.create!(
1436
+ :tax_identifiers => [
1437
+ {:country_code => "US", :identifier => "987654321"},
1438
+ {:country_code => "CL", :identifier => "123456789"}
1439
+ ],
1440
+ )
1441
+
1442
+ result = Braintree::Customer.update(
1443
+ customer.id,
1444
+ :tax_identifiers => [{:country_code => "US", :identifier => "567891234"}],
1445
+ )
1446
+ result.success?.should == true
1447
+ end
1448
+
1449
+ it "validates presence of three_d_secure_version in 3ds pass thru params" do
1450
+ result = Braintree::Customer.create(
1451
+ :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1452
+ :credit_card => {
1453
+ :three_d_secure_pass_thru => {
1454
+ :eci_flag => "02",
1455
+ :cavv => "some_cavv",
1456
+ :xid => "some_xid",
1457
+ :three_d_secure_version => "xx",
1458
+ :authentication_response => "Y",
1459
+ :directory_response => "Y",
1460
+ :cavv_algorithm => "2",
1461
+ :ds_transaction_id => "some_ds_transaction_id",
1462
+ },
1463
+ :options => {:verify_card => true}
1464
+ },
1465
+ )
1466
+
1467
+ expect(result).not_to be_success
1468
+ error = result.errors.for(:verification).first
1469
+ expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsInvalid)
1470
+ expect(error.message).to eq("The version of 3D Secure authentication must be composed only of digits and separated by periods (e.g. `1.0.2`).")
1471
+ end
1472
+
1473
+ it "accepts three_d_secure pass thru params in the request" do
1474
+ result = Braintree::Customer.create(
1475
+ :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1476
+ :credit_card => {
1477
+ :three_d_secure_pass_thru => {
1478
+ :eci_flag => "02",
1479
+ :cavv => "some_cavv",
1480
+ :xid => "some_xid",
1481
+ :three_d_secure_version => "2.2.1",
1482
+ :authentication_response => "Y",
1483
+ :directory_response => "Y",
1484
+ :cavv_algorithm => "2",
1485
+ :ds_transaction_id => "some_ds_transaction_id",
1486
+ },
1487
+ :options => {:verify_card => true}
1488
+ },
1489
+ )
1490
+
1491
+ expect(result).to be_success
1492
+ end
1493
+
1494
+ it "returns 3DS info on cc verification" do
1495
+ result = Braintree::Customer.create(
1496
+ :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1497
+ :credit_card => {
1498
+ :options => {:verify_card => true}
1499
+ },
1500
+ )
1501
+ result.success?.should == true
1502
+
1503
+ three_d_secure_info = result.customer.payment_methods.first.verification.three_d_secure_info
1504
+ three_d_secure_info.enrolled.should == "Y"
1505
+ three_d_secure_info.should be_liability_shifted
1506
+ three_d_secure_info.should be_liability_shift_possible
1507
+ three_d_secure_info.status.should == "authenticate_successful"
1508
+ three_d_secure_info.cavv.should == "cavv_value"
1509
+ three_d_secure_info.xid.should == "xid_value"
1510
+ three_d_secure_info.eci_flag.should == "05"
1511
+ three_d_secure_info.three_d_secure_version.should == "1.0.2"
1512
+ three_d_secure_info.ds_transaction_id.should == nil
1513
+ end
1514
+
1143
1515
  it "can update the nested billing address with billing_address_id" do
1144
1516
  customer = Braintree::Customer.create!
1145
1517
 
1146
1518
  address = Braintree::Address.create!(
1147
1519
  :customer_id => customer.id,
1148
1520
  :first_name => "John",
1149
- :last_name => "Doe"
1521
+ :last_name => "Doe",
1150
1522
  )
1151
1523
 
1152
1524
  customer = Braintree::Customer.update(
@@ -1155,7 +1527,7 @@ describe Braintree::Customer do
1155
1527
  :number => Braintree::Test::CreditCardNumbers::Visa,
1156
1528
  :expiration_date => "12/2009",
1157
1529
  :billing_address_id => address.id
1158
- }
1530
+ },
1159
1531
  ).customer
1160
1532
 
1161
1533
  billing_address = customer.credit_cards.first.billing_address
@@ -1168,23 +1540,144 @@ describe Braintree::Customer do
1168
1540
  customer = Braintree::Customer.create!(:email => "valid@email.com")
1169
1541
  result = Braintree::Customer.update(
1170
1542
  customer.id,
1171
- :email => "@invalid.com"
1543
+ :email => "@invalid.com",
1172
1544
  )
1173
1545
  result.success?.should == false
1174
1546
  result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
1175
1547
  end
1548
+
1549
+ context "verification_currency_iso_code" do
1550
+ it "can update the customer after validating verification_currency_iso_code" do
1551
+ customer = Braintree::Customer.create!(
1552
+ :first_name => "Joe",
1553
+ )
1554
+
1555
+ result = Braintree::Customer.update(
1556
+ customer.id,
1557
+ :first_name => "New Joe",
1558
+ :credit_card => {
1559
+ :cardholder_name => "New Joe Cardholder",
1560
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1561
+ :expiration_date => "12/2009",
1562
+ :options => {:verify_card => true, :verification_currency_iso_code => "USD"}
1563
+ },
1564
+ )
1565
+ result.success?.should == true
1566
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
1567
+ end
1568
+
1569
+ it "can update the customer after validating verification_currency_iso_code against the given verification_merchant_account_id" do
1570
+ customer = Braintree::Customer.create!(
1571
+ :first_name => "Joe",
1572
+ )
1573
+
1574
+ result = Braintree::Customer.update(
1575
+ customer.id,
1576
+ :first_name => "New Joe",
1577
+ :credit_card => {
1578
+ :cardholder_name => "New Joe Cardholder",
1579
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1580
+ :expiration_date => "12/2009",
1581
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "USD"}
1582
+ },
1583
+ )
1584
+ result.success?.should == true
1585
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
1586
+ result.customer.credit_cards[0].verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
1587
+ end
1588
+
1589
+ it "throws error due to verification_currency_iso_code not matching against the currency configured in default merchant account" do
1590
+ customer = Braintree::Customer.create!(
1591
+ :first_name => "Joe",
1592
+ )
1593
+
1594
+ result = Braintree::Customer.update(
1595
+ customer.id,
1596
+ :first_name => "New Joe",
1597
+ :credit_card => {
1598
+ :cardholder_name => "New Joe Cardholder",
1599
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1600
+ :expiration_date => "12/2009",
1601
+ :options => {:verify_card => true, :verification_currency_iso_code => "GBP"}
1602
+ },
1603
+ )
1604
+ result.success?.should == false
1605
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1606
+
1607
+ end
1608
+
1609
+ it "throws error due to verification_currency_iso_code not matching against the currency configured in the given verification merchant account" do
1610
+ customer = Braintree::Customer.create!(
1611
+ :first_name => "Joe",
1612
+ )
1613
+
1614
+ result = Braintree::Customer.update(
1615
+ customer.id,
1616
+ :first_name => "New Joe",
1617
+ :credit_card => {
1618
+ :cardholder_name => "New Joe Cardholder",
1619
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1620
+ :expiration_date => "12/2009",
1621
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "GBP"}
1622
+ },
1623
+ )
1624
+ result.success?.should == false
1625
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1626
+
1627
+ end
1628
+ end
1629
+
1630
+ context "verification_account_type" do
1631
+ it "updates the credit card with account_type credit" do
1632
+ customer = Braintree::Customer.create!
1633
+ update_result = Braintree::Customer.update(
1634
+ customer.id,
1635
+ :credit_card => {
1636
+ :cardholder_name => "New Holder",
1637
+ :cvv => "456",
1638
+ :number => Braintree::Test::CreditCardNumbers::Hiper,
1639
+ :expiration_date => "06/2013",
1640
+ :options => {
1641
+ :verify_card => true,
1642
+ :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
1643
+ :verification_account_type => "credit",
1644
+ },
1645
+ },
1646
+ )
1647
+ expect(update_result).to be_success
1648
+ end
1649
+
1650
+ it "updates the credit card with account_type debit" do
1651
+ customer = Braintree::Customer.create!
1652
+ update_result = Braintree::Customer.update(
1653
+ customer.id,
1654
+ :credit_card => {
1655
+ :cardholder_name => "New Holder",
1656
+ :cvv => "456",
1657
+ :number => Braintree::Test::CreditCardNumbers::Hiper,
1658
+ :expiration_date => "06/2013",
1659
+ :options => {
1660
+ :verify_card => true,
1661
+ :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
1662
+ :verification_account_type => "debit",
1663
+ },
1664
+ },
1665
+ )
1666
+ expect(update_result).to be_success
1667
+ end
1668
+ end
1176
1669
  end
1177
1670
 
1178
1671
  describe "self.update!" do
1179
1672
  it "returns the updated customer if successful" do
1180
1673
  customer = Braintree::Customer.create!(
1181
1674
  :first_name => "Joe",
1182
- :last_name => "Cool"
1675
+ :last_name => "Cool",
1183
1676
  )
1184
1677
  updated_customer = Braintree::Customer.update!(
1185
1678
  customer.id,
1186
1679
  :first_name => "Mr. Joe",
1187
- :last_name => "Super Cool"
1680
+ :last_name => "Super Cool",
1188
1681
  )
1189
1682
  updated_customer.first_name.should == "Mr. Joe"
1190
1683
  updated_customer.last_name.should == "Super Cool"
@@ -1199,214 +1692,7 @@ describe Braintree::Customer do
1199
1692
  end
1200
1693
  end
1201
1694
 
1202
- describe "update" do
1203
- it "updates the customer" do
1204
- customer = Braintree::Customer.create!(
1205
- :first_name => "Joe",
1206
- :last_name => "Cool"
1207
- )
1208
- update_result = customer.update(
1209
- :first_name => "Mr. Joe",
1210
- :last_name => "Super Cool"
1211
- )
1212
- update_result.success?.should == true
1213
- update_result.customer.should == customer
1214
- updated_customer = update_result.customer
1215
- updated_customer.first_name.should == "Mr. Joe"
1216
- updated_customer.last_name.should == "Super Cool"
1217
- end
1218
-
1219
- it "returns an error response if invalid" do
1220
- customer = Braintree::Customer.create!(
1221
- :email => "valid@email.com"
1222
- )
1223
- result = customer.update(
1224
- :email => "@invalid.com"
1225
- )
1226
- result.success?.should == false
1227
- result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
1228
- end
1229
- end
1230
-
1231
- describe "update!" do
1232
- it "returns the customer and updates the customer if successful" do
1233
- customer = Braintree::Customer.create!(
1234
- :first_name => "Joe",
1235
- :last_name => "Cool"
1236
- )
1237
- customer.update!(
1238
- :first_name => "Mr. Joe",
1239
- :last_name => "Super Cool"
1240
- ).should == customer
1241
- customer.first_name.should == "Mr. Joe"
1242
- customer.last_name.should == "Super Cool"
1243
- customer.updated_at.between?(Time.now - 60, Time.now).should == true
1244
- end
1245
-
1246
- it "raises an error if unsuccessful" do
1247
- customer = Braintree::Customer.create!(
1248
- :email => "valid@email.com"
1249
- )
1250
- expect do
1251
- customer.update!(:email => "@invalid.com")
1252
- end.to raise_error(Braintree::ValidationsFailed)
1253
- end
1254
- end
1255
-
1256
- describe "update_from_transparent_redirect" do
1257
- it "returns a successful result if successful" do
1258
- result = Braintree::Customer.create(
1259
- :first_name => "Old First",
1260
- :last_name => "Old Last",
1261
- :company => "Old Company",
1262
- :email => "old@email.com",
1263
- :phone => "000.111.2222",
1264
- :fax => "000.222.3333",
1265
- :website => "old.website.com"
1266
- )
1267
- result.success?.should == true
1268
- original_customer = result.customer
1269
- params = {
1270
- :customer => {
1271
- :first_name => "New First",
1272
- :last_name => "New Last",
1273
- :company => "New Company",
1274
- :email => "new@email.com",
1275
- :phone => "888.111.2222",
1276
- :fax => "999.222.3333",
1277
- :website => "new.website.com"
1278
- }
1279
- }
1280
- tr_data_params = {
1281
- :customer_id => original_customer.id
1282
- }
1283
-
1284
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1285
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Customer.update_customer_url)
1286
- result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
1287
-
1288
- result.success?.should == true
1289
- customer = result.customer
1290
- customer.id.should == original_customer.id
1291
- customer.first_name.should == "New First"
1292
- customer.last_name.should == "New Last"
1293
- customer.company.should == "New Company"
1294
- customer.email.should == "new@email.com"
1295
- customer.phone.should == "888.111.2222"
1296
- customer.fax.should == "999.222.3333"
1297
- customer.website.should == "new.website.com"
1298
- end
1299
-
1300
- it "returns a successful result when updating an existing credit card" do
1301
- result = Braintree::Customer.create(
1302
- :first_name => "Old First",
1303
- :last_name => "Old Last",
1304
- :company => "Old Company",
1305
- :email => "old@email.com",
1306
- :phone => "000.111.2222",
1307
- :fax => "000.222.3333",
1308
- :website => "old.website.com",
1309
- :credit_card => {
1310
- :number => Braintree::Test::CreditCardNumbers::Visa,
1311
- :expiration_date => "12/2009",
1312
- :billing_address => {
1313
- :first_name => "Joe",
1314
- :postal_code => "60622"
1315
- }
1316
- }
1317
- )
1318
- result.success?.should == true
1319
- original_customer = result.customer
1320
-
1321
- tr_data_params = {
1322
- :customer_id => original_customer.id,
1323
- :customer => {
1324
- :first_name => "New First",
1325
- :last_name => "New Last",
1326
- :company => "New Company",
1327
- :email => "new@email.com",
1328
- :phone => "888.111.2222",
1329
- :fax => "999.222.3333",
1330
- :website => "new.website.com",
1331
- :credit_card => {
1332
- :cardholder_name => "New Joe Cardholder",
1333
- :options => { :update_existing_token => original_customer.credit_cards.first.token },
1334
- :billing_address => {
1335
- :last_name => "Cool",
1336
- :postal_code => "60666",
1337
- :options => { :update_existing => true }
1338
- }
1339
- }
1340
- }
1341
- }
1342
-
1343
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1344
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.update_customer_url)
1345
- result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
1346
-
1347
- result.success?.should == true
1348
- customer = result.customer
1349
- customer.id.should == original_customer.id
1350
- customer.first_name.should == "New First"
1351
- customer.last_name.should == "New Last"
1352
- customer.company.should == "New Company"
1353
- customer.email.should == "new@email.com"
1354
- customer.phone.should == "888.111.2222"
1355
- customer.fax.should == "999.222.3333"
1356
- customer.website.should == "new.website.com"
1357
-
1358
- credit_card = customer.credit_cards.first
1359
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa.slice(0, 6)
1360
- credit_card.cardholder_name.should == "New Joe Cardholder"
1361
-
1362
- credit_card.billing_address.first_name.should == "Joe"
1363
- credit_card.billing_address.last_name.should == "Cool"
1364
- credit_card.billing_address.postal_code.should == "60666"
1365
- end
1366
-
1367
- it "can pass any attribute through tr_data" do
1368
- original_customer = Braintree::Customer.create!(
1369
- :first_name => "Old First",
1370
- :last_name => "Old Last",
1371
- :company => "Old Company",
1372
- :email => "old@email.com",
1373
- :phone => "000.111.2222",
1374
- :fax => "000.222.3333",
1375
- :website => "old.website.com"
1376
- )
1377
- new_customer_id = "customer_#{rand(1_000_000)}"
1378
- tr_data_params = {
1379
- :customer_id => original_customer.id,
1380
- :customer => {
1381
- :id => new_customer_id,
1382
- :first_name => "New First",
1383
- :last_name => "New Last",
1384
- :company => "New Company",
1385
- :email => "new@email.com",
1386
- :phone => "888.111.2222",
1387
- :fax => "999.222.3333",
1388
- :website => "new.website.com"
1389
- }
1390
- }
1391
-
1392
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1393
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.update_customer_url)
1394
- result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
1395
-
1396
- result.success?.should == true
1397
- customer = result.customer
1398
- customer.id.should == new_customer_id
1399
- customer.first_name.should == "New First"
1400
- customer.last_name.should == "New Last"
1401
- customer.company.should == "New Company"
1402
- customer.email.should == "new@email.com"
1403
- customer.phone.should == "888.111.2222"
1404
- customer.fax.should == "999.222.3333"
1405
- customer.website.should == "new.website.com"
1406
- end
1407
- end
1408
-
1409
- describe "default_credit_card" do
1695
+ describe "default_payment_method" do
1410
1696
  it "should return the default credit card for a given customer" do
1411
1697
  customer = Braintree::Customer.create!(
1412
1698
  :credit_card => {
@@ -1415,21 +1701,21 @@ describe Braintree::Customer do
1415
1701
  :options => {
1416
1702
  :make_default => false
1417
1703
  }
1418
- }
1704
+ },
1419
1705
  )
1420
1706
 
1421
- default_credit_card = Braintree::CreditCard.create!(
1707
+ default_payment_method = Braintree::CreditCard.create!(
1422
1708
  :customer_id => customer.id,
1423
1709
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1424
1710
  :expiration_date => "11/2015",
1425
1711
  :options => {
1426
1712
  :make_default => true
1427
- }
1713
+ },
1428
1714
  )
1429
1715
 
1430
1716
  customer = Braintree::Customer.find(customer.id)
1431
1717
 
1432
- customer.default_credit_card.should == default_credit_card
1718
+ customer.default_payment_method.should == default_payment_method
1433
1719
  end
1434
1720
  end
1435
1721
 
@@ -1437,7 +1723,7 @@ describe Braintree::Customer do
1437
1723
  context "future" do
1438
1724
  it "creates a customer with a future paypal account" do
1439
1725
  result = Braintree::Customer.create(
1440
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment
1726
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
1441
1727
  )
1442
1728
 
1443
1729
  result.should be_success
@@ -1451,7 +1737,7 @@ describe Braintree::Customer do
1451
1737
  :options => {
1452
1738
  :make_default => true
1453
1739
  }
1454
- }
1740
+ },
1455
1741
  )
1456
1742
 
1457
1743
  paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
@@ -1460,12 +1746,12 @@ describe Braintree::Customer do
1460
1746
  :token => paypal_account_token,
1461
1747
  :options => {
1462
1748
  :make_default => true
1463
- }
1749
+ },
1464
1750
  )
1465
1751
 
1466
1752
  result = Braintree::Customer.update(
1467
1753
  customer.id,
1468
- :payment_method_nonce => nonce
1754
+ :payment_method_nonce => nonce,
1469
1755
  )
1470
1756
 
1471
1757
  result.should be_success
@@ -1474,14 +1760,14 @@ describe Braintree::Customer do
1474
1760
  end
1475
1761
 
1476
1762
  context "limited use" do
1477
- it "creates a customer with payment_method_nonce and options->paypal->payee_email" do
1763
+ it "creates a customer with payment_method_nonce and paypal options" do
1478
1764
  paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
1479
1765
  nonce = nonce_for_paypal_account(
1480
1766
  :consent_code => "PAYPAL_CONSENT_CODE",
1481
1767
  :token => paypal_account_token,
1482
1768
  :options => {
1483
1769
  :make_default => true
1484
- }
1770
+ },
1485
1771
  )
1486
1772
 
1487
1773
  result = Braintree::Customer.create(
@@ -1489,6 +1775,19 @@ describe Braintree::Customer do
1489
1775
  :options => {
1490
1776
  :paypal => {
1491
1777
  :payee_email => "payee@example.com",
1778
+ :order_id => "merchant-order-id",
1779
+ :custom_field => "custom merchant field",
1780
+ :description => "merchant description",
1781
+ :amount => "1.23",
1782
+ :shipping => {
1783
+ :first_name => "first",
1784
+ :last_name => "last",
1785
+ :locality => "Austin",
1786
+ :postal_code => "78729",
1787
+ :street_address => "7700 W Parmer Ln",
1788
+ :country_name => "US",
1789
+ :region => "TX",
1790
+ },
1492
1791
  },
1493
1792
  },
1494
1793
  )
@@ -1496,7 +1795,7 @@ describe Braintree::Customer do
1496
1795
  result.should be_success
1497
1796
  end
1498
1797
 
1499
- it "updates a customer with payment_method_nonce and options->paypal->payee_email" do
1798
+ it "updates a customer with payment_method_nonce and paypal options" do
1500
1799
  customer = Braintree::Customer.create!(
1501
1800
  :credit_card => {
1502
1801
  :number => Braintree::Test::CreditCardNumbers::Visa,
@@ -1504,7 +1803,7 @@ describe Braintree::Customer do
1504
1803
  :options => {
1505
1804
  :make_default => true
1506
1805
  }
1507
- }
1806
+ },
1508
1807
  )
1509
1808
 
1510
1809
  paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
@@ -1513,7 +1812,7 @@ describe Braintree::Customer do
1513
1812
  :token => paypal_account_token,
1514
1813
  :options => {
1515
1814
  :make_default => true
1516
- }
1815
+ },
1517
1816
  )
1518
1817
 
1519
1818
  result = Braintree::Customer.update(
@@ -1522,6 +1821,19 @@ describe Braintree::Customer do
1522
1821
  :options => {
1523
1822
  :paypal => {
1524
1823
  :payee_email => "payee@example.com",
1824
+ :order_id => "merchant-order-id",
1825
+ :custom_field => "custom merchant field",
1826
+ :description => "merchant description",
1827
+ :amount => "1.23",
1828
+ :shipping => {
1829
+ :first_name => "first",
1830
+ :last_name => "last",
1831
+ :locality => "Austin",
1832
+ :postal_code => "78729",
1833
+ :street_address => "7700 W Parmer Ln",
1834
+ :country_name => "US",
1835
+ :region => "TX",
1836
+ },
1525
1837
  },
1526
1838
  },
1527
1839
  )
@@ -1534,7 +1846,7 @@ describe Braintree::Customer do
1534
1846
  context "onetime" do
1535
1847
  it "does not create a customer with a onetime paypal account" do
1536
1848
  result = Braintree::Customer.create(
1537
- :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment
1849
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
1538
1850
  )
1539
1851
 
1540
1852
  result.should_not be_success
@@ -1550,7 +1862,7 @@ describe Braintree::Customer do
1550
1862
  :options => {
1551
1863
  :make_default => true
1552
1864
  }
1553
- }
1865
+ },
1554
1866
  )
1555
1867
 
1556
1868
  paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
@@ -1559,12 +1871,12 @@ describe Braintree::Customer do
1559
1871
  :token => paypal_account_token,
1560
1872
  :options => {
1561
1873
  :make_default => true
1562
- }
1874
+ },
1563
1875
  )
1564
1876
 
1565
1877
  result = Braintree::Customer.update(
1566
1878
  customer.id,
1567
- :payment_method_nonce => nonce
1879
+ :payment_method_nonce => nonce,
1568
1880
  )
1569
1881
 
1570
1882
  result.should_not be_success