braintree 2.98.0 → 4.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +7 -4
  4. data/lib/braintree/account_updater_daily_report.rb +4 -4
  5. data/lib/braintree/ach_mandate.rb +1 -1
  6. data/lib/braintree/add_on_gateway.rb +1 -1
  7. data/lib/braintree/address.rb +7 -27
  8. data/lib/braintree/address_gateway.rb +8 -7
  9. data/lib/braintree/advanced_search.rb +11 -12
  10. data/lib/braintree/apple_pay.rb +4 -4
  11. data/lib/braintree/apple_pay_card.rb +18 -4
  12. data/lib/braintree/apple_pay_options.rb +4 -4
  13. data/lib/braintree/authorization_adjustment.rb +4 -4
  14. data/lib/braintree/base_module.rb +11 -1
  15. data/lib/braintree/bin_data.rb +10 -3
  16. data/lib/braintree/client_token.rb +1 -1
  17. data/lib/braintree/client_token_gateway.rb +4 -3
  18. data/lib/braintree/configuration.rb +35 -35
  19. data/lib/braintree/connected_merchant_paypal_status_changed.rb +2 -2
  20. data/lib/braintree/connected_merchant_status_transitioned.rb +2 -2
  21. data/lib/braintree/credit_card.rb +40 -86
  22. data/lib/braintree/credit_card_gateway.rb +58 -44
  23. data/lib/braintree/credit_card_verification.rb +39 -20
  24. data/lib/braintree/credit_card_verification_gateway.rb +35 -5
  25. data/lib/braintree/credit_card_verification_search.rb +2 -2
  26. data/lib/braintree/customer.rb +23 -88
  27. data/lib/braintree/customer_gateway.rb +17 -32
  28. data/lib/braintree/customer_search.rb +2 -2
  29. data/lib/braintree/descriptor.rb +1 -1
  30. data/lib/braintree/digest.rb +1 -1
  31. data/lib/braintree/disbursement.rb +7 -7
  32. data/lib/braintree/discount_gateway.rb +1 -1
  33. data/lib/braintree/dispute/evidence.rb +1 -1
  34. data/lib/braintree/{transaction/coinbase_details.rb → dispute/paypal_message.rb} +5 -6
  35. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  36. data/lib/braintree/dispute/transaction.rb +3 -1
  37. data/lib/braintree/dispute/transaction_details.rb +1 -1
  38. data/lib/braintree/dispute.rb +47 -6
  39. data/lib/braintree/dispute_gateway.rb +5 -10
  40. data/lib/braintree/dispute_search.rb +8 -4
  41. data/lib/braintree/document_upload.rb +3 -3
  42. data/lib/braintree/document_upload_gateway.rb +3 -3
  43. data/lib/braintree/enriched_customer_data.rb +21 -0
  44. data/lib/braintree/error_codes.rb +217 -175
  45. data/lib/braintree/error_result.rb +2 -3
  46. data/lib/braintree/errors.rb +3 -3
  47. data/lib/braintree/exceptions.rb +6 -5
  48. data/lib/braintree/exchange_rate.rb +13 -0
  49. data/lib/braintree/exchange_rate_quote.rb +24 -0
  50. data/lib/braintree/exchange_rate_quote_gateway.rb +35 -0
  51. data/lib/braintree/exchange_rate_quote_input.rb +21 -0
  52. data/lib/braintree/exchange_rate_quote_request.rb +18 -0
  53. data/lib/braintree/exchange_rate_quote_response.rb +18 -0
  54. data/lib/braintree/facilitated_details.rb +1 -1
  55. data/lib/braintree/facilitator_details.rb +1 -1
  56. data/lib/braintree/gateway.rb +6 -12
  57. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +18 -5
  58. data/lib/braintree/granted_payment_instrument_update.rb +2 -2
  59. data/lib/braintree/graphql_client.rb +14 -8
  60. data/lib/braintree/http.rb +9 -10
  61. data/lib/braintree/local_payment_completed/blik_alias.rb +23 -0
  62. data/lib/braintree/local_payment_completed.rb +10 -5
  63. data/lib/braintree/local_payment_expired.rb +21 -0
  64. data/lib/braintree/local_payment_funded.rb +22 -0
  65. data/lib/braintree/local_payment_reversed.rb +19 -0
  66. data/lib/braintree/merchant.rb +4 -4
  67. data/lib/braintree/merchant_account.rb +3 -3
  68. data/lib/braintree/merchant_account_gateway.rb +10 -8
  69. data/lib/braintree/merchant_gateway.rb +1 -1
  70. data/lib/braintree/meta_checkout_card.rb +89 -0
  71. data/lib/braintree/meta_checkout_token.rb +88 -0
  72. data/lib/braintree/modification.rb +4 -4
  73. data/lib/braintree/oauth_credentials.rb +4 -4
  74. data/lib/braintree/oauth_gateway.rb +5 -5
  75. data/lib/braintree/paginated_collection.rb +2 -2
  76. data/lib/braintree/paginated_result.rb +1 -1
  77. data/lib/braintree/payment_instrument_type.rb +14 -13
  78. data/lib/braintree/payment_method_customer_data_updated_metadata.rb +24 -0
  79. data/lib/braintree/payment_method_gateway.rb +52 -22
  80. data/lib/braintree/payment_method_nonce.rb +12 -7
  81. data/lib/braintree/payment_method_nonce_details.rb +40 -0
  82. data/lib/braintree/payment_method_nonce_details_payer_info.rb +32 -0
  83. data/lib/braintree/payment_method_nonce_gateway.rb +14 -3
  84. data/lib/braintree/payment_method_parser.rb +4 -7
  85. data/lib/braintree/paypal_account.rb +3 -2
  86. data/lib/braintree/paypal_account_gateway.rb +5 -5
  87. data/lib/braintree/plan.rb +22 -2
  88. data/lib/braintree/plan_gateway.rb +101 -1
  89. data/lib/braintree/processor_response_types.rb +3 -3
  90. data/lib/braintree/resource_collection.rb +10 -5
  91. data/lib/braintree/revoked_payment_method_metadata.rb +2 -2
  92. data/lib/braintree/risk_data/liability_shift.rb +22 -0
  93. data/lib/braintree/risk_data.rb +10 -3
  94. data/lib/braintree/samsung_pay_card.rb +8 -6
  95. data/lib/braintree/sepa_direct_debit_account.rb +60 -0
  96. data/lib/braintree/sepa_direct_debit_account_gateway.rb +25 -0
  97. data/lib/braintree/sepa_direct_debit_account_nonce_details.rb +28 -0
  98. data/lib/braintree/settlement_batch_summary.rb +2 -2
  99. data/lib/braintree/settlement_batch_summary_gateway.rb +1 -1
  100. data/lib/braintree/sha256_digest.rb +1 -1
  101. data/lib/braintree/subscription/status_details.rb +1 -1
  102. data/lib/braintree/subscription.rb +13 -13
  103. data/lib/braintree/subscription_gateway.rb +6 -6
  104. data/lib/braintree/subscription_search.rb +1 -1
  105. data/lib/braintree/successful_result.rb +5 -4
  106. data/lib/braintree/test/authentication_id.rb +21 -0
  107. data/lib/braintree/test/credit_card.rb +9 -10
  108. data/lib/braintree/test/merchant_account.rb +1 -1
  109. data/lib/braintree/test/nonce.rb +27 -20
  110. data/lib/braintree/test/transaction_amounts.rb +2 -3
  111. data/lib/braintree/test/venmo_sdk.rb +2 -0
  112. data/lib/braintree/testing_gateway.rb +1 -1
  113. data/lib/braintree/three_d_secure_info.rb +23 -11
  114. data/lib/braintree/transaction/address_details.rb +14 -1
  115. data/lib/braintree/transaction/apple_pay_details.rb +13 -10
  116. data/lib/braintree/transaction/credit_card_details.rb +8 -1
  117. data/lib/braintree/transaction/customer_details.rb +3 -2
  118. data/lib/braintree/transaction/disbursement_details.rb +2 -1
  119. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +6 -1
  120. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  121. data/lib/braintree/transaction/installment.rb +28 -0
  122. data/lib/braintree/transaction/local_payment_details.rb +3 -0
  123. data/lib/braintree/transaction/meta_checkout_card_details.rb +52 -0
  124. data/lib/braintree/transaction/meta_checkout_token_details.rb +54 -0
  125. data/lib/braintree/transaction/package_details.rb +19 -0
  126. data/lib/braintree/transaction/payment_receipt/card_present_data.rb +36 -0
  127. data/lib/braintree/transaction/payment_receipt/merchant_address.rb +19 -0
  128. data/lib/braintree/transaction/payment_receipt.rb +31 -0
  129. data/lib/braintree/transaction/paypal_details.rb +5 -0
  130. data/lib/braintree/transaction/samsung_pay_card_details.rb +3 -1
  131. data/lib/braintree/transaction/sepa_direct_debit_account_details.rb +27 -0
  132. data/lib/braintree/transaction/status_details.rb +1 -1
  133. data/lib/braintree/transaction/subscription_details.rb +3 -1
  134. data/lib/braintree/transaction/us_bank_account_details.rb +2 -1
  135. data/lib/braintree/transaction/visa_checkout_card_details.rb +1 -1
  136. data/lib/braintree/transaction.rb +119 -128
  137. data/lib/braintree/transaction_gateway.rb +138 -64
  138. data/lib/braintree/transaction_line_item.rb +14 -11
  139. data/lib/braintree/transaction_line_item_gateway.rb +1 -1
  140. data/lib/braintree/transaction_review.rb +18 -0
  141. data/lib/braintree/transaction_search.rb +11 -7
  142. data/lib/braintree/unknown_payment_method.rb +2 -2
  143. data/lib/braintree/us_bank_account.rb +5 -5
  144. data/lib/braintree/us_bank_account_verification.rb +24 -16
  145. data/lib/braintree/us_bank_account_verification_gateway.rb +1 -1
  146. data/lib/braintree/us_bank_account_verification_search.rb +1 -1
  147. data/lib/braintree/util.rb +25 -10
  148. data/lib/braintree/validation_error.rb +1 -1
  149. data/lib/braintree/validation_error_collection.rb +3 -3
  150. data/lib/braintree/venmo_account.rb +4 -4
  151. data/lib/braintree/venmo_profile_data.rb +25 -0
  152. data/lib/braintree/version.rb +2 -2
  153. data/lib/braintree/visa_checkout_card.rb +8 -8
  154. data/lib/braintree/webhook_notification.rb +55 -33
  155. data/lib/braintree/webhook_notification_gateway.rb +9 -9
  156. data/lib/braintree/webhook_testing.rb +1 -1
  157. data/lib/braintree/webhook_testing_gateway.rb +569 -46
  158. data/lib/braintree/xml/generator.rb +6 -5
  159. data/lib/braintree/xml/libxml.rb +1 -1
  160. data/lib/braintree/xml/parser.rb +24 -37
  161. data/lib/braintree/xml/rexml.rb +6 -7
  162. data/lib/braintree/xml.rb +1 -1
  163. data/lib/braintree.rb +41 -24
  164. data/lib/ssl/api_braintreegateway_com.ca.crt +401 -168
  165. data/spec/integration/braintree/add_on_spec.rb +10 -10
  166. data/spec/integration/braintree/address_spec.rb +101 -178
  167. data/spec/integration/braintree/advanced_search_spec.rb +93 -93
  168. data/spec/integration/braintree/apple_pay_spec.rb +12 -12
  169. data/spec/integration/braintree/braintree_gateway_spec.rb +2 -1
  170. data/spec/integration/braintree/client_api/client_token_spec.rb +279 -62
  171. data/spec/integration/braintree/client_api/spec_helper.rb +99 -73
  172. data/spec/integration/braintree/credit_card_spec.rb +522 -821
  173. data/spec/integration/braintree/credit_card_verification_search_spec.rb +18 -18
  174. data/spec/integration/braintree/credit_card_verification_spec.rb +219 -30
  175. data/spec/integration/braintree/customer_search_spec.rb +28 -28
  176. data/spec/integration/braintree/customer_spec.rb +840 -757
  177. data/spec/integration/braintree/disbursement_spec.rb +2 -2
  178. data/spec/integration/braintree/discount_spec.rb +9 -9
  179. data/spec/integration/braintree/dispute_search_spec.rb +45 -9
  180. data/spec/integration/braintree/dispute_spec.rb +109 -82
  181. data/spec/integration/braintree/document_upload_spec.rb +29 -17
  182. data/spec/integration/braintree/error_codes_spec.rb +3 -3
  183. data/spec/integration/braintree/exchange_rate_quote_spec.rb +97 -0
  184. data/spec/integration/braintree/graphql_client_spec.rb +0 -2
  185. data/spec/integration/braintree/http_spec.rb +31 -33
  186. data/spec/integration/braintree/merchant_account_spec.rb +155 -156
  187. data/spec/integration/braintree/merchant_spec.rb +71 -192
  188. data/spec/integration/braintree/oauth_spec.rb +72 -72
  189. data/spec/integration/braintree/package_tracking_spec.rb +130 -0
  190. data/spec/integration/braintree/payment_method_nonce_spec.rb +173 -78
  191. data/spec/integration/braintree/payment_method_spec.rb +953 -501
  192. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +147 -234
  193. data/spec/integration/braintree/paypal_account_spec.rb +74 -72
  194. data/spec/integration/braintree/plan_spec.rb +96 -15
  195. data/spec/integration/braintree/samsung_pay_card_spec.rb +75 -73
  196. data/spec/integration/braintree/sepa_direct_debit_account_spec.rb +194 -0
  197. data/spec/integration/braintree/settlement_batch_summary_spec.rb +18 -18
  198. data/spec/integration/braintree/subscription_spec.rb +507 -513
  199. data/spec/integration/braintree/test/transaction_amounts_spec.rb +4 -4
  200. data/spec/integration/braintree/test_transaction_spec.rb +29 -29
  201. data/spec/integration/braintree/transaction_line_item_spec.rb +12 -6
  202. data/spec/integration/braintree/transaction_search_spec.rb +410 -217
  203. data/spec/integration/braintree/transaction_spec.rb +3252 -2102
  204. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +42 -278
  205. data/spec/integration/braintree/us_bank_account_spec.rb +36 -36
  206. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +25 -25
  207. data/spec/integration/braintree/us_bank_account_verification_spec.rb +41 -41
  208. data/spec/integration/braintree/visa_checkout_card_spec.rb +62 -62
  209. data/spec/integration/spec_helper.rb +22 -7
  210. data/spec/oauth_test_helper.rb +1 -1
  211. data/spec/script/httpsd.rb +6 -6
  212. data/spec/spec_helper.rb +15 -20
  213. data/spec/unit/braintree/address_spec.rb +9 -17
  214. data/spec/unit/braintree/apple_pay_card_spec.rb +110 -7
  215. data/spec/unit/braintree/base_module_spec.rb +4 -4
  216. data/spec/unit/braintree/client_token_spec.rb +6 -6
  217. data/spec/unit/braintree/configuration_spec.rb +84 -84
  218. data/spec/unit/braintree/credentials_parser_spec.rb +6 -6
  219. data/spec/unit/braintree/credit_card_spec.rb +91 -58
  220. data/spec/unit/braintree/credit_card_verification_gateway_spec.rb +56 -0
  221. data/spec/unit/braintree/credit_card_verification_search_spec.rb +10 -10
  222. data/spec/unit/braintree/credit_card_verification_spec.rb +40 -18
  223. data/spec/unit/braintree/customer_spec.rb +102 -57
  224. data/spec/unit/braintree/digest_spec.rb +5 -6
  225. data/spec/unit/braintree/disbursement_spec.rb +14 -14
  226. data/spec/unit/braintree/dispute_search_spec.rb +6 -2
  227. data/spec/unit/braintree/dispute_spec.rb +144 -66
  228. data/spec/unit/braintree/document_upload_spec.rb +8 -8
  229. data/spec/unit/braintree/enriched_customer_data_spec.rb +41 -0
  230. data/spec/unit/braintree/error_result_spec.rb +11 -11
  231. data/spec/unit/braintree/errors_spec.rb +17 -17
  232. data/spec/unit/braintree/exchange_rate_quote_input_spec.rb +42 -0
  233. data/spec/unit/braintree/exchange_rate_quote_request_spec.rb +82 -0
  234. data/spec/unit/braintree/exchange_rate_quote_response_spec.rb +52 -0
  235. data/spec/unit/braintree/exchange_rate_quote_spec.rb +42 -0
  236. data/spec/unit/braintree/exchange_rate_spec.rb +23 -0
  237. data/spec/unit/braintree/http_spec.rb +19 -17
  238. data/spec/unit/braintree/local_payment_completed_spec.rb +62 -8
  239. data/spec/unit/braintree/local_payment_expired_spec.rb +24 -0
  240. data/spec/unit/braintree/local_payment_funded_spec.rb +34 -0
  241. data/spec/unit/braintree/merchant_account_spec.rb +5 -5
  242. data/spec/unit/braintree/meta_checkout_card_details_spec.rb +60 -0
  243. data/spec/unit/braintree/meta_checkout_card_spec.rb +60 -0
  244. data/spec/unit/braintree/meta_checkout_token_details_spec.rb +63 -0
  245. data/spec/unit/braintree/meta_checkout_token_spec.rb +63 -0
  246. data/spec/unit/braintree/modification_spec.rb +1 -1
  247. data/spec/unit/braintree/package_tracking_spec.rb +77 -0
  248. data/spec/unit/braintree/payment_method_customer_data_updated_metadata_spec.rb +45 -0
  249. data/spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb +31 -0
  250. data/spec/unit/braintree/payment_method_nonce_details_spec.rb +51 -0
  251. data/spec/unit/braintree/payment_method_nonce_spec.rb +40 -0
  252. data/spec/unit/braintree/payment_method_spec.rb +20 -20
  253. data/spec/unit/braintree/paypal_account_spec.rb +16 -7
  254. data/spec/unit/braintree/resource_collection_spec.rb +34 -5
  255. data/spec/unit/braintree/risk_data/liability_shift.rb +26 -0
  256. data/spec/unit/braintree/risk_data_spec.rb +38 -8
  257. data/spec/unit/braintree/sepa_debit_account_nonce_details_spec.rb +29 -0
  258. data/spec/unit/braintree/sepa_debit_account_spec.rb +86 -0
  259. data/spec/unit/braintree/sha256_digest_spec.rb +1 -1
  260. data/spec/unit/braintree/signature_service_spec.rb +2 -2
  261. data/spec/unit/braintree/subscription_search_spec.rb +18 -18
  262. data/spec/unit/braintree/subscription_spec.rb +8 -8
  263. data/spec/unit/braintree/successful_result_spec.rb +6 -6
  264. data/spec/unit/braintree/three_d_secure_info_spec.rb +37 -17
  265. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +22 -6
  266. data/spec/unit/braintree/transaction/customer_details_spec.rb +3 -2
  267. data/spec/unit/braintree/transaction/deposit_details_spec.rb +4 -4
  268. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  269. data/spec/unit/braintree/transaction/local_payment_details_spec.rb +36 -0
  270. data/spec/unit/braintree/transaction/payment_receipt_spec.rb +73 -0
  271. data/spec/unit/braintree/transaction/paypal_details_spec.rb +63 -0
  272. data/spec/unit/braintree/transaction/sepa_direct_debit_account_details_spec.rb +33 -0
  273. data/spec/unit/braintree/transaction_gateway_spec.rb +150 -0
  274. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  275. data/spec/unit/braintree/transaction_spec.rb +221 -124
  276. data/spec/unit/braintree/unknown_payment_method_spec.rb +4 -4
  277. data/spec/unit/braintree/us_bank_account_spec.rb +2 -2
  278. data/spec/unit/braintree/us_bank_account_verification_search_spec.rb +7 -7
  279. data/spec/unit/braintree/us_bank_account_verification_spec.rb +12 -7
  280. data/spec/unit/braintree/util_spec.rb +78 -44
  281. data/spec/unit/braintree/validation_error_collection_spec.rb +62 -62
  282. data/spec/unit/braintree/validation_error_spec.rb +4 -4
  283. data/spec/unit/braintree/venmo_profile_data_spec.rb +43 -0
  284. data/spec/unit/braintree/webhook_notification_spec.rb +434 -197
  285. data/spec/unit/braintree/xml/libxml_spec.rb +5 -5
  286. data/spec/unit/braintree/xml/parser_spec.rb +27 -22
  287. data/spec/unit/braintree/xml/rexml_spec.rb +5 -5
  288. data/spec/unit/braintree/xml_spec.rb +38 -38
  289. data/spec/unit/braintree_spec.rb +2 -2
  290. metadata +91 -30
  291. data/lib/braintree/amex_express_checkout_card.rb +0 -38
  292. data/lib/braintree/coinbase_account.rb +0 -34
  293. data/lib/braintree/europe_bank_account.rb +0 -36
  294. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  295. data/lib/braintree/ideal_payment.rb +0 -61
  296. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  297. data/lib/braintree/masterpass_card.rb +0 -81
  298. data/lib/braintree/settlement_batch.rb +0 -0
  299. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  300. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  301. data/lib/braintree/transaction/masterpass_card_details.rb +0 -47
  302. data/lib/braintree/transparent_redirect.rb +0 -40
  303. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  304. data/spec/hacks/tcp_socket.rb +0 -18
  305. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  306. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  307. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  308. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
@@ -9,23 +9,25 @@ describe Braintree::PayPalAccount do
9
9
 
10
10
  nonce = nonce_for_paypal_account(
11
11
  :consent_code => "consent-code",
12
- :token => payment_method_token
12
+ :token => payment_method_token,
13
13
  )
14
14
  result = Braintree::PaymentMethod.create(
15
15
  :payment_method_nonce => nonce,
16
- :customer_id => customer.id
16
+ :customer_id => customer.id,
17
17
  )
18
- result.should be_success
18
+ expect(result).to be_success
19
19
 
20
20
  paypal_account = Braintree::PayPalAccount.find(payment_method_token)
21
- paypal_account.should be_a(Braintree::PayPalAccount)
22
- paypal_account.token.should == payment_method_token
23
- paypal_account.email.should == "jane.doe@example.com"
24
- paypal_account.image_url.should_not be_nil
25
- paypal_account.created_at.should_not be_nil
26
- paypal_account.updated_at.should_not be_nil
27
- paypal_account.customer_id.should == customer.id
28
- paypal_account.revoked_at.should be_nil
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
29
31
  end
30
32
 
31
33
  it "returns a PayPalAccount with a billing agreement id" do
@@ -35,12 +37,12 @@ describe Braintree::PayPalAccount do
35
37
  result = Braintree::PaymentMethod.create(
36
38
  :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
37
39
  :customer_id => customer.id,
38
- :token => payment_method_token
40
+ :token => payment_method_token,
39
41
  )
40
- result.should be_success
42
+ expect(result).to be_success
41
43
 
42
44
  paypal_account = Braintree::PayPalAccount.find(payment_method_token)
43
- paypal_account.billing_agreement_id.should_not be_nil
45
+ expect(paypal_account.billing_agreement_id).not_to be_nil
44
46
  end
45
47
 
46
48
  it "raises if the payment method token is not found" do
@@ -51,12 +53,12 @@ describe Braintree::PayPalAccount do
51
53
 
52
54
  it "does not return a different payment method type" do
53
55
  customer = Braintree::Customer.create!
54
- result = Braintree::CreditCard.create(
56
+ Braintree::CreditCard.create(
55
57
  :customer_id => customer.id,
56
58
  :number => Braintree::Test::CreditCardNumbers::Visa,
57
59
  :expiration_date => "05/2009",
58
60
  :cvv => "100",
59
- :token => "CREDIT_CARD_TOKEN"
61
+ :token => "CREDIT_CARD_TOKEN",
60
62
  )
61
63
 
62
64
  expect do
@@ -70,28 +72,28 @@ describe Braintree::PayPalAccount do
70
72
 
71
73
  nonce = nonce_for_paypal_account(
72
74
  :consent_code => "consent-code",
73
- :token => payment_method_token
75
+ :token => payment_method_token,
74
76
  )
75
77
  result = Braintree::PaymentMethod.create(
76
78
  :payment_method_nonce => nonce,
77
- :customer_id => customer.id
79
+ :customer_id => customer.id,
78
80
  )
79
- result.should be_success
81
+ expect(result).to be_success
80
82
 
81
83
  token = result.payment_method.token
82
84
 
83
85
  subscription1 = Braintree::Subscription.create(
84
86
  :payment_method_token => token,
85
- :plan_id => SpecHelper::TriallessPlan[:id]
87
+ :plan_id => SpecHelper::TriallessPlan[:id],
86
88
  ).subscription
87
89
 
88
90
  subscription2 = Braintree::Subscription.create(
89
91
  :payment_method_token => token,
90
- :plan_id => SpecHelper::TriallessPlan[:id]
92
+ :plan_id => SpecHelper::TriallessPlan[:id],
91
93
  ).subscription
92
94
 
93
95
  paypal_account = Braintree::PayPalAccount.find(token)
94
- paypal_account.subscriptions.map(&:id).sort.should == [subscription1.id, subscription2.id].sort
96
+ expect(paypal_account.subscriptions.map(&:id).sort).to eq([subscription1.id, subscription2.id].sort)
95
97
  end
96
98
  end
97
99
 
@@ -105,33 +107,33 @@ describe Braintree::PayPalAccount do
105
107
  :options => {
106
108
  :make_default => true,
107
109
  :fail_on_duplicate_payment_method => true,
108
- }
110
+ },
109
111
  )
110
112
 
111
- result.should be_success
112
- result.paypal_account.billing_agreement_id.should == "some_billing_agreement_id"
113
- result.paypal_account.email.should == "some@example.com"
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")
114
116
  end
115
117
 
116
118
  it "throws an error if customer id is not specified" do
117
119
  result = Braintree::PayPalAccount.create(
118
120
  :billing_agreement_id => "some_billing_agreement_id",
119
- :email => "some@example.com"
121
+ :email => "some@example.com",
120
122
  )
121
123
 
122
- result.success?.should == false
123
- result.errors.first.code.should == "82905"
124
+ expect(result.success?).to eq(false)
125
+ expect(result.errors.first.code).to eq("82905")
124
126
  end
125
127
 
126
128
  it "throws an error if billing agreement id is not specified" do
127
129
  customer = Braintree::Customer.create!
128
130
  result = Braintree::PayPalAccount.create(
129
131
  :customer_id => customer.id,
130
- :email => "some@example.com"
132
+ :email => "some@example.com",
131
133
  )
132
134
 
133
- result.success?.should == false
134
- result.errors.first.code.should == "82902"
135
+ expect(result.success?).to eq(false)
136
+ expect(result.errors.map(&:code)).to include("82902")
135
137
  end
136
138
  end
137
139
 
@@ -141,21 +143,21 @@ describe Braintree::PayPalAccount do
141
143
  create_result = Braintree::PayPalAccount.create(
142
144
  :customer_id => customer.id,
143
145
  :billing_agreement_id => "first_billing_agreement_id",
144
- :email => "first@example.com"
146
+ :email => "first@example.com",
145
147
  )
146
- create_result.success?.should == true
148
+ expect(create_result.success?).to eq(true)
147
149
 
148
150
  update_result = Braintree::PayPalAccount.update(
149
151
  create_result.paypal_account.token,
150
152
  :billing_agreement_id => "second_billing_agreement_id",
151
- :email => "second@example.com"
153
+ :email => "second@example.com",
152
154
  )
153
155
 
154
- update_result.success?.should == true
156
+ expect(update_result.success?).to eq(true)
155
157
  paypal_account = update_result.paypal_account
156
158
 
157
- paypal_account.billing_agreement_id.should == "second_billing_agreement_id"
158
- paypal_account.email.should == "second@example.com"
159
+ expect(paypal_account.billing_agreement_id).to eq("second_billing_agreement_id")
160
+ expect(paypal_account.email).to eq("second@example.com")
159
161
  end
160
162
 
161
163
  it "updates a paypal account's token" do
@@ -163,21 +165,21 @@ describe Braintree::PayPalAccount do
163
165
  original_token = random_payment_method_token
164
166
  nonce = nonce_for_paypal_account(
165
167
  :consent_code => "consent-code",
166
- :token => original_token
168
+ :token => original_token,
167
169
  )
168
170
  original_result = Braintree::PaymentMethod.create(
169
171
  :payment_method_nonce => nonce,
170
- :customer_id => customer.id
172
+ :customer_id => customer.id,
171
173
  )
172
174
 
173
175
  updated_token = "UPDATED_TOKEN-" + rand(36**3).to_s(36)
174
- updated_result = Braintree::PayPalAccount.update(
176
+ Braintree::PayPalAccount.update(
175
177
  original_token,
176
- :token => updated_token
178
+ :token => updated_token,
177
179
  )
178
180
 
179
181
  updated_paypal_account = Braintree::PayPalAccount.find(updated_token)
180
- updated_paypal_account.email.should == original_result.payment_method.email
182
+ expect(updated_paypal_account.email).to eq(original_result.payment_method.email)
181
183
 
182
184
  expect do
183
185
  Braintree::PayPalAccount.find(original_token)
@@ -190,23 +192,23 @@ describe Braintree::PayPalAccount do
190
192
  :customer_id => customer.id,
191
193
  :number => Braintree::Test::CreditCardNumbers::Visa,
192
194
  :expiration_date => "05/2009",
193
- :options => {:make_default => true}
195
+ :options => {:make_default => true},
194
196
  )
195
- result.should be_success
197
+ expect(result).to be_success
196
198
 
197
199
  nonce = nonce_for_paypal_account(:consent_code => "consent-code")
198
200
  original_token = Braintree::PaymentMethod.create(
199
201
  :payment_method_nonce => nonce,
200
- :customer_id => customer.id
202
+ :customer_id => customer.id,
201
203
  ).payment_method.token
202
204
 
203
- updated_result = Braintree::PayPalAccount.update(
205
+ Braintree::PayPalAccount.update(
204
206
  original_token,
205
- :options => {:make_default => true}
207
+ :options => {:make_default => true},
206
208
  )
207
209
 
208
210
  updated_paypal_account = Braintree::PayPalAccount.find(original_token)
209
- updated_paypal_account.should be_default
211
+ expect(updated_paypal_account).to be_default
210
212
  end
211
213
 
212
214
  it "returns an error if a token for account is used to attempt an update" do
@@ -216,29 +218,29 @@ describe Braintree::PayPalAccount do
216
218
 
217
219
  first_nonce = nonce_for_paypal_account(
218
220
  :consent_code => "consent-code",
219
- :token => first_token
221
+ :token => first_token,
220
222
  )
221
- first_result = Braintree::PaymentMethod.create(
223
+ Braintree::PaymentMethod.create(
222
224
  :payment_method_nonce => first_nonce,
223
- :customer_id => customer.id
225
+ :customer_id => customer.id,
224
226
  )
225
227
 
226
228
  second_nonce = nonce_for_paypal_account(
227
229
  :consent_code => "consent-code",
228
- :token => second_token
230
+ :token => second_token,
229
231
  )
230
- second_result = Braintree::PaymentMethod.create(
232
+ Braintree::PaymentMethod.create(
231
233
  :payment_method_nonce => second_nonce,
232
- :customer_id => customer.id
234
+ :customer_id => customer.id,
233
235
  )
234
236
 
235
237
  updated_result = Braintree::PayPalAccount.update(
236
238
  first_token,
237
- :token => second_token
239
+ :token => second_token,
238
240
  )
239
241
 
240
- updated_result.should_not be_success
241
- updated_result.errors.first.code.should == "92906"
242
+ expect(updated_result).not_to be_success
243
+ expect(updated_result.errors.first.code).to eq("92906")
242
244
  end
243
245
  end
244
246
 
@@ -249,14 +251,14 @@ describe Braintree::PayPalAccount do
249
251
 
250
252
  nonce = nonce_for_paypal_account(
251
253
  :consent_code => "consent-code",
252
- :token => token
254
+ :token => token,
253
255
  )
254
256
  Braintree::PaymentMethod.create(
255
257
  :payment_method_nonce => nonce,
256
- :customer_id => customer.id
258
+ :customer_id => customer.id,
257
259
  )
258
260
 
259
- result = Braintree::PayPalAccount.delete(token)
261
+ Braintree::PayPalAccount.delete(token)
260
262
 
261
263
  expect do
262
264
  Braintree::PayPalAccount.find(token)
@@ -267,31 +269,31 @@ describe Braintree::PayPalAccount do
267
269
  context "self.sale" do
268
270
  it "creates a transaction using a paypal account and returns a result object" do
269
271
  customer = Braintree::Customer.create!(
270
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment
272
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
271
273
  )
272
274
 
273
275
  result = Braintree::PayPalAccount.sale(customer.paypal_accounts[0].token, :amount => "100.00")
274
276
 
275
- result.success?.should == true
276
- result.transaction.amount.should == BigDecimal("100.00")
277
- result.transaction.type.should == "sale"
278
- result.transaction.customer_details.id.should == customer.id
279
- result.transaction.paypal_details.token.should == customer.paypal_accounts[0].token
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)
280
282
  end
281
283
  end
282
284
 
283
285
  context "self.sale!" do
284
286
  it "creates a transaction using a paypal account and returns a transaction" do
285
287
  customer = Braintree::Customer.create!(
286
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment
288
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
287
289
  )
288
290
 
289
291
  transaction = Braintree::PayPalAccount.sale!(customer.paypal_accounts[0].token, :amount => "100.00")
290
292
 
291
- transaction.amount.should == BigDecimal("100.00")
292
- transaction.type.should == "sale"
293
- transaction.customer_details.id.should == customer.id
294
- transaction.paypal_details.token.should == customer.paypal_accounts[0].token
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)
295
297
  end
296
298
  end
297
299
  end
@@ -1,4 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
2
3
 
3
4
  describe Braintree::Plan do
4
5
 
@@ -25,26 +26,106 @@ describe Braintree::Plan do
25
26
 
26
27
  plans = Braintree::Plan.all
27
28
  plan = plans.select { |plan| plan.id == plan_token }.first
28
- plan.should_not be_nil
29
- plan.id.should == attributes[:id]
30
- plan.billing_day_of_month.should == attributes[:billing_day_of_month]
31
- plan.billing_frequency.should == attributes[:billing_frequency]
32
- plan.currency_iso_code.should == attributes[:currency_iso_code]
33
- plan.description.should == attributes[:description]
34
- plan.name.should == attributes[:name]
35
- plan.number_of_billing_cycles.should == attributes[:number_of_billing_cycles]
36
- plan.price.should == Braintree::Util.to_big_decimal("1.00")
37
- plan.trial_period.should == attributes[:trial_period]
38
- plan.created_at.should_not be_nil
39
- plan.updated_at.should_not be_nil
40
- plan.add_ons.first.name.should == add_on_name
41
- plan.discounts.first.name.should == discount_name
29
+ expect(plan).not_to be_nil
30
+ expect(plan.id).to eq(attributes[:id])
31
+ expect(plan.billing_day_of_month).to eq(attributes[:billing_day_of_month])
32
+ expect(plan.billing_frequency).to eq(attributes[:billing_frequency])
33
+ expect(plan.currency_iso_code).to eq(attributes[:currency_iso_code])
34
+ expect(plan.description).to eq(attributes[:description])
35
+ expect(plan.name).to eq(attributes[:name])
36
+ expect(plan.number_of_billing_cycles).to eq(attributes[:number_of_billing_cycles])
37
+ expect(plan.price).to eq(Braintree::Util.to_big_decimal("1.00"))
38
+ expect(plan.trial_period).to eq(attributes[:trial_period])
39
+ expect(plan.created_at).not_to be_nil
40
+ expect(plan.updated_at).not_to be_nil
41
+ expect(plan.add_ons.first.name).to eq(add_on_name)
42
+ expect(plan.discounts.first.name).to eq(discount_name)
42
43
  end
43
44
 
44
45
  it "returns an empty array if there are no plans" do
45
46
  gateway = Braintree::Gateway.new(SpecHelper::TestMerchantConfig)
46
47
  plans = gateway.plan.all
47
- plans.should == []
48
+ expect(plans).to eq([])
49
+ end
50
+ end
51
+
52
+ describe "self.create" do
53
+ let(:attributes) do
54
+ {
55
+ :billing_day_of_month => 12,
56
+ :billing_frequency => 1,
57
+ :currency_iso_code => "USD",
58
+ :description => "description on create",
59
+ :name => "my new plan name",
60
+ :number_of_billing_cycles => 1,
61
+ :price => "9.99",
62
+ :trial_period => false
63
+ }
64
+
65
+ it "is successful with given params" do
66
+ result = Braintree::Plan.create(attributes)
67
+ expect(result.success?).to be_truthy
68
+ expect(result.plan.billing_day_of_month).to eq 12
69
+ expect(result.plan.description).to eq "description on create"
70
+ expect(result.plan.name).to eq "my new plan name"
71
+ expect(result.plan.price).to eq "9.99"
72
+ expect(result.plan.billing_frequency).to eq 1
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "self.find" do
78
+ it "finds a plan" do
79
+ plan = Braintree::Plan.create(
80
+ :billing_day_of_month => 12,
81
+ :billing_frequency => 1,
82
+ :currency_iso_code => "USD",
83
+ :description => "description on create",
84
+ :name => "my new plan name",
85
+ :number_of_billing_cycles => 1,
86
+ :price => "9.99",
87
+ :trial_period => false,
88
+ ).plan
89
+
90
+ found_plan = Braintree::Plan.find(plan.id)
91
+ expect(found_plan.name).to eq plan.name
92
+ end
93
+
94
+ it "raises Braintree::NotFoundError if it cannot find" do
95
+ expect {
96
+ Braintree::Plan.find("noSuchPlan")
97
+ }.to raise_error(Braintree::NotFoundError, 'plan with id "noSuchPlan" not found')
98
+ end
99
+ end
100
+
101
+ describe "self.update!" do
102
+ before(:each) do
103
+ @plan = Braintree::Plan.create(
104
+ :billing_day_of_month => 12,
105
+ :billing_frequency => 1,
106
+ :currency_iso_code => "USD",
107
+ :description => "description on create",
108
+ :name => "my new plan name",
109
+ :number_of_billing_cycles => 1,
110
+ :price => "9.99",
111
+ :trial_period => false,
112
+ ).plan
113
+ end
114
+
115
+ it "returns the updated plan if valid" do
116
+ plan = Braintree::Plan.update!(@plan.id,
117
+ :name => "updated name",
118
+ :price => 99.88,
119
+ )
120
+
121
+ expect(plan.name).to eq "updated name"
122
+ expect(plan.price).to eq BigDecimal("99.88")
123
+ end
124
+
125
+ it "raises a ValidationsFailed if invalid" do
126
+ expect do
127
+ Braintree::Plan.update!(@plan.id, :number_of_billing_cycles => "number of billing cycles")
128
+ end.to raise_error(Braintree::ValidationsFailed)
48
129
  end
49
130
  end
50
131