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,97 @@
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::ExchangeRateQuoteGateway do
5
+ let(:gateway) do
6
+ Braintree::Gateway.new(
7
+ :environment => :development,
8
+ :merchant_id => "integration_merchant_id",
9
+ :public_key => "integration_public_key",
10
+ :private_key => "integration_private_key",
11
+ )
12
+ end
13
+
14
+ describe "generate" do
15
+ def quote_input_request
16
+ gateway.exchange_rate_quote.generate({quotes: [quote_input]})
17
+ end
18
+
19
+ let(:quote_input) do
20
+ {
21
+ :baseCurrency => "EUR",
22
+ :quoteCurrency => "GBP",
23
+ :baseAmount => "20.00",
24
+ :markup => "4.00"
25
+ }
26
+ end
27
+
28
+ it "generates exchange rate quotes" do
29
+ result = quote_input_request
30
+ quotes = result[:quotes]
31
+
32
+ expect(quotes[0][:id]).not_to be_nil
33
+ expect(quotes[0][:baseAmount]).not_to be_nil
34
+ expect(quotes[0][:quoteAmount]).not_to be_nil
35
+ expect(quotes[0][:exchangeRate]).not_to be_nil
36
+ expect(quotes[0][:expiresAt]).not_to be_nil
37
+ expect(quotes[0][:refreshesAt]).not_to be_nil
38
+
39
+ expect(quotes[1][:id]).not_to be_nil
40
+ expect(quotes[1][:baseAmount]).not_to be_nil
41
+ expect(quotes[1][:quoteAmount]).not_to be_nil
42
+ expect(quotes[1][:exchangeRate]).not_to be_nil
43
+ expect(quotes[1][:expiresAt]).not_to be_nil
44
+ expect(quotes[1][:refreshesAt]).not_to be_nil
45
+ end
46
+
47
+ context "when base currency input param is not passed" do
48
+ let(:quote_input) do
49
+ {
50
+ :quoteCurrency => "GBP",
51
+ :baseAmount => "20.00",
52
+ :markup => "4.00"
53
+ }
54
+ end
55
+ let(:error_message) { "baseCurrency" }
56
+
57
+ it "raises an UnexpectedError" do
58
+ expect do
59
+ quote_input_request
60
+ end.to raise_error(Braintree::UnexpectedError, /#{error_message}/)
61
+ end
62
+ end
63
+
64
+ context "when quote currency input param is not passed" do
65
+ let(:quote_input) do
66
+ {
67
+ :baseCurrency => "GBP",
68
+ :baseAmount => "20.00",
69
+ :markup => "4.00"
70
+ }
71
+ end
72
+ let(:error_message) { "quoteCurrency" }
73
+
74
+ it "raises an UnexpectedError" do
75
+ expect do
76
+ quote_input_request
77
+ end.to raise_error(Braintree::UnexpectedError, /#{error_message}/)
78
+ end
79
+ end
80
+
81
+ context "when base and quote currency input params are not passed" do
82
+ let(:quote_input) do
83
+ {
84
+ :baseAmount => "20.00",
85
+ :markup => "4.00"
86
+ }
87
+ end
88
+ let(:error_message) { "baseCurrency" }
89
+
90
+ it "raises an UnexpectedError" do
91
+ expect do
92
+ quote_input_request
93
+ end.to raise_error(Braintree::UnexpectedError, /#{error_message}/)
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,72 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Braintree::GraphQLClient do
4
+ before :each do
5
+ @config = Braintree::Configuration.instantiate
6
+ end
7
+
8
+ describe "initialize" do
9
+ it "assigns overriding graphql headers" do
10
+ expect(@config.graphql_client.instance_variable_get("@graphql_headers")).to be_kind_of(Hash)
11
+ end
12
+ end
13
+
14
+ describe "query" do
15
+ it "makes valid GraphQL queries when given a definition" do
16
+ definition = <<-GRAPHQL
17
+ query {
18
+ ping
19
+ }
20
+ GRAPHQL
21
+
22
+ response = Braintree::GraphQLClient.new(@config).query(definition)
23
+
24
+ expect(response[:data]).to eq({:ping=>"pong"})
25
+ end
26
+
27
+ it "makes valid GraphQL requests when given a definitiona and variable" do
28
+ definition = <<-GRAPHQL
29
+ mutation CreateClientToken($input: CreateClientTokenInput!) {
30
+ createClientToken(input: $input) {
31
+ clientToken
32
+ }
33
+ }
34
+ GRAPHQL
35
+
36
+ variables = {
37
+ input: {
38
+ clientToken: {
39
+ merchantAccountId: "ABC123"
40
+ }
41
+ }
42
+ }
43
+
44
+ response = Braintree::GraphQLClient.new(@config).query(definition, variables)
45
+
46
+ expect(response[:data][:createClientToken][:clientToken]).to be_a(String)
47
+ end
48
+
49
+ it "returns results parsable into validation errors" do
50
+ definition = <<-GRAPHQL
51
+ query TransactionLevelFeeReport($date: Date!, $merchantAccountId: ID) {
52
+ report {
53
+ transactionLevelFees(date: $date, merchantAccountId: $merchantAccountId) {
54
+ url
55
+ }
56
+ }
57
+ }
58
+ GRAPHQL
59
+
60
+ variables = {
61
+ date: "2018-01-01",
62
+ merchantAccountId: "some_merchant"
63
+ }
64
+
65
+ response = Braintree::GraphQLClient.new(@config).query(definition, variables)
66
+ errors = Braintree::ValidationErrorCollection.new(response)
67
+
68
+ expect(errors.size).to eq(1)
69
+ expect(errors.first.message).to eq("Invalid merchant account id: some_merchant")
70
+ end
71
+ end
72
+ end
@@ -18,7 +18,7 @@ describe Braintree::Http do
18
18
  it "raises an AuthorizationError if authorization fails" do
19
19
  expect do
20
20
  config = Braintree::Configuration.instantiate
21
- config.http.get("#{config.base_merchant_path}/users")
21
+ config.http.get("#{config.base_merchant_path}/home")
22
22
  end.to raise_error(Braintree::AuthorizationError)
23
23
  end
24
24
  end
@@ -54,7 +54,7 @@ describe Braintree::Http do
54
54
  :customer_id => customer.id,
55
55
  :cardholder_name => "Sam Jones",
56
56
  :number => Braintree::Test::CreditCardNumbers::Visa,
57
- :expiration_date => "05/2009"
57
+ :expiration_date => "05/2009",
58
58
  )
59
59
  result.success?.should == true
60
60
  utc_or_gmt = Time.now.utc.strftime("%Z")
@@ -69,6 +69,14 @@ describe Braintree::Http do
69
69
  end
70
70
  end
71
71
 
72
+ it "posts multipart for file uploads" do
73
+ config = Braintree::Configuration.instantiate
74
+ file = File.new("#{File.dirname(__FILE__)}/../../fixtures/files/bt_logo.png", "r")
75
+ response = config.http.post("#{config.base_merchant_path}/document_uploads", {"document_upload[kind]" => "evidence_document"}, file)
76
+ response[:document_upload][:content_type].should == "image/png"
77
+ response[:document_upload][:id].should_not be_nil
78
+ end
79
+
72
80
  describe "user_agent" do
73
81
  after do
74
82
  Braintree::Configuration.custom_user_agent = nil
@@ -89,7 +97,7 @@ describe Braintree::Http do
89
97
  end
90
98
 
91
99
  describe "ssl_version" do
92
- it "causes failed requests to sandbox with incompatible SSL version" do
100
+ xit "causes failed requests to sandbox with incompatible SSL version" do
93
101
  begin
94
102
  original_env = Braintree::Configuration.environment
95
103
  Braintree::Configuration.environment = :sandbox
@@ -148,7 +156,7 @@ describe Braintree::Http do
148
156
  # Random CA root file from a different certificate authority
149
157
  config = Braintree::Configuration.instantiate
150
158
  config.stub(:ca_file).and_return(
151
- File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "ssl", "geotrust_global.crt"))
159
+ File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "ssl", "geotrust_global.crt")),
152
160
  )
153
161
  config.stub(:ssl?).and_return(true)
154
162
  config.stub(:port).and_return(SSL_TEST_PORT)
@@ -41,7 +41,7 @@ VALID_APPLICATION_PARAMS = {
41
41
  :business => {
42
42
  :legal_name => "Joe's Bloggs",
43
43
  :dba_name => "Joe's Junkyard",
44
- :tax_id => "123456789",
44
+ :tax_id => "423456789",
45
45
  :address => {
46
46
  :street_address => "456 Fake St",
47
47
  :postal_code => "48104",
@@ -65,7 +65,7 @@ describe Braintree::MerchantAccount do
65
65
  gateway = Braintree::Gateway.new(
66
66
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
67
67
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
68
- :logger => Logger.new("/dev/null")
68
+ :logger => Logger.new("/dev/null"),
69
69
  )
70
70
 
71
71
  code = Braintree::OAuthTestHelper.create_grant(gateway, {
@@ -75,12 +75,12 @@ describe Braintree::MerchantAccount do
75
75
 
76
76
  result = gateway.oauth.create_token_from_code(
77
77
  :code => code,
78
- :scope => "read_write"
78
+ :scope => "read_write",
79
79
  )
80
80
 
81
81
  gateway = Braintree::Gateway.new(
82
82
  :access_token => result.credentials.access_token,
83
- :logger => Logger.new("/dev/null")
83
+ :logger => Logger.new("/dev/null"),
84
84
  )
85
85
 
86
86
  result = gateway.merchant_account.all
@@ -92,18 +92,18 @@ describe Braintree::MerchantAccount do
92
92
  gateway = Braintree::Gateway.new(
93
93
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
94
94
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
95
- :logger => Logger.new("/dev/null")
95
+ :logger => Logger.new("/dev/null"),
96
96
  )
97
97
 
98
98
  result = gateway.merchant.create(
99
99
  :email => "name@email.com",
100
100
  :country_code_alpha3 => "USA",
101
- :payment_methods => ["credit_card", "paypal"]
101
+ :payment_methods => ["credit_card", "paypal"],
102
102
  )
103
103
 
104
104
  gateway = Braintree::Gateway.new(
105
105
  :access_token => result.credentials.access_token,
106
- :logger => Logger.new("/dev/null")
106
+ :logger => Logger.new("/dev/null"),
107
107
  )
108
108
 
109
109
  result = gateway.merchant_account.all
@@ -113,6 +113,33 @@ describe Braintree::MerchantAccount do
113
113
  result.merchant_accounts.first.status.should == "active"
114
114
  result.merchant_accounts.first.default.should == true
115
115
  end
116
+
117
+ it "returns all merchant accounts for read_only scoped grants" do
118
+ gateway = Braintree::Gateway.new(
119
+ :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
120
+ :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
121
+ :logger => Logger.new("/dev/null"),
122
+ )
123
+
124
+ code = Braintree::OAuthTestHelper.create_grant(gateway, {
125
+ :merchant_public_id => "integration_merchant_id",
126
+ :scope => "read_only"
127
+ })
128
+
129
+ result = gateway.oauth.create_token_from_code(
130
+ :code => code,
131
+ :scope => "read_only",
132
+ )
133
+
134
+ gateway = Braintree::Gateway.new(
135
+ :access_token => result.credentials.access_token,
136
+ :logger => Logger.new("/dev/null"),
137
+ )
138
+
139
+ result = gateway.merchant_account.all
140
+ result.should be_success
141
+ result.merchant_accounts.count.should > 20
142
+ end
116
143
  end
117
144
 
118
145
  describe "create" do
@@ -137,8 +164,8 @@ describe Braintree::MerchantAccount do
137
164
  sub_merchant_account_id = "sub_merchant_account_id#{random_number}"
138
165
  result = Braintree::MerchantAccount.create(
139
166
  VALID_APPLICATION_PARAMS.merge(
140
- :id => sub_merchant_account_id
141
- )
167
+ :id => sub_merchant_account_id,
168
+ ),
142
169
  )
143
170
 
144
171
  result.should be_success
@@ -155,7 +182,7 @@ describe Braintree::MerchantAccount do
155
182
 
156
183
  it "requires all fields" do
157
184
  result = Braintree::MerchantAccount.create(
158
- :master_merchant_account_id => "sandbox_master_merchant_account"
185
+ :master_merchant_account_id => "sandbox_master_merchant_account",
159
186
  )
160
187
  result.should_not be_success
161
188
  result.errors.for(:merchant_account).on(:tos_accepted).first.code.should == Braintree::ErrorCodes::MerchantAccount::TosAcceptedIsRequired
@@ -190,6 +217,15 @@ describe Braintree::MerchantAccount do
190
217
  end
191
218
  end
192
219
 
220
+ describe "create!" do
221
+ it "creates a merchant account with the new parameters and doesn't require an id" do
222
+ merchant_account = Braintree::MerchantAccount.create!(VALID_APPLICATION_PARAMS)
223
+
224
+ merchant_account.status.should == Braintree::MerchantAccount::Status::Pending
225
+ merchant_account.master_merchant_account.id.should == "sandbox_master_merchant_account"
226
+ end
227
+ end
228
+
193
229
  describe "create_for_currency" do
194
230
  it "creates a new merchant account for currency" do
195
231
  result = SpecHelper::create_merchant
@@ -197,11 +233,11 @@ describe Braintree::MerchantAccount do
197
233
 
198
234
  gateway = Braintree::Gateway.new(
199
235
  :access_token => result.credentials.access_token,
200
- :logger => Logger.new("/dev/null")
236
+ :logger => Logger.new("/dev/null"),
201
237
  )
202
238
 
203
239
  result = gateway.merchant_account.create_for_currency(
204
- :currency => "JPY"
240
+ :currency => "JPY",
205
241
  )
206
242
  result.should be_success
207
243
  result.merchant_account.currency_iso_code.should == "JPY"
@@ -213,16 +249,16 @@ describe Braintree::MerchantAccount do
213
249
 
214
250
  gateway = Braintree::Gateway.new(
215
251
  :access_token => result.credentials.access_token,
216
- :logger => Logger.new("/dev/null")
252
+ :logger => Logger.new("/dev/null"),
217
253
  )
218
254
 
219
255
  result = gateway.merchant_account.create_for_currency(
220
- :currency => "USD"
256
+ :currency => "USD",
221
257
  )
222
258
  result.should be_success
223
259
 
224
260
  result = gateway.merchant_account.create_for_currency(
225
- :currency => "USD"
261
+ :currency => "USD",
226
262
  )
227
263
  result.should_not be_success
228
264
 
@@ -236,11 +272,11 @@ describe Braintree::MerchantAccount do
236
272
 
237
273
  gateway = Braintree::Gateway.new(
238
274
  :access_token => result.credentials.access_token,
239
- :logger => Logger.new("/dev/null")
275
+ :logger => Logger.new("/dev/null"),
240
276
  )
241
277
 
242
278
  result = gateway.merchant_account.create_for_currency(
243
- :currency => nil
279
+ :currency => nil,
244
280
  )
245
281
  result.should_not be_success
246
282
 
@@ -260,11 +296,11 @@ describe Braintree::MerchantAccount do
260
296
 
261
297
  gateway = Braintree::Gateway.new(
262
298
  :access_token => result.credentials.access_token,
263
- :logger => Logger.new("/dev/null")
299
+ :logger => Logger.new("/dev/null"),
264
300
  )
265
301
 
266
302
  result = gateway.merchant_account.create_for_currency(
267
- :currency => "FAKE_CURRENCY"
303
+ :currency => "FAKE_CURRENCY",
268
304
  )
269
305
  result.should_not be_success
270
306
 
@@ -278,13 +314,13 @@ describe Braintree::MerchantAccount do
278
314
 
279
315
  gateway = Braintree::Gateway.new(
280
316
  :access_token => result.credentials.access_token,
281
- :logger => Logger.new("/dev/null")
317
+ :logger => Logger.new("/dev/null"),
282
318
  )
283
319
 
284
320
  merchant = result.merchant
285
321
  result = gateway.merchant_account.create_for_currency(
286
322
  :currency => "USD",
287
- :id => merchant.merchant_accounts.first.id
323
+ :id => merchant.merchant_accounts.first.id,
288
324
  )
289
325
  result.should_not be_success
290
326
 
@@ -302,7 +338,6 @@ describe Braintree::MerchantAccount do
302
338
  id = result.merchant_account.id
303
339
  merchant_account = Braintree::MerchantAccount.find(id)
304
340
 
305
- merchant_account.status.should == Braintree::MerchantAccount::Status::Active
306
341
  merchant_account.individual_details.first_name.should == VALID_APPLICATION_PARAMS[:individual][:first_name]
307
342
  merchant_account.individual_details.last_name.should == VALID_APPLICATION_PARAMS[:individual][:last_name]
308
343
  end
@@ -316,7 +351,7 @@ describe Braintree::MerchantAccount do
316
351
  it "raises a NotFoundError exception if merchant account cannot be found" do
317
352
  expect do
318
353
  Braintree::MerchantAccount.find("non-existant")
319
- end.to raise_error(Braintree::NotFoundError, 'Merchant account with id non-existant not found')
354
+ end.to raise_error(Braintree::NotFoundError, "Merchant account with id non-existant not found")
320
355
  end
321
356
  end
322
357
 
@@ -336,7 +371,7 @@ describe Braintree::MerchantAccount do
336
371
  params[:individual][:address][:postal_code] = "60622"
337
372
  params[:business][:dba_name] = "James's Bloggs"
338
373
  params[:business][:legal_name] = "James's Bloggs Inc"
339
- params[:business][:tax_id] = "123456789"
374
+ params[:business][:tax_id] = "423456789"
340
375
  params[:business][:address][:street_address] = "999 Fake St"
341
376
  params[:business][:address][:locality] = "Miami"
342
377
  params[:business][:address][:region] = "FL"
@@ -362,7 +397,7 @@ describe Braintree::MerchantAccount do
362
397
  result.merchant_account.individual_details.address_details.postal_code.should == "60622"
363
398
  result.merchant_account.business_details.dba_name.should == "James's Bloggs"
364
399
  result.merchant_account.business_details.legal_name.should == "James's Bloggs Inc"
365
- result.merchant_account.business_details.tax_id.should == "123456789"
400
+ result.merchant_account.business_details.tax_id.should == "423456789"
366
401
  result.merchant_account.business_details.address_details.street_address.should == "999 Fake St"
367
402
  result.merchant_account.business_details.address_details.locality.should == "Miami"
368
403
  result.merchant_account.business_details.address_details.region.should == "FL"
@@ -376,7 +411,7 @@ describe Braintree::MerchantAccount do
376
411
  end
377
412
 
378
413
  it "does not require all fields" do
379
- result = Braintree::MerchantAccount.update("sandbox_sub_merchant_account", { :individual => { :first_name => "Jose" } })
414
+ result = Braintree::MerchantAccount.update("sandbox_sub_merchant_account", {:individual => {:first_name => "Jose"}})
380
415
  result.should be_success
381
416
  end
382
417
 
@@ -552,4 +587,17 @@ describe Braintree::MerchantAccount do
552
587
  result.errors.for(:merchant_account).for(:funding).on(:mobile_phone).map(&:code).should == [Braintree::ErrorCodes::MerchantAccount::Funding::MobilePhoneIsRequired]
553
588
  end
554
589
  end
590
+
591
+ describe "update!" do
592
+ it "updates the Merchant Account info" do
593
+ params = VALID_APPLICATION_PARAMS.clone
594
+ params.delete(:tos_accepted)
595
+ params.delete(:master_merchant_account_id)
596
+ params[:individual][:first_name] = "John"
597
+ params[:individual][:last_name] = "Doe"
598
+ merchant_account = Braintree::MerchantAccount.update!("sandbox_sub_merchant_account", params)
599
+ merchant_account.individual_details.first_name.should == "John"
600
+ merchant_account.individual_details.last_name.should == "Doe"
601
+ end
602
+ end
555
603
  end
@@ -6,13 +6,13 @@ describe Braintree::MerchantGateway do
6
6
  gateway = Braintree::Gateway.new(
7
7
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
8
8
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
9
- :logger => Logger.new("/dev/null")
9
+ :logger => Logger.new("/dev/null"),
10
10
  )
11
11
 
12
12
  result = gateway.merchant.create(
13
13
  :email => "name@email.com",
14
14
  :country_code_alpha3 => "USA",
15
- :payment_methods => ["credit_card", "paypal"]
15
+ :payment_methods => ["credit_card", "paypal"],
16
16
  )
17
17
 
18
18
  result.should be_success
@@ -37,13 +37,13 @@ describe Braintree::MerchantGateway do
37
37
  gateway = Braintree::Gateway.new(
38
38
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
39
39
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
40
- :logger => Logger.new("/dev/null")
40
+ :logger => Logger.new("/dev/null"),
41
41
  )
42
42
 
43
43
  result = gateway.merchant.create(
44
44
  :email => "name@email.com",
45
45
  :country_code_alpha3 => "USA",
46
- :payment_methods => ["fake_money"]
46
+ :payment_methods => ["fake_money"],
47
47
  )
48
48
 
49
49
  result.should_not be_success
@@ -52,12 +52,38 @@ describe Braintree::MerchantGateway do
52
52
  errors[0].code.should == Braintree::ErrorCodes::Merchant::PaymentMethodsAreInvalid
53
53
  end
54
54
 
55
+ context "credentials" do
56
+ around(:each) do |example|
57
+ old_merchant_id_value = Braintree::Configuration.merchant_id
58
+ example.run
59
+ Braintree::Configuration.merchant_id = old_merchant_id_value
60
+ end
61
+
62
+ it "allows using a merchant_id passed in through Gateway" do
63
+ Braintree::Configuration.merchant_id = nil
64
+
65
+ gateway = Braintree::Gateway.new(
66
+ :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
67
+ :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
68
+ :merchant_id => "integration_merchant_id",
69
+ :logger => Logger.new("/dev/null"),
70
+ )
71
+ result = gateway.merchant.create(
72
+ :email => "name@email.com",
73
+ :country_code_alpha3 => "USA",
74
+ :payment_methods => ["credit_card", "paypal"],
75
+ )
76
+
77
+ result.should be_success
78
+ end
79
+ end
80
+
55
81
  context "multiple currencies" do
56
82
  before(:each) do
57
83
  @gateway = Braintree::Gateway.new(
58
84
  :client_id => "client_id$development$signup_client_id",
59
85
  :client_secret => "client_secret$development$signup_client_secret",
60
- :logger => Logger.new("/dev/null")
86
+ :logger => Logger.new("/dev/null"),
61
87
  )
62
88
  end
63
89
 
@@ -66,7 +92,7 @@ describe Braintree::MerchantGateway do
66
92
  :email => "name@email.com",
67
93
  :country_code_alpha3 => "USA",
68
94
  :payment_methods => ["credit_card", "paypal"],
69
- :currencies => ["GBP", "USD"]
95
+ :currencies => ["GBP", "USD"],
70
96
  )
71
97
 
72
98
  merchant = result.merchant
@@ -101,7 +127,7 @@ describe Braintree::MerchantGateway do
101
127
  :email => "name@email.com",
102
128
  :country_code_alpha3 => "GBR",
103
129
  :payment_methods => ["credit_card", "paypal"],
104
- :currencies => ["GBP", "USD"]
130
+ :currencies => ["GBP", "USD"],
105
131
  )
106
132
 
107
133
  merchant = result.merchant
@@ -141,7 +167,7 @@ describe Braintree::MerchantGateway do
141
167
  :paypal_account => {
142
168
  :client_id => "paypal_client_id",
143
169
  :client_secret => "paypal_client_secret",
144
- }
170
+ },
145
171
  )
146
172
 
147
173
  result.should be_success
@@ -181,7 +207,7 @@ describe Braintree::MerchantGateway do
181
207
  :paypal_account => {
182
208
  :client_id => "paypal_client_id",
183
209
  :client_secret => "paypal_client_secret",
184
- }
210
+ },
185
211
  )
186
212
 
187
213
  result.should be_success
@@ -217,7 +243,7 @@ describe Braintree::MerchantGateway do
217
243
  :paypal_account => {
218
244
  :client_id => "paypal_client_id",
219
245
  :client_secret => "paypal_client_secret",
220
- }
246
+ },
221
247
  )
222
248
 
223
249
  result.should be_success
@@ -254,7 +280,7 @@ describe Braintree::MerchantGateway do
254
280
  :paypal_account => {
255
281
  :client_id => "paypal_client_id",
256
282
  :client_secret => "paypal_client_secret",
257
- }
283
+ },
258
284
  )
259
285
 
260
286
  result.should_not be_success
@@ -279,7 +305,7 @@ describe Braintree::MerchantGateway do
279
305
  it "succeeds" do
280
306
  result = Braintree::Merchant.provision_raw_apple_pay
281
307
  result.should be_success
282
- result.supported_networks.should == ["visa", "mastercard", "amex", "discover"]
308
+ result.supported_networks.should == ["visa", "mastercard", "amex", "discover", "maestro", "elo"]
283
309
  end
284
310
 
285
311
  it "is repeatable" do
@@ -287,7 +313,7 @@ describe Braintree::MerchantGateway do
287
313
  result.should be_success
288
314
  result = Braintree::Merchant.provision_raw_apple_pay
289
315
  result.should be_success
290
- result.supported_networks.should == ["visa", "mastercard", "amex", "discover"]
316
+ result.supported_networks.should == ["visa", "mastercard", "amex", "discover", "maestro", "elo"]
291
317
  end
292
318
  end
293
319