braintree 2.10.0 → 4.26.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 (353) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +24 -0
  4. data/lib/braintree/account_updater_daily_report.rb +20 -0
  5. data/lib/braintree/ach_mandate.rb +14 -0
  6. data/lib/braintree/add_on.rb +4 -0
  7. data/lib/braintree/add_on_gateway.rb +17 -0
  8. data/lib/braintree/address/country_names.rb +4 -1
  9. data/lib/braintree/address.rb +35 -43
  10. data/lib/braintree/address_gateway.rb +24 -11
  11. data/lib/braintree/advanced_search.rb +26 -11
  12. data/lib/braintree/apple_pay.rb +29 -0
  13. data/lib/braintree/apple_pay_card.rb +66 -0
  14. data/lib/braintree/apple_pay_gateway.rb +37 -0
  15. data/lib/braintree/apple_pay_options.rb +19 -0
  16. data/lib/braintree/authorization_adjustment.rb +23 -0
  17. data/lib/braintree/base_module.rb +11 -1
  18. data/lib/braintree/bin_data.rb +34 -0
  19. data/lib/braintree/client_token.rb +11 -0
  20. data/lib/braintree/client_token_gateway.rb +45 -0
  21. data/lib/braintree/configuration.rb +231 -39
  22. data/lib/braintree/connected_merchant_paypal_status_changed.rb +22 -0
  23. data/lib/braintree/connected_merchant_status_transitioned.rb +22 -0
  24. data/lib/braintree/credentials_parser.rb +44 -0
  25. data/lib/braintree/credit_card.rb +107 -132
  26. data/lib/braintree/credit_card_gateway.rb +90 -41
  27. data/lib/braintree/credit_card_verification.rb +90 -17
  28. data/lib/braintree/credit_card_verification_gateway.rb +87 -0
  29. data/lib/braintree/credit_card_verification_search.rb +20 -0
  30. data/lib/braintree/customer.rb +80 -118
  31. data/lib/braintree/customer_gateway.rb +66 -39
  32. data/lib/braintree/customer_search.rb +5 -2
  33. data/lib/braintree/customer_session_gateway.rb +194 -0
  34. data/lib/braintree/descriptor.rb +4 -2
  35. data/lib/braintree/digest.rb +16 -3
  36. data/lib/braintree/disbursement.rb +63 -0
  37. data/lib/braintree/discount.rb +4 -0
  38. data/lib/braintree/discount_gateway.rb +17 -0
  39. data/lib/braintree/dispute/evidence.rb +24 -0
  40. data/lib/braintree/dispute/paypal_message.rb +15 -0
  41. data/lib/braintree/dispute/status_history.rb +18 -0
  42. data/lib/braintree/dispute/transaction.rb +20 -0
  43. data/lib/braintree/dispute/transaction_details.rb +15 -0
  44. data/lib/braintree/dispute.rb +165 -0
  45. data/lib/braintree/dispute_gateway.rb +142 -0
  46. data/lib/braintree/dispute_search.rb +31 -0
  47. data/lib/braintree/document_upload.rb +37 -0
  48. data/lib/braintree/document_upload_gateway.rb +38 -0
  49. data/lib/braintree/enriched_customer_data.rb +21 -0
  50. data/lib/braintree/error_codes.rb +680 -15
  51. data/lib/braintree/error_result.rb +13 -6
  52. data/lib/braintree/errors.rb +5 -5
  53. data/lib/braintree/exceptions.rb +14 -20
  54. data/lib/braintree/exchange_rate.rb +13 -0
  55. data/lib/braintree/exchange_rate_quote.rb +24 -0
  56. data/lib/braintree/exchange_rate_quote_gateway.rb +35 -0
  57. data/lib/braintree/exchange_rate_quote_input.rb +21 -0
  58. data/lib/braintree/exchange_rate_quote_request.rb +18 -0
  59. data/lib/braintree/exchange_rate_quote_response.rb +18 -0
  60. data/lib/braintree/facilitated_details.rb +21 -0
  61. data/lib/braintree/facilitator_details.rb +20 -0
  62. data/lib/braintree/gateway.rb +104 -6
  63. data/lib/braintree/google_pay_card.rb +62 -0
  64. data/lib/braintree/granted_payment_instrument_update.rb +23 -0
  65. data/lib/braintree/graphql/enums/recommendations.rb +7 -0
  66. data/lib/braintree/graphql/enums/recommended_payment_option.rb +8 -0
  67. data/lib/braintree/graphql/inputs/create_customer_session_input.rb +35 -0
  68. data/lib/braintree/graphql/inputs/customer_recommendations_input.rb +41 -0
  69. data/lib/braintree/graphql/inputs/customer_session_input.rb +39 -0
  70. data/lib/braintree/graphql/inputs/phone_input.rb +32 -0
  71. data/lib/braintree/graphql/inputs/update_customer_session_input.rb +37 -0
  72. data/lib/braintree/graphql/types/customer_recommendations_payload.rb +32 -0
  73. data/lib/braintree/graphql/types/payment_options.rb +33 -0
  74. data/lib/braintree/graphql/unions/customer_recommendations.rb +34 -0
  75. data/lib/braintree/graphql_client.rb +50 -0
  76. data/lib/braintree/http.rb +119 -25
  77. data/lib/braintree/local_payment_completed/blik_alias.rb +23 -0
  78. data/lib/braintree/local_payment_completed.rb +28 -0
  79. data/lib/braintree/local_payment_expired.rb +21 -0
  80. data/lib/braintree/local_payment_funded.rb +22 -0
  81. data/lib/braintree/local_payment_reversed.rb +19 -0
  82. data/lib/braintree/merchant.rb +34 -0
  83. data/lib/braintree/merchant_account/address_details.rb +16 -0
  84. data/lib/braintree/merchant_account/business_details.rb +17 -0
  85. data/lib/braintree/merchant_account/funding_details.rb +18 -0
  86. data/lib/braintree/merchant_account/individual_details.rb +20 -0
  87. data/lib/braintree/merchant_account.rb +76 -0
  88. data/lib/braintree/merchant_account_gateway.rb +130 -0
  89. data/lib/braintree/merchant_gateway.rb +38 -0
  90. data/lib/braintree/meta_checkout_card.rb +90 -0
  91. data/lib/braintree/meta_checkout_token.rb +89 -0
  92. data/lib/braintree/modification.rb +16 -5
  93. data/lib/braintree/oauth_credentials.rb +22 -0
  94. data/lib/braintree/oauth_gateway.rb +73 -0
  95. data/lib/braintree/paginated_collection.rb +25 -0
  96. data/lib/braintree/paginated_result.rb +15 -0
  97. data/lib/braintree/payment_instrument_type.rb +18 -0
  98. data/lib/braintree/payment_method.rb +37 -0
  99. data/lib/braintree/payment_method_customer_data_updated_metadata.rb +24 -0
  100. data/lib/braintree/payment_method_gateway.rb +221 -0
  101. data/lib/braintree/payment_method_nonce.rb +49 -0
  102. data/lib/braintree/payment_method_nonce_details.rb +40 -0
  103. data/lib/braintree/payment_method_nonce_details_payer_info.rb +32 -0
  104. data/lib/braintree/payment_method_nonce_gateway.rb +38 -0
  105. data/lib/braintree/payment_method_parser.rb +29 -0
  106. data/lib/braintree/paypal_account.rb +60 -0
  107. data/lib/braintree/paypal_account_gateway.rb +73 -0
  108. data/lib/braintree/paypal_payment_resource.rb +22 -0
  109. data/lib/braintree/paypal_payment_resource_gateway.rb +36 -0
  110. data/lib/braintree/plan.rb +62 -0
  111. data/lib/braintree/plan_gateway.rb +117 -0
  112. data/lib/braintree/processor_response_types.rb +7 -0
  113. data/lib/braintree/resource_collection.rb +12 -5
  114. data/lib/braintree/revoked_payment_method_metadata.rb +22 -0
  115. data/lib/braintree/risk_data/liability_shift.rb +22 -0
  116. data/lib/braintree/risk_data.rb +29 -0
  117. data/lib/braintree/samsung_pay_card.rb +85 -0
  118. data/lib/braintree/sepa_direct_debit_account.rb +60 -0
  119. data/lib/braintree/sepa_direct_debit_account_gateway.rb +25 -0
  120. data/lib/braintree/sepa_direct_debit_account_nonce_details.rb +28 -0
  121. data/lib/braintree/settlement_batch_summary.rb +25 -0
  122. data/lib/braintree/settlement_batch_summary_gateway.rb +27 -0
  123. data/lib/braintree/sha256_digest.rb +13 -0
  124. data/lib/braintree/signature_service.rb +19 -0
  125. data/lib/braintree/subscription/status_details.rb +20 -0
  126. data/lib/braintree/subscription.rb +67 -47
  127. data/lib/braintree/subscription_gateway.rb +43 -16
  128. data/lib/braintree/subscription_search.rb +2 -2
  129. data/lib/braintree/successful_result.rb +30 -10
  130. data/lib/braintree/test/authentication_id.rb +21 -0
  131. data/lib/braintree/test/credit_card.rb +76 -0
  132. data/lib/braintree/test/merchant_account.rb +12 -0
  133. data/lib/braintree/test/nonce.rb +81 -0
  134. data/lib/braintree/test/transaction_amounts.rb +3 -5
  135. data/lib/braintree/test/venmo_sdk.rb +21 -0
  136. data/lib/braintree/test_transaction.rb +19 -0
  137. data/lib/braintree/testing_gateway.rb +43 -0
  138. data/lib/braintree/three_d_secure_info.rb +53 -0
  139. data/lib/braintree/transaction/address_details.rb +27 -5
  140. data/lib/braintree/transaction/apple_pay_details.rb +35 -0
  141. data/lib/braintree/transaction/credit_card_details.rb +55 -4
  142. data/lib/braintree/transaction/customer_details.rb +11 -3
  143. data/lib/braintree/transaction/disbursement_details.rb +28 -0
  144. data/lib/braintree/transaction/google_pay_details.rb +42 -0
  145. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  146. data/lib/braintree/transaction/installment.rb +28 -0
  147. data/lib/braintree/transaction/local_payment_details.rb +27 -0
  148. data/lib/braintree/transaction/meta_checkout_card_details.rb +55 -0
  149. data/lib/braintree/transaction/meta_checkout_token_details.rb +58 -0
  150. data/lib/braintree/transaction/package_details.rb +19 -0
  151. data/lib/braintree/transaction/payment_receipt/card_present_data.rb +36 -0
  152. data/lib/braintree/transaction/payment_receipt/merchant_address.rb +19 -0
  153. data/lib/braintree/transaction/payment_receipt.rb +31 -0
  154. data/lib/braintree/transaction/paypal_details.rb +40 -0
  155. data/lib/braintree/transaction/paypal_here_details.rb +23 -0
  156. data/lib/braintree/transaction/samsung_pay_card_details.rb +50 -0
  157. data/lib/braintree/transaction/sepa_direct_debit_account_details.rb +27 -0
  158. data/lib/braintree/transaction/status_details.rb +6 -2
  159. data/lib/braintree/transaction/subscription_details.rb +5 -2
  160. data/lib/braintree/transaction/us_bank_account_details.rb +22 -0
  161. data/lib/braintree/transaction/venmo_account_details.rb +17 -0
  162. data/lib/braintree/transaction/visa_checkout_card_details.rb +51 -0
  163. data/lib/braintree/transaction.rb +293 -150
  164. data/lib/braintree/transaction_gateway.rb +303 -59
  165. data/lib/braintree/transaction_line_item.rb +43 -0
  166. data/lib/braintree/transaction_line_item_gateway.rb +19 -0
  167. data/lib/braintree/transaction_review.rb +18 -0
  168. data/lib/braintree/transaction_search.rb +17 -9
  169. data/lib/braintree/unknown_payment_method.rb +26 -0
  170. data/lib/braintree/us_bank_account.rb +57 -0
  171. data/lib/braintree/us_bank_account_gateway.rb +17 -0
  172. data/lib/braintree/us_bank_account_verification.rb +89 -0
  173. data/lib/braintree/us_bank_account_verification_gateway.rb +51 -0
  174. data/lib/braintree/us_bank_account_verification_search.rb +19 -0
  175. data/lib/braintree/util.rb +91 -11
  176. data/lib/braintree/validation_error.rb +14 -5
  177. data/lib/braintree/validation_error_collection.rb +5 -5
  178. data/lib/braintree/venmo_account.rb +34 -0
  179. data/lib/braintree/venmo_profile_data.rb +25 -0
  180. data/lib/braintree/version.rb +2 -2
  181. data/lib/braintree/visa_checkout_card.rb +90 -0
  182. data/lib/braintree/webhook_notification.rb +146 -0
  183. data/lib/braintree/webhook_notification_gateway.rb +46 -0
  184. data/lib/braintree/webhook_testing.rb +7 -0
  185. data/lib/braintree/webhook_testing_gateway.rb +1239 -0
  186. data/lib/braintree/xml/generator.rb +18 -10
  187. data/lib/braintree/xml/libxml.rb +1 -1
  188. data/lib/braintree/xml/parser.rb +24 -36
  189. data/lib/braintree/xml/rexml.rb +6 -7
  190. data/lib/braintree/xml.rb +1 -2
  191. data/lib/braintree.rb +186 -52
  192. data/lib/ssl/api_braintreegateway_com.ca.crt +474 -0
  193. data/spec/fixtures/files/bt_logo.png +0 -0
  194. data/spec/fixtures/files/gif_extension_bt_logo.gif +0 -0
  195. data/spec/fixtures/files/malformed_pdf.pdf +1 -0
  196. data/spec/fixtures/files/too_long.pdf +0 -0
  197. data/spec/integration/braintree/add_on_spec.rb +46 -0
  198. data/spec/integration/braintree/address_spec.rb +101 -178
  199. data/spec/integration/braintree/advanced_search_spec.rb +100 -97
  200. data/spec/integration/braintree/apple_pay_spec.rb +63 -0
  201. data/spec/integration/braintree/braintree_gateway_spec.rb +72 -0
  202. data/spec/integration/braintree/client_api/client_token_spec.rb +407 -0
  203. data/spec/integration/braintree/client_api/spec_helper.rb +300 -0
  204. data/spec/integration/braintree/credit_card_spec.rb +885 -654
  205. data/spec/integration/braintree/credit_card_verification_search_spec.rb +193 -0
  206. data/spec/integration/braintree/credit_card_verification_spec.rb +473 -0
  207. data/spec/integration/braintree/customer_search_spec.rb +69 -21
  208. data/spec/integration/braintree/customer_session_spec.rb +143 -0
  209. data/spec/integration/braintree/customer_spec.rb +1437 -518
  210. data/spec/integration/braintree/disbursement_spec.rb +31 -0
  211. data/spec/integration/braintree/discount_spec.rb +34 -0
  212. data/spec/integration/braintree/dispute_search_spec.rb +165 -0
  213. data/spec/integration/braintree/dispute_spec.rb +333 -0
  214. data/spec/integration/braintree/document_upload_spec.rb +87 -0
  215. data/spec/integration/braintree/error_codes_spec.rb +3 -3
  216. data/spec/integration/braintree/exchange_rate_quote_spec.rb +97 -0
  217. data/spec/integration/braintree/graphql_client_spec.rb +72 -0
  218. data/spec/integration/braintree/http_spec.rb +106 -56
  219. data/spec/integration/braintree/merchant_account_spec.rb +603 -0
  220. data/spec/integration/braintree/merchant_spec.rb +227 -0
  221. data/spec/integration/braintree/oauth_spec.rb +225 -0
  222. data/spec/integration/braintree/package_tracking_spec.rb +130 -0
  223. data/spec/integration/braintree/payment_method_nonce_spec.rb +345 -0
  224. data/spec/integration/braintree/payment_method_spec.rb +2146 -0
  225. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +325 -0
  226. data/spec/integration/braintree/paypal_account_spec.rb +299 -0
  227. data/spec/integration/braintree/paypal_payment_resource_spec.rb +141 -0
  228. data/spec/integration/braintree/plan_spec.rb +136 -0
  229. data/spec/integration/braintree/samsung_pay_card_spec.rb +146 -0
  230. data/spec/integration/braintree/sepa_direct_debit_account_spec.rb +194 -0
  231. data/spec/integration/braintree/settlement_batch_summary_spec.rb +62 -0
  232. data/spec/integration/braintree/subscription_spec.rb +785 -431
  233. data/spec/integration/braintree/test/transaction_amounts_spec.rb +4 -4
  234. data/spec/integration/braintree/test_transaction_spec.rb +145 -0
  235. data/spec/integration/braintree/transaction_line_item_spec.rb +44 -0
  236. data/spec/integration/braintree/transaction_search_spec.rb +745 -156
  237. data/spec/integration/braintree/transaction_spec.rb +7452 -1288
  238. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +196 -0
  239. data/spec/integration/braintree/us_bank_account_spec.rb +113 -0
  240. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +178 -0
  241. data/spec/integration/braintree/us_bank_account_verification_spec.rb +240 -0
  242. data/spec/integration/braintree/visa_checkout_card_spec.rb +110 -0
  243. data/spec/integration/spec_helper.rb +61 -5
  244. data/spec/oauth_test_helper.rb +17 -0
  245. data/spec/script/httpsd.rb +6 -6
  246. data/spec/spec.opts +4 -0
  247. data/spec/spec_helper.rb +77 -21
  248. data/spec/ssl/certificate.crt +17 -0
  249. data/spec/ssl/geotrust_global.crt +20 -0
  250. data/spec/ssl/privateKey.key +15 -0
  251. data/spec/unit/braintree/address_spec.rb +27 -16
  252. data/spec/unit/braintree/apple_pay_card_spec.rb +133 -0
  253. data/spec/unit/braintree/base_module_spec.rb +4 -4
  254. data/spec/unit/braintree/client_token_spec.rb +37 -0
  255. data/spec/unit/braintree/configuration_spec.rb +293 -43
  256. data/spec/unit/braintree/credentials_parser_spec.rb +81 -0
  257. data/spec/unit/braintree/credit_card_spec.rb +138 -47
  258. data/spec/unit/braintree/credit_card_verification_gateway_spec.rb +56 -0
  259. data/spec/unit/braintree/credit_card_verification_search_spec.rb +79 -0
  260. data/spec/unit/braintree/credit_card_verification_spec.rb +132 -6
  261. data/spec/unit/braintree/customer_session_gateway_spec.rb +120 -0
  262. data/spec/unit/braintree/customer_spec.rb +196 -40
  263. data/spec/unit/braintree/digest_spec.rb +16 -3
  264. data/spec/unit/braintree/disbursement_spec.rb +131 -0
  265. data/spec/unit/braintree/dispute_search_spec.rb +66 -0
  266. data/spec/unit/braintree/dispute_spec.rb +479 -0
  267. data/spec/unit/braintree/document_upload_spec.rb +35 -0
  268. data/spec/unit/braintree/enriched_customer_data_spec.rb +41 -0
  269. data/spec/unit/braintree/error_result_spec.rb +11 -11
  270. data/spec/unit/braintree/errors_spec.rb +17 -17
  271. data/spec/unit/braintree/exchange_rate_quote_input_spec.rb +42 -0
  272. data/spec/unit/braintree/exchange_rate_quote_request_spec.rb +82 -0
  273. data/spec/unit/braintree/exchange_rate_quote_response_spec.rb +52 -0
  274. data/spec/unit/braintree/exchange_rate_quote_spec.rb +42 -0
  275. data/spec/unit/braintree/exchange_rate_spec.rb +23 -0
  276. data/spec/unit/braintree/google_pay_card_spec.rb +8 -0
  277. data/spec/unit/braintree/graphql/create_customer_session_input_spec.rb +81 -0
  278. data/spec/unit/braintree/graphql/customer_recommendations_input_spec.rb +110 -0
  279. data/spec/unit/braintree/graphql/customer_session_input_spec.rb +81 -0
  280. data/spec/unit/braintree/graphql/phone_input_spec.rb +51 -0
  281. data/spec/unit/braintree/graphql/update_customer_session_input_spec.rb +93 -0
  282. data/spec/unit/braintree/graphql_client_spec.rb +37 -0
  283. data/spec/unit/braintree/http_spec.rb +164 -2
  284. data/spec/unit/braintree/local_payment_completed_spec.rb +90 -0
  285. data/spec/unit/braintree/local_payment_expired_spec.rb +24 -0
  286. data/spec/unit/braintree/local_payment_funded_spec.rb +34 -0
  287. data/spec/unit/braintree/merchant_account_spec.rb +33 -0
  288. data/spec/unit/braintree/meta_checkout_card_details_spec.rb +60 -0
  289. data/spec/unit/braintree/meta_checkout_card_spec.rb +62 -0
  290. data/spec/unit/braintree/meta_checkout_token_details_spec.rb +63 -0
  291. data/spec/unit/braintree/meta_checkout_token_spec.rb +65 -0
  292. data/spec/unit/braintree/modification_spec.rb +7 -0
  293. data/spec/unit/braintree/package_tracking_spec.rb +77 -0
  294. data/spec/unit/braintree/payment_method_customer_data_updated_metadata_spec.rb +45 -0
  295. data/spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb +31 -0
  296. data/spec/unit/braintree/payment_method_nonce_details_spec.rb +51 -0
  297. data/spec/unit/braintree/payment_method_nonce_spec.rb +43 -0
  298. data/spec/unit/braintree/payment_method_spec.rb +135 -0
  299. data/spec/unit/braintree/paypal_account_spec.rb +53 -0
  300. data/spec/unit/braintree/paypal_payment_resource_spec.rb +125 -0
  301. data/spec/unit/braintree/resource_collection_spec.rb +44 -3
  302. data/spec/unit/braintree/risk_data/liability_shift.rb +26 -0
  303. data/spec/unit/braintree/risk_data_spec.rb +55 -0
  304. data/spec/unit/braintree/sepa_debit_account_nonce_details_spec.rb +29 -0
  305. data/spec/unit/braintree/sepa_debit_account_spec.rb +86 -0
  306. data/spec/unit/braintree/sha256_digest_spec.rb +11 -0
  307. data/spec/unit/braintree/signature_service_spec.rb +23 -0
  308. data/spec/unit/braintree/subscription_search_spec.rb +25 -18
  309. data/spec/unit/braintree/subscription_spec.rb +34 -7
  310. data/spec/unit/braintree/successful_result_spec.rb +9 -9
  311. data/spec/unit/braintree/three_d_secure_info_spec.rb +69 -0
  312. data/spec/unit/braintree/transaction/apple_pay_details_spec.rb +8 -0
  313. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +34 -6
  314. data/spec/unit/braintree/transaction/customer_details_spec.rb +3 -2
  315. data/spec/unit/braintree/transaction/deposit_details_spec.rb +18 -0
  316. data/spec/unit/braintree/transaction/google_pay_details_spec.rb +8 -0
  317. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  318. data/spec/unit/braintree/transaction/local_payment_details_spec.rb +36 -0
  319. data/spec/unit/braintree/transaction/meta_checkout_card_details_spec.rb +8 -0
  320. data/spec/unit/braintree/transaction/meta_checkout_token_details_spec.rb +8 -0
  321. data/spec/unit/braintree/transaction/payment_receipt_spec.rb +73 -0
  322. data/spec/unit/braintree/transaction/paypal_details_spec.rb +68 -0
  323. data/spec/unit/braintree/transaction/sepa_direct_debit_account_details_spec.rb +33 -0
  324. data/spec/unit/braintree/transaction/visa_checkout_card_details_spec.rb +8 -0
  325. data/spec/unit/braintree/transaction_gateway_spec.rb +150 -0
  326. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  327. data/spec/unit/braintree/transaction_spec.rb +366 -52
  328. data/spec/unit/braintree/unknown_payment_method_spec.rb +33 -0
  329. data/spec/unit/braintree/us_bank_account_spec.rb +13 -0
  330. data/spec/unit/braintree/us_bank_account_verification_search_spec.rb +60 -0
  331. data/spec/unit/braintree/us_bank_account_verification_spec.rb +98 -0
  332. data/spec/unit/braintree/util_spec.rb +199 -39
  333. data/spec/unit/braintree/validation_error_collection_spec.rb +336 -133
  334. data/spec/unit/braintree/validation_error_spec.rb +4 -4
  335. data/spec/unit/braintree/venmo_profile_data_spec.rb +43 -0
  336. data/spec/unit/braintree/visa_checkout_card_spec.rb +8 -0
  337. data/spec/unit/braintree/webhook_notification_spec.rb +977 -0
  338. data/spec/unit/braintree/xml/libxml_spec.rb +5 -5
  339. data/spec/unit/braintree/xml/parser_spec.rb +39 -5
  340. data/spec/unit/braintree/xml/rexml_spec.rb +5 -5
  341. data/spec/unit/braintree/xml_spec.rb +39 -32
  342. data/spec/unit/braintree_spec.rb +3 -2
  343. data/spec/unit/credit_card_details_spec.rb +8 -0
  344. metadata +314 -73
  345. data/README.rdoc +0 -80
  346. data/lib/braintree/test/credit_card_numbers.rb +0 -52
  347. data/lib/braintree/transparent_redirect.rb +0 -51
  348. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  349. data/lib/ssl/sandbox_braintreegateway_com.ca.crt +0 -19
  350. data/lib/ssl/www_braintreegateway_com.ca.crt +0 -202
  351. data/spec/hacks/tcp_socket.rb +0 -18
  352. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -236
  353. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -160
@@ -1,4 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
2
3
 
3
4
  describe Braintree::CreditCard do
4
5
  describe "self.create" do
@@ -14,14 +15,29 @@ describe Braintree::CreditCard do
14
15
  :customer_id => customer.id,
15
16
  :number => Braintree::Test::CreditCardNumbers::Visa,
16
17
  :expiration_date => "05/2009",
17
- :cvv => "100"
18
+ :cvv => "100",
18
19
  )
19
- result.success?.should == true
20
+ expect(result.success?).to eq(true)
20
21
  credit_card = result.credit_card
21
- credit_card.token.should =~ /\A\w{4,5}\z/
22
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
23
- credit_card.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
24
- credit_card.expiration_date.should == "05/2009"
22
+ expect(credit_card.token).to match(/\A\w{4,}\z/)
23
+ expect(credit_card.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
24
+ expect(credit_card.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
25
+ expect(credit_card.expiration_date).to eq("05/2009")
26
+ expect(credit_card.unique_number_identifier).to match(/\A\w{32}\z/)
27
+ expect(credit_card.venmo_sdk?).to eq(false)
28
+ expect(credit_card.image_url).not_to be_nil
29
+ end
30
+
31
+ it "supports creation of cards with security params" do
32
+ customer = Braintree::Customer.create!
33
+ result = Braintree::CreditCard.create(
34
+ :customer_id => customer.id,
35
+ :number => Braintree::Test::CreditCardNumbers::Visa,
36
+ :expiration_date => "05/2009",
37
+ :cvv => "100",
38
+ :device_data => "device_data",
39
+ )
40
+ expect(result.success?).to eq(true)
25
41
  end
26
42
 
27
43
  it "can provide expiration month and year separately" do
@@ -30,31 +46,31 @@ describe Braintree::CreditCard do
30
46
  :customer_id => customer.id,
31
47
  :number => Braintree::Test::CreditCardNumbers::Visa,
32
48
  :expiration_month => "05",
33
- :expiration_year => "2012"
49
+ :expiration_year => "2012",
34
50
  )
35
- result.success?.should == true
51
+ expect(result.success?).to eq(true)
36
52
  credit_card = result.credit_card
37
- credit_card.expiration_month.should == "05"
38
- credit_card.expiration_year.should == "2012"
39
- credit_card.expiration_date.should == "05/2012"
53
+ expect(credit_card.expiration_month).to eq("05")
54
+ expect(credit_card.expiration_year).to eq("2012")
55
+ expect(credit_card.expiration_date).to eq("05/2012")
40
56
  end
41
57
 
42
58
  it "can specify the desired token" do
43
- token = "token_#{rand(1_000_000)}"
59
+ token = "token_#{rand(10**10)}"
44
60
  customer = Braintree::Customer.create!
45
61
  result = Braintree::CreditCard.create(
46
62
  :customer_id => customer.id,
47
63
  :number => Braintree::Test::CreditCardNumbers::Visa,
48
64
  :expiration_date => "05/2009",
49
65
  :cvv => "100",
50
- :token => token
66
+ :token => token,
51
67
  )
52
- result.success?.should == true
68
+ expect(result.success?).to eq(true)
53
69
  credit_card = result.credit_card
54
- credit_card.token.should == token
55
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
56
- credit_card.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
57
- credit_card.expiration_date.should == "05/2009"
70
+ expect(credit_card.token).to eq(token)
71
+ expect(credit_card.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
72
+ expect(credit_card.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
73
+ expect(credit_card.expiration_date).to eq("05/2009")
58
74
  end
59
75
 
60
76
  it "accepts billing_address_id" do
@@ -65,12 +81,12 @@ describe Braintree::CreditCard do
65
81
  :customer_id => customer.id,
66
82
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
67
83
  :expiration_date => "05/2009",
68
- :billing_address_id => address.id
84
+ :billing_address_id => address.id,
69
85
  ).credit_card
70
86
 
71
- credit_card.billing_address.id.should == address.id
72
- credit_card.billing_address.first_name.should == "Bobby"
73
- credit_card.billing_address.last_name.should == "Tables"
87
+ expect(credit_card.billing_address.id).to eq(address.id)
88
+ expect(credit_card.billing_address.first_name).to eq("Bobby")
89
+ expect(credit_card.billing_address.last_name).to eq("Tables")
74
90
  end
75
91
 
76
92
  it "accepts empty options hash" do
@@ -79,9 +95,9 @@ describe Braintree::CreditCard do
79
95
  :customer_id => customer.id,
80
96
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
81
97
  :expiration_date => "05/2009",
82
- :options => {}
98
+ :options => {},
83
99
  )
84
- result.success?.should == true
100
+ expect(result.success?).to eq(true)
85
101
  end
86
102
 
87
103
  it "verifies the credit card if options[verify_card]=true" do
@@ -90,16 +106,97 @@ describe Braintree::CreditCard do
90
106
  :customer_id => customer.id,
91
107
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
92
108
  :expiration_date => "05/2009",
93
- :options => {:verify_card => true}
109
+ :options => {:verify_card => true},
94
110
  )
95
- result.success?.should == false
96
- result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
97
- result.credit_card_verification.processor_response_code.should == "2000"
98
- result.credit_card_verification.processor_response_text.should == "Do Not Honor"
99
- result.credit_card_verification.cvv_response_code.should == "I"
100
- result.credit_card_verification.avs_error_response_code.should == nil
101
- result.credit_card_verification.avs_postal_code_response_code.should == "I"
102
- result.credit_card_verification.avs_street_address_response_code.should == "I"
111
+ expect(result.success?).to eq(false)
112
+ expect(result.credit_card_verification.status).to eq(Braintree::CreditCardVerification::Status::ProcessorDeclined)
113
+ expect(result.credit_card_verification.processor_response_code).to eq("2000")
114
+ expect(result.credit_card_verification.processor_response_text).to eq("Do Not Honor")
115
+ expect(result.credit_card_verification.cvv_response_code).to eq("I")
116
+ expect(result.credit_card_verification.avs_error_response_code).to eq(nil)
117
+ expect(result.credit_card_verification.avs_postal_code_response_code).to eq("I")
118
+ expect(result.credit_card_verification.avs_street_address_response_code).to eq("I")
119
+ end
120
+
121
+ it "allows passing a specific verification amount" do
122
+ customer = Braintree::Customer.create!
123
+ result = Braintree::CreditCard.create(
124
+ :customer_id => customer.id,
125
+ :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
126
+ :expiration_date => "05/2009",
127
+ :options => {:verify_card => true, :verification_amount => "100.00"},
128
+ )
129
+ expect(result.success?).to eq(false)
130
+ expect(result.credit_card_verification.status).to eq(Braintree::CreditCardVerification::Status::ProcessorDeclined)
131
+ expect(result.credit_card_verification.processor_response_code).to eq("2000")
132
+ expect(result.credit_card_verification.processor_response_text).to eq("Do Not Honor")
133
+ expect(result.credit_card_verification.cvv_response_code).to eq("I")
134
+ expect(result.credit_card_verification.avs_error_response_code).to eq(nil)
135
+ expect(result.credit_card_verification.avs_postal_code_response_code).to eq("I")
136
+ expect(result.credit_card_verification.avs_street_address_response_code).to eq("I")
137
+ end
138
+
139
+ it "returns risk data on verification on credit_card create" do
140
+ with_fraud_protection_enterprise_merchant do
141
+ customer = Braintree::Customer.create!
142
+ credit_card = Braintree::CreditCard.create!(
143
+ :cardholder_name => "Original Holder",
144
+ :customer_id => customer.id,
145
+ :cvv => "123",
146
+ :number => Braintree::Test::CreditCardNumbers::Visa,
147
+ :expiration_date => "05/2020",
148
+ :options => {:verify_card => true},
149
+ )
150
+ verification = credit_card.verification
151
+ expect(verification.risk_data.id).not_to be_nil
152
+ expect(verification.risk_data.decision).not_to be_nil
153
+ expect(verification.risk_data.decision_reasons).not_to be_nil
154
+ expect(verification.risk_data).to respond_to(:device_data_captured)
155
+ expect(verification.risk_data).to respond_to(:fraud_service_provider)
156
+ expect(verification.risk_data).to respond_to(:transaction_risk_score)
157
+ end
158
+ end
159
+
160
+ it "includes risk data when skip_advanced_fraud_checking is false" do
161
+ with_fraud_protection_enterprise_merchant do
162
+ customer = Braintree::Customer.create!
163
+ result = Braintree::CreditCard.create(
164
+ :cardholder_name => "Original Holder",
165
+ :customer_id => customer.id,
166
+ :cvv => "123",
167
+ :number => Braintree::Test::CreditCardNumbers::Visa,
168
+ :expiration_date => "05/2020",
169
+ :options => {
170
+ :skip_advanced_fraud_checking => false,
171
+ :verify_card => true,
172
+ },
173
+ )
174
+
175
+ expect(result).to be_success
176
+ verification = result.credit_card.verification
177
+ expect(verification.risk_data).not_to be_nil
178
+ end
179
+ end
180
+
181
+ it "does not include risk data when skip_advanced_fraud_checking is true" do
182
+ with_fraud_protection_enterprise_merchant do
183
+ customer = Braintree::Customer.create!
184
+ result = Braintree::CreditCard.create(
185
+ :cardholder_name => "Original Holder",
186
+ :customer_id => customer.id,
187
+ :cvv => "123",
188
+ :number => Braintree::Test::CreditCardNumbers::Visa,
189
+ :expiration_date => "05/2020",
190
+ :options => {
191
+ :skip_advanced_fraud_checking => true,
192
+ :verify_card => true,
193
+ },
194
+ )
195
+
196
+ expect(result).to be_success
197
+ verification = result.credit_card.verification
198
+ expect(verification.risk_data).to be_nil
199
+ end
103
200
  end
104
201
 
105
202
  it "exposes the gateway rejection reason on verification" do
@@ -118,10 +215,10 @@ describe Braintree::CreditCard do
118
215
  :number => Braintree::Test::CreditCardNumbers::Visa,
119
216
  :expiration_date => "05/2009",
120
217
  :cvv => "200",
121
- :options => {:verify_card => true}
218
+ :options => {:verify_card => true},
122
219
  )
123
- result.success?.should == false
124
- result.credit_card_verification.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::CVV
220
+ expect(result.success?).to eq(false)
221
+ expect(result.credit_card_verification.gateway_rejection_reason).to eq(Braintree::CreditCardVerification::GatewayRejectionReason::CVV)
125
222
  ensure
126
223
  Braintree::Configuration.merchant_id = old_merchant
127
224
  Braintree::Configuration.public_key = old_public_key
@@ -129,6 +226,24 @@ describe Braintree::CreditCard do
129
226
  end
130
227
  end
131
228
 
229
+ it "verifies the credit card if options[verify_card]=true" do
230
+ customer = Braintree::Customer.create!
231
+ result = Braintree::CreditCard.create(
232
+ :customer_id => customer.id,
233
+ :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
234
+ :expiration_date => "05/2009",
235
+ :options => {:verify_card => true, :verification_amount => "1.01"},
236
+ )
237
+ expect(result.success?).to eq(false)
238
+ expect(result.credit_card_verification.status).to eq(Braintree::CreditCardVerification::Status::ProcessorDeclined)
239
+ expect(result.credit_card_verification.processor_response_code).to eq("2000")
240
+ expect(result.credit_card_verification.processor_response_text).to eq("Do Not Honor")
241
+ expect(result.credit_card_verification.cvv_response_code).to eq("I")
242
+ expect(result.credit_card_verification.avs_error_response_code).to eq(nil)
243
+ expect(result.credit_card_verification.avs_postal_code_response_code).to eq("I")
244
+ expect(result.credit_card_verification.avs_street_address_response_code).to eq("I")
245
+ end
246
+
132
247
  it "allows user to specify merchant account for verification" do
133
248
  customer = Braintree::Customer.create!
134
249
  result = Braintree::CreditCard.create(
@@ -138,10 +253,10 @@ describe Braintree::CreditCard do
138
253
  :options => {
139
254
  :verify_card => true,
140
255
  :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
141
- }
256
+ },
142
257
  )
143
- result.success?.should == false
144
- result.credit_card_verification.merchant_account_id.should == SpecHelper::NonDefaultMerchantAccountId
258
+ expect(result.success?).to eq(false)
259
+ expect(result.credit_card_verification.merchant_account_id).to eq(SpecHelper::NonDefaultMerchantAccountId)
145
260
  end
146
261
 
147
262
  it "does not verify the card if options[verify_card]=false" do
@@ -150,9 +265,72 @@ describe Braintree::CreditCard do
150
265
  :customer_id => customer.id,
151
266
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
152
267
  :expiration_date => "05/2009",
153
- :options => {:verify_card => false}
268
+ :options => {:verify_card => false},
269
+ )
270
+ expect(result.success?).to eq(true)
271
+ end
272
+
273
+ it "validates presence of three_d_secure_version in 3ds pass thru params" do
274
+ customer = Braintree::Customer.create!
275
+ result = Braintree::CreditCard.create(
276
+ :customer_id => customer.id,
277
+ :payment_method_nonce => Braintree::Test::Nonce::Transactable,
278
+ :three_d_secure_pass_thru => {
279
+ :eci_flag => "05",
280
+ :cavv => "some_cavv",
281
+ :xid => "some_xid",
282
+ :authentication_response => "Y",
283
+ :directory_response => "Y",
284
+ :cavv_algorithm => "2",
285
+ :ds_transaction_id => "some_ds_transaction_id",
286
+ },
287
+ :options => {:verify_card => true},
154
288
  )
155
- result.success?.should == true
289
+ expect(result).not_to be_success
290
+ error = result.errors.for(:verification).first
291
+ expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsRequired)
292
+ expect(error.message).to eq("ThreeDSecureVersion is required.")
293
+ end
294
+
295
+ it "accepts three_d_secure pass thru params in the request" do
296
+ customer = Braintree::Customer.create!
297
+ result = Braintree::CreditCard.create(
298
+ :customer_id => customer.id,
299
+ :payment_method_nonce => Braintree::Test::Nonce::Transactable,
300
+ :three_d_secure_pass_thru => {
301
+ :eci_flag => "05",
302
+ :cavv => "some_cavv",
303
+ :xid => "some_xid",
304
+ :three_d_secure_version => "1.0.2",
305
+ :authentication_response => "Y",
306
+ :directory_response => "Y",
307
+ :cavv_algorithm => "2",
308
+ :ds_transaction_id => "some_ds_transaction_id",
309
+ },
310
+ :options => {:verify_card => true},
311
+ )
312
+ expect(result.success?).to eq(true)
313
+ end
314
+
315
+ it "returns 3DS info on cc verification" do
316
+ customer = Braintree::Customer.create!
317
+ result = Braintree::CreditCard.create(
318
+ :customer_id => customer.id,
319
+ :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
320
+ :options => {:verify_card => true},
321
+ )
322
+ expect(result.success?).to eq(true)
323
+
324
+ three_d_secure_info = result.credit_card.verification.three_d_secure_info
325
+ expect(three_d_secure_info.status).to eq("authenticate_successful")
326
+ expect(three_d_secure_info).to be_liability_shifted
327
+ expect(three_d_secure_info).to be_liability_shift_possible
328
+ expect(three_d_secure_info.enrolled).to be_a(String)
329
+ expect(three_d_secure_info.cavv).to be_a(String)
330
+ expect(three_d_secure_info.xid).to be_a(String)
331
+ expect(three_d_secure_info.eci_flag).to be_a(String)
332
+ expect(three_d_secure_info.three_d_secure_version).to be_a(String)
333
+ expect(three_d_secure_info.three_d_secure_authentication_id).to be_a(String)
156
334
  end
157
335
 
158
336
  it "adds credit card with billing address to customer" do
@@ -166,12 +344,12 @@ describe Braintree::CreditCard do
166
344
  :locality => "Chicago",
167
345
  :region => "Illinois",
168
346
  :postal_code => "60622"
169
- }
347
+ },
170
348
  )
171
- result.success?.should == true
349
+ expect(result.success?).to eq(true)
172
350
  credit_card = result.credit_card
173
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
174
- credit_card.billing_address.street_address.should == "123 Abc Way"
351
+ expect(credit_card.bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
352
+ expect(credit_card.billing_address.street_address).to eq("123 Abc Way")
175
353
  end
176
354
 
177
355
  it "adds credit card with billing using country_code" do
@@ -185,14 +363,14 @@ describe Braintree::CreditCard do
185
363
  :country_code_alpha2 => "US",
186
364
  :country_code_alpha3 => "USA",
187
365
  :country_code_numeric => "840"
188
- }
366
+ },
189
367
  )
190
- result.success?.should == true
368
+ expect(result.success?).to eq(true)
191
369
  credit_card = result.credit_card
192
- credit_card.billing_address.country_name.should == "United States of America"
193
- credit_card.billing_address.country_code_alpha2.should == "US"
194
- credit_card.billing_address.country_code_alpha3.should == "USA"
195
- credit_card.billing_address.country_code_numeric.should == "840"
370
+ expect(credit_card.billing_address.country_name).to eq("United States of America")
371
+ expect(credit_card.billing_address.country_code_alpha2).to eq("US")
372
+ expect(credit_card.billing_address.country_code_alpha3).to eq("USA")
373
+ expect(credit_card.billing_address.country_code_numeric).to eq("840")
196
374
  end
197
375
 
198
376
  it "returns an error when given inconsistent country information" do
@@ -204,10 +382,10 @@ describe Braintree::CreditCard do
204
382
  :billing_address => {
205
383
  :country_name => "Mexico",
206
384
  :country_code_alpha2 => "US"
207
- }
385
+ },
208
386
  )
209
- result.success?.should == false
210
- result.errors.for(:credit_card).for(:billing_address).on(:base).map { |e| e.code }.should include(Braintree::ErrorCodes::Address::InconsistentCountry)
387
+ expect(result.success?).to eq(false)
388
+ expect(result.errors.for(:credit_card).for(:billing_address).on(:base).map { |e| e.code }).to include(Braintree::ErrorCodes::Address::InconsistentCountry)
211
389
  end
212
390
 
213
391
  it "returns an error response if unsuccessful" do
@@ -215,10 +393,10 @@ describe Braintree::CreditCard do
215
393
  result = Braintree::CreditCard.create(
216
394
  :customer_id => customer.id,
217
395
  :number => Braintree::Test::CreditCardNumbers::Visa,
218
- :expiration_date => "invalid_date"
396
+ :expiration_date => "invalid_date",
219
397
  )
220
- result.success?.should == false
221
- result.errors.for(:credit_card).on(:expiration_date)[0].message.should == "Expiration date is invalid."
398
+ expect(result.success?).to eq(false)
399
+ expect(result.errors.for(:credit_card).on(:expiration_date)[0].message).to eq("Expiration date is invalid.")
222
400
  end
223
401
 
224
402
  it "can set the default flag" do
@@ -226,9 +404,9 @@ describe Braintree::CreditCard do
226
404
  card1 = Braintree::CreditCard.create(
227
405
  :customer_id => customer.id,
228
406
  :number => Braintree::Test::CreditCardNumbers::Visa,
229
- :expiration_date => "05/2009"
407
+ :expiration_date => "05/2009",
230
408
  ).credit_card
231
- card1.should be_default
409
+ expect(card1).to be_default
232
410
 
233
411
  card2 = Braintree::CreditCard.create(
234
412
  :customer_id => customer.id,
@@ -236,11 +414,281 @@ describe Braintree::CreditCard do
236
414
  :expiration_date => "05/2009",
237
415
  :options => {
238
416
  :make_default => true
239
- }
417
+ },
240
418
  ).credit_card
241
- card2.should be_default
419
+ expect(card2).to be_default
420
+
421
+ expect(Braintree::CreditCard.find(card1.token)).not_to be_default
422
+ end
423
+
424
+ it "can set the network transaction identifier when creating a credit card" do
425
+ customer = Braintree::Customer.create!
426
+
427
+ result = Braintree::CreditCard.create(
428
+ :customer_id => customer.id,
429
+ :number => Braintree::Test::CreditCardNumbers::Visa,
430
+ :expiration_date => "05/2009",
431
+ :external_vault => {
432
+ :network_transaction_id => "MCC123456789",
433
+ },
434
+ )
242
435
 
243
- Braintree::CreditCard.find(card1.token).should_not be_default
436
+ expect(result.success?).to eq(true)
437
+ end
438
+
439
+ context "card type indicators" do
440
+ it "sets the prepaid field if the card is prepaid" do
441
+ customer = Braintree::Customer.create!
442
+ result = Braintree::CreditCard.create(
443
+ :customer_id => customer.id,
444
+ :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Prepaid,
445
+ :expiration_date => "05/2014",
446
+ :options => {:verify_card => true},
447
+ )
448
+ credit_card = result.credit_card
449
+ expect(credit_card.prepaid).to eq(Braintree::CreditCard::Prepaid::Yes)
450
+ end
451
+
452
+ it "sets the prepaid reloadable field if the card is prepaid reloadable" do
453
+ customer = Braintree::Customer.create!
454
+ result = Braintree::CreditCard.create(
455
+ :customer_id => customer.id,
456
+ :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::PrepaidReloadable,
457
+ :expiration_date => "05/2014",
458
+ :options => {:verify_card => true},
459
+ )
460
+ credit_card = result.credit_card
461
+ expect(credit_card.prepaid_reloadable).to eq(Braintree::CreditCard::PrepaidReloadable::Yes)
462
+ end
463
+
464
+ it "sets the healthcare field if the card is healthcare" do
465
+ customer = Braintree::Customer.create!
466
+ result = Braintree::CreditCard.create(
467
+ :customer_id => customer.id,
468
+ :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Healthcare,
469
+ :expiration_date => "05/2014",
470
+ :options => {:verify_card => true},
471
+ )
472
+ credit_card = result.credit_card
473
+ expect(credit_card.healthcare).to eq(Braintree::CreditCard::Healthcare::Yes)
474
+ expect(credit_card.product_id).to eq("J3")
475
+ end
476
+
477
+ it "sets the durbin regulated field if the card is durbin regulated" do
478
+ customer = Braintree::Customer.create!
479
+ result = Braintree::CreditCard.create(
480
+ :customer_id => customer.id,
481
+ :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::DurbinRegulated,
482
+ :expiration_date => "05/2014",
483
+ :options => {:verify_card => true},
484
+ )
485
+ credit_card = result.credit_card
486
+ expect(credit_card.durbin_regulated).to eq(Braintree::CreditCard::DurbinRegulated::Yes)
487
+ end
488
+
489
+ it "sets the country of issuance field" do
490
+ customer = Braintree::Customer.create!
491
+ result = Braintree::CreditCard.create(
492
+ :customer_id => customer.id,
493
+ :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::CountryOfIssuance,
494
+ :expiration_date => "05/2014",
495
+ :options => {:verify_card => true},
496
+ )
497
+ credit_card = result.credit_card
498
+ expect(credit_card.country_of_issuance).to eq(Braintree::Test::CreditCardDefaults::CountryOfIssuance)
499
+ end
500
+
501
+ it "sets the issuing bank field" do
502
+ customer = Braintree::Customer.create!
503
+ result = Braintree::CreditCard.create(
504
+ :customer_id => customer.id,
505
+ :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::IssuingBank,
506
+ :expiration_date => "05/2014",
507
+ :options => {:verify_card => true},
508
+ )
509
+ credit_card = result.credit_card
510
+ expect(credit_card.issuing_bank).to eq(Braintree::Test::CreditCardDefaults::IssuingBank)
511
+ end
512
+
513
+ it "sets the payroll field if the card is payroll" do
514
+ customer = Braintree::Customer.create!
515
+ result = Braintree::CreditCard.create(
516
+ :customer_id => customer.id,
517
+ :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Payroll,
518
+ :expiration_date => "05/2014",
519
+ :options => {:verify_card => true},
520
+ )
521
+ credit_card = result.credit_card
522
+ expect(credit_card.payroll).to eq(Braintree::CreditCard::Payroll::Yes)
523
+ expect(credit_card.product_id).to eq("MSA")
524
+ end
525
+
526
+ it "sets the debit field if the card is debit" do
527
+ customer = Braintree::Customer.create!
528
+ result = Braintree::CreditCard.create(
529
+ :customer_id => customer.id,
530
+ :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Debit,
531
+ :expiration_date => "05/2014",
532
+ :options => {:verify_card => true},
533
+ )
534
+ credit_card = result.credit_card
535
+ expect(credit_card.debit).to eq(Braintree::CreditCard::Debit::Yes)
536
+ end
537
+
538
+ it "sets the commercial field if the card is commercial" do
539
+ customer = Braintree::Customer.create!
540
+ result = Braintree::CreditCard.create(
541
+ :customer_id => customer.id,
542
+ :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Commercial,
543
+ :expiration_date => "05/2014",
544
+ :options => {:verify_card => true},
545
+ )
546
+ credit_card = result.credit_card
547
+ expect(credit_card.commercial).to eq(Braintree::CreditCard::Commercial::Yes)
548
+ end
549
+
550
+ it "sets negative card type identifiers" do
551
+ customer = Braintree::Customer.create!
552
+ result = Braintree::CreditCard.create(
553
+ :customer_id => customer.id,
554
+ :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::No,
555
+ :expiration_date => "05/2014",
556
+ :options => {:verify_card => true},
557
+ )
558
+ credit_card = result.credit_card
559
+ expect(credit_card.prepaid).to eq(Braintree::CreditCard::Prepaid::No)
560
+ expect(credit_card.commercial).to eq(Braintree::CreditCard::Prepaid::No)
561
+ expect(credit_card.payroll).to eq(Braintree::CreditCard::Prepaid::No)
562
+ expect(credit_card.debit).to eq(Braintree::CreditCard::Prepaid::No)
563
+ expect(credit_card.durbin_regulated).to eq(Braintree::CreditCard::Prepaid::No)
564
+ expect(credit_card.healthcare).to eq(Braintree::CreditCard::Prepaid::No)
565
+ expect(credit_card.product_id).to eq("MSB")
566
+ end
567
+
568
+ it "doesn't set the card type identifiers for an un-identified card" do
569
+ customer = Braintree::Customer.create!
570
+ result = Braintree::CreditCard.create(
571
+ :customer_id => customer.id,
572
+ :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Unknown,
573
+ :expiration_date => "05/2014",
574
+ :options => {:verify_card => true},
575
+ )
576
+ credit_card = result.credit_card
577
+ expect(credit_card.prepaid).to eq(Braintree::CreditCard::Prepaid::Unknown)
578
+ expect(credit_card.commercial).to eq(Braintree::CreditCard::Prepaid::Unknown)
579
+ expect(credit_card.payroll).to eq(Braintree::CreditCard::Prepaid::Unknown)
580
+ expect(credit_card.debit).to eq(Braintree::CreditCard::Prepaid::Unknown)
581
+ expect(credit_card.durbin_regulated).to eq(Braintree::CreditCard::Prepaid::Unknown)
582
+ expect(credit_card.healthcare).to eq(Braintree::CreditCard::Prepaid::Unknown)
583
+ credit_card.country_of_issuance == Braintree::CreditCard::CountryOfIssuance::Unknown
584
+ credit_card.issuing_bank == Braintree::CreditCard::IssuingBank::Unknown
585
+ credit_card.product_id == Braintree::CreditCard::ProductId::Unknown
586
+ end
587
+ end
588
+
589
+ context "client API" do
590
+ it "adds credit card to an existing customer using a payment method nonce" do
591
+ nonce = nonce_for_new_payment_method(
592
+ :credit_card => {
593
+ :number => "4111111111111111",
594
+ :expiration_month => "11",
595
+ :expiration_year => "2099",
596
+ },
597
+ :share => true,
598
+ )
599
+ customer = Braintree::Customer.create!
600
+ result = Braintree::CreditCard.create(
601
+ :customer_id => customer.id,
602
+ :payment_method_nonce => nonce,
603
+ )
604
+
605
+ expect(result.success?).to eq(true)
606
+ credit_card = result.credit_card
607
+ expect(credit_card.bin).to eq("411111")
608
+ expect(credit_card.last_4).to eq("1111")
609
+ expect(credit_card.expiration_date).to eq("11/2099")
610
+ end
611
+ end
612
+
613
+ context "card_type" do
614
+ it "is set to Elo" do
615
+ customer = Braintree::Customer.create!
616
+ result = Braintree::CreditCard.create(
617
+ :customer_id => customer.id,
618
+ :number => Braintree::Test::CreditCardNumbers::Elo,
619
+ :expiration_date => "10/2020",
620
+ )
621
+ expect(result.success?).to eq(true)
622
+ credit_card = result.credit_card
623
+ expect(credit_card.card_type).to eq(Braintree::CreditCard::CardType::Elo)
624
+ end
625
+ end
626
+
627
+ context "verification_account_type" do
628
+ it "verifies card with account_type debit" do
629
+ customer = Braintree::Customer.create!
630
+ result = Braintree::CreditCard.create(
631
+ :customer_id => customer.id,
632
+ :number => Braintree::Test::CreditCardNumbers::Hiper,
633
+ :expiration_month => "11",
634
+ :expiration_year => "2099",
635
+ :options => {
636
+ :verify_card => true,
637
+ :verification_merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
638
+ :verification_account_type => "debit",
639
+ },
640
+ )
641
+
642
+ expect(result).to be_success
643
+ end
644
+
645
+ it "verifies card with account_type credit" do
646
+ customer = Braintree::Customer.create!
647
+ result = Braintree::CreditCard.create(
648
+ :customer_id => customer.id,
649
+ :number => Braintree::Test::CreditCardNumbers::Hiper,
650
+ :expiration_month => "11",
651
+ :expiration_year => "2099",
652
+ :options => {
653
+ :verify_card => true,
654
+ :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
655
+ :verification_account_type => "credit",
656
+ },
657
+ )
658
+
659
+ expect(result).to be_success
660
+ end
661
+
662
+ it "errors with invalid account_type" do
663
+ result = Braintree::CreditCard.create(
664
+ :number => Braintree::Test::CreditCardNumbers::Hiper,
665
+ :expiration_month => "11",
666
+ :expiration_year => "2099",
667
+ :options => {
668
+ :verify_card => true,
669
+ :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
670
+ :verification_account_type => "ach",
671
+ },
672
+ )
673
+
674
+ expect(result).to_not be_success
675
+ expect(result.errors.for(:credit_card).for(:options).on(:verification_account_type)[0].code).to eq Braintree::ErrorCodes::CreditCard::VerificationAccountTypeIsInvalid
676
+ end
677
+
678
+ it "errors when account_type not supported by merchant" do
679
+ result = Braintree::CreditCard.create(
680
+ :number => Braintree::Test::CreditCardNumbers::Visa,
681
+ :expiration_month => "11",
682
+ :expiration_year => "2099",
683
+ :options => {
684
+ :verify_card => true,
685
+ :verification_account_type => "credit",
686
+ },
687
+ )
688
+
689
+ expect(result).to_not be_success
690
+ expect(result.errors.for(:credit_card).for(:options).on(:verification_account_type)[0].code).to eq Braintree::ErrorCodes::CreditCard::VerificationAccountTypeNotSupported
691
+ end
244
692
  end
245
693
  end
246
694
 
@@ -251,12 +699,12 @@ describe Braintree::CreditCard do
251
699
  :customer_id => customer.id,
252
700
  :cardholder_name => "Adam Davis",
253
701
  :number => Braintree::Test::CreditCardNumbers::Visa,
254
- :expiration_date => "05/2009"
702
+ :expiration_date => "05/2009",
255
703
  )
256
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
257
- credit_card.cardholder_name.should == "Adam Davis"
258
- credit_card.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
259
- credit_card.expiration_date.should == "05/2009"
704
+ expect(credit_card.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
705
+ expect(credit_card.cardholder_name).to eq("Adam Davis")
706
+ expect(credit_card.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
707
+ expect(credit_card.expiration_date).to eq("05/2009")
260
708
  end
261
709
 
262
710
  it "raises a ValidationsFailed if unsuccessful" do
@@ -265,32 +713,34 @@ describe Braintree::CreditCard do
265
713
  Braintree::CreditCard.create!(
266
714
  :customer_id => customer.id,
267
715
  :number => Braintree::Test::CreditCardNumbers::Visa,
268
- :expiration_date => "invalid_date"
716
+ :expiration_date => "invalid_date",
269
717
  )
270
718
  end.to raise_error(Braintree::ValidationsFailed)
271
719
  end
272
720
  end
273
721
 
722
+ # NEXT_MAJOR_VERSION remove this test
723
+ # CreditCard.credit has been deprecated in favor of Transaction.credit
274
724
  describe "self.credit" do
275
725
  it "creates a credit transaction using the payment method token, returning a result object" do
276
726
  customer = Braintree::Customer.create!(
277
727
  :credit_card => {
278
728
  :number => Braintree::Test::CreditCardNumbers::Visa,
279
729
  :expiration_date => "05/2010"
280
- }
730
+ },
281
731
  )
282
732
  result = Braintree::CreditCard.credit(
283
733
  customer.credit_cards[0].token,
284
- :amount => "100.00"
734
+ :amount => "100.00",
285
735
  )
286
- result.success?.should == true
287
- result.transaction.amount.should == BigDecimal.new("100.00")
288
- result.transaction.type.should == "credit"
289
- result.transaction.customer_details.id.should == customer.id
290
- result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
291
- result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
292
- result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
293
- result.transaction.credit_card_details.expiration_date.should == "05/2010"
736
+ expect(result.success?).to eq(true)
737
+ expect(result.transaction.amount).to eq(BigDecimal("100.00"))
738
+ expect(result.transaction.type).to eq("credit")
739
+ expect(result.transaction.customer_details.id).to eq(customer.id)
740
+ expect(result.transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
741
+ expect(result.transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
742
+ expect(result.transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
743
+ expect(result.transaction.credit_card_details.expiration_date).to eq("05/2010")
294
744
  end
295
745
  end
296
746
 
@@ -300,108 +750,19 @@ describe Braintree::CreditCard do
300
750
  :credit_card => {
301
751
  :number => Braintree::Test::CreditCardNumbers::Visa,
302
752
  :expiration_date => "05/2010"
303
- }
753
+ },
304
754
  )
305
755
  transaction = Braintree::CreditCard.credit!(
306
756
  customer.credit_cards[0].token,
307
- :amount => "100.00"
308
- )
309
- transaction.amount.should == BigDecimal.new("100.00")
310
- transaction.type.should == "credit"
311
- transaction.customer_details.id.should == customer.id
312
- transaction.credit_card_details.token.should == customer.credit_cards[0].token
313
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
314
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
315
- transaction.credit_card_details.expiration_date.should == "05/2010"
316
- end
317
- end
318
-
319
- describe "self.create_from_transparent_redirect" do
320
- it "returns a successful result if successful" do
321
- result = Braintree::Customer.create
322
- result.success?.should == true
323
- customer = result.customer
324
- params = {
325
- :credit_card => {
326
- :cardholder_name => "Card Holder",
327
- :number => Braintree::Test::CreditCardNumbers::Visa,
328
- :expiration_date => "05/2012"
329
- }
330
- }
331
- tr_data_params = {
332
- :credit_card => {
333
- :customer_id => customer.id
334
- }
335
- }
336
- tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
337
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.create_credit_card_url)
338
- result = Braintree::CreditCard.create_from_transparent_redirect(query_string_response)
339
- result.success?.should == true
340
- credit_card = result.credit_card
341
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
342
- credit_card.cardholder_name.should == "Card Holder"
343
- credit_card.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
344
- credit_card.expiration_month.should == "05"
345
- credit_card.expiration_year.should == "2012"
346
- credit_card.expiration_date.should == "05/2012"
347
- credit_card.customer_id.should == customer.id
348
- end
349
-
350
- it "create card as default" do
351
- customer = Braintree::Customer.create!(
352
- :credit_card => {
353
- :cardholder_name => "Old Cardholder Name",
354
- :number => Braintree::Test::CreditCardNumbers::Visa,
355
- :expiration_date => "05/2012"
356
- }
757
+ :amount => "100.00",
357
758
  )
358
- card1 = customer.credit_cards[0]
359
-
360
- params = {
361
- :credit_card => {
362
- :cardholder_name => "Card Holder",
363
- :number => Braintree::Test::CreditCardNumbers::Visa,
364
- :expiration_date => "05/2012",
365
- :options => {:make_default => true}
366
- }
367
- }
368
- tr_data_params = {
369
- :credit_card => {
370
- :customer_id => customer.id
371
- }
372
- }
373
- tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
374
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.create_credit_card_url)
375
- result = Braintree::CreditCard.create_from_transparent_redirect(query_string_response)
376
- result.success?.should == true
377
- card2 = result.credit_card
378
-
379
- Braintree::CreditCard.find(card1.token).should_not be_default
380
- card2.should be_default
381
- end
382
-
383
- it "returns xml with nested errors if validation errors" do
384
- customer = Braintree::Customer.create.customer
385
- params = {
386
- :credit_card => {
387
- :cardholder_name => "Card Holder",
388
- :number => "eleventy",
389
- :expiration_date => "y2k"
390
- }
391
- }
392
- tr_data_params = {
393
- :credit_card => {
394
- :customer_id => customer.id
395
- }
396
- }
397
- tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
398
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.create_credit_card_url)
399
- result = Braintree::CreditCard.create_from_transparent_redirect(query_string_response)
400
- result.success?.should == false
401
- result.params[:customer_id] == customer.id
402
- result.params[:credit_card]["cardholder_name"] == customer.id
403
- result.params[:credit_card]["number"] == "eleventy"
404
- result.params[:credit_card]["exipiration_date"] == "y2k"
759
+ expect(transaction.amount).to eq(BigDecimal("100.00"))
760
+ expect(transaction.type).to eq("credit")
761
+ expect(transaction.customer_details.id).to eq(customer.id)
762
+ expect(transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
763
+ expect(transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
764
+ expect(transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
765
+ expect(transaction.credit_card_details.expiration_date).to eq("05/2010")
405
766
  end
406
767
  end
407
768
 
@@ -413,21 +774,124 @@ describe Braintree::CreditCard do
413
774
  :customer_id => customer.id,
414
775
  :cvv => "123",
415
776
  :number => Braintree::Test::CreditCardNumbers::Visa,
416
- :expiration_date => "05/2012"
777
+ :expiration_date => "05/2012",
417
778
  )
418
779
  update_result = Braintree::CreditCard.update(credit_card.token,
419
780
  :cardholder_name => "New Holder",
420
781
  :cvv => "456",
421
782
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
422
- :expiration_date => "06/2013"
783
+ :expiration_date => "06/2013",
423
784
  )
424
- update_result.success?.should == true
425
- update_result.credit_card.should == credit_card
785
+ expect(update_result.success?).to eq(true)
786
+ expect(update_result.credit_card).to eq(credit_card)
426
787
  updated_credit_card = update_result.credit_card
427
- updated_credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
428
- updated_credit_card.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
429
- updated_credit_card.expiration_date.should == "06/2013"
430
- updated_credit_card.cardholder_name.should == "New Holder"
788
+ expect(updated_credit_card.bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
789
+ expect(updated_credit_card.last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
790
+ expect(updated_credit_card.expiration_date).to eq("06/2013")
791
+ expect(updated_credit_card.cardholder_name).to eq("New Holder")
792
+ end
793
+
794
+ it "validates presence of three_d_secure_version in 3ds pass thru params" do
795
+ customer = Braintree::Customer.create!
796
+ credit_card = Braintree::CreditCard.create!(
797
+ :cardholder_name => "Original Holder",
798
+ :customer_id => customer.id,
799
+ :cvv => "123",
800
+ :number => Braintree::Test::CreditCardNumbers::Visa,
801
+ :expiration_date => "05/2012",
802
+ )
803
+ result = Braintree::CreditCard.update(credit_card.token,
804
+ :payment_method_nonce => Braintree::Test::Nonce::Transactable,
805
+ :three_d_secure_pass_thru => {
806
+ :eci_flag => "05",
807
+ :cavv => "some_cavv",
808
+ :xid => "some_xid",
809
+ :authentication_response => "Y",
810
+ :directory_response => "Y",
811
+ :cavv_algorithm => "2",
812
+ :ds_transaction_id => "some_ds_transaction_id",
813
+ },
814
+ :options => {:verify_card => true},
815
+ )
816
+ expect(result).not_to be_success
817
+ error = result.errors.for(:verification).first
818
+ expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsRequired)
819
+ expect(error.message).to eq("ThreeDSecureVersion is required.")
820
+ end
821
+
822
+ it "accepts three_d_secure pass thru params in the request" do
823
+ customer = Braintree::Customer.create!
824
+ credit_card = Braintree::CreditCard.create!(
825
+ :cardholder_name => "Original Holder",
826
+ :customer_id => customer.id,
827
+ :cvv => "123",
828
+ :number => Braintree::Test::CreditCardNumbers::Visa,
829
+ :expiration_date => "05/2012",
830
+ )
831
+ result = Braintree::CreditCard.update(credit_card.token,
832
+ :payment_method_nonce => Braintree::Test::Nonce::Transactable,
833
+ :three_d_secure_pass_thru => {
834
+ :eci_flag => "05",
835
+ :cavv => "some_cavv",
836
+ :three_d_secure_version=> "2.1.0",
837
+ :xid => "some_xid",
838
+ :authentication_response => "Y",
839
+ :directory_response => "Y",
840
+ :cavv_algorithm => "2",
841
+ :ds_transaction_id => "some_ds_transaction_id",
842
+ },
843
+ :options => {:verify_card => true},
844
+ )
845
+
846
+ expect(result.success?).to eq(true)
847
+ end
848
+
849
+ it "includes risk data when skip_advanced_fraud_checking is false" do
850
+ with_fraud_protection_enterprise_merchant do
851
+ customer = Braintree::Customer.create!
852
+ credit_card = Braintree::CreditCard.create!(
853
+ :cardholder_name => "Original Holder",
854
+ :customer_id => customer.id,
855
+ :cvv => "123",
856
+ :number => Braintree::Test::CreditCardNumbers::Visa,
857
+ :expiration_date => "05/2020",
858
+ )
859
+ updated_result = Braintree::CreditCard.update(credit_card.token,
860
+ :expiration_date => "05/2021",
861
+ :options => {
862
+ :verify_card => true,
863
+ :skip_advanced_fraud_checking => false,
864
+ },
865
+ )
866
+
867
+ expect(updated_result).to be_success
868
+ verification = updated_result.credit_card.verification
869
+ expect(verification.risk_data).not_to be_nil
870
+ end
871
+ end
872
+
873
+ it "does not include risk data when skip_advanced_fraud_checking is true" do
874
+ with_fraud_protection_enterprise_merchant do
875
+ customer = Braintree::Customer.create!
876
+ credit_card = Braintree::CreditCard.create!(
877
+ :cardholder_name => "Original Holder",
878
+ :customer_id => customer.id,
879
+ :cvv => "123",
880
+ :number => Braintree::Test::CreditCardNumbers::Visa,
881
+ :expiration_date => "05/2020",
882
+ )
883
+ updated_result = Braintree::CreditCard.update(credit_card.token,
884
+ :expiration_date => "05/2021",
885
+ :options => {
886
+ :verify_card => true,
887
+ :skip_advanced_fraud_checking => true,
888
+ },
889
+ )
890
+
891
+ expect(updated_result).to be_success
892
+ verification = updated_result.credit_card.verification
893
+ expect(verification.risk_data).to be_nil
894
+ end
431
895
  end
432
896
 
433
897
  context "billing address" do
@@ -439,18 +903,18 @@ describe Braintree::CreditCard do
439
903
  :expiration_date => "05/2012",
440
904
  :billing_address => {
441
905
  :street_address => "123 Nigeria Ave"
442
- }
906
+ },
443
907
  )
444
908
  update_result = Braintree::CreditCard.update(credit_card.token,
445
909
  :billing_address => {
446
910
  :region => "IL"
447
- }
911
+ },
448
912
  )
449
- update_result.success?.should == true
913
+ expect(update_result.success?).to eq(true)
450
914
  updated_credit_card = update_result.credit_card
451
- updated_credit_card.billing_address.region.should == "IL"
452
- updated_credit_card.billing_address.street_address.should == nil
453
- updated_credit_card.billing_address.id.should_not == credit_card.billing_address.id
915
+ expect(updated_credit_card.billing_address.region).to eq("IL")
916
+ expect(updated_credit_card.billing_address.street_address).to eq(nil)
917
+ expect(updated_credit_card.billing_address.id).not_to eq(credit_card.billing_address.id)
454
918
  end
455
919
 
456
920
  it "updates the billing address if option is specified" do
@@ -461,19 +925,19 @@ describe Braintree::CreditCard do
461
925
  :expiration_date => "05/2012",
462
926
  :billing_address => {
463
927
  :street_address => "123 Nigeria Ave"
464
- }
928
+ },
465
929
  )
466
930
  update_result = Braintree::CreditCard.update(credit_card.token,
467
931
  :billing_address => {
468
932
  :region => "IL",
469
933
  :options => {:update_existing => true}
470
- }
934
+ },
471
935
  )
472
- update_result.success?.should == true
936
+ expect(update_result.success?).to eq(true)
473
937
  updated_credit_card = update_result.credit_card
474
- updated_credit_card.billing_address.region.should == "IL"
475
- updated_credit_card.billing_address.street_address.should == "123 Nigeria Ave"
476
- updated_credit_card.billing_address.id.should == credit_card.billing_address.id
938
+ expect(updated_credit_card.billing_address.region).to eq("IL")
939
+ expect(updated_credit_card.billing_address.street_address).to eq("123 Nigeria Ave")
940
+ expect(updated_credit_card.billing_address.id).to eq(credit_card.billing_address.id)
477
941
  end
478
942
 
479
943
  it "updates the country via codes" do
@@ -484,7 +948,7 @@ describe Braintree::CreditCard do
484
948
  :expiration_date => "05/2012",
485
949
  :billing_address => {
486
950
  :street_address => "123 Nigeria Ave"
487
- }
951
+ },
488
952
  )
489
953
  update_result = Braintree::CreditCard.update(credit_card.token,
490
954
  :billing_address => {
@@ -493,14 +957,14 @@ describe Braintree::CreditCard do
493
957
  :country_code_alpha3 => "ASM",
494
958
  :country_code_numeric => "016",
495
959
  :options => {:update_existing => true}
496
- }
960
+ },
497
961
  )
498
- update_result.success?.should == true
962
+ expect(update_result.success?).to eq(true)
499
963
  updated_credit_card = update_result.credit_card
500
- updated_credit_card.billing_address.country_name.should == "American Samoa"
501
- updated_credit_card.billing_address.country_code_alpha2.should == "AS"
502
- updated_credit_card.billing_address.country_code_alpha3.should == "ASM"
503
- updated_credit_card.billing_address.country_code_numeric.should == "016"
964
+ expect(updated_credit_card.billing_address.country_name).to eq("American Samoa")
965
+ expect(updated_credit_card.billing_address.country_code_alpha2).to eq("AS")
966
+ expect(updated_credit_card.billing_address.country_code_alpha3).to eq("ASM")
967
+ expect(updated_credit_card.billing_address.country_code_numeric).to eq("016")
504
968
  end
505
969
  end
506
970
 
@@ -509,18 +973,18 @@ describe Braintree::CreditCard do
509
973
  credit_card = Braintree::CreditCard.create!(
510
974
  :customer_id => customer.id,
511
975
  :number => Braintree::Test::CreditCardNumbers::Visa,
512
- :expiration_date => "05/2012"
976
+ :expiration_date => "05/2012",
513
977
  )
514
978
  update_result = Braintree::CreditCard.update(credit_card.token,
515
979
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
516
980
  :expiration_month => "07",
517
- :expiration_year => "2011"
981
+ :expiration_year => "2011",
518
982
  )
519
- update_result.success?.should == true
520
- update_result.credit_card.should == credit_card
521
- update_result.credit_card.expiration_month.should == "07"
522
- update_result.credit_card.expiration_year.should == "2011"
523
- update_result.credit_card.expiration_date.should == "07/2011"
983
+ expect(update_result.success?).to eq(true)
984
+ expect(update_result.credit_card).to eq(credit_card)
985
+ expect(update_result.credit_card.expiration_month).to eq("07")
986
+ expect(update_result.credit_card.expiration_year).to eq("2011")
987
+ expect(update_result.credit_card.expiration_date).to eq("07/2011")
524
988
  end
525
989
 
526
990
  it "verifies the update if options[verify_card]=true" do
@@ -530,18 +994,18 @@ describe Braintree::CreditCard do
530
994
  :customer_id => customer.id,
531
995
  :cvv => "123",
532
996
  :number => Braintree::Test::CreditCardNumbers::Visa,
533
- :expiration_date => "05/2012"
997
+ :expiration_date => "05/2012",
534
998
  )
535
999
  update_result = Braintree::CreditCard.update(credit_card.token,
536
1000
  :cardholder_name => "New Holder",
537
1001
  :cvv => "456",
538
1002
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
539
1003
  :expiration_date => "06/2013",
540
- :options => {:verify_card => true}
1004
+ :options => {:verify_card => true},
541
1005
  )
542
- update_result.success?.should == false
543
- update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
544
- update_result.credit_card_verification.gateway_rejection_reason.should be_nil
1006
+ expect(update_result.success?).to eq(false)
1007
+ expect(update_result.credit_card_verification.status).to eq(Braintree::CreditCardVerification::Status::ProcessorDeclined)
1008
+ expect(update_result.credit_card_verification.gateway_rejection_reason).to be_nil
545
1009
  end
546
1010
 
547
1011
  it "can update the billing address" do
@@ -562,7 +1026,7 @@ describe Braintree::CreditCard do
562
1026
  :region => "Old State",
563
1027
  :postal_code => "12345",
564
1028
  :country_name => "Canada"
565
- }
1029
+ },
566
1030
  )
567
1031
  result = Braintree::CreditCard.update(credit_card.token,
568
1032
  :options => {:verify_card => false},
@@ -576,19 +1040,19 @@ describe Braintree::CreditCard do
576
1040
  :region => "New State",
577
1041
  :postal_code => "56789",
578
1042
  :country_name => "United States of America"
579
- }
1043
+ },
580
1044
  )
581
- result.success?.should == true
1045
+ expect(result.success?).to eq(true)
582
1046
  address = result.credit_card.billing_address
583
- address.first_name.should == "New First Name"
584
- address.last_name.should == "New Last Name"
585
- address.company.should == "New Company"
586
- address.street_address.should == "123 New St"
587
- address.extended_address.should == "Apt New"
588
- address.locality.should == "New City"
589
- address.region.should == "New State"
590
- address.postal_code.should == "56789"
591
- address.country_name.should == "United States of America"
1047
+ expect(address.first_name).to eq("New First Name")
1048
+ expect(address.last_name).to eq("New Last Name")
1049
+ expect(address.company).to eq("New Company")
1050
+ expect(address.street_address).to eq("123 New St")
1051
+ expect(address.extended_address).to eq("Apt New")
1052
+ expect(address.locality).to eq("New City")
1053
+ expect(address.region).to eq("New State")
1054
+ expect(address.postal_code).to eq("56789")
1055
+ expect(address.country_name).to eq("United States of America")
592
1056
  end
593
1057
 
594
1058
  it "returns an error response if invalid" do
@@ -597,15 +1061,15 @@ describe Braintree::CreditCard do
597
1061
  :cardholder_name => "Original Holder",
598
1062
  :customer_id => customer.id,
599
1063
  :number => Braintree::Test::CreditCardNumbers::Visa,
600
- :expiration_date => "05/2012"
1064
+ :expiration_date => "05/2012",
601
1065
  )
602
1066
  update_result = Braintree::CreditCard.update(credit_card.token,
603
1067
  :cardholder_name => "New Holder",
604
1068
  :number => "invalid",
605
- :expiration_date => "05/2014"
1069
+ :expiration_date => "05/2014",
606
1070
  )
607
- update_result.success?.should == false
608
- update_result.errors.for(:credit_card).on(:number)[0].message.should == "Credit card number must be 12-19 digits."
1071
+ expect(update_result.success?).to eq(false)
1072
+ expect(update_result.errors.for(:credit_card).on(:number)[0].message).to eq("Credit card number must be 12-19 digits.")
609
1073
  end
610
1074
 
611
1075
  it "can update the default" do
@@ -613,21 +1077,59 @@ describe Braintree::CreditCard do
613
1077
  card1 = Braintree::CreditCard.create(
614
1078
  :customer_id => customer.id,
615
1079
  :number => Braintree::Test::CreditCardNumbers::Visa,
616
- :expiration_date => "05/2009"
1080
+ :expiration_date => "05/2009",
617
1081
  ).credit_card
618
1082
  card2 = Braintree::CreditCard.create(
619
1083
  :customer_id => customer.id,
620
1084
  :number => Braintree::Test::CreditCardNumbers::Visa,
621
- :expiration_date => "05/2009"
1085
+ :expiration_date => "05/2009",
622
1086
  ).credit_card
623
1087
 
624
- card1.should be_default
625
- card2.should_not be_default
1088
+ expect(card1).to be_default
1089
+ expect(card2).not_to be_default
626
1090
 
627
1091
  Braintree::CreditCard.update(card2.token, :options => {:make_default => true})
628
1092
 
629
- Braintree::CreditCard.find(card1.token).should_not be_default
630
- Braintree::CreditCard.find(card2.token).should be_default
1093
+ expect(Braintree::CreditCard.find(card1.token)).not_to be_default
1094
+ expect(Braintree::CreditCard.find(card2.token)).to be_default
1095
+ end
1096
+
1097
+ context "verification_account_type" do
1098
+ it "updates the credit card with account_type credit" do
1099
+ customer = Braintree::Customer.create!
1100
+ card = Braintree::CreditCard.create(
1101
+ :customer_id => customer.id,
1102
+ :number => Braintree::Test::CreditCardNumbers::Hiper,
1103
+ :expiration_date => "06/2013",
1104
+ ).credit_card
1105
+ update_result = Braintree::CreditCard.update(
1106
+ card.token,
1107
+ :options => {
1108
+ :verify_card => true,
1109
+ :verification_account_type => "credit",
1110
+ :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
1111
+ },
1112
+ )
1113
+ expect(update_result).to be_success
1114
+ end
1115
+
1116
+ it "updates the credit card with account_type debit" do
1117
+ customer = Braintree::Customer.create!
1118
+ card = Braintree::CreditCard.create(
1119
+ :customer_id => customer.id,
1120
+ :number => Braintree::Test::CreditCardNumbers::Hiper,
1121
+ :expiration_date => "06/2013",
1122
+ ).credit_card
1123
+ update_result = Braintree::CreditCard.update(
1124
+ card.token,
1125
+ :options => {
1126
+ :verify_card => true,
1127
+ :verification_account_type => "debit",
1128
+ :verification_merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
1129
+ },
1130
+ )
1131
+ expect(update_result).to be_success
1132
+ end
631
1133
  end
632
1134
  end
633
1135
 
@@ -638,19 +1140,19 @@ describe Braintree::CreditCard do
638
1140
  :cardholder_name => "Original Holder",
639
1141
  :customer_id => customer.id,
640
1142
  :number => Braintree::Test::CreditCardNumbers::Visa,
641
- :expiration_date => "05/2012"
1143
+ :expiration_date => "05/2012",
642
1144
  )
643
1145
  updated_credit_card = Braintree::CreditCard.update!(credit_card.token,
644
1146
  :cardholder_name => "New Holder",
645
1147
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
646
- :expiration_date => "06/2013"
1148
+ :expiration_date => "06/2013",
647
1149
  )
648
- updated_credit_card.token.should == credit_card.token
649
- updated_credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
650
- updated_credit_card.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
651
- updated_credit_card.expiration_date.should == "06/2013"
652
- updated_credit_card.cardholder_name.should == "New Holder"
653
- updated_credit_card.updated_at.between?(Time.now - 60, Time.now).should == true
1150
+ expect(updated_credit_card.token).to eq(credit_card.token)
1151
+ expect(updated_credit_card.bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
1152
+ expect(updated_credit_card.last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
1153
+ expect(updated_credit_card.expiration_date).to eq("06/2013")
1154
+ expect(updated_credit_card.cardholder_name).to eq("New Holder")
1155
+ expect(updated_credit_card.updated_at.between?(Time.now - 60, Time.now)).to eq(true)
654
1156
  end
655
1157
 
656
1158
  it "raises a ValidationsFailed if invalid" do
@@ -659,174 +1161,30 @@ describe Braintree::CreditCard do
659
1161
  :cardholder_name => "Original Holder",
660
1162
  :customer_id => customer.id,
661
1163
  :number => Braintree::Test::CreditCardNumbers::Visa,
662
- :expiration_date => "05/2012"
1164
+ :expiration_date => "05/2012",
663
1165
  )
664
1166
  expect do
665
1167
  Braintree::CreditCard.update!(credit_card.token,
666
1168
  :cardholder_name => "New Holder",
667
1169
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
668
- :expiration_date => "invalid/date"
1170
+ :expiration_date => "invalid/date",
669
1171
  )
670
1172
  end.to raise_error(Braintree::ValidationsFailed)
671
1173
  end
672
1174
  end
673
1175
 
674
- describe "self.update_from_transparent_redirect" do
675
- it "updates the credit card" do
676
- old_token = "token#{rand(1_000_000)}"
677
- new_token = "token#{rand(1_000_000)}"
678
- customer = Braintree::Customer.create!(
679
- :credit_card => {
680
- :cardholder_name => "Old Cardholder Name",
681
- :number => Braintree::Test::CreditCardNumbers::Visa,
682
- :expiration_date => "05/2012",
683
- :token => old_token
684
- }
685
- )
686
- credit_card = customer.credit_cards[0]
687
- params = {
688
- :credit_card => {
689
- :cardholder_name => "New Cardholder Name",
690
- :number => Braintree::Test::CreditCardNumbers::MasterCard,
691
- :expiration_date => "05/2014"
692
- }
693
- }
694
- tr_data_params = {
695
- :payment_method_token => old_token,
696
- :credit_card => {
697
- :token => new_token
698
- }
699
- }
700
- tr_data = Braintree::TransparentRedirect.update_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
701
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.update_credit_card_url)
702
- result = Braintree::CreditCard.update_from_transparent_redirect(query_string_response)
703
- result.success?.should == true
704
- credit_card = result.credit_card
705
- credit_card.cardholder_name.should == "New Cardholder Name"
706
- credit_card.masked_number.should == "555555******4444"
707
- credit_card.expiration_date.should == "05/2014"
708
- credit_card.token.should == new_token
709
- end
710
-
711
- it "updates the default credit card" do
712
- customer = Braintree::Customer.create!(
713
- :credit_card => {
714
- :cardholder_name => "Old Cardholder Name",
715
- :number => Braintree::Test::CreditCardNumbers::Visa,
716
- :expiration_date => "05/2012"
717
- }
718
- )
719
- card1 = customer.credit_cards[0]
720
-
721
- card2 = Braintree::CreditCard.create(
722
- :customer_id => customer.id,
723
- :number => Braintree::Test::CreditCardNumbers::Visa,
724
- :expiration_date => "05/2009"
725
- ).credit_card
726
-
727
- card1.should be_default
728
- card2.should_not be_default
729
-
730
- params = {
731
- :credit_card => {
732
- :options => {:make_default => true}
733
- }
734
- }
735
- tr_data_params = {
736
- :payment_method_token => card2.token
737
- }
738
- tr_data = Braintree::TransparentRedirect.update_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
739
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.update_credit_card_url)
740
- result = Braintree::CreditCard.update_from_transparent_redirect(query_string_response)
741
-
742
- Braintree::CreditCard.find(card1.token).should_not be_default
743
- Braintree::CreditCard.find(card2.token).should be_default
744
- end
745
- end
746
-
747
- describe "credit" do
748
- it "creates a credit transaction using the customer, returning a result object" do
749
- customer = Braintree::Customer.create!(
750
- :credit_card => {
751
- :number => Braintree::Test::CreditCardNumbers::Visa,
752
- :expiration_date => "05/2010"
753
- }
754
- )
755
- result = customer.credit_cards[0].credit(
756
- :amount => "100.00"
757
- )
758
- result.success?.should == true
759
- result.transaction.amount.should == BigDecimal.new("100.00")
760
- result.transaction.type.should == "credit"
761
- result.transaction.customer_details.id.should == customer.id
762
- result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
763
- result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
764
- result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
765
- result.transaction.credit_card_details.expiration_date.should == "05/2010"
766
- end
767
- end
768
-
769
- describe "credit!" do
770
- it "returns the created credit tranaction if valid" do
771
- customer = Braintree::Customer.create!(
772
- :credit_card => {
773
- :number => Braintree::Test::CreditCardNumbers::Visa,
774
- :expiration_date => "05/2010"
775
- }
776
- )
777
- transaction = customer.credit_cards[0].credit!(:amount => "100.00")
778
- transaction.amount.should == BigDecimal.new("100.00")
779
- transaction.type.should == "credit"
780
- transaction.customer_details.id.should == customer.id
781
- transaction.credit_card_details.token.should == customer.credit_cards[0].token
782
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
783
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
784
- transaction.credit_card_details.expiration_date.should == "05/2010"
785
- end
786
-
787
- it "raises a ValidationsFailed if invalid" do
788
- customer = Braintree::Customer.create!(
789
- :credit_card => {
790
- :number => Braintree::Test::CreditCardNumbers::Visa,
791
- :expiration_date => "05/2010"
792
- }
793
- )
794
- expect do
795
- customer.credit_cards[0].credit!(:amount => "invalid")
796
- end.to raise_error(Braintree::ValidationsFailed)
797
- end
798
- end
799
-
800
1176
  describe "self.delete" do
801
1177
  it "deletes the credit card" do
802
1178
  customer = Braintree::Customer.create.customer
803
1179
  result = Braintree::CreditCard.create(
804
1180
  :customer_id => customer.id,
805
1181
  :number => Braintree::Test::CreditCardNumbers::Visa,
806
- :expiration_date => "05/2012"
807
- )
808
-
809
- result.success?.should == true
810
- credit_card = result.credit_card
811
- Braintree::CreditCard.delete(credit_card.token).should == true
812
- expect do
813
- Braintree::CreditCard.find(credit_card.token)
814
- end.to raise_error(Braintree::NotFoundError)
815
- end
816
- end
817
-
818
- describe "delete" do
819
- it "deletes the credit card" do
820
- customer = Braintree::Customer.create.customer
821
- result = Braintree::CreditCard.create(
822
- :customer_id => customer.id,
823
- :number => Braintree::Test::CreditCardNumbers::Visa,
824
- :expiration_date => "05/2012"
1182
+ :expiration_date => "05/2012",
825
1183
  )
826
1184
 
827
- result.success?.should == true
1185
+ expect(result.success?).to eq(true)
828
1186
  credit_card = result.credit_card
829
- credit_card.delete.should == true
1187
+ expect(Braintree::CreditCard.delete(credit_card.token)).to eq(true)
830
1188
  expect do
831
1189
  Braintree::CreditCard.find(credit_card.token)
832
1190
  end.to raise_error(Braintree::NotFoundError)
@@ -841,28 +1199,29 @@ describe Braintree::CreditCard do
841
1199
  Braintree::CreditCard.create!(
842
1200
  :customer_id => customer.id,
843
1201
  :number => Braintree::Test::CreditCardNumbers::Visa,
844
- :expiration_date => "01/2010"
1202
+ :expiration_date => "01/#{Time.now.year - 3}",
845
1203
  )
846
1204
  end
847
1205
 
848
1206
  collection = Braintree::CreditCard.expired
849
- collection.maximum_size.should > 100
1207
+ expect(collection.maximum_size).to be > 100
850
1208
 
851
1209
  credit_card_ids = collection.map do |c|
852
- c.expired?.should == true
1210
+ expect(c.expired?).to eq(true)
853
1211
  c.token
854
1212
  end.uniq.compact
855
- credit_card_ids.size.should == collection.maximum_size
1213
+ expect(credit_card_ids.size).to eq(collection.maximum_size)
856
1214
  end
857
1215
  end
858
1216
 
859
1217
  describe "self.expiring_between" do
860
- it "finds payment methods expiring between the given dates" do
1218
+ #Disabling this test until we have a more stable CI
1219
+ xit "finds payment methods expiring between the given dates" do
861
1220
  next_year = Time.now.year + 1
862
1221
  collection = Braintree::CreditCard.expiring_between(Time.mktime(next_year, 1), Time.mktime(next_year, 12))
863
- collection.maximum_size.should > 0
864
- collection.all? { |pm| pm.expired?.should == false }
865
- collection.all? { |pm| pm.expiration_year.should == next_year.to_s }
1222
+ expect(collection.maximum_size).to be > 0
1223
+ collection.all? { |pm| expect(pm.expired?).to eq(false) }
1224
+ collection.all? { |pm| expect(pm.expiration_year).to eq(next_year.to_s) }
866
1225
  end
867
1226
 
868
1227
  it "can iterate over all items" do
@@ -872,15 +1231,15 @@ describe Braintree::CreditCard do
872
1231
  Braintree::CreditCard.create!(
873
1232
  :customer_id => customer.id,
874
1233
  :number => Braintree::Test::CreditCardNumbers::Visa,
875
- :expiration_date => "01/2010"
1234
+ :expiration_date => "01/2010",
876
1235
  )
877
1236
  end
878
1237
 
879
1238
  collection = Braintree::CreditCard.expiring_between(Time.mktime(2010, 1, 1), Time.mktime(2010,3, 1))
880
- collection.maximum_size.should > 100
1239
+ expect(collection.maximum_size).to be > 100
881
1240
 
882
- credit_card_ids = collection.map {|c| c.token }.uniq.compact
883
- credit_card_ids.size.should == collection.maximum_size
1241
+ credit_card_ids = collection.map { |c| c.token }.uniq.compact
1242
+ expect(credit_card_ids.size).to eq(collection.maximum_size)
884
1243
  end
885
1244
  end
886
1245
 
@@ -890,14 +1249,14 @@ describe Braintree::CreditCard do
890
1249
  result = Braintree::CreditCard.create(
891
1250
  :customer_id => customer.id,
892
1251
  :number => Braintree::Test::CreditCardNumbers::Visa,
893
- :expiration_date => "05/2012"
1252
+ :expiration_date => "05/2012",
894
1253
  )
895
- result.success?.should == true
1254
+ expect(result.success?).to eq(true)
896
1255
  credit_card = Braintree::CreditCard.find(result.credit_card.token)
897
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
898
- credit_card.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
899
- credit_card.token.should == result.credit_card.token
900
- credit_card.expiration_date.should == "05/2012"
1256
+ expect(credit_card.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
1257
+ expect(credit_card.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
1258
+ expect(credit_card.token).to eq(result.credit_card.token)
1259
+ expect(credit_card.expiration_date).to eq("05/2012")
901
1260
  end
902
1261
 
903
1262
  it "returns associated subscriptions with the credit card" do
@@ -905,20 +1264,20 @@ describe Braintree::CreditCard do
905
1264
  credit_card = Braintree::CreditCard.create(
906
1265
  :customer_id => customer.id,
907
1266
  :number => Braintree::Test::CreditCardNumbers::Visa,
908
- :expiration_date => "05/2012"
1267
+ :expiration_date => "05/2012",
909
1268
  ).credit_card
910
1269
 
911
1270
  subscription = Braintree::Subscription.create(
912
1271
  :payment_method_token => credit_card.token,
913
1272
  :plan_id => "integration_trialless_plan",
914
- :price => "1.00"
1273
+ :price => "1.00",
915
1274
  ).subscription
916
1275
 
917
1276
  found_card = Braintree::CreditCard.find(credit_card.token)
918
- found_card.subscriptions.first.id.should == subscription.id
919
- found_card.subscriptions.first.plan_id.should == "integration_trialless_plan"
920
- found_card.subscriptions.first.payment_method_token.should == credit_card.token
921
- found_card.subscriptions.first.price.should == BigDecimal.new("1.00")
1277
+ expect(found_card.subscriptions.first.id).to eq(subscription.id)
1278
+ expect(found_card.subscriptions.first.plan_id).to eq("integration_trialless_plan")
1279
+ expect(found_card.subscriptions.first.payment_method_token).to eq(credit_card.token)
1280
+ expect(found_card.subscriptions.first.price).to eq(BigDecimal("1.00"))
922
1281
  end
923
1282
 
924
1283
  it "raises a NotFoundError exception if payment method cannot be found" do
@@ -926,297 +1285,169 @@ describe Braintree::CreditCard do
926
1285
  Braintree::CreditCard.find("invalid-token")
927
1286
  end.to raise_error(Braintree::NotFoundError, 'payment method with token "invalid-token" not found')
928
1287
  end
1288
+
1289
+ it "raises a NotFoundError exception if searching for a PayPalAccount token" do
1290
+ customer = Braintree::Customer.create!
1291
+ paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
1292
+ paypal_nonce = nonce_for_paypal_account({
1293
+ :consent_code => "PAYPAL_CONSENT_CODE",
1294
+ :token => paypal_account_token
1295
+ })
1296
+
1297
+ Braintree::PaymentMethod.create({
1298
+ :payment_method_nonce => paypal_nonce,
1299
+ :customer_id => customer.id
1300
+ })
1301
+
1302
+ expect do
1303
+ Braintree::CreditCard.find(paypal_account_token)
1304
+ end.to raise_error(Braintree::NotFoundError, "payment method with token \"#{paypal_account_token}\" not found")
1305
+ end
929
1306
  end
930
1307
 
931
- describe "self.sale" do
932
- it "creates a sale transaction using the credit card, returning a result object" do
933
- customer = Braintree::Customer.create!(
1308
+ describe "self.from_nonce" do
1309
+ it "finds the payment method with the given nonce" do
1310
+ customer = Braintree::Customer.create!
1311
+ nonce = nonce_for_new_payment_method(
934
1312
  :credit_card => {
935
- :number => Braintree::Test::CreditCardNumbers::Visa,
936
- :expiration_date => "05/2010"
937
- }
1313
+ :number => "4111111111111111",
1314
+ :expiration_month => "11",
1315
+ :expiration_year => "2099",
1316
+ },
1317
+ :client_token_options => {:customer_id => customer.id},
938
1318
  )
939
- result = Braintree::CreditCard.sale(customer.credit_cards[0].token, :amount => "100.00")
940
1319
 
941
- result.success?.should == true
942
- result.transaction.amount.should == BigDecimal.new("100.00")
943
- result.transaction.type.should == "sale"
944
- result.transaction.customer_details.id.should == customer.id
945
- result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
946
- result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
947
- result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
948
- result.transaction.credit_card_details.expiration_date.should == "05/2010"
1320
+ credit_card = Braintree::CreditCard.from_nonce(nonce)
1321
+ customer = Braintree::Customer.find(customer.id)
1322
+ expect(credit_card).to eq(customer.credit_cards.first)
949
1323
  end
950
1324
 
951
- it "allows passing a cvv in addition to the token" do
952
- customer = Braintree::Customer.create!(
953
- :credit_card => {
954
- :number => Braintree::Test::CreditCardNumbers::Visa,
955
- :expiration_date => "05/2010"
956
- }
957
- )
958
- result = Braintree::CreditCard.sale(customer.credit_cards[0].token,
959
- :amount => "100.00",
1325
+ it "does not find a payment method for an unlocked nonce that points to a shared credit card" do
1326
+ nonce = nonce_for_new_payment_method(
960
1327
  :credit_card => {
961
- :cvv => "301"
962
- }
1328
+ :number => "4111111111111111",
1329
+ :expiration_month => "11",
1330
+ :expiration_year => "2099",
1331
+ },
963
1332
  )
964
-
965
- result.success?.should == true
966
- result.transaction.amount.should == BigDecimal.new("100.00")
967
- result.transaction.type.should == "sale"
968
- result.transaction.customer_details.id.should == customer.id
969
- result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
970
- result.transaction.cvv_response_code.should == "S"
1333
+ expect do
1334
+ Braintree::CreditCard.from_nonce(nonce)
1335
+ end.to raise_error(Braintree::NotFoundError)
971
1336
  end
972
- end
973
1337
 
974
- describe "self.sale!" do
975
- it "creates a sale transaction using the credit card, returning the transaction" do
976
- customer = Braintree::Customer.create!(
1338
+ it "does not find the payment method for a consumednonce" do
1339
+ customer = Braintree::Customer.create!
1340
+ nonce = nonce_for_new_payment_method(
977
1341
  :credit_card => {
978
- :number => Braintree::Test::CreditCardNumbers::Visa,
979
- :expiration_date => "05/2010"
980
- }
1342
+ :number => "4111111111111111",
1343
+ :expiration_month => "11",
1344
+ :expiration_year => "2099",
1345
+ },
1346
+ :client_token_options => {:customer_id => customer.id},
981
1347
  )
982
- transaction = Braintree::CreditCard.sale!(customer.credit_cards[0].token, :amount => "100.00")
983
- transaction.amount.should == BigDecimal.new("100.00")
984
- transaction.type.should == "sale"
985
- transaction.customer_details.id.should == customer.id
986
- transaction.credit_card_details.token.should == customer.credit_cards[0].token
987
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
988
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
989
- transaction.credit_card_details.expiration_date.should == "05/2010"
1348
+
1349
+ Braintree::CreditCard.from_nonce(nonce)
1350
+ expect do
1351
+ Braintree::CreditCard.from_nonce(nonce)
1352
+ end.to raise_error(Braintree::NotFoundError, /consumed/)
990
1353
  end
991
1354
  end
992
1355
 
993
- describe "sale" do
1356
+ # NEXT_MAJOR_VERSION remove these tests
1357
+ # CreditCard.sale has been deprecated in favor of Transaction.sale
1358
+ describe "self.sale" do
994
1359
  it "creates a sale transaction using the credit card, returning a result object" do
995
1360
  customer = Braintree::Customer.create!(
996
1361
  :credit_card => {
997
1362
  :number => Braintree::Test::CreditCardNumbers::Visa,
998
1363
  :expiration_date => "05/2010"
999
- }
1000
- )
1001
- result = customer.credit_cards[0].sale(
1002
- :amount => "100.00"
1364
+ },
1003
1365
  )
1004
- result.success?.should == true
1005
- result.transaction.amount.should == BigDecimal.new("100.00")
1006
- result.transaction.type.should == "sale"
1007
- result.transaction.customer_details.id.should == customer.id
1008
- result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
1009
- result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
1010
- result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
1011
- result.transaction.credit_card_details.expiration_date.should == "05/2010"
1366
+ result = Braintree::CreditCard.sale(customer.credit_cards[0].token, :amount => "100.00")
1367
+
1368
+ expect(result.success?).to eq(true)
1369
+ expect(result.transaction.amount).to eq(BigDecimal("100.00"))
1370
+ expect(result.transaction.type).to eq("sale")
1371
+ expect(result.transaction.customer_details.id).to eq(customer.id)
1372
+ expect(result.transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
1373
+ expect(result.transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
1374
+ expect(result.transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
1375
+ expect(result.transaction.credit_card_details.expiration_date).to eq("05/2010")
1012
1376
  end
1013
- end
1014
1377
 
1015
- describe "sale!" do
1016
- it "returns the created sale tranaction if valid" do
1378
+ it "allows passing a cvv in addition to the token" do
1017
1379
  customer = Braintree::Customer.create!(
1018
1380
  :credit_card => {
1019
1381
  :number => Braintree::Test::CreditCardNumbers::Visa,
1020
1382
  :expiration_date => "05/2010"
1021
- }
1383
+ },
1384
+ )
1385
+ result = Braintree::CreditCard.sale(customer.credit_cards[0].token,
1386
+ :amount => "100.00",
1387
+ :credit_card => {
1388
+ :cvv => "301"
1389
+ },
1022
1390
  )
1023
- transaction = customer.credit_cards[0].sale!(:amount => "100.00")
1024
- transaction.amount.should == BigDecimal.new("100.00")
1025
- transaction.type.should == "sale"
1026
- transaction.customer_details.id.should == customer.id
1027
- transaction.credit_card_details.token.should == customer.credit_cards[0].token
1028
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
1029
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
1030
- transaction.credit_card_details.expiration_date.should == "05/2010"
1391
+
1392
+ expect(result.success?).to eq(true)
1393
+ expect(result.transaction.amount).to eq(BigDecimal("100.00"))
1394
+ expect(result.transaction.type).to eq("sale")
1395
+ expect(result.transaction.customer_details.id).to eq(customer.id)
1396
+ expect(result.transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
1397
+ expect(result.transaction.cvv_response_code).to eq("S")
1031
1398
  end
1399
+ end
1032
1400
 
1033
- it "raises a ValidationsFailed if invalid" do
1401
+ # NEXT_MAJOR_VERSION remove this test
1402
+ # CreditCard.sale has been deprecated in favor of Transaction.sale
1403
+ describe "self.sale!" do
1404
+ it "creates a sale transaction using the credit card, returning the transaction" do
1034
1405
  customer = Braintree::Customer.create!(
1035
1406
  :credit_card => {
1036
1407
  :number => Braintree::Test::CreditCardNumbers::Visa,
1037
1408
  :expiration_date => "05/2010"
1038
- }
1409
+ },
1039
1410
  )
1040
- expect do
1041
- customer.credit_cards[0].sale!(:amount => "invalid")
1042
- end.to raise_error(Braintree::ValidationsFailed)
1411
+ transaction = Braintree::CreditCard.sale!(customer.credit_cards[0].token, :amount => "100.00")
1412
+ expect(transaction.amount).to eq(BigDecimal("100.00"))
1413
+ expect(transaction.type).to eq("sale")
1414
+ expect(transaction.customer_details.id).to eq(customer.id)
1415
+ expect(transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
1416
+ expect(transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
1417
+ expect(transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
1418
+ expect(transaction.credit_card_details.expiration_date).to eq("05/2010")
1043
1419
  end
1044
1420
  end
1045
1421
 
1046
- describe "update" do
1047
- it "updates the credit card" do
1048
- customer = Braintree::Customer.create!
1049
- credit_card = Braintree::CreditCard.create!(
1050
- :cardholder_name => "Original Holder",
1051
- :customer_id => customer.id,
1052
- :cvv => "123",
1053
- :number => Braintree::Test::CreditCardNumbers::Visa,
1054
- :expiration_date => "05/2012"
1055
- )
1056
- update_result = credit_card.update(
1057
- :cardholder_name => "New Holder",
1058
- :cvv => "456",
1059
- :number => Braintree::Test::CreditCardNumbers::MasterCard,
1060
- :expiration_date => "06/2013"
1061
- )
1062
- update_result.success?.should == true
1063
- update_result.credit_card.should == credit_card
1064
- updated_credit_card = update_result.credit_card
1065
- updated_credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
1066
- updated_credit_card.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
1067
- updated_credit_card.expiration_date.should == "06/2013"
1068
- updated_credit_card.cardholder_name.should == "New Holder"
1069
- end
1070
-
1071
- it "verifies the update if options[verify_card]=true" do
1072
- customer = Braintree::Customer.create!
1073
- credit_card = Braintree::CreditCard.create!(
1074
- :cardholder_name => "Original Holder",
1075
- :customer_id => customer.id,
1076
- :cvv => "123",
1077
- :number => Braintree::Test::CreditCardNumbers::Visa,
1078
- :expiration_date => "05/2012"
1079
- )
1080
- update_result = credit_card.update(
1081
- :cardholder_name => "New Holder",
1082
- :cvv => "456",
1083
- :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
1084
- :expiration_date => "06/2013",
1085
- :options => {:verify_card => true}
1086
- )
1087
- update_result.success?.should == false
1088
- update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
1089
- end
1090
-
1091
- it "allows user to specify merchant account for verification" do
1092
- customer = Braintree::Customer.create!
1093
- credit_card = Braintree::CreditCard.create!(
1094
- :cardholder_name => "Original Holder",
1095
- :customer_id => customer.id,
1096
- :cvv => "123",
1097
- :number => Braintree::Test::CreditCardNumbers::Visa,
1098
- :expiration_date => "05/2012"
1099
- )
1100
- update_result = credit_card.update(
1101
- :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
1102
- :expiration_date => "05/2009",
1103
- :options => {
1104
- :verify_card => true,
1105
- :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
1106
- }
1107
- )
1108
- update_result.success?.should == false
1109
- update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
1110
- update_result.credit_card_verification.processor_response_code.should == "2000"
1111
- update_result.credit_card_verification.processor_response_text.should == "Do Not Honor"
1112
- update_result.credit_card_verification.cvv_response_code.should == "I"
1113
- update_result.credit_card_verification.avs_error_response_code.should == nil
1114
- update_result.credit_card_verification.avs_postal_code_response_code.should == "I"
1115
- update_result.credit_card_verification.avs_street_address_response_code.should == "I"
1116
- end
1117
-
1118
- it "can update the billing address" do
1422
+ describe "nonce" do
1423
+ it "returns the credit card nonce" do
1119
1424
  customer = Braintree::Customer.create!
1120
1425
  credit_card = Braintree::CreditCard.create!(
1121
1426
  :cardholder_name => "Original Holder",
1122
1427
  :customer_id => customer.id,
1123
- :cvv => "123",
1124
1428
  :number => Braintree::Test::CreditCardNumbers::Visa,
1125
1429
  :expiration_date => "05/2012",
1126
- :billing_address => {
1127
- :first_name => "Old First Name",
1128
- :last_name => "Old Last Name",
1129
- :company => "Old Company",
1130
- :street_address => "123 Old St",
1131
- :extended_address => "Apt Old",
1132
- :locality => "Old City",
1133
- :region => "Old State",
1134
- :postal_code => "12345",
1135
- :country_name => "Canada"
1136
- }
1137
- )
1138
- result = credit_card.update(
1139
- :options => {:verify_card => false},
1140
- :billing_address => {
1141
- :first_name => "New First Name",
1142
- :last_name => "New Last Name",
1143
- :company => "New Company",
1144
- :street_address => "123 New St",
1145
- :extended_address => "Apt New",
1146
- :locality => "New City",
1147
- :region => "New State",
1148
- :postal_code => "56789",
1149
- :country_name => "United States of America"
1150
- }
1151
1430
  )
1152
- result.success?.should == true
1153
- address = result.credit_card.billing_address
1154
- address.should == credit_card.billing_address # making sure credit card instance was updated
1155
- address.first_name.should == "New First Name"
1156
- address.last_name.should == "New Last Name"
1157
- address.company.should == "New Company"
1158
- address.street_address.should == "123 New St"
1159
- address.extended_address.should == "Apt New"
1160
- address.locality.should == "New City"
1161
- address.region.should == "New State"
1162
- address.postal_code.should == "56789"
1163
- address.country_name.should == "United States of America"
1164
- end
1165
1431
 
1166
- it "returns an error response if invalid" do
1167
- customer = Braintree::Customer.create!
1168
- credit_card = Braintree::CreditCard.create!(
1169
- :cardholder_name => "Original Holder",
1170
- :customer_id => customer.id,
1171
- :number => Braintree::Test::CreditCardNumbers::Visa,
1172
- :expiration_date => "05/2012"
1173
- )
1174
- update_result = credit_card.update(
1175
- :cardholder_name => "New Holder",
1176
- :number => "invalid",
1177
- :expiration_date => "05/2014"
1178
- )
1179
- update_result.success?.should == false
1180
- update_result.errors.for(:credit_card).on(:number)[0].message.should == "Credit card number must be 12-19 digits."
1432
+ expect(credit_card.nonce).not_to be_nil
1181
1433
  end
1182
1434
  end
1183
1435
 
1184
- describe "update!" do
1185
- it "updates the credit card and returns true if valid" do
1186
- customer = Braintree::Customer.create!
1187
- credit_card = Braintree::CreditCard.create!(
1188
- :cardholder_name => "Original Holder",
1189
- :customer_id => customer.id,
1190
- :number => Braintree::Test::CreditCardNumbers::Visa,
1191
- :expiration_date => "05/2012"
1192
- )
1193
- credit_card.update!(
1194
- :cardholder_name => "New Holder",
1195
- :number => Braintree::Test::CreditCardNumbers::MasterCard,
1196
- :expiration_date => "06/2013"
1197
- ).should == credit_card
1198
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
1199
- credit_card.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
1200
- credit_card.expiration_date.should == "06/2013"
1201
- credit_card.cardholder_name.should == "New Holder"
1202
- credit_card.updated_at.between?(Time.now - 60, Time.now).should == true
1436
+ describe "card on file network tokenization" do
1437
+ it "should find a network tokenized credit card" do
1438
+ credit_card = Braintree::CreditCard.find("network_tokenized_credit_card")
1439
+ expect(credit_card.is_network_tokenized?).to eq(true)
1203
1440
  end
1204
1441
 
1205
- it "raises a ValidationsFailed if invalid" do
1442
+ it "should find a non-network tokenized credit card" do
1206
1443
  customer = Braintree::Customer.create!
1207
- credit_card = Braintree::CreditCard.create!(
1208
- :cardholder_name => "Original Holder",
1444
+ credit_card = Braintree::CreditCard.create(
1209
1445
  :customer_id => customer.id,
1210
1446
  :number => Braintree::Test::CreditCardNumbers::Visa,
1211
- :expiration_date => "05/2012"
1212
- )
1213
- expect do
1214
- credit_card.update!(
1215
- :cardholder_name => "New Holder",
1216
- :number => Braintree::Test::CreditCardNumbers::MasterCard,
1217
- :expiration_date => "invalid/date"
1218
- )
1219
- end.to raise_error(Braintree::ValidationsFailed)
1447
+ :expiration_date => "05/2009",
1448
+ ).credit_card
1449
+ credit_card_vaulted = Braintree::CreditCard.find(credit_card.token)
1450
+ expect(credit_card_vaulted.is_network_tokenized?).to eq(false)
1220
1451
  end
1221
1452
  end
1222
1453
  end