braintree 2.104.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +7 -4
  4. data/lib/braintree.rb +7 -18
  5. data/lib/braintree/account_updater_daily_report.rb +1 -1
  6. data/lib/braintree/address.rb +1 -23
  7. data/lib/braintree/apple_pay.rb +1 -1
  8. data/lib/braintree/apple_pay_card.rb +1 -1
  9. data/lib/braintree/apple_pay_options.rb +1 -1
  10. data/lib/braintree/authorization_adjustment.rb +1 -1
  11. data/lib/braintree/base_module.rb +6 -0
  12. data/lib/braintree/bin_data.rb +9 -2
  13. data/lib/braintree/client_token.rb +1 -1
  14. data/lib/braintree/configuration.rb +12 -12
  15. data/lib/braintree/connected_merchant_paypal_status_changed.rb +1 -1
  16. data/lib/braintree/connected_merchant_status_transitioned.rb +1 -1
  17. data/lib/braintree/credit_card.rb +2 -77
  18. data/lib/braintree/credit_card_gateway.rb +7 -36
  19. data/lib/braintree/credit_card_verification.rb +18 -5
  20. data/lib/braintree/credit_card_verification_search.rb +1 -1
  21. data/lib/braintree/customer.rb +5 -76
  22. data/lib/braintree/customer_gateway.rb +0 -23
  23. data/lib/braintree/customer_search.rb +1 -1
  24. data/lib/braintree/disbursement.rb +1 -1
  25. data/lib/braintree/dispute.rb +2 -8
  26. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  27. data/lib/braintree/dispute_gateway.rb +4 -9
  28. data/lib/braintree/dispute_search.rb +2 -2
  29. data/lib/braintree/document_upload.rb +1 -1
  30. data/lib/braintree/error_codes.rb +151 -170
  31. data/lib/braintree/exceptions.rb +5 -3
  32. data/lib/braintree/gateway.rb +0 -14
  33. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +2 -3
  34. data/lib/braintree/granted_payment_instrument_update.rb +1 -1
  35. data/lib/braintree/graphql_client.rb +7 -7
  36. data/lib/braintree/http.rb +3 -3
  37. data/lib/braintree/local_payment_completed.rb +1 -1
  38. data/lib/braintree/local_payment_reversed.rb +19 -0
  39. data/lib/braintree/merchant.rb +1 -1
  40. data/lib/braintree/merchant_account.rb +1 -1
  41. data/lib/braintree/merchant_account_gateway.rb +3 -1
  42. data/lib/braintree/merchant_gateway.rb +1 -1
  43. data/lib/braintree/modification.rb +1 -1
  44. data/lib/braintree/oauth_credentials.rb +1 -1
  45. data/lib/braintree/oauth_gateway.rb +5 -5
  46. data/lib/braintree/payment_instrument_type.rb +10 -14
  47. data/lib/braintree/payment_method_gateway.rb +8 -13
  48. data/lib/braintree/payment_method_nonce_gateway.rb +1 -1
  49. data/lib/braintree/payment_method_parser.rb +1 -8
  50. data/lib/braintree/plan.rb +1 -1
  51. data/lib/braintree/processor_response_types.rb +3 -3
  52. data/lib/braintree/resource_collection.rb +8 -3
  53. data/lib/braintree/revoked_payment_method_metadata.rb +1 -1
  54. data/lib/braintree/risk_data.rb +3 -1
  55. data/lib/braintree/samsung_pay_card.rb +1 -1
  56. data/lib/braintree/settlement_batch_summary.rb +2 -2
  57. data/lib/braintree/subscription.rb +11 -11
  58. data/lib/braintree/successful_result.rb +0 -1
  59. data/lib/braintree/test/credit_card.rb +1 -0
  60. data/lib/braintree/test/nonce.rb +4 -23
  61. data/lib/braintree/three_d_secure_info.rb +22 -12
  62. data/lib/braintree/transaction.rb +44 -104
  63. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  64. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  65. data/lib/braintree/transaction/installment.rb +28 -0
  66. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  67. data/lib/braintree/transaction/paypal_details.rb +1 -0
  68. data/lib/braintree/transaction/subscription_details.rb +2 -0
  69. data/lib/braintree/transaction_gateway.rb +37 -25
  70. data/lib/braintree/transaction_line_item.rb +1 -1
  71. data/lib/braintree/transaction_search.rb +3 -2
  72. data/lib/braintree/unknown_payment_method.rb +1 -1
  73. data/lib/braintree/us_bank_account.rb +3 -3
  74. data/lib/braintree/us_bank_account_verification.rb +1 -1
  75. data/lib/braintree/us_bank_account_verification_gateway.rb +1 -1
  76. data/lib/braintree/util.rb +21 -6
  77. data/lib/braintree/venmo_account.rb +1 -1
  78. data/lib/braintree/version.rb +3 -3
  79. data/lib/braintree/visa_checkout_card.rb +2 -2
  80. data/lib/braintree/webhook_notification.rb +28 -29
  81. data/lib/braintree/webhook_notification_gateway.rb +5 -5
  82. data/lib/braintree/webhook_testing_gateway.rb +10 -43
  83. data/lib/braintree/xml/generator.rb +5 -4
  84. data/lib/braintree/xml/libxml.rb +1 -0
  85. data/lib/braintree/xml/parser.rb +21 -44
  86. data/spec/integration/braintree/add_on_spec.rb +1 -1
  87. data/spec/integration/braintree/address_spec.rb +26 -113
  88. data/spec/integration/braintree/advanced_search_spec.rb +45 -45
  89. data/spec/integration/braintree/apple_pay_spec.rb +3 -3
  90. data/spec/integration/braintree/braintree_gateway_spec.rb +2 -1
  91. data/spec/integration/braintree/client_api/client_token_spec.rb +14 -14
  92. data/spec/integration/braintree/client_api/spec_helper.rb +5 -31
  93. data/spec/integration/braintree/credit_card_spec.rb +130 -593
  94. data/spec/integration/braintree/credit_card_verification_search_spec.rb +2 -2
  95. data/spec/integration/braintree/credit_card_verification_spec.rb +1 -1
  96. data/spec/integration/braintree/customer_search_spec.rb +8 -8
  97. data/spec/integration/braintree/customer_spec.rb +336 -509
  98. data/spec/integration/braintree/dispute_search_spec.rb +6 -6
  99. data/spec/integration/braintree/dispute_spec.rb +6 -7
  100. data/spec/integration/braintree/error_codes_spec.rb +1 -1
  101. data/spec/integration/braintree/http_spec.rb +2 -2
  102. data/spec/integration/braintree/merchant_account_spec.rb +25 -26
  103. data/spec/integration/braintree/merchant_spec.rb +14 -14
  104. data/spec/integration/braintree/oauth_spec.rb +11 -11
  105. data/spec/integration/braintree/payment_method_nonce_spec.rb +12 -12
  106. data/spec/integration/braintree/payment_method_spec.rb +403 -269
  107. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +17 -13
  108. data/spec/integration/braintree/paypal_account_spec.rb +28 -28
  109. data/spec/integration/braintree/samsung_pay_card_spec.rb +9 -9
  110. data/spec/integration/braintree/settlement_batch_summary_spec.rb +8 -8
  111. data/spec/integration/braintree/subscription_spec.rb +144 -149
  112. data/spec/integration/braintree/test/transaction_amounts_spec.rb +2 -2
  113. data/spec/integration/braintree/test_transaction_spec.rb +10 -10
  114. data/spec/integration/braintree/transaction_search_spec.rb +96 -70
  115. data/spec/integration/braintree/transaction_spec.rb +832 -904
  116. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +32 -26
  117. data/spec/integration/braintree/us_bank_account_spec.rb +6 -6
  118. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +7 -7
  119. data/spec/integration/braintree/us_bank_account_verification_spec.rb +8 -8
  120. data/spec/integration/braintree/visa_checkout_card_spec.rb +5 -5
  121. data/spec/integration/spec_helper.rb +10 -7
  122. data/spec/oauth_test_helper.rb +1 -1
  123. data/spec/script/httpsd.rb +6 -6
  124. data/spec/spec_helper.rb +6 -14
  125. data/spec/unit/braintree/address_spec.rb +1 -9
  126. data/spec/unit/braintree/apple_pay_card_spec.rb +1 -1
  127. data/spec/unit/braintree/client_token_spec.rb +2 -2
  128. data/spec/unit/braintree/configuration_spec.rb +42 -42
  129. data/spec/unit/braintree/credit_card_spec.rb +9 -28
  130. data/spec/unit/braintree/credit_card_verification_search_spec.rb +1 -1
  131. data/spec/unit/braintree/credit_card_verification_spec.rb +8 -4
  132. data/spec/unit/braintree/customer_spec.rb +5 -16
  133. data/spec/unit/braintree/disbursement_spec.rb +7 -7
  134. data/spec/unit/braintree/dispute_spec.rb +9 -20
  135. data/spec/unit/braintree/error_result_spec.rb +5 -5
  136. data/spec/unit/braintree/errors_spec.rb +8 -8
  137. data/spec/unit/braintree/http_spec.rb +8 -8
  138. data/spec/unit/braintree/merchant_account_spec.rb +1 -1
  139. data/spec/unit/braintree/payment_method_spec.rb +1 -1
  140. data/spec/unit/braintree/paypal_account_spec.rb +2 -2
  141. data/spec/unit/braintree/resource_collection_spec.rb +30 -1
  142. data/spec/unit/braintree/risk_data_spec.rb +9 -5
  143. data/spec/unit/braintree/subscription_search_spec.rb +1 -1
  144. data/spec/unit/braintree/successful_result_spec.rb +1 -1
  145. data/spec/unit/braintree/three_d_secure_info_spec.rb +32 -14
  146. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +3 -3
  147. data/spec/unit/braintree/transaction/customer_details_spec.rb +1 -1
  148. data/spec/unit/braintree/transaction/deposit_details_spec.rb +2 -2
  149. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  150. data/spec/unit/braintree/transaction/paypal_details_spec.rb +3 -1
  151. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  152. data/spec/unit/braintree/transaction_spec.rb +25 -51
  153. data/spec/unit/braintree/util_spec.rb +55 -21
  154. data/spec/unit/braintree/validation_error_collection_spec.rb +36 -36
  155. data/spec/unit/braintree/webhook_notification_spec.rb +73 -57
  156. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  157. data/spec/unit/braintree/xml_spec.rb +31 -31
  158. metadata +30 -31
  159. data/lib/braintree/amex_express_checkout_card.rb +0 -40
  160. data/lib/braintree/coinbase_account.rb +0 -34
  161. data/lib/braintree/europe_bank_account.rb +0 -36
  162. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  163. data/lib/braintree/ideal_payment.rb +0 -61
  164. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  165. data/lib/braintree/masterpass_card.rb +0 -83
  166. data/lib/braintree/settlement_batch.rb +0 -0
  167. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  168. data/lib/braintree/transaction/coinbase_details.rb +0 -16
  169. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  170. data/lib/braintree/transaction/masterpass_card_details.rb +0 -49
  171. data/lib/braintree/transparent_redirect.rb +0 -40
  172. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  173. data/lib/braintree/xml/rexml.rb +0 -71
  174. data/spec/hacks/tcp_socket.rb +0 -18
  175. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  176. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  177. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  178. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
  179. data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
@@ -108,7 +108,7 @@ describe Braintree::CreditCardVerification, "search" do
108
108
  search.id.is verification.id
109
109
  search.created_at.between(
110
110
  created_at - 60,
111
- created_at + 60
111
+ created_at + 60,
112
112
  )
113
113
  end
114
114
 
@@ -135,7 +135,7 @@ describe Braintree::CreditCardVerification, "search" do
135
135
  search.id.is verification.id
136
136
  search.created_at.between(
137
137
  created_at - 300,
138
- created_at - 100
138
+ created_at - 100,
139
139
  )
140
140
  end
141
141
 
@@ -242,7 +242,7 @@ describe Braintree::CreditCardVerification, "search" do
242
242
  :cardholder_name => cardholder_name,
243
243
  :expiration_date => "05/2012",
244
244
  :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Prepaid,
245
- :cvv => '200',
245
+ :cvv => "200",
246
246
  :options => {
247
247
  :verify_card => true
248
248
  }
@@ -36,7 +36,7 @@ describe Braintree::Transaction, "search" do
36
36
  :postal_code => "60622",
37
37
  :country_name => "United States of America"
38
38
  }
39
- }
39
+ },
40
40
  )
41
41
 
42
42
  customer = Braintree::Customer.find(customer.id)
@@ -96,7 +96,7 @@ describe Braintree::Transaction, "search" do
96
96
  :credit_card => {
97
97
  :number => Braintree::Test::CreditCardNumbers::Maestro,
98
98
  :expiration_date => "05/2012"
99
- }
99
+ },
100
100
  ).customer
101
101
 
102
102
  joe = Braintree::Customer.create(
@@ -104,7 +104,7 @@ describe Braintree::Transaction, "search" do
104
104
  :credit_card => {
105
105
  :number => Braintree::Test::CreditCardNumbers::Maestro,
106
106
  :expiration_date => "05/2012"
107
- }
107
+ },
108
108
  ).customer
109
109
 
110
110
  collection = Braintree::Customer.search do |search|
@@ -118,7 +118,7 @@ describe Braintree::Transaction, "search" do
118
118
  it "can search by created_at" do
119
119
  company = "Company #{rand(1_000_000)}"
120
120
  customer = Braintree::Customer.create!(
121
- :company => company
121
+ :company => company,
122
122
  )
123
123
 
124
124
  created_at = customer.created_at
@@ -128,7 +128,7 @@ describe Braintree::Transaction, "search" do
128
128
  search.company.is company
129
129
  search.created_at.between(
130
130
  created_at - 60,
131
- created_at + 60
131
+ created_at + 60,
132
132
  )
133
133
  end
134
134
 
@@ -155,7 +155,7 @@ describe Braintree::Transaction, "search" do
155
155
  search.company.is customer.company
156
156
  search.created_at.between(
157
157
  created_at - 300,
158
- created_at - 100
158
+ created_at - 100,
159
159
  )
160
160
  end
161
161
 
@@ -175,13 +175,13 @@ describe Braintree::Transaction, "search" do
175
175
  paypal_token = rand(36**3).to_s(36)
176
176
  nonce = nonce_for_paypal_account(
177
177
  :consent_code => "PAYPAL_CONSENT_CODE",
178
- :token => paypal_token
178
+ :token => paypal_token,
179
179
  )
180
180
 
181
181
  customer_id = "UNIQUE_CUSTOMER_ID_" + rand(36**3).to_s(36)
182
182
  customer = Braintree::Customer.create!(
183
183
  :payment_method_nonce => nonce,
184
- :id => customer_id
184
+ :id => customer_id,
185
185
  )
186
186
 
187
187
  collection = Braintree::Customer.search do |search|
@@ -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,7 @@ 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
43
  )
44
44
  result.success?.should == true
45
45
  result.customer.id.should =~ /^\d{6,}$/
@@ -58,7 +58,7 @@ describe Braintree::Customer do
58
58
  oauth_gateway = Braintree::Gateway.new(
59
59
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
60
60
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
61
- :logger => Logger.new("/dev/null")
61
+ :logger => Logger.new("/dev/null"),
62
62
  )
63
63
  access_token = Braintree::OAuthTestHelper.create_token(oauth_gateway, {
64
64
  :merchant_public_id => "integration_merchant_id",
@@ -67,7 +67,7 @@ describe Braintree::Customer do
67
67
 
68
68
  gateway = Braintree::Gateway.new(
69
69
  :access_token => access_token,
70
- :logger => Logger.new("/dev/null")
70
+ :logger => Logger.new("/dev/null"),
71
71
  )
72
72
 
73
73
  result = gateway.customer.create(
@@ -77,7 +77,7 @@ describe Braintree::Customer do
77
77
  :email => "joe@example.com",
78
78
  :phone => "312.555.1234",
79
79
  :fax => "614.555.5678",
80
- :website => "www.example.com"
80
+ :website => "www.example.com",
81
81
  )
82
82
  result.success?.should == true
83
83
  result.customer.id.should =~ /^\d{6,}$/
@@ -85,15 +85,14 @@ describe Braintree::Customer do
85
85
  result.customer.last_name.should == "Brown"
86
86
  end
87
87
 
88
- it "supports creation with a device session ID and (optional) fraud_merchant_id" do
88
+ it "supports creation with device_data" do
89
89
  result = Braintree::Customer.create(
90
90
  :credit_card => {
91
91
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
92
92
  :expiration_date => "05/2010",
93
93
  :cvv => "100",
94
- :device_session_id => "abc123",
95
- :fraud_merchant_id => "7"
96
- }
94
+ :device_data => "device_data",
95
+ },
97
96
  )
98
97
 
99
98
  result.should be_success
@@ -109,7 +108,7 @@ describe Braintree::Customer do
109
108
  :risk_data => {
110
109
  :customer_browser => "IE5",
111
110
  :customer_ip => "192.168.0.1"
112
- }
111
+ },
113
112
  )
114
113
 
115
114
  result.should be_success
@@ -135,21 +134,21 @@ describe Braintree::Customer do
135
134
  found_customer.last_name.should == last_name
136
135
  else
137
136
  result.customer.first_name.should == "José"
138
- result.customer.first_name.bytes.map {|b| b.to_s(8)}.should == ["112", "157", "163", "303", "251"]
137
+ result.customer.first_name.bytes.map { |b| b.to_s(8) }.should == ["112", "157", "163", "303", "251"]
139
138
  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"]
139
+ result.customer.last_name.bytes.map { |b| b.to_s(8) }.should == ["115", "165", "303", "261", "157", "172"]
141
140
 
142
141
  found_customer = Braintree::Customer.find(result.customer.id)
143
142
  found_customer.first_name.should == "José"
144
- found_customer.first_name.bytes.map {|b| b.to_s(8)}.should == ["112", "157", "163", "303", "251"]
143
+ found_customer.first_name.bytes.map { |b| b.to_s(8) }.should == ["112", "157", "163", "303", "251"]
145
144
  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"]
145
+ found_customer.last_name.bytes.map { |b| b.to_s(8) }.should == ["115", "165", "303", "261", "157", "172"]
147
146
  end
148
147
  end
149
148
 
150
149
  it "returns an error response if invalid" do
151
150
  result = Braintree::Customer.create(
152
- :email => "@invalid.com"
151
+ :email => "@invalid.com",
153
152
  )
154
153
  result.success?.should == false
155
154
  result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
@@ -163,7 +162,7 @@ describe Braintree::Customer do
163
162
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
164
163
  :expiration_date => "05/2010",
165
164
  :cvv => "100"
166
- }
165
+ },
167
166
  )
168
167
 
169
168
  result.success?.should == true
@@ -183,7 +182,7 @@ describe Braintree::Customer do
183
182
  :email => "other@example.com",
184
183
  :billing_agreement_id => "B-123456",
185
184
  :options => {:make_default => true}
186
- }
185
+ },
187
186
  )
188
187
 
189
188
  result.success?.should == true
@@ -201,7 +200,7 @@ describe Braintree::Customer do
201
200
  :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
202
201
  :expiration_date => "05/2010",
203
202
  :options => {:verify_card => true}
204
- }
203
+ },
205
204
  )
206
205
  result.success?.should == false
207
206
  result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
@@ -215,7 +214,7 @@ describe Braintree::Customer do
215
214
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
216
215
  :expiration_date => "05/2019",
217
216
  :options => {:verify_card => true, :verification_amount => "2.00"}
218
- }
217
+ },
219
218
  )
220
219
  result.success?.should == true
221
220
  end
@@ -225,7 +224,7 @@ describe Braintree::Customer do
225
224
  Braintree::CreditCard.create(
226
225
  :customer_id => customer.id,
227
226
  :number => Braintree::Test::CreditCardNumbers::Visa,
228
- :expiration_date => "05/2015"
227
+ :expiration_date => "05/2015",
229
228
  )
230
229
 
231
230
  result = Braintree::Customer.create(
@@ -235,7 +234,7 @@ describe Braintree::Customer do
235
234
  :number => Braintree::Test::CreditCardNumbers::Visa,
236
235
  :expiration_date => "05/2015",
237
236
  :options => {:fail_on_duplicate_payment_method => true}
238
- }
237
+ },
239
238
  )
240
239
  result.success?.should == false
241
240
  result.errors.for(:customer).for(:credit_card).on(:number)[0].message.should == "Duplicate card exists in the vault."
@@ -252,12 +251,98 @@ describe Braintree::Customer do
252
251
  :verify_card => true,
253
252
  :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
254
253
  }
255
- }
254
+ },
256
255
  )
257
256
  result.success?.should == false
258
257
  result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
259
258
  end
260
259
 
260
+ it "can create a customer and a payment method at the same time after validating verification_currency_iso_code" do
261
+ result = Braintree::Customer.create(
262
+ :first_name => "Mike",
263
+ :last_name => "Jones",
264
+ :credit_card => {
265
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
266
+ :expiration_date => "05/2010",
267
+ :cvv => "100",
268
+ :options => {
269
+ :verify_card => true,
270
+ :verification_currency_iso_code => "USD"
271
+ }
272
+ },
273
+ )
274
+
275
+ result.success?.should == true
276
+ result.customer.first_name.should == "Mike"
277
+ result.customer.last_name.should == "Jones"
278
+ result.customer.credit_cards[0].bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
279
+ result.customer.credit_cards[0].last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
280
+ result.customer.credit_cards[0].expiration_date.should == "05/2010"
281
+ result.customer.credit_cards[0].unique_number_identifier.should =~ /\A\w{32}\z/
282
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
283
+ end
284
+
285
+ it "errors when verification_currency_iso_code is not supported by merchant account" do
286
+ result = Braintree::Customer.create(
287
+ :first_name => "Mike",
288
+ :last_name => "Jones",
289
+ :credit_card => {
290
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
291
+ :expiration_date => "05/2010",
292
+ :cvv => "100",
293
+ :options => {
294
+ :verify_card => true,
295
+ :verification_currency_iso_code => "GBP"
296
+ }
297
+ },
298
+ )
299
+ expect(result).to_not be_success
300
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
301
+ end
302
+
303
+ it "validates verification_currency_iso_code of the given verification_merchant_account_id and creates customer" do
304
+ result = Braintree::Customer.create(
305
+ :first_name => "Mike",
306
+ :last_name => "Jones",
307
+ :credit_card => {
308
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
309
+ :expiration_date => "05/2010",
310
+ :options => {
311
+ :verify_card => true,
312
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
313
+ :verification_currency_iso_code => "USD"
314
+ }
315
+ },
316
+ )
317
+ result.success?.should == true
318
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
319
+ result.customer.first_name.should == "Mike"
320
+ result.customer.last_name.should == "Jones"
321
+ result.customer.credit_cards[0].bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
322
+ result.customer.credit_cards[0].last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
323
+ result.customer.credit_cards[0].expiration_date.should == "05/2010"
324
+ result.customer.credit_cards[0].unique_number_identifier.should =~ /\A\w{32}\z/
325
+ end
326
+
327
+ it "validates verification_currency_iso_code of the given verification_merchant_account_id and returns error" do
328
+ result = Braintree::Customer.create(
329
+ :first_name => "Mike",
330
+ :last_name => "Jones",
331
+ :credit_card => {
332
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
333
+ :expiration_date => "05/2010",
334
+ :options => {
335
+ :verify_card => true,
336
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
337
+ :verification_currency_iso_code => "GBP"
338
+ }
339
+ },
340
+ )
341
+ expect(result).to_not be_success
342
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
343
+ end
344
+
345
+
261
346
  it "can create a customer, payment method, and billing address at the same time" do
262
347
  result = Braintree::Customer.create(
263
348
  :first_name => "Mike",
@@ -273,7 +358,7 @@ describe Braintree::Customer do
273
358
  :postal_code => "60622",
274
359
  :country_name => "United States of America"
275
360
  }
276
- }
361
+ },
277
362
  )
278
363
  result.success?.should == true
279
364
  result.customer.first_name.should == "Mike"
@@ -304,7 +389,7 @@ describe Braintree::Customer do
304
389
  :country_code_alpha3 => "COM",
305
390
  :country_code_numeric => "174"
306
391
  }
307
- }
392
+ },
308
393
  )
309
394
  result.success?.should == true
310
395
  result.customer.addresses[0].country_name.should == "Comoros"
@@ -319,7 +404,7 @@ describe Braintree::Customer do
319
404
  :last_name => "Gates",
320
405
  :custom_fields => {
321
406
  :store_me => "custom value"
322
- }
407
+ },
323
408
  )
324
409
  result.success?.should == true
325
410
  result.customer.custom_fields[:store_me].should == "custom value"
@@ -329,7 +414,7 @@ describe Braintree::Customer do
329
414
  result = Braintree::Customer.create(
330
415
  :first_name => "Bill",
331
416
  :last_name => "Gates",
332
- :custom_fields => { :store_me => "" }
417
+ :custom_fields => {:store_me => ""},
333
418
  )
334
419
  result.success?.should == true
335
420
  result.customer.custom_fields.should == {}
@@ -343,7 +428,7 @@ describe Braintree::Customer do
343
428
  :billing_address => {
344
429
  :country_name => "invalid"
345
430
  }
346
- }
431
+ },
347
432
  )
348
433
  result.success?.should == false
349
434
  result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
@@ -363,10 +448,10 @@ describe Braintree::Customer do
363
448
  :country_code_alpha2 => "US",
364
449
  :country_code_alpha3 => "COM",
365
450
  }
366
- }
451
+ },
367
452
  )
368
453
  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)
454
+ result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:base).map { |e| e.code }.should include(Braintree::ErrorCodes::Address::InconsistentCountry)
370
455
  end
371
456
 
372
457
  it "returns an error if country code alpha2 is invalid" do
@@ -379,10 +464,10 @@ describe Braintree::Customer do
379
464
  :billing_address => {
380
465
  :country_code_alpha2 => "zz",
381
466
  }
382
- }
467
+ },
383
468
  )
384
469
  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)
470
+ 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
471
  end
387
472
 
388
473
  it "returns an error if country code alpha3 is invalid" do
@@ -395,10 +480,10 @@ describe Braintree::Customer do
395
480
  :billing_address => {
396
481
  :country_code_alpha3 => "zzz",
397
482
  }
398
- }
483
+ },
399
484
  )
400
485
  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)
486
+ 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
487
  end
403
488
 
404
489
  it "returns an error if country code numeric is invalid" do
@@ -411,10 +496,10 @@ describe Braintree::Customer do
411
496
  :billing_address => {
412
497
  :country_code_numeric => "zzz",
413
498
  }
414
- }
499
+ },
415
500
  )
416
501
  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)
502
+ 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
503
  end
419
504
 
420
505
  it "returns errors if custom_fields are not registered" do
@@ -423,7 +508,7 @@ describe Braintree::Customer do
423
508
  :last_name => "Kennedy",
424
509
  :custom_fields => {
425
510
  :spouse_name => "Jacqueline"
426
- }
511
+ },
427
512
  )
428
513
  result.success?.should == false
429
514
  result.errors.for(:customer).on(:custom_fields)[0].message.should == "Custom field is invalid: spouse_name."
@@ -436,7 +521,7 @@ describe Braintree::Customer do
436
521
  :last_name => "Hamlin",
437
522
  :credit_card => {
438
523
  :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::VisaPaymentMethodCode
439
- }
524
+ },
440
525
  )
441
526
  result.success?.should == true
442
527
  result.customer.credit_cards.first.bin.should == "400934"
@@ -453,7 +538,7 @@ describe Braintree::Customer do
453
538
  :options => {
454
539
  :venmo_sdk_session => Braintree::Test::VenmoSDK::Session
455
540
  }
456
- }
541
+ },
457
542
  )
458
543
  result.success?.should == true
459
544
  result.customer.credit_cards.first.venmo_sdk?.should == false
@@ -468,13 +553,13 @@ describe Braintree::Customer do
468
553
  :expiration_month => "11",
469
554
  :expiration_year => "2099",
470
555
  },
471
- :share => true
556
+ :share => true,
472
557
  )
473
558
 
474
559
  result = Braintree::Customer.create(
475
560
  :credit_card => {
476
561
  :payment_method_nonce => nonce
477
- }
562
+ },
478
563
  )
479
564
 
480
565
  result.success?.should == true
@@ -504,7 +589,7 @@ describe Braintree::Customer do
504
589
  :number => Braintree::Test::CreditCardNumbers::Hiper,
505
590
  :expiration_month => "11",
506
591
  :expiration_year => "2099",
507
- }
592
+ },
508
593
  )
509
594
  result = Braintree::Customer.create(
510
595
  :payment_method_nonce => nonce,
@@ -514,7 +599,7 @@ describe Braintree::Customer do
514
599
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
515
600
  :verification_account_type => "debit",
516
601
  }
517
- }
602
+ },
518
603
  )
519
604
 
520
605
  expect(result).to be_success
@@ -526,7 +611,7 @@ describe Braintree::Customer do
526
611
  :number => Braintree::Test::CreditCardNumbers::Hiper,
527
612
  :expiration_month => "11",
528
613
  :expiration_year => "2099",
529
- }
614
+ },
530
615
  )
531
616
  result = Braintree::Customer.create(
532
617
  :payment_method_nonce => nonce,
@@ -536,7 +621,7 @@ describe Braintree::Customer do
536
621
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
537
622
  :verification_account_type => "credit",
538
623
  }
539
- }
624
+ },
540
625
  )
541
626
 
542
627
  expect(result).to be_success
@@ -548,7 +633,7 @@ describe Braintree::Customer do
548
633
  :number => Braintree::Test::CreditCardNumbers::Hiper,
549
634
  :expiration_month => "11",
550
635
  :expiration_year => "2099",
551
- }
636
+ },
552
637
  )
553
638
  result = Braintree::Customer.create(
554
639
  :payment_method_nonce => nonce,
@@ -558,7 +643,7 @@ describe Braintree::Customer do
558
643
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
559
644
  :verification_account_type => "ach",
560
645
  }
561
- }
646
+ },
562
647
  )
563
648
 
564
649
  expect(result).to_not be_success
@@ -571,7 +656,7 @@ describe Braintree::Customer do
571
656
  :number => Braintree::Test::CreditCardNumbers::Visa,
572
657
  :expiration_month => "11",
573
658
  :expiration_year => "2099",
574
- }
659
+ },
575
660
  )
576
661
  result = Braintree::Customer.create(
577
662
  :payment_method_nonce => nonce,
@@ -580,7 +665,7 @@ describe Braintree::Customer do
580
665
  :verify_card => true,
581
666
  :verification_account_type => "credit",
582
667
  }
583
- }
668
+ },
584
669
  )
585
670
 
586
671
  expect(result).to_not be_success
@@ -593,7 +678,7 @@ describe Braintree::Customer do
593
678
  it "returns the customer if successful" do
594
679
  customer = Braintree::Customer.create!(
595
680
  :first_name => "Jim",
596
- :last_name => "Smith"
681
+ :last_name => "Smith",
597
682
  )
598
683
  customer.id.should =~ /\d+/
599
684
  customer.first_name.should == "Jim"
@@ -618,7 +703,7 @@ describe Braintree::Customer do
618
703
  :credit_card => {
619
704
  :number => Braintree::Test::CreditCardNumbers::Visa,
620
705
  :expiration_date => "05/2010"
621
- }
706
+ },
622
707
  )
623
708
  result = Braintree::Customer.credit(customer.id, :amount => "100.00")
624
709
  result.success?.should == true
@@ -638,7 +723,7 @@ describe Braintree::Customer do
638
723
  :credit_card => {
639
724
  :number => Braintree::Test::CreditCardNumbers::Visa,
640
725
  :expiration_date => "05/2010"
641
- }
726
+ },
642
727
  )
643
728
  transaction = Braintree::Customer.credit!(customer.id, :amount => "100.00")
644
729
  transaction.amount.should == BigDecimal("100.00")
@@ -657,7 +742,7 @@ describe Braintree::Customer do
657
742
  :credit_card => {
658
743
  :number => Braintree::Test::CreditCardNumbers::Visa,
659
744
  :expiration_date => "05/2010"
660
- }
745
+ },
661
746
  )
662
747
  result = Braintree::Customer.sale(customer.id, :amount => "100.00")
663
748
  result.success?.should == true
@@ -677,7 +762,7 @@ describe Braintree::Customer do
677
762
  :credit_card => {
678
763
  :number => Braintree::Test::CreditCardNumbers::Visa,
679
764
  :expiration_date => "05/2010"
680
- }
765
+ },
681
766
  )
682
767
  transaction = Braintree::Customer.sale!(customer.id, :amount => "100.00")
683
768
  transaction.amount.should == BigDecimal("100.00")
@@ -696,80 +781,24 @@ describe Braintree::Customer do
696
781
  :credit_card => {
697
782
  :number => Braintree::Test::CreditCardNumbers::Visa,
698
783
  :expiration_date => "05/2010"
699
- }
784
+ },
700
785
  )
701
- transaction = customer.sale!(:amount => "100.00")
786
+ transaction = Braintree::Customer.sale!(customer.id, :amount => "100.00")
702
787
  collection = Braintree::Customer.transactions(customer.id)
703
788
  collection.first.should == transaction
704
789
  end
705
790
  end
706
791
 
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
792
  describe "credit" do
764
793
  it "creates a credit transaction using the customer, returning a result object" do
765
794
  customer = Braintree::Customer.create!(
766
795
  :credit_card => {
767
796
  :number => Braintree::Test::CreditCardNumbers::Visa,
768
797
  :expiration_date => "05/2010"
769
- }
798
+ },
770
799
  )
771
800
  result = customer.credit(
772
- :amount => "100.00"
801
+ :amount => "100.00",
773
802
  )
774
803
  result.success?.should == true
775
804
  result.transaction.amount.should == BigDecimal("100.00")
@@ -788,7 +817,7 @@ describe Braintree::Customer do
788
817
  :credit_card => {
789
818
  :number => Braintree::Test::CreditCardNumbers::Visa,
790
819
  :expiration_date => "05/2010"
791
- }
820
+ },
792
821
  )
793
822
  transaction = customer.credit!(:amount => "100.00")
794
823
  transaction.amount.should == BigDecimal("100.00")
@@ -801,72 +830,11 @@ describe Braintree::Customer do
801
830
  end
802
831
  end
803
832
 
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
833
  describe "delete" do
866
834
  it "deletes the customer" do
867
835
  result = Braintree::Customer.create(
868
836
  :first_name => "Joe",
869
- :last_name => "Cool"
837
+ :last_name => "Cool",
870
838
  )
871
839
  result.success?.should == true
872
840
 
@@ -883,7 +851,7 @@ describe Braintree::Customer do
883
851
  it "finds the customer with the given id" do
884
852
  result = Braintree::Customer.create(
885
853
  :first_name => "Joe",
886
- :last_name => "Cool"
854
+ :last_name => "Cool",
887
855
  )
888
856
  result.success?.should == true
889
857
 
@@ -899,13 +867,13 @@ describe Braintree::Customer do
899
867
  credit_card = Braintree::CreditCard.create(
900
868
  :customer_id => customer.id,
901
869
  :number => Braintree::Test::CreditCardNumbers::Visa,
902
- :expiration_date => "05/2012"
870
+ :expiration_date => "05/2012",
903
871
  ).credit_card
904
872
 
905
873
  subscription = Braintree::Subscription.create(
906
874
  :payment_method_token => credit_card.token,
907
875
  :plan_id => "integration_trialless_plan",
908
- :price => "1.00"
876
+ :price => "1.00",
909
877
  ).subscription
910
878
 
911
879
  found_customer = Braintree::Customer.find(customer.id)
@@ -920,7 +888,7 @@ describe Braintree::Customer do
920
888
  customer = Braintree::Customer.create(
921
889
  :custom_fields => {
922
890
  :store_me => "custom value"
923
- }
891
+ },
924
892
  ).customer
925
893
  credit_card = Braintree::CreditCard.create(
926
894
  :customer_id => customer.id,
@@ -932,13 +900,13 @@ describe Braintree::Customer do
932
900
  :region => "Illinois",
933
901
  :postal_code => "60622",
934
902
  :country_name => "United States of America"
935
- }
903
+ },
936
904
  ).credit_card
937
905
 
938
906
  subscription = Braintree::Subscription.create(
939
907
  :payment_method_token => credit_card.token,
940
908
  :plan_id => "integration_trialless_plan",
941
- :price => "1.00"
909
+ :price => "1.00",
942
910
  ).subscription
943
911
 
944
912
  found_customer = Braintree::Customer.find(customer.id, {
@@ -954,7 +922,7 @@ describe Braintree::Customer do
954
922
  customer = Braintree::Customer.create(
955
923
  :custom_fields => {
956
924
  :store_me => "custom value"
957
- }
925
+ },
958
926
  ).customer
959
927
  credit_card = Braintree::CreditCard.create(
960
928
  :customer_id => customer.id,
@@ -966,13 +934,13 @@ describe Braintree::Customer do
966
934
  :region => "Illinois",
967
935
  :postal_code => "60622",
968
936
  :country_name => "United States of America"
969
- }
937
+ },
970
938
  ).credit_card
971
939
 
972
940
  subscription = Braintree::Subscription.create(
973
941
  :payment_method_token => credit_card.token,
974
942
  :plan_id => "integration_trialless_plan",
975
- :price => "1.00"
943
+ :price => "1.00",
976
944
  ).subscription
977
945
 
978
946
  found_customer = Braintree::Customer.find(customer.id, {
@@ -990,7 +958,7 @@ describe Braintree::Customer do
990
958
 
991
959
  it "returns associated ApplePayCards" do
992
960
  result = Braintree::Customer.create(
993
- :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx
961
+ :payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
994
962
  )
995
963
  result.success?.should == true
996
964
 
@@ -1003,56 +971,41 @@ describe Braintree::Customer do
1003
971
  apple_pay_card.payment_instrument_name.should == "AmEx 41002"
1004
972
  end
1005
973
 
1006
- it "returns associated android pay proxy cards" do
974
+ it "returns associated google pay proxy cards" do
1007
975
  result = Braintree::Customer.create(
1008
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover
976
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
1009
977
  )
1010
978
  result.success?.should == true
1011
979
 
1012
980
  found_customer = Braintree::Customer.find(result.customer.id)
1013
- found_customer.android_pay_cards.size.should == 1
981
+ found_customer.google_pay_cards.size.should == 1
1014
982
  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
983
+ google_pay_card = found_customer.google_pay_cards.first
984
+ google_pay_card.should be_a Braintree::GooglePayCard
985
+ google_pay_card.token.should_not be_nil
986
+ google_pay_card.expiration_year.should_not be_nil
987
+ google_pay_card.is_network_tokenized?.should == false
1020
988
  end
1021
989
 
1022
- it "returns associated android pay network tokens" do
990
+ it "returns associated google pay network tokens" do
1023
991
  result = Braintree::Customer.create(
1024
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayMasterCard
992
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
1025
993
  )
1026
994
  result.success?.should == true
1027
995
 
1028
996
  found_customer = Braintree::Customer.find(result.customer.id)
1029
- found_customer.android_pay_cards.size.should == 1
997
+ found_customer.google_pay_cards.size.should == 1
1030
998
  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
1039
- result = Braintree::Customer.create(
1040
- :payment_method_nonce => Braintree::Test::Nonce::AmexExpressCheckout
1041
- )
1042
- result.success?.should == true
1043
-
1044
- found_customer = Braintree::Customer.find(result.customer.id)
1045
- found_customer.amex_express_checkout_cards.size.should == 1
1046
- 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
999
+ google_pay_card = found_customer.google_pay_cards.first
1000
+ google_pay_card.should be_a Braintree::GooglePayCard
1001
+ google_pay_card.token.should_not be_nil
1002
+ google_pay_card.expiration_year.should_not be_nil
1003
+ google_pay_card.is_network_tokenized?.should == true
1051
1004
  end
1052
1005
 
1053
1006
  it "returns associated venmo accounts" do
1054
1007
  result = Braintree::Customer.create(
1055
- :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount
1008
+ :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
1056
1009
  )
1057
1010
  result.success?.should == true
1058
1011
 
@@ -1072,7 +1025,7 @@ describe Braintree::Customer do
1072
1025
  :options => {
1073
1026
  :verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
1074
1027
  }
1075
- }
1028
+ },
1076
1029
  )
1077
1030
  result.should be_success
1078
1031
 
@@ -1118,7 +1071,7 @@ describe Braintree::Customer do
1118
1071
  it "updates the credit card with three_d_secure pass thru params" do
1119
1072
  customer = Braintree::Customer.create!(
1120
1073
  :first_name => "Joe",
1121
- :last_name => "Cool"
1074
+ :last_name => "Cool",
1122
1075
  )
1123
1076
  result = Braintree::Customer.update(
1124
1077
  customer.id,
@@ -1131,17 +1084,17 @@ describe Braintree::Customer do
1131
1084
  :number => 4111111111111111,
1132
1085
  :expiration_date => "05/2060",
1133
1086
  :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',
1087
+ :eci_flag => "02",
1088
+ :cavv => "some_cavv",
1089
+ :xid => "some_xid",
1090
+ :three_d_secure_version => "1.0.2",
1091
+ :authentication_response => "Y",
1092
+ :directory_response => "Y",
1093
+ :cavv_algorithm => "2",
1094
+ :ds_transaction_id => "some_ds_transaction_id",
1142
1095
  },
1143
1096
  :options => {:verify_card => true},
1144
- }
1097
+ },
1145
1098
  )
1146
1099
  result.success?.should == true
1147
1100
  result.customer.id.should == customer.id
@@ -1153,7 +1106,7 @@ describe Braintree::Customer do
1153
1106
  it "validates the presence of three_d_secure_version while passing three_d_secure_pass_thru in update" do
1154
1107
  customer = Braintree::Customer.create!(
1155
1108
  :first_name => "Joe",
1156
- :last_name => "Cool"
1109
+ :last_name => "Cool",
1157
1110
  )
1158
1111
  result = Braintree::Customer.update(
1159
1112
  customer.id,
@@ -1166,16 +1119,16 @@ describe Braintree::Customer do
1166
1119
  :number => 4111111111111111,
1167
1120
  :expiration_date => "05/2060",
1168
1121
  :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',
1122
+ :eci_flag => "02",
1123
+ :cavv => "some_cavv",
1124
+ :xid => "some_xid",
1125
+ :authentication_response => "Y",
1126
+ :directory_response => "Y",
1127
+ :cavv_algorithm => "2",
1128
+ :ds_transaction_id => "some_ds_transaction_id",
1176
1129
  },
1177
1130
  options: {:verify_card => true}
1178
- }
1131
+ },
1179
1132
  )
1180
1133
  expect(result).to_not be_success
1181
1134
  error = result.errors.for(:verification).first
@@ -1186,7 +1139,7 @@ describe Braintree::Customer do
1186
1139
  it "updates the customer with the given id if successful" do
1187
1140
  customer = Braintree::Customer.create!(
1188
1141
  :first_name => "Joe",
1189
- :last_name => "Cool"
1142
+ :last_name => "Cool",
1190
1143
  )
1191
1144
  result = Braintree::Customer.update(
1192
1145
  customer.id,
@@ -1194,7 +1147,7 @@ describe Braintree::Customer do
1194
1147
  :last_name => "Super Cool",
1195
1148
  :custom_fields => {
1196
1149
  :store_me => "a value"
1197
- }
1150
+ },
1198
1151
  )
1199
1152
  result.success?.should == true
1200
1153
  result.customer.id.should == customer.id
@@ -1208,7 +1161,7 @@ describe Braintree::Customer do
1208
1161
  :credit_card => {
1209
1162
  :number => 4111111111111111,
1210
1163
  :expiration_date => "05/2010",
1211
- }
1164
+ },
1212
1165
  )
1213
1166
  result = Braintree::Customer.update(
1214
1167
  customer.id,
@@ -1218,7 +1171,7 @@ describe Braintree::Customer do
1218
1171
  :options=> {
1219
1172
  :fail_on_duplicate_payment_method => true
1220
1173
  }
1221
- }
1174
+ },
1222
1175
  )
1223
1176
  result.success?.should == false
1224
1177
  result.errors.for(:customer).for(:credit_card).on(:number)[0].message.should == "Duplicate card exists in the vault."
@@ -1227,7 +1180,7 @@ describe Braintree::Customer do
1227
1180
  it "updates the default payment method" do
1228
1181
  customer = Braintree::Customer.create!(
1229
1182
  :first_name => "Joe",
1230
- :last_name => "Brown"
1183
+ :last_name => "Brown",
1231
1184
  )
1232
1185
 
1233
1186
  token1 = random_payment_method_token
@@ -1235,7 +1188,7 @@ describe Braintree::Customer do
1235
1188
  payment_method1 = Braintree::PaymentMethod.create(
1236
1189
  :customer_id => customer.id,
1237
1190
  :payment_method_nonce => Braintree::Test::Nonce::TransactableVisa,
1238
- :token => token1
1191
+ :token => token1,
1239
1192
  )
1240
1193
 
1241
1194
  payment_method1 = Braintree::PaymentMethod.find(token1)
@@ -1246,11 +1199,11 @@ describe Braintree::Customer do
1246
1199
  payment_method2 = Braintree::PaymentMethod.create(
1247
1200
  :customer_id => customer.id,
1248
1201
  :payment_method_nonce => Braintree::Test::Nonce::TransactableMasterCard,
1249
- :token => token2
1202
+ :token => token2,
1250
1203
  )
1251
1204
 
1252
1205
  Braintree::Customer.update(customer.id,
1253
- :default_payment_method_token => token2
1206
+ :default_payment_method_token => token2,
1254
1207
  )
1255
1208
 
1256
1209
  payment_method2 = Braintree::PaymentMethod.find(token2)
@@ -1260,7 +1213,7 @@ describe Braintree::Customer do
1260
1213
  it "updates the default payment method in the options" do
1261
1214
  customer = Braintree::Customer.create!(
1262
1215
  :first_name => "Joe",
1263
- :last_name => "Brown"
1216
+ :last_name => "Brown",
1264
1217
  )
1265
1218
 
1266
1219
  token1 = random_payment_method_token
@@ -1268,7 +1221,7 @@ describe Braintree::Customer do
1268
1221
  payment_method1 = Braintree::PaymentMethod.create(
1269
1222
  :customer_id => customer.id,
1270
1223
  :payment_method_nonce => Braintree::Test::Nonce::TransactableVisa,
1271
- :token => token1
1224
+ :token => token1,
1272
1225
  )
1273
1226
 
1274
1227
  payment_method1 = Braintree::PaymentMethod.find(token1)
@@ -1279,7 +1232,7 @@ describe Braintree::Customer do
1279
1232
  payment_method2 = Braintree::PaymentMethod.create(
1280
1233
  :customer_id => customer.id,
1281
1234
  :payment_method_nonce => Braintree::Test::Nonce::TransactableMasterCard,
1282
- :token => token2
1235
+ :token => token2,
1283
1236
  )
1284
1237
 
1285
1238
  Braintree::Customer.update(customer.id,
@@ -1288,7 +1241,7 @@ describe Braintree::Customer do
1288
1241
  :update_existing_token => token2,
1289
1242
  :make_default => true
1290
1243
  }
1291
- }
1244
+ },
1292
1245
  )
1293
1246
 
1294
1247
  payment_method2 = Braintree::PaymentMethod.find(token2)
@@ -1298,7 +1251,7 @@ describe Braintree::Customer do
1298
1251
  it "can use any country code" do
1299
1252
  customer = Braintree::Customer.create!(
1300
1253
  :first_name => "Alex",
1301
- :last_name => "Matterson"
1254
+ :last_name => "Matterson",
1302
1255
  )
1303
1256
  result = Braintree::Customer.update(
1304
1257
  customer.id,
@@ -1313,7 +1266,7 @@ describe Braintree::Customer do
1313
1266
  :country_code_alpha3 => "FJI",
1314
1267
  :country_code_numeric => "242"
1315
1268
  }
1316
- }
1269
+ },
1317
1270
  )
1318
1271
  result.success?.should == true
1319
1272
  result.customer.addresses[0].country_name.should == "Fiji"
@@ -1332,7 +1285,7 @@ describe Braintree::Customer do
1332
1285
  :first_name => "Joe",
1333
1286
  :postal_code => "60622"
1334
1287
  }
1335
- }
1288
+ },
1336
1289
  )
1337
1290
 
1338
1291
  result = Braintree::Customer.update(
@@ -1340,13 +1293,13 @@ describe Braintree::Customer do
1340
1293
  :first_name => "New Joe",
1341
1294
  :credit_card => {
1342
1295
  :cardholder_name => "New Joe Cardholder",
1343
- :options => { :update_existing_token => customer.credit_cards.first.token },
1296
+ :options => {:update_existing_token => customer.credit_cards.first.token},
1344
1297
  :billing_address => {
1345
1298
  :last_name => "Cool",
1346
1299
  :postal_code => "60666",
1347
- :options => { :update_existing => true }
1300
+ :options => {:update_existing => true}
1348
1301
  }
1349
- }
1302
+ },
1350
1303
  )
1351
1304
  result.success?.should == true
1352
1305
  result.customer.id.should == customer.id
@@ -1364,7 +1317,7 @@ describe Braintree::Customer do
1364
1317
 
1365
1318
  it "can update the customer and verify_card with a specific verification_amount" do
1366
1319
  customer = Braintree::Customer.create!(
1367
- :first_name => "Joe"
1320
+ :first_name => "Joe",
1368
1321
  )
1369
1322
 
1370
1323
  result = Braintree::Customer.update(
@@ -1374,8 +1327,8 @@ describe Braintree::Customer do
1374
1327
  :cardholder_name => "New Joe Cardholder",
1375
1328
  :number => Braintree::Test::CreditCardNumbers::Visa,
1376
1329
  :expiration_date => "12/2009",
1377
- :options => { :verify_card => true, :verification_amount => "2.00" }
1378
- }
1330
+ :options => {:verify_card => true, :verification_amount => "2.00"}
1331
+ },
1379
1332
  )
1380
1333
  result.success?.should == true
1381
1334
  end
@@ -1385,17 +1338,17 @@ describe Braintree::Customer do
1385
1338
  :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1386
1339
  :credit_card => {
1387
1340
  :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',
1341
+ :eci_flag => "02",
1342
+ :cavv => "some_cavv",
1343
+ :xid => "some_xid",
1344
+ :three_d_secure_version => "xx",
1345
+ :authentication_response => "Y",
1346
+ :directory_response => "Y",
1347
+ :cavv_algorithm => "2",
1348
+ :ds_transaction_id => "some_ds_transaction_id",
1396
1349
  },
1397
1350
  :options => {:verify_card => true}
1398
- }
1351
+ },
1399
1352
  )
1400
1353
 
1401
1354
  expect(result).not_to be_success
@@ -1409,17 +1362,17 @@ describe Braintree::Customer do
1409
1362
  :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1410
1363
  :credit_card => {
1411
1364
  :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',
1365
+ :eci_flag => "02",
1366
+ :cavv => "some_cavv",
1367
+ :xid => "some_xid",
1368
+ :three_d_secure_version => "2.2.1",
1369
+ :authentication_response => "Y",
1370
+ :directory_response => "Y",
1371
+ :cavv_algorithm => "2",
1372
+ :ds_transaction_id => "some_ds_transaction_id",
1420
1373
  },
1421
1374
  :options => {:verify_card => true}
1422
- }
1375
+ },
1423
1376
  )
1424
1377
 
1425
1378
  expect(result).to be_success
@@ -1430,7 +1383,7 @@ describe Braintree::Customer do
1430
1383
  :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1431
1384
  :credit_card => {
1432
1385
  :options => {:verify_card => true}
1433
- }
1386
+ },
1434
1387
  )
1435
1388
  result.success?.should == true
1436
1389
 
@@ -1452,7 +1405,7 @@ describe Braintree::Customer do
1452
1405
  address = Braintree::Address.create!(
1453
1406
  :customer_id => customer.id,
1454
1407
  :first_name => "John",
1455
- :last_name => "Doe"
1408
+ :last_name => "Doe",
1456
1409
  )
1457
1410
 
1458
1411
  customer = Braintree::Customer.update(
@@ -1461,7 +1414,7 @@ describe Braintree::Customer do
1461
1414
  :number => Braintree::Test::CreditCardNumbers::Visa,
1462
1415
  :expiration_date => "12/2009",
1463
1416
  :billing_address_id => address.id
1464
- }
1417
+ },
1465
1418
  ).customer
1466
1419
 
1467
1420
  billing_address = customer.credit_cards.first.billing_address
@@ -1474,12 +1427,93 @@ describe Braintree::Customer do
1474
1427
  customer = Braintree::Customer.create!(:email => "valid@email.com")
1475
1428
  result = Braintree::Customer.update(
1476
1429
  customer.id,
1477
- :email => "@invalid.com"
1430
+ :email => "@invalid.com",
1478
1431
  )
1479
1432
  result.success?.should == false
1480
1433
  result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
1481
1434
  end
1482
1435
 
1436
+ context "verification_currency_iso_code" do
1437
+ it "can update the customer after validating verification_currency_iso_code" do
1438
+ customer = Braintree::Customer.create!(
1439
+ :first_name => "Joe",
1440
+ )
1441
+
1442
+ result = Braintree::Customer.update(
1443
+ customer.id,
1444
+ :first_name => "New Joe",
1445
+ :credit_card => {
1446
+ :cardholder_name => "New Joe Cardholder",
1447
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1448
+ :expiration_date => "12/2009",
1449
+ :options => {:verify_card => true, :verification_currency_iso_code => "USD"}
1450
+ },
1451
+ )
1452
+ result.success?.should == true
1453
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
1454
+ end
1455
+
1456
+ it "can update the customer after validating verification_currency_iso_code against the given verification_merchant_account_id" do
1457
+ customer = Braintree::Customer.create!(
1458
+ :first_name => "Joe",
1459
+ )
1460
+
1461
+ result = Braintree::Customer.update(
1462
+ customer.id,
1463
+ :first_name => "New Joe",
1464
+ :credit_card => {
1465
+ :cardholder_name => "New Joe Cardholder",
1466
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1467
+ :expiration_date => "12/2009",
1468
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "USD"}
1469
+ },
1470
+ )
1471
+ result.success?.should == true
1472
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
1473
+ result.customer.credit_cards[0].verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
1474
+ end
1475
+
1476
+ it "throws error due to verification_currency_iso_code not matching against the currency configured in default merchant account" do
1477
+ customer = Braintree::Customer.create!(
1478
+ :first_name => "Joe",
1479
+ )
1480
+
1481
+ result = Braintree::Customer.update(
1482
+ customer.id,
1483
+ :first_name => "New Joe",
1484
+ :credit_card => {
1485
+ :cardholder_name => "New Joe Cardholder",
1486
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1487
+ :expiration_date => "12/2009",
1488
+ :options => {:verify_card => true, :verification_currency_iso_code => "GBP"}
1489
+ },
1490
+ )
1491
+ result.success?.should == false
1492
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1493
+
1494
+ end
1495
+
1496
+ it "throws error due to verification_currency_iso_code not matching against the currency configured in the given verification merchant account" do
1497
+ customer = Braintree::Customer.create!(
1498
+ :first_name => "Joe",
1499
+ )
1500
+
1501
+ result = Braintree::Customer.update(
1502
+ customer.id,
1503
+ :first_name => "New Joe",
1504
+ :credit_card => {
1505
+ :cardholder_name => "New Joe Cardholder",
1506
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1507
+ :expiration_date => "12/2009",
1508
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "GBP"}
1509
+ },
1510
+ )
1511
+ result.success?.should == false
1512
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1513
+
1514
+ end
1515
+ end
1516
+
1483
1517
  context "verification_account_type" do
1484
1518
  it "updates the credit card with account_type credit" do
1485
1519
  customer = Braintree::Customer.create!
@@ -1495,7 +1529,7 @@ describe Braintree::Customer do
1495
1529
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
1496
1530
  :verification_account_type => "credit",
1497
1531
  },
1498
- }
1532
+ },
1499
1533
  )
1500
1534
  expect(update_result).to be_success
1501
1535
  end
@@ -1514,7 +1548,7 @@ describe Braintree::Customer do
1514
1548
  :verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
1515
1549
  :verification_account_type => "debit",
1516
1550
  },
1517
- }
1551
+ },
1518
1552
  )
1519
1553
  expect(update_result).to be_success
1520
1554
  end
@@ -1525,12 +1559,12 @@ describe Braintree::Customer do
1525
1559
  it "returns the updated customer if successful" do
1526
1560
  customer = Braintree::Customer.create!(
1527
1561
  :first_name => "Joe",
1528
- :last_name => "Cool"
1562
+ :last_name => "Cool",
1529
1563
  )
1530
1564
  updated_customer = Braintree::Customer.update!(
1531
1565
  customer.id,
1532
1566
  :first_name => "Mr. Joe",
1533
- :last_name => "Super Cool"
1567
+ :last_name => "Super Cool",
1534
1568
  )
1535
1569
  updated_customer.first_name.should == "Mr. Joe"
1536
1570
  updated_customer.last_name.should == "Super Cool"
@@ -1545,214 +1579,7 @@ describe Braintree::Customer do
1545
1579
  end
1546
1580
  end
1547
1581
 
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
1582
+ describe "default_payment_method" do
1756
1583
  it "should return the default credit card for a given customer" do
1757
1584
  customer = Braintree::Customer.create!(
1758
1585
  :credit_card => {
@@ -1761,21 +1588,21 @@ describe Braintree::Customer do
1761
1588
  :options => {
1762
1589
  :make_default => false
1763
1590
  }
1764
- }
1591
+ },
1765
1592
  )
1766
1593
 
1767
- default_credit_card = Braintree::CreditCard.create!(
1594
+ default_payment_method = Braintree::CreditCard.create!(
1768
1595
  :customer_id => customer.id,
1769
1596
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1770
1597
  :expiration_date => "11/2015",
1771
1598
  :options => {
1772
1599
  :make_default => true
1773
- }
1600
+ },
1774
1601
  )
1775
1602
 
1776
1603
  customer = Braintree::Customer.find(customer.id)
1777
1604
 
1778
- customer.default_credit_card.should == default_credit_card
1605
+ customer.default_payment_method.should == default_payment_method
1779
1606
  end
1780
1607
  end
1781
1608
 
@@ -1783,7 +1610,7 @@ describe Braintree::Customer do
1783
1610
  context "future" do
1784
1611
  it "creates a customer with a future paypal account" do
1785
1612
  result = Braintree::Customer.create(
1786
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment
1613
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
1787
1614
  )
1788
1615
 
1789
1616
  result.should be_success
@@ -1797,7 +1624,7 @@ describe Braintree::Customer do
1797
1624
  :options => {
1798
1625
  :make_default => true
1799
1626
  }
1800
- }
1627
+ },
1801
1628
  )
1802
1629
 
1803
1630
  paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
@@ -1806,12 +1633,12 @@ describe Braintree::Customer do
1806
1633
  :token => paypal_account_token,
1807
1634
  :options => {
1808
1635
  :make_default => true
1809
- }
1636
+ },
1810
1637
  )
1811
1638
 
1812
1639
  result = Braintree::Customer.update(
1813
1640
  customer.id,
1814
- :payment_method_nonce => nonce
1641
+ :payment_method_nonce => nonce,
1815
1642
  )
1816
1643
 
1817
1644
  result.should be_success
@@ -1827,7 +1654,7 @@ describe Braintree::Customer do
1827
1654
  :token => paypal_account_token,
1828
1655
  :options => {
1829
1656
  :make_default => true
1830
- }
1657
+ },
1831
1658
  )
1832
1659
 
1833
1660
  result = Braintree::Customer.create(
@@ -1863,7 +1690,7 @@ describe Braintree::Customer do
1863
1690
  :options => {
1864
1691
  :make_default => true
1865
1692
  }
1866
- }
1693
+ },
1867
1694
  )
1868
1695
 
1869
1696
  paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
@@ -1872,7 +1699,7 @@ describe Braintree::Customer do
1872
1699
  :token => paypal_account_token,
1873
1700
  :options => {
1874
1701
  :make_default => true
1875
- }
1702
+ },
1876
1703
  )
1877
1704
 
1878
1705
  result = Braintree::Customer.update(
@@ -1906,7 +1733,7 @@ describe Braintree::Customer do
1906
1733
  context "onetime" do
1907
1734
  it "does not create a customer with a onetime paypal account" do
1908
1735
  result = Braintree::Customer.create(
1909
- :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment
1736
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
1910
1737
  )
1911
1738
 
1912
1739
  result.should_not be_success
@@ -1922,7 +1749,7 @@ describe Braintree::Customer do
1922
1749
  :options => {
1923
1750
  :make_default => true
1924
1751
  }
1925
- }
1752
+ },
1926
1753
  )
1927
1754
 
1928
1755
  paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
@@ -1931,12 +1758,12 @@ describe Braintree::Customer do
1931
1758
  :token => paypal_account_token,
1932
1759
  :options => {
1933
1760
  :make_default => true
1934
- }
1761
+ },
1935
1762
  )
1936
1763
 
1937
1764
  result = Braintree::Customer.update(
1938
1765
  customer.id,
1939
- :payment_method_nonce => nonce
1766
+ :payment_method_nonce => nonce,
1940
1767
  )
1941
1768
 
1942
1769
  result.should_not be_success