braintree 4.9.0 → 4.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/braintree/apple_pay_card.rb +2 -0
  3. data/lib/braintree/customer.rb +4 -1
  4. data/lib/braintree/dispute.rb +9 -0
  5. data/lib/braintree/dispute_search.rb +1 -0
  6. data/lib/braintree/error_codes.rb +6 -0
  7. data/lib/braintree/gateway.rb +4 -0
  8. data/lib/braintree/payment_instrument_type.rb +7 -6
  9. data/lib/braintree/payment_method_gateway.rb +2 -0
  10. data/lib/braintree/payment_method_nonce_details.rb +3 -0
  11. data/lib/braintree/payment_method_parser.rb +2 -0
  12. data/lib/braintree/sepa_direct_debit_account.rb +58 -0
  13. data/lib/braintree/sepa_direct_debit_account_gateway.rb +25 -0
  14. data/lib/braintree/sepa_direct_debit_account_nonce_details.rb +28 -0
  15. data/lib/braintree/test/nonce.rb +2 -0
  16. data/lib/braintree/transaction/sepa_direct_debit_account_details.rb +27 -0
  17. data/lib/braintree/transaction.rb +4 -0
  18. data/lib/braintree/transaction_search.rb +1 -0
  19. data/lib/braintree/version.rb +1 -1
  20. data/lib/braintree/webhook_notification.rb +1 -0
  21. data/lib/braintree/webhook_testing_gateway.rb +76 -0
  22. data/lib/braintree.rb +4 -0
  23. data/spec/integration/braintree/customer_spec.rb +1 -1
  24. data/spec/integration/braintree/dispute_search_spec.rb +29 -5
  25. data/spec/integration/braintree/paypal_account_spec.rb +2 -2
  26. data/spec/integration/braintree/sepa_direct_debit_account_spec.rb +176 -0
  27. data/spec/integration/braintree/subscription_spec.rb +1 -1
  28. data/spec/integration/braintree/transaction_search_spec.rb +34 -2
  29. data/spec/integration/braintree/transaction_spec.rb +35 -17
  30. data/spec/integration/spec_helper.rb +6 -0
  31. data/spec/unit/braintree/apple_pay_card_spec.rb +99 -11
  32. data/spec/unit/braintree/customer_spec.rb +11 -1
  33. data/spec/unit/braintree/dispute_search_spec.rb +1 -0
  34. data/spec/unit/braintree/dispute_spec.rb +8 -0
  35. data/spec/unit/braintree/payment_method_nonce_details_spec.rb +9 -1
  36. data/spec/unit/braintree/sepa_debit_account_nonce_details_spec.rb +29 -0
  37. data/spec/unit/braintree/sepa_debit_account_spec.rb +85 -0
  38. data/spec/unit/braintree/transaction/deposit_details_spec.rb +1 -1
  39. data/spec/unit/braintree/transaction/sepa_direct_debit_account_details_spec.rb +33 -0
  40. data/spec/unit/braintree/transaction_spec.rb +30 -0
  41. data/spec/unit/braintree/webhook_notification_spec.rb +16 -0
  42. metadata +11 -3
@@ -0,0 +1,176 @@
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
+ end
54
+
55
+ describe "self.delete" do
56
+ subject do
57
+ described_class.delete(token)
58
+ end
59
+
60
+ context "when payment method exists" do
61
+ it "deletes a payment method" do
62
+ should be_success
63
+
64
+ expect {
65
+ described_class.find(token)
66
+ }.to raise_error(Braintree::NotFoundError)
67
+ end
68
+ end
69
+
70
+ context "when payment method does not exist" do
71
+ let(:token) { "ABC123" }
72
+
73
+ it "raises an error" do
74
+ expect {
75
+ subject
76
+ }.to raise_error(Braintree::NotFoundError)
77
+ end
78
+ end
79
+ end
80
+
81
+ describe "self.sale" do
82
+ let(:params) do
83
+ {
84
+ amount: 1.23,
85
+ }
86
+ end
87
+
88
+ subject do
89
+ described_class.sale(token, params)
90
+ end
91
+
92
+ context "when payment method exists" do
93
+ it "creates a transaction" do
94
+ should be_success
95
+
96
+ transaction = subject.transaction
97
+ transaction.amount.should eq(1.23)
98
+ transaction.status.should == "settling"
99
+ sepa_direct_debit_account_details = transaction.sepa_direct_debit_account_details
100
+ sepa_direct_debit_account_details.should be_a(Braintree::Transaction::SepaDirectDebitAccountDetails)
101
+ sepa_direct_debit_account_details.bank_reference_token.should == "a-fake-bank-reference-token"
102
+ sepa_direct_debit_account_details.capture_id.should_not be_empty
103
+ sepa_direct_debit_account_details.debug_id.should be_nil
104
+ sepa_direct_debit_account_details.global_id.should_not be_empty
105
+ sepa_direct_debit_account_details.last_4.should == "1234"
106
+ sepa_direct_debit_account_details.mandate_type.should == "RECURRENT"
107
+ sepa_direct_debit_account_details.merchant_or_partner_customer_id.should == "a-fake-mp-customer-id"
108
+ sepa_direct_debit_account_details.paypal_v2_order_id.should be_nil
109
+ sepa_direct_debit_account_details.refund_from_transaction_fee_amount.should be_nil
110
+ sepa_direct_debit_account_details.refund_from_transaction_fee_currency_iso_code.should be_nil
111
+ sepa_direct_debit_account_details.refund_id.should be_nil
112
+ sepa_direct_debit_account_details.settlement_type.should be_nil
113
+ sepa_direct_debit_account_details.token.should == token
114
+ sepa_direct_debit_account_details.transaction_fee_amount.should == "0.01"
115
+ sepa_direct_debit_account_details.transaction_fee_currency_iso_code.should == "USD"
116
+ end
117
+ end
118
+
119
+ context "when payment method does not exist" do
120
+ let(:token) { "ABC123" }
121
+
122
+ it "not raises an error" do
123
+ expect {
124
+ subject
125
+ }.to_not raise_error
126
+ end
127
+ end
128
+ end
129
+
130
+ describe "self.sale!" do
131
+ let(:params) do
132
+ {
133
+ amount: 1.23,
134
+ }
135
+ end
136
+
137
+ subject do
138
+ described_class.sale!(token, params)
139
+ end
140
+
141
+ context "when payment method exists" do
142
+ it "creates a transaction" do
143
+ transaction = subject
144
+ transaction.amount.should eq(1.23)
145
+ transaction.status.should == "settling"
146
+ sepa_direct_debit_account_details = transaction.sepa_direct_debit_account_details
147
+ sepa_direct_debit_account_details.should be_a(Braintree::Transaction::SepaDirectDebitAccountDetails)
148
+ sepa_direct_debit_account_details.bank_reference_token.should == "a-fake-bank-reference-token"
149
+ sepa_direct_debit_account_details.capture_id.should_not be_empty
150
+ sepa_direct_debit_account_details.debug_id.should be_nil
151
+ sepa_direct_debit_account_details.global_id.should_not be_empty
152
+ sepa_direct_debit_account_details.last_4.should == "1234"
153
+ sepa_direct_debit_account_details.mandate_type.should == "RECURRENT"
154
+ sepa_direct_debit_account_details.merchant_or_partner_customer_id.should == "a-fake-mp-customer-id"
155
+ sepa_direct_debit_account_details.paypal_v2_order_id.should be_nil
156
+ sepa_direct_debit_account_details.refund_from_transaction_fee_amount.should be_nil
157
+ sepa_direct_debit_account_details.refund_from_transaction_fee_currency_iso_code.should be_nil
158
+ sepa_direct_debit_account_details.refund_id.should be_nil
159
+ sepa_direct_debit_account_details.settlement_type.should be_nil
160
+ sepa_direct_debit_account_details.token.should == token
161
+ sepa_direct_debit_account_details.transaction_fee_amount.should == "0.01"
162
+ sepa_direct_debit_account_details.transaction_fee_currency_iso_code.should == "USD"
163
+ end
164
+ end
165
+
166
+ context "when payment method does not exist" do
167
+ let(:token) { "ABC123" }
168
+
169
+ it "not raises an error" do
170
+ expect {
171
+ subject
172
+ }.to raise_error(Braintree::ValidationsFailed)
173
+ end
174
+ end
175
+ end
176
+ 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,
@@ -1001,6 +1001,24 @@ describe Braintree::Transaction do
1001
1001
  result.success?.should == false
1002
1002
  result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::TokenIssuance
1003
1003
  end
1004
+
1005
+ it "exposes the excessive_retry gateway rejection reason" do
1006
+ with_duplicate_checking_merchant do
1007
+ result = nil
1008
+ 16.times do
1009
+ result = Braintree::Transaction.sale(
1010
+ :amount => Braintree::Test::TransactionAmounts::Decline,
1011
+ :credit_card => {
1012
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1013
+ :expiration_month => "05",
1014
+ :expiration_year => "2011"
1015
+ },
1016
+ )
1017
+ end
1018
+ result.success?.should == false
1019
+ result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::ExcessiveRetry
1020
+ end
1021
+ end
1004
1022
  end
1005
1023
 
1006
1024
  it "accepts credit card expiration month and expiration year" do
@@ -2687,7 +2705,7 @@ describe Braintree::Transaction do
2687
2705
  it "can create a transaction" do
2688
2706
  payment_method_result = Braintree::PaymentMethod.create(
2689
2707
  :customer_id => Braintree::Customer.create.customer.id,
2690
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
2708
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
2691
2709
  )
2692
2710
  result = Braintree::Transaction.create(
2693
2711
  :type => "sale",
@@ -4334,7 +4352,7 @@ describe Braintree::Transaction do
4334
4352
  it "returns a validation error if used with an unsupported instrument type" do
4335
4353
  customer = Braintree::Customer.create!
4336
4354
  result = Braintree::PaymentMethod.create(
4337
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
4355
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
4338
4356
  :customer_id => customer.id,
4339
4357
  )
4340
4358
  payment_method_token = result.payment_method.token
@@ -5208,7 +5226,7 @@ describe Braintree::Transaction do
5208
5226
  end
5209
5227
  end
5210
5228
 
5211
- context "Amex Pay with Points" do
5229
+ xit "Amex Pay with Points" do
5212
5230
  context "transaction creation" do
5213
5231
  it "succeeds when submit_for_settlement is true" do
5214
5232
  result = Braintree::Transaction.sale(
@@ -5517,7 +5535,7 @@ describe Braintree::Transaction do
5517
5535
  end
5518
5536
  end
5519
5537
 
5520
- it "succeeds when level 2 data is provided" do
5538
+ xit "succeeds when level 2 data is provided" do
5521
5539
  result = Braintree::Transaction.sale(
5522
5540
  :amount => Braintree::Test::TransactionAmounts::Authorize,
5523
5541
  :merchant_account_id => SpecHelper::FakeAmexDirectMerchantAccountId,
@@ -5541,7 +5559,7 @@ describe Braintree::Transaction do
5541
5559
  result.transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
5542
5560
  end
5543
5561
 
5544
- it "succeeds when level 3 data is provided" do
5562
+ xit "succeeds when level 3 data is provided" do
5545
5563
  result = Braintree::Transaction.sale(
5546
5564
  :amount => Braintree::Test::TransactionAmounts::Authorize,
5547
5565
  :merchant_account_id => SpecHelper::FakeAmexDirectMerchantAccountId,
@@ -6323,23 +6341,23 @@ describe Braintree::Transaction do
6323
6341
  expect(transaction.three_d_secure_info.authentication).to have_key(:trans_status_reason)
6324
6342
  expect(transaction.three_d_secure_info.lookup).to have_key(:trans_status)
6325
6343
  expect(transaction.three_d_secure_info.lookup).to have_key(:trans_status_reason)
6326
- transaction.three_d_secure_info.cavv.should == "somebase64value"
6327
- transaction.three_d_secure_info.ds_transaction_id.should == "dstxnid"
6328
- transaction.three_d_secure_info.eci_flag.should == "07"
6329
- transaction.three_d_secure_info.enrolled.should == "Y"
6330
- transaction.three_d_secure_info.pares_status.should == "Y"
6331
- transaction.three_d_secure_info.should be_liability_shift_possible
6332
- transaction.three_d_secure_info.should be_liability_shifted
6333
- transaction.three_d_secure_info.status.should == "authenticate_successful"
6344
+ expect(transaction.three_d_secure_info.cavv).to eq("somebase64value")
6345
+ expect(transaction.three_d_secure_info.ds_transaction_id).to eq("dstxnid")
6346
+ expect(transaction.three_d_secure_info.eci_flag).to eq("07")
6347
+ expect(transaction.three_d_secure_info.enrolled).to eq("Y")
6348
+ expect(transaction.three_d_secure_info.pares_status).to eq("Y")
6349
+ expect(transaction.three_d_secure_info).to be_liability_shift_possible
6350
+ expect(transaction.three_d_secure_info).to be_liability_shifted
6351
+ expect(transaction.three_d_secure_info.status).to eq("authenticate_successful")
6334
6352
  expect(transaction.three_d_secure_info.three_d_secure_authentication_id).to be
6335
- transaction.three_d_secure_info.three_d_secure_version.should == "1.0.2"
6336
- transaction.three_d_secure_info.xid.should == "xidvalue"
6353
+ expect(transaction.three_d_secure_info.three_d_secure_version).not_to be_nil
6354
+ expect(transaction.three_d_secure_info.xid).to eq("xidvalue")
6337
6355
  end
6338
6356
 
6339
6357
  it "is nil if the transaction wasn't 3d secured" do
6340
6358
  transaction = Braintree::Transaction.find("settledtransaction")
6341
6359
 
6342
- transaction.three_d_secure_info.should be_nil
6360
+ expect(transaction.three_d_secure_info).to be_nil
6343
6361
  end
6344
6362
  end
6345
6363
 
@@ -7215,7 +7233,7 @@ describe Braintree::Transaction do
7215
7233
  end
7216
7234
 
7217
7235
  it "returns failure, when transaction authorization type final or undefined" do
7218
- additional_params = {:transaction_source => "recurring_first"}
7236
+ additional_params = {:transaction_source => "recurring"}
7219
7237
  initial_transaction = Braintree::Transaction.sale(first_data_master_transaction_params.merge(additional_params))
7220
7238
  expect(initial_transaction.success?).to eq(true)
7221
7239
 
@@ -67,4 +67,10 @@ unless defined?(INTEGRATION_SPEC_HELPER_LOADED)
67
67
  def random_payment_method_token
68
68
  "payment-method-token-#{SecureRandom.hex(6)}"
69
69
  end
70
+
71
+ def with_duplicate_checking_merchant(&block)
72
+ with_other_merchant("dup_checking_integration_merchant_id", "dup_checking_integration_public_key", "dup_checking_integration_private_key") do
73
+ block.call
74
+ end
75
+ end
70
76
  end
@@ -1,35 +1,123 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe Braintree::ApplePayCard do
4
- describe "bin" do
5
- it "returns Apple pay card bin" do
6
- Braintree::ApplePayCard._new(:gateway, bin: "411111").bin.should == "411111"
7
- end
4
+ let(:attributes) do
5
+ {
6
+ :billing_address => {
7
+ company: "Braintree",
8
+ country_code_alpha2: "US",
9
+ country_code_alpha3: "USA",
10
+ country_code_numeric: "840",
11
+ country_name: "United States of America",
12
+ extended_address: "Apt 1",
13
+ first_name: "John",
14
+ last_name: "Miller",
15
+ locality: "Chicago",
16
+ phone_number: "17708675309",
17
+ postal_code: "12345",
18
+ region: "Illinois",
19
+ street_address: "123 Sesame Street",
20
+ },
21
+ :bin => "411111",
22
+ :card_type => "Apple Pay - MasterCard",
23
+ :cardholder_name => "John Miller",
24
+ :commercial => "No",
25
+ :country_of_issuance => "USA",
26
+ :created_at => Time.now,
27
+ :customer_id => "cid1",
28
+ :debit => "No",
29
+ :default => true,
30
+ :durbin_regulated => "Yes",
31
+ :expiration_month => "01",
32
+ :expiration_year => "2025",
33
+ :expired => false,
34
+ :healthcare => "No",
35
+ :image_url => nil,
36
+ :issuing_bank => "Big Bad Bank",
37
+ :last_4 => "9876",
38
+ :payment_instrument_name => nil,
39
+ :payroll => "No",
40
+ :prepaid => "No",
41
+ :product_id => "MAC",
42
+ :source_description => "blah",
43
+ :subscriptions => [
44
+ {
45
+ balance: "50.00",
46
+ price: "10.00",
47
+ descriptor: [],
48
+ transactions: [],
49
+ add_ons: [],
50
+ discounts: [],
51
+ },
52
+ ],
53
+ :token => "123456789",
54
+ :updated_at => Time.now,
55
+ }
8
56
  end
9
57
 
10
- describe "cardholder_name" do
11
- it "returns Apple pay card cardholder name" do
12
- Braintree::ApplePayCard._new(:gateway, cardholder_name: "John Miller").cardholder_name.should == "John Miller"
58
+ describe "initialize" do
59
+ it "converts billing address hash to Braintree::Address object" do
60
+ card = Braintree::ApplePayCard._new(:gateway, attributes)
61
+
62
+ expect(card.billing_address).to be_instance_of(Braintree::Address)
63
+ end
64
+
65
+ it "converts subscriptions hash to Braintree::Subscription object" do
66
+ card = Braintree::ApplePayCard._new(:gateway, attributes)
67
+
68
+ expect(card.subscriptions[0]).to be_instance_of(Braintree::Subscription)
69
+ end
70
+
71
+ it "handles nil billing address" do
72
+ attributes.delete(:billing_address)
73
+ card = Braintree::ApplePayCard._new(:gateway, attributes)
74
+
75
+ expect(card.billing_address).to be_nil
76
+ end
77
+
78
+ it "handles nil subscriptions" do
79
+ attributes.delete(:subscriptions)
80
+ card = Braintree::ApplePayCard._new(:gateway, attributes)
81
+
82
+ expect(card.subscriptions).to be_empty
13
83
  end
14
84
  end
15
85
 
16
86
  describe "default?" do
17
87
  it "is true if the Apple pay card is the default payment method for the customer" do
18
- Braintree::ApplePayCard._new(:gateway, :default => true).default?.should == true
88
+ card = Braintree::ApplePayCard._new(:gateway, attributes)
89
+
90
+ expect(card.default?).to be true
19
91
  end
20
92
 
21
93
  it "is false if the Apple pay card is not the default payment methodfor the customer" do
22
- Braintree::ApplePayCard._new(:gateway, :default => false).default?.should == false
94
+ attributes.merge!(:default => false)
95
+ card = Braintree::ApplePayCard._new(:gateway, attributes)
96
+
97
+ expect(card.default?).to be false
23
98
  end
24
99
  end
25
100
 
26
101
  describe "expired?" do
27
102
  it "is true if the Apple pay card is expired" do
28
- Braintree::ApplePayCard._new(:gateway, :expired => true).expired?.should == true
103
+ attributes.merge!(:expired => true)
104
+ card = Braintree::ApplePayCard._new(:gateway, attributes)
105
+
106
+ expect(card.expired?).to be true
29
107
  end
30
108
 
31
109
  it "is false if the Apple pay card is not expired" do
32
- Braintree::ApplePayCard._new(:gateway, :expired => false).expired?.should == false
110
+ card = Braintree::ApplePayCard._new(:gateway, attributes)
111
+
112
+ expect(card.expired?).to be false
113
+ end
114
+ end
115
+
116
+ describe "self.new" do
117
+ it "is protected" do
118
+ expect do
119
+ Braintree::ApplePayCard.new
120
+ end.to raise_error(NoMethodError, /protected method .new/)
33
121
  end
34
122
  end
35
123
  end
@@ -301,6 +301,10 @@ describe Braintree::Customer do
301
301
  {:token => "paypal_1"},
302
302
  {:token => "paypal_2"}
303
303
  ],
304
+ :sepa_debit_accounts => [
305
+ {:token => "sepa_debit_1"},
306
+ {:token => "sepa_debit_2"}
307
+ ],
304
308
  )
305
309
 
306
310
  customer.credit_cards.size.should == 2
@@ -311,11 +315,17 @@ describe Braintree::Customer do
311
315
  customer.paypal_accounts[0].token.should == "paypal_1"
312
316
  customer.paypal_accounts[1].token.should == "paypal_2"
313
317
 
314
- customer.payment_methods.count.should == 4
318
+ customer.sepa_direct_debit_accounts.size.should == 2
319
+ customer.sepa_direct_debit_accounts[0].token.should == "sepa_debit_1"
320
+ customer.sepa_direct_debit_accounts[1].token.should == "sepa_debit_2"
321
+
322
+ customer.payment_methods.count.should == 6
315
323
  customer.payment_methods.map(&:token).should include("credit_card_1")
316
324
  customer.payment_methods.map(&:token).should include("credit_card_2")
317
325
  customer.payment_methods.map(&:token).should include("paypal_1")
318
326
  customer.payment_methods.map(&:token).should include("paypal_2")
327
+ customer.payment_methods.map(&:token).should include("sepa_debit_1")
328
+ customer.payment_methods.map(&:token).should include("sepa_debit_2")
319
329
  end
320
330
  end
321
331
 
@@ -47,6 +47,7 @@ describe Braintree::DisputeSearch do
47
47
  :kind,
48
48
  :reason,
49
49
  :status,
50
+ :pre_dispute_program,
50
51
  ].each do |field|
51
52
  it "raises if provided an unknown #{field} value" do
52
53
  search = Braintree::DisputeSearch.new
@@ -16,6 +16,7 @@ describe Braintree::Dispute do
16
16
  :received_date => "2009-03-09",
17
17
  :reply_by_date => nil,
18
18
  :updated_at => Time.utc(2009, 3, 9, 10, 50, 39),
19
+ :pre_dispute_program => Braintree::Dispute::PreDisputeProgram::None,
19
20
  :evidence => [
20
21
  {
21
22
  comment: nil,
@@ -428,6 +429,13 @@ describe Braintree::Dispute do
428
429
  dispute.date_opened.should == Date.new(2009, 3, 9)
429
430
  dispute.date_won.should == Date.new(2009, 4, 15)
430
431
  end
432
+
433
+ it "returns pre_dispute_program value" do
434
+ attributes.merge!(:pre_dispute_program => Braintree::Dispute::PreDisputeProgram::VisaRdr)
435
+ dispute = Braintree::Dispute._new(attributes)
436
+
437
+ expect(dispute.pre_dispute_program).to eq(Braintree::Dispute::PreDisputeProgram::VisaRdr)
438
+ end
431
439
  end
432
440
 
433
441
  describe "==" do
@@ -3,12 +3,16 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
3
3
  describe Braintree::PaymentMethodNonceDetails do
4
4
  let(:payment_method_nonce_details) {
5
5
  Braintree::PaymentMethodNonceDetails.new(
6
+ :bank_reference_token => "a-bank-reference-token",
6
7
  :bin => "bin",
7
8
  :card_type => "American Express",
8
9
  :expiration_month => "12",
9
10
  :expiration_year => "2025",
10
11
  :is_network_tokenized => true,
12
+ :last_4 => "abcd",
11
13
  :last_two => "11",
14
+ :mandate_type => "ONE_OFF",
15
+ :merchant_or_partner_customer_id => "a-mp-customer-id",
12
16
  :payer_info => {
13
17
  :billing_agreement_id => "1234",
14
18
  :country_code => "US",
@@ -26,12 +30,16 @@ describe Braintree::PaymentMethodNonceDetails do
26
30
  payment_method_nonce_details.last_two.should == "11"
27
31
  payment_method_nonce_details.payer_info.billing_agreement_id.should == "1234"
28
32
  payment_method_nonce_details.payer_info.country_code.should == "US"
33
+ payment_method_nonce_details.sepa_direct_debit_account_nonce_details.bank_reference_token.should == "a-bank-reference-token"
34
+ payment_method_nonce_details.sepa_direct_debit_account_nonce_details.last_4.should == "abcd"
35
+ payment_method_nonce_details.sepa_direct_debit_account_nonce_details.mandate_type.should == "ONE_OFF"
36
+ payment_method_nonce_details.sepa_direct_debit_account_nonce_details.merchant_or_partner_customer_id.should == "a-mp-customer-id"
29
37
  end
30
38
  end
31
39
 
32
40
  describe "inspect" do
33
41
  it "prints the attributes" do
34
- payment_method_nonce_details.inspect.should == %(#<PaymentMethodNonceDetails bin: "bin", card_type: "American Express", expiration_month: "12", expiration_year: "2025", is_network_tokenized: true, last_two: "11", payer_info: #<PaymentMethodNonceDetailsPayerInfo billing_agreement_id: "1234", country_code: "US", email: nil, first_name: nil, last_name: nil, payer_id: nil>>)
42
+ payment_method_nonce_details.inspect.should == %(#<PaymentMethodNonceDetails bin: "bin", card_type: "American Express", expiration_month: "12", expiration_year: "2025", is_network_tokenized: true, last_two: "11", payer_info: #<PaymentMethodNonceDetailsPayerInfo billing_agreement_id: "1234", country_code: "US", email: nil, first_name: nil, last_name: nil, payer_id: nil>, sepa_direct_debit_account_nonce_details: #<SepaDirectDebitAccountNonceDetailsbank_reference_token: "a-bank-reference-token", last_4: "abcd", mandate_type: "ONE_OFF", merchant_or_partner_customer_id: "a-mp-customer-id">>)
35
43
  end
36
44
  end
37
45
 
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+ describe Braintree::SepaDirectDebitAccountNonceDetails do
4
+ subject do
5
+ described_class.new(
6
+ :bank_reference_token => "a-bank-reference-token",
7
+ :last_4 => "abcd",
8
+ :mandate_type => "ONE_OFF",
9
+ :merchant_or_partner_customer_id => "a-mp-customer-id",
10
+ )
11
+ end
12
+
13
+ describe "#initialize" do
14
+ it "sets attributes" do
15
+ is_expected.to have_attributes(
16
+ :bank_reference_token => "a-bank-reference-token",
17
+ :last_4 => "abcd",
18
+ :mandate_type => "ONE_OFF",
19
+ :merchant_or_partner_customer_id => "a-mp-customer-id",
20
+ )
21
+ end
22
+ end
23
+
24
+ describe "inspect" do
25
+ it "prints the attributes" do
26
+ subject.inspect.should == %(#<SepaDirectDebitAccountNonceDetailsbank_reference_token: "a-bank-reference-token", last_4: "abcd", mandate_type: "ONE_OFF", merchant_or_partner_customer_id: "a-mp-customer-id">)
27
+ end
28
+ end
29
+ end