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
@@ -6,10 +6,10 @@ describe Braintree::Customer do
6
6
  describe "self.all" do
7
7
  it "gets more than a page of customers" do
8
8
  customers = Braintree::Customer.all
9
- customers.maximum_size.should > 100
9
+ expect(customers.maximum_size).to be > 100
10
10
 
11
- customer_ids = customers.map {|c| c.id }.uniq.compact
12
- customer_ids.size.should == customers.maximum_size
11
+ customer_ids = customers.map { |c| c.id }.uniq.compact
12
+ expect(customer_ids.size).to eq(customers.maximum_size)
13
13
  end
14
14
  end
15
15
 
@@ -17,13 +17,13 @@ describe Braintree::Customer do
17
17
  it "deletes the customer with the given id" do
18
18
  create_result = Braintree::Customer.create(
19
19
  :first_name => "Joe",
20
- :last_name => "Cool"
20
+ :last_name => "Cool",
21
21
  )
22
- create_result.success?.should == true
22
+ expect(create_result.success?).to eq(true)
23
23
  customer = create_result.customer
24
24
 
25
25
  delete_result = Braintree::Customer.delete(customer.id)
26
- delete_result.success?.should == true
26
+ expect(delete_result.success?).to eq(true)
27
27
  expect do
28
28
  Braintree::Customer.find(customer.id)
29
29
  end.to raise_error(Braintree::NotFoundError)
@@ -38,27 +38,31 @@ describe Braintree::Customer do
38
38
  :company => "Microsoft",
39
39
  :email => "bill@microsoft.com",
40
40
  :phone => "312.555.1234",
41
+ :international_phone => {:country_code => "1", :national_number => "3121234567"},
41
42
  :fax => "614.555.5678",
42
- :website => "www.microsoft.com"
43
- )
44
- result.success?.should == true
45
- result.customer.id.should =~ /^\d{6,}$/
46
- result.customer.first_name.should == "Bill"
47
- result.customer.last_name.should == "Gates"
48
- result.customer.company.should == "Microsoft"
49
- result.customer.email.should == "bill@microsoft.com"
50
- result.customer.phone.should == "312.555.1234"
51
- result.customer.fax.should == "614.555.5678"
52
- result.customer.website.should == "www.microsoft.com"
53
- result.customer.created_at.between?(Time.now - 10, Time.now).should == true
54
- result.customer.updated_at.between?(Time.now - 10, Time.now).should == true
43
+ :website => "www.microsoft.com",
44
+ :tax_identifiers => [{:country_code => "US", :identifier => "987654321"}],
45
+ )
46
+ expect(result.success?).to eq(true)
47
+ expect(result.customer.id).to match(/^\d{6,}$/)
48
+ expect(result.customer.first_name).to eq("Bill")
49
+ expect(result.customer.last_name).to eq("Gates")
50
+ expect(result.customer.company).to eq("Microsoft")
51
+ expect(result.customer.email).to eq("bill@microsoft.com")
52
+ expect(result.customer.phone).to eq("312.555.1234")
53
+ expect(result.customer.international_phone[:country_code]).to eq("1")
54
+ expect(result.customer.international_phone[:national_number]).to eq("3121234567")
55
+ expect(result.customer.fax).to eq("614.555.5678")
56
+ expect(result.customer.website).to eq("www.microsoft.com")
57
+ expect(result.customer.created_at.between?(Time.now - 10, Time.now)).to eq(true)
58
+ expect(result.customer.updated_at.between?(Time.now - 10, Time.now)).to eq(true)
55
59
  end
56
60
 
57
61
  it "returns a successful result if successful using an access token" do
58
62
  oauth_gateway = Braintree::Gateway.new(
59
63
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
60
64
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
61
- :logger => Logger.new("/dev/null")
65
+ :logger => Logger.new("/dev/null"),
62
66
  )
63
67
  access_token = Braintree::OAuthTestHelper.create_token(oauth_gateway, {
64
68
  :merchant_public_id => "integration_merchant_id",
@@ -67,7 +71,7 @@ describe Braintree::Customer do
67
71
 
68
72
  gateway = Braintree::Gateway.new(
69
73
  :access_token => access_token,
70
- :logger => Logger.new("/dev/null")
74
+ :logger => Logger.new("/dev/null"),
71
75
  )
72
76
 
73
77
  result = gateway.customer.create(
@@ -77,26 +81,25 @@ describe Braintree::Customer do
77
81
  :email => "joe@example.com",
78
82
  :phone => "312.555.1234",
79
83
  :fax => "614.555.5678",
80
- :website => "www.example.com"
84
+ :website => "www.example.com",
81
85
  )
82
- result.success?.should == true
83
- result.customer.id.should =~ /^\d{6,}$/
84
- result.customer.first_name.should == "Joe"
85
- result.customer.last_name.should == "Brown"
86
+ expect(result.success?).to eq(true)
87
+ expect(result.customer.id).to match(/^\d{6,}$/)
88
+ expect(result.customer.first_name).to eq("Joe")
89
+ expect(result.customer.last_name).to eq("Brown")
86
90
  end
87
91
 
88
- it "supports creation with a device session ID and (optional) fraud_merchant_id" do
92
+ it "supports creation with device_data" do
89
93
  result = Braintree::Customer.create(
90
94
  :credit_card => {
91
95
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
92
96
  :expiration_date => "05/2010",
93
97
  :cvv => "100",
94
- :device_session_id => "abc123",
95
- :fraud_merchant_id => "7"
96
- }
98
+ :device_data => "device_data",
99
+ },
97
100
  )
98
101
 
99
- result.should be_success
102
+ expect(result).to be_success
100
103
  end
101
104
 
102
105
  it "supports creation including risk data with customer_browser and customer_ip" do
@@ -109,50 +112,101 @@ describe Braintree::Customer do
109
112
  :risk_data => {
110
113
  :customer_browser => "IE5",
111
114
  :customer_ip => "192.168.0.1"
112
- }
115
+ },
113
116
  )
114
117
 
115
- result.should be_success
118
+ expect(result).to be_success
119
+ end
120
+
121
+ it "includes risk data when skip_advanced_fraud_checking is false" do
122
+ with_fraud_protection_enterprise_merchant do
123
+ result = Braintree::Customer.create(
124
+ :credit_card => {
125
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
126
+ :expiration_date => "05/2010",
127
+ :cvv => "100",
128
+ :options => {
129
+ :skip_advanced_fraud_checking => false,
130
+ :verify_card => true,
131
+ },
132
+ },
133
+ )
134
+
135
+ expect(result).to be_success
136
+ verification = result.customer.credit_cards.first.verification
137
+ expect(verification.risk_data).not_to be_nil
138
+ end
139
+ end
140
+
141
+ it "does not include risk data when skip_advanced_fraud_checking is true" do
142
+ with_fraud_protection_enterprise_merchant do
143
+ result = Braintree::Customer.create(
144
+ :credit_card => {
145
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
146
+ :expiration_date => "05/2010",
147
+ :cvv => "100",
148
+ :options => {
149
+ :skip_advanced_fraud_checking => true,
150
+ :verify_card => true,
151
+ },
152
+ },
153
+ )
154
+
155
+ expect(result).to be_success
156
+ verification = result.customer.credit_cards.first.verification
157
+ expect(verification.risk_data).to be_nil
158
+ end
159
+ end
160
+
161
+ it "supports creation with tax_identifiers" do
162
+ result = Braintree::Customer.create(
163
+ :tax_identifiers => [
164
+ {:country_code => "US", :identifier => "987654321"},
165
+ {:country_code => "CL", :identifier => "123456789"}
166
+ ],
167
+ )
168
+
169
+ expect(result).to be_success
116
170
  end
117
171
 
118
172
  it "can create without any attributes" do
119
173
  result = Braintree::Customer.create
120
- result.success?.should == true
174
+ expect(result.success?).to eq(true)
121
175
  end
122
176
 
123
177
  it "supports utf-8" do
124
178
  first_name = "Jos\303\251"
125
179
  last_name = "Mu\303\261oz"
126
180
  result = Braintree::Customer.create(:first_name => first_name, :last_name => last_name)
127
- result.success?.should == true
181
+ expect(result.success?).to eq(true)
128
182
 
129
183
  if RUBY_VERSION =~ /^1.8/
130
- result.customer.first_name.should == first_name
131
- result.customer.last_name.should == last_name
184
+ expect(result.customer.first_name).to eq(first_name)
185
+ expect(result.customer.last_name).to eq(last_name)
132
186
 
133
187
  found_customer = Braintree::Customer.find(result.customer.id)
134
- found_customer.first_name.should == first_name
135
- found_customer.last_name.should == last_name
188
+ expect(found_customer.first_name).to eq(first_name)
189
+ expect(found_customer.last_name).to eq(last_name)
136
190
  else
137
- result.customer.first_name.should == "José"
138
- result.customer.first_name.bytes.map {|b| b.to_s(8)}.should == ["112", "157", "163", "303", "251"]
139
- result.customer.last_name.should == "Muñoz"
140
- result.customer.last_name.bytes.map {|b| b.to_s(8)}.should == ["115", "165", "303", "261", "157", "172"]
191
+ expect(result.customer.first_name).to eq("José")
192
+ expect(result.customer.first_name.bytes.map { |b| b.to_s(8) }).to eq(["112", "157", "163", "303", "251"])
193
+ expect(result.customer.last_name).to eq("Muñoz")
194
+ expect(result.customer.last_name.bytes.map { |b| b.to_s(8) }).to eq(["115", "165", "303", "261", "157", "172"])
141
195
 
142
196
  found_customer = Braintree::Customer.find(result.customer.id)
143
- found_customer.first_name.should == "José"
144
- found_customer.first_name.bytes.map {|b| b.to_s(8)}.should == ["112", "157", "163", "303", "251"]
145
- found_customer.last_name.should == "Muñoz"
146
- found_customer.last_name.bytes.map {|b| b.to_s(8)}.should == ["115", "165", "303", "261", "157", "172"]
197
+ expect(found_customer.first_name).to eq("José")
198
+ expect(found_customer.first_name.bytes.map { |b| b.to_s(8) }).to eq(["112", "157", "163", "303", "251"])
199
+ expect(found_customer.last_name).to eq("Muñoz")
200
+ expect(found_customer.last_name.bytes.map { |b| b.to_s(8) }).to eq(["115", "165", "303", "261", "157", "172"])
147
201
  end
148
202
  end
149
203
 
150
204
  it "returns an error response if invalid" do
151
205
  result = Braintree::Customer.create(
152
- :email => "@invalid.com"
206
+ :email => "@invalid.com",
153
207
  )
154
- result.success?.should == false
155
- result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
208
+ expect(result.success?).to eq(false)
209
+ expect(result.errors.for(:customer).on(:email)[0].message).to eq("Email is an invalid format.")
156
210
  end
157
211
 
158
212
  it "can create a customer and a payment method at the same time" do
@@ -163,16 +217,16 @@ describe Braintree::Customer do
163
217
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
164
218
  :expiration_date => "05/2010",
165
219
  :cvv => "100"
166
- }
220
+ },
167
221
  )
168
222
 
169
- result.success?.should == true
170
- result.customer.first_name.should == "Mike"
171
- result.customer.last_name.should == "Jones"
172
- result.customer.credit_cards[0].bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
173
- result.customer.credit_cards[0].last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
174
- result.customer.credit_cards[0].expiration_date.should == "05/2010"
175
- result.customer.credit_cards[0].unique_number_identifier.should =~ /\A\w{32}\z/
223
+ expect(result.success?).to eq(true)
224
+ expect(result.customer.first_name).to eq("Mike")
225
+ expect(result.customer.last_name).to eq("Jones")
226
+ expect(result.customer.credit_cards[0].bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
227
+ expect(result.customer.credit_cards[0].last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
228
+ expect(result.customer.credit_cards[0].expiration_date).to eq("05/2010")
229
+ expect(result.customer.credit_cards[0].unique_number_identifier).to match(/\A\w{32}\z/)
176
230
  end
177
231
 
178
232
  it "can create a customer and a paypal account at the same time" do
@@ -183,14 +237,14 @@ describe Braintree::Customer do
183
237
  :email => "other@example.com",
184
238
  :billing_agreement_id => "B-123456",
185
239
  :options => {:make_default => true}
186
- }
240
+ },
187
241
  )
188
242
 
189
- result.success?.should == true
190
- result.customer.first_name.should == "Mike"
191
- result.customer.last_name.should == "Jones"
192
- result.customer.paypal_accounts[0].billing_agreement_id.should == "B-123456"
193
- result.customer.paypal_accounts[0].email.should == "other@example.com"
243
+ expect(result.success?).to eq(true)
244
+ expect(result.customer.first_name).to eq("Mike")
245
+ expect(result.customer.last_name).to eq("Jones")
246
+ expect(result.customer.paypal_accounts[0].billing_agreement_id).to eq("B-123456")
247
+ expect(result.customer.paypal_accounts[0].email).to eq("other@example.com")
194
248
  end
195
249
 
196
250
  it "verifies the card if credit_card[options][verify_card]=true" do
@@ -201,10 +255,10 @@ describe Braintree::Customer do
201
255
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
202
256
  :expiration_date => "05/2010",
203
257
  :options => {:verify_card => true}
204
- }
258
+ },
205
259
  )
206
- result.success?.should == false
207
- result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
260
+ expect(result.success?).to eq(false)
261
+ expect(result.credit_card_verification.status).to eq(Braintree::Transaction::Status::ProcessorDeclined)
208
262
  end
209
263
 
210
264
  it "allows a verification_amount" do
@@ -215,9 +269,9 @@ describe Braintree::Customer do
215
269
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
216
270
  :expiration_date => "05/2019",
217
271
  :options => {:verify_card => true, :verification_amount => "2.00"}
218
- }
272
+ },
219
273
  )
220
- result.success?.should == true
274
+ expect(result.success?).to eq(true)
221
275
  end
222
276
 
223
277
  it "fails on create if credit_card[options][fail_on_duplicate_payment_method]=true and there is a duplicated payment method" do
@@ -225,7 +279,7 @@ describe Braintree::Customer do
225
279
  Braintree::CreditCard.create(
226
280
  :customer_id => customer.id,
227
281
  :number => Braintree::Test::CreditCardNumbers::Visa,
228
- :expiration_date => "05/2015"
282
+ :expiration_date => "05/2015",
229
283
  )
230
284
 
231
285
  result = Braintree::Customer.create(
@@ -235,10 +289,10 @@ describe Braintree::Customer do
235
289
  :number => Braintree::Test::CreditCardNumbers::Visa,
236
290
  :expiration_date => "05/2015",
237
291
  :options => {:fail_on_duplicate_payment_method => true}
238
- }
292
+ },
239
293
  )
240
- result.success?.should == false
241
- result.errors.for(:customer).for(:credit_card).on(:number)[0].message.should == "Duplicate card exists in the vault."
294
+ expect(result.success?).to eq(false)
295
+ expect(result.errors.for(:customer).for(:credit_card).on(:number)[0].message).to eq("Duplicate card exists in the vault.")
242
296
  end
243
297
 
244
298
  it "allows the user to specify the merchant account for verification" do
@@ -252,12 +306,98 @@ describe Braintree::Customer do
252
306
  :verify_card => true,
253
307
  :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
254
308
  }
255
- }
309
+ },
310
+ )
311
+ expect(result.success?).to eq(false)
312
+ expect(result.credit_card_verification.status).to eq(Braintree::Transaction::Status::ProcessorDeclined)
313
+ end
314
+
315
+ it "can create a customer and a payment method at the same time after validating verification_currency_iso_code" do
316
+ result = Braintree::Customer.create(
317
+ :first_name => "Mike",
318
+ :last_name => "Jones",
319
+ :credit_card => {
320
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
321
+ :expiration_date => "05/2010",
322
+ :cvv => "100",
323
+ :options => {
324
+ :verify_card => true,
325
+ :verification_currency_iso_code => "USD"
326
+ }
327
+ },
256
328
  )
257
- result.success?.should == false
258
- result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
329
+
330
+ expect(result.success?).to eq(true)
331
+ expect(result.customer.first_name).to eq("Mike")
332
+ expect(result.customer.last_name).to eq("Jones")
333
+ expect(result.customer.credit_cards[0].bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
334
+ expect(result.customer.credit_cards[0].last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
335
+ expect(result.customer.credit_cards[0].expiration_date).to eq("05/2010")
336
+ expect(result.customer.credit_cards[0].unique_number_identifier).to match(/\A\w{32}\z/)
337
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
259
338
  end
260
339
 
340
+ it "errors when verification_currency_iso_code is not supported by merchant account" do
341
+ result = Braintree::Customer.create(
342
+ :first_name => "Mike",
343
+ :last_name => "Jones",
344
+ :credit_card => {
345
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
346
+ :expiration_date => "05/2010",
347
+ :cvv => "100",
348
+ :options => {
349
+ :verify_card => true,
350
+ :verification_currency_iso_code => "GBP"
351
+ }
352
+ },
353
+ )
354
+ expect(result).to_not be_success
355
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
356
+ end
357
+
358
+ it "validates verification_currency_iso_code of the given verification_merchant_account_id and creates customer" do
359
+ result = Braintree::Customer.create(
360
+ :first_name => "Mike",
361
+ :last_name => "Jones",
362
+ :credit_card => {
363
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
364
+ :expiration_date => "05/2010",
365
+ :options => {
366
+ :verify_card => true,
367
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
368
+ :verification_currency_iso_code => "USD"
369
+ }
370
+ },
371
+ )
372
+ expect(result.success?).to eq(true)
373
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
374
+ expect(result.customer.first_name).to eq("Mike")
375
+ expect(result.customer.last_name).to eq("Jones")
376
+ expect(result.customer.credit_cards[0].bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
377
+ expect(result.customer.credit_cards[0].last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
378
+ expect(result.customer.credit_cards[0].expiration_date).to eq("05/2010")
379
+ expect(result.customer.credit_cards[0].unique_number_identifier).to match(/\A\w{32}\z/)
380
+ end
381
+
382
+ it "validates verification_currency_iso_code of the given verification_merchant_account_id and returns error" do
383
+ result = Braintree::Customer.create(
384
+ :first_name => "Mike",
385
+ :last_name => "Jones",
386
+ :credit_card => {
387
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
388
+ :expiration_date => "05/2010",
389
+ :options => {
390
+ :verify_card => true,
391
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
392
+ :verification_currency_iso_code => "GBP"
393
+ }
394
+ },
395
+ )
396
+ expect(result).to_not be_success
397
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
398
+ end
399
+
400
+
261
401
  it "can create a customer, payment method, and billing address at the same time" do
262
402
  result = Braintree::Customer.create(
263
403
  :first_name => "Mike",
@@ -273,22 +413,22 @@ describe Braintree::Customer do
273
413
  :postal_code => "60622",
274
414
  :country_name => "United States of America"
275
415
  }
276
- }
277
- )
278
- result.success?.should == true
279
- result.customer.first_name.should == "Mike"
280
- result.customer.last_name.should == "Jones"
281
- result.customer.credit_cards[0].bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
282
- result.customer.credit_cards[0].last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
283
- result.customer.credit_cards[0].expiration_date.should == "05/2010"
284
- result.customer.credit_cards[0].billing_address.id.should == result.customer.addresses[0].id
285
- result.customer.addresses[0].id.should =~ /\w+/
286
- result.customer.addresses[0].street_address.should == "1 E Main St"
287
- result.customer.addresses[0].extended_address.should == "Suite 3"
288
- result.customer.addresses[0].locality.should == "Chicago"
289
- result.customer.addresses[0].region.should == "Illinois"
290
- result.customer.addresses[0].postal_code.should == "60622"
291
- result.customer.addresses[0].country_name.should == "United States of America"
416
+ },
417
+ )
418
+ expect(result.success?).to eq(true)
419
+ expect(result.customer.first_name).to eq("Mike")
420
+ expect(result.customer.last_name).to eq("Jones")
421
+ expect(result.customer.credit_cards[0].bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
422
+ expect(result.customer.credit_cards[0].last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
423
+ expect(result.customer.credit_cards[0].expiration_date).to eq("05/2010")
424
+ expect(result.customer.credit_cards[0].billing_address.id).to eq(result.customer.addresses[0].id)
425
+ expect(result.customer.addresses[0].id).to match(/\w+/)
426
+ expect(result.customer.addresses[0].street_address).to eq("1 E Main St")
427
+ expect(result.customer.addresses[0].extended_address).to eq("Suite 3")
428
+ expect(result.customer.addresses[0].locality).to eq("Chicago")
429
+ expect(result.customer.addresses[0].region).to eq("Illinois")
430
+ expect(result.customer.addresses[0].postal_code).to eq("60622")
431
+ expect(result.customer.addresses[0].country_name).to eq("United States of America")
292
432
  end
293
433
 
294
434
  it "can use any country code" do
@@ -304,13 +444,13 @@ describe Braintree::Customer do
304
444
  :country_code_alpha3 => "COM",
305
445
  :country_code_numeric => "174"
306
446
  }
307
- }
447
+ },
308
448
  )
309
- result.success?.should == true
310
- result.customer.addresses[0].country_name.should == "Comoros"
311
- result.customer.addresses[0].country_code_alpha2.should == "KM"
312
- result.customer.addresses[0].country_code_alpha3.should == "COM"
313
- result.customer.addresses[0].country_code_numeric.should == "174"
449
+ expect(result.success?).to eq(true)
450
+ expect(result.customer.addresses[0].country_name).to eq("Comoros")
451
+ expect(result.customer.addresses[0].country_code_alpha2).to eq("KM")
452
+ expect(result.customer.addresses[0].country_code_alpha3).to eq("COM")
453
+ expect(result.customer.addresses[0].country_code_numeric).to eq("174")
314
454
  end
315
455
 
316
456
  it "stores custom fields when valid" do
@@ -319,20 +459,20 @@ describe Braintree::Customer do
319
459
  :last_name => "Gates",
320
460
  :custom_fields => {
321
461
  :store_me => "custom value"
322
- }
462
+ },
323
463
  )
324
- result.success?.should == true
325
- result.customer.custom_fields[:store_me].should == "custom value"
464
+ expect(result.success?).to eq(true)
465
+ expect(result.customer.custom_fields[:store_me]).to eq("custom value")
326
466
  end
327
467
 
328
468
  it "returns empty hash for custom fields when blank" do
329
469
  result = Braintree::Customer.create(
330
470
  :first_name => "Bill",
331
471
  :last_name => "Gates",
332
- :custom_fields => { :store_me => "" }
472
+ :custom_fields => {:store_me => ""},
333
473
  )
334
- result.success?.should == true
335
- result.customer.custom_fields.should == {}
474
+ expect(result.success?).to eq(true)
475
+ expect(result.customer.custom_fields).to eq({})
336
476
  end
337
477
 
338
478
  it "returns nested errors if credit card and/or billing address are invalid" do
@@ -343,12 +483,12 @@ describe Braintree::Customer do
343
483
  :billing_address => {
344
484
  :country_name => "invalid"
345
485
  }
346
- }
486
+ },
347
487
  )
348
- result.success?.should == false
349
- result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
350
- result.errors.for(:customer).for(:credit_card).on(:number)[0].message.should == "Credit card number is invalid."
351
- result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_name)[0].message.should == "Country name is not an accepted country."
488
+ expect(result.success?).to eq(false)
489
+ expect(result.errors.for(:customer).on(:email)[0].message).to eq("Email is an invalid format.")
490
+ expect(result.errors.for(:customer).for(:credit_card).on(:number)[0].message).to eq("Credit card number is invalid.")
491
+ expect(result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_name)[0].message).to eq("Country name is not an accepted country.")
352
492
  end
353
493
 
354
494
  it "returns errors if country codes are inconsistent" do
@@ -363,10 +503,10 @@ describe Braintree::Customer do
363
503
  :country_code_alpha2 => "US",
364
504
  :country_code_alpha3 => "COM",
365
505
  }
366
- }
506
+ },
367
507
  )
368
- result.success?.should == false
369
- result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:base).map {|e| e.code}.should include(Braintree::ErrorCodes::Address::InconsistentCountry)
508
+ expect(result.success?).to eq(false)
509
+ expect(result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:base).map { |e| e.code }).to include(Braintree::ErrorCodes::Address::InconsistentCountry)
370
510
  end
371
511
 
372
512
  it "returns an error if country code alpha2 is invalid" do
@@ -379,10 +519,10 @@ describe Braintree::Customer do
379
519
  :billing_address => {
380
520
  :country_code_alpha2 => "zz",
381
521
  }
382
- }
522
+ },
383
523
  )
384
- result.success?.should == false
385
- result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_alpha2).map {|e| e.code}.should include(Braintree::ErrorCodes::Address::CountryCodeAlpha2IsNotAccepted)
524
+ expect(result.success?).to eq(false)
525
+ expect(result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_alpha2).map { |e| e.code }).to include(Braintree::ErrorCodes::Address::CountryCodeAlpha2IsNotAccepted)
386
526
  end
387
527
 
388
528
  it "returns an error if country code alpha3 is invalid" do
@@ -395,10 +535,10 @@ describe Braintree::Customer do
395
535
  :billing_address => {
396
536
  :country_code_alpha3 => "zzz",
397
537
  }
398
- }
538
+ },
399
539
  )
400
- result.success?.should == false
401
- result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_alpha3).map {|e| e.code}.should include(Braintree::ErrorCodes::Address::CountryCodeAlpha3IsNotAccepted)
540
+ expect(result.success?).to eq(false)
541
+ expect(result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_alpha3).map { |e| e.code }).to include(Braintree::ErrorCodes::Address::CountryCodeAlpha3IsNotAccepted)
402
542
  end
403
543
 
404
544
  it "returns an error if country code numeric is invalid" do
@@ -411,10 +551,10 @@ describe Braintree::Customer do
411
551
  :billing_address => {
412
552
  :country_code_numeric => "zzz",
413
553
  }
414
- }
554
+ },
415
555
  )
416
- result.success?.should == false
417
- result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_numeric).map {|e| e.code}.should include(Braintree::ErrorCodes::Address::CountryCodeNumericIsNotAccepted)
556
+ expect(result.success?).to eq(false)
557
+ expect(result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_numeric).map { |e| e.code }).to include(Braintree::ErrorCodes::Address::CountryCodeNumericIsNotAccepted)
418
558
  end
419
559
 
420
560
  it "returns errors if custom_fields are not registered" do
@@ -423,41 +563,10 @@ describe Braintree::Customer do
423
563
  :last_name => "Kennedy",
424
564
  :custom_fields => {
425
565
  :spouse_name => "Jacqueline"
426
- }
566
+ },
427
567
  )
428
- result.success?.should == false
429
- result.errors.for(:customer).on(:custom_fields)[0].message.should == "Custom field is invalid: spouse_name."
430
- end
431
-
432
- describe "venmo_sdk" do
433
- it "can create a customer with a venmo sdk payment method code" do
434
- result = Braintree::Customer.create(
435
- :first_name => "Steve",
436
- :last_name => "Hamlin",
437
- :credit_card => {
438
- :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::VisaPaymentMethodCode
439
- }
440
- )
441
- result.success?.should == true
442
- result.customer.credit_cards.first.bin.should == "400934"
443
- result.customer.credit_cards.first.last_4.should == "1881"
444
- end
445
-
446
- it "can create a customer with a venmo sdk session" do
447
- result = Braintree::Customer.create(
448
- :first_name => "Steve",
449
- :last_name => "Hamlin",
450
- :credit_card => {
451
- :number => Braintree::Test::CreditCardNumbers::MasterCard,
452
- :expiration_date => "05/2010",
453
- :options => {
454
- :venmo_sdk_session => Braintree::Test::VenmoSDK::Session
455
- }
456
- }
457
- )
458
- result.success?.should == true
459
- result.customer.credit_cards.first.venmo_sdk?.should == false
460
- end
568
+ expect(result.success?).to eq(false)
569
+ expect(result.errors.for(:customer).on(:custom_fields)[0].message).to eq("Custom field is invalid: spouse_name.")
461
570
  end
462
571
 
463
572
  context "client API" do
@@ -468,33 +577,33 @@ describe Braintree::Customer do
468
577
  :expiration_month => "11",
469
578
  :expiration_year => "2099",
470
579
  },
471
- :share => true
580
+ :share => true,
472
581
  )
473
582
 
474
583
  result = Braintree::Customer.create(
475
584
  :credit_card => {
476
585
  :payment_method_nonce => nonce
477
- }
586
+ },
478
587
  )
479
588
 
480
- result.success?.should == true
481
- result.customer.credit_cards.first.bin.should == "411111"
482
- result.customer.credit_cards.first.last_4.should == "1111"
589
+ expect(result.success?).to eq(true)
590
+ expect(result.customer.credit_cards.first.bin).to eq("411111")
591
+ expect(result.customer.credit_cards.first.last_4).to eq("1111")
483
592
  end
484
593
  end
485
594
 
486
595
  it "can create a customer with an apple pay payment method" do
487
596
  result = Braintree::Customer.create(:payment_method_nonce => Braintree::Test::Nonce::ApplePayVisa)
488
597
 
489
- result.success?.should == true
490
- result.customer.payment_methods.should_not be_empty
491
- result.customer.payment_methods.first.token.should_not be_nil
598
+ expect(result.success?).to eq(true)
599
+ expect(result.customer.payment_methods).not_to be_empty
600
+ expect(result.customer.payment_methods.first.token).not_to be_nil
492
601
  end
493
602
 
494
603
  it "can create a customer with an unknown payment method" do
495
604
  result = Braintree::Customer.create(:payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable)
496
605
 
497
- result.success?.should == true
606
+ expect(result.success?).to eq(true)
498
607
  end
499
608
 
500
609
  context "verification_account_type" do
@@ -504,17 +613,17 @@ describe Braintree::Customer do
504
613
  :number => Braintree::Test::CreditCardNumbers::Hiper,
505
614
  :expiration_month => "11",
506
615
  :expiration_year => "2099",
507
- }
616
+ },
508
617
  )
509
618
  result = Braintree::Customer.create(
510
619
  :payment_method_nonce => nonce,
511
620
  :credit_card => {
512
621
  :options => {
513
622
  :verify_card => true,
514
- :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
623
+ :verification_merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
515
624
  :verification_account_type => "debit",
516
625
  }
517
- }
626
+ },
518
627
  )
519
628
 
520
629
  expect(result).to be_success
@@ -526,7 +635,7 @@ describe Braintree::Customer do
526
635
  :number => Braintree::Test::CreditCardNumbers::Hiper,
527
636
  :expiration_month => "11",
528
637
  :expiration_year => "2099",
529
- }
638
+ },
530
639
  )
531
640
  result = Braintree::Customer.create(
532
641
  :payment_method_nonce => nonce,
@@ -536,7 +645,7 @@ describe Braintree::Customer do
536
645
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
537
646
  :verification_account_type => "credit",
538
647
  }
539
- }
648
+ },
540
649
  )
541
650
 
542
651
  expect(result).to be_success
@@ -548,7 +657,7 @@ describe Braintree::Customer do
548
657
  :number => Braintree::Test::CreditCardNumbers::Hiper,
549
658
  :expiration_month => "11",
550
659
  :expiration_year => "2099",
551
- }
660
+ },
552
661
  )
553
662
  result = Braintree::Customer.create(
554
663
  :payment_method_nonce => nonce,
@@ -558,7 +667,7 @@ describe Braintree::Customer do
558
667
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
559
668
  :verification_account_type => "ach",
560
669
  }
561
- }
670
+ },
562
671
  )
563
672
 
564
673
  expect(result).to_not be_success
@@ -571,7 +680,7 @@ describe Braintree::Customer do
571
680
  :number => Braintree::Test::CreditCardNumbers::Visa,
572
681
  :expiration_month => "11",
573
682
  :expiration_year => "2099",
574
- }
683
+ },
575
684
  )
576
685
  result = Braintree::Customer.create(
577
686
  :payment_method_nonce => nonce,
@@ -580,7 +689,7 @@ describe Braintree::Customer do
580
689
  :verify_card => true,
581
690
  :verification_account_type => "credit",
582
691
  }
583
- }
692
+ },
584
693
  )
585
694
 
586
695
  expect(result).to_not be_success
@@ -593,16 +702,16 @@ describe Braintree::Customer do
593
702
  it "returns the customer if successful" do
594
703
  customer = Braintree::Customer.create!(
595
704
  :first_name => "Jim",
596
- :last_name => "Smith"
705
+ :last_name => "Smith",
597
706
  )
598
- customer.id.should =~ /\d+/
599
- customer.first_name.should == "Jim"
600
- customer.last_name.should == "Smith"
707
+ expect(customer.id).to match(/\d+/)
708
+ expect(customer.first_name).to eq("Jim")
709
+ expect(customer.last_name).to eq("Smith")
601
710
  end
602
711
 
603
712
  it "can create without any attributes" do
604
713
  customer = Braintree::Customer.create!
605
- customer.id.should =~ /\d+/
714
+ expect(customer.id).to match(/\d+/)
606
715
  end
607
716
 
608
717
  it "raises an exception if not successful" do
@@ -618,17 +727,17 @@ describe Braintree::Customer do
618
727
  :credit_card => {
619
728
  :number => Braintree::Test::CreditCardNumbers::Visa,
620
729
  :expiration_date => "05/2010"
621
- }
730
+ },
622
731
  )
623
732
  result = Braintree::Customer.credit(customer.id, :amount => "100.00")
624
- result.success?.should == true
625
- result.transaction.amount.should == BigDecimal("100.00")
626
- result.transaction.type.should == "credit"
627
- result.transaction.customer_details.id.should == customer.id
628
- result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
629
- result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
630
- result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
631
- result.transaction.credit_card_details.expiration_date.should == "05/2010"
733
+ expect(result.success?).to eq(true)
734
+ expect(result.transaction.amount).to eq(BigDecimal("100.00"))
735
+ expect(result.transaction.type).to eq("credit")
736
+ expect(result.transaction.customer_details.id).to eq(customer.id)
737
+ expect(result.transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
738
+ expect(result.transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
739
+ expect(result.transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
740
+ expect(result.transaction.credit_card_details.expiration_date).to eq("05/2010")
632
741
  end
633
742
  end
634
743
 
@@ -638,16 +747,16 @@ describe Braintree::Customer do
638
747
  :credit_card => {
639
748
  :number => Braintree::Test::CreditCardNumbers::Visa,
640
749
  :expiration_date => "05/2010"
641
- }
750
+ },
642
751
  )
643
752
  transaction = Braintree::Customer.credit!(customer.id, :amount => "100.00")
644
- transaction.amount.should == BigDecimal("100.00")
645
- transaction.type.should == "credit"
646
- transaction.customer_details.id.should == customer.id
647
- transaction.credit_card_details.token.should == customer.credit_cards[0].token
648
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
649
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
650
- transaction.credit_card_details.expiration_date.should == "05/2010"
753
+ expect(transaction.amount).to eq(BigDecimal("100.00"))
754
+ expect(transaction.type).to eq("credit")
755
+ expect(transaction.customer_details.id).to eq(customer.id)
756
+ expect(transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
757
+ expect(transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
758
+ expect(transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
759
+ expect(transaction.credit_card_details.expiration_date).to eq("05/2010")
651
760
  end
652
761
  end
653
762
 
@@ -657,17 +766,17 @@ describe Braintree::Customer do
657
766
  :credit_card => {
658
767
  :number => Braintree::Test::CreditCardNumbers::Visa,
659
768
  :expiration_date => "05/2010"
660
- }
769
+ },
661
770
  )
662
771
  result = Braintree::Customer.sale(customer.id, :amount => "100.00")
663
- result.success?.should == true
664
- result.transaction.amount.should == BigDecimal("100.00")
665
- result.transaction.type.should == "sale"
666
- result.transaction.customer_details.id.should == customer.id
667
- result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
668
- result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
669
- result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
670
- result.transaction.credit_card_details.expiration_date.should == "05/2010"
772
+ expect(result.success?).to eq(true)
773
+ expect(result.transaction.amount).to eq(BigDecimal("100.00"))
774
+ expect(result.transaction.type).to eq("sale")
775
+ expect(result.transaction.customer_details.id).to eq(customer.id)
776
+ expect(result.transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
777
+ expect(result.transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
778
+ expect(result.transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
779
+ expect(result.transaction.credit_card_details.expiration_date).to eq("05/2010")
671
780
  end
672
781
  end
673
782
 
@@ -677,16 +786,16 @@ describe Braintree::Customer do
677
786
  :credit_card => {
678
787
  :number => Braintree::Test::CreditCardNumbers::Visa,
679
788
  :expiration_date => "05/2010"
680
- }
789
+ },
681
790
  )
682
791
  transaction = Braintree::Customer.sale!(customer.id, :amount => "100.00")
683
- transaction.amount.should == BigDecimal("100.00")
684
- transaction.type.should == "sale"
685
- transaction.customer_details.id.should == customer.id
686
- transaction.credit_card_details.token.should == customer.credit_cards[0].token
687
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
688
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
689
- transaction.credit_card_details.expiration_date.should == "05/2010"
792
+ expect(transaction.amount).to eq(BigDecimal("100.00"))
793
+ expect(transaction.type).to eq("sale")
794
+ expect(transaction.customer_details.id).to eq(customer.id)
795
+ expect(transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
796
+ expect(transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
797
+ expect(transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
798
+ expect(transaction.credit_card_details.expiration_date).to eq("05/2010")
690
799
  end
691
800
  end
692
801
 
@@ -696,67 +805,11 @@ describe Braintree::Customer do
696
805
  :credit_card => {
697
806
  :number => Braintree::Test::CreditCardNumbers::Visa,
698
807
  :expiration_date => "05/2010"
699
- }
808
+ },
700
809
  )
701
- transaction = customer.sale!(:amount => "100.00")
810
+ transaction = Braintree::Customer.sale!(customer.id, :amount => "100.00")
702
811
  collection = Braintree::Customer.transactions(customer.id)
703
- collection.first.should == transaction
704
- end
705
- end
706
-
707
-
708
- describe "sale" do
709
- it "creates a sale transaction using the customer, returning a result object" do
710
- customer = Braintree::Customer.create!(
711
- :credit_card => {
712
- :number => Braintree::Test::CreditCardNumbers::Visa,
713
- :expiration_date => "05/2010"
714
- }
715
- )
716
- result = customer.sale(
717
- :amount => "100.00"
718
- )
719
- result.success?.should == true
720
- result.transaction.amount.should == BigDecimal("100.00")
721
- result.transaction.type.should == "sale"
722
- result.transaction.customer_details.id.should == customer.id
723
- result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
724
- result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
725
- result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
726
- result.transaction.credit_card_details.expiration_date.should == "05/2010"
727
- end
728
- end
729
-
730
- describe "sale!" do
731
- it "returns the created sale tranaction if valid" do
732
- customer = Braintree::Customer.create!(
733
- :credit_card => {
734
- :number => Braintree::Test::CreditCardNumbers::Visa,
735
- :expiration_date => "05/2010"
736
- }
737
- )
738
- transaction = customer.sale!(:amount => "100.00")
739
- transaction.amount.should == BigDecimal("100.00")
740
- transaction.type.should == "sale"
741
- transaction.customer_details.id.should == customer.id
742
- transaction.credit_card_details.token.should == customer.credit_cards[0].token
743
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
744
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
745
- transaction.credit_card_details.expiration_date.should == "05/2010"
746
- end
747
- end
748
-
749
- describe "transactions" do
750
- it "finds transactions for the customer" do
751
- customer = Braintree::Customer.create!(
752
- :credit_card => {
753
- :number => Braintree::Test::CreditCardNumbers::Visa,
754
- :expiration_date => "05/2010"
755
- }
756
- )
757
- transaction = customer.sale!(:amount => "100.00")
758
- collection = customer.transactions
759
- collection.first.should == transaction
812
+ expect(collection.first).to eq(transaction)
760
813
  end
761
814
  end
762
815
 
@@ -766,19 +819,19 @@ describe Braintree::Customer do
766
819
  :credit_card => {
767
820
  :number => Braintree::Test::CreditCardNumbers::Visa,
768
821
  :expiration_date => "05/2010"
769
- }
822
+ },
770
823
  )
771
824
  result = customer.credit(
772
- :amount => "100.00"
825
+ :amount => "100.00",
773
826
  )
774
- result.success?.should == true
775
- result.transaction.amount.should == BigDecimal("100.00")
776
- result.transaction.type.should == "credit"
777
- result.transaction.customer_details.id.should == customer.id
778
- result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
779
- result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
780
- result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
781
- result.transaction.credit_card_details.expiration_date.should == "05/2010"
827
+ expect(result.success?).to eq(true)
828
+ expect(result.transaction.amount).to eq(BigDecimal("100.00"))
829
+ expect(result.transaction.type).to eq("credit")
830
+ expect(result.transaction.customer_details.id).to eq(customer.id)
831
+ expect(result.transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
832
+ expect(result.transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
833
+ expect(result.transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
834
+ expect(result.transaction.credit_card_details.expiration_date).to eq("05/2010")
782
835
  end
783
836
  end
784
837
 
@@ -788,77 +841,16 @@ describe Braintree::Customer do
788
841
  :credit_card => {
789
842
  :number => Braintree::Test::CreditCardNumbers::Visa,
790
843
  :expiration_date => "05/2010"
791
- }
844
+ },
792
845
  )
793
846
  transaction = customer.credit!(:amount => "100.00")
794
- transaction.amount.should == BigDecimal("100.00")
795
- transaction.type.should == "credit"
796
- transaction.customer_details.id.should == customer.id
797
- transaction.credit_card_details.token.should == customer.credit_cards[0].token
798
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
799
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
800
- transaction.credit_card_details.expiration_date.should == "05/2010"
801
- end
802
- end
803
-
804
- describe "create_from_transparent_redirect" do
805
- it "returns a successful result if successful" do
806
- params = {
807
- :customer => {
808
- :first_name => "John",
809
- :last_name => "Doe",
810
- :company => "Doe Co",
811
- :email => "john@doe.com",
812
- :phone => "312.555.2323",
813
- :fax => "614.555.5656",
814
- :website => "www.johndoe.com"
815
- }
816
- }
817
-
818
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge({}))
819
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Customer.create_customer_url)
820
- result = Braintree::Customer.create_from_transparent_redirect(query_string_response)
821
-
822
- result.success?.should == true
823
- customer = result.customer
824
- customer.first_name.should == "John"
825
- customer.last_name.should == "Doe"
826
- customer.company.should == "Doe Co"
827
- customer.email.should == "john@doe.com"
828
- customer.phone.should == "312.555.2323"
829
- customer.fax.should == "614.555.5656"
830
- customer.website.should == "www.johndoe.com"
831
- end
832
-
833
- it "can pass any attribute through tr_data" do
834
- customer_id = "customer_#{rand(1_000_000)}"
835
- tr_data_params = {
836
- :customer => {
837
- :id => customer_id,
838
- :first_name => "John",
839
- :last_name => "Doe",
840
- :company => "Doe Co",
841
- :email => "john@doe.com",
842
- :phone => "312.555.2323",
843
- :fax => "614.555.5656",
844
- :website => "www.johndoe.com"
845
- }
846
- }
847
-
848
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
849
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.create_customer_url)
850
- result = Braintree::Customer.create_from_transparent_redirect(query_string_response)
851
-
852
- result.success?.should == true
853
- customer = result.customer
854
- customer.id.should == customer_id
855
- customer.first_name.should == "John"
856
- customer.last_name.should == "Doe"
857
- customer.company.should == "Doe Co"
858
- customer.email.should == "john@doe.com"
859
- customer.phone.should == "312.555.2323"
860
- customer.fax.should == "614.555.5656"
861
- customer.website.should == "www.johndoe.com"
847
+ expect(transaction.amount).to eq(BigDecimal("100.00"))
848
+ expect(transaction.type).to eq("credit")
849
+ expect(transaction.customer_details.id).to eq(customer.id)
850
+ expect(transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
851
+ expect(transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
852
+ expect(transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
853
+ expect(transaction.credit_card_details.expiration_date).to eq("05/2010")
862
854
  end
863
855
  end
864
856
 
@@ -866,12 +858,12 @@ describe Braintree::Customer do
866
858
  it "deletes the customer" do
867
859
  result = Braintree::Customer.create(
868
860
  :first_name => "Joe",
869
- :last_name => "Cool"
861
+ :last_name => "Cool",
870
862
  )
871
- result.success?.should == true
863
+ expect(result.success?).to eq(true)
872
864
 
873
865
  customer = result.customer
874
- customer.delete.success?.should == true
866
+ expect(customer.delete.success?).to eq(true)
875
867
  expect do
876
868
  Braintree::Customer.find(customer.id)
877
869
  end.to raise_error(Braintree::NotFoundError)
@@ -883,14 +875,15 @@ describe Braintree::Customer do
883
875
  it "finds the customer with the given id" do
884
876
  result = Braintree::Customer.create(
885
877
  :first_name => "Joe",
886
- :last_name => "Cool"
878
+ :last_name => "Cool",
887
879
  )
888
- result.success?.should == true
880
+ expect(result.success?).to eq(true)
889
881
 
890
882
  customer = Braintree::Customer.find(result.customer.id)
891
- customer.id.should == result.customer.id
892
- customer.first_name.should == "Joe"
893
- customer.last_name.should == "Cool"
883
+ expect(customer.id).to eq(result.customer.id)
884
+ expect(customer.graphql_id).not_to be_nil
885
+ expect(customer.first_name).to eq("Joe")
886
+ expect(customer.last_name).to eq("Cool")
894
887
  end
895
888
 
896
889
  it "returns associated subscriptions" do
@@ -898,20 +891,20 @@ describe Braintree::Customer do
898
891
  credit_card = Braintree::CreditCard.create(
899
892
  :customer_id => customer.id,
900
893
  :number => Braintree::Test::CreditCardNumbers::Visa,
901
- :expiration_date => "05/2012"
894
+ :expiration_date => "05/2012",
902
895
  ).credit_card
903
896
 
904
897
  subscription = Braintree::Subscription.create(
905
898
  :payment_method_token => credit_card.token,
906
899
  :plan_id => "integration_trialless_plan",
907
- :price => "1.00"
900
+ :price => "1.00",
908
901
  ).subscription
909
902
 
910
903
  found_customer = Braintree::Customer.find(customer.id)
911
- found_customer.credit_cards.first.subscriptions.first.id.should == subscription.id
912
- found_customer.credit_cards.first.subscriptions.first.plan_id.should == "integration_trialless_plan"
913
- found_customer.credit_cards.first.subscriptions.first.payment_method_token.should == credit_card.token
914
- found_customer.credit_cards.first.subscriptions.first.price.should == BigDecimal("1.00")
904
+ expect(found_customer.credit_cards.first.subscriptions.first.id).to eq(subscription.id)
905
+ expect(found_customer.credit_cards.first.subscriptions.first.plan_id).to eq("integration_trialless_plan")
906
+ expect(found_customer.credit_cards.first.subscriptions.first.payment_method_token).to eq(credit_card.token)
907
+ expect(found_customer.credit_cards.first.subscriptions.first.price).to eq(BigDecimal("1.00"))
915
908
  end
916
909
 
917
910
  context "when given an association filter id" do
@@ -919,7 +912,7 @@ describe Braintree::Customer do
919
912
  customer = Braintree::Customer.create(
920
913
  :custom_fields => {
921
914
  :store_me => "custom value"
922
- }
915
+ },
923
916
  ).customer
924
917
  credit_card = Braintree::CreditCard.create(
925
918
  :customer_id => customer.id,
@@ -931,29 +924,29 @@ describe Braintree::Customer do
931
924
  :region => "Illinois",
932
925
  :postal_code => "60622",
933
926
  :country_name => "United States of America"
934
- }
927
+ },
935
928
  ).credit_card
936
929
 
937
- subscription = Braintree::Subscription.create(
930
+ Braintree::Subscription.create(
938
931
  :payment_method_token => credit_card.token,
939
932
  :plan_id => "integration_trialless_plan",
940
- :price => "1.00"
941
- ).subscription
933
+ :price => "1.00",
934
+ )
942
935
 
943
936
  found_customer = Braintree::Customer.find(customer.id, {
944
937
  :association_filter_id => "customernoassociations"
945
938
  })
946
- found_customer.credit_cards.length.should == 0
947
- found_customer.payment_methods.length.should == 0
948
- found_customer.addresses.length.should == 0
949
- found_customer.custom_fields.should == {}
939
+ expect(found_customer.credit_cards.length).to eq(0)
940
+ expect(found_customer.payment_methods.length).to eq(0)
941
+ expect(found_customer.addresses.length).to eq(0)
942
+ expect(found_customer.custom_fields).to eq({})
950
943
  end
951
944
 
952
945
  it "filters out nested filterable associations" do
953
946
  customer = Braintree::Customer.create(
954
947
  :custom_fields => {
955
948
  :store_me => "custom value"
956
- }
949
+ },
957
950
  ).customer
958
951
  credit_card = Braintree::CreditCard.create(
959
952
  :customer_id => customer.id,
@@ -965,131 +958,145 @@ describe Braintree::Customer do
965
958
  :region => "Illinois",
966
959
  :postal_code => "60622",
967
960
  :country_name => "United States of America"
968
- }
961
+ },
969
962
  ).credit_card
970
963
 
971
- subscription = Braintree::Subscription.create(
964
+ Braintree::Subscription.create(
972
965
  :payment_method_token => credit_card.token,
973
966
  :plan_id => "integration_trialless_plan",
974
- :price => "1.00"
975
- ).subscription
967
+ :price => "1.00",
968
+ )
976
969
 
977
970
  found_customer = Braintree::Customer.find(customer.id, {
978
971
  :association_filter_id => "customertoplevelassociations"
979
972
  })
980
973
 
981
- found_customer.credit_cards.length.should == 1
982
- found_customer.credit_cards.first.subscriptions.length.should == 0
983
- found_customer.payment_methods.length.should == 1
984
- found_customer.payment_methods.first.subscriptions.length.should == 0
985
- found_customer.addresses.length.should == 1
986
- found_customer.custom_fields.length.should == 1
974
+ expect(found_customer.credit_cards.length).to eq(1)
975
+ expect(found_customer.credit_cards.first.subscriptions.length).to eq(0)
976
+ expect(found_customer.payment_methods.length).to eq(1)
977
+ expect(found_customer.payment_methods.first.subscriptions.length).to eq(0)
978
+ expect(found_customer.addresses.length).to eq(1)
979
+ expect(found_customer.custom_fields.length).to eq(1)
987
980
  end
988
981
  end
989
982
 
990
983
  it "returns associated ApplePayCards" do
991
984
  result = Braintree::Customer.create(
992
- :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx
985
+ :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
993
986
  )
994
- result.success?.should == true
987
+ expect(result.success?).to eq(true)
995
988
 
996
989
  found_customer = Braintree::Customer.find(result.customer.id)
997
- found_customer.apple_pay_cards.should_not be_nil
990
+ expect(found_customer.apple_pay_cards).not_to be_nil
998
991
  apple_pay_card = found_customer.apple_pay_cards.first
999
- apple_pay_card.should be_a Braintree::ApplePayCard
1000
- apple_pay_card.token.should_not be_nil
1001
- apple_pay_card.expiration_year.should_not be_nil
1002
- apple_pay_card.payment_instrument_name.should == "AmEx 41002"
1003
- end
1004
-
1005
- it "returns associated android pay proxy cards" do
1006
- result = Braintree::Customer.create(
1007
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover
1008
- )
1009
- result.success?.should == true
1010
-
1011
- found_customer = Braintree::Customer.find(result.customer.id)
1012
- found_customer.android_pay_cards.size.should == 1
1013
- found_customer.payment_methods.size.should == 1
1014
- android_pay_card = found_customer.android_pay_cards.first
1015
- android_pay_card.should be_a Braintree::AndroidPayCard
1016
- android_pay_card.token.should_not be_nil
1017
- android_pay_card.expiration_year.should_not be_nil
1018
- end
1019
-
1020
- it "returns associated android pay network tokens" do
992
+ expect(apple_pay_card).to be_a Braintree::ApplePayCard
993
+ expect(apple_pay_card.token).not_to be_nil
994
+ expect(apple_pay_card.expiration_year).not_to be_nil
995
+ expect(apple_pay_card.payment_instrument_name).to eq("AmEx 41002")
996
+ expect(apple_pay_card.commercial).not_to be_nil
997
+ expect(apple_pay_card.country_of_issuance).not_to be_nil
998
+ expect(apple_pay_card.debit).not_to be_nil
999
+ expect(apple_pay_card.durbin_regulated).not_to be_nil
1000
+ expect(apple_pay_card.healthcare).not_to be_nil
1001
+ expect(apple_pay_card.issuing_bank).not_to be_nil
1002
+ expect(apple_pay_card.payroll).not_to be_nil
1003
+ expect(apple_pay_card.prepaid).not_to be_nil
1004
+ expect(apple_pay_card.product_id).not_to be_nil
1005
+ end
1006
+
1007
+ it "returns associated google pay proxy cards" do
1021
1008
  result = Braintree::Customer.create(
1022
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayMasterCard
1009
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
1023
1010
  )
1024
- result.success?.should == true
1011
+ expect(result.success?).to eq(true)
1025
1012
 
1026
1013
  found_customer = Braintree::Customer.find(result.customer.id)
1027
- found_customer.android_pay_cards.size.should == 1
1028
- found_customer.payment_methods.size.should == 1
1029
- android_pay_card = found_customer.android_pay_cards.first
1030
- android_pay_card.should be_a Braintree::AndroidPayCard
1031
- android_pay_card.token.should_not be_nil
1032
- android_pay_card.expiration_year.should_not be_nil
1033
- end
1034
-
1035
- it "returns associated amex express checkout cards" do
1014
+ expect(found_customer.google_pay_cards.size).to eq(1)
1015
+ expect(found_customer.payment_methods.size).to eq(1)
1016
+ google_pay_card = found_customer.google_pay_cards.first
1017
+ expect(google_pay_card).to be_a Braintree::GooglePayCard
1018
+ expect(google_pay_card.token).not_to be_nil
1019
+ expect(google_pay_card.expiration_year).not_to be_nil
1020
+ expect(google_pay_card.is_network_tokenized?).to eq(false)
1021
+ expect(google_pay_card.commercial).not_to be_nil
1022
+ expect(google_pay_card.country_of_issuance).not_to be_nil
1023
+ expect(google_pay_card.debit).not_to be_nil
1024
+ expect(google_pay_card.durbin_regulated).not_to be_nil
1025
+ expect(google_pay_card.healthcare).not_to be_nil
1026
+ expect(google_pay_card.issuing_bank).not_to be_nil
1027
+ expect(google_pay_card.payroll).not_to be_nil
1028
+ expect(google_pay_card.prepaid).not_to be_nil
1029
+ expect(google_pay_card.product_id).not_to be_nil
1030
+ end
1031
+
1032
+ it "returns associated google pay network tokens" do
1036
1033
  result = Braintree::Customer.create(
1037
- :payment_method_nonce => Braintree::Test::Nonce::AmexExpressCheckout
1034
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
1038
1035
  )
1039
- result.success?.should == true
1036
+ expect(result.success?).to eq(true)
1040
1037
 
1041
1038
  found_customer = Braintree::Customer.find(result.customer.id)
1042
- found_customer.amex_express_checkout_cards.size.should == 1
1043
- found_customer.payment_methods.size.should == 1
1044
- amex_express_checkout_card = found_customer.amex_express_checkout_cards.first
1045
- amex_express_checkout_card.should be_a Braintree::AmexExpressCheckoutCard
1046
- amex_express_checkout_card.token.should_not be_nil
1047
- amex_express_checkout_card.expiration_year.should_not be_nil
1039
+ expect(found_customer.google_pay_cards.size).to eq(1)
1040
+ expect(found_customer.payment_methods.size).to eq(1)
1041
+ google_pay_card = found_customer.google_pay_cards.first
1042
+ expect(google_pay_card).to be_a Braintree::GooglePayCard
1043
+ expect(google_pay_card.token).not_to be_nil
1044
+ expect(google_pay_card.expiration_year).not_to be_nil
1045
+ expect(google_pay_card.is_network_tokenized?).to eq(true)
1046
+ expect(google_pay_card.commercial).not_to be_nil
1047
+ expect(google_pay_card.country_of_issuance).not_to be_nil
1048
+ expect(google_pay_card.debit).not_to be_nil
1049
+ expect(google_pay_card.durbin_regulated).not_to be_nil
1050
+ expect(google_pay_card.healthcare).not_to be_nil
1051
+ expect(google_pay_card.issuing_bank).not_to be_nil
1052
+ expect(google_pay_card.payroll).not_to be_nil
1053
+ expect(google_pay_card.prepaid).not_to be_nil
1054
+ expect(google_pay_card.product_id).not_to be_nil
1048
1055
  end
1049
1056
 
1050
1057
  it "returns associated venmo accounts" do
1051
1058
  result = Braintree::Customer.create(
1052
- :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount
1059
+ :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
1053
1060
  )
1054
- result.success?.should == true
1061
+ expect(result.success?).to eq(true)
1055
1062
 
1056
1063
  found_customer = Braintree::Customer.find(result.customer.id)
1057
- found_customer.venmo_accounts.size.should == 1
1058
- found_customer.payment_methods.size.should == 1
1064
+ expect(found_customer.venmo_accounts.size).to eq(1)
1065
+ expect(found_customer.payment_methods.size).to eq(1)
1059
1066
  venmo_account = found_customer.venmo_accounts.first
1060
- venmo_account.should be_a Braintree::VenmoAccount
1061
- venmo_account.token.should_not be_nil
1062
- venmo_account.username.should_not be_nil
1067
+ expect(venmo_account).to be_a Braintree::VenmoAccount
1068
+ expect(venmo_account.token).not_to be_nil
1069
+ expect(venmo_account.username).not_to be_nil
1063
1070
  end
1064
1071
 
1065
- it "returns associated us bank accounts" do
1072
+ xit "returns associated us bank accounts" do
1066
1073
  result = Braintree::Customer.create(
1067
1074
  :payment_method_nonce => generate_non_plaid_us_bank_account_nonce,
1068
1075
  :credit_card => {
1069
1076
  :options => {
1070
1077
  :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
1071
1078
  }
1072
- }
1079
+ },
1073
1080
  )
1074
- result.should be_success
1081
+ expect(result).to be_success
1075
1082
 
1076
1083
  found_customer = Braintree::Customer.find(result.customer.id)
1077
- found_customer.us_bank_accounts.size.should == 1
1078
- found_customer.payment_methods.size.should == 1
1084
+ expect(found_customer.us_bank_accounts.size).to eq(1)
1085
+ expect(found_customer.payment_methods.size).to eq(1)
1079
1086
 
1080
1087
  us_bank_account = found_customer.us_bank_accounts.first
1081
- us_bank_account.should be_a(Braintree::UsBankAccount)
1082
- us_bank_account.routing_number.should == "021000021"
1083
- us_bank_account.last_4.should == "0000"
1084
- us_bank_account.account_type.should == "checking"
1085
- us_bank_account.account_holder_name.should == "John Doe"
1086
- us_bank_account.bank_name.should =~ /CHASE/
1088
+ expect(us_bank_account).to be_a(Braintree::UsBankAccount)
1089
+ expect(us_bank_account.routing_number).to eq("021000021")
1090
+ expect(us_bank_account.last_4).to eq("0000")
1091
+ expect(us_bank_account.account_type).to eq("checking")
1092
+ expect(us_bank_account.account_holder_name).to eq("John Doe")
1093
+ expect(us_bank_account.bank_name).to match(/CHASE/)
1087
1094
  end
1088
1095
 
1089
1096
  it "works for a blank customer" do
1090
1097
  created_customer = Braintree::Customer.create!
1091
1098
  found_customer = Braintree::Customer.find(created_customer.id)
1092
- found_customer.id.should == created_customer.id
1099
+ expect(found_customer.id).to eq(created_customer.id)
1093
1100
  end
1094
1101
 
1095
1102
  it "raises an ArgumentError if customer_id is not a string" do
@@ -1112,24 +1119,95 @@ describe Braintree::Customer do
1112
1119
  end
1113
1120
 
1114
1121
  describe "self.update" do
1122
+ it "updates the credit card with three_d_secure pass thru params" do
1123
+ customer = Braintree::Customer.create!(
1124
+ :first_name => "Joe",
1125
+ :last_name => "Cool",
1126
+ )
1127
+ result = Braintree::Customer.update(
1128
+ customer.id,
1129
+ :first_name => "Mr. Joe",
1130
+ :last_name => "Super Cool",
1131
+ :custom_fields => {
1132
+ :store_me => "a value"
1133
+ },
1134
+ :credit_card => {
1135
+ :number => 4111111111111111,
1136
+ :expiration_date => "05/2060",
1137
+ :three_d_secure_pass_thru => {
1138
+ :eci_flag => "05",
1139
+ :cavv => "some_cavv",
1140
+ :xid => "some_xid",
1141
+ :three_d_secure_version => "1.0.2",
1142
+ :authentication_response => "Y",
1143
+ :directory_response => "Y",
1144
+ :cavv_algorithm => "2",
1145
+ :ds_transaction_id => "some_ds_transaction_id",
1146
+ },
1147
+ :options => {:verify_card => true},
1148
+ },
1149
+ )
1150
+ expect(result.success?).to eq(true)
1151
+ expect(result.customer.id).to eq(customer.id)
1152
+ expect(result.customer.first_name).to eq("Mr. Joe")
1153
+ expect(result.customer.last_name).to eq("Super Cool")
1154
+ expect(result.customer.custom_fields[:store_me]).to eq("a value")
1155
+ end
1156
+
1157
+ it "validates the presence of three_d_secure_version while passing three_d_secure_pass_thru in update" do
1158
+ customer = Braintree::Customer.create!(
1159
+ :first_name => "Joe",
1160
+ :last_name => "Cool",
1161
+ )
1162
+ result = Braintree::Customer.update(
1163
+ customer.id,
1164
+ :first_name => "Mr. Joe",
1165
+ :last_name => "Super Cool",
1166
+ :custom_fields => {
1167
+ :store_me => "a value"
1168
+ },
1169
+ :credit_card => {
1170
+ :number => 4111111111111111,
1171
+ :expiration_date => "05/2060",
1172
+ :three_d_secure_pass_thru => {
1173
+ :eci_flag => "05",
1174
+ :cavv => "some_cavv",
1175
+ :xid => "some_xid",
1176
+ :authentication_response => "Y",
1177
+ :directory_response => "Y",
1178
+ :cavv_algorithm => "2",
1179
+ :ds_transaction_id => "some_ds_transaction_id",
1180
+ },
1181
+ options: {:verify_card => true}
1182
+ },
1183
+ )
1184
+ expect(result).to_not be_success
1185
+ error = result.errors.for(:verification).first
1186
+ expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsRequired)
1187
+ expect(error.message).to eq("ThreeDSecureVersion is required.")
1188
+ end
1189
+
1115
1190
  it "updates the customer with the given id if successful" do
1116
1191
  customer = Braintree::Customer.create!(
1117
1192
  :first_name => "Joe",
1118
- :last_name => "Cool"
1193
+ :last_name => "Cool",
1119
1194
  )
1120
1195
  result = Braintree::Customer.update(
1121
1196
  customer.id,
1122
1197
  :first_name => "Mr. Joe",
1123
1198
  :last_name => "Super Cool",
1199
+ :international_phone => {:country_code => "1", :national_number => "3121234567"},
1124
1200
  :custom_fields => {
1125
1201
  :store_me => "a value"
1126
- }
1202
+ },
1127
1203
  )
1128
- result.success?.should == true
1129
- result.customer.id.should == customer.id
1130
- result.customer.first_name.should == "Mr. Joe"
1131
- result.customer.last_name.should == "Super Cool"
1132
- result.customer.custom_fields[:store_me].should == "a value"
1204
+ expect(result.success?).to eq(true)
1205
+ expect(result.customer.id).to eq(customer.id)
1206
+ expect(result.customer.first_name).to eq("Mr. Joe")
1207
+ expect(result.customer.last_name).to eq("Super Cool")
1208
+ expect(result.customer.international_phone[:country_code]).to eq("1")
1209
+ expect(result.customer.international_phone[:national_number]).to eq("3121234567")
1210
+ expect(result.customer.custom_fields[:store_me]).to eq("a value")
1133
1211
  end
1134
1212
 
1135
1213
  it "does not update customer with duplicate payment method if fail_on_payment_method option set" do
@@ -1137,7 +1215,7 @@ describe Braintree::Customer do
1137
1215
  :credit_card => {
1138
1216
  :number => 4111111111111111,
1139
1217
  :expiration_date => "05/2010",
1140
- }
1218
+ },
1141
1219
  )
1142
1220
  result = Braintree::Customer.update(
1143
1221
  customer.id,
@@ -1147,68 +1225,89 @@ describe Braintree::Customer do
1147
1225
  :options=> {
1148
1226
  :fail_on_duplicate_payment_method => true
1149
1227
  }
1150
- }
1228
+ },
1151
1229
  )
1152
- result.success?.should == false
1153
- result.errors.for(:customer).for(:credit_card).on(:number)[0].message.should == "Duplicate card exists in the vault."
1230
+ expect(result.success?).to eq(false)
1231
+ expect(result.errors.for(:customer).for(:credit_card).on(:number)[0].message).to eq("Duplicate card exists in the vault.")
1232
+ end
1233
+
1234
+ it "does not update customer with duplicate payment method if fail_on_payment_method_for_customer option set" do
1235
+ customer = Braintree::Customer.create!(
1236
+ :credit_card => {
1237
+ :number => 4111111111111111,
1238
+ :expiration_date => "05/2010",
1239
+ },
1240
+ )
1241
+ result = Braintree::Customer.update(
1242
+ customer.id,
1243
+ :credit_card => {
1244
+ :number => 4111111111111111,
1245
+ :expiration_date => "05/2010",
1246
+ :options=> {
1247
+ :fail_on_duplicate_payment_method_for_customer => true
1248
+ }
1249
+ },
1250
+ )
1251
+ expect(result.success?).to eq(false)
1252
+ expect(result.errors.for(:customer).for(:credit_card).on(:number)[0].message).to eq("Duplicate card exists in the vault for the customer.")
1154
1253
  end
1155
1254
 
1156
1255
  it "updates the default payment method" do
1157
1256
  customer = Braintree::Customer.create!(
1158
1257
  :first_name => "Joe",
1159
- :last_name => "Brown"
1258
+ :last_name => "Brown",
1160
1259
  )
1161
1260
 
1162
1261
  token1 = random_payment_method_token
1163
1262
 
1164
- payment_method1 = Braintree::PaymentMethod.create(
1263
+ Braintree::PaymentMethod.create(
1165
1264
  :customer_id => customer.id,
1166
1265
  :payment_method_nonce => Braintree::Test::Nonce::TransactableVisa,
1167
- :token => token1
1266
+ :token => token1,
1168
1267
  )
1169
1268
 
1170
1269
  payment_method1 = Braintree::PaymentMethod.find(token1)
1171
- payment_method1.should be_default
1270
+ expect(payment_method1).to be_default
1172
1271
 
1173
1272
  token2 = random_payment_method_token
1174
1273
 
1175
- payment_method2 = Braintree::PaymentMethod.create(
1274
+ Braintree::PaymentMethod.create(
1176
1275
  :customer_id => customer.id,
1177
1276
  :payment_method_nonce => Braintree::Test::Nonce::TransactableMasterCard,
1178
- :token => token2
1277
+ :token => token2,
1179
1278
  )
1180
1279
 
1181
1280
  Braintree::Customer.update(customer.id,
1182
- :default_payment_method_token => token2
1281
+ :default_payment_method_token => token2,
1183
1282
  )
1184
1283
 
1185
1284
  payment_method2 = Braintree::PaymentMethod.find(token2)
1186
- payment_method2.should be_default
1285
+ expect(payment_method2).to be_default
1187
1286
  end
1188
1287
 
1189
1288
  it "updates the default payment method in the options" do
1190
1289
  customer = Braintree::Customer.create!(
1191
1290
  :first_name => "Joe",
1192
- :last_name => "Brown"
1291
+ :last_name => "Brown",
1193
1292
  )
1194
1293
 
1195
1294
  token1 = random_payment_method_token
1196
1295
 
1197
- payment_method1 = Braintree::PaymentMethod.create(
1296
+ Braintree::PaymentMethod.create(
1198
1297
  :customer_id => customer.id,
1199
1298
  :payment_method_nonce => Braintree::Test::Nonce::TransactableVisa,
1200
- :token => token1
1299
+ :token => token1,
1201
1300
  )
1202
1301
 
1203
1302
  payment_method1 = Braintree::PaymentMethod.find(token1)
1204
- payment_method1.should be_default
1303
+ expect(payment_method1).to be_default
1205
1304
 
1206
1305
  token2 = random_payment_method_token
1207
1306
 
1208
- payment_method2 = Braintree::PaymentMethod.create(
1307
+ Braintree::PaymentMethod.create(
1209
1308
  :customer_id => customer.id,
1210
1309
  :payment_method_nonce => Braintree::Test::Nonce::TransactableMasterCard,
1211
- :token => token2
1310
+ :token => token2,
1212
1311
  )
1213
1312
 
1214
1313
  Braintree::Customer.update(customer.id,
@@ -1217,17 +1316,17 @@ describe Braintree::Customer do
1217
1316
  :update_existing_token => token2,
1218
1317
  :make_default => true
1219
1318
  }
1220
- }
1319
+ },
1221
1320
  )
1222
1321
 
1223
1322
  payment_method2 = Braintree::PaymentMethod.find(token2)
1224
- payment_method2.should be_default
1323
+ expect(payment_method2).to be_default
1225
1324
  end
1226
1325
 
1227
1326
  it "can use any country code" do
1228
1327
  customer = Braintree::Customer.create!(
1229
1328
  :first_name => "Alex",
1230
- :last_name => "Matterson"
1329
+ :last_name => "Matterson",
1231
1330
  )
1232
1331
  result = Braintree::Customer.update(
1233
1332
  customer.id,
@@ -1242,13 +1341,13 @@ describe Braintree::Customer do
1242
1341
  :country_code_alpha3 => "FJI",
1243
1342
  :country_code_numeric => "242"
1244
1343
  }
1245
- }
1344
+ },
1246
1345
  )
1247
- result.success?.should == true
1248
- result.customer.addresses[0].country_name.should == "Fiji"
1249
- result.customer.addresses[0].country_code_alpha2.should == "FJ"
1250
- result.customer.addresses[0].country_code_alpha3.should == "FJI"
1251
- result.customer.addresses[0].country_code_numeric.should == "242"
1346
+ expect(result.success?).to eq(true)
1347
+ expect(result.customer.addresses[0].country_name).to eq("Fiji")
1348
+ expect(result.customer.addresses[0].country_code_alpha2).to eq("FJ")
1349
+ expect(result.customer.addresses[0].country_code_alpha3).to eq("FJI")
1350
+ expect(result.customer.addresses[0].country_code_numeric).to eq("242")
1252
1351
  end
1253
1352
 
1254
1353
  it "can update the customer, credit card, and billing address in one request" do
@@ -1261,7 +1360,7 @@ describe Braintree::Customer do
1261
1360
  :first_name => "Joe",
1262
1361
  :postal_code => "60622"
1263
1362
  }
1264
- }
1363
+ },
1265
1364
  )
1266
1365
 
1267
1366
  result = Braintree::Customer.update(
@@ -1269,31 +1368,31 @@ describe Braintree::Customer do
1269
1368
  :first_name => "New Joe",
1270
1369
  :credit_card => {
1271
1370
  :cardholder_name => "New Joe Cardholder",
1272
- :options => { :update_existing_token => customer.credit_cards.first.token },
1371
+ :options => {:update_existing_token => customer.credit_cards.first.token},
1273
1372
  :billing_address => {
1274
1373
  :last_name => "Cool",
1275
1374
  :postal_code => "60666",
1276
- :options => { :update_existing => true }
1375
+ :options => {:update_existing => true}
1277
1376
  }
1278
- }
1377
+ },
1279
1378
  )
1280
- result.success?.should == true
1281
- result.customer.id.should == customer.id
1282
- result.customer.first_name.should == "New Joe"
1379
+ expect(result.success?).to eq(true)
1380
+ expect(result.customer.id).to eq(customer.id)
1381
+ expect(result.customer.first_name).to eq("New Joe")
1283
1382
 
1284
- result.customer.credit_cards.size.should == 1
1383
+ expect(result.customer.credit_cards.size).to eq(1)
1285
1384
  credit_card = result.customer.credit_cards.first
1286
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa.slice(0, 6)
1287
- credit_card.cardholder_name.should == "New Joe Cardholder"
1385
+ expect(credit_card.bin).to eq(Braintree::Test::CreditCardNumbers::Visa.slice(0, 6))
1386
+ expect(credit_card.cardholder_name).to eq("New Joe Cardholder")
1288
1387
 
1289
- credit_card.billing_address.first_name.should == "Joe"
1290
- credit_card.billing_address.last_name.should == "Cool"
1291
- credit_card.billing_address.postal_code.should == "60666"
1388
+ expect(credit_card.billing_address.first_name).to eq("Joe")
1389
+ expect(credit_card.billing_address.last_name).to eq("Cool")
1390
+ expect(credit_card.billing_address.postal_code).to eq("60666")
1292
1391
  end
1293
1392
 
1294
1393
  it "can update the customer and verify_card with a specific verification_amount" do
1295
1394
  customer = Braintree::Customer.create!(
1296
- :first_name => "Joe"
1395
+ :first_name => "Joe",
1297
1396
  )
1298
1397
 
1299
1398
  result = Braintree::Customer.update(
@@ -1303,10 +1402,120 @@ describe Braintree::Customer do
1303
1402
  :cardholder_name => "New Joe Cardholder",
1304
1403
  :number => Braintree::Test::CreditCardNumbers::Visa,
1305
1404
  :expiration_date => "12/2009",
1306
- :options => { :verify_card => true, :verification_amount => "2.00" }
1307
- }
1405
+ :options => {:verify_card => true, :verification_amount => "2.00"}
1406
+ },
1308
1407
  )
1309
- result.success?.should == true
1408
+ expect(result.success?).to eq(true)
1409
+ end
1410
+
1411
+ it "includes risk data when skip_advanced_fraud_checking is false" do
1412
+ with_fraud_protection_enterprise_merchant do
1413
+ customer = Braintree::Customer.create!(
1414
+ :first_name => "Joe",
1415
+ )
1416
+
1417
+ updated_result = Braintree::Customer.update(
1418
+ customer.id,
1419
+ :credit_card => {
1420
+ :cardholder_name => "New Joe Cardholder",
1421
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1422
+ :expiration_date => "12/2009",
1423
+ :options => {
1424
+ :skip_advanced_fraud_checking => false,
1425
+ :verify_card => true,
1426
+ },
1427
+ },
1428
+ )
1429
+
1430
+ expect(updated_result).to be_success
1431
+ verification = updated_result.customer.credit_cards.first.verification
1432
+ expect(verification.risk_data).not_to be_nil
1433
+ end
1434
+ end
1435
+
1436
+ it "does not include risk data when skip_advanced_fraud_checking is true" do
1437
+ with_fraud_protection_enterprise_merchant do
1438
+ customer = Braintree::Customer.create!(
1439
+ :first_name => "Joe",
1440
+ )
1441
+
1442
+ updated_result = Braintree::Customer.update(
1443
+ customer.id,
1444
+ :credit_card => {
1445
+ :cardholder_name => "New Joe Cardholder",
1446
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1447
+ :expiration_date => "12/2009",
1448
+ :options => {
1449
+ :skip_advanced_fraud_checking => true,
1450
+ :verify_card => true,
1451
+ },
1452
+ },
1453
+ )
1454
+
1455
+ expect(updated_result).to be_success
1456
+ verification = updated_result.customer.credit_cards.first.verification
1457
+ expect(verification.risk_data).to be_nil
1458
+ end
1459
+ end
1460
+
1461
+ it "can update a tax_identifier" do
1462
+ customer = Braintree::Customer.create!(
1463
+ :tax_identifiers => [
1464
+ {:country_code => "US", :identifier => "987654321"},
1465
+ {:country_code => "CL", :identifier => "123456789"}
1466
+ ],
1467
+ )
1468
+
1469
+ result = Braintree::Customer.update(
1470
+ customer.id,
1471
+ :tax_identifiers => [{:country_code => "US", :identifier => "567891234"}],
1472
+ )
1473
+ expect(result.success?).to eq(true)
1474
+ end
1475
+
1476
+ it "validates presence of three_d_secure_version in 3ds pass thru params" do
1477
+ result = Braintree::Customer.create(
1478
+ :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1479
+ :credit_card => {
1480
+ :three_d_secure_pass_thru => {
1481
+ :eci_flag => "05",
1482
+ :cavv => "some_cavv",
1483
+ :xid => "some_xid",
1484
+ :three_d_secure_version => "xx",
1485
+ :authentication_response => "Y",
1486
+ :directory_response => "Y",
1487
+ :cavv_algorithm => "2",
1488
+ :ds_transaction_id => "some_ds_transaction_id",
1489
+ },
1490
+ :options => {:verify_card => true}
1491
+ },
1492
+ )
1493
+
1494
+ expect(result).not_to be_success
1495
+ error = result.errors.for(:verification).first
1496
+ expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsInvalid)
1497
+ expect(error.message).to eq("The version of 3D Secure authentication must be composed only of digits and separated by periods (e.g. `1.0.2`).")
1498
+ end
1499
+
1500
+ it "accepts three_d_secure pass thru params in the request" do
1501
+ result = Braintree::Customer.create(
1502
+ :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1503
+ :credit_card => {
1504
+ :three_d_secure_pass_thru => {
1505
+ :eci_flag => "05",
1506
+ :cavv => "some_cavv",
1507
+ :xid => "some_xid",
1508
+ :three_d_secure_version => "2.2.1",
1509
+ :authentication_response => "Y",
1510
+ :directory_response => "Y",
1511
+ :cavv_algorithm => "2",
1512
+ :ds_transaction_id => "some_ds_transaction_id",
1513
+ },
1514
+ :options => {:verify_card => true}
1515
+ },
1516
+ )
1517
+
1518
+ expect(result).to be_success
1310
1519
  end
1311
1520
 
1312
1521
  it "returns 3DS info on cc verification" do
@@ -1314,20 +1523,20 @@ describe Braintree::Customer do
1314
1523
  :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1315
1524
  :credit_card => {
1316
1525
  :options => {:verify_card => true}
1317
- }
1526
+ },
1318
1527
  )
1319
- result.success?.should == true
1528
+ expect(result.success?).to eq(true)
1320
1529
 
1321
1530
  three_d_secure_info = result.customer.payment_methods.first.verification.three_d_secure_info
1322
- three_d_secure_info.enrolled.should == "Y"
1323
- three_d_secure_info.should be_liability_shifted
1324
- three_d_secure_info.should be_liability_shift_possible
1325
- three_d_secure_info.status.should == "authenticate_successful"
1326
- three_d_secure_info.cavv.should == "cavv_value"
1327
- three_d_secure_info.xid.should == "xid_value"
1328
- three_d_secure_info.eci_flag.should == "05"
1329
- three_d_secure_info.three_d_secure_version.should == "1.0.2"
1330
- three_d_secure_info.ds_transaction_id.should == nil
1531
+ expect(three_d_secure_info.enrolled).to eq("Y")
1532
+ expect(three_d_secure_info).to be_liability_shifted
1533
+ expect(three_d_secure_info).to be_liability_shift_possible
1534
+ expect(three_d_secure_info.status).to eq("authenticate_successful")
1535
+ expect(three_d_secure_info.cavv).to eq("cavv_value")
1536
+ expect(three_d_secure_info.xid).to eq("xid_value")
1537
+ expect(three_d_secure_info.eci_flag).to eq("05")
1538
+ expect(three_d_secure_info.three_d_secure_version).to eq("1.0.2")
1539
+ expect(three_d_secure_info.ds_transaction_id).to eq(nil)
1331
1540
  end
1332
1541
 
1333
1542
  it "can update the nested billing address with billing_address_id" do
@@ -1336,7 +1545,7 @@ describe Braintree::Customer do
1336
1545
  address = Braintree::Address.create!(
1337
1546
  :customer_id => customer.id,
1338
1547
  :first_name => "John",
1339
- :last_name => "Doe"
1548
+ :last_name => "Doe",
1340
1549
  )
1341
1550
 
1342
1551
  customer = Braintree::Customer.update(
@@ -1345,23 +1554,104 @@ describe Braintree::Customer do
1345
1554
  :number => Braintree::Test::CreditCardNumbers::Visa,
1346
1555
  :expiration_date => "12/2009",
1347
1556
  :billing_address_id => address.id
1348
- }
1557
+ },
1349
1558
  ).customer
1350
1559
 
1351
1560
  billing_address = customer.credit_cards.first.billing_address
1352
- billing_address.id.should == address.id
1353
- billing_address.first_name.should == "John"
1354
- billing_address.last_name.should == "Doe"
1561
+ expect(billing_address.id).to eq(address.id)
1562
+ expect(billing_address.first_name).to eq("John")
1563
+ expect(billing_address.last_name).to eq("Doe")
1355
1564
  end
1356
1565
 
1357
1566
  it "returns an error response if invalid" do
1358
1567
  customer = Braintree::Customer.create!(:email => "valid@email.com")
1359
1568
  result = Braintree::Customer.update(
1360
1569
  customer.id,
1361
- :email => "@invalid.com"
1570
+ :email => "@invalid.com",
1362
1571
  )
1363
- result.success?.should == false
1364
- result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
1572
+ expect(result.success?).to eq(false)
1573
+ expect(result.errors.for(:customer).on(:email)[0].message).to eq("Email is an invalid format.")
1574
+ end
1575
+
1576
+ context "verification_currency_iso_code" do
1577
+ it "can update the customer after validating verification_currency_iso_code" do
1578
+ customer = Braintree::Customer.create!(
1579
+ :first_name => "Joe",
1580
+ )
1581
+
1582
+ result = Braintree::Customer.update(
1583
+ customer.id,
1584
+ :first_name => "New Joe",
1585
+ :credit_card => {
1586
+ :cardholder_name => "New Joe Cardholder",
1587
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1588
+ :expiration_date => "12/2009",
1589
+ :options => {:verify_card => true, :verification_currency_iso_code => "USD"}
1590
+ },
1591
+ )
1592
+ expect(result.success?).to eq(true)
1593
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
1594
+ end
1595
+
1596
+ it "can update the customer after validating verification_currency_iso_code against the given verification_merchant_account_id" do
1597
+ customer = Braintree::Customer.create!(
1598
+ :first_name => "Joe",
1599
+ )
1600
+
1601
+ result = Braintree::Customer.update(
1602
+ customer.id,
1603
+ :first_name => "New Joe",
1604
+ :credit_card => {
1605
+ :cardholder_name => "New Joe Cardholder",
1606
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1607
+ :expiration_date => "12/2009",
1608
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "USD"}
1609
+ },
1610
+ )
1611
+ expect(result.success?).to eq(true)
1612
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
1613
+ result.customer.credit_cards[0].verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
1614
+ end
1615
+
1616
+ it "throws error due to verification_currency_iso_code not matching against the currency configured in default merchant account" do
1617
+ customer = Braintree::Customer.create!(
1618
+ :first_name => "Joe",
1619
+ )
1620
+
1621
+ result = Braintree::Customer.update(
1622
+ customer.id,
1623
+ :first_name => "New Joe",
1624
+ :credit_card => {
1625
+ :cardholder_name => "New Joe Cardholder",
1626
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1627
+ :expiration_date => "12/2009",
1628
+ :options => {:verify_card => true, :verification_currency_iso_code => "GBP"}
1629
+ },
1630
+ )
1631
+ expect(result.success?).to eq(false)
1632
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1633
+
1634
+ end
1635
+
1636
+ it "throws error due to verification_currency_iso_code not matching against the currency configured in the given verification merchant account" do
1637
+ customer = Braintree::Customer.create!(
1638
+ :first_name => "Joe",
1639
+ )
1640
+
1641
+ result = Braintree::Customer.update(
1642
+ customer.id,
1643
+ :first_name => "New Joe",
1644
+ :credit_card => {
1645
+ :cardholder_name => "New Joe Cardholder",
1646
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1647
+ :expiration_date => "12/2009",
1648
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "GBP"}
1649
+ },
1650
+ )
1651
+ expect(result.success?).to eq(false)
1652
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1653
+
1654
+ end
1365
1655
  end
1366
1656
 
1367
1657
  context "verification_account_type" do
@@ -1379,7 +1669,7 @@ describe Braintree::Customer do
1379
1669
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
1380
1670
  :verification_account_type => "credit",
1381
1671
  },
1382
- }
1672
+ },
1383
1673
  )
1384
1674
  expect(update_result).to be_success
1385
1675
  end
@@ -1395,10 +1685,10 @@ describe Braintree::Customer do
1395
1685
  :expiration_date => "06/2013",
1396
1686
  :options => {
1397
1687
  :verify_card => true,
1398
- :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
1688
+ :verification_merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
1399
1689
  :verification_account_type => "debit",
1400
1690
  },
1401
- }
1691
+ },
1402
1692
  )
1403
1693
  expect(update_result).to be_success
1404
1694
  end
@@ -1409,16 +1699,16 @@ describe Braintree::Customer do
1409
1699
  it "returns the updated customer if successful" do
1410
1700
  customer = Braintree::Customer.create!(
1411
1701
  :first_name => "Joe",
1412
- :last_name => "Cool"
1702
+ :last_name => "Cool",
1413
1703
  )
1414
1704
  updated_customer = Braintree::Customer.update!(
1415
1705
  customer.id,
1416
1706
  :first_name => "Mr. Joe",
1417
- :last_name => "Super Cool"
1707
+ :last_name => "Super Cool",
1418
1708
  )
1419
- updated_customer.first_name.should == "Mr. Joe"
1420
- updated_customer.last_name.should == "Super Cool"
1421
- updated_customer.updated_at.between?(Time.now - 60, Time.now).should == true
1709
+ expect(updated_customer.first_name).to eq("Mr. Joe")
1710
+ expect(updated_customer.last_name).to eq("Super Cool")
1711
+ expect(updated_customer.updated_at.between?(Time.now - 60, Time.now)).to eq(true)
1422
1712
  end
1423
1713
 
1424
1714
  it "raises an error if unsuccessful" do
@@ -1429,214 +1719,7 @@ describe Braintree::Customer do
1429
1719
  end
1430
1720
  end
1431
1721
 
1432
- describe "update" do
1433
- it "updates the customer" do
1434
- customer = Braintree::Customer.create!(
1435
- :first_name => "Joe",
1436
- :last_name => "Cool"
1437
- )
1438
- update_result = customer.update(
1439
- :first_name => "Mr. Joe",
1440
- :last_name => "Super Cool"
1441
- )
1442
- update_result.success?.should == true
1443
- update_result.customer.should == customer
1444
- updated_customer = update_result.customer
1445
- updated_customer.first_name.should == "Mr. Joe"
1446
- updated_customer.last_name.should == "Super Cool"
1447
- end
1448
-
1449
- it "returns an error response if invalid" do
1450
- customer = Braintree::Customer.create!(
1451
- :email => "valid@email.com"
1452
- )
1453
- result = customer.update(
1454
- :email => "@invalid.com"
1455
- )
1456
- result.success?.should == false
1457
- result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
1458
- end
1459
- end
1460
-
1461
- describe "update!" do
1462
- it "returns the customer and updates the customer if successful" do
1463
- customer = Braintree::Customer.create!(
1464
- :first_name => "Joe",
1465
- :last_name => "Cool"
1466
- )
1467
- customer.update!(
1468
- :first_name => "Mr. Joe",
1469
- :last_name => "Super Cool"
1470
- ).should == customer
1471
- customer.first_name.should == "Mr. Joe"
1472
- customer.last_name.should == "Super Cool"
1473
- customer.updated_at.between?(Time.now - 60, Time.now).should == true
1474
- end
1475
-
1476
- it "raises an error if unsuccessful" do
1477
- customer = Braintree::Customer.create!(
1478
- :email => "valid@email.com"
1479
- )
1480
- expect do
1481
- customer.update!(:email => "@invalid.com")
1482
- end.to raise_error(Braintree::ValidationsFailed)
1483
- end
1484
- end
1485
-
1486
- describe "update_from_transparent_redirect" do
1487
- it "returns a successful result if successful" do
1488
- result = Braintree::Customer.create(
1489
- :first_name => "Old First",
1490
- :last_name => "Old Last",
1491
- :company => "Old Company",
1492
- :email => "old@email.com",
1493
- :phone => "000.111.2222",
1494
- :fax => "000.222.3333",
1495
- :website => "old.website.com"
1496
- )
1497
- result.success?.should == true
1498
- original_customer = result.customer
1499
- params = {
1500
- :customer => {
1501
- :first_name => "New First",
1502
- :last_name => "New Last",
1503
- :company => "New Company",
1504
- :email => "new@email.com",
1505
- :phone => "888.111.2222",
1506
- :fax => "999.222.3333",
1507
- :website => "new.website.com"
1508
- }
1509
- }
1510
- tr_data_params = {
1511
- :customer_id => original_customer.id
1512
- }
1513
-
1514
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1515
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Customer.update_customer_url)
1516
- result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
1517
-
1518
- result.success?.should == true
1519
- customer = result.customer
1520
- customer.id.should == original_customer.id
1521
- customer.first_name.should == "New First"
1522
- customer.last_name.should == "New Last"
1523
- customer.company.should == "New Company"
1524
- customer.email.should == "new@email.com"
1525
- customer.phone.should == "888.111.2222"
1526
- customer.fax.should == "999.222.3333"
1527
- customer.website.should == "new.website.com"
1528
- end
1529
-
1530
- it "returns a successful result when updating an existing credit card" do
1531
- result = Braintree::Customer.create(
1532
- :first_name => "Old First",
1533
- :last_name => "Old Last",
1534
- :company => "Old Company",
1535
- :email => "old@email.com",
1536
- :phone => "000.111.2222",
1537
- :fax => "000.222.3333",
1538
- :website => "old.website.com",
1539
- :credit_card => {
1540
- :number => Braintree::Test::CreditCardNumbers::Visa,
1541
- :expiration_date => "12/2009",
1542
- :billing_address => {
1543
- :first_name => "Joe",
1544
- :postal_code => "60622"
1545
- }
1546
- }
1547
- )
1548
- result.success?.should == true
1549
- original_customer = result.customer
1550
-
1551
- tr_data_params = {
1552
- :customer_id => original_customer.id,
1553
- :customer => {
1554
- :first_name => "New First",
1555
- :last_name => "New Last",
1556
- :company => "New Company",
1557
- :email => "new@email.com",
1558
- :phone => "888.111.2222",
1559
- :fax => "999.222.3333",
1560
- :website => "new.website.com",
1561
- :credit_card => {
1562
- :cardholder_name => "New Joe Cardholder",
1563
- :options => { :update_existing_token => original_customer.credit_cards.first.token },
1564
- :billing_address => {
1565
- :last_name => "Cool",
1566
- :postal_code => "60666",
1567
- :options => { :update_existing => true }
1568
- }
1569
- }
1570
- }
1571
- }
1572
-
1573
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1574
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.update_customer_url)
1575
- result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
1576
-
1577
- result.success?.should == true
1578
- customer = result.customer
1579
- customer.id.should == original_customer.id
1580
- customer.first_name.should == "New First"
1581
- customer.last_name.should == "New Last"
1582
- customer.company.should == "New Company"
1583
- customer.email.should == "new@email.com"
1584
- customer.phone.should == "888.111.2222"
1585
- customer.fax.should == "999.222.3333"
1586
- customer.website.should == "new.website.com"
1587
-
1588
- credit_card = customer.credit_cards.first
1589
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa.slice(0, 6)
1590
- credit_card.cardholder_name.should == "New Joe Cardholder"
1591
-
1592
- credit_card.billing_address.first_name.should == "Joe"
1593
- credit_card.billing_address.last_name.should == "Cool"
1594
- credit_card.billing_address.postal_code.should == "60666"
1595
- end
1596
-
1597
- it "can pass any attribute through tr_data" do
1598
- original_customer = Braintree::Customer.create!(
1599
- :first_name => "Old First",
1600
- :last_name => "Old Last",
1601
- :company => "Old Company",
1602
- :email => "old@email.com",
1603
- :phone => "000.111.2222",
1604
- :fax => "000.222.3333",
1605
- :website => "old.website.com"
1606
- )
1607
- new_customer_id = "customer_#{rand(1_000_000)}"
1608
- tr_data_params = {
1609
- :customer_id => original_customer.id,
1610
- :customer => {
1611
- :id => new_customer_id,
1612
- :first_name => "New First",
1613
- :last_name => "New Last",
1614
- :company => "New Company",
1615
- :email => "new@email.com",
1616
- :phone => "888.111.2222",
1617
- :fax => "999.222.3333",
1618
- :website => "new.website.com"
1619
- }
1620
- }
1621
-
1622
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1623
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.update_customer_url)
1624
- result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
1625
-
1626
- result.success?.should == true
1627
- customer = result.customer
1628
- customer.id.should == new_customer_id
1629
- customer.first_name.should == "New First"
1630
- customer.last_name.should == "New Last"
1631
- customer.company.should == "New Company"
1632
- customer.email.should == "new@email.com"
1633
- customer.phone.should == "888.111.2222"
1634
- customer.fax.should == "999.222.3333"
1635
- customer.website.should == "new.website.com"
1636
- end
1637
- end
1638
-
1639
- describe "default_credit_card" do
1722
+ describe "default_payment_method" do
1640
1723
  it "should return the default credit card for a given customer" do
1641
1724
  customer = Braintree::Customer.create!(
1642
1725
  :credit_card => {
@@ -1645,21 +1728,21 @@ describe Braintree::Customer do
1645
1728
  :options => {
1646
1729
  :make_default => false
1647
1730
  }
1648
- }
1731
+ },
1649
1732
  )
1650
1733
 
1651
- default_credit_card = Braintree::CreditCard.create!(
1734
+ default_payment_method = Braintree::CreditCard.create!(
1652
1735
  :customer_id => customer.id,
1653
1736
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1654
1737
  :expiration_date => "11/2015",
1655
1738
  :options => {
1656
1739
  :make_default => true
1657
- }
1740
+ },
1658
1741
  )
1659
1742
 
1660
1743
  customer = Braintree::Customer.find(customer.id)
1661
1744
 
1662
- customer.default_credit_card.should == default_credit_card
1745
+ expect(customer.default_payment_method).to eq(default_payment_method)
1663
1746
  end
1664
1747
  end
1665
1748
 
@@ -1667,10 +1750,10 @@ describe Braintree::Customer do
1667
1750
  context "future" do
1668
1751
  it "creates a customer with a future paypal account" do
1669
1752
  result = Braintree::Customer.create(
1670
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment
1753
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
1671
1754
  )
1672
1755
 
1673
- result.should be_success
1756
+ expect(result).to be_success
1674
1757
  end
1675
1758
 
1676
1759
  it "updates a customer with a future paypal account" do
@@ -1681,7 +1764,7 @@ describe Braintree::Customer do
1681
1764
  :options => {
1682
1765
  :make_default => true
1683
1766
  }
1684
- }
1767
+ },
1685
1768
  )
1686
1769
 
1687
1770
  paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
@@ -1690,16 +1773,16 @@ describe Braintree::Customer do
1690
1773
  :token => paypal_account_token,
1691
1774
  :options => {
1692
1775
  :make_default => true
1693
- }
1776
+ },
1694
1777
  )
1695
1778
 
1696
1779
  result = Braintree::Customer.update(
1697
1780
  customer.id,
1698
- :payment_method_nonce => nonce
1781
+ :payment_method_nonce => nonce,
1699
1782
  )
1700
1783
 
1701
- result.should be_success
1702
- result.customer.default_payment_method.token.should == paypal_account_token
1784
+ expect(result).to be_success
1785
+ expect(result.customer.default_payment_method.token).to eq(paypal_account_token)
1703
1786
  end
1704
1787
  end
1705
1788
 
@@ -1711,7 +1794,7 @@ describe Braintree::Customer do
1711
1794
  :token => paypal_account_token,
1712
1795
  :options => {
1713
1796
  :make_default => true
1714
- }
1797
+ },
1715
1798
  )
1716
1799
 
1717
1800
  result = Braintree::Customer.create(
@@ -1736,7 +1819,7 @@ describe Braintree::Customer do
1736
1819
  },
1737
1820
  )
1738
1821
 
1739
- result.should be_success
1822
+ expect(result).to be_success
1740
1823
  end
1741
1824
 
1742
1825
  it "updates a customer with payment_method_nonce and paypal options" do
@@ -1747,7 +1830,7 @@ describe Braintree::Customer do
1747
1830
  :options => {
1748
1831
  :make_default => true
1749
1832
  }
1750
- }
1833
+ },
1751
1834
  )
1752
1835
 
1753
1836
  paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
@@ -1756,7 +1839,7 @@ describe Braintree::Customer do
1756
1839
  :token => paypal_account_token,
1757
1840
  :options => {
1758
1841
  :make_default => true
1759
- }
1842
+ },
1760
1843
  )
1761
1844
 
1762
1845
  result = Braintree::Customer.update(
@@ -1782,18 +1865,18 @@ describe Braintree::Customer do
1782
1865
  },
1783
1866
  )
1784
1867
 
1785
- result.should be_success
1786
- result.customer.default_payment_method.token.should == paypal_account_token
1868
+ expect(result).to be_success
1869
+ expect(result.customer.default_payment_method.token).to eq(paypal_account_token)
1787
1870
  end
1788
1871
  end
1789
1872
 
1790
1873
  context "onetime" do
1791
1874
  it "does not create a customer with a onetime paypal account" do
1792
1875
  result = Braintree::Customer.create(
1793
- :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment
1876
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
1794
1877
  )
1795
1878
 
1796
- result.should_not be_success
1879
+ expect(result).not_to be_success
1797
1880
  end
1798
1881
 
1799
1882
  it "does not update a customer with a onetime paypal account" do
@@ -1806,7 +1889,7 @@ describe Braintree::Customer do
1806
1889
  :options => {
1807
1890
  :make_default => true
1808
1891
  }
1809
- }
1892
+ },
1810
1893
  )
1811
1894
 
1812
1895
  paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
@@ -1815,16 +1898,16 @@ describe Braintree::Customer do
1815
1898
  :token => paypal_account_token,
1816
1899
  :options => {
1817
1900
  :make_default => true
1818
- }
1901
+ },
1819
1902
  )
1820
1903
 
1821
1904
  result = Braintree::Customer.update(
1822
1905
  customer.id,
1823
- :payment_method_nonce => nonce
1906
+ :payment_method_nonce => nonce,
1824
1907
  )
1825
1908
 
1826
- result.should_not be_success
1827
- customer.default_payment_method.token.should == credit_card_token
1909
+ expect(result).not_to be_success
1910
+ expect(customer.default_payment_method.token).to eq(credit_card_token)
1828
1911
  end
1829
1912
  end
1830
1913
  end