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
@@ -0,0 +1,325 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
3
+
4
+ describe Braintree::PaymentMethod do
5
+ describe "self.create" do
6
+ context "compliant merchant" do
7
+ before do
8
+ Braintree::Configuration.merchant_id = "integration2_merchant_id"
9
+ Braintree::Configuration.public_key = "integration2_public_key"
10
+ Braintree::Configuration.private_key = "integration2_private_key"
11
+ end
12
+
13
+ context "non plaid verified nonce" do
14
+ let(:nonce) { generate_non_plaid_us_bank_account_nonce }
15
+
16
+ it "succeeds and does not verify when no method provided" do
17
+ customer = Braintree::Customer.create.customer
18
+ result = Braintree::PaymentMethod.create(
19
+ :payment_method_nonce => nonce,
20
+ :customer_id => customer.id,
21
+ :options => {
22
+ :verification_merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
23
+ },
24
+ )
25
+
26
+ expect(result).to be_success
27
+ us_bank_account = result.payment_method
28
+ expect(us_bank_account).to be_a(Braintree::UsBankAccount)
29
+ expect(us_bank_account.routing_number).to eq("021000021")
30
+ expect(us_bank_account.last_4).to eq("0000")
31
+ expect(us_bank_account.account_type).to eq("checking")
32
+ expect(us_bank_account.account_holder_name).to eq("John Doe")
33
+ expect(us_bank_account.bank_name).to match(/CHASE/)
34
+ expect(us_bank_account.default).to eq(true)
35
+ expect(us_bank_account.ach_mandate.text).to eq("cl mandate text")
36
+ expect(us_bank_account.ach_mandate.accepted_at).to be_a Time
37
+
38
+ expect(us_bank_account.verifications.count).to eq(0)
39
+ expect(us_bank_account.verified).to eq(false)
40
+
41
+ expect(Braintree::PaymentMethod.find(us_bank_account.token)).to be_a(Braintree::UsBankAccount)
42
+ end
43
+
44
+ [
45
+ Braintree::UsBankAccountVerification::VerificationMethod::IndependentCheck,
46
+ Braintree::UsBankAccountVerification::VerificationMethod::NetworkCheck,
47
+ ].each do |method|
48
+ it "succeeds and verifies via #{method}" do
49
+ customer = Braintree::Customer.create.customer
50
+ result = Braintree::PaymentMethod.create(
51
+ :payment_method_nonce => nonce,
52
+ :customer_id => customer.id,
53
+ :options => {
54
+ :us_bank_account_verification_method => method,
55
+ :verification_merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
56
+ },
57
+ )
58
+
59
+ expect(result).to be_success
60
+ us_bank_account = result.payment_method
61
+ expect(us_bank_account).to be_a(Braintree::UsBankAccount)
62
+ expect(us_bank_account.routing_number).to eq("021000021")
63
+ expect(us_bank_account.last_4).to eq("0000")
64
+ expect(us_bank_account.account_type).to eq("checking")
65
+ expect(us_bank_account.account_holder_name).to eq("John Doe")
66
+ expect(us_bank_account.bank_name).to match(/CHASE/)
67
+ expect(us_bank_account.default).to eq(true)
68
+ expect(us_bank_account.ach_mandate.text).to eq("cl mandate text")
69
+ expect(us_bank_account.ach_mandate.accepted_at).to be_a Time
70
+
71
+ expect(us_bank_account.verifications.count).to eq(1)
72
+ expect(us_bank_account.verifications.first.status).to eq(Braintree::UsBankAccountVerification::Status::Verified)
73
+ expect(us_bank_account.verifications.first.verification_method).to eq(method)
74
+ expect(us_bank_account.verifications.first.id).not_to be_empty
75
+ expect(us_bank_account.verifications.first.verification_determined_at).to be_a Time
76
+ expect(us_bank_account.verified).to eq(true)
77
+
78
+ expect(Braintree::PaymentMethod.find(us_bank_account.token)).to be_a(Braintree::UsBankAccount)
79
+ end
80
+ end
81
+
82
+ it "succeeds and verifies with verification_add_ons for NetworkCheck with fake nonce" do
83
+ customer = Braintree::Customer.create.customer
84
+ result = Braintree::PaymentMethod.create(
85
+ :payment_method_nonce => Braintree::Test::Nonce::UsBankAccount,
86
+ :customer_id => customer.id,
87
+ :options => {
88
+ :us_bank_account_verification_method => Braintree::UsBankAccountVerification::VerificationMethod::NetworkCheck,
89
+ :verification_add_ons => Braintree::UsBankAccountVerification::VerificationAddOns::CustomerVerification,
90
+ :verification_merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
91
+ },
92
+ )
93
+
94
+ expect(result).to be_success
95
+ us_bank_account = result.payment_method
96
+ expect(us_bank_account).to be_a(Braintree::UsBankAccount)
97
+ expect(us_bank_account.routing_number).to eq("123456789")
98
+ expect(us_bank_account.last_4).to eq("0000")
99
+ expect(us_bank_account.account_type).to eq("checking")
100
+ expect(us_bank_account.account_holder_name).to eq("Dan Schulman")
101
+ expect(us_bank_account.bank_name).to match(/Wells Fargo/)
102
+ expect(us_bank_account.default).to eq(true)
103
+ expect(us_bank_account.ach_mandate.text).to eq("example mandate text")
104
+ expect(us_bank_account.ach_mandate.accepted_at).to be_a Time
105
+
106
+ expect(us_bank_account.verifications.count).to eq(1)
107
+ expect(us_bank_account.verifications.first.status).to eq(Braintree::UsBankAccountVerification::Status::Verified)
108
+ expect(us_bank_account.verifications.first.verification_method).to eq(Braintree::UsBankAccountVerification::VerificationMethod::NetworkCheck)
109
+ expect(us_bank_account.verifications.first.id).not_to be_empty
110
+ expect(us_bank_account.verifications.first.verification_determined_at).to be_a Time
111
+ expect(us_bank_account.verifications.first.processor_response_code).to eq("1000")
112
+ expect(us_bank_account.verified).to eq(true)
113
+
114
+ expect(Braintree::PaymentMethod.find(us_bank_account.token)).to be_a(Braintree::UsBankAccount)
115
+ end
116
+
117
+ it "returns additional processor response for failed NetworkCheck" do
118
+ customer = Braintree::Customer.create.customer
119
+ invalid_nonce = generate_non_plaid_us_bank_account_nonce("1000000005")
120
+ result = Braintree::PaymentMethod.create(
121
+ :payment_method_nonce => invalid_nonce,
122
+ :customer_id => customer.id,
123
+ :options => {
124
+ :us_bank_account_verification_method => Braintree::UsBankAccountVerification::VerificationMethod::NetworkCheck,
125
+ :verification_merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
126
+ },
127
+ )
128
+
129
+ expect(result).to be_success
130
+ us_bank_account = result.payment_method
131
+ expect(us_bank_account).to be_a(Braintree::UsBankAccount)
132
+ expect(us_bank_account.routing_number).to eq("021000021")
133
+ expect(us_bank_account.last_4).to eq("0005")
134
+ expect(us_bank_account.account_type).to eq("checking")
135
+ expect(us_bank_account.account_holder_name).to eq("John Doe")
136
+ expect(us_bank_account.bank_name).to match(/CHASE/)
137
+ expect(us_bank_account.default).to eq(true)
138
+ expect(us_bank_account.ach_mandate.text).to eq("cl mandate text")
139
+ expect(us_bank_account.ach_mandate.accepted_at).to be_a Time
140
+
141
+ expect(us_bank_account.verifications.count).to eq(1)
142
+ expect(us_bank_account.verifications.first.status).to eq(Braintree::UsBankAccountVerification::Status::ProcessorDeclined)
143
+ expect(us_bank_account.verifications.first.verification_method).to eq(Braintree::UsBankAccountVerification::VerificationMethod::NetworkCheck)
144
+ expect(us_bank_account.verifications.first.id).not_to be_empty
145
+ expect(us_bank_account.verifications.first.verification_determined_at).to be_a Time
146
+ expect(us_bank_account.verifications.first.processor_response_code).to eq("2061")
147
+ expect(us_bank_account.verifications.first.additional_processor_response).to eq("Invalid routing number")
148
+
149
+ expect(us_bank_account.verified).to eq(false)
150
+
151
+ expect(Braintree::PaymentMethod.find(us_bank_account.token)).to be_a(Braintree::UsBankAccount)
152
+ end
153
+ end
154
+
155
+ it "fails with invalid nonce" do
156
+ customer = Braintree::Customer.create.customer
157
+ result = Braintree::PaymentMethod.create(
158
+ :payment_method_nonce => generate_invalid_us_bank_account_nonce,
159
+ :customer_id => customer.id,
160
+ )
161
+
162
+ expect(result).not_to be_success
163
+ expect(result.errors.for(:payment_method).on(:payment_method_nonce)[0].code).to eq(Braintree::ErrorCodes::PaymentMethod::PaymentMethodNonceUnknown)
164
+ end
165
+ end
166
+
167
+ context "exempt merchant" do
168
+ it "fails with invalid nonce" do
169
+ customer = Braintree::Customer.create.customer
170
+ result = Braintree::PaymentMethod.create(
171
+ :payment_method_nonce => generate_invalid_us_bank_account_nonce,
172
+ :customer_id => customer.id,
173
+ )
174
+
175
+ expect(result).not_to be_success
176
+ expect(result.errors.for(:payment_method).on(:payment_method_nonce)[0].code).to eq(Braintree::ErrorCodes::PaymentMethod::PaymentMethodNonceUnknown)
177
+ end
178
+ end
179
+ end
180
+
181
+ context "self.update" do
182
+ context "compliant merchant" do
183
+ before do
184
+ Braintree::Configuration.merchant_id = "integration2_merchant_id"
185
+ Braintree::Configuration.public_key = "integration2_public_key"
186
+ Braintree::Configuration.private_key = "integration2_private_key"
187
+ end
188
+
189
+ context "unverified token" do
190
+ let(:payment_method) do
191
+ customer = Braintree::Customer.create.customer
192
+ Braintree::PaymentMethod.create(
193
+ :payment_method_nonce => generate_non_plaid_us_bank_account_nonce,
194
+ :customer_id => customer.id,
195
+ :options => {
196
+ :verification_merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
197
+ },
198
+ ).payment_method
199
+ end
200
+
201
+ [
202
+ Braintree::UsBankAccountVerification::VerificationMethod::IndependentCheck,
203
+ Braintree::UsBankAccountVerification::VerificationMethod::NetworkCheck,
204
+ ].each do |method|
205
+ it "succeeds and verifies via #{method}" do
206
+ result = Braintree::PaymentMethod.update(
207
+ payment_method.token,
208
+ :options => {
209
+ :verification_merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
210
+ :us_bank_account_verification_method => method,
211
+ },
212
+ )
213
+
214
+ expect(result).to be_success
215
+
216
+ us_bank_account = result.payment_method
217
+ expect(us_bank_account).to be_a(Braintree::UsBankAccount)
218
+ expect(us_bank_account.routing_number).to eq("021000021")
219
+ expect(us_bank_account.last_4).to eq("0000")
220
+ expect(us_bank_account.account_type).to eq("checking")
221
+ expect(us_bank_account.account_holder_name).to eq("John Doe")
222
+ expect(us_bank_account.bank_name).to match(/CHASE/)
223
+ expect(us_bank_account.default).to eq(true)
224
+ expect(us_bank_account.ach_mandate.text).to eq("cl mandate text")
225
+ expect(us_bank_account.ach_mandate.accepted_at).to be_a Time
226
+
227
+ expect(us_bank_account.verifications.count).to eq(1)
228
+ expect(us_bank_account.verifications.first.status).to eq(Braintree::UsBankAccountVerification::Status::Verified)
229
+ expect(us_bank_account.verifications.first.verification_method).to eq(method)
230
+ expect(us_bank_account.verifications.first.id).not_to be_empty
231
+ expect(us_bank_account.verifications.first.verification_determined_at).to be_a Time
232
+ expect(us_bank_account.verified).to eq(true)
233
+
234
+ expect(Braintree::PaymentMethod.find(us_bank_account.token)).to be_a(Braintree::UsBankAccount)
235
+ end
236
+ end
237
+
238
+ it "fails with invalid verification method" do
239
+ result = Braintree::PaymentMethod.update(
240
+ payment_method.token,
241
+ :options => {
242
+ :verification_merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
243
+ :us_bank_account_verification_method => "blahblah",
244
+ },
245
+ )
246
+
247
+ expect(result).not_to be_success
248
+ expect(result.errors.for(:options).first.code).to eq(Braintree::ErrorCodes::PaymentMethod::Options::UsBankAccountVerificationMethodIsInvalid)
249
+ end
250
+ end
251
+ end
252
+
253
+ context "exempt merchant" do
254
+ before do
255
+ Braintree::Configuration.merchant_id = "integration_merchant_id"
256
+ Braintree::Configuration.public_key = "integration_public_key"
257
+ Braintree::Configuration.private_key = "integration_private_key"
258
+ end
259
+
260
+ context "unverified token" do
261
+ let(:payment_method) do
262
+ customer = Braintree::Customer.create.customer
263
+ Braintree::PaymentMethod.create(
264
+ :payment_method_nonce => generate_non_plaid_us_bank_account_nonce,
265
+ :customer_id => customer.id,
266
+ :options => {
267
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
268
+ },
269
+ ).payment_method
270
+ end
271
+
272
+ [
273
+ Braintree::UsBankAccountVerification::VerificationMethod::IndependentCheck,
274
+ Braintree::UsBankAccountVerification::VerificationMethod::NetworkCheck,
275
+ ].each do |method|
276
+ it "succeeds and verifies via #{method}" do
277
+ result = Braintree::PaymentMethod.update(
278
+ payment_method.token,
279
+ :options => {
280
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
281
+ :us_bank_account_verification_method => method,
282
+ },
283
+ )
284
+
285
+ expect(result).to be_success
286
+
287
+ us_bank_account = result.payment_method
288
+ expect(us_bank_account).to be_a(Braintree::UsBankAccount)
289
+ expect(us_bank_account.routing_number).to eq("021000021")
290
+ expect(us_bank_account.last_4).to eq("0000")
291
+ expect(us_bank_account.account_type).to eq("checking")
292
+ expect(us_bank_account.account_holder_name).to eq("John Doe")
293
+ expect(us_bank_account.bank_name).to match(/CHASE/)
294
+ expect(us_bank_account.default).to eq(true)
295
+ expect(us_bank_account.ach_mandate.text).to eq("cl mandate text")
296
+ expect(us_bank_account.ach_mandate.accepted_at).to be_a Time
297
+
298
+ expect(us_bank_account.verifications.count).to eq(2)
299
+ verification = us_bank_account.verifications.find do |verification|
300
+ verification.verification_method == method
301
+ end
302
+ expect(verification.status).to eq(Braintree::UsBankAccountVerification::Status::Verified)
303
+ expect(verification.id).not_to be_empty
304
+ expect(verification.verification_determined_at).to be_a Time
305
+ expect(us_bank_account.verified).to eq(true)
306
+
307
+ expect(Braintree::PaymentMethod.find(us_bank_account.token)).to be_a(Braintree::UsBankAccount)
308
+ end
309
+ end
310
+
311
+ it "fails with invalid verification method" do
312
+ result = Braintree::PaymentMethod.update(
313
+ payment_method.token,
314
+ :options => {
315
+ :us_bank_account_verification_method => "blahblah",
316
+ },
317
+ )
318
+
319
+ expect(result).not_to be_success
320
+ expect(result.errors.for(:options).first.code).to eq(Braintree::ErrorCodes::PaymentMethod::Options::UsBankAccountVerificationMethodIsInvalid)
321
+ end
322
+ end
323
+ end
324
+ end
325
+ end
@@ -0,0 +1,299 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
3
+
4
+ describe Braintree::PayPalAccount do
5
+ describe "self.find" do
6
+ it "returns a PayPalAccount" do
7
+ customer = Braintree::Customer.create!
8
+ payment_method_token = random_payment_method_token
9
+
10
+ nonce = nonce_for_paypal_account(
11
+ :consent_code => "consent-code",
12
+ :token => payment_method_token,
13
+ )
14
+ result = Braintree::PaymentMethod.create(
15
+ :payment_method_nonce => nonce,
16
+ :customer_id => customer.id,
17
+ )
18
+ expect(result).to be_success
19
+
20
+ paypal_account = Braintree::PayPalAccount.find(payment_method_token)
21
+ expect(paypal_account).to be_a(Braintree::PayPalAccount)
22
+ expect(paypal_account.token).to eq(payment_method_token)
23
+ expect(paypal_account.email).to eq("jane.doe@example.com")
24
+ expect(paypal_account.image_url).not_to be_nil
25
+ expect(paypal_account.created_at).not_to be_nil
26
+ expect(paypal_account.updated_at).not_to be_nil
27
+ expect(paypal_account.customer_id).to eq(customer.id)
28
+ expect(paypal_account.funding_source_description).to be_nil
29
+ expect(paypal_account.edit_paypal_vault_id).to be_nil
30
+ expect(paypal_account.revoked_at).to be_nil
31
+ end
32
+
33
+ it "returns a PayPalAccount with a billing agreement id" do
34
+ customer = Braintree::Customer.create!
35
+ payment_method_token = random_payment_method_token
36
+
37
+ result = Braintree::PaymentMethod.create(
38
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
39
+ :customer_id => customer.id,
40
+ :token => payment_method_token,
41
+ )
42
+ expect(result).to be_success
43
+
44
+ paypal_account = Braintree::PayPalAccount.find(payment_method_token)
45
+ expect(paypal_account.billing_agreement_id).not_to be_nil
46
+ end
47
+
48
+ it "raises if the payment method token is not found" do
49
+ expect do
50
+ Braintree::PayPalAccount.find("nonexistant-paypal-account")
51
+ end.to raise_error(Braintree::NotFoundError)
52
+ end
53
+
54
+ it "does not return a different payment method type" do
55
+ customer = Braintree::Customer.create!
56
+ Braintree::CreditCard.create(
57
+ :customer_id => customer.id,
58
+ :number => Braintree::Test::CreditCardNumbers::Visa,
59
+ :expiration_date => "05/2009",
60
+ :cvv => "100",
61
+ :token => "CREDIT_CARD_TOKEN",
62
+ )
63
+
64
+ expect do
65
+ Braintree::PayPalAccount.find("CREDIT_CARD_TOKEN")
66
+ end.to raise_error(Braintree::NotFoundError)
67
+ end
68
+
69
+ it "returns subscriptions associated with a paypal account" do
70
+ customer = Braintree::Customer.create!
71
+ payment_method_token = random_payment_method_token
72
+
73
+ nonce = nonce_for_paypal_account(
74
+ :consent_code => "consent-code",
75
+ :token => payment_method_token,
76
+ )
77
+ result = Braintree::PaymentMethod.create(
78
+ :payment_method_nonce => nonce,
79
+ :customer_id => customer.id,
80
+ )
81
+ expect(result).to be_success
82
+
83
+ token = result.payment_method.token
84
+
85
+ subscription1 = Braintree::Subscription.create(
86
+ :payment_method_token => token,
87
+ :plan_id => SpecHelper::TriallessPlan[:id],
88
+ ).subscription
89
+
90
+ subscription2 = Braintree::Subscription.create(
91
+ :payment_method_token => token,
92
+ :plan_id => SpecHelper::TriallessPlan[:id],
93
+ ).subscription
94
+
95
+ paypal_account = Braintree::PayPalAccount.find(token)
96
+ expect(paypal_account.subscriptions.map(&:id).sort).to eq([subscription1.id, subscription2.id].sort)
97
+ end
98
+ end
99
+
100
+ describe "self.create" do
101
+ it "creates a PayPalAccount" do
102
+ customer = Braintree::Customer.create!
103
+ result = Braintree::PayPalAccount.create(
104
+ :customer_id => customer.id,
105
+ :billing_agreement_id => "some_billing_agreement_id",
106
+ :email => "some@example.com",
107
+ :options => {
108
+ :make_default => true,
109
+ :fail_on_duplicate_payment_method => true,
110
+ },
111
+ )
112
+
113
+ expect(result).to be_success
114
+ expect(result.paypal_account.billing_agreement_id).to eq("some_billing_agreement_id")
115
+ expect(result.paypal_account.email).to eq("some@example.com")
116
+ end
117
+
118
+ it "throws an error if customer id is not specified" do
119
+ result = Braintree::PayPalAccount.create(
120
+ :billing_agreement_id => "some_billing_agreement_id",
121
+ :email => "some@example.com",
122
+ )
123
+
124
+ expect(result.success?).to eq(false)
125
+ expect(result.errors.first.code).to eq("82905")
126
+ end
127
+
128
+ it "throws an error if billing agreement id is not specified" do
129
+ customer = Braintree::Customer.create!
130
+ result = Braintree::PayPalAccount.create(
131
+ :customer_id => customer.id,
132
+ :email => "some@example.com",
133
+ )
134
+
135
+ expect(result.success?).to eq(false)
136
+ expect(result.errors.map(&:code)).to include("82902")
137
+ end
138
+ end
139
+
140
+ describe "self.update" do
141
+ it "updates a PayPalAccount" do
142
+ customer = Braintree::Customer.create!
143
+ create_result = Braintree::PayPalAccount.create(
144
+ :customer_id => customer.id,
145
+ :billing_agreement_id => "first_billing_agreement_id",
146
+ :email => "first@example.com",
147
+ )
148
+ expect(create_result.success?).to eq(true)
149
+
150
+ update_result = Braintree::PayPalAccount.update(
151
+ create_result.paypal_account.token,
152
+ :billing_agreement_id => "second_billing_agreement_id",
153
+ :email => "second@example.com",
154
+ )
155
+
156
+ expect(update_result.success?).to eq(true)
157
+ paypal_account = update_result.paypal_account
158
+
159
+ expect(paypal_account.billing_agreement_id).to eq("second_billing_agreement_id")
160
+ expect(paypal_account.email).to eq("second@example.com")
161
+ end
162
+
163
+ it "updates a paypal account's token" do
164
+ customer = Braintree::Customer.create!
165
+ original_token = random_payment_method_token
166
+ nonce = nonce_for_paypal_account(
167
+ :consent_code => "consent-code",
168
+ :token => original_token,
169
+ )
170
+ original_result = Braintree::PaymentMethod.create(
171
+ :payment_method_nonce => nonce,
172
+ :customer_id => customer.id,
173
+ )
174
+
175
+ updated_token = "UPDATED_TOKEN-" + rand(36**3).to_s(36)
176
+ Braintree::PayPalAccount.update(
177
+ original_token,
178
+ :token => updated_token,
179
+ )
180
+
181
+ updated_paypal_account = Braintree::PayPalAccount.find(updated_token)
182
+ expect(updated_paypal_account.email).to eq(original_result.payment_method.email)
183
+
184
+ expect do
185
+ Braintree::PayPalAccount.find(original_token)
186
+ end.to raise_error(Braintree::NotFoundError, "payment method with token \"#{original_token}\" not found")
187
+ end
188
+
189
+ it "can make a paypal account the default payment method" do
190
+ customer = Braintree::Customer.create!
191
+ result = Braintree::CreditCard.create(
192
+ :customer_id => customer.id,
193
+ :number => Braintree::Test::CreditCardNumbers::Visa,
194
+ :expiration_date => "05/2009",
195
+ :options => {:make_default => true},
196
+ )
197
+ expect(result).to be_success
198
+
199
+ nonce = nonce_for_paypal_account(:consent_code => "consent-code")
200
+ original_token = Braintree::PaymentMethod.create(
201
+ :payment_method_nonce => nonce,
202
+ :customer_id => customer.id,
203
+ ).payment_method.token
204
+
205
+ Braintree::PayPalAccount.update(
206
+ original_token,
207
+ :options => {:make_default => true},
208
+ )
209
+
210
+ updated_paypal_account = Braintree::PayPalAccount.find(original_token)
211
+ expect(updated_paypal_account).to be_default
212
+ end
213
+
214
+ it "returns an error if a token for account is used to attempt an update" do
215
+ customer = Braintree::Customer.create!
216
+ first_token = random_payment_method_token
217
+ second_token = random_payment_method_token
218
+
219
+ first_nonce = nonce_for_paypal_account(
220
+ :consent_code => "consent-code",
221
+ :token => first_token,
222
+ )
223
+ Braintree::PaymentMethod.create(
224
+ :payment_method_nonce => first_nonce,
225
+ :customer_id => customer.id,
226
+ )
227
+
228
+ second_nonce = nonce_for_paypal_account(
229
+ :consent_code => "consent-code",
230
+ :token => second_token,
231
+ )
232
+ Braintree::PaymentMethod.create(
233
+ :payment_method_nonce => second_nonce,
234
+ :customer_id => customer.id,
235
+ )
236
+
237
+ updated_result = Braintree::PayPalAccount.update(
238
+ first_token,
239
+ :token => second_token,
240
+ )
241
+
242
+ expect(updated_result).not_to be_success
243
+ expect(updated_result.errors.first.code).to eq("92906")
244
+ end
245
+ end
246
+
247
+ context "self.delete" do
248
+ it "deletes a PayPal account" do
249
+ customer = Braintree::Customer.create!
250
+ token = random_payment_method_token
251
+
252
+ nonce = nonce_for_paypal_account(
253
+ :consent_code => "consent-code",
254
+ :token => token,
255
+ )
256
+ Braintree::PaymentMethod.create(
257
+ :payment_method_nonce => nonce,
258
+ :customer_id => customer.id,
259
+ )
260
+
261
+ Braintree::PayPalAccount.delete(token)
262
+
263
+ expect do
264
+ Braintree::PayPalAccount.find(token)
265
+ end.to raise_error(Braintree::NotFoundError, "payment method with token \"#{token}\" not found")
266
+ end
267
+ end
268
+
269
+ context "self.sale" do
270
+ it "creates a transaction using a paypal account and returns a result object" do
271
+ customer = Braintree::Customer.create!(
272
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
273
+ )
274
+
275
+ result = Braintree::PayPalAccount.sale(customer.paypal_accounts[0].token, :amount => "100.00")
276
+
277
+ expect(result.success?).to eq(true)
278
+ expect(result.transaction.amount).to eq(BigDecimal("100.00"))
279
+ expect(result.transaction.type).to eq("sale")
280
+ expect(result.transaction.customer_details.id).to eq(customer.id)
281
+ expect(result.transaction.paypal_details.token).to eq(customer.paypal_accounts[0].token)
282
+ end
283
+ end
284
+
285
+ context "self.sale!" do
286
+ it "creates a transaction using a paypal account and returns a transaction" do
287
+ customer = Braintree::Customer.create!(
288
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
289
+ )
290
+
291
+ transaction = Braintree::PayPalAccount.sale!(customer.paypal_accounts[0].token, :amount => "100.00")
292
+
293
+ expect(transaction.amount).to eq(BigDecimal("100.00"))
294
+ expect(transaction.type).to eq("sale")
295
+ expect(transaction.customer_details.id).to eq(customer.id)
296
+ expect(transaction.paypal_details.token).to eq(customer.paypal_accounts[0].token)
297
+ end
298
+ end
299
+ end