braintree 2.103.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +6 -3
  4. data/lib/braintree.rb +5 -17
  5. data/lib/braintree/address.rb +0 -22
  6. data/lib/braintree/base_module.rb +6 -0
  7. data/lib/braintree/bin_data.rb +9 -2
  8. data/lib/braintree/configuration.rb +1 -1
  9. data/lib/braintree/credit_card.rb +0 -75
  10. data/lib/braintree/credit_card_gateway.rb +4 -33
  11. data/lib/braintree/credit_card_verification.rb +13 -0
  12. data/lib/braintree/customer.rb +3 -72
  13. data/lib/braintree/customer_gateway.rb +0 -23
  14. data/lib/braintree/dispute.rb +1 -7
  15. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  16. data/lib/braintree/dispute/transaction.rb +1 -0
  17. data/lib/braintree/dispute_gateway.rb +2 -7
  18. data/lib/braintree/error_codes.rb +144 -170
  19. data/lib/braintree/exceptions.rb +5 -3
  20. data/lib/braintree/gateway.rb +0 -14
  21. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +1 -1
  22. data/lib/braintree/local_payment_completed.rb +1 -1
  23. data/lib/braintree/merchant_account_gateway.rb +2 -0
  24. data/lib/braintree/payment_instrument_type.rb +1 -4
  25. data/lib/braintree/payment_method_gateway.rb +5 -9
  26. data/lib/braintree/payment_method_parser.rb +1 -7
  27. data/lib/braintree/resource_collection.rb +8 -3
  28. data/lib/braintree/subscription.rb +5 -5
  29. data/lib/braintree/successful_result.rb +0 -1
  30. data/lib/braintree/test/credit_card.rb +1 -0
  31. data/lib/braintree/test/nonce.rb +4 -20
  32. data/lib/braintree/transaction.rb +12 -74
  33. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  34. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  35. data/lib/braintree/transaction/installment.rb +28 -0
  36. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  37. data/lib/braintree/transaction/paypal_details.rb +3 -0
  38. data/lib/braintree/transaction/subscription_details.rb +2 -0
  39. data/lib/braintree/transaction_gateway.rb +14 -20
  40. data/lib/braintree/transaction_search.rb +0 -1
  41. data/lib/braintree/util.rb +17 -2
  42. data/lib/braintree/version.rb +2 -2
  43. data/lib/braintree/webhook_notification.rb +0 -10
  44. data/lib/braintree/webhook_testing_gateway.rb +0 -43
  45. data/lib/braintree/xml/libxml.rb +1 -0
  46. data/lib/braintree/xml/parser.rb +11 -34
  47. data/spec/integration/braintree/address_spec.rb +2 -89
  48. data/spec/integration/braintree/client_api/spec_helper.rb +0 -26
  49. data/spec/integration/braintree/credit_card_spec.rb +6 -471
  50. data/spec/integration/braintree/customer_spec.rb +189 -362
  51. data/spec/integration/braintree/dispute_search_spec.rb +3 -3
  52. data/spec/integration/braintree/dispute_spec.rb +1 -2
  53. data/spec/integration/braintree/merchant_spec.rb +2 -2
  54. data/spec/integration/braintree/payment_method_spec.rb +254 -120
  55. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +8 -4
  56. data/spec/integration/braintree/paypal_account_spec.rb +1 -1
  57. data/spec/integration/braintree/subscription_spec.rb +11 -16
  58. data/spec/integration/braintree/transaction_search_spec.rb +3 -3
  59. data/spec/integration/braintree/transaction_spec.rb +300 -534
  60. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +12 -6
  61. data/spec/integration/spec_helper.rb +1 -4
  62. data/spec/spec_helper.rb +2 -11
  63. data/spec/unit/braintree/address_spec.rb +0 -8
  64. data/spec/unit/braintree/credit_card_spec.rb +3 -22
  65. data/spec/unit/braintree/customer_spec.rb +2 -13
  66. data/spec/unit/braintree/dispute_spec.rb +3 -12
  67. data/spec/unit/braintree/http_spec.rb +3 -3
  68. data/spec/unit/braintree/local_payment_completed_spec.rb +14 -0
  69. data/spec/unit/braintree/resource_collection_spec.rb +29 -0
  70. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  71. data/spec/unit/braintree/transaction/paypal_details_spec.rb +59 -0
  72. data/spec/unit/braintree/transaction_spec.rb +1 -35
  73. data/spec/unit/braintree/util_spec.rb +37 -3
  74. data/spec/unit/braintree/webhook_notification_spec.rb +1 -1
  75. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  76. metadata +30 -30
  77. data/lib/braintree/amex_express_checkout_card.rb +0 -38
  78. data/lib/braintree/coinbase_account.rb +0 -34
  79. data/lib/braintree/europe_bank_account.rb +0 -36
  80. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  81. data/lib/braintree/ideal_payment.rb +0 -61
  82. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  83. data/lib/braintree/masterpass_card.rb +0 -81
  84. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  85. data/lib/braintree/transaction/coinbase_details.rb +0 -16
  86. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  87. data/lib/braintree/transaction/masterpass_card_details.rb +0 -47
  88. data/lib/braintree/transparent_redirect.rb +0 -40
  89. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  90. data/lib/braintree/xml/rexml.rb +0 -71
  91. data/spec/hacks/tcp_socket.rb +0 -18
  92. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  93. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  94. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  95. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
  96. data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
@@ -14,7 +14,8 @@ describe Braintree::Transaction do
14
14
  let(:plaid_nonce) { generate_valid_plaid_us_bank_account_nonce }
15
15
 
16
16
  context "nonce" do
17
- it "sale succeeds" do
17
+ # we are temporarily skipping this test until we have a more stable CI env
18
+ xit "sale succeeds" do
18
19
  result = Braintree::Transaction.create(
19
20
  :type => "sale",
20
21
  :amount => Braintree::Test::TransactionAmounts::Authorize,
@@ -41,7 +42,8 @@ describe Braintree::Transaction do
41
42
  end
42
43
 
43
44
  context "token" do
44
- it "payment_method#create then sale succeeds" do
45
+ # we are temporarily skipping this test until we have a more stable CI env
46
+ xit "payment_method#create then sale succeeds" do
45
47
  payment_method = Braintree::PaymentMethod.create(
46
48
  :payment_method_nonce => plaid_nonce,
47
49
  :customer_id => Braintree::Customer.create.customer.id,
@@ -84,7 +86,8 @@ describe Braintree::Transaction do
84
86
  transaction.us_bank_account_details.ach_mandate.accepted_at.should be_a Time
85
87
  end
86
88
 
87
- it "transaction#create store_in_vault then sale succeeds" do
89
+ # we are temporarily skipping this test until we have a more stable CI env
90
+ xit "transaction#create store_in_vault then sale succeeds" do
88
91
  result = Braintree::Transaction.create(
89
92
  :type => "sale",
90
93
  :amount => Braintree::Test::TransactionAmounts::Authorize,
@@ -233,7 +236,8 @@ describe Braintree::Transaction do
233
236
  let(:plaid_nonce) { generate_valid_plaid_us_bank_account_nonce }
234
237
 
235
238
  context "nonce" do
236
- it "sale succeeds" do
239
+ # we are temporarily skipping this test until we have a more stable CI env
240
+ xit "sale succeeds" do
237
241
  result = Braintree::Transaction.create(
238
242
  :type => "sale",
239
243
  :amount => Braintree::Test::TransactionAmounts::Authorize,
@@ -260,7 +264,8 @@ describe Braintree::Transaction do
260
264
  end
261
265
 
262
266
  context "token" do
263
- it "payment_method#create then sale succeeds" do
267
+ # we are temporarily skipping this test until we have a more stable CI env
268
+ xit "payment_method#create then sale succeeds" do
264
269
  result = Braintree::PaymentMethod.create(
265
270
  :payment_method_nonce => plaid_nonce,
266
271
  :customer_id => Braintree::Customer.create.customer.id,
@@ -305,7 +310,8 @@ describe Braintree::Transaction do
305
310
  transaction.us_bank_account_details.ach_mandate.accepted_at.should be_a Time
306
311
  end
307
312
 
308
- it "transaction#create store_in_vault then sale succeeds" do
313
+ # we are temporarily skipping this test until we have a more stable CI env
314
+ xit "transaction#create store_in_vault then sale succeeds" do
309
315
  result = Braintree::Transaction.create(
310
316
  :type => "sale",
311
317
  :amount => Braintree::Test::TransactionAmounts::Authorize,
@@ -5,7 +5,6 @@ unless defined?(INTEGRATION_SPEC_HELPER_LOADED)
5
5
  SSL_TEST_PORT = ENV['SSL_TEST_PORT'] || 8444
6
6
 
7
7
  require File.dirname(__FILE__) + "/../spec_helper"
8
- require File.dirname(__FILE__) + "/../hacks/tcp_socket"
9
8
 
10
9
  def start_ssl_server
11
10
  web_server_pid_file = File.expand_path(File.join(File.dirname(__FILE__), "..", "httpsd.pid"))
@@ -13,9 +12,7 @@ unless defined?(INTEGRATION_SPEC_HELPER_LOADED)
13
12
  FileUtils.rm(web_server_pid_file) if File.exist?(web_server_pid_file)
14
13
  command = File.expand_path(File.join(File.dirname(__FILE__), "..", "script", "httpsd.rb"))
15
14
  `#{command} #{web_server_pid_file}`
16
- TCPSocket.wait_for_service :host => "127.0.0.1", :port => SSL_TEST_PORT
17
-
18
- yield
15
+ TCPSocket.new("127.0.0.1",SSL_TEST_PORT)
19
16
 
20
17
  10.times { unless File.exists?(web_server_pid_file); sleep 1; end }
21
18
  ensure
@@ -4,7 +4,6 @@ unless defined?(SPEC_HELPER_LOADED)
4
4
  require "rubygems"
5
5
  require "bundler/setup"
6
6
  require "rspec"
7
- require "libxml"
8
7
  require "pry"
9
8
 
10
9
  braintree_lib = "#{project_root}/lib"
@@ -28,10 +27,6 @@ unless defined?(SPEC_HELPER_LOADED)
28
27
  end
29
28
  end
30
29
 
31
- def now_in_eastern
32
- (Time.now.utc - 5*60*60).strftime("%Y-%m-%d")
33
- end
34
-
35
30
  module SpecHelper
36
31
 
37
32
  DefaultMerchantAccountId = "sandbox_credit_card"
@@ -44,6 +39,7 @@ unless defined?(SPEC_HELPER_LOADED)
44
39
  AnotherUsBankMerchantAccountId = "another_us_bank_merchant_account"
45
40
  AdyenMerchantAccountId = "adyen_ma"
46
41
  HiperBRLMerchantAccountId = "hiper_brl"
42
+ CardProcessorBRLMerchantAccountId = "card_processor_brl"
47
43
 
48
44
  TrialPlan = {
49
45
  :description => "Plan for integration tests -- with trial",
@@ -188,16 +184,11 @@ unless defined?(SPEC_HELPER_LOADED)
188
184
  end
189
185
 
190
186
  def matches?(xml_string)
191
- @libxml_parse = Braintree::Xml::Parser.hash_from_xml(xml_string, Braintree::Xml::Libxml)
192
- @rexml_parse = Braintree::Xml::Parser.hash_from_xml(xml_string, Braintree::Xml::Rexml)
187
+ @libxml_parse = Braintree::Xml::Parser.hash_from_xml(xml_string)
193
188
  if @libxml_parse != @expected_hash
194
189
  @results = @libxml_parse
195
190
  @failed_parser = "libxml"
196
191
  false
197
- elsif @rexml_parse != @expected_hash
198
- @results = @rexml_parse
199
- @failed_parser = "rexml"
200
- false
201
192
  else
202
193
  true
203
194
  end
@@ -94,12 +94,4 @@ describe Braintree::Address do
94
94
  end.to raise_error(NoMethodError, /protected method .new/)
95
95
  end
96
96
  end
97
-
98
- describe "update" do
99
- it "raises an exception if hash includes an invalid key" do
100
- expect do
101
- Braintree::Address._new(Braintree::Configuration.gateway, {}).update(:street_address => "456 E Main", :invalid_key2 => "foo")
102
- end.to raise_error(ArgumentError, "invalid keys: invalid_key2")
103
- end
104
- end
105
97
  end
@@ -15,7 +15,6 @@ describe Braintree::CreditCard do
15
15
  :billing_address_id,
16
16
  :cardholder_name,
17
17
  :cvv,
18
- :device_session_id,
19
18
  :expiration_date,
20
19
  :expiration_month,
21
20
  :expiration_year,
@@ -23,10 +22,9 @@ describe Braintree::CreditCard do
23
22
  :token,
24
23
  :venmo_sdk_payment_method_code,
25
24
  :device_data,
26
- :fraud_merchant_id,
27
25
  :payment_method_nonce,
28
26
  {:external_vault=>[:network_transaction_id]},
29
- {:options => [:make_default, :verification_merchant_account_id, :verify_card, :verification_amount, :venmo_sdk_session, :fail_on_duplicate_payment_method, :verification_account_type]},
27
+ {:options => [:make_default, :verification_merchant_account_id, :verify_card, :verification_amount, :venmo_sdk_session, :fail_on_duplicate_payment_method, :verification_account_type, :verification_currency_iso_code]},
30
28
  {:billing_address => [
31
29
  :company,
32
30
  :country_code_alpha2,
@@ -63,7 +61,6 @@ describe Braintree::CreditCard do
63
61
  :billing_address_id,
64
62
  :cardholder_name,
65
63
  :cvv,
66
- :device_session_id,
67
64
  :expiration_date,
68
65
  :expiration_month,
69
66
  :expiration_year,
@@ -71,10 +68,9 @@ describe Braintree::CreditCard do
71
68
  :token,
72
69
  :venmo_sdk_payment_method_code,
73
70
  :device_data,
74
- :fraud_merchant_id,
75
71
  :payment_method_nonce,
76
72
  {:external_vault=>[:network_transaction_id]},
77
- {:options => [:make_default, :verification_merchant_account_id, :verify_card, :verification_amount, :venmo_sdk_session, :fail_on_duplicate_payment_method, :verification_account_type]},
73
+ {:options => [:make_default, :verification_merchant_account_id, :verify_card, :verification_amount, :venmo_sdk_session, :fail_on_duplicate_payment_method, :verification_account_type, :verification_currency_iso_code]},
78
74
  {:billing_address => [
79
75
  :company,
80
76
  :country_code_alpha2,
@@ -105,21 +101,6 @@ describe Braintree::CreditCard do
105
101
  end
106
102
  end
107
103
 
108
- describe "self.create_from_transparent_redirect" do
109
- it "raises an exception if the query string is forged" do
110
- expect do
111
- Braintree::CreditCard.create_from_transparent_redirect("http_status=200&forged=query_string")
112
- end.to raise_error(Braintree::ForgedQueryString)
113
- end
114
- end
115
-
116
- describe "self.create_credit_card_url" do
117
- it "returns the url" do
118
- config = Braintree::Configuration.instantiate
119
- Braintree::CreditCard.create_credit_card_url.should == "http#{config.ssl? ? 's' : ''}://#{config.server}:#{config.port}/merchants/integration_merchant_id/payment_methods/all/create_via_transparent_redirect_request"
120
- end
121
- end
122
-
123
104
  describe "==" do
124
105
  it "returns true if given a credit card with the same token" do
125
106
  first = Braintree::CreditCard._new(:gateway, :token => 123)
@@ -253,7 +234,7 @@ describe Braintree::CreditCard do
253
234
  describe "self.update" do
254
235
  it "raises an exception if attributes contain an invalid key" do
255
236
  expect do
256
- Braintree::CreditCard._new(Braintree::Configuration.gateway, {}).update(:invalid_key => 'val')
237
+ Braintree::CreditCard.update(:gateway, :invalid_key => 'val')
257
238
  end.to raise_error(ArgumentError, "invalid keys: invalid_key")
258
239
  end
259
240
  end
@@ -91,7 +91,6 @@ describe Braintree::Customer do
91
91
  :billing_address_id,
92
92
  :cardholder_name,
93
93
  :cvv,
94
- :device_session_id,
95
94
  :expiration_date,
96
95
  :expiration_month,
97
96
  :expiration_year,
@@ -99,10 +98,9 @@ describe Braintree::Customer do
99
98
  :token,
100
99
  :venmo_sdk_payment_method_code,
101
100
  :device_data,
102
- :fraud_merchant_id,
103
101
  :payment_method_nonce,
104
102
  {:external_vault=>[:network_transaction_id]},
105
- {:options => [:make_default, :verification_merchant_account_id, :verify_card, :verification_amount, :venmo_sdk_session, :fail_on_duplicate_payment_method, :verification_account_type]},
103
+ {:options => [:make_default, :verification_merchant_account_id, :verify_card, :verification_amount, :venmo_sdk_session, :fail_on_duplicate_payment_method, :verification_account_type, :verification_currency_iso_code]},
106
104
  {:billing_address => [
107
105
  :company,
108
106
  :country_code_alpha2,
@@ -182,7 +180,6 @@ describe Braintree::Customer do
182
180
  :billing_address_id,
183
181
  :cardholder_name,
184
182
  :cvv,
185
- :device_session_id,
186
183
  :expiration_date,
187
184
  :expiration_month,
188
185
  :expiration_year,
@@ -190,7 +187,6 @@ describe Braintree::Customer do
190
187
  :token,
191
188
  :venmo_sdk_payment_method_code,
192
189
  :device_data,
193
- :fraud_merchant_id,
194
190
  :payment_method_nonce,
195
191
  {:external_vault=>[:network_transaction_id]},
196
192
  {:options => [
@@ -201,6 +197,7 @@ describe Braintree::Customer do
201
197
  :venmo_sdk_session,
202
198
  :fail_on_duplicate_payment_method,
203
199
  :verification_account_type,
200
+ :verification_currency_iso_code,
204
201
  :update_existing_token
205
202
  ]},
206
203
  {:billing_address => [
@@ -259,14 +256,6 @@ describe Braintree::Customer do
259
256
  end
260
257
  end
261
258
 
262
- describe "self.create_from_transparent_redirect" do
263
- it "raises an exception if the query string is forged" do
264
- expect do
265
- Braintree::Customer.create_from_transparent_redirect("http_status=200&forged=query_string")
266
- end.to raise_error(Braintree::ForgedQueryString)
267
- end
268
- end
269
-
270
259
  describe "==" do
271
260
  it "returns true when given a customer with the same id" do
272
261
  first = Braintree::Customer._new(:gateway, :id => 123)
@@ -42,6 +42,7 @@ describe Braintree::Dispute do
42
42
  :amount => "31.00",
43
43
  :id => "open_disputed_transaction",
44
44
  :created_at => Time.utc(2009, 2, 9, 12, 59, 59),
45
+ :installment_count => nil,
45
46
  :order_id => nil,
46
47
  :purchase_order_number => "po",
47
48
  :payment_instrument_subtype => "Visa",
@@ -197,13 +198,6 @@ describe Braintree::Dispute do
197
198
 
198
199
  describe "with optional params" do
199
200
  it "does not raise an exception if the optional parameters are valid" do
200
- Braintree::Http.stub(:new).and_return double.as_null_object
201
- expect do
202
- Braintree::Dispute.add_text_evidence("dispute_id", { content: "a", tag: "", sequence_number: 3 })
203
- end.to_not raise_error
204
- end
205
-
206
- it "does not raise an exception if the category parameter is provided" do
207
201
  Braintree::Http.stub(:new).and_return double.as_null_object
208
202
  expect do
209
203
  Braintree::Dispute.add_text_evidence("dispute_id", { content: "a", category: "", sequence_number: 3 })
@@ -320,12 +314,13 @@ describe Braintree::Dispute do
320
314
  dispute.transaction.amount.should == 31.00
321
315
  dispute.transaction.id.should == "open_disputed_transaction"
322
316
  dispute.transaction.created_at.should == Time.utc(2009, 2, 9, 12, 59, 59)
317
+ dispute.transaction.installment_count.should == nil
323
318
  dispute.transaction.order_id.should == nil
324
319
  dispute.transaction.purchase_order_number.should == "po"
325
320
  dispute.transaction.payment_instrument_subtype.should == "Visa"
326
321
  end
327
322
 
328
- it "converts status_history hash into an array of Dispute::HistoryEvent objects" do
323
+ it "converts status_history hash into an array of Dispute::StatusHistory objects" do
329
324
  dispute = Braintree::Dispute._new(attributes)
330
325
 
331
326
  dispute.status_history.length.should == 1
@@ -396,10 +391,6 @@ describe Braintree::Dispute do
396
391
  describe "comments" do
397
392
  let(:dispute) { Braintree::Dispute._new(attributes) }
398
393
 
399
- it "#forwarded_comments returns `processor_comments`" do
400
- expect(dispute.forwarded_comments).to eq(dispute.processor_comments)
401
- end
402
-
403
394
  it "#processor_comments" do
404
395
  expect(dispute.processor_comments).to eq(attributes[:processor_comments])
405
396
  end
@@ -130,7 +130,7 @@ END
130
130
  expect(default_headers["Accept-Encoding"]).to eq("gzip")
131
131
  expect(default_headers["Content-Type"]).to eq("application/xml")
132
132
  expect(default_headers["User-Agent"]).to match(/Braintree Ruby Gem .*/)
133
- expect(default_headers["X-ApiVersion"]).to eq("5")
133
+ expect(default_headers["X-ApiVersion"]).to eq("6")
134
134
  end
135
135
 
136
136
  it "overwrites defaults with override headers" do
@@ -144,7 +144,7 @@ END
144
144
  expect(headers["Authorization"]).to eq("token")
145
145
  expect(headers["Content-Type"]).to eq("application/xml")
146
146
  expect(headers["User-Agent"]).to match(/Braintree Ruby Gem .*/)
147
- expect(headers["X-ApiVersion"]).to eq("5")
147
+ expect(headers["X-ApiVersion"]).to eq("6")
148
148
  end
149
149
 
150
150
  it "extends default headers when new headers are specified" do
@@ -156,7 +156,7 @@ END
156
156
  expect(headers["Accept-Encoding"]).to eq("gzip")
157
157
  expect(headers["Content-Type"]).to eq("application/xml")
158
158
  expect(headers["User-Agent"]).to match(/Braintree Ruby Gem .*/)
159
- expect(headers["X-ApiVersion"]).to eq("5")
159
+ expect(headers["X-ApiVersion"]).to eq("6")
160
160
  expect(headers["New-Header"]).to eq("New Value")
161
161
  end
162
162
  end
@@ -32,5 +32,19 @@ describe Braintree::LocalPaymentCompleted do
32
32
  local_payment_completed.transaction.order_id.should eq("an-order-id")
33
33
  local_payment_completed.transaction.status.should eq(Braintree::Transaction::Status::Authorized)
34
34
  end
35
+
36
+ it "initializes the object with the appropriate attributes set if no transaction is provided" do
37
+ params = {
38
+ payment_id: "a-payment-id",
39
+ payer_id: "a-payer-id",
40
+ payment_method_nonce: "a-nonce",
41
+ }
42
+ local_payment_completed = Braintree::LocalPaymentCompleted._new(params)
43
+
44
+ local_payment_completed.payment_id.should eq("a-payment-id")
45
+ local_payment_completed.payer_id.should eq("a-payer-id")
46
+ local_payment_completed.payment_method_nonce.should eq("a-nonce")
47
+ local_payment_completed.transaction.should be_nil
48
+ end
35
49
  end
36
50
  end
@@ -18,6 +18,35 @@ describe "Braintree::ResourceCollection" do
18
18
  end
19
19
  end
20
20
 
21
+ describe "#first" do
22
+ it 'returns nil with no results' do
23
+ values = %w(a b c d e)
24
+ collection = Braintree::ResourceCollection.new(:search_results => {:ids => [], :page_size => 2}) do |ids|
25
+ ids.map {|id| values[id] }
26
+ end
27
+
28
+ collection.first.should == nil
29
+ end
30
+
31
+ context 'with results' do
32
+ let(:collection) do
33
+ values = %w(a b c d e)
34
+
35
+ Braintree::ResourceCollection.new(:search_results => {:ids => [0,1,2,3,4], :page_size => 2}) do |ids|
36
+ ids.map {|id| values[id] }
37
+ end
38
+ end
39
+
40
+ it 'returns the first occourence' do
41
+ collection.first.should == 'a'
42
+ end
43
+
44
+ it 'returns the first N occourences' do
45
+ collection.first(4).should == ['a','b','c','d']
46
+ end
47
+ end
48
+ end
49
+
21
50
  describe "#ids" do
22
51
  it "returns a list of the resource collection ids" do
23
52
  collection = Braintree::ResourceCollection.new(:search_results => {:ids => [0,1,2,3,4], :page_size => 2})
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+ describe Braintree::Transaction::Installment do
4
+ describe "inspect" do
5
+ it "assigns all fields" do
6
+ adjustment_attributes = {
7
+ :amount => "0.98",
8
+ :kind => "REFUND",
9
+ :projected_disbursement_date => "2020-01-03 01:02:03Z",
10
+ :actual_disbursement_date => "2020-01-04 01:02:03Z",
11
+ }
12
+ installment_attributes = {
13
+ :id => "abc123",
14
+ :amount => "1.23",
15
+ :projected_disbursement_date => "2020-01-01 01:02:03Z",
16
+ :actual_disbursement_date => "2020-01-02 01:02:03Z",
17
+ :adjustments => [adjustment_attributes],
18
+ }
19
+
20
+ installment = Braintree::Transaction::Installment.new(installment_attributes)
21
+
22
+ expect(installment.inspect).to eq('#<id: "abc123", amount: 0.123e1, projected_disbursement_date: "2020-01-01 01:02:03Z", actual_disbursement_date: "2020-01-02 01:02:03Z", adjustments: [#<amount: 0.98e0, kind: "REFUND", projected_disbursement_date: "2020-01-03 01:02:03Z", actual_disbursement_date: "2020-01-04 01:02:03Z">]>')
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+ describe Braintree::Transaction::PayPalDetails do
4
+ describe "initialize" do
5
+ it "sets all fields" do
6
+ details = Braintree::Transaction::PayPalDetails.new(
7
+ :authorization_id => "id",
8
+ :billing_agreement_id => "billing-agreement-id",
9
+ :capture_id => "capture-id",
10
+ :custom_field => "custom-field",
11
+ :debug_id => "debug-id",
12
+ :description => "description",
13
+ :image_url => "www.image.com",
14
+ :implicitly_vaulted_payment_method_global_id => "global-id",
15
+ :implicitly_vaulted_payment_method_token => "payment-method-token",
16
+ :payee_email => "payee@example.com",
17
+ :payee_id => "payee-id",
18
+ :payer_email => "payer@example.com",
19
+ :payer_first_name => "Grace",
20
+ :payer_id => "payer-id",
21
+ :payer_last_name => "Hopper",
22
+ :payer_status =>"status",
23
+ :payment_id => "payment-id",
24
+ :refund_from_transaction_fee_amount => "1.00",
25
+ :refund_from_transaction_fee_currency_iso_code => "123",
26
+ :refund_id => "refund-id",
27
+ :seller_protection_status => "seller-protection-status",
28
+ :token => "token",
29
+ :transaction_fee_amount => "2.00",
30
+ :transaction_fee_currency_iso_code => "123"
31
+ )
32
+
33
+ expect(details.authorization_id).to eq("id")
34
+ expect(details.billing_agreement_id).to eq("billing-agreement-id")
35
+ expect(details.capture_id).to eq("capture-id")
36
+ expect(details.custom_field).to eq("custom-field")
37
+ expect(details.debug_id).to eq("debug-id")
38
+ expect(details.description).to eq("description")
39
+ expect(details.image_url).to eq("www.image.com")
40
+ expect(details.implicitly_vaulted_payment_method_global_id).to eq("global-id")
41
+ expect(details.implicitly_vaulted_payment_method_token).to eq("payment-method-token")
42
+ expect(details.payee_email).to eq("payee@example.com")
43
+ expect(details.payee_id).to eq("payee-id")
44
+ expect(details.payer_email).to eq("payer@example.com")
45
+ expect(details.payer_first_name).to eq("Grace")
46
+ expect(details.payer_id).to eq("payer-id")
47
+ expect(details.payer_last_name).to eq("Hopper")
48
+ expect(details.payer_status).to eq("status")
49
+ expect(details.payment_id).to eq("payment-id")
50
+ expect(details.refund_from_transaction_fee_amount).to eq("1.00")
51
+ expect(details.refund_from_transaction_fee_currency_iso_code).to eq("123")
52
+ expect(details.refund_id).to eq("refund-id")
53
+ expect(details.seller_protection_status).to eq("seller-protection-status")
54
+ expect(details.token).to eq("token")
55
+ expect(details.transaction_fee_amount).to eq("2.00")
56
+ expect(details.transaction_fee_currency_iso_code).to eq("123")
57
+ end
58
+ end
59
+ end