braintree 4.9.0 → 4.11.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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/lib/braintree/apple_pay_card.rb +2 -0
  3. data/lib/braintree/credit_card_verification_gateway.rb +18 -5
  4. data/lib/braintree/customer.rb +4 -1
  5. data/lib/braintree/dispute.rb +9 -0
  6. data/lib/braintree/dispute_search.rb +1 -0
  7. data/lib/braintree/error_codes.rb +7 -0
  8. data/lib/braintree/gateway.rb +4 -0
  9. data/lib/braintree/payment_instrument_type.rb +7 -6
  10. data/lib/braintree/payment_method_gateway.rb +2 -0
  11. data/lib/braintree/payment_method_nonce_details.rb +3 -0
  12. data/lib/braintree/payment_method_parser.rb +2 -0
  13. data/lib/braintree/sepa_direct_debit_account.rb +60 -0
  14. data/lib/braintree/sepa_direct_debit_account_gateway.rb +25 -0
  15. data/lib/braintree/sepa_direct_debit_account_nonce_details.rb +28 -0
  16. data/lib/braintree/test/nonce.rb +2 -0
  17. data/lib/braintree/transaction/credit_card_details.rb +4 -0
  18. data/lib/braintree/transaction/sepa_direct_debit_account_details.rb +27 -0
  19. data/lib/braintree/transaction.rb +6 -0
  20. data/lib/braintree/transaction_gateway.rb +1 -1
  21. data/lib/braintree/transaction_search.rb +1 -0
  22. data/lib/braintree/version.rb +1 -1
  23. data/lib/braintree/webhook_notification.rb +1 -0
  24. data/lib/braintree/webhook_testing_gateway.rb +76 -0
  25. data/lib/braintree.rb +4 -0
  26. data/spec/integration/braintree/credit_card_spec.rb +0 -60
  27. data/spec/integration/braintree/credit_card_verification_spec.rb +124 -1
  28. data/spec/integration/braintree/customer_spec.rb +1 -32
  29. data/spec/integration/braintree/dispute_search_spec.rb +28 -19
  30. data/spec/integration/braintree/dispute_spec.rb +27 -0
  31. data/spec/integration/braintree/http_spec.rb +1 -1
  32. data/spec/integration/braintree/paypal_account_spec.rb +2 -2
  33. data/spec/integration/braintree/sepa_direct_debit_account_spec.rb +196 -0
  34. data/spec/integration/braintree/subscription_spec.rb +1 -1
  35. data/spec/integration/braintree/transaction_search_spec.rb +34 -2
  36. data/spec/integration/braintree/transaction_spec.rb +107 -101
  37. data/spec/integration/spec_helper.rb +6 -0
  38. data/spec/unit/braintree/apple_pay_card_spec.rb +99 -11
  39. data/spec/unit/braintree/credit_card_verification_gateway_spec.rb +51 -0
  40. data/spec/unit/braintree/customer_spec.rb +11 -1
  41. data/spec/unit/braintree/dispute_search_spec.rb +1 -0
  42. data/spec/unit/braintree/dispute_spec.rb +8 -0
  43. data/spec/unit/braintree/payment_method_nonce_details_spec.rb +9 -1
  44. data/spec/unit/braintree/sepa_debit_account_nonce_details_spec.rb +29 -0
  45. data/spec/unit/braintree/sepa_debit_account_spec.rb +86 -0
  46. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +16 -0
  47. data/spec/unit/braintree/transaction/deposit_details_spec.rb +1 -1
  48. data/spec/unit/braintree/transaction/sepa_direct_debit_account_details_spec.rb +33 -0
  49. data/spec/unit/braintree/transaction_gateway_spec.rb +111 -0
  50. data/spec/unit/braintree/transaction_spec.rb +72 -0
  51. data/spec/unit/braintree/webhook_notification_spec.rb +16 -0
  52. metadata +13 -3
@@ -1,4 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
2
3
 
3
4
  describe Braintree::CreditCardVerification, "search" do
4
5
 
@@ -11,7 +12,7 @@ describe Braintree::CreditCardVerification, "search" do
11
12
  },
12
13
  :options => {
13
14
  :amount => "10.00"
14
- }
15
+ },
15
16
  }
16
17
 
17
18
  result = Braintree::CreditCardVerification.create(verification_params)
@@ -259,4 +260,126 @@ describe Braintree::CreditCardVerification, "search" do
259
260
  end
260
261
  end
261
262
  end
263
+
264
+ describe "intended transaction source" do
265
+ it "creates a new verification with intended transaction source installment" do
266
+ verification_params = {
267
+ :credit_card => {
268
+ :expiration_date => "05/2029",
269
+ :number => Braintree::Test::CreditCardNumbers::Visa,
270
+ },
271
+ :options => {
272
+ :amount => "10.00"
273
+ },
274
+ :intended_transaction_source => "installment"
275
+ }
276
+
277
+ result = Braintree::CreditCardVerification.create(verification_params)
278
+
279
+ result.should be_success
280
+ result.credit_card_verification.id.should =~ /^\w{6,}$/
281
+ result.credit_card_verification.status.should == Braintree::CreditCardVerification::Status::Verified
282
+ result.credit_card_verification.processor_response_code.should == "1000"
283
+ result.credit_card_verification.processor_response_text.should == "Approved"
284
+ result.credit_card_verification.processor_response_type.should == Braintree::ProcessorResponseTypes::Approved
285
+ expect(result.credit_card_verification.network_transaction_id).not_to be_nil
286
+ end
287
+ end
288
+
289
+ context "three_d_secure" do
290
+ it "can create a verification with a three_d_secure_authentication_id" do
291
+ three_d_secure_authentication_id = SpecHelper.create_3ds_verification(
292
+ SpecHelper::ThreeDSecureMerchantAccountId,
293
+ :number => Braintree::Test::CreditCardNumbers::Visa,
294
+ :expiration_month => "12",
295
+ :expiration_year => "2029",
296
+ )
297
+
298
+ verification_params = {
299
+ :credit_card => {
300
+ :expiration_date => "12/2029",
301
+ :number => Braintree::Test::CreditCardNumbers::Visa,
302
+ },
303
+ :options => {
304
+ :amount => "10.00",
305
+ :merchant_account_id => SpecHelper::ThreeDSecureMerchantAccountId,
306
+ },
307
+ :three_d_secure_authentication_id => three_d_secure_authentication_id,
308
+ }
309
+
310
+ result = Braintree::CreditCardVerification.create(verification_params)
311
+
312
+ result.should be_success
313
+ result.credit_card_verification.id.should =~ /^\w{6,}$/
314
+ result.credit_card_verification.status.should == Braintree::CreditCardVerification::Status::Verified
315
+ result.credit_card_verification.processor_response_code.should == "1000"
316
+ result.credit_card_verification.processor_response_text.should == "Approved"
317
+ result.credit_card_verification.processor_response_type.should == Braintree::ProcessorResponseTypes::Approved
318
+ expect(result.credit_card_verification.network_transaction_id).not_to be_nil
319
+ end
320
+
321
+ it "can create a verification with a payment_method_nonce" do
322
+ nonce = nonce_for_new_payment_method(
323
+ :credit_card => {
324
+ :number => Braintree::Test::CreditCardNumbers::Visa,
325
+ :expiration_month => "11",
326
+ :expiration_year => "2099",
327
+ },
328
+ )
329
+ nonce.should_not be_nil
330
+
331
+ verification_params = {
332
+ :credit_card => {
333
+ :number => Braintree::Test::CreditCardNumbers::Visa,
334
+ },
335
+ :options => {
336
+ :amount => "10.00",
337
+ :merchant_account_id => SpecHelper::ThreeDSecureMerchantAccountId,
338
+ },
339
+ :payment_method_nonce => nonce,
340
+ }
341
+
342
+ result = Braintree::CreditCardVerification.create(verification_params)
343
+
344
+ result.should be_success
345
+ result.credit_card_verification.id.should =~ /^\w{6,}$/
346
+ result.credit_card_verification.status.should == Braintree::CreditCardVerification::Status::Verified
347
+ result.credit_card_verification.processor_response_code.should == "1000"
348
+ result.credit_card_verification.processor_response_text.should == "Approved"
349
+ result.credit_card_verification.processor_response_type.should == Braintree::ProcessorResponseTypes::Approved
350
+ expect(result.credit_card_verification.network_transaction_id).not_to be_nil
351
+ end
352
+
353
+ it "can create a verification with a verification_three_d_secure_pass_thru" do
354
+ verification_params = {
355
+ :credit_card => {
356
+ :number => Braintree::Test::CreditCardNumbers::Visa,
357
+ :expiration_date => "12/12",
358
+ },
359
+ :options => {
360
+ :amount => "10.00",
361
+ },
362
+ :three_d_secure_pass_thru => {
363
+ :eci_flag => "02",
364
+ :cavv => "some_cavv",
365
+ :xid => "some_xid",
366
+ :three_d_secure_version => "1.0.2",
367
+ :authentication_response => "Y",
368
+ :directory_response => "Y",
369
+ :cavv_algorithm => "2",
370
+ :ds_transaction_id => "some_ds_id",
371
+ },
372
+ }
373
+
374
+ result = Braintree::CreditCardVerification.create(verification_params)
375
+
376
+ result.should be_success
377
+ result.credit_card_verification.id.should =~ /^\w{6,}$/
378
+ result.credit_card_verification.status.should == Braintree::CreditCardVerification::Status::Verified
379
+ result.credit_card_verification.processor_response_code.should == "1000"
380
+ result.credit_card_verification.processor_response_text.should == "Approved"
381
+ result.credit_card_verification.processor_response_type.should == Braintree::ProcessorResponseTypes::Approved
382
+ expect(result.credit_card_verification.network_transaction_id).not_to be_nil
383
+ end
384
+ end
262
385
  end
@@ -566,37 +566,6 @@ describe Braintree::Customer do
566
566
  result.errors.for(:customer).on(:custom_fields)[0].message.should == "Custom field is invalid: spouse_name."
567
567
  end
568
568
 
569
- describe "venmo_sdk" do
570
- it "can create a customer with a venmo sdk payment method code" do
571
- result = Braintree::Customer.create(
572
- :first_name => "Steve",
573
- :last_name => "Hamlin",
574
- :credit_card => {
575
- :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::VisaPaymentMethodCode
576
- },
577
- )
578
- result.success?.should == true
579
- result.customer.credit_cards.first.bin.should == "400934"
580
- result.customer.credit_cards.first.last_4.should == "1881"
581
- end
582
-
583
- it "can create a customer with a venmo sdk session" do
584
- result = Braintree::Customer.create(
585
- :first_name => "Steve",
586
- :last_name => "Hamlin",
587
- :credit_card => {
588
- :number => Braintree::Test::CreditCardNumbers::MasterCard,
589
- :expiration_date => "05/2010",
590
- :options => {
591
- :venmo_sdk_session => Braintree::Test::VenmoSDK::Session
592
- }
593
- },
594
- )
595
- result.success?.should == true
596
- result.customer.credit_cards.first.venmo_sdk?.should == false
597
- end
598
- end
599
-
600
569
  context "client API" do
601
570
  it "can create a customer with a payment method nonce" do
602
571
  nonce = nonce_for_new_payment_method(
@@ -1754,7 +1723,7 @@ describe Braintree::Customer do
1754
1723
  context "future" do
1755
1724
  it "creates a customer with a future paypal account" do
1756
1725
  result = Braintree::Customer.create(
1757
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
1726
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
1758
1727
  )
1759
1728
 
1760
1729
  result.should be_success
@@ -78,33 +78,42 @@ describe Braintree::Dispute, "search" do
78
78
  dispute = collection.disputes.first
79
79
  end
80
80
 
81
- it "correctly returns chargeback protected disputes" do
82
- collection = Braintree::Dispute.search do |search|
83
- search.case_number.is "CASE-CHARGEBACK-PROTECTED"
84
- end
85
-
86
- expect(collection.disputes.count).to eq(1)
87
- dispute = collection.disputes.first
88
-
89
- # NEXT_MAJOR_VERSION Remove this assertion when chargeback_protection_level is removed from the SDK
90
- expect(dispute.chargeback_protection_level).to eq(Braintree::Dispute::ChargebackProtectionLevel::Effortless)
91
- expect(dispute.protection_level).to eq(Braintree::Dispute::ProtectionLevel::EffortlessCBP)
92
- expect(dispute.reason).to eq(Braintree::Dispute::Reason::Fraud)
93
- end
94
-
95
81
  it "correctly returns disputes by chargeback protection level flag" do
96
82
  collection = Braintree::Dispute.search do |search|
97
83
  search.chargeback_protection_level.in [
98
84
  Braintree::Dispute::ChargebackProtectionLevel::Effortless
99
85
  ]
100
86
  end
101
- expect(collection.disputes.count).to eq(1)
102
- dispute = collection.disputes.first
87
+ expect(collection.disputes.count).to be > 0
103
88
 
104
89
  # NEXT_MAJOR_VERSION Remove this assertion when chargeback_protection_level is removed from the SDK
105
- expect(dispute.chargeback_protection_level).to eq(Braintree::Dispute::ChargebackProtectionLevel::Effortless)
106
- expect(dispute.protection_level).to eq(Braintree::Dispute::ProtectionLevel::EffortlessCBP)
107
- expect(dispute.reason).to eq(Braintree::Dispute::Reason::Fraud)
90
+ collection.disputes.each do |dispute|
91
+ expect(dispute.chargeback_protection_level).to eq(Braintree::Dispute::ChargebackProtectionLevel::Effortless)
92
+ expect(dispute.protection_level).to eq(Braintree::Dispute::ProtectionLevel::EffortlessCBP)
93
+ end
94
+ end
95
+
96
+ context "pre-dispute program" do
97
+ it "correctly returns disputes by pre-dispute program" do
98
+ collection = Braintree::Dispute.search do |search|
99
+ search.pre_dispute_program.in [
100
+ Braintree::Dispute::PreDisputeProgram::VisaRdr
101
+ ]
102
+ end
103
+
104
+ expect(collection.disputes.count).to eq(1)
105
+ dispute = collection.disputes.first
106
+ expect(dispute.pre_dispute_program).to eq(Braintree::Dispute::PreDisputeProgram::VisaRdr)
107
+ end
108
+
109
+ it "correctly returns disputes with no pre-dispute program" do
110
+ collection = Braintree::Dispute.search do |search|
111
+ search.pre_dispute_program.is Braintree::Dispute::PreDisputeProgram::None
112
+ end
113
+
114
+ expect(collection.disputes.count).to be > 1
115
+ expect(collection.disputes.map(&:pre_dispute_program).uniq).to eq([Braintree::Dispute::PreDisputeProgram::None])
116
+ end
108
117
  end
109
118
 
110
119
  it "correctly returns disputes by effective_date range" do
@@ -151,6 +151,33 @@ describe Braintree::Dispute do
151
151
  result.evidence.sent_to_processor_at.should == nil
152
152
  result.evidence.sequence_number.should == 7
153
153
  end
154
+
155
+ it "creates text evidence for the dispute with CARRIER_NAME shipping tracking" do
156
+ result = Braintree::Dispute.add_text_evidence(dispute.id, {content: "UPS", category: "CARRIER_NAME", sequence_number: 0})
157
+
158
+ result.success?.should == true
159
+ result.evidence.category.should == "CARRIER_NAME"
160
+ result.evidence.comment.should == "UPS"
161
+ result.evidence.sequence_number.should == 0
162
+ end
163
+
164
+ it "creates text evidence for the dispute with TRACKING_NUMBER shipping tracking" do
165
+ result = Braintree::Dispute.add_text_evidence(dispute.id, {content: "3", category: "TRACKING_NUMBER", sequence_number: 0})
166
+
167
+ result.success?.should == true
168
+ result.evidence.category.should == "TRACKING_NUMBER"
169
+ result.evidence.comment.should == "3"
170
+ result.evidence.sequence_number.should == 0
171
+ end
172
+
173
+ it "creates text evidence for the dispute with TRACKING_URL shipping tracking" do
174
+ result = Braintree::Dispute.add_text_evidence(dispute.id, {content: "https://example.com/tracking-number/abc12345", category: "TRACKING_URL", sequence_number: 1})
175
+
176
+ result.success?.should == true
177
+ result.evidence.category.should == "TRACKING_URL"
178
+ result.evidence.comment.should == "https://example.com/tracking-number/abc12345"
179
+ result.evidence.sequence_number.should == 1
180
+ end
154
181
  end
155
182
 
156
183
  describe "self.finalize" do
@@ -97,7 +97,7 @@ describe Braintree::Http do
97
97
  end
98
98
 
99
99
  describe "ssl_version" do
100
- it "causes failed requests to sandbox with incompatible SSL version" do
100
+ xit "causes failed requests to sandbox with incompatible SSL version" do
101
101
  begin
102
102
  original_env = Braintree::Configuration.environment
103
103
  Braintree::Configuration.environment = :sandbox
@@ -267,7 +267,7 @@ describe Braintree::PayPalAccount do
267
267
  context "self.sale" do
268
268
  it "creates a transaction using a paypal account and returns a result object" do
269
269
  customer = Braintree::Customer.create!(
270
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
270
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
271
271
  )
272
272
 
273
273
  result = Braintree::PayPalAccount.sale(customer.paypal_accounts[0].token, :amount => "100.00")
@@ -283,7 +283,7 @@ describe Braintree::PayPalAccount do
283
283
  context "self.sale!" do
284
284
  it "creates a transaction using a paypal account and returns a transaction" do
285
285
  customer = Braintree::Customer.create!(
286
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
286
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
287
287
  )
288
288
 
289
289
  transaction = Braintree::PayPalAccount.sale!(customer.paypal_accounts[0].token, :amount => "100.00")
@@ -0,0 +1,196 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Braintree::SepaDirectDebitAccount do
4
+ before do
5
+ Braintree::Configuration.merchant_id = "integration_merchant_id"
6
+ Braintree::Configuration.public_key = "integration_public_key"
7
+ Braintree::Configuration.private_key = "integration_private_key"
8
+ end
9
+
10
+ let(:customer) { Braintree::Customer.create.customer }
11
+ let(:nonce) { Braintree::Test::Nonce::SepaDirectDebit }
12
+
13
+ let(:token) do
14
+ Braintree::PaymentMethod.create(
15
+ payment_method_nonce: nonce,
16
+ customer_id: customer.id,
17
+ ).payment_method.token
18
+ end
19
+
20
+ describe "self.find" do
21
+ subject do
22
+ described_class.find(token)
23
+ end
24
+
25
+ context "when payment method exists" do
26
+ it "returns a payment method" do
27
+ sepa_direct_debit_account = subject
28
+ sepa_direct_debit_account.should be_a(Braintree::SepaDirectDebitAccount)
29
+ sepa_direct_debit_account.last_4.should == "1234"
30
+ sepa_direct_debit_account.default.should == true
31
+ sepa_direct_debit_account.customer_id.should == customer.id
32
+ sepa_direct_debit_account.global_id.should_not be_empty
33
+ sepa_direct_debit_account.customer_global_id.should_not be_empty
34
+ sepa_direct_debit_account.bank_reference_token.should == "a-fake-bank-reference-token"
35
+ sepa_direct_debit_account.mandate_type.should == "RECURRENT"
36
+ sepa_direct_debit_account.merchant_or_partner_customer_id.should == "a-fake-mp-customer-id"
37
+ sepa_direct_debit_account.token.should_not be_empty
38
+ sepa_direct_debit_account.image_url.should_not be_empty
39
+ sepa_direct_debit_account.created_at.should be_a Time
40
+ sepa_direct_debit_account.updated_at.should be_a Time
41
+ end
42
+ end
43
+
44
+ context "when payment method does not exist" do
45
+ let(:token) { "ABC123" }
46
+
47
+ it "raises an error" do
48
+ expect {
49
+ subject
50
+ }.to raise_error(Braintree::NotFoundError)
51
+ end
52
+ end
53
+
54
+ context "subscriptions" do
55
+ it "returns subscriptions associated with a SEPA direct debit account" do
56
+ customer = Braintree::Customer.create!
57
+
58
+ subscription1 = Braintree::Subscription.create(
59
+ :payment_method_token => token,
60
+ :plan_id => SpecHelper::TriallessPlan[:id],
61
+ ).subscription
62
+
63
+ subscription2 = Braintree::Subscription.create(
64
+ :payment_method_token => token,
65
+ :plan_id => SpecHelper::TriallessPlan[:id],
66
+ ).subscription
67
+
68
+ sepa_debit_account = Braintree::SepaDirectDebitAccount.find(token)
69
+ subscription_ids = sepa_debit_account.subscriptions.map { |h| h[:id] }.sort
70
+ expect(subscription_ids).to eq([subscription1.id, subscription2.id].sort)
71
+ end
72
+ end
73
+ end
74
+
75
+ describe "self.delete" do
76
+ subject do
77
+ described_class.delete(token)
78
+ end
79
+
80
+ context "when payment method exists" do
81
+ it "deletes a payment method" do
82
+ should be_success
83
+
84
+ expect {
85
+ described_class.find(token)
86
+ }.to raise_error(Braintree::NotFoundError)
87
+ end
88
+ end
89
+
90
+ context "when payment method does not exist" do
91
+ let(:token) { "ABC123" }
92
+
93
+ it "raises an error" do
94
+ expect {
95
+ subject
96
+ }.to raise_error(Braintree::NotFoundError)
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "self.sale" do
102
+ let(:params) do
103
+ {
104
+ amount: 1.23,
105
+ }
106
+ end
107
+
108
+ subject do
109
+ described_class.sale(token, params)
110
+ end
111
+
112
+ context "when payment method exists" do
113
+ it "creates a transaction" do
114
+ should be_success
115
+
116
+ transaction = subject.transaction
117
+ transaction.amount.should eq(1.23)
118
+ transaction.status.should == "settling"
119
+ sepa_direct_debit_account_details = transaction.sepa_direct_debit_account_details
120
+ sepa_direct_debit_account_details.should be_a(Braintree::Transaction::SepaDirectDebitAccountDetails)
121
+ sepa_direct_debit_account_details.bank_reference_token.should == "a-fake-bank-reference-token"
122
+ sepa_direct_debit_account_details.capture_id.should_not be_empty
123
+ sepa_direct_debit_account_details.debug_id.should be_nil
124
+ sepa_direct_debit_account_details.global_id.should_not be_empty
125
+ sepa_direct_debit_account_details.last_4.should == "1234"
126
+ sepa_direct_debit_account_details.mandate_type.should == "RECURRENT"
127
+ sepa_direct_debit_account_details.merchant_or_partner_customer_id.should == "a-fake-mp-customer-id"
128
+ sepa_direct_debit_account_details.paypal_v2_order_id.should be_nil
129
+ sepa_direct_debit_account_details.refund_from_transaction_fee_amount.should be_nil
130
+ sepa_direct_debit_account_details.refund_from_transaction_fee_currency_iso_code.should be_nil
131
+ sepa_direct_debit_account_details.refund_id.should be_nil
132
+ sepa_direct_debit_account_details.settlement_type.should be_nil
133
+ sepa_direct_debit_account_details.token.should == token
134
+ sepa_direct_debit_account_details.transaction_fee_amount.should == "0.01"
135
+ sepa_direct_debit_account_details.transaction_fee_currency_iso_code.should == "USD"
136
+ end
137
+ end
138
+
139
+ context "when payment method does not exist" do
140
+ let(:token) { "ABC123" }
141
+
142
+ it "not raises an error" do
143
+ expect {
144
+ subject
145
+ }.to_not raise_error
146
+ end
147
+ end
148
+ end
149
+
150
+ describe "self.sale!" do
151
+ let(:params) do
152
+ {
153
+ amount: 1.23,
154
+ }
155
+ end
156
+
157
+ subject do
158
+ described_class.sale!(token, params)
159
+ end
160
+
161
+ context "when payment method exists" do
162
+ it "creates a transaction" do
163
+ transaction = subject
164
+ transaction.amount.should eq(1.23)
165
+ transaction.status.should == "settling"
166
+ sepa_direct_debit_account_details = transaction.sepa_direct_debit_account_details
167
+ sepa_direct_debit_account_details.should be_a(Braintree::Transaction::SepaDirectDebitAccountDetails)
168
+ sepa_direct_debit_account_details.bank_reference_token.should == "a-fake-bank-reference-token"
169
+ sepa_direct_debit_account_details.capture_id.should_not be_empty
170
+ sepa_direct_debit_account_details.debug_id.should be_nil
171
+ sepa_direct_debit_account_details.global_id.should_not be_empty
172
+ sepa_direct_debit_account_details.last_4.should == "1234"
173
+ sepa_direct_debit_account_details.mandate_type.should == "RECURRENT"
174
+ sepa_direct_debit_account_details.merchant_or_partner_customer_id.should == "a-fake-mp-customer-id"
175
+ sepa_direct_debit_account_details.paypal_v2_order_id.should be_nil
176
+ sepa_direct_debit_account_details.refund_from_transaction_fee_amount.should be_nil
177
+ sepa_direct_debit_account_details.refund_from_transaction_fee_currency_iso_code.should be_nil
178
+ sepa_direct_debit_account_details.refund_id.should be_nil
179
+ sepa_direct_debit_account_details.settlement_type.should be_nil
180
+ sepa_direct_debit_account_details.token.should == token
181
+ sepa_direct_debit_account_details.transaction_fee_amount.should == "0.01"
182
+ sepa_direct_debit_account_details.transaction_fee_currency_iso_code.should == "USD"
183
+ end
184
+ end
185
+
186
+ context "when payment method does not exist" do
187
+ let(:token) { "ABC123" }
188
+
189
+ it "not raises an error" do
190
+ expect {
191
+ subject
192
+ }.to raise_error(Braintree::ValidationsFailed)
193
+ end
194
+ end
195
+ end
196
+ end
@@ -96,7 +96,7 @@ describe Braintree::Subscription do
96
96
  it "creates a subscription when given a paypal account payment_method_nonce" do
97
97
  customer = Braintree::Customer.create!
98
98
  payment_method_result = Braintree::PaymentMethod.create(
99
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
99
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
100
100
  :customer_id => customer.id,
101
101
  )
102
102
 
@@ -133,7 +133,7 @@ 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::PayPalBillingAgreement,
137
137
  )
138
138
 
139
139
  collection = Braintree::Transaction.search do |search|
@@ -146,7 +146,7 @@ describe Braintree::Transaction, "search" do
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::PayPalBillingAgreement,
150
150
  )
151
151
 
152
152
  paypal_details = transaction.paypal_details
@@ -396,6 +396,38 @@ describe Braintree::Transaction, "search" do
396
396
  collection.first.payment_instrument_type.should == Braintree::PaymentInstrumentType::LocalPayment
397
397
  end
398
398
 
399
+ it "searches by payment instrument type SepaDebitAccountDetail" do
400
+ transaction = Braintree::Transaction.sale!(
401
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
402
+ :payment_method_nonce => Braintree::Test::Nonce::SepaDirectDebit,
403
+ :options => {:submit_for_settlement => true},
404
+ )
405
+
406
+ collection = Braintree::Transaction.search do |search|
407
+ search.id.is transaction.id
408
+ search.payment_instrument_type.in ["SEPADebitAccountDetail"]
409
+ end
410
+
411
+ collection.first.id.should == transaction.id
412
+ collection.first.payment_instrument_type.should == Braintree::PaymentInstrumentType::SepaDirectDebitAccount
413
+ end
414
+
415
+ it "searches by paypal_v2_order_id" do
416
+ transaction = Braintree::Transaction.sale!(
417
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
418
+ :payment_method_nonce => Braintree::Test::Nonce::SepaDirectDebit,
419
+ :options => {:submit_for_settlement => true},
420
+ )
421
+
422
+ collection = Braintree::Transaction.search do |search|
423
+ search.id.is transaction.id
424
+ search.sepa_debit_paypal_v2_order_id.is transaction.sepa_direct_debit_account_details.paypal_v2_order_id
425
+ end
426
+
427
+ collection.first.id.should == transaction.id
428
+ collection.first.payment_instrument_type.should == Braintree::PaymentInstrumentType::SepaDirectDebitAccount
429
+ end
430
+
399
431
  it "searches by payment instrument type ApplePay" do
400
432
  transaction = Braintree::Transaction.sale!(
401
433
  :amount => Braintree::Test::TransactionAmounts::Authorize,