braintree 2.98.0 → 4.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +7 -4
  4. data/lib/braintree/account_updater_daily_report.rb +4 -4
  5. data/lib/braintree/ach_mandate.rb +1 -1
  6. data/lib/braintree/add_on_gateway.rb +1 -1
  7. data/lib/braintree/address.rb +7 -27
  8. data/lib/braintree/address_gateway.rb +8 -7
  9. data/lib/braintree/advanced_search.rb +11 -12
  10. data/lib/braintree/apple_pay.rb +4 -4
  11. data/lib/braintree/apple_pay_card.rb +18 -4
  12. data/lib/braintree/apple_pay_options.rb +4 -4
  13. data/lib/braintree/authorization_adjustment.rb +4 -4
  14. data/lib/braintree/base_module.rb +11 -1
  15. data/lib/braintree/bin_data.rb +10 -3
  16. data/lib/braintree/client_token.rb +1 -1
  17. data/lib/braintree/client_token_gateway.rb +4 -3
  18. data/lib/braintree/configuration.rb +35 -35
  19. data/lib/braintree/connected_merchant_paypal_status_changed.rb +2 -2
  20. data/lib/braintree/connected_merchant_status_transitioned.rb +2 -2
  21. data/lib/braintree/credit_card.rb +40 -86
  22. data/lib/braintree/credit_card_gateway.rb +58 -44
  23. data/lib/braintree/credit_card_verification.rb +39 -20
  24. data/lib/braintree/credit_card_verification_gateway.rb +35 -5
  25. data/lib/braintree/credit_card_verification_search.rb +2 -2
  26. data/lib/braintree/customer.rb +23 -88
  27. data/lib/braintree/customer_gateway.rb +17 -32
  28. data/lib/braintree/customer_search.rb +2 -2
  29. data/lib/braintree/descriptor.rb +1 -1
  30. data/lib/braintree/digest.rb +1 -1
  31. data/lib/braintree/disbursement.rb +7 -7
  32. data/lib/braintree/discount_gateway.rb +1 -1
  33. data/lib/braintree/dispute/evidence.rb +1 -1
  34. data/lib/braintree/{transaction/coinbase_details.rb → dispute/paypal_message.rb} +5 -6
  35. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  36. data/lib/braintree/dispute/transaction.rb +3 -1
  37. data/lib/braintree/dispute/transaction_details.rb +1 -1
  38. data/lib/braintree/dispute.rb +47 -6
  39. data/lib/braintree/dispute_gateway.rb +5 -10
  40. data/lib/braintree/dispute_search.rb +8 -4
  41. data/lib/braintree/document_upload.rb +3 -3
  42. data/lib/braintree/document_upload_gateway.rb +3 -3
  43. data/lib/braintree/enriched_customer_data.rb +21 -0
  44. data/lib/braintree/error_codes.rb +217 -175
  45. data/lib/braintree/error_result.rb +2 -3
  46. data/lib/braintree/errors.rb +3 -3
  47. data/lib/braintree/exceptions.rb +6 -5
  48. data/lib/braintree/exchange_rate.rb +13 -0
  49. data/lib/braintree/exchange_rate_quote.rb +24 -0
  50. data/lib/braintree/exchange_rate_quote_gateway.rb +35 -0
  51. data/lib/braintree/exchange_rate_quote_input.rb +21 -0
  52. data/lib/braintree/exchange_rate_quote_request.rb +18 -0
  53. data/lib/braintree/exchange_rate_quote_response.rb +18 -0
  54. data/lib/braintree/facilitated_details.rb +1 -1
  55. data/lib/braintree/facilitator_details.rb +1 -1
  56. data/lib/braintree/gateway.rb +6 -12
  57. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +18 -5
  58. data/lib/braintree/granted_payment_instrument_update.rb +2 -2
  59. data/lib/braintree/graphql_client.rb +14 -8
  60. data/lib/braintree/http.rb +9 -10
  61. data/lib/braintree/local_payment_completed/blik_alias.rb +23 -0
  62. data/lib/braintree/local_payment_completed.rb +10 -5
  63. data/lib/braintree/local_payment_expired.rb +21 -0
  64. data/lib/braintree/local_payment_funded.rb +22 -0
  65. data/lib/braintree/local_payment_reversed.rb +19 -0
  66. data/lib/braintree/merchant.rb +4 -4
  67. data/lib/braintree/merchant_account.rb +3 -3
  68. data/lib/braintree/merchant_account_gateway.rb +10 -8
  69. data/lib/braintree/merchant_gateway.rb +1 -1
  70. data/lib/braintree/meta_checkout_card.rb +89 -0
  71. data/lib/braintree/meta_checkout_token.rb +88 -0
  72. data/lib/braintree/modification.rb +4 -4
  73. data/lib/braintree/oauth_credentials.rb +4 -4
  74. data/lib/braintree/oauth_gateway.rb +5 -5
  75. data/lib/braintree/paginated_collection.rb +2 -2
  76. data/lib/braintree/paginated_result.rb +1 -1
  77. data/lib/braintree/payment_instrument_type.rb +14 -13
  78. data/lib/braintree/payment_method_customer_data_updated_metadata.rb +24 -0
  79. data/lib/braintree/payment_method_gateway.rb +52 -22
  80. data/lib/braintree/payment_method_nonce.rb +12 -7
  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 +14 -3
  84. data/lib/braintree/payment_method_parser.rb +4 -7
  85. data/lib/braintree/paypal_account.rb +3 -2
  86. data/lib/braintree/paypal_account_gateway.rb +5 -5
  87. data/lib/braintree/plan.rb +22 -2
  88. data/lib/braintree/plan_gateway.rb +101 -1
  89. data/lib/braintree/processor_response_types.rb +3 -3
  90. data/lib/braintree/resource_collection.rb +10 -5
  91. data/lib/braintree/revoked_payment_method_metadata.rb +2 -2
  92. data/lib/braintree/risk_data/liability_shift.rb +22 -0
  93. data/lib/braintree/risk_data.rb +10 -3
  94. data/lib/braintree/samsung_pay_card.rb +8 -6
  95. data/lib/braintree/sepa_direct_debit_account.rb +60 -0
  96. data/lib/braintree/sepa_direct_debit_account_gateway.rb +25 -0
  97. data/lib/braintree/sepa_direct_debit_account_nonce_details.rb +28 -0
  98. data/lib/braintree/settlement_batch_summary.rb +2 -2
  99. data/lib/braintree/settlement_batch_summary_gateway.rb +1 -1
  100. data/lib/braintree/sha256_digest.rb +1 -1
  101. data/lib/braintree/subscription/status_details.rb +1 -1
  102. data/lib/braintree/subscription.rb +13 -13
  103. data/lib/braintree/subscription_gateway.rb +6 -6
  104. data/lib/braintree/subscription_search.rb +1 -1
  105. data/lib/braintree/successful_result.rb +5 -4
  106. data/lib/braintree/test/authentication_id.rb +21 -0
  107. data/lib/braintree/test/credit_card.rb +9 -10
  108. data/lib/braintree/test/merchant_account.rb +1 -1
  109. data/lib/braintree/test/nonce.rb +27 -20
  110. data/lib/braintree/test/transaction_amounts.rb +2 -3
  111. data/lib/braintree/test/venmo_sdk.rb +2 -0
  112. data/lib/braintree/testing_gateway.rb +1 -1
  113. data/lib/braintree/three_d_secure_info.rb +23 -11
  114. data/lib/braintree/transaction/address_details.rb +14 -1
  115. data/lib/braintree/transaction/apple_pay_details.rb +13 -10
  116. data/lib/braintree/transaction/credit_card_details.rb +8 -1
  117. data/lib/braintree/transaction/customer_details.rb +3 -2
  118. data/lib/braintree/transaction/disbursement_details.rb +2 -1
  119. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +6 -1
  120. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  121. data/lib/braintree/transaction/installment.rb +28 -0
  122. data/lib/braintree/transaction/local_payment_details.rb +3 -0
  123. data/lib/braintree/transaction/meta_checkout_card_details.rb +52 -0
  124. data/lib/braintree/transaction/meta_checkout_token_details.rb +54 -0
  125. data/lib/braintree/transaction/package_details.rb +19 -0
  126. data/lib/braintree/transaction/payment_receipt/card_present_data.rb +36 -0
  127. data/lib/braintree/transaction/payment_receipt/merchant_address.rb +19 -0
  128. data/lib/braintree/transaction/payment_receipt.rb +31 -0
  129. data/lib/braintree/transaction/paypal_details.rb +5 -0
  130. data/lib/braintree/transaction/samsung_pay_card_details.rb +3 -1
  131. data/lib/braintree/transaction/sepa_direct_debit_account_details.rb +27 -0
  132. data/lib/braintree/transaction/status_details.rb +1 -1
  133. data/lib/braintree/transaction/subscription_details.rb +3 -1
  134. data/lib/braintree/transaction/us_bank_account_details.rb +2 -1
  135. data/lib/braintree/transaction/visa_checkout_card_details.rb +1 -1
  136. data/lib/braintree/transaction.rb +119 -128
  137. data/lib/braintree/transaction_gateway.rb +138 -64
  138. data/lib/braintree/transaction_line_item.rb +14 -11
  139. data/lib/braintree/transaction_line_item_gateway.rb +1 -1
  140. data/lib/braintree/transaction_review.rb +18 -0
  141. data/lib/braintree/transaction_search.rb +11 -7
  142. data/lib/braintree/unknown_payment_method.rb +2 -2
  143. data/lib/braintree/us_bank_account.rb +5 -5
  144. data/lib/braintree/us_bank_account_verification.rb +24 -16
  145. data/lib/braintree/us_bank_account_verification_gateway.rb +1 -1
  146. data/lib/braintree/us_bank_account_verification_search.rb +1 -1
  147. data/lib/braintree/util.rb +25 -10
  148. data/lib/braintree/validation_error.rb +1 -1
  149. data/lib/braintree/validation_error_collection.rb +3 -3
  150. data/lib/braintree/venmo_account.rb +4 -4
  151. data/lib/braintree/venmo_profile_data.rb +25 -0
  152. data/lib/braintree/version.rb +2 -2
  153. data/lib/braintree/visa_checkout_card.rb +8 -8
  154. data/lib/braintree/webhook_notification.rb +55 -33
  155. data/lib/braintree/webhook_notification_gateway.rb +9 -9
  156. data/lib/braintree/webhook_testing.rb +1 -1
  157. data/lib/braintree/webhook_testing_gateway.rb +569 -46
  158. data/lib/braintree/xml/generator.rb +6 -5
  159. data/lib/braintree/xml/libxml.rb +1 -1
  160. data/lib/braintree/xml/parser.rb +24 -37
  161. data/lib/braintree/xml/rexml.rb +6 -7
  162. data/lib/braintree/xml.rb +1 -1
  163. data/lib/braintree.rb +41 -24
  164. data/lib/ssl/api_braintreegateway_com.ca.crt +401 -168
  165. data/spec/integration/braintree/add_on_spec.rb +10 -10
  166. data/spec/integration/braintree/address_spec.rb +101 -178
  167. data/spec/integration/braintree/advanced_search_spec.rb +93 -93
  168. data/spec/integration/braintree/apple_pay_spec.rb +12 -12
  169. data/spec/integration/braintree/braintree_gateway_spec.rb +2 -1
  170. data/spec/integration/braintree/client_api/client_token_spec.rb +279 -62
  171. data/spec/integration/braintree/client_api/spec_helper.rb +99 -73
  172. data/spec/integration/braintree/credit_card_spec.rb +522 -821
  173. data/spec/integration/braintree/credit_card_verification_search_spec.rb +18 -18
  174. data/spec/integration/braintree/credit_card_verification_spec.rb +219 -30
  175. data/spec/integration/braintree/customer_search_spec.rb +28 -28
  176. data/spec/integration/braintree/customer_spec.rb +840 -757
  177. data/spec/integration/braintree/disbursement_spec.rb +2 -2
  178. data/spec/integration/braintree/discount_spec.rb +9 -9
  179. data/spec/integration/braintree/dispute_search_spec.rb +45 -9
  180. data/spec/integration/braintree/dispute_spec.rb +109 -82
  181. data/spec/integration/braintree/document_upload_spec.rb +29 -17
  182. data/spec/integration/braintree/error_codes_spec.rb +3 -3
  183. data/spec/integration/braintree/exchange_rate_quote_spec.rb +97 -0
  184. data/spec/integration/braintree/graphql_client_spec.rb +0 -2
  185. data/spec/integration/braintree/http_spec.rb +31 -33
  186. data/spec/integration/braintree/merchant_account_spec.rb +155 -156
  187. data/spec/integration/braintree/merchant_spec.rb +71 -192
  188. data/spec/integration/braintree/oauth_spec.rb +72 -72
  189. data/spec/integration/braintree/package_tracking_spec.rb +130 -0
  190. data/spec/integration/braintree/payment_method_nonce_spec.rb +173 -78
  191. data/spec/integration/braintree/payment_method_spec.rb +953 -501
  192. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +147 -234
  193. data/spec/integration/braintree/paypal_account_spec.rb +74 -72
  194. data/spec/integration/braintree/plan_spec.rb +96 -15
  195. data/spec/integration/braintree/samsung_pay_card_spec.rb +75 -73
  196. data/spec/integration/braintree/sepa_direct_debit_account_spec.rb +194 -0
  197. data/spec/integration/braintree/settlement_batch_summary_spec.rb +18 -18
  198. data/spec/integration/braintree/subscription_spec.rb +507 -513
  199. data/spec/integration/braintree/test/transaction_amounts_spec.rb +4 -4
  200. data/spec/integration/braintree/test_transaction_spec.rb +29 -29
  201. data/spec/integration/braintree/transaction_line_item_spec.rb +12 -6
  202. data/spec/integration/braintree/transaction_search_spec.rb +410 -217
  203. data/spec/integration/braintree/transaction_spec.rb +3252 -2102
  204. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +42 -278
  205. data/spec/integration/braintree/us_bank_account_spec.rb +36 -36
  206. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +25 -25
  207. data/spec/integration/braintree/us_bank_account_verification_spec.rb +41 -41
  208. data/spec/integration/braintree/visa_checkout_card_spec.rb +62 -62
  209. data/spec/integration/spec_helper.rb +22 -7
  210. data/spec/oauth_test_helper.rb +1 -1
  211. data/spec/script/httpsd.rb +6 -6
  212. data/spec/spec_helper.rb +15 -20
  213. data/spec/unit/braintree/address_spec.rb +9 -17
  214. data/spec/unit/braintree/apple_pay_card_spec.rb +110 -7
  215. data/spec/unit/braintree/base_module_spec.rb +4 -4
  216. data/spec/unit/braintree/client_token_spec.rb +6 -6
  217. data/spec/unit/braintree/configuration_spec.rb +84 -84
  218. data/spec/unit/braintree/credentials_parser_spec.rb +6 -6
  219. data/spec/unit/braintree/credit_card_spec.rb +91 -58
  220. data/spec/unit/braintree/credit_card_verification_gateway_spec.rb +56 -0
  221. data/spec/unit/braintree/credit_card_verification_search_spec.rb +10 -10
  222. data/spec/unit/braintree/credit_card_verification_spec.rb +40 -18
  223. data/spec/unit/braintree/customer_spec.rb +102 -57
  224. data/spec/unit/braintree/digest_spec.rb +5 -6
  225. data/spec/unit/braintree/disbursement_spec.rb +14 -14
  226. data/spec/unit/braintree/dispute_search_spec.rb +6 -2
  227. data/spec/unit/braintree/dispute_spec.rb +144 -66
  228. data/spec/unit/braintree/document_upload_spec.rb +8 -8
  229. data/spec/unit/braintree/enriched_customer_data_spec.rb +41 -0
  230. data/spec/unit/braintree/error_result_spec.rb +11 -11
  231. data/spec/unit/braintree/errors_spec.rb +17 -17
  232. data/spec/unit/braintree/exchange_rate_quote_input_spec.rb +42 -0
  233. data/spec/unit/braintree/exchange_rate_quote_request_spec.rb +82 -0
  234. data/spec/unit/braintree/exchange_rate_quote_response_spec.rb +52 -0
  235. data/spec/unit/braintree/exchange_rate_quote_spec.rb +42 -0
  236. data/spec/unit/braintree/exchange_rate_spec.rb +23 -0
  237. data/spec/unit/braintree/http_spec.rb +19 -17
  238. data/spec/unit/braintree/local_payment_completed_spec.rb +62 -8
  239. data/spec/unit/braintree/local_payment_expired_spec.rb +24 -0
  240. data/spec/unit/braintree/local_payment_funded_spec.rb +34 -0
  241. data/spec/unit/braintree/merchant_account_spec.rb +5 -5
  242. data/spec/unit/braintree/meta_checkout_card_details_spec.rb +60 -0
  243. data/spec/unit/braintree/meta_checkout_card_spec.rb +60 -0
  244. data/spec/unit/braintree/meta_checkout_token_details_spec.rb +63 -0
  245. data/spec/unit/braintree/meta_checkout_token_spec.rb +63 -0
  246. data/spec/unit/braintree/modification_spec.rb +1 -1
  247. data/spec/unit/braintree/package_tracking_spec.rb +77 -0
  248. data/spec/unit/braintree/payment_method_customer_data_updated_metadata_spec.rb +45 -0
  249. data/spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb +31 -0
  250. data/spec/unit/braintree/payment_method_nonce_details_spec.rb +51 -0
  251. data/spec/unit/braintree/payment_method_nonce_spec.rb +40 -0
  252. data/spec/unit/braintree/payment_method_spec.rb +20 -20
  253. data/spec/unit/braintree/paypal_account_spec.rb +16 -7
  254. data/spec/unit/braintree/resource_collection_spec.rb +34 -5
  255. data/spec/unit/braintree/risk_data/liability_shift.rb +26 -0
  256. data/spec/unit/braintree/risk_data_spec.rb +38 -8
  257. data/spec/unit/braintree/sepa_debit_account_nonce_details_spec.rb +29 -0
  258. data/spec/unit/braintree/sepa_debit_account_spec.rb +86 -0
  259. data/spec/unit/braintree/sha256_digest_spec.rb +1 -1
  260. data/spec/unit/braintree/signature_service_spec.rb +2 -2
  261. data/spec/unit/braintree/subscription_search_spec.rb +18 -18
  262. data/spec/unit/braintree/subscription_spec.rb +8 -8
  263. data/spec/unit/braintree/successful_result_spec.rb +6 -6
  264. data/spec/unit/braintree/three_d_secure_info_spec.rb +37 -17
  265. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +22 -6
  266. data/spec/unit/braintree/transaction/customer_details_spec.rb +3 -2
  267. data/spec/unit/braintree/transaction/deposit_details_spec.rb +4 -4
  268. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  269. data/spec/unit/braintree/transaction/local_payment_details_spec.rb +36 -0
  270. data/spec/unit/braintree/transaction/payment_receipt_spec.rb +73 -0
  271. data/spec/unit/braintree/transaction/paypal_details_spec.rb +63 -0
  272. data/spec/unit/braintree/transaction/sepa_direct_debit_account_details_spec.rb +33 -0
  273. data/spec/unit/braintree/transaction_gateway_spec.rb +150 -0
  274. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  275. data/spec/unit/braintree/transaction_spec.rb +221 -124
  276. data/spec/unit/braintree/unknown_payment_method_spec.rb +4 -4
  277. data/spec/unit/braintree/us_bank_account_spec.rb +2 -2
  278. data/spec/unit/braintree/us_bank_account_verification_search_spec.rb +7 -7
  279. data/spec/unit/braintree/us_bank_account_verification_spec.rb +12 -7
  280. data/spec/unit/braintree/util_spec.rb +78 -44
  281. data/spec/unit/braintree/validation_error_collection_spec.rb +62 -62
  282. data/spec/unit/braintree/validation_error_spec.rb +4 -4
  283. data/spec/unit/braintree/venmo_profile_data_spec.rb +43 -0
  284. data/spec/unit/braintree/webhook_notification_spec.rb +434 -197
  285. data/spec/unit/braintree/xml/libxml_spec.rb +5 -5
  286. data/spec/unit/braintree/xml/parser_spec.rb +27 -22
  287. data/spec/unit/braintree/xml/rexml_spec.rb +5 -5
  288. data/spec/unit/braintree/xml_spec.rb +38 -38
  289. data/spec/unit/braintree_spec.rb +2 -2
  290. metadata +91 -30
  291. data/lib/braintree/amex_express_checkout_card.rb +0 -38
  292. data/lib/braintree/coinbase_account.rb +0 -34
  293. data/lib/braintree/europe_bank_account.rb +0 -36
  294. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  295. data/lib/braintree/ideal_payment.rb +0 -61
  296. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  297. data/lib/braintree/masterpass_card.rb +0 -81
  298. data/lib/braintree/settlement_batch.rb +0 -0
  299. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  300. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  301. data/lib/braintree/transaction/masterpass_card_details.rb +0 -47
  302. data/lib/braintree/transparent_redirect.rb +0 -40
  303. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  304. data/spec/hacks/tcp_socket.rb +0 -18
  305. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  306. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  307. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  308. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
@@ -17,28 +17,28 @@ describe Braintree::PaymentMethod do
17
17
  config,
18
18
  :authorization_fingerprint => authorization_fingerprint,
19
19
  :shared_customer_identifier => "fake_identifier",
20
- :shared_customer_identifier_type => "testing"
20
+ :shared_customer_identifier_type => "testing",
21
21
  )
22
22
 
23
23
  response = http.create_credit_card(
24
24
  :number => 4111111111111111,
25
25
  :expirationMonth => 12,
26
- :expirationYear => 2020
26
+ :expirationYear => 2020,
27
27
  )
28
- response.code.should == "201"
28
+ expect(response.code).to eq("201")
29
29
 
30
30
  nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
31
31
  result = Braintree::PaymentMethod.create(
32
32
  :payment_method_nonce => nonce,
33
- :customer_id => customer.id
33
+ :customer_id => customer.id,
34
34
  )
35
35
 
36
- result.should be_success
37
- result.payment_method.should be_a(Braintree::CreditCard)
36
+ expect(result).to be_success
37
+ expect(result.payment_method).to be_a(Braintree::CreditCard)
38
38
  token = result.payment_method.token
39
39
 
40
40
  found_credit_card = Braintree::CreditCard.find(token)
41
- found_credit_card.should_not be_nil
41
+ expect(found_credit_card).not_to be_nil
42
42
  end
43
43
 
44
44
  it "creates a payment method from an unvalidated credit card nonce" do
@@ -51,29 +51,29 @@ describe Braintree::PaymentMethod do
51
51
  config,
52
52
  :authorization_fingerprint => authorization_fingerprint,
53
53
  :shared_customer_identifier => "fake_identifier",
54
- :shared_customer_identifier_type => "testing"
54
+ :shared_customer_identifier_type => "testing",
55
55
  )
56
56
 
57
57
  response = http.create_credit_card(
58
58
  :number => "4111111111111111",
59
59
  :expirationMonth => "12",
60
60
  :expirationYear => "2020",
61
- :options => {:validate => false}
61
+ :options => {:validate => false},
62
62
  )
63
- response.code.should == "202"
63
+ expect(response.code).to eq("202")
64
64
 
65
65
  nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
66
66
  result = Braintree::PaymentMethod.create(
67
67
  :payment_method_nonce => nonce,
68
- :customer_id => customer.id
68
+ :customer_id => customer.id,
69
69
  )
70
70
 
71
- result.should be_success
72
- result.payment_method.should be_a(Braintree::CreditCard)
71
+ expect(result).to be_success
72
+ expect(result.payment_method).to be_a(Braintree::CreditCard)
73
73
  token = result.payment_method.token
74
74
 
75
75
  found_credit_card = Braintree::CreditCard.find(token)
76
- found_credit_card.should_not be_nil
76
+ expect(found_credit_card).not_to be_nil
77
77
  end
78
78
 
79
79
  it "creates a payment method from a fake apple pay nonce" do
@@ -82,104 +82,142 @@ describe Braintree::PaymentMethod do
82
82
  result = Braintree::PaymentMethod.create(
83
83
  :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
84
84
  :customer_id => customer.id,
85
- :token => token
85
+ :token => token,
86
86
  )
87
87
 
88
- result.should be_success
88
+ expect(result).to be_success
89
89
  apple_pay_card = result.payment_method
90
- apple_pay_card.should be_a(Braintree::ApplePayCard)
91
- apple_pay_card.should_not be_nil
92
- apple_pay_card.bin.should_not be_nil
93
- apple_pay_card.token.should == token
94
- apple_pay_card.card_type.should == Braintree::ApplePayCard::CardType::AmEx
95
- apple_pay_card.payment_instrument_name.should == "AmEx 41002"
96
- apple_pay_card.source_description.should == "AmEx 41002"
97
- apple_pay_card.default.should == true
98
- apple_pay_card.image_url.should =~ /apple_pay/
99
- apple_pay_card.expiration_month.to_i.should > 0
100
- apple_pay_card.expiration_year.to_i.should > 0
101
- apple_pay_card.customer_id.should == customer.id
90
+ expect(apple_pay_card).to be_a(Braintree::ApplePayCard)
91
+ expect(apple_pay_card).not_to be_nil
92
+ expect(apple_pay_card.bin).not_to be_nil
93
+ expect(apple_pay_card.token).to eq(token)
94
+ expect(apple_pay_card.card_type).to eq(Braintree::ApplePayCard::CardType::AmEx)
95
+ expect(apple_pay_card.payment_instrument_name).to eq("AmEx 41002")
96
+ expect(apple_pay_card.source_description).to eq("AmEx 41002")
97
+ expect(apple_pay_card.default).to eq(true)
98
+ expect(apple_pay_card.image_url).to match(/apple_pay/)
99
+ expect(apple_pay_card.expiration_month.to_i).to be > 0
100
+ expect(apple_pay_card.expiration_year.to_i).to be > 0
101
+ expect(apple_pay_card.customer_id).to eq(customer.id)
102
+ expect(apple_pay_card.commercial).not_to be_nil
103
+ expect(apple_pay_card.country_of_issuance).not_to be_nil
104
+ expect(apple_pay_card.debit).not_to be_nil
105
+ expect(apple_pay_card.durbin_regulated).not_to be_nil
106
+ expect(apple_pay_card.healthcare).not_to be_nil
107
+ expect(apple_pay_card.issuing_bank).not_to be_nil
108
+ expect(apple_pay_card.payroll).not_to be_nil
109
+ expect(apple_pay_card.prepaid).not_to be_nil
110
+ expect(apple_pay_card.product_id).not_to be_nil
102
111
  end
103
112
 
104
- it "creates a payment method from a fake android pay proxy card nonce" do
113
+ it "creates a payment method from a fake apple pay mpan nonce" do
105
114
  customer = Braintree::Customer.create.customer
106
115
  token = SecureRandom.hex(16)
107
116
  result = Braintree::PaymentMethod.create(
108
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover,
117
+ :payment_method_nonce => Braintree::Test::Nonce::ApplePayMpan,
109
118
  :customer_id => customer.id,
110
- :token => token
119
+ :token => token,
111
120
  )
112
121
 
113
- result.should be_success
114
- android_pay_card = result.payment_method
115
- android_pay_card.should be_a(Braintree::AndroidPayCard)
116
- android_pay_card.should_not be_nil
117
- android_pay_card.token.should == token
118
- android_pay_card.card_type.should == Braintree::CreditCard::CardType::Discover
119
- android_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
120
- android_pay_card.expiration_month.to_i.should > 0
121
- android_pay_card.expiration_year.to_i.should > 0
122
- android_pay_card.default.should == true
123
- android_pay_card.image_url.should =~ /android_pay/
124
- android_pay_card.source_card_type.should == Braintree::CreditCard::CardType::Discover
125
- android_pay_card.source_card_last_4.should == "1111"
126
- android_pay_card.google_transaction_id.should == "google_transaction_id"
127
- android_pay_card.source_description.should == "Discover 1111"
128
- android_pay_card.customer_id.should == customer.id
122
+ expect(result).to be_success
123
+ apple_pay_card = result.payment_method
124
+ expect(apple_pay_card).to be_a(Braintree::ApplePayCard)
125
+ expect(apple_pay_card).not_to be_nil
126
+ expect(apple_pay_card.bin).not_to be_nil
127
+ expect(apple_pay_card.token).to eq(token)
128
+ expect(apple_pay_card.card_type).to eq(Braintree::ApplePayCard::CardType::Visa)
129
+ expect(apple_pay_card.payment_instrument_name).to eq("Visa 8886")
130
+ expect(apple_pay_card.source_description).to eq("Visa 8886")
131
+ expect(apple_pay_card.default).to eq(true)
132
+ expect(apple_pay_card.image_url).to match(/apple_pay/)
133
+ expect(apple_pay_card.expiration_month.to_i).to be > 0
134
+ expect(apple_pay_card.expiration_year.to_i).to be > 0
135
+ expect(apple_pay_card.customer_id).to eq(customer.id)
136
+ expect(apple_pay_card.commercial).not_to be_nil
137
+ expect(apple_pay_card.country_of_issuance).not_to be_nil
138
+ expect(apple_pay_card.debit).not_to be_nil
139
+ expect(apple_pay_card.durbin_regulated).not_to be_nil
140
+ expect(apple_pay_card.healthcare).not_to be_nil
141
+ expect(apple_pay_card.issuing_bank).not_to be_nil
142
+ expect(apple_pay_card.payroll).not_to be_nil
143
+ expect(apple_pay_card.prepaid).not_to be_nil
144
+ expect(apple_pay_card.product_id).not_to be_nil
145
+ expect(apple_pay_card.merchant_token_identifier).not_to be_nil
146
+ expect(apple_pay_card.source_card_last4).not_to be_nil
129
147
  end
130
148
 
131
- it "creates a payment method from a android pay network token nonce" do
149
+ it "creates a payment method from a fake google pay proxy card nonce" do
132
150
  customer = Braintree::Customer.create.customer
133
151
  token = SecureRandom.hex(16)
134
152
  result = Braintree::PaymentMethod.create(
135
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayMasterCard,
153
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
136
154
  :customer_id => customer.id,
137
- :token => token
155
+ :token => token,
138
156
  )
139
157
 
140
- result.should be_success
141
- android_pay_card = result.payment_method
142
- android_pay_card.should be_a(Braintree::AndroidPayCard)
143
- android_pay_card.should_not be_nil
144
- android_pay_card.token.should == token
145
- android_pay_card.card_type.should == Braintree::CreditCard::CardType::MasterCard
146
- android_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
147
- android_pay_card.expiration_month.to_i.should > 0
148
- android_pay_card.expiration_year.to_i.should > 0
149
- android_pay_card.default.should == true
150
- android_pay_card.image_url.should =~ /android_pay/
151
- android_pay_card.source_card_type.should == Braintree::CreditCard::CardType::MasterCard
152
- android_pay_card.source_card_last_4.should == "4444"
153
- android_pay_card.google_transaction_id.should == "google_transaction_id"
154
- android_pay_card.source_description.should == "MasterCard 4444"
155
- android_pay_card.customer_id.should == customer.id
158
+ expect(result).to be_success
159
+ google_pay_card = result.payment_method
160
+ expect(google_pay_card).to be_a(Braintree::GooglePayCard)
161
+ expect(google_pay_card).not_to be_nil
162
+ expect(google_pay_card.token).to eq(token)
163
+ expect(google_pay_card.card_type).to eq(Braintree::CreditCard::CardType::Discover)
164
+ expect(google_pay_card.virtual_card_type).to eq(Braintree::CreditCard::CardType::Discover)
165
+ expect(google_pay_card.expiration_month.to_i).to be > 0
166
+ expect(google_pay_card.expiration_year.to_i).to be > 0
167
+ expect(google_pay_card.default).to eq(true)
168
+ expect(google_pay_card.image_url).to match(/android_pay/)
169
+ expect(google_pay_card.is_network_tokenized?).to eq(false)
170
+ expect(google_pay_card.source_card_type).to eq(Braintree::CreditCard::CardType::Discover)
171
+ expect(google_pay_card.source_card_last_4).to eq("1111")
172
+ expect(google_pay_card.google_transaction_id).to eq("google_transaction_id")
173
+ expect(google_pay_card.source_description).to eq("Discover 1111")
174
+ expect(google_pay_card.customer_id).to eq(customer.id)
175
+ expect(google_pay_card.commercial).not_to be_nil
176
+ expect(google_pay_card.country_of_issuance).not_to be_nil
177
+ expect(google_pay_card.debit).not_to be_nil
178
+ expect(google_pay_card.durbin_regulated).not_to be_nil
179
+ expect(google_pay_card.healthcare).not_to be_nil
180
+ expect(google_pay_card.issuing_bank).not_to be_nil
181
+ expect(google_pay_card.payroll).not_to be_nil
182
+ expect(google_pay_card.prepaid).not_to be_nil
183
+ expect(google_pay_card.product_id).not_to be_nil
156
184
  end
157
185
 
158
- it "creates a payment method from an amex express checkout card nonce" do
186
+ it "creates a payment method from a google pay network token nonce" do
159
187
  customer = Braintree::Customer.create.customer
160
188
  token = SecureRandom.hex(16)
161
189
  result = Braintree::PaymentMethod.create(
162
- :payment_method_nonce => Braintree::Test::Nonce::AmexExpressCheckout,
190
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
163
191
  :customer_id => customer.id,
164
- :token => token
192
+ :token => token,
165
193
  )
166
194
 
167
- result.should be_success
168
- amex_express_checkout_card = result.payment_method
169
- amex_express_checkout_card.should be_a(Braintree::AmexExpressCheckoutCard)
170
- amex_express_checkout_card.should_not be_nil
171
-
172
- amex_express_checkout_card.default.should == true
173
- amex_express_checkout_card.card_type.should == "American Express"
174
- amex_express_checkout_card.token.should == token
175
- amex_express_checkout_card.bin.should =~ /\A\d{6}\z/
176
- amex_express_checkout_card.expiration_month.should =~ /\A\d{2}\z/
177
- amex_express_checkout_card.expiration_year.should =~ /\A\d{4}\z/
178
- amex_express_checkout_card.card_member_number.should =~ /\A\d{4}\z/
179
- amex_express_checkout_card.card_member_expiry_date.should =~ /\A\d{2}\/\d{2}\z/
180
- amex_express_checkout_card.image_url.should include(".png")
181
- amex_express_checkout_card.source_description.should =~ /\AAmEx \d{4}\z/
182
- amex_express_checkout_card.customer_id.should == customer.id
195
+ expect(result).to be_success
196
+ google_pay_card = result.payment_method
197
+ expect(google_pay_card).to be_a(Braintree::GooglePayCard)
198
+ expect(google_pay_card).not_to be_nil
199
+ expect(google_pay_card.token).to eq(token)
200
+ expect(google_pay_card.card_type).to eq(Braintree::CreditCard::CardType::MasterCard)
201
+ expect(google_pay_card.virtual_card_type).to eq(Braintree::CreditCard::CardType::MasterCard)
202
+ expect(google_pay_card.expiration_month.to_i).to be > 0
203
+ expect(google_pay_card.expiration_year.to_i).to be > 0
204
+ expect(google_pay_card.default).to eq(true)
205
+ expect(google_pay_card.image_url).to match(/android_pay/)
206
+ expect(google_pay_card.is_network_tokenized?).to eq(true)
207
+ expect(google_pay_card.source_card_type).to eq(Braintree::CreditCard::CardType::MasterCard)
208
+ expect(google_pay_card.source_card_last_4).to eq("4444")
209
+ expect(google_pay_card.google_transaction_id).to eq("google_transaction_id")
210
+ expect(google_pay_card.source_description).to eq("MasterCard 4444")
211
+ expect(google_pay_card.customer_id).to eq(customer.id)
212
+ expect(google_pay_card.commercial).not_to be_nil
213
+ expect(google_pay_card.country_of_issuance).not_to be_nil
214
+ expect(google_pay_card.debit).not_to be_nil
215
+ expect(google_pay_card.durbin_regulated).not_to be_nil
216
+ expect(google_pay_card.healthcare).not_to be_nil
217
+ expect(google_pay_card.issuing_bank).not_to be_nil
218
+ expect(google_pay_card.payroll).not_to be_nil
219
+ expect(google_pay_card.prepaid).not_to be_nil
220
+ expect(google_pay_card.product_id).not_to be_nil
183
221
  end
184
222
 
185
223
  it "creates a payment method from venmo account nonce" do
@@ -188,20 +226,20 @@ describe Braintree::PaymentMethod do
188
226
  result = Braintree::PaymentMethod.create(
189
227
  :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
190
228
  :customer_id => customer.id,
191
- :token => token
229
+ :token => token,
192
230
  )
193
231
 
194
- result.should be_success
232
+ expect(result).to be_success
195
233
  venmo_account = result.payment_method
196
- venmo_account.should be_a(Braintree::VenmoAccount)
197
-
198
- venmo_account.default.should == true
199
- venmo_account.token.should == token
200
- venmo_account.username.should == "venmojoe"
201
- venmo_account.venmo_user_id.should == "Venmo-Joe-1"
202
- venmo_account.image_url.should include(".png")
203
- venmo_account.source_description.should == "Venmo Account: venmojoe"
204
- venmo_account.customer_id.should == customer.id
234
+ expect(venmo_account).to be_a(Braintree::VenmoAccount)
235
+
236
+ expect(venmo_account.default).to eq(true)
237
+ expect(venmo_account.token).to eq(token)
238
+ expect(venmo_account.username).to eq("venmojoe")
239
+ expect(venmo_account.venmo_user_id).to eq("1234567891234567891")
240
+ expect(venmo_account.image_url).to include(".png")
241
+ expect(venmo_account.source_description).to eq("Venmo Account: venmojoe")
242
+ expect(venmo_account.customer_id).to eq(customer.id)
205
243
  end
206
244
 
207
245
  it "allows passing the make_default option alongside the nonce" do
@@ -210,22 +248,22 @@ describe Braintree::PaymentMethod do
210
248
  :customer_id => customer.id,
211
249
  :number => Braintree::Test::CreditCardNumbers::Visa,
212
250
  :expiration_date => "05/2009",
213
- :cvv => "100"
251
+ :cvv => "100",
214
252
  )
215
- result.success?.should == true
253
+ expect(result.success?).to eq(true)
216
254
  original_payment_method = result.credit_card
217
- original_payment_method.should be_default
255
+ expect(original_payment_method).to be_default
218
256
 
219
257
  nonce = nonce_for_paypal_account(:consent_code => "PAYPAL_CONSENT_CODE")
220
258
  result = Braintree::PaymentMethod.create(
221
259
  :payment_method_nonce => nonce,
222
260
  :customer_id => customer.id,
223
- :options => {:make_default => true}
261
+ :options => {:make_default => true},
224
262
  )
225
263
 
226
- result.should be_success
264
+ expect(result).to be_success
227
265
  new_payment_method = result.payment_method
228
- new_payment_method.should be_default
266
+ expect(new_payment_method).to be_default
229
267
  end
230
268
 
231
269
  it "overrides the token in the nonce" do
@@ -235,17 +273,17 @@ describe Braintree::PaymentMethod do
235
273
  second_token = make_token
236
274
  nonce = nonce_for_paypal_account(
237
275
  :consent_code => "PAYPAL_CONSENT_CODE",
238
- :token => first_token
276
+ :token => first_token,
239
277
  )
240
278
  result = Braintree::PaymentMethod.create(
241
279
  :payment_method_nonce => nonce,
242
280
  :customer_id => customer.id,
243
- :token => second_token
281
+ :token => second_token,
244
282
  )
245
283
 
246
- result.should be_success
284
+ expect(result).to be_success
247
285
  payment_method = result.payment_method
248
- payment_method.token.should == second_token
286
+ expect(payment_method.token).to eq(second_token)
249
287
  end
250
288
 
251
289
  it "respects verify_card and verification_merchant_account_id when included outside of the nonce" do
@@ -254,7 +292,7 @@ describe Braintree::PaymentMethod do
254
292
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
255
293
  :expiration_month => "11",
256
294
  :expiration_year => "2099",
257
- }
295
+ },
258
296
  )
259
297
  customer = Braintree::Customer.create!
260
298
  result = Braintree::PaymentMethod.create(
@@ -263,14 +301,14 @@ describe Braintree::PaymentMethod do
263
301
  :options => {
264
302
  :verify_card => true,
265
303
  :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
266
- }
304
+ },
267
305
  )
268
306
 
269
- result.should_not be_success
270
- result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
271
- result.credit_card_verification.processor_response_code.should == "2000"
272
- result.credit_card_verification.processor_response_text.should == "Do Not Honor"
273
- result.credit_card_verification.merchant_account_id.should == SpecHelper::NonDefaultMerchantAccountId
307
+ expect(result).not_to be_success
308
+ expect(result.credit_card_verification.status).to eq(Braintree::Transaction::Status::ProcessorDeclined)
309
+ expect(result.credit_card_verification.processor_response_code).to eq("2000")
310
+ expect(result.credit_card_verification.processor_response_text).to eq("Do Not Honor")
311
+ expect(result.credit_card_verification.merchant_account_id).to eq(SpecHelper::NonDefaultMerchantAccountId)
274
312
  end
275
313
 
276
314
  it "respects verification amount when included outside of the nonce" do
@@ -279,7 +317,7 @@ describe Braintree::PaymentMethod do
279
317
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
280
318
  :expiration_month => "11",
281
319
  :expiration_year => "2099",
282
- }
320
+ },
283
321
  )
284
322
  customer = Braintree::Customer.create!
285
323
  result = Braintree::PaymentMethod.create(
@@ -288,14 +326,58 @@ describe Braintree::PaymentMethod do
288
326
  :options => {
289
327
  :verify_card => true,
290
328
  :verification_amount => "100.00"
291
- }
329
+ },
330
+ )
331
+
332
+ expect(result).not_to be_success
333
+ expect(result.credit_card_verification.status).to eq(Braintree::Transaction::Status::ProcessorDeclined)
334
+ expect(result.credit_card_verification.processor_response_code).to eq("2000")
335
+ expect(result.credit_card_verification.processor_response_text).to eq("Do Not Honor")
336
+ expect(result.credit_card_verification.amount).to eq(BigDecimal("100.00"))
337
+ end
338
+
339
+ it "validates presence of three_d_secure_version in 3ds pass thru params" do
340
+ customer = Braintree::Customer.create!
341
+ result = Braintree::PaymentMethod.create(
342
+ :customer_id => customer.id,
343
+ :payment_method_nonce => Braintree::Test::Nonce::Transactable,
344
+ :three_d_secure_pass_thru => {
345
+ :eci_flag => "05",
346
+ :cavv => "some_cavv",
347
+ :xid => "some_xid",
348
+ :three_d_secure_version => "xx",
349
+ :authentication_response => "Y",
350
+ :directory_response => "Y",
351
+ :cavv_algorithm => "2",
352
+ :ds_transaction_id => "some_ds_transaction_id",
353
+ },
354
+ :options => {:verify_card => true},
355
+ )
356
+ expect(result).not_to be_success
357
+ error = result.errors.for(:verification).first
358
+ expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsInvalid)
359
+ 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`).")
360
+ end
361
+
362
+ it "accepts three_d_secure pass thru params in the request" do
363
+ customer = Braintree::Customer.create!
364
+ result = Braintree::PaymentMethod.create(
365
+ :customer_id => customer.id,
366
+ :payment_method_nonce => Braintree::Test::Nonce::Transactable,
367
+ :three_d_secure_pass_thru => {
368
+ :eci_flag => "05",
369
+ :cavv => "some_cavv",
370
+ :xid => "some_xid",
371
+ :three_d_secure_version => "1.0.2",
372
+ :authentication_response => "Y",
373
+ :directory_response => "Y",
374
+ :cavv_algorithm => "2",
375
+ :ds_transaction_id => "some_ds_transaction_id",
376
+ },
377
+ :options => {:verify_card => true},
292
378
  )
293
379
 
294
- result.should_not be_success
295
- result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
296
- result.credit_card_verification.processor_response_code.should == "2000"
297
- result.credit_card_verification.processor_response_text.should == "Do Not Honor"
298
- result.credit_card_verification.amount.should == BigDecimal("100.00")
380
+ expect(result).to be_success
299
381
  end
300
382
 
301
383
  it "returns 3DS info on cc verification" do
@@ -305,18 +387,17 @@ describe Braintree::PaymentMethod do
305
387
  :options => {:verify_card => true},
306
388
  :customer_id => customer.id,
307
389
  )
308
- result.success?.should == true
390
+ expect(result.success?).to eq(true)
309
391
 
310
392
  three_d_secure_info = result.payment_method.verification.three_d_secure_info
311
- three_d_secure_info.enrolled.should == "Y"
312
- three_d_secure_info.should be_liability_shifted
313
- three_d_secure_info.should be_liability_shift_possible
314
- three_d_secure_info.status.should == "authenticate_successful"
315
- three_d_secure_info.cavv.should == "cavv_value"
316
- three_d_secure_info.xid.should == "xid_value"
317
- three_d_secure_info.eci_flag.should == "05"
318
- three_d_secure_info.three_d_secure_version.should == "1.0.2"
319
- three_d_secure_info.ds_transaction_id.should == nil
393
+ expect(three_d_secure_info.status).to eq("authenticate_successful")
394
+ expect(three_d_secure_info).to be_liability_shifted
395
+ expect(three_d_secure_info).to be_liability_shift_possible
396
+ expect(three_d_secure_info.enrolled).to be_a(String)
397
+ expect(three_d_secure_info.cavv).to be_a(String)
398
+ expect(three_d_secure_info.xid).to be_a(String)
399
+ expect(three_d_secure_info.eci_flag).to be_a(String)
400
+ expect(three_d_secure_info.three_d_secure_version).to be_a(String)
320
401
  end
321
402
 
322
403
  it "respects fail_on_duplicate_payment_method when included outside of the nonce" do
@@ -324,26 +405,53 @@ describe Braintree::PaymentMethod do
324
405
  result = Braintree::CreditCard.create(
325
406
  :customer_id => customer.id,
326
407
  :number => Braintree::Test::CreditCardNumbers::Visa,
327
- :expiration_date => "05/2012"
408
+ :expiration_date => "05/2012",
328
409
  )
329
- result.should be_success
410
+ expect(result).to be_success
330
411
 
331
412
  nonce = nonce_for_new_payment_method(
332
413
  :credit_card => {
333
414
  :number => Braintree::Test::CreditCardNumbers::Visa,
334
415
  :expiration_date => "05/2012"
335
- }
416
+ },
336
417
  )
337
418
  result = Braintree::PaymentMethod.create(
338
419
  :payment_method_nonce => nonce,
339
420
  :customer_id => customer.id,
340
421
  :options => {
341
422
  :fail_on_duplicate_payment_method => true
342
- }
423
+ },
424
+ )
425
+
426
+ expect(result).not_to be_success
427
+ expect(result.errors.first.code).to eq("81724")
428
+ end
429
+
430
+ it "respects fail_on_duplicate_payment_method_for_customer when included outside of the nonce" do
431
+ customer = Braintree::Customer.create!
432
+ result = Braintree::CreditCard.create(
433
+ :customer_id => customer.id,
434
+ :number => 4111111111111111,
435
+ :expiration_date => "05/2012",
436
+ )
437
+ expect(result).to be_success
438
+
439
+ nonce = nonce_for_new_payment_method(
440
+ :credit_card => {
441
+ :number => 4111111111111111,
442
+ :expiration_date => "05/2012"
443
+ },
444
+ )
445
+ result = Braintree::PaymentMethod.create(
446
+ :payment_method_nonce => nonce,
447
+ :customer_id => customer.id,
448
+ :options => {
449
+ :fail_on_duplicate_payment_method_for_customer => true
450
+ },
343
451
  )
344
452
 
345
- result.should_not be_success
346
- result.errors.first.code.should == "81724"
453
+ expect(result).not_to be_success
454
+ expect(result.errors.first.code).to eq("81763")
347
455
  end
348
456
 
349
457
  it "allows passing the billing address outside of the nonce" do
@@ -356,33 +464,36 @@ describe Braintree::PaymentMethod do
356
464
  config,
357
465
  :authorization_fingerprint => authorization_fingerprint,
358
466
  :shared_customer_identifier => "fake_identifier",
359
- :shared_customer_identifier_type => "testing"
467
+ :shared_customer_identifier_type => "testing",
360
468
  )
361
469
 
362
470
  response = http.create_credit_card(
363
471
  :number => "4111111111111111",
364
472
  :expirationMonth => "12",
365
473
  :expirationYear => "2020",
366
- :options => {:validate => false}
474
+ :options => {:validate => false},
367
475
  )
368
- response.code.should == "202"
476
+ expect(response.code).to eq("202")
369
477
 
370
478
  nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
371
479
  result = Braintree::PaymentMethod.create(
372
480
  :payment_method_nonce => nonce,
373
481
  :customer_id => customer.id,
374
482
  :billing_address => {
375
- :street_address => "123 Abc Way"
376
- }
483
+ :street_address => "123 Abc Way",
484
+ :international_phone => {:country_code => "1", :national_number => "3121234567"},
485
+ },
377
486
  )
378
487
 
379
- result.should be_success
380
- result.payment_method.should be_a(Braintree::CreditCard)
488
+ expect(result).to be_success
489
+ expect(result.payment_method).to be_a(Braintree::CreditCard)
381
490
  token = result.payment_method.token
382
491
 
383
492
  found_credit_card = Braintree::CreditCard.find(token)
384
- found_credit_card.should_not be_nil
385
- found_credit_card.billing_address.street_address.should == "123 Abc Way"
493
+ expect(found_credit_card).not_to be_nil
494
+ expect(found_credit_card.billing_address.street_address).to eq("123 Abc Way")
495
+ expect(found_credit_card.billing_address.international_phone[:country_code]).to eq("1")
496
+ expect(found_credit_card.billing_address.international_phone[:national_number]).to eq("3121234567")
386
497
  end
387
498
 
388
499
  it "allows passing a billing address id outside of the nonce" do
@@ -395,16 +506,16 @@ describe Braintree::PaymentMethod do
395
506
  config,
396
507
  :authorization_fingerprint => authorization_fingerprint,
397
508
  :shared_customer_identifier => "fake_identifier",
398
- :shared_customer_identifier_type => "testing"
509
+ :shared_customer_identifier_type => "testing",
399
510
  )
400
511
 
401
512
  response = http.create_credit_card(
402
513
  :number => "4111111111111111",
403
514
  :expirationMonth => "12",
404
515
  :expirationYear => "2020",
405
- :options => {:validate => false}
516
+ :options => {:validate => false},
406
517
  )
407
- response.code.should == "202"
518
+ expect(response.code).to eq("202")
408
519
 
409
520
  nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
410
521
 
@@ -412,17 +523,17 @@ describe Braintree::PaymentMethod do
412
523
  result = Braintree::PaymentMethod.create(
413
524
  :payment_method_nonce => nonce,
414
525
  :customer_id => customer.id,
415
- :billing_address_id => address.id
526
+ :billing_address_id => address.id,
416
527
  )
417
528
 
418
- result.should be_success
419
- result.payment_method.should be_a(Braintree::CreditCard)
529
+ expect(result).to be_success
530
+ expect(result.payment_method).to be_a(Braintree::CreditCard)
420
531
  token = result.payment_method.token
421
532
 
422
533
  found_credit_card = Braintree::CreditCard.find(token)
423
- found_credit_card.should_not be_nil
424
- found_credit_card.billing_address.first_name.should == "Bobby"
425
- found_credit_card.billing_address.last_name.should == "Tables"
534
+ expect(found_credit_card).not_to be_nil
535
+ expect(found_credit_card.billing_address.first_name).to eq("Bobby")
536
+ expect(found_credit_card.billing_address.last_name).to eq("Tables")
426
537
  end
427
538
 
428
539
  it "overrides the billing address in the nonce" do
@@ -435,7 +546,7 @@ describe Braintree::PaymentMethod do
435
546
  config,
436
547
  :authorization_fingerprint => authorization_fingerprint,
437
548
  :shared_customer_identifier => "fake_identifier",
438
- :shared_customer_identifier_type => "testing"
549
+ :shared_customer_identifier_type => "testing",
439
550
  )
440
551
 
441
552
  response = http.create_credit_card(
@@ -445,9 +556,9 @@ describe Braintree::PaymentMethod do
445
556
  :options => {:validate => false},
446
557
  :billing_address => {
447
558
  :street_address => "456 Xyz Way"
448
- }
559
+ },
449
560
  )
450
- response.code.should == "202"
561
+ expect(response.code).to eq("202")
451
562
 
452
563
  nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
453
564
  result = Braintree::PaymentMethod.create(
@@ -455,16 +566,16 @@ describe Braintree::PaymentMethod do
455
566
  :customer_id => customer.id,
456
567
  :billing_address => {
457
568
  :street_address => "123 Abc Way"
458
- }
569
+ },
459
570
  )
460
571
 
461
- result.should be_success
462
- result.payment_method.should be_a(Braintree::CreditCard)
572
+ expect(result).to be_success
573
+ expect(result.payment_method).to be_a(Braintree::CreditCard)
463
574
  token = result.payment_method.token
464
575
 
465
576
  found_credit_card = Braintree::CreditCard.find(token)
466
- found_credit_card.should_not be_nil
467
- found_credit_card.billing_address.street_address.should == "123 Abc Way"
577
+ expect(found_credit_card).not_to be_nil
578
+ expect(found_credit_card.billing_address.street_address).to eq("123 Abc Way")
468
579
  end
469
580
 
470
581
  it "does not override the billing address for a vaulted credit card" do
@@ -477,7 +588,7 @@ describe Braintree::PaymentMethod do
477
588
  config,
478
589
  :authorization_fingerprint => authorization_fingerprint,
479
590
  :shared_customer_identifier => "fake_identifier",
480
- :shared_customer_identifier_type => "testing"
591
+ :shared_customer_identifier_type => "testing",
481
592
  )
482
593
 
483
594
  response = http.create_credit_card(
@@ -486,9 +597,9 @@ describe Braintree::PaymentMethod do
486
597
  :expirationYear => 2020,
487
598
  :billing_address => {
488
599
  :street_address => "456 Xyz Way"
489
- }
600
+ },
490
601
  )
491
- response.code.should == "201"
602
+ expect(response.code).to eq("201")
492
603
 
493
604
  nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
494
605
  result = Braintree::PaymentMethod.create(
@@ -496,16 +607,68 @@ describe Braintree::PaymentMethod do
496
607
  :customer_id => customer.id,
497
608
  :billing_address => {
498
609
  :street_address => "123 Abc Way"
499
- }
610
+ },
500
611
  )
501
612
 
502
- result.should be_success
503
- result.payment_method.should be_a(Braintree::CreditCard)
613
+ expect(result).to be_success
614
+ expect(result.payment_method).to be_a(Braintree::CreditCard)
504
615
  token = result.payment_method.token
505
616
 
506
617
  found_credit_card = Braintree::CreditCard.find(token)
507
- found_credit_card.should_not be_nil
508
- found_credit_card.billing_address.street_address.should == "456 Xyz Way"
618
+ expect(found_credit_card).not_to be_nil
619
+ expect(found_credit_card.billing_address.street_address).to eq("456 Xyz Way")
620
+ end
621
+
622
+ it "includes risk data when skip_advanced_fraud_checking is false" do
623
+ with_fraud_protection_enterprise_merchant do
624
+ customer = Braintree::Customer.create!
625
+
626
+ nonce = nonce_for_new_payment_method(
627
+ :credit_card => {
628
+ :cvv => "123",
629
+ :number => Braintree::Test::CreditCardNumbers::Visa,
630
+ :expiration_date => "05/2009",
631
+ },
632
+ )
633
+ result = Braintree::PaymentMethod.create(
634
+ :payment_method_nonce => nonce,
635
+ :customer_id => customer.id,
636
+ :options => {
637
+ :verify_card => true,
638
+ :skip_advanced_fraud_checking => false,
639
+ },
640
+ )
641
+
642
+ expect(result).to be_success
643
+ verification = result.payment_method.verification
644
+ expect(verification.risk_data).not_to be_nil
645
+ end
646
+ end
647
+
648
+ it "does not include risk data when skip_advanced_fraud_checking is true" do
649
+ with_fraud_protection_enterprise_merchant do
650
+ customer = Braintree::Customer.create!
651
+
652
+ nonce = nonce_for_new_payment_method(
653
+ :credit_card => {
654
+ :cvv => "123",
655
+ :number => Braintree::Test::CreditCardNumbers::Visa,
656
+ :expiration_date => "05/2009",
657
+ },
658
+ )
659
+ result = Braintree::PaymentMethod.create(
660
+ :payment_method_nonce => nonce,
661
+ :customer_id => customer.id,
662
+ :options => {
663
+ :verify_card => true,
664
+ :skip_advanced_fraud_checking => true,
665
+ },
666
+ )
667
+
668
+ expect(result).to be_success
669
+ verification = result.payment_method.verification
670
+ expect(verification.risk_data).to be_nil
671
+ end
509
672
  end
510
673
 
511
674
  context "account_type" do
@@ -515,7 +678,7 @@ describe Braintree::PaymentMethod do
515
678
  :number => Braintree::Test::CreditCardNumbers::Hiper,
516
679
  :expiration_month => "11",
517
680
  :expiration_year => "2099",
518
- }
681
+ },
519
682
  )
520
683
  customer = Braintree::Customer.create!
521
684
  result = Braintree::PaymentMethod.create(
@@ -523,13 +686,13 @@ describe Braintree::PaymentMethod do
523
686
  :customer_id => customer.id,
524
687
  :options => {
525
688
  :verify_card => true,
526
- :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
689
+ :verification_merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
527
690
  :verification_account_type => "debit",
528
- }
691
+ },
529
692
  )
530
693
 
531
- result.should be_success
532
- result.payment_method.verification.credit_card[:account_type].should == "debit"
694
+ expect(result).to be_success
695
+ expect(result.payment_method.verification.credit_card[:account_type]).to eq("debit")
533
696
  end
534
697
 
535
698
  it "verifies card with account_type credit" do
@@ -538,7 +701,7 @@ describe Braintree::PaymentMethod do
538
701
  :number => Braintree::Test::CreditCardNumbers::Hiper,
539
702
  :expiration_month => "11",
540
703
  :expiration_year => "2099",
541
- }
704
+ },
542
705
  )
543
706
  customer = Braintree::Customer.create!
544
707
  result = Braintree::PaymentMethod.create(
@@ -548,11 +711,11 @@ describe Braintree::PaymentMethod do
548
711
  :verify_card => true,
549
712
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
550
713
  :verification_account_type => "credit",
551
- }
714
+ },
552
715
  )
553
716
 
554
- result.should be_success
555
- result.payment_method.verification.credit_card[:account_type].should == "credit"
717
+ expect(result).to be_success
718
+ expect(result.payment_method.verification.credit_card[:account_type]).to eq("credit")
556
719
  end
557
720
 
558
721
  it "errors with invalid account_type" do
@@ -561,7 +724,7 @@ describe Braintree::PaymentMethod do
561
724
  :number => Braintree::Test::CreditCardNumbers::Hiper,
562
725
  :expiration_month => "11",
563
726
  :expiration_year => "2099",
564
- }
727
+ },
565
728
  )
566
729
  customer = Braintree::Customer.create!
567
730
  result = Braintree::PaymentMethod.create(
@@ -571,11 +734,11 @@ describe Braintree::PaymentMethod do
571
734
  :verify_card => true,
572
735
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
573
736
  :verification_account_type => "ach",
574
- }
737
+ },
575
738
  )
576
739
 
577
- result.should_not be_success
578
- result.errors.for(:credit_card).for(:options).on(:verification_account_type)[0].code.should == Braintree::ErrorCodes::CreditCard::VerificationAccountTypeIsInvalid
740
+ expect(result).not_to be_success
741
+ expect(result.errors.for(:credit_card).for(:options).on(:verification_account_type)[0].code).to eq(Braintree::ErrorCodes::CreditCard::VerificationAccountTypeIsInvalid)
579
742
  end
580
743
 
581
744
  it "errors when account_type not supported by merchant" do
@@ -584,7 +747,7 @@ describe Braintree::PaymentMethod do
584
747
  :number => Braintree::Test::CreditCardNumbers::Visa,
585
748
  :expiration_month => "11",
586
749
  :expiration_year => "2099",
587
- }
750
+ },
588
751
  )
589
752
  customer = Braintree::Customer.create!
590
753
  result = Braintree::PaymentMethod.create(
@@ -593,11 +756,11 @@ describe Braintree::PaymentMethod do
593
756
  :options => {
594
757
  :verify_card => true,
595
758
  :verification_account_type => "credit",
596
- }
759
+ },
597
760
  )
598
761
 
599
- result.should_not be_success
600
- result.errors.for(:credit_card).for(:options).on(:verification_account_type)[0].code.should == Braintree::ErrorCodes::CreditCard::VerificationAccountTypeNotSupported
762
+ expect(result).not_to be_success
763
+ expect(result.errors.for(:credit_card).for(:options).on(:verification_account_type)[0].code).to eq(Braintree::ErrorCodes::CreditCard::VerificationAccountTypeNotSupported)
601
764
  end
602
765
 
603
766
  it "updates the credit card with account_type credit" do
@@ -607,7 +770,7 @@ describe Braintree::PaymentMethod do
607
770
  :customer_id => customer.id,
608
771
  :cvv => "123",
609
772
  :number => Braintree::Test::CreditCardNumbers::Visa,
610
- :expiration_date => "05/2012"
773
+ :expiration_date => "05/2012",
611
774
  )
612
775
  update_result = Braintree::PaymentMethod.update(credit_card.token,
613
776
  :cardholder_name => "New Holder",
@@ -620,8 +783,8 @@ describe Braintree::PaymentMethod do
620
783
  :verification_account_type => "credit",
621
784
  },
622
785
  )
623
- update_result.success?.should == true
624
- update_result.payment_method.verification.credit_card[:account_type].should == "credit"
786
+ expect(update_result.success?).to eq(true)
787
+ expect(update_result.payment_method.verification.credit_card[:account_type]).to eq("credit")
625
788
  end
626
789
 
627
790
  it "updates the credit card with account_type debit" do
@@ -631,7 +794,7 @@ describe Braintree::PaymentMethod do
631
794
  :customer_id => customer.id,
632
795
  :cvv => "123",
633
796
  :number => Braintree::Test::CreditCardNumbers::Visa,
634
- :expiration_date => "05/2012"
797
+ :expiration_date => "05/2012",
635
798
  )
636
799
  update_result = Braintree::PaymentMethod.update(credit_card.token,
637
800
  :cardholder_name => "New Holder",
@@ -640,12 +803,12 @@ describe Braintree::PaymentMethod do
640
803
  :expiration_date => "06/2013",
641
804
  :options => {
642
805
  :verify_card => true,
643
- :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
806
+ :verification_merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
644
807
  :verification_account_type => "debit",
645
808
  },
646
809
  )
647
- update_result.success?.should == true
648
- update_result.payment_method.verification.credit_card[:account_type].should == "debit"
810
+ expect(update_result.success?).to eq(true)
811
+ expect(update_result.payment_method.verification.credit_card[:account_type]).to eq("debit")
649
812
  end
650
813
  end
651
814
 
@@ -655,16 +818,16 @@ describe Braintree::PaymentMethod do
655
818
  customer = Braintree::Customer.create.customer
656
819
  result = Braintree::PaymentMethod.create(
657
820
  :payment_method_nonce => nonce,
658
- :customer_id => customer.id
821
+ :customer_id => customer.id,
659
822
  )
660
823
 
661
- result.should be_success
662
- result.payment_method.should be_a(Braintree::PayPalAccount)
663
- result.payment_method.image_url.should_not be_nil
824
+ expect(result).to be_success
825
+ expect(result.payment_method).to be_a(Braintree::PayPalAccount)
826
+ expect(result.payment_method.image_url).not_to be_nil
664
827
  token = result.payment_method.token
665
828
 
666
829
  found_paypal_account = Braintree::PayPalAccount.find(token)
667
- found_paypal_account.should_not be_nil
830
+ expect(found_paypal_account).not_to be_nil
668
831
  end
669
832
 
670
833
  it "creates a limited use payment method from a paypal account nonce for a paypal intent==order payment" do
@@ -697,15 +860,15 @@ describe Braintree::PaymentMethod do
697
860
  },
698
861
  )
699
862
 
700
- result.should be_success
701
- result.payment_method.should be_a(Braintree::PayPalAccount)
702
- result.payment_method.image_url.should_not be_nil
703
- result.payment_method.payer_id.should_not be_nil
863
+ expect(result).to be_success
864
+ expect(result.payment_method).to be_a(Braintree::PayPalAccount)
865
+ expect(result.payment_method.image_url).not_to be_nil
866
+ expect(result.payment_method.payer_id).not_to be_nil
704
867
  token = result.payment_method.token
705
868
 
706
869
  found_paypal_account = Braintree::PayPalAccount.find(token)
707
- found_paypal_account.should_not be_nil
708
- found_paypal_account.payer_id.should_not be_nil
870
+ expect(found_paypal_account).not_to be_nil
871
+ expect(found_paypal_account.payer_id).not_to be_nil
709
872
  end
710
873
 
711
874
  it "creates a billing agreement payment method from a refresh token" do
@@ -715,34 +878,16 @@ describe Braintree::PaymentMethod do
715
878
  :paypal_refresh_token => "some_future_payment_token",
716
879
  )
717
880
 
718
- result.should be_success
719
- result.payment_method.should be_a(Braintree::PayPalAccount)
720
- result.payment_method.billing_agreement_id.should eq("B_FAKE_ID")
721
- result.payment_method.payer_id.should_not be_nil
722
- token = result.payment_method.token
723
-
724
- found_paypal_account = Braintree::PayPalAccount.find(token)
725
- found_paypal_account.should_not be_nil
726
- found_paypal_account.billing_agreement_id.should eq("B_FAKE_ID")
727
- found_paypal_account.payer_id.should_not be_nil
728
- end
729
-
730
- it "creates a billing agreement payment method from a refresh token without upgrading" do
731
- customer = Braintree::Customer.create.customer
732
- result = Braintree::PaymentMethod.create(
733
- :customer_id => customer.id,
734
- :paypal_refresh_token => "some_future_payment_token",
735
- :paypal_vault_without_upgrade => true,
736
- )
737
-
738
- result.should be_success
739
- result.payment_method.should be_a(Braintree::PayPalAccount)
740
- result.payment_method.billing_agreement_id.should be_nil
881
+ expect(result).to be_success
882
+ expect(result.payment_method).to be_a(Braintree::PayPalAccount)
883
+ expect(result.payment_method.billing_agreement_id).to eq("B_FAKE_ID")
884
+ expect(result.payment_method.payer_id).not_to be_nil
741
885
  token = result.payment_method.token
742
886
 
743
887
  found_paypal_account = Braintree::PayPalAccount.find(token)
744
- found_paypal_account.should_not be_nil
745
- found_paypal_account.billing_agreement_id.should be_nil
888
+ expect(found_paypal_account).not_to be_nil
889
+ expect(found_paypal_account.billing_agreement_id).to eq("B_FAKE_ID")
890
+ expect(found_paypal_account.payer_id).not_to be_nil
746
891
  end
747
892
 
748
893
  it "does not create a payment method from an unvalidated onetime paypal account nonce" do
@@ -750,11 +895,11 @@ describe Braintree::PaymentMethod do
750
895
  nonce = nonce_for_paypal_account(:access_token => "PAYPAL_ACCESS_TOKEN")
751
896
  result = Braintree::PaymentMethod.create(
752
897
  :payment_method_nonce => nonce,
753
- :customer_id => customer.id
898
+ :customer_id => customer.id,
754
899
  )
755
900
 
756
- result.should_not be_success
757
- result.errors.first.code.should == "82902"
901
+ expect(result).not_to be_success
902
+ expect(result.errors.first.code).to eq("82902")
758
903
  end
759
904
 
760
905
  it "ignores passed billing address params" do
@@ -765,16 +910,16 @@ describe Braintree::PaymentMethod do
765
910
  :customer_id => customer.id,
766
911
  :billing_address => {
767
912
  :street_address => "123 Abc Way"
768
- }
913
+ },
769
914
  )
770
915
 
771
- result.should be_success
772
- result.payment_method.should be_a(Braintree::PayPalAccount)
773
- result.payment_method.image_url.should_not be_nil
916
+ expect(result).to be_success
917
+ expect(result.payment_method).to be_a(Braintree::PayPalAccount)
918
+ expect(result.payment_method.image_url).not_to be_nil
774
919
  token = result.payment_method.token
775
920
 
776
921
  found_paypal_account = Braintree::PayPalAccount.find(token)
777
- found_paypal_account.should_not be_nil
922
+ expect(found_paypal_account).not_to be_nil
778
923
  end
779
924
 
780
925
  it "ignores passed billing address id" do
@@ -783,16 +928,16 @@ describe Braintree::PaymentMethod do
783
928
  result = Braintree::PaymentMethod.create(
784
929
  :payment_method_nonce => nonce,
785
930
  :customer_id => customer.id,
786
- :billing_address_id => "address_id"
931
+ :billing_address_id => "address_id",
787
932
  )
788
933
 
789
- result.should be_success
790
- result.payment_method.should be_a(Braintree::PayPalAccount)
791
- result.payment_method.image_url.should_not be_nil
934
+ expect(result).to be_success
935
+ expect(result.payment_method).to be_a(Braintree::PayPalAccount)
936
+ expect(result.payment_method.image_url).not_to be_nil
792
937
  token = result.payment_method.token
793
938
 
794
939
  found_paypal_account = Braintree::PayPalAccount.find(token)
795
- found_paypal_account.should_not be_nil
940
+ expect(found_paypal_account).not_to be_nil
796
941
  end
797
942
 
798
943
  it "returns appropriate validation errors" do
@@ -800,13 +945,13 @@ describe Braintree::PaymentMethod do
800
945
  nonce = nonce_for_paypal_account(:token => "PAYPAL_TOKEN")
801
946
  result = Braintree::PaymentMethod.create(
802
947
  :payment_method_nonce => nonce,
803
- :customer_id => customer.id
948
+ :customer_id => customer.id,
804
949
  )
805
950
 
806
- result.should_not be_success
951
+ expect(result).not_to be_success
807
952
  errors = result.errors.map(&:code)
808
- errors.should include("82901")
809
- errors.should include("82902")
953
+ expect(errors).to include("82901")
954
+ expect(errors).to include("82902")
810
955
  end
811
956
 
812
957
  it "doesn't return an error if credit card options are present for a paypal nonce" do
@@ -814,7 +959,7 @@ describe Braintree::PaymentMethod do
814
959
  original_token = random_payment_method_token
815
960
  nonce = nonce_for_paypal_account(
816
961
  :consent_code => "consent-code",
817
- :token => original_token
962
+ :token => original_token,
818
963
  )
819
964
 
820
965
  result = Braintree::PaymentMethod.create(
@@ -824,10 +969,10 @@ describe Braintree::PaymentMethod do
824
969
  :verify_card => true,
825
970
  :fail_on_duplicate_payment_method => true,
826
971
  :verification_merchant_account_id => "not_a_real_merchant_account_id"
827
- }
972
+ },
828
973
  )
829
974
 
830
- result.should be_success
975
+ expect(result).to be_success
831
976
  end
832
977
  end
833
978
 
@@ -838,14 +983,107 @@ describe Braintree::PaymentMethod do
838
983
  result = Braintree::PaymentMethod.create(
839
984
  :payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable,
840
985
  :customer_id => customer.id,
841
- :token => token
986
+ :token => token,
842
987
  )
843
988
 
844
- result.should be_success
989
+ expect(result).to be_success
845
990
  payment_method = result.payment_method
846
- payment_method.should_not be_nil
847
- payment_method.token.should == token
848
- payment_method.should be_a Braintree::UnknownPaymentMethod
991
+ expect(payment_method).not_to be_nil
992
+ expect(payment_method.token).to eq(token)
993
+ expect(payment_method).to be_a Braintree::UnknownPaymentMethod
994
+ end
995
+ end
996
+
997
+ context "verification_currency_iso_code" do
998
+ it "validates verification_currency_iso_code against currency configured in default merchant account" do
999
+ nonce = nonce_for_new_payment_method(
1000
+ :credit_card => {
1001
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1002
+ :expiration_month => "11",
1003
+ :expiration_year => "2099",
1004
+ },
1005
+ )
1006
+ customer = Braintree::Customer.create!
1007
+ result = Braintree::PaymentMethod.create(
1008
+ :payment_method_nonce => nonce,
1009
+ :customer_id => customer.id,
1010
+ :options => {
1011
+ :verify_card => true,
1012
+ :verification_currency_iso_code => "USD"
1013
+ },
1014
+ )
1015
+
1016
+ expect(result).to be_success
1017
+ result.payment_method.verification.currency_iso_code == "USD"
1018
+ end
1019
+
1020
+ it "validates verification_currency_iso_code against currency configured in verification_merchant_account_id" do
1021
+ nonce = nonce_for_new_payment_method(
1022
+ :credit_card => {
1023
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1024
+ :expiration_month => "11",
1025
+ :expiration_year => "2099",
1026
+ },
1027
+ )
1028
+ customer = Braintree::Customer.create!
1029
+ result = Braintree::PaymentMethod.create(
1030
+ :payment_method_nonce => nonce,
1031
+ :customer_id => customer.id,
1032
+ :options => {
1033
+ :verify_card => true,
1034
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
1035
+ :verification_currency_iso_code => "USD"
1036
+ },
1037
+ )
1038
+
1039
+ expect(result).to be_success
1040
+ result.payment_method.verification.currency_iso_code == "USD"
1041
+ result.payment_method.verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
1042
+ end
1043
+
1044
+
1045
+ it "errors with invalid presentment currency due to verification_currency_iso_code not matching with currency configured in default merchant account" do
1046
+ nonce = nonce_for_new_payment_method(
1047
+ :credit_card => {
1048
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1049
+ :expiration_month => "11",
1050
+ :expiration_year => "2099",
1051
+ },
1052
+ )
1053
+ customer = Braintree::Customer.create!
1054
+ result = Braintree::PaymentMethod.create(
1055
+ :payment_method_nonce => nonce,
1056
+ :customer_id => customer.id,
1057
+ :options => {
1058
+ :verify_card => true,
1059
+ :verification_currency_iso_code => "GBP"
1060
+ },
1061
+ )
1062
+ expect(result).not_to be_success
1063
+ expect(result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq(Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount)
1064
+ end
1065
+
1066
+ it "errors with invalid presentment currency due to verification_currency_iso_code not matching with currency configured in verification_merchant_account_id" do
1067
+ nonce = nonce_for_new_payment_method(
1068
+ :credit_card => {
1069
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1070
+ :expiration_month => "11",
1071
+ :expiration_year => "2099",
1072
+ },
1073
+ )
1074
+ customer = Braintree::Customer.create!
1075
+ result = Braintree::PaymentMethod.create(
1076
+ :payment_method_nonce => nonce,
1077
+ :customer_id => customer.id,
1078
+ :options => {
1079
+ :verify_card => true,
1080
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
1081
+ :verification_currency_iso_code => "GBP"
1082
+ },
1083
+ )
1084
+
1085
+ expect(result).not_to be_success
1086
+ expect(result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq(Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount)
849
1087
  end
850
1088
  end
851
1089
  end
@@ -861,27 +1099,27 @@ describe Braintree::PaymentMethod do
861
1099
  config,
862
1100
  :authorization_fingerprint => authorization_fingerprint,
863
1101
  :shared_customer_identifier => "fake_identifier",
864
- :shared_customer_identifier_type => "testing"
1102
+ :shared_customer_identifier_type => "testing",
865
1103
  )
866
1104
 
867
1105
  response = http.create_credit_card(
868
1106
  :number => 4111111111111111,
869
1107
  :expirationMonth => 12,
870
- :expirationYear => 2020
1108
+ :expirationYear => 2020,
871
1109
  )
872
- response.code.should == "201"
1110
+ expect(response.code).to eq("201")
873
1111
 
874
1112
  nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
875
1113
  payment_method = Braintree::PaymentMethod.create!(
876
1114
  :payment_method_nonce => nonce,
877
- :customer_id => customer.id
1115
+ :customer_id => customer.id,
878
1116
  )
879
1117
 
880
- payment_method.should be_a(Braintree::CreditCard)
1118
+ expect(payment_method).to be_a(Braintree::CreditCard)
881
1119
  token = payment_method.token
882
1120
 
883
1121
  found_credit_card = Braintree::CreditCard.find(token)
884
- found_credit_card.should_not be_nil
1122
+ expect(found_credit_card).not_to be_nil
885
1123
  end
886
1124
  end
887
1125
 
@@ -892,15 +1130,15 @@ describe Braintree::PaymentMethod do
892
1130
  result = Braintree::CreditCard.create(
893
1131
  :customer_id => customer.id,
894
1132
  :number => Braintree::Test::CreditCardNumbers::Visa,
895
- :expiration_date => "05/2012"
1133
+ :expiration_date => "05/2012",
896
1134
  )
897
- result.success?.should == true
1135
+ expect(result.success?).to eq(true)
898
1136
 
899
1137
  credit_card = Braintree::PaymentMethod.find(result.credit_card.token)
900
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
901
- credit_card.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
902
- credit_card.token.should == result.credit_card.token
903
- credit_card.expiration_date.should == "05/2012"
1138
+ expect(credit_card.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
1139
+ expect(credit_card.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
1140
+ expect(credit_card.token).to eq(result.credit_card.token)
1141
+ expect(credit_card.expiration_date).to eq("05/2012")
904
1142
  end
905
1143
 
906
1144
  it "returns associated subscriptions with the credit card" do
@@ -908,20 +1146,20 @@ describe Braintree::PaymentMethod do
908
1146
  credit_card = Braintree::CreditCard.create(
909
1147
  :customer_id => customer.id,
910
1148
  :number => Braintree::Test::CreditCardNumbers::Visa,
911
- :expiration_date => "05/2012"
1149
+ :expiration_date => "05/2012",
912
1150
  ).credit_card
913
1151
 
914
1152
  subscription = Braintree::Subscription.create(
915
1153
  :payment_method_token => credit_card.token,
916
1154
  :plan_id => "integration_trialless_plan",
917
- :price => "1.00"
1155
+ :price => "1.00",
918
1156
  ).subscription
919
1157
 
920
1158
  found_card = Braintree::PaymentMethod.find(credit_card.token)
921
- found_card.subscriptions.first.id.should == subscription.id
922
- found_card.subscriptions.first.plan_id.should == "integration_trialless_plan"
923
- found_card.subscriptions.first.payment_method_token.should == credit_card.token
924
- found_card.subscriptions.first.price.should == BigDecimal("1.00")
1159
+ expect(found_card.subscriptions.first.id).to eq(subscription.id)
1160
+ expect(found_card.subscriptions.first.plan_id).to eq("integration_trialless_plan")
1161
+ expect(found_card.subscriptions.first.payment_method_token).to eq(credit_card.token)
1162
+ expect(found_card.subscriptions.first.price).to eq(BigDecimal("1.00"))
925
1163
  end
926
1164
  end
927
1165
 
@@ -931,19 +1169,19 @@ describe Braintree::PaymentMethod do
931
1169
  payment_method_token = make_token
932
1170
  nonce = nonce_for_paypal_account(
933
1171
  :consent_code => "consent-code",
934
- :token => payment_method_token
1172
+ :token => payment_method_token,
935
1173
  )
936
1174
  result = Braintree::PaymentMethod.create(
937
1175
  :payment_method_nonce => nonce,
938
- :customer_id => customer.id
1176
+ :customer_id => customer.id,
939
1177
  )
940
- result.should be_success
1178
+ expect(result).to be_success
941
1179
 
942
1180
  paypal_account = Braintree::PaymentMethod.find(payment_method_token)
943
- paypal_account.should be_a(Braintree::PayPalAccount)
944
- paypal_account.token.should == payment_method_token
945
- paypal_account.email.should == "jane.doe@example.com"
946
- paypal_account.customer_id.should == customer.id
1181
+ expect(paypal_account).to be_a(Braintree::PayPalAccount)
1182
+ expect(paypal_account.token).to eq(payment_method_token)
1183
+ expect(paypal_account.email).to eq("jane.doe@example.com")
1184
+ expect(paypal_account.customer_id).to eq(customer.id)
947
1185
  end
948
1186
  end
949
1187
 
@@ -954,21 +1192,46 @@ describe Braintree::PaymentMethod do
954
1192
  result = Braintree::PaymentMethod.create(
955
1193
  :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
956
1194
  :customer_id => customer.id,
957
- :token => payment_method_token
1195
+ :token => payment_method_token,
1196
+ )
1197
+ expect(result).to be_success
1198
+
1199
+ apple_pay_card = Braintree::PaymentMethod.find(payment_method_token)
1200
+ expect(apple_pay_card).to be_a(Braintree::ApplePayCard)
1201
+ expect(apple_pay_card).not_to be_nil
1202
+ expect(apple_pay_card.token).to eq(payment_method_token)
1203
+ expect(apple_pay_card.card_type).to eq(Braintree::ApplePayCard::CardType::AmEx)
1204
+ expect(apple_pay_card.default).to eq(true)
1205
+ expect(apple_pay_card.image_url).to match(/apple_pay/)
1206
+ expect(apple_pay_card.expiration_month.to_i).to be > 0
1207
+ expect(apple_pay_card.expiration_year.to_i).to be > 0
1208
+ expect(apple_pay_card.source_description).to eq("AmEx 41002")
1209
+ expect(apple_pay_card.customer_id).to eq(customer.id)
1210
+ end
1211
+
1212
+ it "finds the payment method with the given mpan token" do
1213
+ customer = Braintree::Customer.create!
1214
+ payment_method_token = make_token
1215
+ result = Braintree::PaymentMethod.create(
1216
+ :payment_method_nonce => Braintree::Test::Nonce::ApplePayMpan,
1217
+ :customer_id => customer.id,
1218
+ :token => payment_method_token,
958
1219
  )
959
- result.should be_success
1220
+ expect(result).to be_success
960
1221
 
961
1222
  apple_pay_card = Braintree::PaymentMethod.find(payment_method_token)
962
- apple_pay_card.should be_a(Braintree::ApplePayCard)
963
- apple_pay_card.should_not be_nil
964
- apple_pay_card.token.should == payment_method_token
965
- apple_pay_card.card_type.should == Braintree::ApplePayCard::CardType::AmEx
966
- apple_pay_card.default.should == true
967
- apple_pay_card.image_url.should =~ /apple_pay/
968
- apple_pay_card.expiration_month.to_i.should > 0
969
- apple_pay_card.expiration_year.to_i.should > 0
970
- apple_pay_card.source_description.should == "AmEx 41002"
971
- apple_pay_card.customer_id.should == customer.id
1223
+ expect(apple_pay_card).to be_a(Braintree::ApplePayCard)
1224
+ expect(apple_pay_card).not_to be_nil
1225
+ expect(apple_pay_card.token).to eq(payment_method_token)
1226
+ expect(apple_pay_card.card_type).to eq(Braintree::ApplePayCard::CardType::Visa)
1227
+ expect(apple_pay_card.default).to eq(true)
1228
+ expect(apple_pay_card.image_url).to match(/apple_pay/)
1229
+ expect(apple_pay_card.expiration_month.to_i).to be > 0
1230
+ expect(apple_pay_card.expiration_year.to_i).to be > 0
1231
+ expect(apple_pay_card.source_description).to eq("Visa 8886")
1232
+ expect(apple_pay_card.customer_id).to eq(customer.id)
1233
+ apple_pay_card.merchant_token_identifier == "DNITHE302308980427388297"
1234
+ apple_pay_card.source_card_last4 == "2006"
972
1235
  end
973
1236
  end
974
1237
 
@@ -979,76 +1242,78 @@ describe Braintree::PaymentMethod do
979
1242
  result = Braintree::PaymentMethod.create(
980
1243
  :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
981
1244
  :customer_id => customer.id,
982
- :token => payment_method_token
1245
+ :token => payment_method_token,
983
1246
  )
984
- result.should be_success
1247
+ expect(result).to be_success
985
1248
 
986
1249
  venmo_account = Braintree::PaymentMethod.find(payment_method_token)
987
- venmo_account.should be_a(Braintree::VenmoAccount)
988
- venmo_account.should_not be_nil
989
- venmo_account.token.should == payment_method_token
990
- venmo_account.default.should == true
991
- venmo_account.image_url.should =~ /venmo/
992
- venmo_account.username.should == 'venmojoe'
993
- venmo_account.venmo_user_id.should == 'Venmo-Joe-1'
994
- venmo_account.source_description.should == "Venmo Account: venmojoe"
995
- venmo_account.customer_id.should == customer.id
1250
+ expect(venmo_account).to be_a(Braintree::VenmoAccount)
1251
+ expect(venmo_account).not_to be_nil
1252
+ expect(venmo_account.token).to eq(payment_method_token)
1253
+ expect(venmo_account.default).to eq(true)
1254
+ expect(venmo_account.image_url).to match(/venmo/)
1255
+ expect(venmo_account.username).to eq("venmojoe")
1256
+ expect(venmo_account.venmo_user_id).to eq("1234567891234567891")
1257
+ expect(venmo_account.source_description).to eq("Venmo Account: venmojoe")
1258
+ expect(venmo_account.customer_id).to eq(customer.id)
996
1259
  end
997
1260
  end
998
1261
 
999
- context "android pay cards" do
1262
+ context "google pay cards" do
1000
1263
  it "finds the proxy card payment method with the given token" do
1001
1264
  customer = Braintree::Customer.create!
1002
1265
  payment_method_token = make_token
1003
1266
  result = Braintree::PaymentMethod.create(
1004
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover,
1267
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
1005
1268
  :customer_id => customer.id,
1006
- :token => payment_method_token
1007
- )
1008
- result.should be_success
1009
-
1010
- android_pay_card = Braintree::PaymentMethod.find(payment_method_token)
1011
- android_pay_card.should be_a(Braintree::AndroidPayCard)
1012
- android_pay_card.should_not be_nil
1013
- android_pay_card.token.should == payment_method_token
1014
- android_pay_card.card_type.should == Braintree::CreditCard::CardType::Discover
1015
- android_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1016
- android_pay_card.expiration_month.to_i.should > 0
1017
- android_pay_card.expiration_year.to_i.should > 0
1018
- android_pay_card.default.should == true
1019
- android_pay_card.image_url.should =~ /android_pay/
1020
- android_pay_card.source_card_type.should == Braintree::CreditCard::CardType::Discover
1021
- android_pay_card.source_card_last_4.should == "1111"
1022
- android_pay_card.google_transaction_id.should == "google_transaction_id"
1023
- android_pay_card.source_description.should == "Discover 1111"
1024
- android_pay_card.customer_id.should == customer.id
1269
+ :token => payment_method_token,
1270
+ )
1271
+ expect(result).to be_success
1272
+
1273
+ google_pay_card = Braintree::PaymentMethod.find(payment_method_token)
1274
+ expect(google_pay_card).to be_a(Braintree::GooglePayCard)
1275
+ expect(google_pay_card).not_to be_nil
1276
+ expect(google_pay_card.token).to eq(payment_method_token)
1277
+ expect(google_pay_card.card_type).to eq(Braintree::CreditCard::CardType::Discover)
1278
+ expect(google_pay_card.virtual_card_type).to eq(Braintree::CreditCard::CardType::Discover)
1279
+ expect(google_pay_card.expiration_month.to_i).to be > 0
1280
+ expect(google_pay_card.expiration_year.to_i).to be > 0
1281
+ expect(google_pay_card.default).to eq(true)
1282
+ expect(google_pay_card.image_url).to match(/android_pay/)
1283
+ expect(google_pay_card.is_network_tokenized?).to eq(false)
1284
+ expect(google_pay_card.source_card_type).to eq(Braintree::CreditCard::CardType::Discover)
1285
+ expect(google_pay_card.source_card_last_4).to eq("1111")
1286
+ expect(google_pay_card.google_transaction_id).to eq("google_transaction_id")
1287
+ expect(google_pay_card.source_description).to eq("Discover 1111")
1288
+ expect(google_pay_card.customer_id).to eq(customer.id)
1025
1289
  end
1026
1290
 
1027
1291
  it "finds the network token payment method with the given token" do
1028
1292
  customer = Braintree::Customer.create!
1029
1293
  payment_method_token = make_token
1030
1294
  result = Braintree::PaymentMethod.create(
1031
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayMasterCard,
1295
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
1032
1296
  :customer_id => customer.id,
1033
- :token => payment_method_token
1034
- )
1035
- result.should be_success
1036
-
1037
- android_pay_card = Braintree::PaymentMethod.find(payment_method_token)
1038
- android_pay_card.should be_a(Braintree::AndroidPayCard)
1039
- android_pay_card.should_not be_nil
1040
- android_pay_card.token.should == payment_method_token
1041
- android_pay_card.card_type.should == Braintree::CreditCard::CardType::MasterCard
1042
- android_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
1043
- android_pay_card.expiration_month.to_i.should > 0
1044
- android_pay_card.expiration_year.to_i.should > 0
1045
- android_pay_card.default.should == true
1046
- android_pay_card.image_url.should =~ /android_pay/
1047
- android_pay_card.source_card_type.should == Braintree::CreditCard::CardType::MasterCard
1048
- android_pay_card.source_card_last_4.should == "4444"
1049
- android_pay_card.google_transaction_id.should == "google_transaction_id"
1050
- android_pay_card.source_description.should == "MasterCard 4444"
1051
- android_pay_card.customer_id.should == customer.id
1297
+ :token => payment_method_token,
1298
+ )
1299
+ expect(result).to be_success
1300
+
1301
+ google_pay_card = Braintree::PaymentMethod.find(payment_method_token)
1302
+ expect(google_pay_card).to be_a(Braintree::GooglePayCard)
1303
+ expect(google_pay_card).not_to be_nil
1304
+ expect(google_pay_card.token).to eq(payment_method_token)
1305
+ expect(google_pay_card.card_type).to eq(Braintree::CreditCard::CardType::MasterCard)
1306
+ expect(google_pay_card.virtual_card_type).to eq(Braintree::CreditCard::CardType::MasterCard)
1307
+ expect(google_pay_card.expiration_month.to_i).to be > 0
1308
+ expect(google_pay_card.expiration_year.to_i).to be > 0
1309
+ expect(google_pay_card.default).to eq(true)
1310
+ expect(google_pay_card.image_url).to match(/android_pay/)
1311
+ expect(google_pay_card.is_network_tokenized?).to eq(true)
1312
+ expect(google_pay_card.source_card_type).to eq(Braintree::CreditCard::CardType::MasterCard)
1313
+ expect(google_pay_card.source_card_last_4).to eq("4444")
1314
+ expect(google_pay_card.google_transaction_id).to eq("google_transaction_id")
1315
+ expect(google_pay_card.source_description).to eq("MasterCard 4444")
1316
+ expect(google_pay_card.customer_id).to eq(customer.id)
1052
1317
  end
1053
1318
  end
1054
1319
 
@@ -1059,16 +1324,16 @@ describe Braintree::PaymentMethod do
1059
1324
  result = Braintree::PaymentMethod.create(
1060
1325
  :payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable,
1061
1326
  :customer_id => customer.id,
1062
- :token => payment_method_token
1327
+ :token => payment_method_token,
1063
1328
  )
1064
- result.should be_success
1329
+ expect(result).to be_success
1065
1330
 
1066
1331
  payment_method = Braintree::PaymentMethod.find(payment_method_token)
1067
- payment_method.should_not be_nil
1068
- payment_method.token.should == payment_method_token
1069
- payment_method.image_url.should_not be_nil
1070
- payment_method.should be_a Braintree::UnknownPaymentMethod
1071
- payment_method.customer_id.should == customer.id
1332
+ expect(payment_method).not_to be_nil
1333
+ expect(payment_method.token).to eq(payment_method_token)
1334
+ expect(payment_method.image_url).not_to be_nil
1335
+ expect(payment_method).to be_a Braintree::UnknownPaymentMethod
1336
+ expect(payment_method.customer_id).to eq(customer.id)
1072
1337
  end
1073
1338
  end
1074
1339
 
@@ -1080,21 +1345,21 @@ describe Braintree::PaymentMethod do
1080
1345
  end
1081
1346
 
1082
1347
  describe "self.delete" do
1083
- it "deletes an android pay card" do
1348
+ it "deletes an google pay card" do
1084
1349
  customer = Braintree::Customer.create!
1085
1350
 
1086
1351
  create_result = Braintree::PaymentMethod.create(
1087
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover,
1088
- :customer_id => customer.id
1352
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
1353
+ :customer_id => customer.id,
1089
1354
  )
1090
1355
 
1091
1356
  token = create_result.payment_method.token
1092
1357
 
1093
- android_card = Braintree::PaymentMethod.find(token)
1094
- android_card.should be_a(Braintree::AndroidPayCard)
1358
+ google_card = Braintree::PaymentMethod.find(token)
1359
+ expect(google_card).to be_a(Braintree::GooglePayCard)
1095
1360
 
1096
1361
  delete_result = Braintree::PaymentMethod.delete(token)
1097
- delete_result.success?.should == true
1362
+ expect(delete_result.success?).to eq(true)
1098
1363
 
1099
1364
  expect do
1100
1365
  Braintree::PaymentMethod.find(token)
@@ -1106,15 +1371,15 @@ describe Braintree::PaymentMethod do
1106
1371
 
1107
1372
  create_result = Braintree::PaymentMethod.create(
1108
1373
  :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
1109
- :customer_id => customer.id
1374
+ :customer_id => customer.id,
1110
1375
  )
1111
1376
  token = create_result.payment_method.token
1112
1377
 
1113
1378
  apple_pay_card = Braintree::PaymentMethod.find(token)
1114
- apple_pay_card.should be_a(Braintree::ApplePayCard)
1379
+ expect(apple_pay_card).to be_a(Braintree::ApplePayCard)
1115
1380
 
1116
1381
  delete_result = Braintree::PaymentMethod.delete(token)
1117
- delete_result.success?.should == true
1382
+ expect(delete_result.success?).to eq(true)
1118
1383
 
1119
1384
  expect do
1120
1385
  Braintree::PaymentMethod.find(token)
@@ -1127,18 +1392,18 @@ describe Braintree::PaymentMethod do
1127
1392
 
1128
1393
  nonce = nonce_for_paypal_account(
1129
1394
  :consent_code => "PAYPAL_CONSENT_CODE",
1130
- :token => paypal_account_token
1395
+ :token => paypal_account_token,
1131
1396
  )
1132
1397
  Braintree::PaymentMethod.create(
1133
1398
  :payment_method_nonce => nonce,
1134
- :customer_id => customer.id
1399
+ :customer_id => customer.id,
1135
1400
  )
1136
1401
 
1137
1402
  paypal_account = Braintree::PaymentMethod.find(paypal_account_token)
1138
- paypal_account.should be_a(Braintree::PayPalAccount)
1403
+ expect(paypal_account).to be_a(Braintree::PayPalAccount)
1139
1404
 
1140
1405
  result = Braintree::PaymentMethod.delete(paypal_account_token, {:revoke_all_grants => false})
1141
- result.success?.should == true
1406
+ expect(result.success?).to eq(true)
1142
1407
 
1143
1408
  expect do
1144
1409
  Braintree::PaymentMethod.find(paypal_account_token)
@@ -1160,11 +1425,11 @@ describe Braintree::PaymentMethod do
1160
1425
 
1161
1426
  Braintree::PaymentMethod.create(
1162
1427
  :payment_method_nonce => nonce,
1163
- :customer_id => customer.id
1428
+ :customer_id => customer.id,
1164
1429
  )
1165
1430
 
1166
1431
  result = Braintree::PaymentMethod.delete(token)
1167
- result.success?.should == true
1432
+ expect(result.success?).to eq(true)
1168
1433
 
1169
1434
  expect do
1170
1435
  Braintree::PaymentMethod.find(token)
@@ -1173,7 +1438,6 @@ describe Braintree::PaymentMethod do
1173
1438
 
1174
1439
  it "raises a NotFoundError exception if payment method cannot be found" do
1175
1440
  token = make_token
1176
- customer = Braintree::Customer.create!
1177
1441
 
1178
1442
  expect do
1179
1443
  Braintree::PaymentMethod.delete(token)
@@ -1183,6 +1447,71 @@ describe Braintree::PaymentMethod do
1183
1447
 
1184
1448
  describe "self.update" do
1185
1449
  context "credit cards" do
1450
+ it "throws validation error when passing invalid pass thru params" do
1451
+ customer = Braintree::Customer.create!
1452
+ credit_card = Braintree::CreditCard.create!(
1453
+ :customer_id => customer.id,
1454
+ :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1455
+ :options => {:verify_card => true},
1456
+ )
1457
+
1458
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1459
+ :cardholder_name => "New Holder",
1460
+ :cvv => "456",
1461
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1462
+ :expiration_date => "06/2013",
1463
+ :three_d_secure_pass_thru => {
1464
+ :eci_flag => "02",
1465
+ :cavv => "some_cavv",
1466
+ :xid => "some_xid",
1467
+ :three_d_secure_version => "xx",
1468
+ :authentication_response => "Y",
1469
+ :directory_response => "Y",
1470
+ :cavv_algorithm => "2",
1471
+ :ds_transaction_id => "some_ds_transaction_id",
1472
+ },
1473
+ :options => {:verify_card => true},
1474
+ )
1475
+ expect(update_result).to_not be_success
1476
+ error = update_result.errors.for(:verification).first
1477
+ expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsInvalid)
1478
+ 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`).")
1479
+ end
1480
+
1481
+ it "updates the credit card with three_d_secure pass thru params" do
1482
+ customer = Braintree::Customer.create!
1483
+ credit_card = Braintree::CreditCard.create!(
1484
+ :customer_id => customer.id,
1485
+ :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1486
+ :options => {:verify_card => true},
1487
+ )
1488
+
1489
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1490
+ :cardholder_name => "New Holder",
1491
+ :cvv => "456",
1492
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1493
+ :expiration_date => "06/2013",
1494
+ :three_d_secure_pass_thru => {
1495
+ :eci_flag => "02",
1496
+ :cavv => "some_cavv",
1497
+ :xid => "some_xid",
1498
+ :three_d_secure_version => "1.0.2",
1499
+ :authentication_response => "Y",
1500
+ :directory_response => "Y",
1501
+ :cavv_algorithm => "2",
1502
+ :ds_transaction_id => "some_ds_transaction_id",
1503
+ },
1504
+ :options => {:verify_card => true},
1505
+ )
1506
+ expect(update_result.success?).to eq(true)
1507
+ expect(update_result.payment_method).to eq(credit_card)
1508
+ updated_credit_card = update_result.payment_method
1509
+ expect(updated_credit_card.cardholder_name).to eq("New Holder")
1510
+ expect(updated_credit_card.bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
1511
+ expect(updated_credit_card.last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
1512
+ expect(updated_credit_card.expiration_date).to eq("06/2013")
1513
+ end
1514
+
1186
1515
  it "updates the credit card" do
1187
1516
  customer = Braintree::Customer.create!
1188
1517
  credit_card = Braintree::CreditCard.create!(
@@ -1190,23 +1519,159 @@ describe Braintree::PaymentMethod do
1190
1519
  :customer_id => customer.id,
1191
1520
  :cvv => "123",
1192
1521
  :number => Braintree::Test::CreditCardNumbers::Visa,
1193
- :expiration_date => "05/2012"
1522
+ :expiration_date => "05/2012",
1194
1523
  )
1195
1524
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1196
1525
  :cardholder_name => "New Holder",
1197
1526
  :cvv => "456",
1198
1527
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1199
- :expiration_date => "06/2013"
1528
+ :expiration_date => "06/2013",
1200
1529
  )
1201
- update_result.success?.should == true
1202
- update_result.payment_method.should == credit_card
1530
+ expect(update_result.success?).to eq(true)
1531
+ expect(update_result.payment_method).to eq(credit_card)
1203
1532
  updated_credit_card = update_result.payment_method
1204
- updated_credit_card.cardholder_name.should == "New Holder"
1205
- updated_credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
1206
- updated_credit_card.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
1207
- updated_credit_card.expiration_date.should == "06/2013"
1533
+ expect(updated_credit_card.cardholder_name).to eq("New Holder")
1534
+ expect(updated_credit_card.bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
1535
+ expect(updated_credit_card.last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
1536
+ expect(updated_credit_card.expiration_date).to eq("06/2013")
1537
+ end
1538
+
1539
+ it "includes risk data when skip_advanced_fraud_checking is false" do
1540
+ with_fraud_protection_enterprise_merchant do
1541
+ customer = Braintree::Customer.create!
1542
+ credit_card = Braintree::CreditCard.create!(
1543
+ :customer_id => customer.id,
1544
+ :cvv => "123",
1545
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1546
+ :expiration_date => "05/2012",
1547
+ )
1548
+ update_result = Braintree::PaymentMethod.update(
1549
+ credit_card.token,
1550
+ :cvv => "456",
1551
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1552
+ :expiration_date => "06/2013",
1553
+ :options => {
1554
+ :verify_card => true,
1555
+ :skip_advanced_fraud_checking => false
1556
+ },
1557
+ )
1558
+
1559
+ expect(update_result).to be_success
1560
+ verification = update_result.payment_method.verification
1561
+ expect(verification.risk_data).not_to be_nil
1562
+ end
1208
1563
  end
1209
1564
 
1565
+ it "does not include risk data when skip_advanced_fraud_checking is true" do
1566
+ with_fraud_protection_enterprise_merchant do
1567
+ customer = Braintree::Customer.create!
1568
+ credit_card = Braintree::CreditCard.create!(
1569
+ :customer_id => customer.id,
1570
+ :cvv => "123",
1571
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1572
+ :expiration_date => "05/2012",
1573
+ )
1574
+ update_result = Braintree::PaymentMethod.update(
1575
+ credit_card.token,
1576
+ :cvv => "456",
1577
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1578
+ :expiration_date => "06/2013",
1579
+ :options => {
1580
+ :verify_card => true,
1581
+ :skip_advanced_fraud_checking => true
1582
+ },
1583
+ )
1584
+
1585
+ expect(update_result).to be_success
1586
+ verification = update_result.payment_method.verification
1587
+ expect(verification.risk_data).to be_nil
1588
+ end
1589
+ end
1590
+
1591
+ context "verification_currency_iso_code" do
1592
+ it "validates verification_currency_iso_code and updates the credit card " do
1593
+ customer = Braintree::Customer.create!
1594
+ credit_card = Braintree::CreditCard.create!(
1595
+ :cardholder_name => "Original Holder",
1596
+ :customer_id => customer.id,
1597
+ :cvv => "123",
1598
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1599
+ :expiration_date => "05/2012",
1600
+ )
1601
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1602
+ :cardholder_name => "New Holder",
1603
+ :cvv => "456",
1604
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1605
+ :expiration_date => "06/2013",
1606
+ :options => {:verify_card => true, :verification_currency_iso_code => "USD"},
1607
+ )
1608
+ expect(update_result.success?).to eq(true)
1609
+ update_result.payment_method.verification.currency_iso_code == "USD"
1610
+ end
1611
+
1612
+ it "validates verification_currency_iso_code against the given verification_merchant_account_id and updates the credit card " do
1613
+ customer = Braintree::Customer.create!
1614
+ credit_card = Braintree::CreditCard.create!(
1615
+ :cardholder_name => "Original Holder",
1616
+ :customer_id => customer.id,
1617
+ :cvv => "123",
1618
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1619
+ :expiration_date => "05/2012",
1620
+ )
1621
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1622
+ :cardholder_name => "New Holder",
1623
+ :cvv => "456",
1624
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1625
+ :expiration_date => "06/2013",
1626
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "USD"},
1627
+ )
1628
+ expect(update_result.success?).to eq(true)
1629
+ update_result.payment_method.verification.currency_iso_code == "USD"
1630
+ update_result.payment_method.verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
1631
+ end
1632
+
1633
+ it "throws validation error when passing invalid verification_currency_iso_code" do
1634
+ customer = Braintree::Customer.create!
1635
+ credit_card = Braintree::CreditCard.create!(
1636
+ :cardholder_name => "Original Holder",
1637
+ :customer_id => customer.id,
1638
+ :cvv => "123",
1639
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1640
+ :expiration_date => "05/2012",
1641
+ )
1642
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1643
+ :cardholder_name => "New Holder",
1644
+ :cvv => "456",
1645
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1646
+ :expiration_date => "06/2013",
1647
+ :options => {:verify_card => true, :verification_currency_iso_code => "GBP"},
1648
+ )
1649
+ expect(update_result).to_not be_success
1650
+ expect(update_result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq(Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount)
1651
+ end
1652
+
1653
+ it "throws validation error when passing invalid verification_currency_iso_code of the given verification merchant account id" do
1654
+ customer = Braintree::Customer.create!
1655
+ credit_card = Braintree::CreditCard.create!(
1656
+ :cardholder_name => "Original Holder",
1657
+ :customer_id => customer.id,
1658
+ :cvv => "123",
1659
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1660
+ :expiration_date => "05/2012",
1661
+ )
1662
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1663
+ :cardholder_name => "New Holder",
1664
+ :cvv => "456",
1665
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1666
+ :expiration_date => "06/2013",
1667
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "GBP"},
1668
+ )
1669
+ expect(update_result).to_not be_success
1670
+ expect(update_result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq(Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount)
1671
+ end
1672
+ end
1673
+
1674
+
1210
1675
  context "billing address" do
1211
1676
  it "creates a new billing address by default" do
1212
1677
  customer = Braintree::Customer.create!
@@ -1216,18 +1681,18 @@ describe Braintree::PaymentMethod do
1216
1681
  :expiration_date => "05/2012",
1217
1682
  :billing_address => {
1218
1683
  :street_address => "123 Nigeria Ave"
1219
- }
1684
+ },
1220
1685
  )
1221
1686
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1222
1687
  :billing_address => {
1223
1688
  :region => "IL"
1224
- }
1689
+ },
1225
1690
  )
1226
- update_result.success?.should == true
1691
+ expect(update_result.success?).to eq(true)
1227
1692
  updated_credit_card = update_result.payment_method
1228
- updated_credit_card.billing_address.region.should == "IL"
1229
- updated_credit_card.billing_address.street_address.should == nil
1230
- updated_credit_card.billing_address.id.should_not == credit_card.billing_address.id
1693
+ expect(updated_credit_card.billing_address.region).to eq("IL")
1694
+ expect(updated_credit_card.billing_address.street_address).to eq(nil)
1695
+ expect(updated_credit_card.billing_address.id).not_to eq(credit_card.billing_address.id)
1231
1696
  end
1232
1697
 
1233
1698
  it "updates the billing address if option is specified" do
@@ -1238,19 +1703,22 @@ describe Braintree::PaymentMethod do
1238
1703
  :expiration_date => "05/2012",
1239
1704
  :billing_address => {
1240
1705
  :street_address => "123 Nigeria Ave"
1241
- }
1706
+ },
1242
1707
  )
1243
1708
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1244
1709
  :billing_address => {
1710
+ :international_phone => {:country_code => "1", :national_number => "3121234567"},
1245
1711
  :region => "IL",
1246
1712
  :options => {:update_existing => true}
1247
- }
1713
+ },
1248
1714
  )
1249
- update_result.success?.should == true
1715
+ expect(update_result.success?).to eq(true)
1250
1716
  updated_credit_card = update_result.payment_method
1251
- updated_credit_card.billing_address.region.should == "IL"
1252
- updated_credit_card.billing_address.street_address.should == "123 Nigeria Ave"
1253
- updated_credit_card.billing_address.id.should == credit_card.billing_address.id
1717
+ expect(updated_credit_card.billing_address.international_phone[:country_code]).to eq("1")
1718
+ expect(updated_credit_card.billing_address.international_phone[:national_number]).to eq("3121234567")
1719
+ expect(updated_credit_card.billing_address.region).to eq("IL")
1720
+ expect(updated_credit_card.billing_address.street_address).to eq("123 Nigeria Ave")
1721
+ expect(updated_credit_card.billing_address.id).to eq(credit_card.billing_address.id)
1254
1722
  end
1255
1723
 
1256
1724
  it "updates the country via codes" do
@@ -1261,7 +1729,7 @@ describe Braintree::PaymentMethod do
1261
1729
  :expiration_date => "05/2012",
1262
1730
  :billing_address => {
1263
1731
  :street_address => "123 Nigeria Ave"
1264
- }
1732
+ },
1265
1733
  )
1266
1734
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1267
1735
  :billing_address => {
@@ -1270,14 +1738,14 @@ describe Braintree::PaymentMethod do
1270
1738
  :country_code_alpha3 => "ASM",
1271
1739
  :country_code_numeric => "016",
1272
1740
  :options => {:update_existing => true}
1273
- }
1741
+ },
1274
1742
  )
1275
- update_result.success?.should == true
1743
+ expect(update_result.success?).to eq(true)
1276
1744
  updated_credit_card = update_result.payment_method
1277
- updated_credit_card.billing_address.country_name.should == "American Samoa"
1278
- updated_credit_card.billing_address.country_code_alpha2.should == "AS"
1279
- updated_credit_card.billing_address.country_code_alpha3.should == "ASM"
1280
- updated_credit_card.billing_address.country_code_numeric.should == "016"
1745
+ expect(updated_credit_card.billing_address.country_name).to eq("American Samoa")
1746
+ expect(updated_credit_card.billing_address.country_code_alpha2).to eq("AS")
1747
+ expect(updated_credit_card.billing_address.country_code_alpha3).to eq("ASM")
1748
+ expect(updated_credit_card.billing_address.country_code_numeric).to eq("016")
1281
1749
  end
1282
1750
  end
1283
1751
 
@@ -1286,18 +1754,18 @@ describe Braintree::PaymentMethod do
1286
1754
  credit_card = Braintree::CreditCard.create!(
1287
1755
  :customer_id => customer.id,
1288
1756
  :number => Braintree::Test::CreditCardNumbers::Visa,
1289
- :expiration_date => "05/2012"
1757
+ :expiration_date => "05/2012",
1290
1758
  )
1291
1759
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1292
1760
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1293
1761
  :expiration_month => "07",
1294
- :expiration_year => "2011"
1762
+ :expiration_year => "2011",
1295
1763
  )
1296
- update_result.success?.should == true
1297
- update_result.payment_method.should == credit_card
1298
- update_result.payment_method.expiration_month.should == "07"
1299
- update_result.payment_method.expiration_year.should == "2011"
1300
- update_result.payment_method.expiration_date.should == "07/2011"
1764
+ expect(update_result.success?).to eq(true)
1765
+ expect(update_result.payment_method).to eq(credit_card)
1766
+ expect(update_result.payment_method.expiration_month).to eq("07")
1767
+ expect(update_result.payment_method.expiration_year).to eq("2011")
1768
+ expect(update_result.payment_method.expiration_date).to eq("07/2011")
1301
1769
  end
1302
1770
 
1303
1771
  it "verifies the update if options[verify_card]=true" do
@@ -1307,18 +1775,18 @@ describe Braintree::PaymentMethod do
1307
1775
  :customer_id => customer.id,
1308
1776
  :cvv => "123",
1309
1777
  :number => Braintree::Test::CreditCardNumbers::Visa,
1310
- :expiration_date => "05/2012"
1778
+ :expiration_date => "05/2012",
1311
1779
  )
1312
1780
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1313
1781
  :cardholder_name => "New Holder",
1314
1782
  :cvv => "456",
1315
1783
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
1316
1784
  :expiration_date => "06/2013",
1317
- :options => {:verify_card => true}
1785
+ :options => {:verify_card => true},
1318
1786
  )
1319
- update_result.success?.should == false
1320
- update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
1321
- update_result.credit_card_verification.gateway_rejection_reason.should be_nil
1787
+ expect(update_result.success?).to eq(false)
1788
+ expect(update_result.credit_card_verification.status).to eq(Braintree::Transaction::Status::ProcessorDeclined)
1789
+ expect(update_result.credit_card_verification.gateway_rejection_reason).to be_nil
1322
1790
  end
1323
1791
 
1324
1792
  it "accepts a custom verification amount" do
@@ -1328,16 +1796,16 @@ describe Braintree::PaymentMethod do
1328
1796
  :customer_id => customer.id,
1329
1797
  :cvv => "123",
1330
1798
  :number => Braintree::Test::CreditCardNumbers::Visa,
1331
- :expiration_date => "05/2020"
1799
+ :expiration_date => "05/2020",
1332
1800
  )
1333
1801
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1334
1802
  :payment_method_nonce => Braintree::Test::Nonce::ProcessorDeclinedMasterCard,
1335
- :options => {:verify_card => true, :verification_amount => "2.34"}
1803
+ :options => {:verify_card => true, :verification_amount => "2.34"},
1336
1804
  )
1337
- update_result.success?.should == false
1338
- update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
1339
- update_result.credit_card_verification.gateway_rejection_reason.should be_nil
1340
- update_result.credit_card_verification.amount.should == BigDecimal("2.34")
1805
+ expect(update_result.success?).to eq(false)
1806
+ expect(update_result.credit_card_verification.status).to eq(Braintree::Transaction::Status::ProcessorDeclined)
1807
+ expect(update_result.credit_card_verification.gateway_rejection_reason).to be_nil
1808
+ expect(update_result.credit_card_verification.amount).to eq(BigDecimal("2.34"))
1341
1809
  end
1342
1810
 
1343
1811
  it "can update the billing address" do
@@ -1358,7 +1826,7 @@ describe Braintree::PaymentMethod do
1358
1826
  :region => "Old State",
1359
1827
  :postal_code => "12345",
1360
1828
  :country_name => "Canada"
1361
- }
1829
+ },
1362
1830
  )
1363
1831
  result = Braintree::PaymentMethod.update(credit_card.token,
1364
1832
  :options => {:verify_card => false},
@@ -1372,19 +1840,19 @@ describe Braintree::PaymentMethod do
1372
1840
  :region => "New State",
1373
1841
  :postal_code => "56789",
1374
1842
  :country_name => "United States of America"
1375
- }
1843
+ },
1376
1844
  )
1377
- result.success?.should == true
1845
+ expect(result.success?).to eq(true)
1378
1846
  address = result.payment_method.billing_address
1379
- address.first_name.should == "New First Name"
1380
- address.last_name.should == "New Last Name"
1381
- address.company.should == "New Company"
1382
- address.street_address.should == "123 New St"
1383
- address.extended_address.should == "Apt New"
1384
- address.locality.should == "New City"
1385
- address.region.should == "New State"
1386
- address.postal_code.should == "56789"
1387
- address.country_name.should == "United States of America"
1847
+ expect(address.first_name).to eq("New First Name")
1848
+ expect(address.last_name).to eq("New Last Name")
1849
+ expect(address.company).to eq("New Company")
1850
+ expect(address.street_address).to eq("123 New St")
1851
+ expect(address.extended_address).to eq("Apt New")
1852
+ expect(address.locality).to eq("New City")
1853
+ expect(address.region).to eq("New State")
1854
+ expect(address.postal_code).to eq("56789")
1855
+ expect(address.country_name).to eq("United States of America")
1388
1856
  end
1389
1857
 
1390
1858
  it "returns an error response if invalid" do
@@ -1393,15 +1861,15 @@ describe Braintree::PaymentMethod do
1393
1861
  :cardholder_name => "Original Holder",
1394
1862
  :customer_id => customer.id,
1395
1863
  :number => Braintree::Test::CreditCardNumbers::Visa,
1396
- :expiration_date => "05/2012"
1864
+ :expiration_date => "05/2012",
1397
1865
  )
1398
1866
  update_result = Braintree::PaymentMethod.update(credit_card.token,
1399
1867
  :cardholder_name => "New Holder",
1400
1868
  :number => "invalid",
1401
- :expiration_date => "05/2014"
1869
+ :expiration_date => "05/2014",
1402
1870
  )
1403
- update_result.success?.should == false
1404
- update_result.errors.for(:credit_card).on(:number)[0].message.should == "Credit card number must be 12-19 digits."
1871
+ expect(update_result.success?).to eq(false)
1872
+ expect(update_result.errors.for(:credit_card).on(:number)[0].message).to eq("Credit card number must be 12-19 digits.")
1405
1873
  end
1406
1874
 
1407
1875
  it "can update the default" do
@@ -1409,37 +1877,21 @@ describe Braintree::PaymentMethod do
1409
1877
  card1 = Braintree::CreditCard.create(
1410
1878
  :customer_id => customer.id,
1411
1879
  :number => Braintree::Test::CreditCardNumbers::Visa,
1412
- :expiration_date => "05/2009"
1880
+ :expiration_date => "05/2009",
1413
1881
  ).credit_card
1414
1882
  card2 = Braintree::CreditCard.create(
1415
1883
  :customer_id => customer.id,
1416
1884
  :number => Braintree::Test::CreditCardNumbers::Visa,
1417
- :expiration_date => "05/2009"
1885
+ :expiration_date => "05/2009",
1418
1886
  ).credit_card
1419
1887
 
1420
- card1.should be_default
1421
- card2.should_not be_default
1888
+ expect(card1).to be_default
1889
+ expect(card2).not_to be_default
1422
1890
 
1423
1891
  Braintree::PaymentMethod.update(card2.token, :options => {:make_default => true})
1424
1892
 
1425
- Braintree::CreditCard.find(card1.token).should_not be_default
1426
- Braintree::CreditCard.find(card2.token).should be_default
1427
- end
1428
- end
1429
-
1430
- context "coinbase accounts" do
1431
- it "cannot create a payment method token with Coinbase" do
1432
- customer = Braintree::Customer.create!
1433
-
1434
- nonce = Braintree::Test::Nonce::Coinbase
1435
- result = Braintree::PaymentMethod.create(
1436
- :payment_method_nonce => nonce,
1437
- :customer_id => customer.id
1438
- )
1439
-
1440
- result.should_not be_success
1441
-
1442
- result.errors.for(:coinbase_account).first.code.should == Braintree::ErrorCodes::PaymentMethod::PaymentMethodNoLongerSupported
1893
+ expect(Braintree::CreditCard.find(card1.token)).not_to be_default
1894
+ expect(Braintree::CreditCard.find(card2.token)).to be_default
1443
1895
  end
1444
1896
  end
1445
1897
 
@@ -1449,21 +1901,21 @@ describe Braintree::PaymentMethod do
1449
1901
  original_token = random_payment_method_token
1450
1902
  nonce = nonce_for_paypal_account(
1451
1903
  :consent_code => "consent-code",
1452
- :token => original_token
1904
+ :token => original_token,
1453
1905
  )
1454
1906
  original_result = Braintree::PaymentMethod.create(
1455
1907
  :payment_method_nonce => nonce,
1456
- :customer_id => customer.id
1908
+ :customer_id => customer.id,
1457
1909
  )
1458
1910
 
1459
1911
  updated_token = make_token
1460
- updated_result = Braintree::PaymentMethod.update(
1912
+ Braintree::PaymentMethod.update(
1461
1913
  original_token,
1462
- :token => updated_token
1914
+ :token => updated_token,
1463
1915
  )
1464
1916
 
1465
1917
  updated_paypal_account = Braintree::PayPalAccount.find(updated_token)
1466
- updated_paypal_account.email.should == original_result.payment_method.email
1918
+ expect(updated_paypal_account.email).to eq(original_result.payment_method.email)
1467
1919
 
1468
1920
  expect do
1469
1921
  Braintree::PayPalAccount.find(original_token)
@@ -1476,23 +1928,23 @@ describe Braintree::PaymentMethod do
1476
1928
  :customer_id => customer.id,
1477
1929
  :number => Braintree::Test::CreditCardNumbers::Visa,
1478
1930
  :expiration_date => "05/2009",
1479
- :options => {:make_default => true}
1931
+ :options => {:make_default => true},
1480
1932
  )
1481
- result.should be_success
1933
+ expect(result).to be_success
1482
1934
 
1483
1935
  nonce = nonce_for_paypal_account(:consent_code => "consent-code")
1484
1936
  original_token = Braintree::PaymentMethod.create(
1485
1937
  :payment_method_nonce => nonce,
1486
- :customer_id => customer.id
1938
+ :customer_id => customer.id,
1487
1939
  ).payment_method.token
1488
1940
 
1489
- updated_result = Braintree::PaymentMethod.update(
1941
+ Braintree::PaymentMethod.update(
1490
1942
  original_token,
1491
- :options => {:make_default => true}
1943
+ :options => {:make_default => true},
1492
1944
  )
1493
1945
 
1494
1946
  updated_paypal_account = Braintree::PayPalAccount.find(original_token)
1495
- updated_paypal_account.should be_default
1947
+ expect(updated_paypal_account).to be_default
1496
1948
  end
1497
1949
 
1498
1950
  it "returns an error if a token for account is used to attempt an update" do
@@ -1502,29 +1954,29 @@ describe Braintree::PaymentMethod do
1502
1954
 
1503
1955
  first_nonce = nonce_for_paypal_account(
1504
1956
  :consent_code => "consent-code",
1505
- :token => first_token
1957
+ :token => first_token,
1506
1958
  )
1507
- first_result = Braintree::PaymentMethod.create(
1959
+ Braintree::PaymentMethod.create(
1508
1960
  :payment_method_nonce => first_nonce,
1509
- :customer_id => customer.id
1961
+ :customer_id => customer.id,
1510
1962
  )
1511
1963
 
1512
1964
  second_nonce = nonce_for_paypal_account(
1513
1965
  :consent_code => "consent-code",
1514
- :token => second_token
1966
+ :token => second_token,
1515
1967
  )
1516
- second_result = Braintree::PaymentMethod.create(
1968
+ Braintree::PaymentMethod.create(
1517
1969
  :payment_method_nonce => second_nonce,
1518
- :customer_id => customer.id
1970
+ :customer_id => customer.id,
1519
1971
  )
1520
1972
 
1521
1973
  updated_result = Braintree::PaymentMethod.update(
1522
1974
  first_token,
1523
- :token => second_token
1975
+ :token => second_token,
1524
1976
  )
1525
1977
 
1526
- updated_result.should_not be_success
1527
- updated_result.errors.first.code.should == "92906"
1978
+ expect(updated_result).not_to be_success
1979
+ expect(updated_result.errors.first.code).to eq("92906")
1528
1980
  end
1529
1981
  end
1530
1982
  end
@@ -1537,19 +1989,19 @@ describe Braintree::PaymentMethod do
1537
1989
  :customer_id => customer.id,
1538
1990
  :cvv => "123",
1539
1991
  :number => Braintree::Test::CreditCardNumbers::Visa,
1540
- :expiration_date => "05/2012"
1992
+ :expiration_date => "05/2012",
1541
1993
  )
1542
1994
  payment_method = Braintree::PaymentMethod.update!(credit_card.token,
1543
1995
  :cardholder_name => "New Holder",
1544
1996
  :cvv => "456",
1545
1997
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1546
- :expiration_date => "06/2013"
1998
+ :expiration_date => "06/2013",
1547
1999
  )
1548
- payment_method.should == credit_card
1549
- payment_method.cardholder_name.should == "New Holder"
1550
- payment_method.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
1551
- payment_method.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
1552
- payment_method.expiration_date.should == "06/2013"
2000
+ expect(payment_method).to eq(credit_card)
2001
+ expect(payment_method.cardholder_name).to eq("New Holder")
2002
+ expect(payment_method.bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
2003
+ expect(payment_method.last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
2004
+ expect(payment_method.expiration_date).to eq("06/2013")
1553
2005
  end
1554
2006
  end
1555
2007
 
@@ -1560,7 +2012,7 @@ describe Braintree::PaymentMethod do
1560
2012
  :public_key => "oauth_app_partner_user_public_key",
1561
2013
  :private_key => "oauth_app_partner_user_private_key",
1562
2014
  :environment => Braintree::Configuration.environment,
1563
- :logger => Logger.new("/dev/null")
2015
+ :logger => Logger.new("/dev/null"),
1564
2016
  )
1565
2017
  customer = @partner_merchant_gateway.customer.create(
1566
2018
  :first_name => "Joe",
@@ -1569,19 +2021,19 @@ describe Braintree::PaymentMethod do
1569
2021
  :email => "joe@example.com",
1570
2022
  :phone => "312.555.1234",
1571
2023
  :fax => "614.555.5678",
1572
- :website => "www.example.com"
2024
+ :website => "www.example.com",
1573
2025
  ).customer
1574
2026
  @credit_card = @partner_merchant_gateway.credit_card.create(
1575
2027
  :customer_id => customer.id,
1576
2028
  :cardholder_name => "Adam Davis",
1577
2029
  :number => Braintree::Test::CreditCardNumbers::Visa,
1578
- :expiration_date => "05/2009"
2030
+ :expiration_date => "05/2009",
1579
2031
  ).credit_card
1580
2032
 
1581
2033
  @oauth_gateway = Braintree::Gateway.new(
1582
2034
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
1583
2035
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
1584
- :logger => Logger.new("/dev/null")
2036
+ :logger => Logger.new("/dev/null"),
1585
2037
  )
1586
2038
  access_token = Braintree::OAuthTestHelper.create_token(@oauth_gateway, {
1587
2039
  :merchant_public_id => "integration_merchant_id",
@@ -1590,31 +2042,31 @@ describe Braintree::PaymentMethod do
1590
2042
 
1591
2043
  @granting_gateway = Braintree::Gateway.new(
1592
2044
  :access_token => access_token,
1593
- :logger => Logger.new("/dev/null")
2045
+ :logger => Logger.new("/dev/null"),
1594
2046
  )
1595
2047
  end
1596
2048
 
1597
2049
  describe "self.grant" do
1598
2050
  it "returns an error result when the grant doesn't succeed" do
1599
2051
  grant_result = @granting_gateway.payment_method.grant("payment_method_from_grant", true)
1600
- grant_result.should_not be_success
2052
+ expect(grant_result).not_to be_success
1601
2053
  end
1602
2054
 
1603
2055
  it "returns a nonce that is transactable by a partner merchant exactly once" do
1604
2056
  grant_result = @granting_gateway.payment_method.grant(@credit_card.token, :allow_vaulting => false)
1605
- grant_result.should be_success
2057
+ expect(grant_result).to be_success
1606
2058
 
1607
2059
  result = Braintree::Transaction.sale(
1608
2060
  :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1609
- :amount => Braintree::Test::TransactionAmounts::Authorize
2061
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
1610
2062
  )
1611
- result.should be_success
2063
+ expect(result).to be_success
1612
2064
 
1613
2065
  result2 = Braintree::Transaction.sale(
1614
2066
  :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1615
- :amount => Braintree::Test::TransactionAmounts::Authorize
2067
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
1616
2068
  )
1617
- result2.should_not be_success
2069
+ expect(result2).not_to be_success
1618
2070
  end
1619
2071
 
1620
2072
  it "returns a nonce that is not vaultable" do
@@ -1624,9 +2076,9 @@ describe Braintree::PaymentMethod do
1624
2076
 
1625
2077
  result = Braintree::PaymentMethod.create(
1626
2078
  :customer_id => customer_result.customer.id,
1627
- :payment_method_nonce => grant_result.payment_method_nonce.nonce
2079
+ :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1628
2080
  )
1629
- result.should_not be_success
2081
+ expect(result).not_to be_success
1630
2082
  end
1631
2083
 
1632
2084
  it "returns a nonce that is vaultable" do
@@ -1636,21 +2088,21 @@ describe Braintree::PaymentMethod do
1636
2088
 
1637
2089
  result = Braintree::PaymentMethod.create(
1638
2090
  :customer_id => customer_result.customer.id,
1639
- :payment_method_nonce => grant_result.payment_method_nonce.nonce
2091
+ :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1640
2092
  )
1641
- result.should be_success
2093
+ expect(result).to be_success
1642
2094
  end
1643
2095
 
1644
2096
  it "raises an error if the token isn't found" do
1645
2097
  expect do
1646
2098
  @granting_gateway.payment_method.grant("not_a_real_token", false)
1647
- end.to raise_error
2099
+ end.to raise_error(Braintree::NotFoundError)
1648
2100
  end
1649
2101
 
1650
2102
  it "returns a valid nonce with no options set" do
1651
2103
  expect do
1652
2104
  grant_result = @granting_gateway.payment_method.grant(@credit_card.token)
1653
- grant_result.should be_success
2105
+ expect(grant_result).to be_success
1654
2106
  end
1655
2107
  end
1656
2108
  end
@@ -1659,35 +2111,35 @@ describe Braintree::PaymentMethod do
1659
2111
  it "raises an error if the token isn't found" do
1660
2112
  expect do
1661
2113
  @granting_gateway.payment_method.revoke("not_a_real_token")
1662
- end.to raise_error
2114
+ end.to raise_error(Braintree::NotFoundError)
1663
2115
  end
1664
2116
 
1665
2117
  it "renders a granted nonce useless" do
1666
2118
  grant_result = @granting_gateway.payment_method.grant(@credit_card.token)
1667
2119
  revoke_result = @granting_gateway.payment_method.revoke(@credit_card.token)
1668
- revoke_result.should be_success
2120
+ expect(revoke_result).to be_success
1669
2121
 
1670
2122
  customer_result = Braintree::Customer.create()
1671
2123
 
1672
2124
  result = Braintree::PaymentMethod.create(
1673
2125
  :customer_id => customer_result.customer.id,
1674
- :payment_method_nonce => grant_result.payment_method_nonce.nonce
2126
+ :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1675
2127
  )
1676
- result.should_not be_success
2128
+ expect(result).not_to be_success
1677
2129
  end
1678
2130
 
1679
2131
  it "renders a granted nonce obtained uisng options hash, useless" do
1680
2132
  grant_result = @granting_gateway.payment_method.grant(@credit_card.token, :allow_vaulting => true)
1681
2133
  revoke_result = @granting_gateway.payment_method.revoke(@credit_card.token)
1682
- revoke_result.should be_success
2134
+ expect(revoke_result).to be_success
1683
2135
 
1684
2136
  customer_result = Braintree::Customer.create()
1685
2137
 
1686
2138
  result = Braintree::PaymentMethod.create(
1687
2139
  :customer_id => customer_result.customer.id,
1688
- :payment_method_nonce => grant_result.payment_method_nonce.nonce
2140
+ :payment_method_nonce => grant_result.payment_method_nonce.nonce,
1689
2141
  )
1690
- result.should_not be_success
2142
+ expect(result).not_to be_success
1691
2143
  end
1692
2144
  end
1693
2145
  end