braintree 4.2.0 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/braintree.gemspec +1 -1
  3. data/lib/braintree/apple_pay_card.rb +9 -0
  4. data/lib/braintree/enriched_customer_data.rb +21 -0
  5. data/lib/braintree/error_codes.rb +1 -0
  6. data/lib/braintree/google_pay_card.rb +9 -0
  7. data/lib/braintree/http.rb +1 -0
  8. data/lib/braintree/local_payment_expired.rb +21 -0
  9. data/lib/braintree/local_payment_funded.rb +22 -0
  10. data/lib/braintree/payment_method_customer_data_updated_metadata.rb +24 -0
  11. data/lib/braintree/plan.rb +20 -0
  12. data/lib/braintree/plan_gateway.rb +100 -0
  13. data/lib/braintree/successful_result.rb +1 -0
  14. data/lib/braintree/transaction/paypal_details.rb +2 -0
  15. data/lib/braintree/transaction_gateway.rb +2 -2
  16. data/lib/braintree/transaction_review.rb +18 -0
  17. data/lib/braintree/venmo_profile_data.rb +23 -0
  18. data/lib/braintree/version.rb +1 -1
  19. data/lib/braintree/webhook_notification.rb +14 -0
  20. data/lib/braintree/webhook_testing_gateway.rb +91 -17
  21. data/lib/braintree.rb +5 -0
  22. data/spec/integration/braintree/customer_spec.rb +27 -0
  23. data/spec/integration/braintree/merchant_account_spec.rb +3 -3
  24. data/spec/integration/braintree/payment_method_nonce_spec.rb +2 -1
  25. data/spec/integration/braintree/payment_method_spec.rb +27 -0
  26. data/spec/integration/braintree/plan_spec.rb +82 -0
  27. data/spec/integration/braintree/transaction_spec.rb +28 -0
  28. data/spec/unit/braintree/enriched_customer_data_spec.rb +32 -0
  29. data/spec/unit/braintree/http_spec.rb +2 -0
  30. data/spec/unit/braintree/local_payment_expired_spec.rb +24 -0
  31. data/spec/unit/braintree/local_payment_funded_spec.rb +34 -0
  32. data/spec/unit/braintree/payment_method_customer_data_updated_metadata_spec.rb +45 -0
  33. data/spec/unit/braintree/transaction/paypal_details_spec.rb +4 -0
  34. data/spec/unit/braintree/transaction_spec.rb +3 -3
  35. data/spec/unit/braintree/venmo_profile_data_spec.rb +32 -0
  36. data/spec/unit/braintree/webhook_notification_spec.rb +78 -1
  37. metadata +15 -4
@@ -1021,6 +1021,15 @@ describe Braintree::Customer do
1021
1021
  apple_pay_card.token.should_not be_nil
1022
1022
  apple_pay_card.expiration_year.should_not be_nil
1023
1023
  apple_pay_card.payment_instrument_name.should == "AmEx 41002"
1024
+ apple_pay_card.commercial.should_not be_nil
1025
+ apple_pay_card.country_of_issuance.should_not be_nil
1026
+ apple_pay_card.debit.should_not be_nil
1027
+ apple_pay_card.durbin_regulated.should_not be_nil
1028
+ apple_pay_card.healthcare.should_not be_nil
1029
+ apple_pay_card.issuing_bank.should_not be_nil
1030
+ apple_pay_card.payroll.should_not be_nil
1031
+ apple_pay_card.prepaid.should_not be_nil
1032
+ apple_pay_card.product_id.should_not be_nil
1024
1033
  end
1025
1034
 
1026
1035
  it "returns associated google pay proxy cards" do
@@ -1037,6 +1046,15 @@ describe Braintree::Customer do
1037
1046
  google_pay_card.token.should_not be_nil
1038
1047
  google_pay_card.expiration_year.should_not be_nil
1039
1048
  google_pay_card.is_network_tokenized?.should == false
1049
+ google_pay_card.commercial.should_not be_nil
1050
+ google_pay_card.country_of_issuance.should_not be_nil
1051
+ google_pay_card.debit.should_not be_nil
1052
+ google_pay_card.durbin_regulated.should_not be_nil
1053
+ google_pay_card.healthcare.should_not be_nil
1054
+ google_pay_card.issuing_bank.should_not be_nil
1055
+ google_pay_card.payroll.should_not be_nil
1056
+ google_pay_card.prepaid.should_not be_nil
1057
+ google_pay_card.product_id.should_not be_nil
1040
1058
  end
1041
1059
 
1042
1060
  it "returns associated google pay network tokens" do
@@ -1053,6 +1071,15 @@ describe Braintree::Customer do
1053
1071
  google_pay_card.token.should_not be_nil
1054
1072
  google_pay_card.expiration_year.should_not be_nil
1055
1073
  google_pay_card.is_network_tokenized?.should == true
1074
+ google_pay_card.commercial.should_not be_nil
1075
+ google_pay_card.country_of_issuance.should_not be_nil
1076
+ google_pay_card.debit.should_not be_nil
1077
+ google_pay_card.durbin_regulated.should_not be_nil
1078
+ google_pay_card.healthcare.should_not be_nil
1079
+ google_pay_card.issuing_bank.should_not be_nil
1080
+ google_pay_card.payroll.should_not be_nil
1081
+ google_pay_card.prepaid.should_not be_nil
1082
+ google_pay_card.product_id.should_not be_nil
1056
1083
  end
1057
1084
 
1058
1085
  it "returns associated venmo accounts" do
@@ -41,7 +41,7 @@ VALID_APPLICATION_PARAMS = {
41
41
  :business => {
42
42
  :legal_name => "Joe's Bloggs",
43
43
  :dba_name => "Joe's Junkyard",
44
- :tax_id => "123456789",
44
+ :tax_id => "423456789",
45
45
  :address => {
46
46
  :street_address => "456 Fake St",
47
47
  :postal_code => "48104",
@@ -371,7 +371,7 @@ describe Braintree::MerchantAccount do
371
371
  params[:individual][:address][:postal_code] = "60622"
372
372
  params[:business][:dba_name] = "James's Bloggs"
373
373
  params[:business][:legal_name] = "James's Bloggs Inc"
374
- params[:business][:tax_id] = "123456789"
374
+ params[:business][:tax_id] = "423456789"
375
375
  params[:business][:address][:street_address] = "999 Fake St"
376
376
  params[:business][:address][:locality] = "Miami"
377
377
  params[:business][:address][:region] = "FL"
@@ -397,7 +397,7 @@ describe Braintree::MerchantAccount do
397
397
  result.merchant_account.individual_details.address_details.postal_code.should == "60622"
398
398
  result.merchant_account.business_details.dba_name.should == "James's Bloggs"
399
399
  result.merchant_account.business_details.legal_name.should == "James's Bloggs Inc"
400
- result.merchant_account.business_details.tax_id.should == "123456789"
400
+ result.merchant_account.business_details.tax_id.should == "423456789"
401
401
  result.merchant_account.business_details.address_details.street_address.should == "999 Fake St"
402
402
  result.merchant_account.business_details.address_details.locality.should == "Miami"
403
403
  result.merchant_account.business_details.address_details.region.should == "FL"
@@ -1,5 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
  require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
3
+ require "date"
3
4
 
4
5
  describe Braintree::PaymentMethodNonce do
5
6
  let(:config) { Braintree::Configuration.instantiate }
@@ -84,7 +85,7 @@ describe Braintree::PaymentMethodNonce do
84
85
  nonce.details.bin.should == "401288"
85
86
  nonce.details.card_type.should == "Visa"
86
87
  nonce.details.expiration_month.should == "12"
87
- nonce.details.expiration_year.should == "2022"
88
+ nonce.details.expiration_year.should == Date.today.next_year.year.to_s
88
89
  nonce.details.is_network_tokenized?.should be_nil
89
90
  nonce.details.last_two.should == "81"
90
91
  nonce.details.payer_info.should be_nil
@@ -99,6 +99,15 @@ describe Braintree::PaymentMethod do
99
99
  apple_pay_card.expiration_month.to_i.should > 0
100
100
  apple_pay_card.expiration_year.to_i.should > 0
101
101
  apple_pay_card.customer_id.should == customer.id
102
+ apple_pay_card.commercial.should_not be_nil
103
+ apple_pay_card.country_of_issuance.should_not be_nil
104
+ apple_pay_card.debit.should_not be_nil
105
+ apple_pay_card.durbin_regulated.should_not be_nil
106
+ apple_pay_card.healthcare.should_not be_nil
107
+ apple_pay_card.issuing_bank.should_not be_nil
108
+ apple_pay_card.payroll.should_not be_nil
109
+ apple_pay_card.prepaid.should_not be_nil
110
+ apple_pay_card.product_id.should_not be_nil
102
111
  end
103
112
 
104
113
  it "creates a payment method from a fake google pay proxy card nonce" do
@@ -127,6 +136,15 @@ describe Braintree::PaymentMethod do
127
136
  google_pay_card.google_transaction_id.should == "google_transaction_id"
128
137
  google_pay_card.source_description.should == "Discover 1111"
129
138
  google_pay_card.customer_id.should == customer.id
139
+ google_pay_card.commercial.should_not be_nil
140
+ google_pay_card.country_of_issuance.should_not be_nil
141
+ google_pay_card.debit.should_not be_nil
142
+ google_pay_card.durbin_regulated.should_not be_nil
143
+ google_pay_card.healthcare.should_not be_nil
144
+ google_pay_card.issuing_bank.should_not be_nil
145
+ google_pay_card.payroll.should_not be_nil
146
+ google_pay_card.prepaid.should_not be_nil
147
+ google_pay_card.product_id.should_not be_nil
130
148
  end
131
149
 
132
150
  it "creates a payment method from a google pay network token nonce" do
@@ -155,6 +173,15 @@ describe Braintree::PaymentMethod do
155
173
  google_pay_card.google_transaction_id.should == "google_transaction_id"
156
174
  google_pay_card.source_description.should == "MasterCard 4444"
157
175
  google_pay_card.customer_id.should == customer.id
176
+ google_pay_card.commercial.should_not be_nil
177
+ google_pay_card.country_of_issuance.should_not be_nil
178
+ google_pay_card.debit.should_not be_nil
179
+ google_pay_card.durbin_regulated.should_not be_nil
180
+ google_pay_card.healthcare.should_not be_nil
181
+ google_pay_card.issuing_bank.should_not be_nil
182
+ google_pay_card.payroll.should_not be_nil
183
+ google_pay_card.prepaid.should_not be_nil
184
+ google_pay_card.product_id.should_not be_nil
158
185
  end
159
186
 
160
187
  it "creates a payment method from venmo account nonce" do
@@ -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::Plan do
4
5
 
@@ -48,6 +49,87 @@ describe Braintree::Plan do
48
49
  end
49
50
  end
50
51
 
52
+ describe "self.create" do
53
+ let(:attributes) do
54
+ {
55
+ :billing_day_of_month => 12,
56
+ :billing_frequency => 1,
57
+ :currency_iso_code => "USD",
58
+ :description => "description on create",
59
+ :name => "my new plan name",
60
+ :number_of_billing_cycles => 1,
61
+ :price => "9.99",
62
+ :trial_period => false
63
+ }
64
+
65
+ it "is successful with given params" do
66
+ result = Braintree::Plan.create(attributes)
67
+ expect(result.success?).to be_truthy
68
+ expect(result.plan.billing_day_of_month).to eq 12
69
+ expect(result.plan.description).to eq "description on create"
70
+ expect(result.plan.name).to eq "my new plan name"
71
+ expect(result.plan.price).to eq "9.99"
72
+ expect(result.plan.billing_frequency).to eq 1
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "self.find" do
78
+ it "finds a plan" do
79
+ plan = Braintree::Plan.create(
80
+ :billing_day_of_month => 12,
81
+ :billing_frequency => 1,
82
+ :currency_iso_code => "USD",
83
+ :description => "description on create",
84
+ :name => "my new plan name",
85
+ :number_of_billing_cycles => 1,
86
+ :price => "9.99",
87
+ :trial_period => false,
88
+ ).plan
89
+
90
+ found_plan = Braintree::Plan.find(plan.id)
91
+ expect(found_plan.name).to eq plan.name
92
+ end
93
+
94
+ it "raises Braintree::NotFoundError if it cannot find" do
95
+ expect {
96
+ Braintree::Plan.find("noSuchPlan")
97
+ }.to raise_error(Braintree::NotFoundError, 'plan with id "noSuchPlan" not found')
98
+ end
99
+ end
100
+
101
+ describe "self.update!" do
102
+ before(:each) do
103
+ @plan = Braintree::Plan.create(
104
+ :billing_day_of_month => 12,
105
+ :billing_frequency => 1,
106
+ :currency_iso_code => "USD",
107
+ :description => "description on create",
108
+ :name => "my new plan name",
109
+ :number_of_billing_cycles => 1,
110
+ :price => "9.99",
111
+ :trial_period => false,
112
+ ).plan
113
+ end
114
+
115
+ it "returns the updated plan if valid" do
116
+ new_id = rand(36**9).to_s(36)
117
+ plan = Braintree::Plan.update!(@plan.id,
118
+ :name => "updated name",
119
+ :price => 99.88,
120
+ )
121
+
122
+ expect(plan.name).to eq "updated name"
123
+ expect(plan.price).to eq BigDecimal("99.88")
124
+ end
125
+
126
+ it "raises a ValidationsFailed if invalid" do
127
+ expect do
128
+ Braintree::Plan.update!(@plan.id, :number_of_billing_cycles => "number of billing cycles")
129
+ end.to raise_error(Braintree::ValidationsFailed)
130
+ end
131
+ end
132
+
51
133
  def create_plan_for_tests(attributes)
52
134
  config = Braintree::Configuration.gateway.config
53
135
  config.http.post("#{config.base_merchant_path}/plans/create_plan_for_tests", :plan => attributes)
@@ -999,6 +999,34 @@ describe Braintree::Transaction do
999
999
  result.transaction.credit_card_details.expiration_date.should == "05/2011"
1000
1000
  end
1001
1001
 
1002
+ it "accepts exchange_rate_quote_id" do
1003
+ result = Braintree::Transaction.create(
1004
+ :type => "sale",
1005
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
1006
+ :credit_card => {
1007
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1008
+ :expiration_date => "05/2009"
1009
+ },
1010
+ :exchange_rate_quote_id => "dummyExchangeRateQuoteId-Brainree-Ruby",
1011
+ )
1012
+ result.success?.should == true
1013
+ result.transaction.credit_card_details.expiration_date.should == "05/2009"
1014
+ end
1015
+
1016
+ it "returns an error if provided invalid exchange_rate_quote_id" do
1017
+ result = Braintree::Transaction.create(
1018
+ :type => "sale",
1019
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
1020
+ :credit_card => {
1021
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1022
+ :expiration_date => "05/2009"
1023
+ },
1024
+ :exchange_rate_quote_id => "a" * 4010,
1025
+ )
1026
+ result.success?.should == false
1027
+ result.errors.for(:transaction).on(:exchange_rate_quote_id)[0].code.should == Braintree::ErrorCodes::Transaction::ExchangeRateQuoteIdTooLong
1028
+ end
1029
+
1002
1030
  it "returns some error if customer_id is invalid" do
1003
1031
  result = Braintree::Transaction.create(
1004
1032
  :type => "sale",
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Braintree::EnrichedCustomerData do
4
+ describe "self.new" do
5
+ it "is protected" do
6
+ expect do
7
+ Braintree::EnrichedCustomerData.new
8
+ end.to raise_error(NoMethodError, /protected method .new/)
9
+ end
10
+ end
11
+
12
+ describe "self._new" do
13
+ it "initializes the object with the appropriate attributes set" do
14
+
15
+ params = {
16
+ fields_updated: ["username"],
17
+ profile_data: {
18
+ username: "a-username",
19
+ first_name: "a-first-name",
20
+ last_name: "a-last-name",
21
+ phone_number: "a-phone-number",
22
+ email: "a-email",
23
+ },
24
+ }
25
+
26
+ payment_method_customer_data_updated = Braintree::EnrichedCustomerData._new(params)
27
+
28
+ payment_method_customer_data_updated.profile_data.should be_a(Braintree::VenmoProfileData)
29
+ payment_method_customer_data_updated.fields_updated.should eq(["username"])
30
+ end
31
+ end
32
+ end
@@ -25,6 +25,7 @@ END
25
25
  <last-name>Doe</last-name>
26
26
  <number>1234560000001234</number>
27
27
  <cvv>123</cvv>
28
+ <encrypted-card-data>8F34DFB312DC79C24FD5320622F3E11682D79E6B0C0FD881</encrypted-card-data>
28
29
  </customer>
29
30
  END
30
31
 
@@ -34,6 +35,7 @@ END
34
35
  [Braintree] <last-name>Doe</last-name>
35
36
  [Braintree] <number>123456******1234</number>
36
37
  [Braintree] <cvv>***</cvv>
38
+ [Braintree] <encrypted-card-data>***</encrypted-card-data>
37
39
  [Braintree] </customer>
38
40
  END
39
41
  Braintree::Http.new(:config)._format_and_sanitize_body_for_log(input_xml).should == expected_xml
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Braintree::LocalPaymentExpired do
4
+ describe "self.new" do
5
+ it "is protected" do
6
+ expect do
7
+ Braintree::LocalPaymentExpired.new
8
+ end.to raise_error(NoMethodError, /protected method .new/)
9
+ end
10
+ end
11
+
12
+ describe "self._new" do
13
+ it "initializes the object with the appropriate attributes set" do
14
+ params = {
15
+ payment_id: "a-payment-id",
16
+ payment_context_id: "a-payment-context-id",
17
+ }
18
+ local_payment_expired = Braintree::LocalPaymentExpired._new(params)
19
+
20
+ local_payment_expired.payment_id.should eq("a-payment-id")
21
+ local_payment_expired.payment_context_id.should eq("a-payment-context-id")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Braintree::LocalPaymentFunded do
4
+ describe "self.new" do
5
+ it "is protected" do
6
+ expect do
7
+ Braintree::LocalPaymentFunded.new
8
+ end.to raise_error(NoMethodError, /protected method .new/)
9
+ end
10
+ end
11
+
12
+ describe "self._new" do
13
+ it "initializes the object with the appropriate attributes set" do
14
+ params = {
15
+ payment_id: "a-payment-id",
16
+ payment_context_id: "a-payment-context-id",
17
+ transaction: {
18
+ id: "a-transaction-id",
19
+ amount: "31.00",
20
+ order_id: "an-order-id",
21
+ status: Braintree::Transaction::Status::Settled,
22
+ },
23
+ }
24
+ local_payment_funded = Braintree::LocalPaymentFunded._new(params)
25
+
26
+ local_payment_funded.payment_id.should eq("a-payment-id")
27
+ local_payment_funded.payment_context_id.should eq("a-payment-context-id")
28
+ local_payment_funded.transaction.id.should eq("a-transaction-id")
29
+ local_payment_funded.transaction.amount.should eq(31.0)
30
+ local_payment_funded.transaction.order_id.should eq("an-order-id")
31
+ local_payment_funded.transaction.status.should eq(Braintree::Transaction::Status::Settled)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Braintree::PaymentMethodCustomerDataUpdatedMetadata do
4
+ describe "self.new" do
5
+ it "is protected" do
6
+ expect do
7
+ Braintree::PaymentMethodCustomerDataUpdatedMetadata.new
8
+ end.to raise_error(NoMethodError, /protected method .new/)
9
+ end
10
+ end
11
+
12
+ describe "self._new" do
13
+ it "initializes the object with the appropriate attributes set" do
14
+
15
+ params = {
16
+ token: "a-token",
17
+ payment_method: {
18
+ venmo_account: {
19
+ venmo_user_id: "venmo-user-id",
20
+ },
21
+ },
22
+ datetime_updated: "2022-01-01T21:28:37Z",
23
+ enriched_customer_data: {
24
+ fields_updated: ["username"],
25
+ profile_data: {
26
+ username: "a-username",
27
+ first_name: "a-first-name",
28
+ last_name: "a-last-name",
29
+ phone_number: "a-phone-number",
30
+ email: "a-email",
31
+ },
32
+ },
33
+ }
34
+
35
+ payment_method_customer_data_updated = Braintree::PaymentMethodCustomerDataUpdatedMetadata._new(:gateway, params)
36
+
37
+ payment_method_customer_data_updated.token.should eq("a-token")
38
+ payment_method_customer_data_updated.datetime_updated.should eq("2022-01-01T21:28:37Z")
39
+ payment_method_customer_data_updated.payment_method.should be_a(Braintree::VenmoAccount)
40
+ payment_method_customer_data_updated.enriched_customer_data.profile_data.first_name.should eq("a-first-name")
41
+ payment_method_customer_data_updated.enriched_customer_data.profile_data.last_name.should eq("a-last-name")
42
+ payment_method_customer_data_updated.enriched_customer_data.fields_updated.should eq(["username"])
43
+ end
44
+ end
45
+ 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
 
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Braintree::VenmoProfileData do
4
+ describe "self.new" do
5
+ it "is protected" do
6
+ expect do
7
+ Braintree::VenmoProfileData.new
8
+ end.to raise_error(NoMethodError, /protected method .new/)
9
+ end
10
+ end
11
+
12
+ describe "self._new" do
13
+ it "initializes the object with the appropriate attributes set" do
14
+
15
+ params = {
16
+ username: "a-username",
17
+ first_name: "a-first-name",
18
+ last_name: "a-last-name",
19
+ phone_number: "12312312343",
20
+ email: "a-email",
21
+ }
22
+
23
+ payment_method_customer_data_updated = Braintree::VenmoProfileData._new(params)
24
+
25
+ payment_method_customer_data_updated.username.should eq("a-username")
26
+ payment_method_customer_data_updated.first_name.should eq("a-first-name")
27
+ payment_method_customer_data_updated.last_name.should eq("a-last-name")
28
+ payment_method_customer_data_updated.phone_number.should eq("12312312343")
29
+ payment_method_customer_data_updated.email.should eq("a-email")
30
+ end
31
+ end
32
+ end
@@ -317,6 +317,24 @@ describe Braintree::WebhookNotification do
317
317
  end
318
318
  end
319
319
 
320
+ context "transaction review" do
321
+ it " builds a sample notification for a transaction reviewed webhook" do
322
+ sample_notification = Braintree::WebhookTesting.sample_notification(
323
+ Braintree::WebhookNotification::Kind::TransactionReviewed,
324
+ "my_id",
325
+ )
326
+
327
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
328
+
329
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::TransactionReviewed)
330
+ expect(notification.transaction_review.transaction_id).to eq("my_id")
331
+ expect(notification.transaction_review.decision).to eq("decision")
332
+ expect(notification.transaction_review.reviewer_email).to eq("hey@girl.com")
333
+ expect(notification.transaction_review.reviewer_note).to eq("i reviewed this")
334
+ expect(notification.transaction_review.reviewed_time).to_not be_nil
335
+ end
336
+ end
337
+
320
338
  context "us bank account transactions" do
321
339
  it "builds a sample notification for a settlement webhook" do
322
340
  sample_notification = Braintree::WebhookTesting.sample_notification(
@@ -668,6 +686,40 @@ describe Braintree::WebhookNotification do
668
686
  end
669
687
  end
670
688
 
689
+ context "local_payment_expired" do
690
+ it "builds a sample notification for a local_payment_expired webhook" do
691
+ sample_notification = Braintree::WebhookTesting.sample_notification(
692
+ Braintree::WebhookNotification::Kind::LocalPaymentExpired,
693
+ "my_id",
694
+ )
695
+
696
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
697
+ notification.kind.should == Braintree::WebhookNotification::Kind::LocalPaymentExpired
698
+
699
+ local_payment_expired = notification.local_payment_expired
700
+ local_payment_expired.payment_id.should == "PAY-XYZ123"
701
+ local_payment_expired.payment_context_id.should == "cG5b="
702
+ end
703
+ end
704
+
705
+ context "local_payment_funded" do
706
+ it "builds a sample notification for a local_payment_funded webhook" do
707
+ sample_notification = Braintree::WebhookTesting.sample_notification(
708
+ Braintree::WebhookNotification::Kind::LocalPaymentFunded,
709
+ "my_id",
710
+ )
711
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
712
+ notification.kind.should == Braintree::WebhookNotification::Kind::LocalPaymentFunded
713
+
714
+ local_payment_funded = notification.local_payment_funded
715
+ local_payment_funded.payment_id.should == "PAY-XYZ123"
716
+ local_payment_funded.payment_context_id.should == "cG5b="
717
+ local_payment_funded.transaction.id.should == "my_id"
718
+ local_payment_funded.transaction.status.should == Braintree::Transaction::Status::Settled
719
+ local_payment_funded.transaction.amount.should == 49.99
720
+ local_payment_funded.transaction.order_id.should == "order4567"
721
+ end
722
+ end
671
723
 
672
724
  context "local_payment_reversed" do
673
725
  it "builds a sample notification for a local_payment webhook" do
@@ -675,7 +727,6 @@ describe Braintree::WebhookNotification do
675
727
  Braintree::WebhookNotification::Kind::LocalPaymentReversed,
676
728
  "my_id",
677
729
  )
678
-
679
730
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
680
731
  notification.kind.should == Braintree::WebhookNotification::Kind::LocalPaymentReversed
681
732
 
@@ -684,6 +735,32 @@ describe Braintree::WebhookNotification do
684
735
  end
685
736
  end
686
737
 
738
+ context "payment_method_customer_data_updated" do
739
+ it "builds a sample notification for a payment_method_customer_data_updated webhook" do
740
+ sample_notification = Braintree::WebhookTesting.sample_notification(
741
+ Braintree::WebhookNotification::Kind::PaymentMethodCustomerDataUpdated,
742
+ "my_id",
743
+ )
744
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
745
+ notification.kind.should == Braintree::WebhookNotification::Kind::PaymentMethodCustomerDataUpdated
746
+
747
+ payment_method_customer_data_updated = notification.payment_method_customer_data_updated_metadata
748
+
749
+ payment_method_customer_data_updated.token.should eq("TOKEN-12345")
750
+ payment_method_customer_data_updated.datetime_updated.should eq("2022-01-01T21:28:37Z")
751
+
752
+ enriched_customer_data = payment_method_customer_data_updated.enriched_customer_data
753
+ enriched_customer_data.fields_updated.should eq(["username"])
754
+
755
+ profile_data = enriched_customer_data.profile_data
756
+ profile_data.first_name.should eq("John")
757
+ profile_data.last_name.should eq("Doe")
758
+ profile_data.username.should eq("venmo_username")
759
+ profile_data.phone_number.should eq("1231231234")
760
+ profile_data.email.should eq("john.doe@paypal.com")
761
+ end
762
+ end
763
+
687
764
  describe "parse" do
688
765
  it "raises InvalidSignature error when the signature is nil" do
689
766
  expect do