braintree 3.4.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/braintree.gemspec +2 -2
  3. data/lib/braintree.rb +4 -0
  4. data/lib/braintree/address.rb +1 -0
  5. data/lib/braintree/apple_pay_card.rb +9 -0
  6. data/lib/braintree/credit_card_gateway.rb +11 -1
  7. data/lib/braintree/customer.rb +4 -2
  8. data/lib/braintree/customer_gateway.rb +2 -0
  9. data/lib/braintree/dispute.rb +14 -0
  10. data/lib/braintree/dispute/paypal_message.rb +15 -0
  11. data/lib/braintree/dispute_search.rb +1 -0
  12. data/lib/braintree/error_codes.rb +4 -6
  13. data/lib/braintree/google_pay_card.rb +9 -0
  14. data/lib/braintree/payment_method_gateway.rb +7 -4
  15. data/lib/braintree/payment_method_nonce.rb +7 -4
  16. data/lib/braintree/payment_method_nonce_details.rb +37 -0
  17. data/lib/braintree/payment_method_nonce_details_payer_info.rb +32 -0
  18. data/lib/braintree/transaction/paypal_details.rb +2 -0
  19. data/lib/braintree/transaction_gateway.rb +3 -3
  20. data/lib/braintree/version.rb +2 -2
  21. data/lib/braintree/webhook_notification.rb +2 -1
  22. data/lib/braintree/webhook_testing_gateway.rb +20 -0
  23. data/lib/braintree/xml/libxml.rb +0 -1
  24. data/lib/braintree/xml/parser.rb +12 -2
  25. data/lib/braintree/xml/rexml.rb +70 -0
  26. data/spec/integration/braintree/address_spec.rb +4 -0
  27. data/spec/integration/braintree/credit_card_spec.rb +89 -0
  28. data/spec/integration/braintree/customer_spec.rb +144 -0
  29. data/spec/integration/braintree/dispute_search_spec.rb +25 -0
  30. data/spec/integration/braintree/merchant_account_spec.rb +3 -3
  31. data/spec/integration/braintree/payment_method_nonce_spec.rb +16 -23
  32. data/spec/integration/braintree/payment_method_spec.rb +131 -0
  33. data/spec/integration/braintree/transaction_spec.rb +82 -2
  34. data/spec/spec_helper.rb +2 -0
  35. data/spec/unit/braintree/credit_card_spec.rb +6 -6
  36. data/spec/unit/braintree/customer_spec.rb +17 -7
  37. data/spec/unit/braintree/dispute_search_spec.rb +1 -0
  38. data/spec/unit/braintree/dispute_spec.rb +26 -1
  39. data/spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb +31 -0
  40. data/spec/unit/braintree/payment_method_nonce_details_spec.rb +43 -0
  41. data/spec/unit/braintree/payment_method_nonce_spec.rb +40 -0
  42. data/spec/unit/braintree/transaction/paypal_details_spec.rb +4 -0
  43. data/spec/unit/braintree/transaction_spec.rb +3 -3
  44. data/spec/unit/braintree/webhook_notification_spec.rb +16 -0
  45. data/spec/unit/braintree/xml/rexml_spec.rb +51 -0
  46. metadata +15 -7
@@ -31,6 +31,7 @@ describe Braintree::Customer do
31
31
  output.should include(%q(addresses: []))
32
32
  output.should include(%q(credit_cards: []))
33
33
  output.should include(%q(paypal_accounts: []))
34
+ output.should include(%q(tax_identifiers: []))
34
35
  output.should include(%Q(created_at: #{customer.created_at.inspect}))
35
36
  output.should include(%Q(updated_at: #{customer.updated_at.inspect}))
36
37
  end
@@ -75,7 +76,7 @@ describe Braintree::Customer do
75
76
 
76
77
  describe "self.create_signature" do
77
78
  it "should be what we expect" do
78
- Braintree::CustomerGateway._create_signature.should == [
79
+ expect(Braintree::CustomerGateway._create_signature).to match([
79
80
  :company,
80
81
  :email,
81
82
  :fax,
@@ -100,7 +101,7 @@ describe Braintree::Customer do
100
101
  :device_data,
101
102
  :payment_method_nonce,
102
103
  {:external_vault=>[:network_transaction_id]},
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]},
104
+ {:options => match_array([:make_default, :skip_advanced_fraud_checking, :verification_merchant_account_id, :verify_card, :verification_amount, :venmo_sdk_session, :fail_on_duplicate_payment_method, :verification_account_type, :verification_currency_iso_code])},
104
105
  {:billing_address => [
105
106
  :company,
106
107
  :country_code_alpha2,
@@ -133,6 +134,10 @@ describe Braintree::Customer do
133
134
  :billing_agreement_id,
134
135
  {:options => [:make_default]},
135
136
  ]},
137
+ {:tax_identifiers => [
138
+ :country_code,
139
+ :identifier
140
+ ]},
136
141
  {:options =>
137
142
  [:paypal => [
138
143
  :payee_email,
@@ -158,13 +163,13 @@ describe Braintree::Customer do
158
163
  ]]
159
164
  },
160
165
  {:custom_fields => :_any_key_}
161
- ]
166
+ ])
162
167
  end
163
168
  end
164
169
 
165
170
  describe "self.update_signature" do
166
171
  it "should be what we expect" do
167
- Braintree::CustomerGateway._update_signature.should == [
172
+ expect(Braintree::CustomerGateway._update_signature).to match([
168
173
  :company,
169
174
  :email,
170
175
  :fax,
@@ -189,8 +194,9 @@ describe Braintree::Customer do
189
194
  :device_data,
190
195
  :payment_method_nonce,
191
196
  {:external_vault=>[:network_transaction_id]},
192
- {:options => [
197
+ {:options => match_array([
193
198
  :make_default,
199
+ :skip_advanced_fraud_checking,
194
200
  :verification_merchant_account_id,
195
201
  :verify_card,
196
202
  :verification_amount,
@@ -199,7 +205,7 @@ describe Braintree::Customer do
199
205
  :verification_account_type,
200
206
  :verification_currency_iso_code,
201
207
  :update_existing_token
202
- ]},
208
+ ])},
203
209
  {:billing_address => [
204
210
  :company,
205
211
  :country_code_alpha2,
@@ -227,6 +233,10 @@ describe Braintree::Customer do
227
233
  :ds_transaction_id,
228
234
  ]},
229
235
  ]},
236
+ {:tax_identifiers => [
237
+ :country_code,
238
+ :identifier
239
+ ]},
230
240
  {:options =>
231
241
  [:paypal => [
232
242
  :payee_email,
@@ -252,7 +262,7 @@ describe Braintree::Customer do
252
262
  ]]
253
263
  },
254
264
  {:custom_fields => :_any_key_}
255
- ]
265
+ ])
256
266
  end
257
267
  end
258
268
 
@@ -41,6 +41,7 @@ describe Braintree::DisputeSearch do
41
41
  end
42
42
 
43
43
  [
44
+ :chargeback_protection_level,
44
45
  :kind,
45
46
  :reason,
46
47
  :status,
@@ -46,7 +46,14 @@ describe Braintree::Dispute do
46
46
  :order_id => nil,
47
47
  :purchase_order_number => "po",
48
48
  :payment_instrument_subtype => "Visa",
49
- }
49
+ },
50
+ :paypal_messages => [
51
+ {
52
+ :message => "message",
53
+ :sender => "seller",
54
+ :sent_at => Time.utc(2009, 3, 9, 10, 50, 39),
55
+ }
56
+ ]
50
57
  }
51
58
  end
52
59
 
@@ -348,6 +355,16 @@ describe Braintree::Dispute do
348
355
  evidence2.url.should == nil
349
356
  end
350
357
 
358
+ it "converts paypal_messages hash into an array of Dispute::PayPalMessage objects" do
359
+ dispute = Braintree::Dispute._new(attributes)
360
+
361
+ dispute.paypal_messages.length.should == 1
362
+ paypal_message_1 = dispute.paypal_messages.first
363
+ paypal_message_1.message.should == "message"
364
+ paypal_message_1.sender.should == "seller"
365
+ paypal_message_1.sent_at.should == Time.utc(2009, 3, 9, 10, 50, 39)
366
+ end
367
+
351
368
  it "handles nil evidence" do
352
369
  attributes.delete(:evidence)
353
370
 
@@ -356,6 +373,14 @@ describe Braintree::Dispute do
356
373
  dispute.evidence.should == nil
357
374
  end
358
375
 
376
+ it "handles nil paypal_messages" do
377
+ attributes.delete(:paypal_messages)
378
+
379
+ dispute = Braintree::Dispute._new(attributes)
380
+
381
+ dispute.paypal_messages.should == nil
382
+ end
383
+
359
384
  it "sets the older webhook fields for backwards compatibility" do
360
385
  dispute = Braintree::Dispute._new(attributes)
361
386
 
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+ describe Braintree::PaymentMethodNonceDetailsPayerInfo do
4
+ let(:payment_method_nonce_details_payer_info) {
5
+ Braintree::PaymentMethodNonceDetailsPayerInfo.new(
6
+ :billing_agreement_id => "billing-agreement-id",
7
+ :country_code => "US",
8
+ :email => "test@example.com",
9
+ :first_name => "First",
10
+ :last_name => "Last",
11
+ :payer_id => "payer-id",
12
+ )
13
+ }
14
+
15
+ describe "#initialize" do
16
+ it "sets attributes" do
17
+ payment_method_nonce_details_payer_info.billing_agreement_id.should == "billing-agreement-id"
18
+ payment_method_nonce_details_payer_info.country_code.should == "US"
19
+ payment_method_nonce_details_payer_info.email.should == "test@example.com"
20
+ payment_method_nonce_details_payer_info.first_name.should == "First"
21
+ payment_method_nonce_details_payer_info.last_name.should == "Last"
22
+ payment_method_nonce_details_payer_info.payer_id.should == "payer-id"
23
+ end
24
+ end
25
+
26
+ describe "inspect" do
27
+ it "prints the attributes" do
28
+ payment_method_nonce_details_payer_info.inspect.should == %(#<PaymentMethodNonceDetailsPayerInfo billing_agreement_id: \"billing-agreement-id\", country_code: \"US\", email: \"test@example.com\", first_name: \"First\", last_name: \"Last\", payer_id: \"payer-id\">)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+ describe Braintree::PaymentMethodNonceDetails do
4
+ let(:payment_method_nonce_details) {
5
+ Braintree::PaymentMethodNonceDetails.new(
6
+ :bin => "bin",
7
+ :card_type => "American Express",
8
+ :expiration_month => "12",
9
+ :expiration_year => "2025",
10
+ :is_network_tokenized => true,
11
+ :last_two => "11",
12
+ :payer_info => {
13
+ :billing_agreement_id => "1234",
14
+ :country_code => "US",
15
+ },
16
+ )
17
+ }
18
+
19
+ describe "#initialize" do
20
+ it "sets attributes" do
21
+ payment_method_nonce_details.bin.should == "bin"
22
+ payment_method_nonce_details.card_type.should == "American Express"
23
+ payment_method_nonce_details.expiration_month.should == "12"
24
+ payment_method_nonce_details.expiration_year.should == "2025"
25
+ payment_method_nonce_details.is_network_tokenized.should == true
26
+ payment_method_nonce_details.last_two.should == "11"
27
+ payment_method_nonce_details.payer_info.billing_agreement_id.should == "1234"
28
+ payment_method_nonce_details.payer_info.country_code.should == "US"
29
+ end
30
+ end
31
+
32
+ describe "inspect" do
33
+ 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>>)
35
+ end
36
+ end
37
+
38
+ describe "is_network_tokenized" do
39
+ it "is aliased to is_network_tokenized?" do
40
+ payment_method_nonce_details.is_network_tokenized?.should == true
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+ describe Braintree::PaymentMethodNonce do
4
+ let(:payment_method_nonce) {
5
+ Braintree::PaymentMethodNonce._new(
6
+ :gateway,
7
+ :nonce => "some-nonce",
8
+ :type => "CreditCard",
9
+ :default => true,
10
+ :details => {
11
+ :bin => "some-bin"
12
+ },
13
+ :three_d_secure_info => {
14
+ :liability_shift_possible => false,
15
+ :liability_shifted => false
16
+ },
17
+ :bin_data => {
18
+ :country_of_issuance => "USA"
19
+ },
20
+ )
21
+ }
22
+
23
+ describe "#initialize" do
24
+ it "sets attributes" do
25
+ expect(payment_method_nonce.nonce).to eq("some-nonce")
26
+ expect(payment_method_nonce.type).to eq("CreditCard")
27
+ expect(payment_method_nonce.default).to be true
28
+ expect(payment_method_nonce.details.bin).to eq("some-bin")
29
+ expect(payment_method_nonce.three_d_secure_info.liability_shift_possible).to be false
30
+ expect(payment_method_nonce.three_d_secure_info.liability_shifted).to be false
31
+ expect(payment_method_nonce.bin_data.country_of_issuance).to eq("USA")
32
+ end
33
+ end
34
+
35
+ describe "default" do
36
+ it "is aliased to default?" do
37
+ expect(payment_method_nonce.default?).to be true
38
+ end
39
+ end
40
+ end
@@ -25,6 +25,8 @@ describe Braintree::Transaction::PayPalDetails do
25
25
  :refund_from_transaction_fee_currency_iso_code => "123",
26
26
  :refund_id => "refund-id",
27
27
  :seller_protection_status => "seller-protection-status",
28
+ :tax_id => "tax-id",
29
+ :tax_id_type => "tax-id-type",
28
30
  :token => "token",
29
31
  :transaction_fee_amount => "2.00",
30
32
  :transaction_fee_currency_iso_code => "123",
@@ -51,6 +53,8 @@ describe Braintree::Transaction::PayPalDetails do
51
53
  expect(details.refund_from_transaction_fee_currency_iso_code).to eq("123")
52
54
  expect(details.refund_id).to eq("refund-id")
53
55
  expect(details.seller_protection_status).to eq("seller-protection-status")
56
+ expect(details.tax_id).to eq("tax-id")
57
+ expect(details.tax_id_type).to eq("tax-id-type")
54
58
  expect(details.token).to eq("token")
55
59
  expect(details.transaction_fee_amount).to eq("2.00")
56
60
  expect(details.transaction_fee_currency_iso_code).to eq("123")
@@ -21,19 +21,19 @@ describe Braintree::Transaction do
21
21
  it "raises error if passed empty string" do
22
22
  expect do
23
23
  Braintree::Transaction.find("")
24
- end.to raise_error(ArgumentError)
24
+ end.to raise_error(ArgumentError, "id can not be empty")
25
25
  end
26
26
 
27
27
  it "raises error if passed empty string wth space" do
28
28
  expect do
29
29
  Braintree::Transaction.find(" ")
30
- end.to raise_error(ArgumentError)
30
+ end.to raise_error(ArgumentError, "id can not be empty")
31
31
  end
32
32
 
33
33
  it "raises error if passed nil" do
34
34
  expect do
35
35
  Braintree::Transaction.find(nil)
36
- end.to raise_error(ArgumentError)
36
+ end.to raise_error(ArgumentError, "id can not be empty")
37
37
  end
38
38
  end
39
39
 
@@ -611,6 +611,22 @@ describe Braintree::WebhookNotification do
611
611
  metadata.token.should == "venmo_token"
612
612
  metadata.revoked_payment_method.class.should == Braintree::VenmoAccount
613
613
  end
614
+
615
+ it "builds a sample notification for a GrantedPaymentMethodRevoked webhook" do
616
+ sample_notification = Braintree::WebhookTesting.sample_notification(
617
+ Braintree::WebhookNotification::Kind::GrantedPaymentMethodRevoked,
618
+ "my_id",
619
+ )
620
+
621
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
622
+ expect(notification.kind).to eq Braintree::WebhookNotification::Kind::GrantedPaymentMethodRevoked
623
+
624
+ metadata = notification.revoked_payment_method_metadata
625
+
626
+ expect(metadata.customer_id).to eq "venmo_customer_id"
627
+ expect(metadata.token).to eq "my_id"
628
+ expect(metadata.revoked_payment_method.class).to eq Braintree::VenmoAccount
629
+ end
614
630
  end
615
631
  end
616
632
 
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+ describe Braintree::Xml::Rexml do
4
+ describe "self.parse" do
5
+ it "typecasts integers" do
6
+ xml = "<root><foo type=\"integer\">123</foo></root>"
7
+ Braintree::Xml::Rexml.parse(xml).should == {"root"=>{"foo"=>{"__content__"=>"123", "type"=>"integer"}}}
8
+ end
9
+
10
+ it "works with dashes or underscores" do
11
+ xml = <<-END
12
+ <root>
13
+ <dash-es />
14
+ <under_scores />
15
+ </root>
16
+ END
17
+ Braintree::Xml::Rexml.parse(xml).should == {"root"=>{"dash-es"=>{}, "under_scores"=>{}}}
18
+ end
19
+
20
+ it "uses nil if nil=true, otherwise uses empty string" do
21
+ xml = <<-END
22
+ <root>
23
+ <a_nil_value nil="true"></a_nil_value>
24
+ <an_empty_string></an_empty_string>
25
+ </root>
26
+ END
27
+ Braintree::Xml::Rexml.parse(xml).should == {"root"=>{"a_nil_value"=>{"nil"=>"true"}, "an_empty_string"=>{}}}
28
+ end
29
+
30
+ it "typecasts dates and times" do
31
+ xml = <<-END
32
+ <root>
33
+ <created-at type="datetime">2009-10-28T10:19:49Z</created-at>
34
+ </root>
35
+ END
36
+ Braintree::Xml::Rexml.parse(xml).should == {"root"=>{"created-at"=>{"__content__"=>"2009-10-28T10:19:49Z", "type"=>"datetime"}}}
37
+ end
38
+
39
+ it "builds an array if type=array" do
40
+ xml = <<-END
41
+ <root>
42
+ <customers type="array">
43
+ <customer><name>Adam</name></customer>
44
+ <customer><name>Ben</name></customer>
45
+ </customers>
46
+ </root>
47
+ END
48
+ Braintree::Xml::Rexml.parse(xml).should == {"root"=>{"customers"=>{"type"=>"array", "customer"=>[{"name"=>{"__content__"=>"Adam"}}, {"name"=>{"__content__"=>"Ben"}}]}}}
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: braintree
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Braintree
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-12 00:00:00.000000000 Z
11
+ date: 2021-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.4
27
27
  - !ruby/object:Gem::Dependency
28
- name: libxml-ruby
28
+ name: rexml
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 3.2.0
33
+ version: 3.1.9
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 3.2.0
40
+ version: 3.1.9
41
41
  description: Resources and tools for developers to integrate Braintree's global payments
42
42
  platform.
43
43
  email: code@getbraintree.com
@@ -84,6 +84,7 @@ files:
84
84
  - lib/braintree/discount_gateway.rb
85
85
  - lib/braintree/dispute.rb
86
86
  - lib/braintree/dispute/evidence.rb
87
+ - lib/braintree/dispute/paypal_message.rb
87
88
  - lib/braintree/dispute/status_history.rb
88
89
  - lib/braintree/dispute/transaction.rb
89
90
  - lib/braintree/dispute/transaction_details.rb
@@ -121,6 +122,8 @@ files:
121
122
  - lib/braintree/payment_method.rb
122
123
  - lib/braintree/payment_method_gateway.rb
123
124
  - lib/braintree/payment_method_nonce.rb
125
+ - lib/braintree/payment_method_nonce_details.rb
126
+ - lib/braintree/payment_method_nonce_details_payer_info.rb
124
127
  - lib/braintree/payment_method_nonce_gateway.rb
125
128
  - lib/braintree/payment_method_parser.rb
126
129
  - lib/braintree/paypal_account.rb
@@ -192,6 +195,7 @@ files:
192
195
  - lib/braintree/xml/generator.rb
193
196
  - lib/braintree/xml/libxml.rb
194
197
  - lib/braintree/xml/parser.rb
198
+ - lib/braintree/xml/rexml.rb
195
199
  - lib/ssl/api_braintreegateway_com.ca.crt
196
200
  - lib/ssl/securetrust_ca.crt
197
201
  - spec/fixtures/files/bt_logo.png
@@ -268,6 +272,9 @@ files:
268
272
  - spec/unit/braintree/local_payment_completed_spec.rb
269
273
  - spec/unit/braintree/merchant_account_spec.rb
270
274
  - spec/unit/braintree/modification_spec.rb
275
+ - spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb
276
+ - spec/unit/braintree/payment_method_nonce_details_spec.rb
277
+ - spec/unit/braintree/payment_method_nonce_spec.rb
271
278
  - spec/unit/braintree/payment_method_spec.rb
272
279
  - spec/unit/braintree/paypal_account_spec.rb
273
280
  - spec/unit/braintree/resource_collection_spec.rb
@@ -295,6 +302,7 @@ files:
295
302
  - spec/unit/braintree/webhook_notification_spec.rb
296
303
  - spec/unit/braintree/xml/libxml_spec.rb
297
304
  - spec/unit/braintree/xml/parser_spec.rb
305
+ - spec/unit/braintree/xml/rexml_spec.rb
298
306
  - spec/unit/braintree/xml_spec.rb
299
307
  - spec/unit/braintree_spec.rb
300
308
  - spec/unit/spec_helper.rb
@@ -314,14 +322,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
314
322
  requirements:
315
323
  - - ">="
316
324
  - !ruby/object:Gem::Version
317
- version: 2.5.0
325
+ version: 2.6.0
318
326
  required_rubygems_version: !ruby/object:Gem::Requirement
319
327
  requirements:
320
328
  - - ">="
321
329
  - !ruby/object:Gem::Version
322
330
  version: '0'
323
331
  requirements: []
324
- rubygems_version: 3.0.8
332
+ rubygems_version: 3.2.24
325
333
  signing_key:
326
334
  specification_version: 4
327
335
  summary: Braintree Ruby Server SDK