braintree 2.74.0 → 4.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (286) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +13 -7
  4. data/lib/braintree/account_updater_daily_report.rb +2 -2
  5. data/lib/braintree/ach_mandate.rb +2 -1
  6. data/lib/braintree/address/country_names.rb +4 -1
  7. data/lib/braintree/address.rb +30 -38
  8. data/lib/braintree/address_gateway.rb +12 -2
  9. data/lib/braintree/advanced_search.rb +8 -0
  10. data/lib/braintree/apple_pay.rb +29 -0
  11. data/lib/braintree/apple_pay_card.rb +28 -4
  12. data/lib/braintree/apple_pay_gateway.rb +37 -0
  13. data/lib/braintree/apple_pay_options.rb +19 -0
  14. data/lib/braintree/authorization_adjustment.rb +23 -0
  15. data/lib/braintree/base_module.rb +10 -0
  16. data/lib/braintree/bin_data.rb +33 -0
  17. data/lib/braintree/client_token.rb +3 -3
  18. data/lib/braintree/client_token_gateway.rb +3 -1
  19. data/lib/braintree/configuration.rb +57 -10
  20. data/lib/braintree/connected_merchant_paypal_status_changed.rb +6 -2
  21. data/lib/braintree/connected_merchant_status_transitioned.rb +6 -2
  22. data/lib/braintree/credentials_parser.rb +5 -1
  23. data/lib/braintree/credit_card.rb +53 -107
  24. data/lib/braintree/credit_card_gateway.rb +43 -30
  25. data/lib/braintree/credit_card_verification.rb +61 -21
  26. data/lib/braintree/credit_card_verification_gateway.rb +19 -6
  27. data/lib/braintree/credit_card_verification_search.rb +1 -1
  28. data/lib/braintree/customer.rb +51 -98
  29. data/lib/braintree/customer_gateway.rb +30 -23
  30. data/lib/braintree/customer_search.rb +1 -1
  31. data/lib/braintree/descriptor.rb +3 -1
  32. data/lib/braintree/disbursement.rb +24 -2
  33. data/lib/braintree/dispute/evidence.rb +24 -0
  34. data/lib/braintree/{transaction/coinbase_details.rb → dispute/paypal_message.rb} +5 -3
  35. data/lib/braintree/dispute/status_history.rb +18 -0
  36. data/lib/braintree/dispute/transaction.rb +20 -0
  37. data/lib/braintree/dispute/transaction_details.rb +2 -1
  38. data/lib/braintree/dispute.rb +114 -10
  39. data/lib/braintree/dispute_gateway.rb +142 -0
  40. data/lib/braintree/dispute_search.rb +31 -0
  41. data/lib/braintree/document_upload.rb +37 -0
  42. data/lib/braintree/document_upload_gateway.rb +38 -0
  43. data/lib/braintree/enriched_customer_data.rb +21 -0
  44. data/lib/braintree/error_codes.rb +328 -109
  45. data/lib/braintree/error_result.rb +8 -1
  46. data/lib/braintree/exceptions.rb +5 -3
  47. data/lib/braintree/exchange_rate.rb +13 -0
  48. data/lib/braintree/exchange_rate_quote.rb +24 -0
  49. data/lib/braintree/exchange_rate_quote_gateway.rb +35 -0
  50. data/lib/braintree/exchange_rate_quote_input.rb +21 -0
  51. data/lib/braintree/exchange_rate_quote_request.rb +18 -0
  52. data/lib/braintree/exchange_rate_quote_response.rb +18 -0
  53. data/lib/braintree/facilitated_details.rb +21 -0
  54. data/lib/braintree/facilitator_details.rb +2 -1
  55. data/lib/braintree/gateway.rb +29 -11
  56. data/lib/braintree/google_pay_card.rb +61 -0
  57. data/lib/braintree/granted_payment_instrument_update.rb +23 -0
  58. data/lib/braintree/graphql_client.rb +34 -0
  59. data/lib/braintree/http.rb +81 -20
  60. data/lib/braintree/local_payment_completed.rb +23 -0
  61. data/lib/braintree/local_payment_expired.rb +21 -0
  62. data/lib/braintree/local_payment_funded.rb +22 -0
  63. data/lib/braintree/local_payment_reversed.rb +19 -0
  64. data/lib/braintree/merchant.rb +11 -4
  65. data/lib/braintree/merchant_account/address_details.rb +4 -1
  66. data/lib/braintree/merchant_account/business_details.rb +4 -1
  67. data/lib/braintree/merchant_account/funding_details.rb +6 -1
  68. data/lib/braintree/merchant_account/individual_details.rb +7 -2
  69. data/lib/braintree/merchant_account.rb +23 -10
  70. data/lib/braintree/merchant_account_gateway.rb +13 -1
  71. data/lib/braintree/merchant_gateway.rb +2 -2
  72. data/lib/braintree/modification.rb +1 -1
  73. data/lib/braintree/oauth_credentials.rb +5 -2
  74. data/lib/braintree/oauth_gateway.rb +8 -14
  75. data/lib/braintree/paginated_result.rb +3 -1
  76. data/lib/braintree/payment_instrument_type.rb +11 -11
  77. data/lib/braintree/payment_method.rb +20 -12
  78. data/lib/braintree/payment_method_customer_data_updated_metadata.rb +24 -0
  79. data/lib/braintree/payment_method_gateway.rb +82 -54
  80. data/lib/braintree/payment_method_nonce.rb +22 -8
  81. data/lib/braintree/payment_method_nonce_details.rb +40 -0
  82. data/lib/braintree/payment_method_nonce_details_payer_info.rb +32 -0
  83. data/lib/braintree/payment_method_nonce_gateway.rb +19 -2
  84. data/lib/braintree/payment_method_parser.rb +28 -0
  85. data/lib/braintree/paypal_account.rb +10 -1
  86. data/lib/braintree/plan.rb +25 -5
  87. data/lib/braintree/plan_gateway.rb +100 -0
  88. data/lib/braintree/processor_response_types.rb +7 -0
  89. data/lib/braintree/resource_collection.rb +8 -3
  90. data/lib/braintree/revoked_payment_method_metadata.rb +22 -0
  91. data/lib/braintree/risk_data/liability_shift.rb +22 -0
  92. data/lib/braintree/risk_data.rb +12 -2
  93. data/lib/braintree/samsung_pay_card.rb +83 -0
  94. data/lib/braintree/sepa_direct_debit_account.rb +60 -0
  95. data/lib/braintree/sepa_direct_debit_account_gateway.rb +25 -0
  96. data/lib/braintree/sepa_direct_debit_account_nonce_details.rb +28 -0
  97. data/lib/braintree/settlement_batch_summary.rb +2 -1
  98. data/lib/braintree/settlement_batch_summary_gateway.rb +2 -0
  99. data/lib/braintree/subscription/status_details.rb +8 -1
  100. data/lib/braintree/subscription.rb +56 -41
  101. data/lib/braintree/subscription_gateway.rb +25 -2
  102. data/lib/braintree/successful_result.rb +23 -1
  103. data/lib/braintree/test/authentication_id.rb +21 -0
  104. data/lib/braintree/test/credit_card.rb +13 -0
  105. data/lib/braintree/test/nonce.rb +28 -20
  106. data/lib/braintree/test/transaction_amounts.rb +1 -0
  107. data/lib/braintree/three_d_secure_info.rb +34 -2
  108. data/lib/braintree/transaction/address_details.rb +24 -4
  109. data/lib/braintree/transaction/apple_pay_details.rb +20 -2
  110. data/lib/braintree/transaction/credit_card_details.rb +45 -6
  111. data/lib/braintree/transaction/customer_details.rb +8 -1
  112. data/lib/braintree/transaction/disbursement_details.rb +6 -1
  113. data/lib/braintree/transaction/google_pay_details.rb +41 -0
  114. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  115. data/lib/braintree/transaction/installment.rb +28 -0
  116. data/lib/braintree/transaction/local_payment_details.rb +24 -0
  117. data/lib/braintree/transaction/paypal_details.rb +26 -4
  118. data/lib/braintree/transaction/paypal_here_details.rb +23 -0
  119. data/lib/braintree/transaction/{masterpass_card_details.rb → samsung_pay_card_details.rb} +21 -6
  120. data/lib/braintree/transaction/sepa_direct_debit_account_details.rb +27 -0
  121. data/lib/braintree/transaction/status_details.rb +5 -1
  122. data/lib/braintree/transaction/subscription_details.rb +4 -1
  123. data/lib/braintree/transaction/us_bank_account_details.rb +8 -1
  124. data/lib/braintree/transaction/venmo_account_details.rb +5 -1
  125. data/lib/braintree/transaction/visa_checkout_card_details.rb +19 -4
  126. data/lib/braintree/transaction.rb +201 -188
  127. data/lib/braintree/transaction_gateway.rb +124 -30
  128. data/lib/braintree/transaction_line_item.rb +40 -0
  129. data/lib/braintree/transaction_line_item_gateway.rb +19 -0
  130. data/lib/braintree/transaction_review.rb +18 -0
  131. data/lib/braintree/transaction_search.rb +6 -3
  132. data/lib/braintree/unknown_payment_method.rb +3 -2
  133. data/lib/braintree/us_bank_account.rb +24 -8
  134. data/lib/braintree/us_bank_account_gateway.rb +0 -1
  135. data/lib/braintree/us_bank_account_verification.rb +81 -0
  136. data/lib/braintree/us_bank_account_verification_gateway.rb +51 -0
  137. data/lib/braintree/us_bank_account_verification_search.rb +19 -0
  138. data/lib/braintree/util.rb +79 -9
  139. data/lib/braintree/validation_error.rb +13 -3
  140. data/lib/braintree/validation_error_collection.rb +2 -1
  141. data/lib/braintree/venmo_account.rb +11 -4
  142. data/lib/braintree/venmo_profile_data.rb +23 -0
  143. data/lib/braintree/version.rb +2 -2
  144. data/lib/braintree/visa_checkout_card.rb +29 -13
  145. data/lib/braintree/webhook_notification.rb +66 -26
  146. data/lib/braintree/webhook_notification_gateway.rb +5 -3
  147. data/lib/braintree/webhook_testing.rb +2 -2
  148. data/lib/braintree/webhook_testing_gateway.rb +721 -55
  149. data/lib/braintree/xml/generator.rb +6 -4
  150. data/lib/braintree/xml/parser.rb +22 -35
  151. data/lib/braintree/xml/rexml.rb +4 -5
  152. data/lib/braintree.rb +60 -22
  153. data/lib/ssl/api_braintreegateway_com.ca.crt +50 -0
  154. data/spec/fixtures/files/bt_logo.png +0 -0
  155. data/spec/fixtures/files/gif_extension_bt_logo.gif +0 -0
  156. data/spec/fixtures/files/malformed_pdf.pdf +1 -0
  157. data/spec/fixtures/files/too_long.pdf +0 -0
  158. data/spec/integration/braintree/add_on_spec.rb +3 -3
  159. data/spec/integration/braintree/address_spec.rb +30 -113
  160. data/spec/integration/braintree/advanced_search_spec.rb +45 -45
  161. data/spec/integration/braintree/apple_pay_spec.rb +63 -0
  162. data/spec/integration/braintree/braintree_gateway_spec.rb +72 -0
  163. data/spec/integration/braintree/client_api/client_token_spec.rb +14 -32
  164. data/spec/integration/braintree/client_api/spec_helper.rb +104 -65
  165. data/spec/integration/braintree/credit_card_spec.rb +460 -615
  166. data/spec/integration/braintree/credit_card_verification_search_spec.rb +2 -2
  167. data/spec/integration/braintree/credit_card_verification_spec.rb +222 -6
  168. data/spec/integration/braintree/customer_search_spec.rb +8 -8
  169. data/spec/integration/braintree/customer_spec.rb +810 -498
  170. data/spec/integration/braintree/discount_spec.rb +1 -1
  171. data/spec/integration/braintree/dispute_search_spec.rb +167 -0
  172. data/spec/integration/braintree/dispute_spec.rb +333 -0
  173. data/spec/integration/braintree/document_upload_spec.rb +87 -0
  174. data/spec/integration/braintree/error_codes_spec.rb +1 -1
  175. data/spec/integration/braintree/exchange_rate_quote_spec.rb +97 -0
  176. data/spec/integration/braintree/graphql_client_spec.rb +72 -0
  177. data/spec/integration/braintree/http_spec.rb +12 -4
  178. data/spec/integration/braintree/merchant_account_spec.rb +74 -26
  179. data/spec/integration/braintree/merchant_spec.rb +39 -13
  180. data/spec/integration/braintree/oauth_spec.rb +18 -25
  181. data/spec/integration/braintree/payment_method_nonce_spec.rb +239 -5
  182. data/spec/integration/braintree/payment_method_spec.rb +882 -300
  183. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +416 -0
  184. data/spec/integration/braintree/paypal_account_spec.rb +32 -31
  185. data/spec/integration/braintree/plan_spec.rb +82 -0
  186. data/spec/integration/braintree/samsung_pay_card_spec.rb +144 -0
  187. data/spec/integration/braintree/sepa_direct_debit_account_spec.rb +196 -0
  188. data/spec/integration/braintree/settlement_batch_summary_spec.rb +8 -8
  189. data/spec/integration/braintree/subscription_spec.rb +274 -180
  190. data/spec/integration/braintree/test/transaction_amounts_spec.rb +2 -2
  191. data/spec/integration/braintree/test_transaction_spec.rb +18 -18
  192. data/spec/integration/braintree/transaction_line_item_spec.rb +38 -0
  193. data/spec/integration/braintree/transaction_search_spec.rb +280 -152
  194. data/spec/integration/braintree/transaction_spec.rb +3709 -1175
  195. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +438 -0
  196. data/spec/integration/braintree/us_bank_account_spec.rb +38 -17
  197. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +178 -0
  198. data/spec/integration/braintree/us_bank_account_verification_spec.rb +240 -0
  199. data/spec/integration/braintree/visa_checkout_card_spec.rb +5 -5
  200. data/spec/integration/spec_helper.rb +27 -6
  201. data/spec/oauth_test_helper.rb +1 -1
  202. data/spec/script/httpsd.rb +6 -6
  203. data/spec/spec_helper.rb +26 -23
  204. data/spec/unit/braintree/address_spec.rb +1 -9
  205. data/spec/unit/braintree/apple_pay_card_spec.rb +104 -4
  206. data/spec/unit/braintree/client_token_spec.rb +2 -2
  207. data/spec/unit/braintree/configuration_spec.rb +108 -33
  208. data/spec/unit/braintree/credit_card_spec.rb +62 -33
  209. data/spec/unit/braintree/credit_card_verification_gateway_spec.rb +51 -0
  210. data/spec/unit/braintree/credit_card_verification_search_spec.rb +1 -1
  211. data/spec/unit/braintree/credit_card_verification_spec.rb +39 -6
  212. data/spec/unit/braintree/customer_spec.rb +107 -27
  213. data/spec/unit/braintree/disbursement_spec.rb +59 -7
  214. data/spec/unit/braintree/dispute_search_spec.rb +66 -0
  215. data/spec/unit/braintree/dispute_spec.rb +472 -8
  216. data/spec/unit/braintree/document_upload_spec.rb +35 -0
  217. data/spec/unit/braintree/enriched_customer_data_spec.rb +32 -0
  218. data/spec/unit/braintree/error_result_spec.rb +5 -5
  219. data/spec/unit/braintree/errors_spec.rb +8 -8
  220. data/spec/unit/braintree/exchange_rate_quote_input_spec.rb +42 -0
  221. data/spec/unit/braintree/exchange_rate_quote_request_spec.rb +82 -0
  222. data/spec/unit/braintree/exchange_rate_quote_response_spec.rb +52 -0
  223. data/spec/unit/braintree/exchange_rate_quote_spec.rb +42 -0
  224. data/spec/unit/braintree/exchange_rate_spec.rb +23 -0
  225. data/spec/unit/braintree/http_spec.rb +93 -5
  226. data/spec/unit/braintree/local_payment_completed_spec.rb +50 -0
  227. data/spec/unit/braintree/local_payment_expired_spec.rb +24 -0
  228. data/spec/unit/braintree/local_payment_funded_spec.rb +34 -0
  229. data/spec/unit/braintree/merchant_account_spec.rb +1 -1
  230. data/spec/unit/braintree/modification_spec.rb +1 -1
  231. data/spec/unit/braintree/payment_method_customer_data_updated_metadata_spec.rb +45 -0
  232. data/spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb +31 -0
  233. data/spec/unit/braintree/payment_method_nonce_details_spec.rb +51 -0
  234. data/spec/unit/braintree/payment_method_nonce_spec.rb +40 -0
  235. data/spec/unit/braintree/payment_method_spec.rb +1 -1
  236. data/spec/unit/braintree/paypal_account_spec.rb +2 -2
  237. data/spec/unit/braintree/resource_collection_spec.rb +30 -1
  238. data/spec/unit/braintree/risk_data/liability_shift.rb +26 -0
  239. data/spec/unit/braintree/risk_data_spec.rb +40 -6
  240. data/spec/unit/braintree/sepa_debit_account_nonce_details_spec.rb +29 -0
  241. data/spec/unit/braintree/sepa_debit_account_spec.rb +86 -0
  242. data/spec/unit/braintree/subscription_search_spec.rb +1 -1
  243. data/spec/unit/braintree/subscription_spec.rb +2 -2
  244. data/spec/unit/braintree/successful_result_spec.rb +1 -1
  245. data/spec/unit/braintree/three_d_secure_info_spec.rb +34 -6
  246. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +19 -3
  247. data/spec/unit/braintree/transaction/customer_details_spec.rb +1 -1
  248. data/spec/unit/braintree/transaction/deposit_details_spec.rb +2 -2
  249. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  250. data/spec/unit/braintree/transaction/paypal_details_spec.rb +63 -0
  251. data/spec/unit/braintree/transaction/sepa_direct_debit_account_details_spec.rb +33 -0
  252. data/spec/unit/braintree/transaction_gateway_spec.rb +111 -0
  253. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  254. data/spec/unit/braintree/transaction_spec.rb +171 -55
  255. data/spec/unit/braintree/us_bank_account_verification_search_spec.rb +60 -0
  256. data/spec/unit/braintree/us_bank_account_verification_spec.rb +93 -0
  257. data/spec/unit/braintree/util_spec.rb +162 -19
  258. data/spec/unit/braintree/validation_error_collection_spec.rb +336 -133
  259. data/spec/unit/braintree/venmo_profile_data_spec.rb +32 -0
  260. data/spec/unit/braintree/webhook_notification_spec.rb +546 -114
  261. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  262. data/spec/unit/braintree/xml_spec.rb +31 -24
  263. data/spec/unit/braintree_spec.rb +1 -0
  264. metadata +290 -198
  265. data/README.rdoc +0 -93
  266. data/lib/braintree/amex_express_checkout_card.rb +0 -26
  267. data/lib/braintree/android_pay_card.rb +0 -35
  268. data/lib/braintree/coinbase_account.rb +0 -25
  269. data/lib/braintree/europe_bank_account.rb +0 -34
  270. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  271. data/lib/braintree/ideal_payment.rb +0 -46
  272. data/lib/braintree/ideal_payment_gateway.rb +0 -18
  273. data/lib/braintree/masterpass_card.rb +0 -66
  274. data/lib/braintree/settlement_batch.rb +0 -0
  275. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -14
  276. data/lib/braintree/transaction/android_pay_details.rb +0 -17
  277. data/lib/braintree/transaction/ideal_payment_details.rb +0 -13
  278. data/lib/braintree/transparent_redirect.rb +0 -40
  279. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  280. data/spec/hacks/tcp_socket.rb +0 -18
  281. data/spec/httpsd.pid +0 -1
  282. data/spec/integration/braintree/coinbase_spec.rb +0 -31
  283. data/spec/integration/braintree/ideal_payment_spec.rb +0 -87
  284. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  285. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  286. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
@@ -0,0 +1,438 @@
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::Transaction do
5
+ describe "self.create us bank account" 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 "plaid-verified" do
14
+ let(:plaid_nonce) { generate_valid_plaid_us_bank_account_nonce }
15
+
16
+ context "nonce" do
17
+ # we are temporarily skipping this test until we have a more stable CI env
18
+ xit "sale succeeds" do
19
+ result = Braintree::Transaction.create(
20
+ :type => "sale",
21
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
22
+ :merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
23
+ :payment_method_nonce => plaid_nonce,
24
+ :options => {
25
+ :submit_for_settlement => true,
26
+ },
27
+ )
28
+ result.success?.should == true
29
+ result.transaction.id.should =~ /^\w{6,}$/
30
+ result.transaction.type.should == "sale"
31
+ result.transaction.payment_instrument_type.should == Braintree::PaymentInstrumentType::UsBankAccount
32
+ result.transaction.amount.should == BigDecimal(Braintree::Test::TransactionAmounts::Authorize)
33
+ result.transaction.status.should == Braintree::Transaction::Status::SettlementPending
34
+ result.transaction.us_bank_account_details.routing_number.should == "011000015"
35
+ result.transaction.us_bank_account_details.last_4.should == "0000"
36
+ result.transaction.us_bank_account_details.account_type.should == "checking"
37
+ result.transaction.us_bank_account_details.account_holder_name.should == "PayPal, Inc."
38
+ result.transaction.us_bank_account_details.bank_name.should == "FEDERAL RESERVE BANK"
39
+ result.transaction.us_bank_account_details.ach_mandate.text.should == "cl mandate text"
40
+ result.transaction.us_bank_account_details.ach_mandate.accepted_at.should be_a Time
41
+ end
42
+ end
43
+
44
+ context "token" do
45
+ # we are temporarily skipping this test until we have a more stable CI env
46
+ xit "payment_method#create then sale succeeds" do
47
+ payment_method = Braintree::PaymentMethod.create(
48
+ :payment_method_nonce => plaid_nonce,
49
+ :customer_id => Braintree::Customer.create.customer.id,
50
+ :options => {
51
+ :verification_merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
52
+ },
53
+ ).payment_method
54
+
55
+ payment_method.verifications.count.should == 1
56
+ payment_method.verifications.first.status.should == Braintree::UsBankAccountVerification::Status::Verified
57
+ payment_method.verifications.first.verification_method.should == Braintree::UsBankAccountVerification::VerificationMethod::TokenizedCheck
58
+ payment_method.verifications.first.id.should_not be_empty
59
+ payment_method.verifications.first.verification_determined_at.should be_a Time
60
+ payment_method.verified.should == true
61
+
62
+ result = Braintree::Transaction.create(
63
+ :type => "sale",
64
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
65
+ :merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
66
+ :payment_method_token => payment_method.token,
67
+ :options => {
68
+ :submit_for_settlement => true,
69
+ },
70
+ )
71
+
72
+ result.success?.should == true
73
+
74
+ transaction = result.transaction
75
+
76
+ transaction.id.should =~ /^\w{6,}$/
77
+ transaction.type.should == "sale"
78
+ transaction.amount.should == BigDecimal(Braintree::Test::TransactionAmounts::Authorize)
79
+ transaction.status.should == Braintree::Transaction::Status::SettlementPending
80
+ transaction.us_bank_account_details.routing_number.should == "011000015"
81
+ transaction.us_bank_account_details.last_4.should == "0000"
82
+ transaction.us_bank_account_details.account_type.should == "checking"
83
+ transaction.us_bank_account_details.account_holder_name.should == "PayPal, Inc."
84
+ transaction.us_bank_account_details.bank_name.should == "FEDERAL RESERVE BANK"
85
+ transaction.us_bank_account_details.ach_mandate.text.should == "cl mandate text"
86
+ transaction.us_bank_account_details.ach_mandate.accepted_at.should be_a Time
87
+ end
88
+
89
+ # we are temporarily skipping this test until we have a more stable CI env
90
+ xit "transaction#create store_in_vault then sale succeeds" do
91
+ result = Braintree::Transaction.create(
92
+ :type => "sale",
93
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
94
+ :merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
95
+ :payment_method_nonce => plaid_nonce,
96
+ :options => {
97
+ :submit_for_settlement => true,
98
+ :store_in_vault => true,
99
+ },
100
+ )
101
+
102
+ result.success?.should == true
103
+
104
+ result = Braintree::Transaction.create(
105
+ :type => "sale",
106
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
107
+ :merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
108
+ :payment_method_token => result.transaction.us_bank_account_details.token,
109
+ :options => {
110
+ :submit_for_settlement => true,
111
+ },
112
+ )
113
+
114
+ result.success?.should == true
115
+
116
+ transaction = result.transaction
117
+
118
+ transaction.id.should =~ /^\w{6,}$/
119
+ transaction.type.should == "sale"
120
+ transaction.amount.should == BigDecimal(Braintree::Test::TransactionAmounts::Authorize)
121
+ transaction.status.should == Braintree::Transaction::Status::SettlementPending
122
+ transaction.us_bank_account_details.routing_number.should == "011000015"
123
+ transaction.us_bank_account_details.last_4.should == "0000"
124
+ transaction.us_bank_account_details.account_type.should == "checking"
125
+ transaction.us_bank_account_details.account_holder_name.should == "PayPal, Inc."
126
+ transaction.us_bank_account_details.bank_name.should == "FEDERAL RESERVE BANK"
127
+ transaction.us_bank_account_details.ach_mandate.text.should == "cl mandate text"
128
+ transaction.us_bank_account_details.ach_mandate.accepted_at.should be_a Time
129
+ end
130
+ end
131
+ end
132
+
133
+ context "not plaid-verified" do
134
+ let(:non_plaid_nonce) { generate_non_plaid_us_bank_account_nonce }
135
+ let(:invalid_nonce) { generate_invalid_us_bank_account_nonce }
136
+
137
+ context "nonce" do
138
+ it "sale fails for valid nonce" do
139
+ result = Braintree::Transaction.create(
140
+ :type => "sale",
141
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
142
+ :merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
143
+ :payment_method_nonce => non_plaid_nonce,
144
+ :options => {
145
+ :submit_for_settlement => true,
146
+ },
147
+ )
148
+ result.success?.should == false
149
+ result.errors.for(:transaction).on(:payment_method_nonce)[0].code.should == Braintree::ErrorCodes::Transaction::UsBankAccountNonceMustBePlaidVerified
150
+ end
151
+
152
+ it "sale fails for invalid nonce" do
153
+ result = Braintree::Transaction.create(
154
+ :type => "sale",
155
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
156
+ :merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
157
+ :payment_method_nonce => invalid_nonce,
158
+ :options => {
159
+ :submit_for_settlement => true,
160
+ },
161
+ )
162
+ result.success?.should == false
163
+ result.errors.for(:transaction).on(:payment_method_nonce)[0].code.should == Braintree::ErrorCodes::Transaction::PaymentMethodNonceUnknown
164
+ end
165
+ end
166
+
167
+ context "token" do
168
+ it "sale succeeds for verified token" do
169
+ result = Braintree::PaymentMethod.create(
170
+ :payment_method_nonce => non_plaid_nonce,
171
+ :customer_id => Braintree::Customer.create.customer.id,
172
+ :options => {
173
+ :us_bank_account_verification_method => "independent_check",
174
+ :verification_merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
175
+ },
176
+ )
177
+ payment_method = result.payment_method
178
+
179
+ payment_method.verifications.count.should == 1
180
+ payment_method.verifications.first.status == Braintree::UsBankAccountVerification::Status::Verified
181
+ payment_method.verifications.first.verification_method == Braintree::UsBankAccountVerification::VerificationMethod::IndependentCheck
182
+ payment_method.verifications.first.id.should_not be_empty
183
+ payment_method.verifications.first.verification_determined_at.should be_a Time
184
+ payment_method.verified.should == true
185
+
186
+ result = Braintree::Transaction.create(
187
+ :type => "sale",
188
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
189
+ :merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
190
+ :payment_method_token => payment_method.token,
191
+ :options => {
192
+ :submit_for_settlement => true,
193
+ },
194
+ )
195
+
196
+ result.success?.should == true
197
+ end
198
+
199
+ it "sale fails for unverified token" do
200
+ payment_method = Braintree::PaymentMethod.create(
201
+ :payment_method_nonce => non_plaid_nonce,
202
+ :customer_id => Braintree::Customer.create.customer.id,
203
+ :options => {
204
+ :verification_merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
205
+ },
206
+ ).payment_method
207
+
208
+ payment_method.verifications.count.should == 0
209
+ payment_method.verified.should == false
210
+
211
+ result = Braintree::Transaction.create(
212
+ :type => "sale",
213
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
214
+ :merchant_account_id => SpecHelper::AnotherUsBankMerchantAccountId,
215
+ :payment_method_token => payment_method.token,
216
+ :options => {
217
+ :submit_for_settlement => true,
218
+ },
219
+ )
220
+
221
+ result.success?.should == false
222
+ result.errors.for(:transaction)[0].code.should == Braintree::ErrorCodes::Transaction::UsBankAccountNotVerified
223
+ end
224
+ end
225
+ end
226
+ end
227
+
228
+ context "exempt merchant" do
229
+ before do
230
+ Braintree::Configuration.merchant_id = "integration_merchant_id"
231
+ Braintree::Configuration.public_key = "integration_public_key"
232
+ Braintree::Configuration.private_key = "integration_private_key"
233
+ end
234
+
235
+ context "plaid-verified" do
236
+ let(:plaid_nonce) { generate_valid_plaid_us_bank_account_nonce }
237
+
238
+ context "nonce" do
239
+ # we are temporarily skipping this test until we have a more stable CI env
240
+ xit "sale succeeds" do
241
+ result = Braintree::Transaction.create(
242
+ :type => "sale",
243
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
244
+ :merchant_account_id => SpecHelper::UsBankMerchantAccountId,
245
+ :payment_method_nonce => plaid_nonce,
246
+ :options => {
247
+ :submit_for_settlement => true,
248
+ },
249
+ )
250
+ result.success?.should == true
251
+ result.transaction.id.should =~ /^\w{6,}$/
252
+ result.transaction.type.should == "sale"
253
+ result.transaction.payment_instrument_type.should == Braintree::PaymentInstrumentType::UsBankAccount
254
+ result.transaction.amount.should == BigDecimal(Braintree::Test::TransactionAmounts::Authorize)
255
+ result.transaction.status.should == Braintree::Transaction::Status::SettlementPending
256
+ result.transaction.us_bank_account_details.routing_number.should == "011000015"
257
+ result.transaction.us_bank_account_details.last_4.should == "0000"
258
+ result.transaction.us_bank_account_details.account_type.should == "checking"
259
+ result.transaction.us_bank_account_details.account_holder_name.should == "PayPal, Inc."
260
+ result.transaction.us_bank_account_details.bank_name.should == "FEDERAL RESERVE BANK"
261
+ result.transaction.us_bank_account_details.ach_mandate.text.should == "cl mandate text"
262
+ result.transaction.us_bank_account_details.ach_mandate.accepted_at.should be_a Time
263
+ end
264
+ end
265
+
266
+ context "token" do
267
+ # we are temporarily skipping this test until we have a more stable CI env
268
+ xit "payment_method#create then sale succeeds" do
269
+ result = Braintree::PaymentMethod.create(
270
+ :payment_method_nonce => plaid_nonce,
271
+ :customer_id => Braintree::Customer.create.customer.id,
272
+ :options => {
273
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
274
+ },
275
+ )
276
+
277
+ payment_method = result.payment_method
278
+
279
+ payment_method.verifications.count.should == 1
280
+ payment_method.verifications.first.status.should == Braintree::UsBankAccountVerification::Status::Verified
281
+ payment_method.verifications.first.verification_method.should == Braintree::UsBankAccountVerification::VerificationMethod::TokenizedCheck
282
+ payment_method.verifications.first.id.should_not be_empty
283
+ payment_method.verifications.first.verification_determined_at.should be_a Time
284
+ payment_method.verified.should == true
285
+
286
+ result = Braintree::Transaction.create(
287
+ :type => "sale",
288
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
289
+ :merchant_account_id => SpecHelper::UsBankMerchantAccountId,
290
+ :payment_method_token => payment_method.token,
291
+ :options => {
292
+ :submit_for_settlement => true,
293
+ },
294
+ )
295
+
296
+ result.success?.should == true
297
+
298
+ transaction = result.transaction
299
+
300
+ transaction.id.should =~ /^\w{6,}$/
301
+ transaction.type.should == "sale"
302
+ transaction.amount.should == BigDecimal(Braintree::Test::TransactionAmounts::Authorize)
303
+ transaction.status.should == Braintree::Transaction::Status::SettlementPending
304
+ transaction.us_bank_account_details.routing_number.should == "011000015"
305
+ transaction.us_bank_account_details.last_4.should == "0000"
306
+ transaction.us_bank_account_details.account_type.should == "checking"
307
+ transaction.us_bank_account_details.account_holder_name.should == "PayPal, Inc."
308
+ transaction.us_bank_account_details.bank_name.should == "FEDERAL RESERVE BANK"
309
+ transaction.us_bank_account_details.ach_mandate.text.should == "cl mandate text"
310
+ transaction.us_bank_account_details.ach_mandate.accepted_at.should be_a Time
311
+ end
312
+
313
+ # we are temporarily skipping this test until we have a more stable CI env
314
+ xit "transaction#create store_in_vault then sale succeeds" do
315
+ result = Braintree::Transaction.create(
316
+ :type => "sale",
317
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
318
+ :merchant_account_id => SpecHelper::UsBankMerchantAccountId,
319
+ :payment_method_nonce => plaid_nonce,
320
+ :options => {
321
+ :submit_for_settlement => true,
322
+ :store_in_vault => true,
323
+ },
324
+ )
325
+
326
+ result.success?.should == true
327
+
328
+ result = Braintree::Transaction.create(
329
+ :type => "sale",
330
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
331
+ :merchant_account_id => SpecHelper::UsBankMerchantAccountId,
332
+ :payment_method_token => result.transaction.us_bank_account_details.token,
333
+ :options => {
334
+ :submit_for_settlement => true,
335
+ },
336
+ )
337
+
338
+ result.success?.should == true
339
+
340
+ transaction = result.transaction
341
+
342
+ transaction.id.should =~ /^\w{6,}$/
343
+ transaction.type.should == "sale"
344
+ transaction.amount.should == BigDecimal(Braintree::Test::TransactionAmounts::Authorize)
345
+ transaction.status.should == Braintree::Transaction::Status::SettlementPending
346
+ transaction.us_bank_account_details.routing_number.should == "011000015"
347
+ transaction.us_bank_account_details.last_4.should == "0000"
348
+ transaction.us_bank_account_details.account_type.should == "checking"
349
+ transaction.us_bank_account_details.account_holder_name.should == "PayPal, Inc."
350
+ transaction.us_bank_account_details.bank_name.should == "FEDERAL RESERVE BANK"
351
+ transaction.us_bank_account_details.ach_mandate.text.should == "cl mandate text"
352
+ transaction.us_bank_account_details.ach_mandate.accepted_at.should be_a Time
353
+ end
354
+ end
355
+ end
356
+
357
+ context "not plaid-verified" do
358
+ let(:non_plaid_nonce) { generate_non_plaid_us_bank_account_nonce }
359
+ let(:invalid_nonce) { generate_invalid_us_bank_account_nonce }
360
+
361
+ context "nonce" do
362
+ it "sale succeeds for valid nonce" do
363
+ result = Braintree::Transaction.create(
364
+ :type => "sale",
365
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
366
+ :merchant_account_id => SpecHelper::UsBankMerchantAccountId,
367
+ :payment_method_nonce => non_plaid_nonce,
368
+ :options => {
369
+ :submit_for_settlement => true,
370
+ },
371
+ )
372
+ result.success?.should == true
373
+
374
+ transaction = result.transaction
375
+
376
+ transaction.id.should =~ /^\w{6,}$/
377
+ transaction.type.should == "sale"
378
+ transaction.amount.should == BigDecimal(Braintree::Test::TransactionAmounts::Authorize)
379
+ transaction.status.should == Braintree::Transaction::Status::SettlementPending
380
+ transaction.us_bank_account_details.routing_number.should == "021000021"
381
+ transaction.us_bank_account_details.last_4.should == "0000"
382
+ transaction.us_bank_account_details.account_type.should == "checking"
383
+ transaction.us_bank_account_details.account_holder_name.should == "John Doe"
384
+ transaction.us_bank_account_details.bank_name.should =~ /CHASE/
385
+ transaction.us_bank_account_details.ach_mandate.text.should == "cl mandate text"
386
+ transaction.us_bank_account_details.ach_mandate.accepted_at.should be_a Time
387
+ end
388
+
389
+ it "sale fails for invalid nonce" do
390
+ result = Braintree::Transaction.create(
391
+ :type => "sale",
392
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
393
+ :merchant_account_id => SpecHelper::UsBankMerchantAccountId,
394
+ :payment_method_nonce => invalid_nonce,
395
+ :options => {
396
+ :submit_for_settlement => true,
397
+ },
398
+ )
399
+ result.success?.should == false
400
+ result.errors.for(:transaction).on(:payment_method_nonce)[0].code.should == Braintree::ErrorCodes::Transaction::PaymentMethodNonceUnknown
401
+ end
402
+ end
403
+
404
+ context "token" do
405
+ it "sale succeeds for unverified token" do
406
+ result = Braintree::PaymentMethod.create(
407
+ :payment_method_nonce => non_plaid_nonce,
408
+ :customer_id => Braintree::Customer.create.customer.id,
409
+ :options => {
410
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
411
+ },
412
+ )
413
+ payment_method = result.payment_method
414
+
415
+ payment_method.verifications.count.should == 1
416
+ payment_method.verifications.first.status == Braintree::UsBankAccountVerification::Status::Verified
417
+ payment_method.verifications.first.verification_method == Braintree::UsBankAccountVerification::VerificationMethod::IndependentCheck
418
+ payment_method.verifications.first.id.should_not be_empty
419
+ payment_method.verifications.first.verification_determined_at.should be_a Time
420
+ payment_method.verified.should == true
421
+
422
+ result = Braintree::Transaction.create(
423
+ :type => "sale",
424
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
425
+ :merchant_account_id => SpecHelper::UsBankMerchantAccountId,
426
+ :payment_method_token => payment_method.token,
427
+ :options => {
428
+ :submit_for_settlement => true,
429
+ },
430
+ )
431
+
432
+ result.success?.should == true
433
+ end
434
+ end
435
+ end
436
+ end
437
+ end
438
+ end
@@ -5,20 +5,23 @@ describe Braintree::UsBankAccount do
5
5
  describe "self.find" do
6
6
  it "returns a UsBankAccount" do
7
7
  customer = Braintree::Customer.create!
8
- nonce = generate_valid_us_bank_account_nonce
8
+ nonce = generate_non_plaid_us_bank_account_nonce
9
9
 
10
10
  result = Braintree::PaymentMethod.create(
11
11
  :payment_method_nonce => nonce,
12
- :customer_id => customer.id
12
+ :customer_id => customer.id,
13
+ :options => {
14
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
15
+ },
13
16
  )
14
17
  result.should be_success
15
18
 
16
19
  us_bank_account = Braintree::UsBankAccount.find(result.payment_method.token)
17
20
  us_bank_account.should be_a(Braintree::UsBankAccount)
18
21
  us_bank_account.routing_number.should == "021000021"
19
- us_bank_account.last_4.should == "1234"
22
+ us_bank_account.last_4.should == "0000"
20
23
  us_bank_account.account_type.should == "checking"
21
- us_bank_account.account_holder_name.should == "Dan Schulman"
24
+ us_bank_account.account_holder_name.should == "John Doe"
22
25
  us_bank_account.bank_name.should =~ /CHASE/
23
26
  us_bank_account.ach_mandate.text.should == "cl mandate text"
24
27
  us_bank_account.ach_mandate.accepted_at.should be_a Time
@@ -34,24 +37,31 @@ describe Braintree::UsBankAccount do
34
37
  context "self.sale" do
35
38
  it "creates a transaction using a us bank account and returns a result object" do
36
39
  customer = Braintree::Customer.create!
37
- nonce = generate_valid_us_bank_account_nonce
40
+ nonce = generate_non_plaid_us_bank_account_nonce
38
41
 
39
42
  result = Braintree::PaymentMethod.create(
40
43
  :payment_method_nonce => nonce,
41
- :customer_id => customer.id
44
+ :customer_id => customer.id,
45
+ :options => {
46
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
47
+ },
42
48
  )
43
49
  result.should be_success
44
50
 
45
- result = Braintree::UsBankAccount.sale(result.payment_method.token, :merchant_account_id => "us_bank_merchant_account", :amount => "100.00")
51
+ result = Braintree::UsBankAccount.sale(
52
+ result.payment_method.token,
53
+ :merchant_account_id => SpecHelper::UsBankMerchantAccountId,
54
+ :amount => "100.00",
55
+ )
46
56
 
47
57
  result.success?.should == true
48
- result.transaction.amount.should == BigDecimal.new("100.00")
58
+ result.transaction.amount.should == BigDecimal("100.00")
49
59
  result.transaction.type.should == "sale"
50
60
  us_bank_account = result.transaction.us_bank_account_details
51
61
  us_bank_account.routing_number.should == "021000021"
52
- us_bank_account.last_4.should == "1234"
62
+ us_bank_account.last_4.should == "0000"
53
63
  us_bank_account.account_type.should == "checking"
54
- us_bank_account.account_holder_name.should == "Dan Schulman"
64
+ us_bank_account.account_holder_name.should == "John Doe"
55
65
  us_bank_account.bank_name.should =~ /CHASE/
56
66
  us_bank_account.ach_mandate.text.should == "cl mandate text"
57
67
  us_bank_account.ach_mandate.accepted_at.should be_a Time
@@ -61,23 +71,30 @@ describe Braintree::UsBankAccount do
61
71
  context "self.sale!" do
62
72
  it "creates a transaction using a us bank account and returns a result object" do
63
73
  customer = Braintree::Customer.create!
64
- nonce = generate_valid_us_bank_account_nonce
74
+ nonce = generate_non_plaid_us_bank_account_nonce
65
75
 
66
76
  result = Braintree::PaymentMethod.create(
67
77
  :payment_method_nonce => nonce,
68
- :customer_id => customer.id
78
+ :customer_id => customer.id,
79
+ :options => {
80
+ :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
81
+ },
69
82
  )
70
83
  result.should be_success
71
84
 
72
- transaction = Braintree::UsBankAccount.sale!(result.payment_method.token, :merchant_account_id => "us_bank_merchant_account", :amount => "100.00")
85
+ transaction = Braintree::UsBankAccount.sale!(
86
+ result.payment_method.token,
87
+ :merchant_account_id => SpecHelper::UsBankMerchantAccountId,
88
+ :amount => "100.00",
89
+ )
73
90
 
74
- transaction.amount.should == BigDecimal.new("100.00")
91
+ transaction.amount.should == BigDecimal("100.00")
75
92
  transaction.type.should == "sale"
76
93
  us_bank_account = transaction.us_bank_account_details
77
94
  us_bank_account.routing_number.should == "021000021"
78
- us_bank_account.last_4.should == "1234"
95
+ us_bank_account.last_4.should == "0000"
79
96
  us_bank_account.account_type.should == "checking"
80
- us_bank_account.account_holder_name.should == "Dan Schulman"
97
+ us_bank_account.account_holder_name.should == "John Doe"
81
98
  us_bank_account.bank_name.should =~ /CHASE/
82
99
  us_bank_account.ach_mandate.text.should == "cl mandate text"
83
100
  us_bank_account.ach_mandate.accepted_at.should be_a Time
@@ -85,7 +102,11 @@ describe Braintree::UsBankAccount do
85
102
 
86
103
  it "does not creates a transaction using a us bank account and returns raises an exception" do
87
104
  expect do
88
- Braintree::UsBankAccount.sale!(generate_invalid_us_bank_account_nonce, :merchant_account_id => "us_bank_merchant_account", :amount => "100.00")
105
+ Braintree::UsBankAccount.sale!(
106
+ generate_invalid_us_bank_account_nonce,
107
+ :merchant_account_id => SpecHelper::UsBankMerchantAccountId,
108
+ :amount => "100.00",
109
+ )
89
110
  end.to raise_error(Braintree::ValidationsFailed)
90
111
  end
91
112
  end