braintree 2.104.0 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) 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 +1 -1
  5. data/lib/braintree/address.rb +2 -23
  6. data/lib/braintree/apple_pay.rb +1 -1
  7. data/lib/braintree/apple_pay_card.rb +11 -1
  8. data/lib/braintree/apple_pay_options.rb +1 -1
  9. data/lib/braintree/authorization_adjustment.rb +1 -1
  10. data/lib/braintree/base_module.rb +6 -0
  11. data/lib/braintree/bin_data.rb +9 -2
  12. data/lib/braintree/client_token.rb +1 -1
  13. data/lib/braintree/configuration.rb +12 -12
  14. data/lib/braintree/connected_merchant_paypal_status_changed.rb +1 -1
  15. data/lib/braintree/connected_merchant_status_transitioned.rb +1 -1
  16. data/lib/braintree/credit_card.rb +2 -77
  17. data/lib/braintree/credit_card_gateway.rb +17 -36
  18. data/lib/braintree/credit_card_verification.rb +18 -5
  19. data/lib/braintree/credit_card_verification_search.rb +1 -1
  20. data/lib/braintree/customer.rb +9 -78
  21. data/lib/braintree/customer_gateway.rb +2 -23
  22. data/lib/braintree/customer_search.rb +1 -1
  23. data/lib/braintree/disbursement.rb +1 -1
  24. data/lib/braintree/{transaction/coinbase_details.rb → dispute/paypal_message.rb} +5 -6
  25. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  26. data/lib/braintree/dispute.rb +32 -8
  27. data/lib/braintree/dispute_gateway.rb +4 -9
  28. data/lib/braintree/dispute_search.rb +6 -3
  29. data/lib/braintree/document_upload.rb +1 -1
  30. data/lib/braintree/enriched_customer_data.rb +21 -0
  31. data/lib/braintree/error_codes.rb +150 -171
  32. data/lib/braintree/exceptions.rb +5 -3
  33. data/lib/braintree/exchange_rate.rb +13 -0
  34. data/lib/braintree/exchange_rate_quote.rb +24 -0
  35. data/lib/braintree/exchange_rate_quote_gateway.rb +35 -0
  36. data/lib/braintree/exchange_rate_quote_input.rb +21 -0
  37. data/lib/braintree/exchange_rate_quote_request.rb +18 -0
  38. data/lib/braintree/exchange_rate_quote_response.rb +18 -0
  39. data/lib/braintree/gateway.rb +4 -14
  40. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +11 -3
  41. data/lib/braintree/granted_payment_instrument_update.rb +1 -1
  42. data/lib/braintree/graphql_client.rb +7 -7
  43. data/lib/braintree/http.rb +4 -3
  44. data/lib/braintree/local_payment_completed.rb +2 -2
  45. data/lib/braintree/local_payment_expired.rb +21 -0
  46. data/lib/braintree/local_payment_funded.rb +22 -0
  47. data/lib/braintree/local_payment_reversed.rb +19 -0
  48. data/lib/braintree/merchant.rb +1 -1
  49. data/lib/braintree/merchant_account.rb +1 -1
  50. data/lib/braintree/merchant_account_gateway.rb +3 -1
  51. data/lib/braintree/merchant_gateway.rb +1 -1
  52. data/lib/braintree/modification.rb +1 -1
  53. data/lib/braintree/oauth_credentials.rb +1 -1
  54. data/lib/braintree/oauth_gateway.rb +5 -5
  55. data/lib/braintree/payment_instrument_type.rb +10 -14
  56. data/lib/braintree/payment_method_customer_data_updated_metadata.rb +24 -0
  57. data/lib/braintree/payment_method_gateway.rb +15 -17
  58. data/lib/braintree/payment_method_nonce.rb +7 -4
  59. data/lib/braintree/payment_method_nonce_details.rb +37 -0
  60. data/lib/braintree/payment_method_nonce_details_payer_info.rb +32 -0
  61. data/lib/braintree/payment_method_nonce_gateway.rb +1 -1
  62. data/lib/braintree/payment_method_parser.rb +1 -8
  63. data/lib/braintree/plan.rb +21 -1
  64. data/lib/braintree/plan_gateway.rb +100 -0
  65. data/lib/braintree/processor_response_types.rb +3 -3
  66. data/lib/braintree/resource_collection.rb +8 -3
  67. data/lib/braintree/revoked_payment_method_metadata.rb +1 -1
  68. data/lib/braintree/risk_data/liability_shift.rb +22 -0
  69. data/lib/braintree/risk_data.rb +5 -1
  70. data/lib/braintree/samsung_pay_card.rb +1 -1
  71. data/lib/braintree/settlement_batch_summary.rb +2 -2
  72. data/lib/braintree/subscription.rb +11 -11
  73. data/lib/braintree/successful_result.rb +3 -2
  74. data/lib/braintree/test/credit_card.rb +1 -0
  75. data/lib/braintree/test/nonce.rb +4 -23
  76. data/lib/braintree/three_d_secure_info.rb +22 -12
  77. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  78. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  79. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  80. data/lib/braintree/transaction/installment.rb +28 -0
  81. data/lib/braintree/transaction/paypal_details.rb +3 -0
  82. data/lib/braintree/transaction/subscription_details.rb +2 -0
  83. data/lib/braintree/transaction.rb +65 -120
  84. data/lib/braintree/transaction_gateway.rb +39 -27
  85. data/lib/braintree/transaction_line_item.rb +1 -1
  86. data/lib/braintree/transaction_review.rb +18 -0
  87. data/lib/braintree/transaction_search.rb +5 -3
  88. data/lib/braintree/unknown_payment_method.rb +1 -1
  89. data/lib/braintree/us_bank_account.rb +3 -3
  90. data/lib/braintree/us_bank_account_verification.rb +1 -1
  91. data/lib/braintree/us_bank_account_verification_gateway.rb +1 -1
  92. data/lib/braintree/util.rb +21 -6
  93. data/lib/braintree/venmo_account.rb +1 -1
  94. data/lib/braintree/venmo_profile_data.rb +23 -0
  95. data/lib/braintree/version.rb +2 -2
  96. data/lib/braintree/visa_checkout_card.rb +2 -2
  97. data/lib/braintree/webhook_notification.rb +44 -30
  98. data/lib/braintree/webhook_notification_gateway.rb +5 -5
  99. data/lib/braintree/webhook_testing_gateway.rb +104 -43
  100. data/lib/braintree/xml/generator.rb +5 -4
  101. data/lib/braintree/xml/parser.rb +22 -35
  102. data/lib/braintree/xml/rexml.rb +4 -5
  103. data/lib/braintree.rb +28 -23
  104. data/spec/integration/braintree/add_on_spec.rb +1 -1
  105. data/spec/integration/braintree/address_spec.rb +30 -113
  106. data/spec/integration/braintree/advanced_search_spec.rb +45 -45
  107. data/spec/integration/braintree/apple_pay_spec.rb +3 -3
  108. data/spec/integration/braintree/braintree_gateway_spec.rb +2 -1
  109. data/spec/integration/braintree/client_api/client_token_spec.rb +14 -14
  110. data/spec/integration/braintree/client_api/spec_helper.rb +5 -31
  111. data/spec/integration/braintree/credit_card_spec.rb +219 -593
  112. data/spec/integration/braintree/credit_card_verification_search_spec.rb +2 -2
  113. data/spec/integration/braintree/credit_card_verification_spec.rb +1 -1
  114. data/spec/integration/braintree/customer_search_spec.rb +8 -8
  115. data/spec/integration/braintree/customer_spec.rb +484 -513
  116. data/spec/integration/braintree/dispute_search_spec.rb +35 -6
  117. data/spec/integration/braintree/dispute_spec.rb +6 -7
  118. data/spec/integration/braintree/error_codes_spec.rb +1 -1
  119. data/spec/integration/braintree/exchange_rate_quote_spec.rb +97 -0
  120. data/spec/integration/braintree/graphql_client_spec.rb +0 -2
  121. data/spec/integration/braintree/http_spec.rb +2 -2
  122. data/spec/integration/braintree/merchant_account_spec.rb +28 -29
  123. data/spec/integration/braintree/merchant_spec.rb +14 -14
  124. data/spec/integration/braintree/oauth_spec.rb +11 -11
  125. data/spec/integration/braintree/payment_method_nonce_spec.rb +29 -35
  126. data/spec/integration/braintree/payment_method_spec.rb +535 -270
  127. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +17 -13
  128. data/spec/integration/braintree/paypal_account_spec.rb +28 -28
  129. data/spec/integration/braintree/plan_spec.rb +82 -0
  130. data/spec/integration/braintree/samsung_pay_card_spec.rb +9 -9
  131. data/spec/integration/braintree/settlement_batch_summary_spec.rb +8 -8
  132. data/spec/integration/braintree/subscription_spec.rb +144 -149
  133. data/spec/integration/braintree/test/transaction_amounts_spec.rb +2 -2
  134. data/spec/integration/braintree/test_transaction_spec.rb +10 -10
  135. data/spec/integration/braintree/transaction_search_spec.rb +175 -70
  136. data/spec/integration/braintree/transaction_spec.rb +955 -894
  137. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +32 -26
  138. data/spec/integration/braintree/us_bank_account_spec.rb +6 -6
  139. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +7 -7
  140. data/spec/integration/braintree/us_bank_account_verification_spec.rb +8 -8
  141. data/spec/integration/braintree/visa_checkout_card_spec.rb +5 -5
  142. data/spec/integration/spec_helper.rb +16 -7
  143. data/spec/oauth_test_helper.rb +1 -1
  144. data/spec/script/httpsd.rb +6 -6
  145. data/spec/spec_helper.rb +8 -14
  146. data/spec/unit/braintree/address_spec.rb +1 -9
  147. data/spec/unit/braintree/apple_pay_card_spec.rb +7 -1
  148. data/spec/unit/braintree/client_token_spec.rb +2 -2
  149. data/spec/unit/braintree/configuration_spec.rb +42 -42
  150. data/spec/unit/braintree/credit_card_spec.rb +13 -32
  151. data/spec/unit/braintree/credit_card_verification_search_spec.rb +1 -1
  152. data/spec/unit/braintree/credit_card_verification_spec.rb +8 -4
  153. data/spec/unit/braintree/customer_spec.rb +21 -22
  154. data/spec/unit/braintree/disbursement_spec.rb +7 -7
  155. data/spec/unit/braintree/dispute_search_spec.rb +3 -0
  156. data/spec/unit/braintree/dispute_spec.rb +75 -21
  157. data/spec/unit/braintree/enriched_customer_data_spec.rb +32 -0
  158. data/spec/unit/braintree/error_result_spec.rb +5 -5
  159. data/spec/unit/braintree/errors_spec.rb +8 -8
  160. data/spec/unit/braintree/exchange_rate_quote_input_spec.rb +42 -0
  161. data/spec/unit/braintree/exchange_rate_quote_request_spec.rb +82 -0
  162. data/spec/unit/braintree/exchange_rate_quote_response_spec.rb +52 -0
  163. data/spec/unit/braintree/exchange_rate_quote_spec.rb +42 -0
  164. data/spec/unit/braintree/exchange_rate_spec.rb +23 -0
  165. data/spec/unit/braintree/http_spec.rb +10 -8
  166. data/spec/unit/braintree/local_payment_completed_spec.rb +14 -0
  167. data/spec/unit/braintree/local_payment_expired_spec.rb +24 -0
  168. data/spec/unit/braintree/local_payment_funded_spec.rb +34 -0
  169. data/spec/unit/braintree/merchant_account_spec.rb +1 -1
  170. data/spec/unit/braintree/payment_method_customer_data_updated_metadata_spec.rb +45 -0
  171. data/spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb +31 -0
  172. data/spec/unit/braintree/payment_method_nonce_details_spec.rb +43 -0
  173. data/spec/unit/braintree/payment_method_nonce_spec.rb +40 -0
  174. data/spec/unit/braintree/payment_method_spec.rb +1 -1
  175. data/spec/unit/braintree/paypal_account_spec.rb +2 -2
  176. data/spec/unit/braintree/resource_collection_spec.rb +30 -1
  177. data/spec/unit/braintree/risk_data/liability_shift.rb +26 -0
  178. data/spec/unit/braintree/risk_data_spec.rb +38 -8
  179. data/spec/unit/braintree/subscription_search_spec.rb +1 -1
  180. data/spec/unit/braintree/successful_result_spec.rb +1 -1
  181. data/spec/unit/braintree/three_d_secure_info_spec.rb +32 -14
  182. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +3 -3
  183. data/spec/unit/braintree/transaction/customer_details_spec.rb +1 -1
  184. data/spec/unit/braintree/transaction/deposit_details_spec.rb +2 -2
  185. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  186. data/spec/unit/braintree/transaction/paypal_details_spec.rb +7 -1
  187. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  188. data/spec/unit/braintree/transaction_spec.rb +36 -54
  189. data/spec/unit/braintree/util_spec.rb +55 -21
  190. data/spec/unit/braintree/validation_error_collection_spec.rb +36 -36
  191. data/spec/unit/braintree/venmo_profile_data_spec.rb +32 -0
  192. data/spec/unit/braintree/webhook_notification_spec.rb +166 -57
  193. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  194. data/spec/unit/braintree/xml_spec.rb +31 -31
  195. metadata +62 -30
  196. data/lib/braintree/amex_express_checkout_card.rb +0 -40
  197. data/lib/braintree/coinbase_account.rb +0 -34
  198. data/lib/braintree/europe_bank_account.rb +0 -36
  199. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  200. data/lib/braintree/ideal_payment.rb +0 -61
  201. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  202. data/lib/braintree/masterpass_card.rb +0 -83
  203. data/lib/braintree/settlement_batch.rb +0 -0
  204. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  205. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  206. data/lib/braintree/transaction/masterpass_card_details.rb +0 -49
  207. data/lib/braintree/transparent_redirect.rb +0 -40
  208. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  209. data/spec/hacks/tcp_socket.rb +0 -18
  210. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  211. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  212. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  213. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
@@ -8,7 +8,7 @@ describe Braintree::Customer do
8
8
  customers = Braintree::Customer.all
9
9
  customers.maximum_size.should > 100
10
10
 
11
- customer_ids = customers.map {|c| c.id }.uniq.compact
11
+ customer_ids = customers.map { |c| c.id }.uniq.compact
12
12
  customer_ids.size.should == customers.maximum_size
13
13
  end
14
14
  end
@@ -17,7 +17,7 @@ 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
22
  create_result.success?.should == true
23
23
  customer = create_result.customer
@@ -39,7 +39,8 @@ describe Braintree::Customer do
39
39
  :email => "bill@microsoft.com",
40
40
  :phone => "312.555.1234",
41
41
  :fax => "614.555.5678",
42
- :website => "www.microsoft.com"
42
+ :website => "www.microsoft.com",
43
+ :tax_identifiers => [{:country_code => "US", :identifier => "987654321"}],
43
44
  )
44
45
  result.success?.should == true
45
46
  result.customer.id.should =~ /^\d{6,}$/
@@ -58,7 +59,7 @@ describe Braintree::Customer do
58
59
  oauth_gateway = Braintree::Gateway.new(
59
60
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
60
61
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
61
- :logger => Logger.new("/dev/null")
62
+ :logger => Logger.new("/dev/null"),
62
63
  )
63
64
  access_token = Braintree::OAuthTestHelper.create_token(oauth_gateway, {
64
65
  :merchant_public_id => "integration_merchant_id",
@@ -67,7 +68,7 @@ describe Braintree::Customer do
67
68
 
68
69
  gateway = Braintree::Gateway.new(
69
70
  :access_token => access_token,
70
- :logger => Logger.new("/dev/null")
71
+ :logger => Logger.new("/dev/null"),
71
72
  )
72
73
 
73
74
  result = gateway.customer.create(
@@ -77,7 +78,7 @@ describe Braintree::Customer do
77
78
  :email => "joe@example.com",
78
79
  :phone => "312.555.1234",
79
80
  :fax => "614.555.5678",
80
- :website => "www.example.com"
81
+ :website => "www.example.com",
81
82
  )
82
83
  result.success?.should == true
83
84
  result.customer.id.should =~ /^\d{6,}$/
@@ -85,15 +86,14 @@ describe Braintree::Customer do
85
86
  result.customer.last_name.should == "Brown"
86
87
  end
87
88
 
88
- it "supports creation with a device session ID and (optional) fraud_merchant_id" do
89
+ it "supports creation with device_data" do
89
90
  result = Braintree::Customer.create(
90
91
  :credit_card => {
91
92
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
92
93
  :expiration_date => "05/2010",
93
94
  :cvv => "100",
94
- :device_session_id => "abc123",
95
- :fraud_merchant_id => "7"
96
- }
95
+ :device_data => "device_data",
96
+ },
97
97
  )
98
98
 
99
99
  result.should be_success
@@ -109,7 +109,58 @@ describe Braintree::Customer do
109
109
  :risk_data => {
110
110
  :customer_browser => "IE5",
111
111
  :customer_ip => "192.168.0.1"
112
- }
112
+ },
113
+ )
114
+
115
+ result.should be_success
116
+ end
117
+
118
+ it "includes risk data when skip_advanced_fraud_checking is false" do
119
+ with_fraud_protection_enterprise_merchant do
120
+ result = Braintree::Customer.create(
121
+ :credit_card => {
122
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
123
+ :expiration_date => "05/2010",
124
+ :cvv => "100",
125
+ :options => {
126
+ :skip_advanced_fraud_checking => false,
127
+ :verify_card => true,
128
+ },
129
+ },
130
+ )
131
+
132
+ expect(result).to be_success
133
+ verification = result.customer.credit_cards.first.verification
134
+ expect(verification.risk_data).not_to be_nil
135
+ end
136
+ end
137
+
138
+ it "does not include risk data when skip_advanced_fraud_checking is true" do
139
+ with_fraud_protection_enterprise_merchant do
140
+ result = Braintree::Customer.create(
141
+ :credit_card => {
142
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
143
+ :expiration_date => "05/2010",
144
+ :cvv => "100",
145
+ :options => {
146
+ :skip_advanced_fraud_checking => true,
147
+ :verify_card => true,
148
+ },
149
+ },
150
+ )
151
+
152
+ expect(result).to be_success
153
+ verification = result.customer.credit_cards.first.verification
154
+ expect(verification.risk_data).to be_nil
155
+ end
156
+ end
157
+
158
+ it "supports creation with tax_identifiers" do
159
+ result = Braintree::Customer.create(
160
+ :tax_identifiers => [
161
+ {:country_code => "US", :identifier => "987654321"},
162
+ {:country_code => "CL", :identifier => "123456789"}
163
+ ],
113
164
  )
114
165
 
115
166
  result.should be_success
@@ -135,21 +186,21 @@ describe Braintree::Customer do
135
186
  found_customer.last_name.should == last_name
136
187
  else
137
188
  result.customer.first_name.should == "José"
138
- result.customer.first_name.bytes.map {|b| b.to_s(8)}.should == ["112", "157", "163", "303", "251"]
189
+ result.customer.first_name.bytes.map { |b| b.to_s(8) }.should == ["112", "157", "163", "303", "251"]
139
190
  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
+ result.customer.last_name.bytes.map { |b| b.to_s(8) }.should == ["115", "165", "303", "261", "157", "172"]
141
192
 
142
193
  found_customer = Braintree::Customer.find(result.customer.id)
143
194
  found_customer.first_name.should == "José"
144
- found_customer.first_name.bytes.map {|b| b.to_s(8)}.should == ["112", "157", "163", "303", "251"]
195
+ found_customer.first_name.bytes.map { |b| b.to_s(8) }.should == ["112", "157", "163", "303", "251"]
145
196
  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
+ found_customer.last_name.bytes.map { |b| b.to_s(8) }.should == ["115", "165", "303", "261", "157", "172"]
147
198
  end
148
199
  end
149
200
 
150
201
  it "returns an error response if invalid" do
151
202
  result = Braintree::Customer.create(
152
- :email => "@invalid.com"
203
+ :email => "@invalid.com",
153
204
  )
154
205
  result.success?.should == false
155
206
  result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
@@ -163,7 +214,7 @@ describe Braintree::Customer do
163
214
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
164
215
  :expiration_date => "05/2010",
165
216
  :cvv => "100"
166
- }
217
+ },
167
218
  )
168
219
 
169
220
  result.success?.should == true
@@ -183,7 +234,7 @@ describe Braintree::Customer do
183
234
  :email => "other@example.com",
184
235
  :billing_agreement_id => "B-123456",
185
236
  :options => {:make_default => true}
186
- }
237
+ },
187
238
  )
188
239
 
189
240
  result.success?.should == true
@@ -201,7 +252,7 @@ describe Braintree::Customer do
201
252
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
202
253
  :expiration_date => "05/2010",
203
254
  :options => {:verify_card => true}
204
- }
255
+ },
205
256
  )
206
257
  result.success?.should == false
207
258
  result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
@@ -215,7 +266,7 @@ describe Braintree::Customer do
215
266
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
216
267
  :expiration_date => "05/2019",
217
268
  :options => {:verify_card => true, :verification_amount => "2.00"}
218
- }
269
+ },
219
270
  )
220
271
  result.success?.should == true
221
272
  end
@@ -225,7 +276,7 @@ describe Braintree::Customer do
225
276
  Braintree::CreditCard.create(
226
277
  :customer_id => customer.id,
227
278
  :number => Braintree::Test::CreditCardNumbers::Visa,
228
- :expiration_date => "05/2015"
279
+ :expiration_date => "05/2015",
229
280
  )
230
281
 
231
282
  result = Braintree::Customer.create(
@@ -235,7 +286,7 @@ describe Braintree::Customer do
235
286
  :number => Braintree::Test::CreditCardNumbers::Visa,
236
287
  :expiration_date => "05/2015",
237
288
  :options => {:fail_on_duplicate_payment_method => true}
238
- }
289
+ },
239
290
  )
240
291
  result.success?.should == false
241
292
  result.errors.for(:customer).for(:credit_card).on(:number)[0].message.should == "Duplicate card exists in the vault."
@@ -252,12 +303,98 @@ describe Braintree::Customer do
252
303
  :verify_card => true,
253
304
  :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
254
305
  }
255
- }
306
+ },
256
307
  )
257
308
  result.success?.should == false
258
309
  result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
259
310
  end
260
311
 
312
+ it "can create a customer and a payment method at the same time after validating verification_currency_iso_code" do
313
+ result = Braintree::Customer.create(
314
+ :first_name => "Mike",
315
+ :last_name => "Jones",
316
+ :credit_card => {
317
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
318
+ :expiration_date => "05/2010",
319
+ :cvv => "100",
320
+ :options => {
321
+ :verify_card => true,
322
+ :verification_currency_iso_code => "USD"
323
+ }
324
+ },
325
+ )
326
+
327
+ result.success?.should == true
328
+ result.customer.first_name.should == "Mike"
329
+ result.customer.last_name.should == "Jones"
330
+ result.customer.credit_cards[0].bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
331
+ result.customer.credit_cards[0].last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
332
+ result.customer.credit_cards[0].expiration_date.should == "05/2010"
333
+ result.customer.credit_cards[0].unique_number_identifier.should =~ /\A\w{32}\z/
334
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
335
+ end
336
+
337
+ it "errors when verification_currency_iso_code is not supported by merchant account" do
338
+ result = Braintree::Customer.create(
339
+ :first_name => "Mike",
340
+ :last_name => "Jones",
341
+ :credit_card => {
342
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
343
+ :expiration_date => "05/2010",
344
+ :cvv => "100",
345
+ :options => {
346
+ :verify_card => true,
347
+ :verification_currency_iso_code => "GBP"
348
+ }
349
+ },
350
+ )
351
+ expect(result).to_not be_success
352
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
353
+ end
354
+
355
+ it "validates verification_currency_iso_code of the given verification_merchant_account_id and creates customer" do
356
+ result = Braintree::Customer.create(
357
+ :first_name => "Mike",
358
+ :last_name => "Jones",
359
+ :credit_card => {
360
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
361
+ :expiration_date => "05/2010",
362
+ :options => {
363
+ :verify_card => true,
364
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
365
+ :verification_currency_iso_code => "USD"
366
+ }
367
+ },
368
+ )
369
+ result.success?.should == true
370
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
371
+ result.customer.first_name.should == "Mike"
372
+ result.customer.last_name.should == "Jones"
373
+ result.customer.credit_cards[0].bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
374
+ result.customer.credit_cards[0].last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
375
+ result.customer.credit_cards[0].expiration_date.should == "05/2010"
376
+ result.customer.credit_cards[0].unique_number_identifier.should =~ /\A\w{32}\z/
377
+ end
378
+
379
+ it "validates verification_currency_iso_code of the given verification_merchant_account_id and returns error" do
380
+ result = Braintree::Customer.create(
381
+ :first_name => "Mike",
382
+ :last_name => "Jones",
383
+ :credit_card => {
384
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
385
+ :expiration_date => "05/2010",
386
+ :options => {
387
+ :verify_card => true,
388
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
389
+ :verification_currency_iso_code => "GBP"
390
+ }
391
+ },
392
+ )
393
+ expect(result).to_not be_success
394
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
395
+ end
396
+
397
+
261
398
  it "can create a customer, payment method, and billing address at the same time" do
262
399
  result = Braintree::Customer.create(
263
400
  :first_name => "Mike",
@@ -273,7 +410,7 @@ describe Braintree::Customer do
273
410
  :postal_code => "60622",
274
411
  :country_name => "United States of America"
275
412
  }
276
- }
413
+ },
277
414
  )
278
415
  result.success?.should == true
279
416
  result.customer.first_name.should == "Mike"
@@ -304,7 +441,7 @@ describe Braintree::Customer do
304
441
  :country_code_alpha3 => "COM",
305
442
  :country_code_numeric => "174"
306
443
  }
307
- }
444
+ },
308
445
  )
309
446
  result.success?.should == true
310
447
  result.customer.addresses[0].country_name.should == "Comoros"
@@ -319,7 +456,7 @@ describe Braintree::Customer do
319
456
  :last_name => "Gates",
320
457
  :custom_fields => {
321
458
  :store_me => "custom value"
322
- }
459
+ },
323
460
  )
324
461
  result.success?.should == true
325
462
  result.customer.custom_fields[:store_me].should == "custom value"
@@ -329,7 +466,7 @@ describe Braintree::Customer do
329
466
  result = Braintree::Customer.create(
330
467
  :first_name => "Bill",
331
468
  :last_name => "Gates",
332
- :custom_fields => { :store_me => "" }
469
+ :custom_fields => {:store_me => ""},
333
470
  )
334
471
  result.success?.should == true
335
472
  result.customer.custom_fields.should == {}
@@ -343,7 +480,7 @@ describe Braintree::Customer do
343
480
  :billing_address => {
344
481
  :country_name => "invalid"
345
482
  }
346
- }
483
+ },
347
484
  )
348
485
  result.success?.should == false
349
486
  result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
@@ -363,10 +500,10 @@ describe Braintree::Customer do
363
500
  :country_code_alpha2 => "US",
364
501
  :country_code_alpha3 => "COM",
365
502
  }
366
- }
503
+ },
367
504
  )
368
505
  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)
506
+ result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:base).map { |e| e.code }.should include(Braintree::ErrorCodes::Address::InconsistentCountry)
370
507
  end
371
508
 
372
509
  it "returns an error if country code alpha2 is invalid" do
@@ -379,10 +516,10 @@ describe Braintree::Customer do
379
516
  :billing_address => {
380
517
  :country_code_alpha2 => "zz",
381
518
  }
382
- }
519
+ },
383
520
  )
384
521
  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)
522
+ result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_alpha2).map { |e| e.code }.should include(Braintree::ErrorCodes::Address::CountryCodeAlpha2IsNotAccepted)
386
523
  end
387
524
 
388
525
  it "returns an error if country code alpha3 is invalid" do
@@ -395,10 +532,10 @@ describe Braintree::Customer do
395
532
  :billing_address => {
396
533
  :country_code_alpha3 => "zzz",
397
534
  }
398
- }
535
+ },
399
536
  )
400
537
  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)
538
+ result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_alpha3).map { |e| e.code }.should include(Braintree::ErrorCodes::Address::CountryCodeAlpha3IsNotAccepted)
402
539
  end
403
540
 
404
541
  it "returns an error if country code numeric is invalid" do
@@ -411,10 +548,10 @@ describe Braintree::Customer do
411
548
  :billing_address => {
412
549
  :country_code_numeric => "zzz",
413
550
  }
414
- }
551
+ },
415
552
  )
416
553
  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)
554
+ result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_numeric).map { |e| e.code }.should include(Braintree::ErrorCodes::Address::CountryCodeNumericIsNotAccepted)
418
555
  end
419
556
 
420
557
  it "returns errors if custom_fields are not registered" do
@@ -423,7 +560,7 @@ describe Braintree::Customer do
423
560
  :last_name => "Kennedy",
424
561
  :custom_fields => {
425
562
  :spouse_name => "Jacqueline"
426
- }
563
+ },
427
564
  )
428
565
  result.success?.should == false
429
566
  result.errors.for(:customer).on(:custom_fields)[0].message.should == "Custom field is invalid: spouse_name."
@@ -436,7 +573,7 @@ describe Braintree::Customer do
436
573
  :last_name => "Hamlin",
437
574
  :credit_card => {
438
575
  :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::VisaPaymentMethodCode
439
- }
576
+ },
440
577
  )
441
578
  result.success?.should == true
442
579
  result.customer.credit_cards.first.bin.should == "400934"
@@ -453,7 +590,7 @@ describe Braintree::Customer do
453
590
  :options => {
454
591
  :venmo_sdk_session => Braintree::Test::VenmoSDK::Session
455
592
  }
456
- }
593
+ },
457
594
  )
458
595
  result.success?.should == true
459
596
  result.customer.credit_cards.first.venmo_sdk?.should == false
@@ -468,13 +605,13 @@ describe Braintree::Customer do
468
605
  :expiration_month => "11",
469
606
  :expiration_year => "2099",
470
607
  },
471
- :share => true
608
+ :share => true,
472
609
  )
473
610
 
474
611
  result = Braintree::Customer.create(
475
612
  :credit_card => {
476
613
  :payment_method_nonce => nonce
477
- }
614
+ },
478
615
  )
479
616
 
480
617
  result.success?.should == true
@@ -504,7 +641,7 @@ describe Braintree::Customer do
504
641
  :number => Braintree::Test::CreditCardNumbers::Hiper,
505
642
  :expiration_month => "11",
506
643
  :expiration_year => "2099",
507
- }
644
+ },
508
645
  )
509
646
  result = Braintree::Customer.create(
510
647
  :payment_method_nonce => nonce,
@@ -514,7 +651,7 @@ describe Braintree::Customer do
514
651
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
515
652
  :verification_account_type => "debit",
516
653
  }
517
- }
654
+ },
518
655
  )
519
656
 
520
657
  expect(result).to be_success
@@ -526,7 +663,7 @@ describe Braintree::Customer do
526
663
  :number => Braintree::Test::CreditCardNumbers::Hiper,
527
664
  :expiration_month => "11",
528
665
  :expiration_year => "2099",
529
- }
666
+ },
530
667
  )
531
668
  result = Braintree::Customer.create(
532
669
  :payment_method_nonce => nonce,
@@ -536,7 +673,7 @@ describe Braintree::Customer do
536
673
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
537
674
  :verification_account_type => "credit",
538
675
  }
539
- }
676
+ },
540
677
  )
541
678
 
542
679
  expect(result).to be_success
@@ -548,7 +685,7 @@ describe Braintree::Customer do
548
685
  :number => Braintree::Test::CreditCardNumbers::Hiper,
549
686
  :expiration_month => "11",
550
687
  :expiration_year => "2099",
551
- }
688
+ },
552
689
  )
553
690
  result = Braintree::Customer.create(
554
691
  :payment_method_nonce => nonce,
@@ -558,7 +695,7 @@ describe Braintree::Customer do
558
695
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
559
696
  :verification_account_type => "ach",
560
697
  }
561
- }
698
+ },
562
699
  )
563
700
 
564
701
  expect(result).to_not be_success
@@ -571,7 +708,7 @@ describe Braintree::Customer do
571
708
  :number => Braintree::Test::CreditCardNumbers::Visa,
572
709
  :expiration_month => "11",
573
710
  :expiration_year => "2099",
574
- }
711
+ },
575
712
  )
576
713
  result = Braintree::Customer.create(
577
714
  :payment_method_nonce => nonce,
@@ -580,7 +717,7 @@ describe Braintree::Customer do
580
717
  :verify_card => true,
581
718
  :verification_account_type => "credit",
582
719
  }
583
- }
720
+ },
584
721
  )
585
722
 
586
723
  expect(result).to_not be_success
@@ -593,7 +730,7 @@ describe Braintree::Customer do
593
730
  it "returns the customer if successful" do
594
731
  customer = Braintree::Customer.create!(
595
732
  :first_name => "Jim",
596
- :last_name => "Smith"
733
+ :last_name => "Smith",
597
734
  )
598
735
  customer.id.should =~ /\d+/
599
736
  customer.first_name.should == "Jim"
@@ -618,7 +755,7 @@ describe Braintree::Customer do
618
755
  :credit_card => {
619
756
  :number => Braintree::Test::CreditCardNumbers::Visa,
620
757
  :expiration_date => "05/2010"
621
- }
758
+ },
622
759
  )
623
760
  result = Braintree::Customer.credit(customer.id, :amount => "100.00")
624
761
  result.success?.should == true
@@ -638,7 +775,7 @@ describe Braintree::Customer do
638
775
  :credit_card => {
639
776
  :number => Braintree::Test::CreditCardNumbers::Visa,
640
777
  :expiration_date => "05/2010"
641
- }
778
+ },
642
779
  )
643
780
  transaction = Braintree::Customer.credit!(customer.id, :amount => "100.00")
644
781
  transaction.amount.should == BigDecimal("100.00")
@@ -657,7 +794,7 @@ describe Braintree::Customer do
657
794
  :credit_card => {
658
795
  :number => Braintree::Test::CreditCardNumbers::Visa,
659
796
  :expiration_date => "05/2010"
660
- }
797
+ },
661
798
  )
662
799
  result = Braintree::Customer.sale(customer.id, :amount => "100.00")
663
800
  result.success?.should == true
@@ -677,7 +814,7 @@ describe Braintree::Customer do
677
814
  :credit_card => {
678
815
  :number => Braintree::Test::CreditCardNumbers::Visa,
679
816
  :expiration_date => "05/2010"
680
- }
817
+ },
681
818
  )
682
819
  transaction = Braintree::Customer.sale!(customer.id, :amount => "100.00")
683
820
  transaction.amount.should == BigDecimal("100.00")
@@ -696,80 +833,24 @@ describe Braintree::Customer do
696
833
  :credit_card => {
697
834
  :number => Braintree::Test::CreditCardNumbers::Visa,
698
835
  :expiration_date => "05/2010"
699
- }
836
+ },
700
837
  )
701
- transaction = customer.sale!(:amount => "100.00")
838
+ transaction = Braintree::Customer.sale!(customer.id, :amount => "100.00")
702
839
  collection = Braintree::Customer.transactions(customer.id)
703
840
  collection.first.should == transaction
704
841
  end
705
842
  end
706
843
 
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
760
- end
761
- end
762
-
763
844
  describe "credit" do
764
845
  it "creates a credit transaction using the customer, returning a result object" do
765
846
  customer = Braintree::Customer.create!(
766
847
  :credit_card => {
767
848
  :number => Braintree::Test::CreditCardNumbers::Visa,
768
849
  :expiration_date => "05/2010"
769
- }
850
+ },
770
851
  )
771
852
  result = customer.credit(
772
- :amount => "100.00"
853
+ :amount => "100.00",
773
854
  )
774
855
  result.success?.should == true
775
856
  result.transaction.amount.should == BigDecimal("100.00")
@@ -788,7 +869,7 @@ describe Braintree::Customer do
788
869
  :credit_card => {
789
870
  :number => Braintree::Test::CreditCardNumbers::Visa,
790
871
  :expiration_date => "05/2010"
791
- }
872
+ },
792
873
  )
793
874
  transaction = customer.credit!(:amount => "100.00")
794
875
  transaction.amount.should == BigDecimal("100.00")
@@ -801,72 +882,11 @@ describe Braintree::Customer do
801
882
  end
802
883
  end
803
884
 
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"
862
- end
863
- end
864
-
865
885
  describe "delete" do
866
886
  it "deletes the customer" do
867
887
  result = Braintree::Customer.create(
868
888
  :first_name => "Joe",
869
- :last_name => "Cool"
889
+ :last_name => "Cool",
870
890
  )
871
891
  result.success?.should == true
872
892
 
@@ -883,7 +903,7 @@ describe Braintree::Customer do
883
903
  it "finds the customer with the given id" do
884
904
  result = Braintree::Customer.create(
885
905
  :first_name => "Joe",
886
- :last_name => "Cool"
906
+ :last_name => "Cool",
887
907
  )
888
908
  result.success?.should == true
889
909
 
@@ -899,13 +919,13 @@ describe Braintree::Customer do
899
919
  credit_card = Braintree::CreditCard.create(
900
920
  :customer_id => customer.id,
901
921
  :number => Braintree::Test::CreditCardNumbers::Visa,
902
- :expiration_date => "05/2012"
922
+ :expiration_date => "05/2012",
903
923
  ).credit_card
904
924
 
905
925
  subscription = Braintree::Subscription.create(
906
926
  :payment_method_token => credit_card.token,
907
927
  :plan_id => "integration_trialless_plan",
908
- :price => "1.00"
928
+ :price => "1.00",
909
929
  ).subscription
910
930
 
911
931
  found_customer = Braintree::Customer.find(customer.id)
@@ -920,7 +940,7 @@ describe Braintree::Customer do
920
940
  customer = Braintree::Customer.create(
921
941
  :custom_fields => {
922
942
  :store_me => "custom value"
923
- }
943
+ },
924
944
  ).customer
925
945
  credit_card = Braintree::CreditCard.create(
926
946
  :customer_id => customer.id,
@@ -932,13 +952,13 @@ describe Braintree::Customer do
932
952
  :region => "Illinois",
933
953
  :postal_code => "60622",
934
954
  :country_name => "United States of America"
935
- }
955
+ },
936
956
  ).credit_card
937
957
 
938
958
  subscription = Braintree::Subscription.create(
939
959
  :payment_method_token => credit_card.token,
940
960
  :plan_id => "integration_trialless_plan",
941
- :price => "1.00"
961
+ :price => "1.00",
942
962
  ).subscription
943
963
 
944
964
  found_customer = Braintree::Customer.find(customer.id, {
@@ -954,7 +974,7 @@ describe Braintree::Customer do
954
974
  customer = Braintree::Customer.create(
955
975
  :custom_fields => {
956
976
  :store_me => "custom value"
957
- }
977
+ },
958
978
  ).customer
959
979
  credit_card = Braintree::CreditCard.create(
960
980
  :customer_id => customer.id,
@@ -966,13 +986,13 @@ describe Braintree::Customer do
966
986
  :region => "Illinois",
967
987
  :postal_code => "60622",
968
988
  :country_name => "United States of America"
969
- }
989
+ },
970
990
  ).credit_card
971
991
 
972
992
  subscription = Braintree::Subscription.create(
973
993
  :payment_method_token => credit_card.token,
974
994
  :plan_id => "integration_trialless_plan",
975
- :price => "1.00"
995
+ :price => "1.00",
976
996
  ).subscription
977
997
 
978
998
  found_customer = Braintree::Customer.find(customer.id, {
@@ -990,7 +1010,7 @@ describe Braintree::Customer do
990
1010
 
991
1011
  it "returns associated ApplePayCards" do
992
1012
  result = Braintree::Customer.create(
993
- :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx
1013
+ :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
994
1014
  )
995
1015
  result.success?.should == true
996
1016
 
@@ -1001,58 +1021,70 @@ describe Braintree::Customer do
1001
1021
  apple_pay_card.token.should_not be_nil
1002
1022
  apple_pay_card.expiration_year.should_not be_nil
1003
1023
  apple_pay_card.payment_instrument_name.should == "AmEx 41002"
1004
- end
1005
-
1006
- it "returns associated android pay proxy cards" do
1007
- result = Braintree::Customer.create(
1008
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover
1009
- )
1010
- result.success?.should == true
1011
-
1012
- found_customer = Braintree::Customer.find(result.customer.id)
1013
- found_customer.android_pay_cards.size.should == 1
1014
- found_customer.payment_methods.size.should == 1
1015
- android_pay_card = found_customer.android_pay_cards.first
1016
- android_pay_card.should be_a Braintree::AndroidPayCard
1017
- android_pay_card.token.should_not be_nil
1018
- android_pay_card.expiration_year.should_not be_nil
1019
- android_pay_card.is_network_tokenized?.should == false
1020
- end
1021
-
1022
- it "returns associated android pay network tokens" do
1024
+ apple_pay_card.commercial.should_not be_nil
1025
+ apple_pay_card.country_of_issuance.should_not be_nil
1026
+ apple_pay_card.debit.should_not be_nil
1027
+ apple_pay_card.durbin_regulated.should_not be_nil
1028
+ apple_pay_card.healthcare.should_not be_nil
1029
+ apple_pay_card.issuing_bank.should_not be_nil
1030
+ apple_pay_card.payroll.should_not be_nil
1031
+ apple_pay_card.prepaid.should_not be_nil
1032
+ apple_pay_card.product_id.should_not be_nil
1033
+ end
1034
+
1035
+ it "returns associated google pay proxy cards" do
1023
1036
  result = Braintree::Customer.create(
1024
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayMasterCard
1037
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
1025
1038
  )
1026
1039
  result.success?.should == true
1027
1040
 
1028
1041
  found_customer = Braintree::Customer.find(result.customer.id)
1029
- found_customer.android_pay_cards.size.should == 1
1042
+ found_customer.google_pay_cards.size.should == 1
1030
1043
  found_customer.payment_methods.size.should == 1
1031
- android_pay_card = found_customer.android_pay_cards.first
1032
- android_pay_card.should be_a Braintree::AndroidPayCard
1033
- android_pay_card.token.should_not be_nil
1034
- android_pay_card.expiration_year.should_not be_nil
1035
- android_pay_card.is_network_tokenized?.should == true
1036
- end
1037
-
1038
- it "returns associated amex express checkout cards" do
1044
+ google_pay_card = found_customer.google_pay_cards.first
1045
+ google_pay_card.should be_a Braintree::GooglePayCard
1046
+ google_pay_card.token.should_not be_nil
1047
+ google_pay_card.expiration_year.should_not be_nil
1048
+ google_pay_card.is_network_tokenized?.should == false
1049
+ google_pay_card.commercial.should_not be_nil
1050
+ google_pay_card.country_of_issuance.should_not be_nil
1051
+ google_pay_card.debit.should_not be_nil
1052
+ google_pay_card.durbin_regulated.should_not be_nil
1053
+ google_pay_card.healthcare.should_not be_nil
1054
+ google_pay_card.issuing_bank.should_not be_nil
1055
+ google_pay_card.payroll.should_not be_nil
1056
+ google_pay_card.prepaid.should_not be_nil
1057
+ google_pay_card.product_id.should_not be_nil
1058
+ end
1059
+
1060
+ it "returns associated google pay network tokens" do
1039
1061
  result = Braintree::Customer.create(
1040
- :payment_method_nonce => Braintree::Test::Nonce::AmexExpressCheckout
1062
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
1041
1063
  )
1042
1064
  result.success?.should == true
1043
1065
 
1044
1066
  found_customer = Braintree::Customer.find(result.customer.id)
1045
- found_customer.amex_express_checkout_cards.size.should == 1
1067
+ found_customer.google_pay_cards.size.should == 1
1046
1068
  found_customer.payment_methods.size.should == 1
1047
- amex_express_checkout_card = found_customer.amex_express_checkout_cards.first
1048
- amex_express_checkout_card.should be_a Braintree::AmexExpressCheckoutCard
1049
- amex_express_checkout_card.token.should_not be_nil
1050
- amex_express_checkout_card.expiration_year.should_not be_nil
1069
+ google_pay_card = found_customer.google_pay_cards.first
1070
+ google_pay_card.should be_a Braintree::GooglePayCard
1071
+ google_pay_card.token.should_not be_nil
1072
+ google_pay_card.expiration_year.should_not be_nil
1073
+ google_pay_card.is_network_tokenized?.should == true
1074
+ google_pay_card.commercial.should_not be_nil
1075
+ google_pay_card.country_of_issuance.should_not be_nil
1076
+ google_pay_card.debit.should_not be_nil
1077
+ google_pay_card.durbin_regulated.should_not be_nil
1078
+ google_pay_card.healthcare.should_not be_nil
1079
+ google_pay_card.issuing_bank.should_not be_nil
1080
+ google_pay_card.payroll.should_not be_nil
1081
+ google_pay_card.prepaid.should_not be_nil
1082
+ google_pay_card.product_id.should_not be_nil
1051
1083
  end
1052
1084
 
1053
1085
  it "returns associated venmo accounts" do
1054
1086
  result = Braintree::Customer.create(
1055
- :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount
1087
+ :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
1056
1088
  )
1057
1089
  result.success?.should == true
1058
1090
 
@@ -1072,7 +1104,7 @@ describe Braintree::Customer do
1072
1104
  :options => {
1073
1105
  :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
1074
1106
  }
1075
- }
1107
+ },
1076
1108
  )
1077
1109
  result.should be_success
1078
1110
 
@@ -1118,7 +1150,7 @@ describe Braintree::Customer do
1118
1150
  it "updates the credit card with three_d_secure pass thru params" do
1119
1151
  customer = Braintree::Customer.create!(
1120
1152
  :first_name => "Joe",
1121
- :last_name => "Cool"
1153
+ :last_name => "Cool",
1122
1154
  )
1123
1155
  result = Braintree::Customer.update(
1124
1156
  customer.id,
@@ -1131,17 +1163,17 @@ describe Braintree::Customer do
1131
1163
  :number => 4111111111111111,
1132
1164
  :expiration_date => "05/2060",
1133
1165
  :three_d_secure_pass_thru => {
1134
- :eci_flag => '02',
1135
- :cavv => 'some_cavv',
1136
- :xid => 'some_xid',
1137
- :three_d_secure_version => '1.0.2',
1138
- :authentication_response => 'Y',
1139
- :directory_response => 'Y',
1140
- :cavv_algorithm => '2',
1141
- :ds_transaction_id => 'some_ds_transaction_id',
1166
+ :eci_flag => "02",
1167
+ :cavv => "some_cavv",
1168
+ :xid => "some_xid",
1169
+ :three_d_secure_version => "1.0.2",
1170
+ :authentication_response => "Y",
1171
+ :directory_response => "Y",
1172
+ :cavv_algorithm => "2",
1173
+ :ds_transaction_id => "some_ds_transaction_id",
1142
1174
  },
1143
1175
  :options => {:verify_card => true},
1144
- }
1176
+ },
1145
1177
  )
1146
1178
  result.success?.should == true
1147
1179
  result.customer.id.should == customer.id
@@ -1153,7 +1185,7 @@ describe Braintree::Customer do
1153
1185
  it "validates the presence of three_d_secure_version while passing three_d_secure_pass_thru in update" do
1154
1186
  customer = Braintree::Customer.create!(
1155
1187
  :first_name => "Joe",
1156
- :last_name => "Cool"
1188
+ :last_name => "Cool",
1157
1189
  )
1158
1190
  result = Braintree::Customer.update(
1159
1191
  customer.id,
@@ -1166,16 +1198,16 @@ describe Braintree::Customer do
1166
1198
  :number => 4111111111111111,
1167
1199
  :expiration_date => "05/2060",
1168
1200
  :three_d_secure_pass_thru => {
1169
- :eci_flag => '02',
1170
- :cavv => 'some_cavv',
1171
- :xid => 'some_xid',
1172
- :authentication_response => 'Y',
1173
- :directory_response => 'Y',
1174
- :cavv_algorithm => '2',
1175
- :ds_transaction_id => 'some_ds_transaction_id',
1201
+ :eci_flag => "02",
1202
+ :cavv => "some_cavv",
1203
+ :xid => "some_xid",
1204
+ :authentication_response => "Y",
1205
+ :directory_response => "Y",
1206
+ :cavv_algorithm => "2",
1207
+ :ds_transaction_id => "some_ds_transaction_id",
1176
1208
  },
1177
1209
  options: {:verify_card => true}
1178
- }
1210
+ },
1179
1211
  )
1180
1212
  expect(result).to_not be_success
1181
1213
  error = result.errors.for(:verification).first
@@ -1186,7 +1218,7 @@ describe Braintree::Customer do
1186
1218
  it "updates the customer with the given id if successful" do
1187
1219
  customer = Braintree::Customer.create!(
1188
1220
  :first_name => "Joe",
1189
- :last_name => "Cool"
1221
+ :last_name => "Cool",
1190
1222
  )
1191
1223
  result = Braintree::Customer.update(
1192
1224
  customer.id,
@@ -1194,7 +1226,7 @@ describe Braintree::Customer do
1194
1226
  :last_name => "Super Cool",
1195
1227
  :custom_fields => {
1196
1228
  :store_me => "a value"
1197
- }
1229
+ },
1198
1230
  )
1199
1231
  result.success?.should == true
1200
1232
  result.customer.id.should == customer.id
@@ -1208,7 +1240,7 @@ describe Braintree::Customer do
1208
1240
  :credit_card => {
1209
1241
  :number => 4111111111111111,
1210
1242
  :expiration_date => "05/2010",
1211
- }
1243
+ },
1212
1244
  )
1213
1245
  result = Braintree::Customer.update(
1214
1246
  customer.id,
@@ -1218,7 +1250,7 @@ describe Braintree::Customer do
1218
1250
  :options=> {
1219
1251
  :fail_on_duplicate_payment_method => true
1220
1252
  }
1221
- }
1253
+ },
1222
1254
  )
1223
1255
  result.success?.should == false
1224
1256
  result.errors.for(:customer).for(:credit_card).on(:number)[0].message.should == "Duplicate card exists in the vault."
@@ -1227,7 +1259,7 @@ describe Braintree::Customer do
1227
1259
  it "updates the default payment method" do
1228
1260
  customer = Braintree::Customer.create!(
1229
1261
  :first_name => "Joe",
1230
- :last_name => "Brown"
1262
+ :last_name => "Brown",
1231
1263
  )
1232
1264
 
1233
1265
  token1 = random_payment_method_token
@@ -1235,7 +1267,7 @@ describe Braintree::Customer do
1235
1267
  payment_method1 = Braintree::PaymentMethod.create(
1236
1268
  :customer_id => customer.id,
1237
1269
  :payment_method_nonce => Braintree::Test::Nonce::TransactableVisa,
1238
- :token => token1
1270
+ :token => token1,
1239
1271
  )
1240
1272
 
1241
1273
  payment_method1 = Braintree::PaymentMethod.find(token1)
@@ -1246,11 +1278,11 @@ describe Braintree::Customer do
1246
1278
  payment_method2 = Braintree::PaymentMethod.create(
1247
1279
  :customer_id => customer.id,
1248
1280
  :payment_method_nonce => Braintree::Test::Nonce::TransactableMasterCard,
1249
- :token => token2
1281
+ :token => token2,
1250
1282
  )
1251
1283
 
1252
1284
  Braintree::Customer.update(customer.id,
1253
- :default_payment_method_token => token2
1285
+ :default_payment_method_token => token2,
1254
1286
  )
1255
1287
 
1256
1288
  payment_method2 = Braintree::PaymentMethod.find(token2)
@@ -1260,7 +1292,7 @@ describe Braintree::Customer do
1260
1292
  it "updates the default payment method in the options" do
1261
1293
  customer = Braintree::Customer.create!(
1262
1294
  :first_name => "Joe",
1263
- :last_name => "Brown"
1295
+ :last_name => "Brown",
1264
1296
  )
1265
1297
 
1266
1298
  token1 = random_payment_method_token
@@ -1268,7 +1300,7 @@ describe Braintree::Customer do
1268
1300
  payment_method1 = Braintree::PaymentMethod.create(
1269
1301
  :customer_id => customer.id,
1270
1302
  :payment_method_nonce => Braintree::Test::Nonce::TransactableVisa,
1271
- :token => token1
1303
+ :token => token1,
1272
1304
  )
1273
1305
 
1274
1306
  payment_method1 = Braintree::PaymentMethod.find(token1)
@@ -1279,7 +1311,7 @@ describe Braintree::Customer do
1279
1311
  payment_method2 = Braintree::PaymentMethod.create(
1280
1312
  :customer_id => customer.id,
1281
1313
  :payment_method_nonce => Braintree::Test::Nonce::TransactableMasterCard,
1282
- :token => token2
1314
+ :token => token2,
1283
1315
  )
1284
1316
 
1285
1317
  Braintree::Customer.update(customer.id,
@@ -1288,7 +1320,7 @@ describe Braintree::Customer do
1288
1320
  :update_existing_token => token2,
1289
1321
  :make_default => true
1290
1322
  }
1291
- }
1323
+ },
1292
1324
  )
1293
1325
 
1294
1326
  payment_method2 = Braintree::PaymentMethod.find(token2)
@@ -1298,7 +1330,7 @@ describe Braintree::Customer do
1298
1330
  it "can use any country code" do
1299
1331
  customer = Braintree::Customer.create!(
1300
1332
  :first_name => "Alex",
1301
- :last_name => "Matterson"
1333
+ :last_name => "Matterson",
1302
1334
  )
1303
1335
  result = Braintree::Customer.update(
1304
1336
  customer.id,
@@ -1313,7 +1345,7 @@ describe Braintree::Customer do
1313
1345
  :country_code_alpha3 => "FJI",
1314
1346
  :country_code_numeric => "242"
1315
1347
  }
1316
- }
1348
+ },
1317
1349
  )
1318
1350
  result.success?.should == true
1319
1351
  result.customer.addresses[0].country_name.should == "Fiji"
@@ -1332,7 +1364,7 @@ describe Braintree::Customer do
1332
1364
  :first_name => "Joe",
1333
1365
  :postal_code => "60622"
1334
1366
  }
1335
- }
1367
+ },
1336
1368
  )
1337
1369
 
1338
1370
  result = Braintree::Customer.update(
@@ -1340,13 +1372,13 @@ describe Braintree::Customer do
1340
1372
  :first_name => "New Joe",
1341
1373
  :credit_card => {
1342
1374
  :cardholder_name => "New Joe Cardholder",
1343
- :options => { :update_existing_token => customer.credit_cards.first.token },
1375
+ :options => {:update_existing_token => customer.credit_cards.first.token},
1344
1376
  :billing_address => {
1345
1377
  :last_name => "Cool",
1346
1378
  :postal_code => "60666",
1347
- :options => { :update_existing => true }
1379
+ :options => {:update_existing => true}
1348
1380
  }
1349
- }
1381
+ },
1350
1382
  )
1351
1383
  result.success?.should == true
1352
1384
  result.customer.id.should == customer.id
@@ -1364,7 +1396,7 @@ describe Braintree::Customer do
1364
1396
 
1365
1397
  it "can update the customer and verify_card with a specific verification_amount" do
1366
1398
  customer = Braintree::Customer.create!(
1367
- :first_name => "Joe"
1399
+ :first_name => "Joe",
1368
1400
  )
1369
1401
 
1370
1402
  result = Braintree::Customer.update(
@@ -1374,8 +1406,73 @@ describe Braintree::Customer do
1374
1406
  :cardholder_name => "New Joe Cardholder",
1375
1407
  :number => Braintree::Test::CreditCardNumbers::Visa,
1376
1408
  :expiration_date => "12/2009",
1377
- :options => { :verify_card => true, :verification_amount => "2.00" }
1378
- }
1409
+ :options => {:verify_card => true, :verification_amount => "2.00"}
1410
+ },
1411
+ )
1412
+ result.success?.should == true
1413
+ end
1414
+
1415
+ it "includes risk data when skip_advanced_fraud_checking is false" do
1416
+ with_fraud_protection_enterprise_merchant do
1417
+ customer = Braintree::Customer.create!(
1418
+ :first_name => "Joe",
1419
+ )
1420
+
1421
+ updated_result = Braintree::Customer.update(
1422
+ customer.id,
1423
+ :credit_card => {
1424
+ :cardholder_name => "New Joe Cardholder",
1425
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1426
+ :expiration_date => "12/2009",
1427
+ :options => {
1428
+ :skip_advanced_fraud_checking => false,
1429
+ :verify_card => true,
1430
+ },
1431
+ },
1432
+ )
1433
+
1434
+ expect(updated_result).to be_success
1435
+ verification = updated_result.customer.credit_cards.first.verification
1436
+ expect(verification.risk_data).not_to be_nil
1437
+ end
1438
+ end
1439
+
1440
+ it "does not include risk data when skip_advanced_fraud_checking is true" do
1441
+ with_fraud_protection_enterprise_merchant do
1442
+ customer = Braintree::Customer.create!(
1443
+ :first_name => "Joe",
1444
+ )
1445
+
1446
+ updated_result = Braintree::Customer.update(
1447
+ customer.id,
1448
+ :credit_card => {
1449
+ :cardholder_name => "New Joe Cardholder",
1450
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1451
+ :expiration_date => "12/2009",
1452
+ :options => {
1453
+ :skip_advanced_fraud_checking => true,
1454
+ :verify_card => true,
1455
+ },
1456
+ },
1457
+ )
1458
+
1459
+ expect(updated_result).to be_success
1460
+ verification = updated_result.customer.credit_cards.first.verification
1461
+ expect(verification.risk_data).to be_nil
1462
+ end
1463
+ end
1464
+
1465
+ it "can update a tax_identifier" do
1466
+ customer = Braintree::Customer.create!(
1467
+ :tax_identifiers => [
1468
+ {:country_code => "US", :identifier => "987654321"},
1469
+ {:country_code => "CL", :identifier => "123456789"}
1470
+ ],
1471
+ )
1472
+
1473
+ result = Braintree::Customer.update(
1474
+ customer.id,
1475
+ :tax_identifiers => [{:country_code => "US", :identifier => "567891234"}],
1379
1476
  )
1380
1477
  result.success?.should == true
1381
1478
  end
@@ -1385,17 +1482,17 @@ describe Braintree::Customer do
1385
1482
  :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1386
1483
  :credit_card => {
1387
1484
  :three_d_secure_pass_thru => {
1388
- :eci_flag => '02',
1389
- :cavv => 'some_cavv',
1390
- :xid => 'some_xid',
1391
- :three_d_secure_version => 'xx',
1392
- :authentication_response => 'Y',
1393
- :directory_response => 'Y',
1394
- :cavv_algorithm => '2',
1395
- :ds_transaction_id => 'some_ds_transaction_id',
1485
+ :eci_flag => "02",
1486
+ :cavv => "some_cavv",
1487
+ :xid => "some_xid",
1488
+ :three_d_secure_version => "xx",
1489
+ :authentication_response => "Y",
1490
+ :directory_response => "Y",
1491
+ :cavv_algorithm => "2",
1492
+ :ds_transaction_id => "some_ds_transaction_id",
1396
1493
  },
1397
1494
  :options => {:verify_card => true}
1398
- }
1495
+ },
1399
1496
  )
1400
1497
 
1401
1498
  expect(result).not_to be_success
@@ -1409,17 +1506,17 @@ describe Braintree::Customer do
1409
1506
  :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1410
1507
  :credit_card => {
1411
1508
  :three_d_secure_pass_thru => {
1412
- :eci_flag => '02',
1413
- :cavv => 'some_cavv',
1414
- :xid => 'some_xid',
1415
- :three_d_secure_version => '2.2.1',
1416
- :authentication_response => 'Y',
1417
- :directory_response => 'Y',
1418
- :cavv_algorithm => '2',
1419
- :ds_transaction_id => 'some_ds_transaction_id',
1509
+ :eci_flag => "02",
1510
+ :cavv => "some_cavv",
1511
+ :xid => "some_xid",
1512
+ :three_d_secure_version => "2.2.1",
1513
+ :authentication_response => "Y",
1514
+ :directory_response => "Y",
1515
+ :cavv_algorithm => "2",
1516
+ :ds_transaction_id => "some_ds_transaction_id",
1420
1517
  },
1421
1518
  :options => {:verify_card => true}
1422
- }
1519
+ },
1423
1520
  )
1424
1521
 
1425
1522
  expect(result).to be_success
@@ -1430,7 +1527,7 @@ describe Braintree::Customer do
1430
1527
  :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1431
1528
  :credit_card => {
1432
1529
  :options => {:verify_card => true}
1433
- }
1530
+ },
1434
1531
  )
1435
1532
  result.success?.should == true
1436
1533
 
@@ -1452,7 +1549,7 @@ describe Braintree::Customer do
1452
1549
  address = Braintree::Address.create!(
1453
1550
  :customer_id => customer.id,
1454
1551
  :first_name => "John",
1455
- :last_name => "Doe"
1552
+ :last_name => "Doe",
1456
1553
  )
1457
1554
 
1458
1555
  customer = Braintree::Customer.update(
@@ -1461,7 +1558,7 @@ describe Braintree::Customer do
1461
1558
  :number => Braintree::Test::CreditCardNumbers::Visa,
1462
1559
  :expiration_date => "12/2009",
1463
1560
  :billing_address_id => address.id
1464
- }
1561
+ },
1465
1562
  ).customer
1466
1563
 
1467
1564
  billing_address = customer.credit_cards.first.billing_address
@@ -1474,12 +1571,93 @@ describe Braintree::Customer do
1474
1571
  customer = Braintree::Customer.create!(:email => "valid@email.com")
1475
1572
  result = Braintree::Customer.update(
1476
1573
  customer.id,
1477
- :email => "@invalid.com"
1574
+ :email => "@invalid.com",
1478
1575
  )
1479
1576
  result.success?.should == false
1480
1577
  result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
1481
1578
  end
1482
1579
 
1580
+ context "verification_currency_iso_code" do
1581
+ it "can update the customer after validating verification_currency_iso_code" do
1582
+ customer = Braintree::Customer.create!(
1583
+ :first_name => "Joe",
1584
+ )
1585
+
1586
+ result = Braintree::Customer.update(
1587
+ customer.id,
1588
+ :first_name => "New Joe",
1589
+ :credit_card => {
1590
+ :cardholder_name => "New Joe Cardholder",
1591
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1592
+ :expiration_date => "12/2009",
1593
+ :options => {:verify_card => true, :verification_currency_iso_code => "USD"}
1594
+ },
1595
+ )
1596
+ result.success?.should == true
1597
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
1598
+ end
1599
+
1600
+ it "can update the customer after validating verification_currency_iso_code against the given verification_merchant_account_id" do
1601
+ customer = Braintree::Customer.create!(
1602
+ :first_name => "Joe",
1603
+ )
1604
+
1605
+ result = Braintree::Customer.update(
1606
+ customer.id,
1607
+ :first_name => "New Joe",
1608
+ :credit_card => {
1609
+ :cardholder_name => "New Joe Cardholder",
1610
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1611
+ :expiration_date => "12/2009",
1612
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "USD"}
1613
+ },
1614
+ )
1615
+ result.success?.should == true
1616
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
1617
+ result.customer.credit_cards[0].verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
1618
+ end
1619
+
1620
+ it "throws error due to verification_currency_iso_code not matching against the currency configured in default merchant account" do
1621
+ customer = Braintree::Customer.create!(
1622
+ :first_name => "Joe",
1623
+ )
1624
+
1625
+ result = Braintree::Customer.update(
1626
+ customer.id,
1627
+ :first_name => "New Joe",
1628
+ :credit_card => {
1629
+ :cardholder_name => "New Joe Cardholder",
1630
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1631
+ :expiration_date => "12/2009",
1632
+ :options => {:verify_card => true, :verification_currency_iso_code => "GBP"}
1633
+ },
1634
+ )
1635
+ result.success?.should == false
1636
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1637
+
1638
+ end
1639
+
1640
+ it "throws error due to verification_currency_iso_code not matching against the currency configured in the given verification merchant account" do
1641
+ customer = Braintree::Customer.create!(
1642
+ :first_name => "Joe",
1643
+ )
1644
+
1645
+ result = Braintree::Customer.update(
1646
+ customer.id,
1647
+ :first_name => "New Joe",
1648
+ :credit_card => {
1649
+ :cardholder_name => "New Joe Cardholder",
1650
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1651
+ :expiration_date => "12/2009",
1652
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "GBP"}
1653
+ },
1654
+ )
1655
+ result.success?.should == false
1656
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1657
+
1658
+ end
1659
+ end
1660
+
1483
1661
  context "verification_account_type" do
1484
1662
  it "updates the credit card with account_type credit" do
1485
1663
  customer = Braintree::Customer.create!
@@ -1495,7 +1673,7 @@ describe Braintree::Customer do
1495
1673
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
1496
1674
  :verification_account_type => "credit",
1497
1675
  },
1498
- }
1676
+ },
1499
1677
  )
1500
1678
  expect(update_result).to be_success
1501
1679
  end
@@ -1514,7 +1692,7 @@ describe Braintree::Customer do
1514
1692
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
1515
1693
  :verification_account_type => "debit",
1516
1694
  },
1517
- }
1695
+ },
1518
1696
  )
1519
1697
  expect(update_result).to be_success
1520
1698
  end
@@ -1525,12 +1703,12 @@ describe Braintree::Customer do
1525
1703
  it "returns the updated customer if successful" do
1526
1704
  customer = Braintree::Customer.create!(
1527
1705
  :first_name => "Joe",
1528
- :last_name => "Cool"
1706
+ :last_name => "Cool",
1529
1707
  )
1530
1708
  updated_customer = Braintree::Customer.update!(
1531
1709
  customer.id,
1532
1710
  :first_name => "Mr. Joe",
1533
- :last_name => "Super Cool"
1711
+ :last_name => "Super Cool",
1534
1712
  )
1535
1713
  updated_customer.first_name.should == "Mr. Joe"
1536
1714
  updated_customer.last_name.should == "Super Cool"
@@ -1545,214 +1723,7 @@ describe Braintree::Customer do
1545
1723
  end
1546
1724
  end
1547
1725
 
1548
- describe "update" do
1549
- it "updates the customer" do
1550
- customer = Braintree::Customer.create!(
1551
- :first_name => "Joe",
1552
- :last_name => "Cool"
1553
- )
1554
- update_result = customer.update(
1555
- :first_name => "Mr. Joe",
1556
- :last_name => "Super Cool"
1557
- )
1558
- update_result.success?.should == true
1559
- update_result.customer.should == customer
1560
- updated_customer = update_result.customer
1561
- updated_customer.first_name.should == "Mr. Joe"
1562
- updated_customer.last_name.should == "Super Cool"
1563
- end
1564
-
1565
- it "returns an error response if invalid" do
1566
- customer = Braintree::Customer.create!(
1567
- :email => "valid@email.com"
1568
- )
1569
- result = customer.update(
1570
- :email => "@invalid.com"
1571
- )
1572
- result.success?.should == false
1573
- result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
1574
- end
1575
- end
1576
-
1577
- describe "update!" do
1578
- it "returns the customer and updates the customer if successful" do
1579
- customer = Braintree::Customer.create!(
1580
- :first_name => "Joe",
1581
- :last_name => "Cool"
1582
- )
1583
- customer.update!(
1584
- :first_name => "Mr. Joe",
1585
- :last_name => "Super Cool"
1586
- ).should == customer
1587
- customer.first_name.should == "Mr. Joe"
1588
- customer.last_name.should == "Super Cool"
1589
- customer.updated_at.between?(Time.now - 60, Time.now).should == true
1590
- end
1591
-
1592
- it "raises an error if unsuccessful" do
1593
- customer = Braintree::Customer.create!(
1594
- :email => "valid@email.com"
1595
- )
1596
- expect do
1597
- customer.update!(:email => "@invalid.com")
1598
- end.to raise_error(Braintree::ValidationsFailed)
1599
- end
1600
- end
1601
-
1602
- describe "update_from_transparent_redirect" do
1603
- it "returns a successful result if successful" do
1604
- result = Braintree::Customer.create(
1605
- :first_name => "Old First",
1606
- :last_name => "Old Last",
1607
- :company => "Old Company",
1608
- :email => "old@email.com",
1609
- :phone => "000.111.2222",
1610
- :fax => "000.222.3333",
1611
- :website => "old.website.com"
1612
- )
1613
- result.success?.should == true
1614
- original_customer = result.customer
1615
- params = {
1616
- :customer => {
1617
- :first_name => "New First",
1618
- :last_name => "New Last",
1619
- :company => "New Company",
1620
- :email => "new@email.com",
1621
- :phone => "888.111.2222",
1622
- :fax => "999.222.3333",
1623
- :website => "new.website.com"
1624
- }
1625
- }
1626
- tr_data_params = {
1627
- :customer_id => original_customer.id
1628
- }
1629
-
1630
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1631
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Customer.update_customer_url)
1632
- result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
1633
-
1634
- result.success?.should == true
1635
- customer = result.customer
1636
- customer.id.should == original_customer.id
1637
- customer.first_name.should == "New First"
1638
- customer.last_name.should == "New Last"
1639
- customer.company.should == "New Company"
1640
- customer.email.should == "new@email.com"
1641
- customer.phone.should == "888.111.2222"
1642
- customer.fax.should == "999.222.3333"
1643
- customer.website.should == "new.website.com"
1644
- end
1645
-
1646
- it "returns a successful result when updating an existing credit card" do
1647
- result = Braintree::Customer.create(
1648
- :first_name => "Old First",
1649
- :last_name => "Old Last",
1650
- :company => "Old Company",
1651
- :email => "old@email.com",
1652
- :phone => "000.111.2222",
1653
- :fax => "000.222.3333",
1654
- :website => "old.website.com",
1655
- :credit_card => {
1656
- :number => Braintree::Test::CreditCardNumbers::Visa,
1657
- :expiration_date => "12/2009",
1658
- :billing_address => {
1659
- :first_name => "Joe",
1660
- :postal_code => "60622"
1661
- }
1662
- }
1663
- )
1664
- result.success?.should == true
1665
- original_customer = result.customer
1666
-
1667
- tr_data_params = {
1668
- :customer_id => original_customer.id,
1669
- :customer => {
1670
- :first_name => "New First",
1671
- :last_name => "New Last",
1672
- :company => "New Company",
1673
- :email => "new@email.com",
1674
- :phone => "888.111.2222",
1675
- :fax => "999.222.3333",
1676
- :website => "new.website.com",
1677
- :credit_card => {
1678
- :cardholder_name => "New Joe Cardholder",
1679
- :options => { :update_existing_token => original_customer.credit_cards.first.token },
1680
- :billing_address => {
1681
- :last_name => "Cool",
1682
- :postal_code => "60666",
1683
- :options => { :update_existing => true }
1684
- }
1685
- }
1686
- }
1687
- }
1688
-
1689
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1690
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.update_customer_url)
1691
- result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
1692
-
1693
- result.success?.should == true
1694
- customer = result.customer
1695
- customer.id.should == original_customer.id
1696
- customer.first_name.should == "New First"
1697
- customer.last_name.should == "New Last"
1698
- customer.company.should == "New Company"
1699
- customer.email.should == "new@email.com"
1700
- customer.phone.should == "888.111.2222"
1701
- customer.fax.should == "999.222.3333"
1702
- customer.website.should == "new.website.com"
1703
-
1704
- credit_card = customer.credit_cards.first
1705
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa.slice(0, 6)
1706
- credit_card.cardholder_name.should == "New Joe Cardholder"
1707
-
1708
- credit_card.billing_address.first_name.should == "Joe"
1709
- credit_card.billing_address.last_name.should == "Cool"
1710
- credit_card.billing_address.postal_code.should == "60666"
1711
- end
1712
-
1713
- it "can pass any attribute through tr_data" do
1714
- original_customer = Braintree::Customer.create!(
1715
- :first_name => "Old First",
1716
- :last_name => "Old Last",
1717
- :company => "Old Company",
1718
- :email => "old@email.com",
1719
- :phone => "000.111.2222",
1720
- :fax => "000.222.3333",
1721
- :website => "old.website.com"
1722
- )
1723
- new_customer_id = "customer_#{rand(1_000_000)}"
1724
- tr_data_params = {
1725
- :customer_id => original_customer.id,
1726
- :customer => {
1727
- :id => new_customer_id,
1728
- :first_name => "New First",
1729
- :last_name => "New Last",
1730
- :company => "New Company",
1731
- :email => "new@email.com",
1732
- :phone => "888.111.2222",
1733
- :fax => "999.222.3333",
1734
- :website => "new.website.com"
1735
- }
1736
- }
1737
-
1738
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1739
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.update_customer_url)
1740
- result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
1741
-
1742
- result.success?.should == true
1743
- customer = result.customer
1744
- customer.id.should == new_customer_id
1745
- customer.first_name.should == "New First"
1746
- customer.last_name.should == "New Last"
1747
- customer.company.should == "New Company"
1748
- customer.email.should == "new@email.com"
1749
- customer.phone.should == "888.111.2222"
1750
- customer.fax.should == "999.222.3333"
1751
- customer.website.should == "new.website.com"
1752
- end
1753
- end
1754
-
1755
- describe "default_credit_card" do
1726
+ describe "default_payment_method" do
1756
1727
  it "should return the default credit card for a given customer" do
1757
1728
  customer = Braintree::Customer.create!(
1758
1729
  :credit_card => {
@@ -1761,21 +1732,21 @@ describe Braintree::Customer do
1761
1732
  :options => {
1762
1733
  :make_default => false
1763
1734
  }
1764
- }
1735
+ },
1765
1736
  )
1766
1737
 
1767
- default_credit_card = Braintree::CreditCard.create!(
1738
+ default_payment_method = Braintree::CreditCard.create!(
1768
1739
  :customer_id => customer.id,
1769
1740
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1770
1741
  :expiration_date => "11/2015",
1771
1742
  :options => {
1772
1743
  :make_default => true
1773
- }
1744
+ },
1774
1745
  )
1775
1746
 
1776
1747
  customer = Braintree::Customer.find(customer.id)
1777
1748
 
1778
- customer.default_credit_card.should == default_credit_card
1749
+ customer.default_payment_method.should == default_payment_method
1779
1750
  end
1780
1751
  end
1781
1752
 
@@ -1783,7 +1754,7 @@ describe Braintree::Customer do
1783
1754
  context "future" do
1784
1755
  it "creates a customer with a future paypal account" do
1785
1756
  result = Braintree::Customer.create(
1786
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment
1757
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
1787
1758
  )
1788
1759
 
1789
1760
  result.should be_success
@@ -1797,7 +1768,7 @@ describe Braintree::Customer do
1797
1768
  :options => {
1798
1769
  :make_default => true
1799
1770
  }
1800
- }
1771
+ },
1801
1772
  )
1802
1773
 
1803
1774
  paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
@@ -1806,12 +1777,12 @@ describe Braintree::Customer do
1806
1777
  :token => paypal_account_token,
1807
1778
  :options => {
1808
1779
  :make_default => true
1809
- }
1780
+ },
1810
1781
  )
1811
1782
 
1812
1783
  result = Braintree::Customer.update(
1813
1784
  customer.id,
1814
- :payment_method_nonce => nonce
1785
+ :payment_method_nonce => nonce,
1815
1786
  )
1816
1787
 
1817
1788
  result.should be_success
@@ -1827,7 +1798,7 @@ describe Braintree::Customer do
1827
1798
  :token => paypal_account_token,
1828
1799
  :options => {
1829
1800
  :make_default => true
1830
- }
1801
+ },
1831
1802
  )
1832
1803
 
1833
1804
  result = Braintree::Customer.create(
@@ -1863,7 +1834,7 @@ describe Braintree::Customer do
1863
1834
  :options => {
1864
1835
  :make_default => true
1865
1836
  }
1866
- }
1837
+ },
1867
1838
  )
1868
1839
 
1869
1840
  paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
@@ -1872,7 +1843,7 @@ describe Braintree::Customer do
1872
1843
  :token => paypal_account_token,
1873
1844
  :options => {
1874
1845
  :make_default => true
1875
- }
1846
+ },
1876
1847
  )
1877
1848
 
1878
1849
  result = Braintree::Customer.update(
@@ -1906,7 +1877,7 @@ describe Braintree::Customer do
1906
1877
  context "onetime" do
1907
1878
  it "does not create a customer with a onetime paypal account" do
1908
1879
  result = Braintree::Customer.create(
1909
- :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment
1880
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
1910
1881
  )
1911
1882
 
1912
1883
  result.should_not be_success
@@ -1922,7 +1893,7 @@ describe Braintree::Customer do
1922
1893
  :options => {
1923
1894
  :make_default => true
1924
1895
  }
1925
- }
1896
+ },
1926
1897
  )
1927
1898
 
1928
1899
  paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
@@ -1931,12 +1902,12 @@ describe Braintree::Customer do
1931
1902
  :token => paypal_account_token,
1932
1903
  :options => {
1933
1904
  :make_default => true
1934
- }
1905
+ },
1935
1906
  )
1936
1907
 
1937
1908
  result = Braintree::Customer.update(
1938
1909
  customer.id,
1939
- :payment_method_nonce => nonce
1910
+ :payment_method_nonce => nonce,
1940
1911
  )
1941
1912
 
1942
1913
  result.should_not be_success