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
@@ -60,7 +60,7 @@ describe Braintree::Transaction, "search" do
60
60
  :postal_code => "54321",
61
61
  :region => "MA",
62
62
  :street_address => "456 Road"
63
- }
63
+ },
64
64
  )
65
65
 
66
66
  SpecHelper.settle_transaction transaction.id
@@ -133,20 +133,20 @@ describe Braintree::Transaction, "search" do
133
133
  it "searches on users" do
134
134
  transaction = Braintree::Transaction.sale!(
135
135
  :amount => Braintree::Test::TransactionAmounts::Authorize,
136
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment
136
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
137
137
  )
138
138
 
139
139
  collection = Braintree::Transaction.search do |search|
140
140
  search.user.is "integration_user_public_id"
141
141
  end
142
142
 
143
- collection.any?{ |t| t.id == transaction.id }.should == true
143
+ collection.any? { |t| t.id == transaction.id }.should == true
144
144
  end
145
145
 
146
146
  it "searches on paypal transactions" do
147
147
  transaction = Braintree::Transaction.sale!(
148
148
  :amount => Braintree::Test::TransactionAmounts::Authorize,
149
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment
149
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
150
150
  )
151
151
 
152
152
  paypal_details = transaction.paypal_details
@@ -161,6 +161,42 @@ describe Braintree::Transaction, "search" do
161
161
  collection.first.id.should == transaction.id
162
162
  end
163
163
 
164
+ it "searches on store_id" do
165
+ transaction_id = "contact_visa_transaction"
166
+ store_id = "store-id"
167
+
168
+ collection = Braintree::Transaction.search do |search|
169
+ search.id.is transaction_id
170
+ search.store_ids.in store_id
171
+ end
172
+
173
+ collection.maximum_size.should == 1
174
+ collection.first.id.should == transaction_id
175
+ end
176
+
177
+ it "searches on reason_code" do
178
+ transaction_id = "ach_txn_ret1"
179
+ reason_code = "R01"
180
+
181
+ collection = Braintree::Transaction.search do |search|
182
+ search.reason_code.in reason_code
183
+ end
184
+
185
+ collection.maximum_size.should == 1
186
+ collection.first.id.should == transaction_id
187
+ collection.first.ach_return_responses.first[:reason_code].should == "R01"
188
+ end
189
+
190
+ it "searches on reason_codes" do
191
+ reason_code = "any_reason_code"
192
+
193
+ collection = Braintree::Transaction.search do |search|
194
+ search.reason_code.is reason_code
195
+ end
196
+
197
+ collection.maximum_size.should == 2
198
+ end
199
+
164
200
  context "multiple value fields" do
165
201
  it "searches on created_using" do
166
202
  transaction = Braintree::Transaction.sale!(
@@ -168,7 +204,7 @@ describe Braintree::Transaction, "search" do
168
204
  :credit_card => {
169
205
  :number => Braintree::Test::CreditCardNumbers::Visa,
170
206
  :expiration_date => "05/12"
171
- }
207
+ },
172
208
  )
173
209
 
174
210
  collection = Braintree::Transaction.search do |search|
@@ -199,7 +235,7 @@ describe Braintree::Transaction, "search" do
199
235
  :credit_card => {
200
236
  :number => Braintree::Test::CreditCardNumbers::Visa,
201
237
  :expiration_date => "05/12"
202
- }
238
+ },
203
239
  )
204
240
 
205
241
  collection = Braintree::Transaction.search do |search|
@@ -230,7 +266,7 @@ describe Braintree::Transaction, "search" do
230
266
  :credit_card => {
231
267
  :number => Braintree::Test::CreditCardNumbers::Visa,
232
268
  :expiration_date => "05/12"
233
- }
269
+ },
234
270
  )
235
271
 
236
272
  collection = Braintree::Transaction.search do |search|
@@ -261,7 +297,7 @@ describe Braintree::Transaction, "search" do
261
297
  :credit_card => {
262
298
  :number => Braintree::Test::CreditCardNumbers::Visa,
263
299
  :expiration_date => "05/12"
264
- }
300
+ },
265
301
  )
266
302
 
267
303
  collection = Braintree::Transaction.search do |search|
@@ -301,7 +337,7 @@ describe Braintree::Transaction, "search" do
301
337
  :number => Braintree::Test::CreditCardNumbers::Elo,
302
338
  :cvv => "737",
303
339
  :expiration_date => "10/2020"
304
- }
340
+ },
305
341
  )
306
342
 
307
343
  collection = Braintree::Transaction.search do |search|
@@ -318,7 +354,7 @@ describe Braintree::Transaction, "search" do
318
354
  :credit_card => {
319
355
  :number => Braintree::Test::CreditCardNumbers::Visa,
320
356
  :expiration_date => "05/12"
321
- }
357
+ },
322
358
  )
323
359
 
324
360
  collection = Braintree::Transaction.search do |search|
@@ -333,7 +369,7 @@ describe Braintree::Transaction, "search" do
333
369
  it "searches by payment instrument type PayPal" do
334
370
  transaction = Braintree::Transaction.sale!(
335
371
  :amount => Braintree::Test::TransactionAmounts::Authorize,
336
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment
372
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
337
373
  )
338
374
 
339
375
  collection = Braintree::Transaction.search do |search|
@@ -348,7 +384,7 @@ describe Braintree::Transaction, "search" do
348
384
  it "searches by payment instrument type LocalPaymentDetail" do
349
385
  transaction = Braintree::Transaction.sale!(
350
386
  :amount => Braintree::Test::TransactionAmounts::Authorize,
351
- :payment_method_nonce => Braintree::Test::Nonce::LocalPayment
387
+ :payment_method_nonce => Braintree::Test::Nonce::LocalPayment,
352
388
  )
353
389
 
354
390
  collection = Braintree::Transaction.search do |search|
@@ -363,7 +399,7 @@ describe Braintree::Transaction, "search" do
363
399
  it "searches by payment instrument type ApplePay" do
364
400
  transaction = Braintree::Transaction.sale!(
365
401
  :amount => Braintree::Test::TransactionAmounts::Authorize,
366
- :payment_method_nonce => Braintree::Test::Nonce::ApplePayVisa
402
+ :payment_method_nonce => Braintree::Test::Nonce::ApplePayVisa,
367
403
  )
368
404
 
369
405
  collection = Braintree::Transaction.search do |search|
@@ -381,7 +417,7 @@ describe Braintree::Transaction, "search" do
381
417
  :credit_card => {
382
418
  :number => Braintree::Test::CreditCardNumbers::Visa,
383
419
  :expiration_date => "05/12"
384
- }
420
+ },
385
421
  )
386
422
 
387
423
  collection = Braintree::Transaction.search do |search|
@@ -406,6 +442,17 @@ describe Braintree::Transaction, "search" do
406
442
  collection.maximum_size.should == 0
407
443
  end
408
444
 
445
+ it "searches for settlement_confirmed transaction" do
446
+ transaction_id = "settlement_confirmed_txn"
447
+
448
+ collection = Braintree::Transaction.search do |search|
449
+ search.id.is transaction_id
450
+ end
451
+
452
+ collection.maximum_size.should == 1
453
+ collection.first.id.should == transaction_id
454
+ end
455
+
409
456
  it "finds expired authorizations by status" do
410
457
  collection = Braintree::Transaction.search do |search|
411
458
  search.status.in Braintree::Transaction::Status::AuthorizationExpired
@@ -421,7 +468,7 @@ describe Braintree::Transaction, "search" do
421
468
  :credit_card => {
422
469
  :number => Braintree::Test::CreditCardNumbers::Visa,
423
470
  :expiration_date => "05/12"
424
- }
471
+ },
425
472
  )
426
473
 
427
474
  collection = Braintree::Transaction.search do |search|
@@ -454,7 +501,7 @@ describe Braintree::Transaction, "search" do
454
501
  :cardholder_name => cardholder_name,
455
502
  :number => Braintree::Test::CreditCardNumbers::Visa,
456
503
  :expiration_date => "05/12"
457
- }
504
+ },
458
505
  )
459
506
 
460
507
  transaction = Braintree::Transaction.sale!(
@@ -464,11 +511,11 @@ describe Braintree::Transaction, "search" do
464
511
  :number => Braintree::Test::CreditCardNumbers::Visa,
465
512
  :expiration_date => "05/12"
466
513
  },
467
- :options => { :submit_for_settlement => true }
514
+ :options => {:submit_for_settlement => true},
468
515
  )
469
516
  SpecHelper.settle_transaction transaction.id
470
517
 
471
- refund_transaction = transaction.refund.new_transaction
518
+ refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
472
519
 
473
520
  collection = Braintree::Transaction.search do |search|
474
521
  search.credit_card_cardholder_name.is cardholder_name
@@ -495,6 +542,42 @@ describe Braintree::Transaction, "search" do
495
542
  collection.maximum_size.should == 1
496
543
  collection.first.id.should == credit_transaction.id
497
544
  end
545
+
546
+ it "searches on store_ids" do
547
+ transaction_id = "contact_visa_transaction"
548
+ store_ids = ["store-id"]
549
+
550
+ collection = Braintree::Transaction.search do |search|
551
+ search.id.is transaction_id
552
+ search.store_ids.in store_ids
553
+ end
554
+
555
+ collection.maximum_size.should == 1
556
+ collection.first.id.should == transaction_id
557
+ end
558
+
559
+ it "searches on reason_codes for 2 items" do
560
+ reason_code = ["R01", "R02"]
561
+
562
+ collection = Braintree::Transaction.search do |search|
563
+ search.reason_code.in reason_code
564
+ end
565
+
566
+ collection.maximum_size.should == 2
567
+ end
568
+
569
+ it "searches on a reason_code" do
570
+ reason_code = ["R01"]
571
+ transaction_id = "ach_txn_ret1"
572
+
573
+ collection = Braintree::Transaction.search do |search|
574
+ search.reason_code.in reason_code
575
+ end
576
+
577
+ collection.maximum_size.should == 1
578
+ collection.first.id.should == transaction_id
579
+ end
580
+
498
581
  end
499
582
 
500
583
  context "invalid search" do
@@ -516,7 +599,7 @@ describe Braintree::Transaction, "search" do
516
599
  :credit_card => {
517
600
  :number => Braintree::Test::CreditCardNumbers::Visa,
518
601
  :expiration_date => "05/12"
519
- }
602
+ },
520
603
  )
521
604
 
522
605
  collection = Braintree::Transaction.search do |search|
@@ -557,7 +640,7 @@ describe Braintree::Transaction, "search" do
557
640
  :credit_card => {
558
641
  :number => Braintree::Test::CreditCardNumbers::Visa,
559
642
  :expiration_date => "05/12"
560
- }
643
+ },
561
644
  )
562
645
 
563
646
  collection = Braintree::Transaction.search do |search|
@@ -576,7 +659,7 @@ describe Braintree::Transaction, "search" do
576
659
  :credit_card => {
577
660
  :number => Braintree::Test::CreditCardNumbers::Visa,
578
661
  :expiration_date => "05/12"
579
- }
662
+ },
580
663
  )
581
664
 
582
665
  created_at = transaction.created_at
@@ -586,7 +669,7 @@ describe Braintree::Transaction, "search" do
586
669
  search.id.is transaction.id
587
670
  search.created_at.between(
588
671
  created_at - 60,
589
- created_at + 60
672
+ created_at + 60,
590
673
  )
591
674
  end
592
675
 
@@ -613,7 +696,7 @@ describe Braintree::Transaction, "search" do
613
696
  search.id.is transaction.id
614
697
  search.created_at.between(
615
698
  created_at - 300,
616
- created_at - 100
699
+ created_at - 100,
617
700
  )
618
701
  end
619
702
 
@@ -634,7 +717,7 @@ describe Braintree::Transaction, "search" do
634
717
  :credit_card => {
635
718
  :number => Braintree::Test::CreditCardNumbers::Visa,
636
719
  :expiration_date => "05/12"
637
- }
720
+ },
638
721
  )
639
722
 
640
723
  now = Time.now
@@ -643,7 +726,7 @@ describe Braintree::Transaction, "search" do
643
726
  search.id.is transaction.id
644
727
  search.created_at.between(
645
728
  now - 60,
646
- now + 60
729
+ now + 60,
647
730
  )
648
731
  end
649
732
 
@@ -670,7 +753,7 @@ describe Braintree::Transaction, "search" do
670
753
  search.id.is transaction.id
671
754
  search.created_at.between(
672
755
  now - 300,
673
- now - 100
756
+ now - 100,
674
757
  )
675
758
  end
676
759
 
@@ -683,14 +766,14 @@ describe Braintree::Transaction, "search" do
683
766
  :credit_card => {
684
767
  :number => Braintree::Test::CreditCardNumbers::Visa,
685
768
  :expiration_date => "05/12"
686
- }
769
+ },
687
770
  )
688
771
 
689
772
  collection = Braintree::Transaction.search do |search|
690
773
  search.id.is transaction.id
691
774
  search.created_at.between(
692
775
  Date.today - 1,
693
- Date.today + 1
776
+ Date.today + 1,
694
777
  )
695
778
  end
696
779
 
@@ -699,6 +782,28 @@ describe Braintree::Transaction, "search" do
699
782
  end
700
783
  end
701
784
 
785
+ context "ach return response created at" do
786
+ it "it finds records within date range of the custom field" do
787
+ reason_code = "any_reason_code"
788
+
789
+ date_search = Braintree::Transaction.search do |search|
790
+ search.ach_return_responses_created_at.between(DateTime.now - 1.0, DateTime.now + 1.0)
791
+ end
792
+
793
+ date_search.maximum_size.should == 2
794
+ end
795
+
796
+ it "it does not find records not within date range of the custom field" do
797
+ reason_code = "any_reason_code"
798
+
799
+ neg_date_search = Braintree::Transaction.search do |search|
800
+ search.ach_return_responses_created_at.between(DateTime.now + 1.0, DateTime.now - 1.0)
801
+ end
802
+
803
+ neg_date_search.maximum_size.should == 0
804
+ end
805
+ end
806
+
702
807
  context "disbursement_date" do
703
808
  it "searches on disbursement_date in UTC, as a date" do
704
809
  disbursement_time = Date.parse("2013-04-10")
@@ -708,7 +813,7 @@ describe Braintree::Transaction, "search" do
708
813
  search.id.is transaction_id
709
814
  search.disbursement_date.between(
710
815
  disbursement_time - 60,
711
- disbursement_time + 60
816
+ disbursement_time + 60,
712
817
  )
713
818
  end
714
819
 
@@ -735,7 +840,7 @@ describe Braintree::Transaction, "search" do
735
840
  search.id.is transaction_id
736
841
  search.disbursement_date.between(
737
842
  disbursement_time - 300,
738
- disbursement_time - 100
843
+ disbursement_time - 100,
739
844
  )
740
845
  end
741
846
 
@@ -758,7 +863,7 @@ describe Braintree::Transaction, "search" do
758
863
  search.id.is transaction_id
759
864
  search.disbursement_date.between(
760
865
  now - 60,
761
- now + 60
866
+ now + 60,
762
867
  )
763
868
  end
764
869
 
@@ -785,7 +890,7 @@ describe Braintree::Transaction, "search" do
785
890
  search.id.is transaction_id
786
891
  search.disbursement_date.between(
787
892
  now - 300,
788
- now - 100
893
+ now - 100,
789
894
  )
790
895
  end
791
896
 
@@ -800,7 +905,7 @@ describe Braintree::Transaction, "search" do
800
905
  search.id.is transaction_id
801
906
  search.disbursement_date.between(
802
907
  disbursement_date - 1,
803
- disbursement_date + 1
908
+ disbursement_date + 1,
804
909
  )
805
910
  end
806
911
 
@@ -816,7 +921,7 @@ describe Braintree::Transaction, "search" do
816
921
  :credit_card => {
817
922
  :number => Braintree::Test::CreditCardNumbers::Disputes::Chargeback,
818
923
  :expiration_date => "03/18"
819
- }
924
+ },
820
925
  )
821
926
 
822
927
  @disputed_date = @disputed_transaction.disputes.first.received_date
@@ -841,7 +946,7 @@ describe Braintree::Transaction, "search" do
841
946
  search.id.is @disputed_transaction.id
842
947
  search.dispute_date.between(
843
948
  @disputed_time - 60,
844
- @disputed_time + 60
949
+ @disputed_time + 60,
845
950
  )
846
951
  end
847
952
 
@@ -880,7 +985,7 @@ describe Braintree::Transaction, "search" do
880
985
  search.id.is @disputed_transaction.id
881
986
  search.dispute_date.between(
882
987
  now - 60,
883
- now + 60
988
+ now + 60,
884
989
  )
885
990
  end
886
991
 
@@ -908,7 +1013,7 @@ describe Braintree::Transaction, "search" do
908
1013
  search.id.is @disputed_transaction.id
909
1014
  search.dispute_date.between(
910
1015
  @disputed_date - 1,
911
- @disputed_date + 1
1016
+ @disputed_date + 1,
912
1017
  )
913
1018
  end
914
1019
 
@@ -924,14 +1029,14 @@ describe Braintree::Transaction, "search" do
924
1029
  :credit_card => {
925
1030
  :number => Braintree::Test::CreditCardNumbers::Visa,
926
1031
  :expiration_date => "05/12"
927
- }
1032
+ },
928
1033
  )
929
1034
 
930
1035
  collection = Braintree::Transaction.search do |search|
931
1036
  search.id.is transaction.id
932
1037
  search.authorized_at.between(
933
1038
  Date.today - 2,
934
- Date.today - 1
1039
+ Date.today - 1,
935
1040
  )
936
1041
  end
937
1042
 
@@ -941,7 +1046,7 @@ describe Braintree::Transaction, "search" do
941
1046
  search.id.is transaction.id
942
1047
  search.authorized_at.between(
943
1048
  Date.today - 1,
944
- Date.today + 1
1049
+ Date.today + 1,
945
1050
  )
946
1051
  end
947
1052
 
@@ -955,14 +1060,14 @@ describe Braintree::Transaction, "search" do
955
1060
  :credit_card => {
956
1061
  :number => Braintree::Test::CreditCardNumbers::Visa,
957
1062
  :expiration_date => "05/12"
958
- }
1063
+ },
959
1064
  ).transaction
960
1065
 
961
1066
  collection = Braintree::Transaction.search do |search|
962
1067
  search.id.is transaction.id
963
1068
  search.failed_at.between(
964
1069
  Date.today - 2,
965
- Date.today - 1
1070
+ Date.today - 1,
966
1071
  )
967
1072
  end
968
1073
 
@@ -972,7 +1077,7 @@ describe Braintree::Transaction, "search" do
972
1077
  search.id.is transaction.id
973
1078
  search.failed_at.between(
974
1079
  Date.today - 1,
975
- Date.today + 1
1080
+ Date.today + 1,
976
1081
  )
977
1082
  end
978
1083
 
@@ -984,7 +1089,7 @@ describe Braintree::Transaction, "search" do
984
1089
  collection = Braintree::Transaction.search do |search|
985
1090
  search.authorization_expired_at.between(
986
1091
  Date.today - 2,
987
- Date.today - 1
1092
+ Date.today - 1,
988
1093
  )
989
1094
  end
990
1095
 
@@ -993,7 +1098,7 @@ describe Braintree::Transaction, "search" do
993
1098
  collection = Braintree::Transaction.search do |search|
994
1099
  search.authorization_expired_at.between(
995
1100
  Date.today - 1,
996
- Date.today + 1
1101
+ Date.today + 1,
997
1102
  )
998
1103
  end
999
1104
 
@@ -1017,14 +1122,14 @@ describe Braintree::Transaction, "search" do
1017
1122
  :number => Braintree::Test::CreditCardNumbers::Visa,
1018
1123
  :expiration_date => "05/12",
1019
1124
  :cvv => "200"
1020
- }
1125
+ },
1021
1126
  ).transaction
1022
1127
 
1023
1128
  collection = Braintree::Transaction.search do |search|
1024
1129
  search.id.is transaction.id
1025
1130
  search.gateway_rejected_at.between(
1026
1131
  Date.today - 2,
1027
- Date.today - 1
1132
+ Date.today - 1,
1028
1133
  )
1029
1134
  end
1030
1135
 
@@ -1034,7 +1139,7 @@ describe Braintree::Transaction, "search" do
1034
1139
  search.id.is transaction.id
1035
1140
  search.gateway_rejected_at.between(
1036
1141
  Date.today - 1,
1037
- Date.today + 1
1142
+ Date.today + 1,
1038
1143
  )
1039
1144
  end
1040
1145
 
@@ -1053,14 +1158,14 @@ describe Braintree::Transaction, "search" do
1053
1158
  :credit_card => {
1054
1159
  :number => Braintree::Test::CreditCardNumbers::Visa,
1055
1160
  :expiration_date => "05/12"
1056
- }
1161
+ },
1057
1162
  ).transaction
1058
1163
 
1059
1164
  collection = Braintree::Transaction.search do |search|
1060
1165
  search.id.is transaction.id
1061
1166
  search.processor_declined_at.between(
1062
1167
  Date.today - 2,
1063
- Date.today - 1
1168
+ Date.today - 1,
1064
1169
  )
1065
1170
  end
1066
1171
 
@@ -1070,7 +1175,7 @@ describe Braintree::Transaction, "search" do
1070
1175
  search.id.is transaction.id
1071
1176
  search.processor_declined_at.between(
1072
1177
  Date.today - 1,
1073
- Date.today + 1
1178
+ Date.today + 1,
1074
1179
  )
1075
1180
  end
1076
1181
 
@@ -1087,7 +1192,7 @@ describe Braintree::Transaction, "search" do
1087
1192
  },
1088
1193
  :options => {
1089
1194
  :submit_for_settlement => true
1090
- }
1195
+ },
1091
1196
  ).transaction
1092
1197
 
1093
1198
  SpecHelper.settle_transaction transaction.id
@@ -1096,7 +1201,7 @@ describe Braintree::Transaction, "search" do
1096
1201
  search.id.is transaction.id
1097
1202
  search.settled_at.between(
1098
1203
  Date.today - 2,
1099
- Date.today - 1
1204
+ Date.today - 1,
1100
1205
  )
1101
1206
  end
1102
1207
 
@@ -1106,7 +1211,7 @@ describe Braintree::Transaction, "search" do
1106
1211
  search.id.is transaction.id
1107
1212
  search.settled_at.between(
1108
1213
  Date.today - 1,
1109
- Date.today + 1
1214
+ Date.today + 1,
1110
1215
  )
1111
1216
  end
1112
1217
 
@@ -1123,14 +1228,14 @@ describe Braintree::Transaction, "search" do
1123
1228
  },
1124
1229
  :options => {
1125
1230
  :submit_for_settlement => true
1126
- }
1231
+ },
1127
1232
  ).transaction
1128
1233
 
1129
1234
  collection = Braintree::Transaction.search do |search|
1130
1235
  search.id.is transaction.id
1131
1236
  search.submitted_for_settlement_at.between(
1132
1237
  Date.today - 2,
1133
- Date.today - 1
1238
+ Date.today - 1,
1134
1239
  )
1135
1240
  end
1136
1241
 
@@ -1140,7 +1245,7 @@ describe Braintree::Transaction, "search" do
1140
1245
  search.id.is transaction.id
1141
1246
  search.submitted_for_settlement_at.between(
1142
1247
  Date.today - 1,
1143
- Date.today + 1
1248
+ Date.today + 1,
1144
1249
  )
1145
1250
  end
1146
1251
 
@@ -1154,7 +1259,7 @@ describe Braintree::Transaction, "search" do
1154
1259
  :credit_card => {
1155
1260
  :number => Braintree::Test::CreditCardNumbers::Visa,
1156
1261
  :expiration_date => "05/12"
1157
- }
1262
+ },
1158
1263
  )
1159
1264
  transaction = Braintree::Transaction.void(transaction.id).transaction
1160
1265
 
@@ -1162,7 +1267,7 @@ describe Braintree::Transaction, "search" do
1162
1267
  search.id.is transaction.id
1163
1268
  search.voided_at.between(
1164
1269
  Date.today - 2,
1165
- Date.today - 1
1270
+ Date.today - 1,
1166
1271
  )
1167
1272
  end
1168
1273
 
@@ -1172,7 +1277,7 @@ describe Braintree::Transaction, "search" do
1172
1277
  search.id.is transaction.id
1173
1278
  search.voided_at.between(
1174
1279
  Date.today - 1,
1175
- Date.today + 1
1280
+ Date.today + 1,
1176
1281
  )
1177
1282
  end
1178
1283
 
@@ -1190,18 +1295,18 @@ describe Braintree::Transaction, "search" do
1190
1295
  },
1191
1296
  :options => {
1192
1297
  :submit_for_settlement => true
1193
- }
1298
+ },
1194
1299
  )
1195
1300
 
1196
1301
  collection = Braintree::Transaction.search do |search|
1197
1302
  search.id.is transaction.id
1198
1303
  search.authorized_at.between(
1199
1304
  Date.today - 1,
1200
- Date.today + 1
1305
+ Date.today + 1,
1201
1306
  )
1202
1307
  search.submitted_for_settlement_at.between(
1203
1308
  Date.today - 1,
1204
- Date.today + 1
1309
+ Date.today + 1,
1205
1310
  )
1206
1311
  end
1207
1312
 
@@ -1213,7 +1318,7 @@ describe Braintree::Transaction, "search" do
1213
1318
  collection = Braintree::Transaction.search
1214
1319
  collection.maximum_size.should > 100
1215
1320
 
1216
- transaction_ids = collection.map {|t| t.id }.uniq.compact
1321
+ transaction_ids = collection.map { |t| t.id }.uniq.compact
1217
1322
  transaction_ids.size.should == collection.maximum_size
1218
1323
  end
1219
1324
 
@@ -1225,7 +1330,7 @@ describe Braintree::Transaction, "search" do
1225
1330
  :number => Braintree::Test::CreditCardNumbers::Visa,
1226
1331
  :expiration_date => "05/2012",
1227
1332
  :cardholder_name => "Tom Smith"
1228
- }
1333
+ },
1229
1334
  )
1230
1335
  end
1231
1336
 
@@ -1316,12 +1421,12 @@ describe Braintree::Transaction, "search" do
1316
1421
  end
1317
1422
 
1318
1423
  context "when the search times out" do
1319
- it "raises a Down for Maintenance Error" do
1424
+ it "raises a UnexpectedError" do
1320
1425
  expect {
1321
1426
  collection = Braintree::Transaction.search do |search|
1322
- search.amount.is -10
1427
+ search.amount.is(-10)
1323
1428
  end
1324
- }.to raise_error(Braintree::DownForMaintenanceError)
1429
+ }.to raise_error(Braintree::UnexpectedError)
1325
1430
  end
1326
1431
  end
1327
1432
  end
@@ -1336,7 +1441,7 @@ describe Braintree::Transaction, "search" do
1336
1441
  :number => Braintree::Test::CreditCardNumbers::Visa,
1337
1442
  :expiration_date => "05/2012",
1338
1443
  :cardholder_name => "#{cardholder_name} #{index}"
1339
- }
1444
+ },
1340
1445
  )
1341
1446
  end
1342
1447
 
@@ -1353,7 +1458,7 @@ describe Braintree::Transaction, "search" do
1353
1458
  :number => Braintree::Test::CreditCardNumbers::Visa,
1354
1459
  :expiration_date => "05/2012",
1355
1460
  :cardholder_name => new_cardholder_name,
1356
- }
1461
+ },
1357
1462
  )
1358
1463
 
1359
1464
  transactions = collection.to_a