braintree 4.23.0 → 4.25.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/lib/braintree/customer_session_gateway.rb +194 -0
  3. data/lib/braintree/error_result.rb +1 -1
  4. data/lib/braintree/errors.rb +2 -1
  5. data/lib/braintree/gateway.rb +4 -0
  6. data/lib/braintree/graphql/enums/recommendations.rb +7 -0
  7. data/lib/braintree/graphql/enums/recommended_payment_option.rb +8 -0
  8. data/lib/braintree/graphql/inputs/create_customer_session_input.rb +35 -0
  9. data/lib/braintree/graphql/inputs/customer_recommendations_input.rb +41 -0
  10. data/lib/braintree/graphql/inputs/customer_session_input.rb +39 -0
  11. data/lib/braintree/graphql/inputs/phone_input.rb +32 -0
  12. data/lib/braintree/graphql/inputs/update_customer_session_input.rb +37 -0
  13. data/lib/braintree/graphql/types/customer_recommendations_payload.rb +32 -0
  14. data/lib/braintree/graphql/types/payment_options.rb +33 -0
  15. data/lib/braintree/graphql/unions/customer_recommendations.rb +34 -0
  16. data/lib/braintree/graphql_client.rb +16 -0
  17. data/lib/braintree/successful_result.rb +2 -0
  18. data/lib/braintree/transaction/paypal_details.rb +2 -0
  19. data/lib/braintree/transaction_gateway.rb +10 -10
  20. data/lib/braintree/version.rb +1 -1
  21. data/lib/braintree.rb +11 -0
  22. data/spec/integration/braintree/advanced_search_spec.rb +7 -4
  23. data/spec/integration/braintree/credit_card_spec.rb +2 -1
  24. data/spec/integration/braintree/customer_session_spec.rb +143 -0
  25. data/spec/integration/braintree/customer_spec.rb +2 -1
  26. data/spec/integration/braintree/transaction_search_spec.rb +9 -6
  27. data/spec/integration/braintree/transaction_spec.rb +38 -0
  28. data/spec/unit/braintree/customer_session_gateway_spec.rb +120 -0
  29. data/spec/unit/braintree/graphql/create_customer_session_input_spec.rb +81 -0
  30. data/spec/unit/braintree/graphql/customer_recommendations_input_spec.rb +110 -0
  31. data/spec/unit/braintree/graphql/customer_session_input_spec.rb +81 -0
  32. data/spec/unit/braintree/graphql/phone_input_spec.rb +51 -0
  33. data/spec/unit/braintree/graphql/update_customer_session_input_spec.rb +93 -0
  34. data/spec/unit/braintree/graphql_client_spec.rb +37 -0
  35. data/spec/unit/braintree/transaction/paypal_details_spec.rb +5 -0
  36. data/spec/unit/braintree/transaction_gateway_spec.rb +10 -10
  37. metadata +21 -2
@@ -0,0 +1,81 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+
4
+ describe Braintree::CustomerSessionInput do
5
+ let(:input_data) do
6
+ {
7
+ email: "test@example.com" ,
8
+ phone: {
9
+ country_phone_code: "1",
10
+ phone_number: "555-123-4567",
11
+ extension_number: "123",
12
+ },
13
+ user_agent: "Mozilla"
14
+ }
15
+ end
16
+
17
+ describe "#initialize" do
18
+ it "initializes with attributes" do
19
+ input = Braintree::CustomerSessionInput.new(input_data)
20
+
21
+ expect(input.attrs).to eq(input_data.keys)
22
+ expect(input.email).to eq("test@example.com")
23
+ expect(input.phone.country_phone_code).to eq("1")
24
+ expect(input.phone.phone_number).to eq("555-123-4567")
25
+ expect(input.phone.extension_number).to eq("123")
26
+ expect(input.user_agent).to eq("Mozilla")
27
+ end
28
+
29
+ it "handles nil email" do
30
+ attributes = {}
31
+ input = Braintree::CustomerSessionInput.new(attributes)
32
+ expect(input.email).to be_nil
33
+ end
34
+ end
35
+
36
+
37
+ describe "#inspect" do
38
+ it "returns a string representation of the object" do
39
+ input = Braintree::CustomerSessionInput.new(input_data)
40
+ expected_string = "#<Braintree::CustomerSessionInput email:\"test@example.com\" phone:#<Braintree::PhoneInput country_phone_code:\"1\" phone_number:\"555-123-4567\" extension_number:\"123\"> user_agent:\"Mozilla\">"
41
+ expect(input.inspect).to eq(expected_string)
42
+
43
+ end
44
+
45
+ it "handles nil values" do
46
+ attributes = {}
47
+ input = Braintree::CustomerSessionInput.new(attributes)
48
+ expected_string = "#<Braintree::CustomerSessionInput >"
49
+
50
+ expect(input.inspect).to eq(expected_string)
51
+ end
52
+
53
+ end
54
+
55
+ describe "#to_graphql_variables" do
56
+ it "converts the input to graphql variables" do
57
+ input = Braintree::CustomerSessionInput.new(input_data)
58
+ expected_variables = {
59
+ "email" => "test@example.com",
60
+ "phone" => {
61
+ "countryPhoneCode" => "1",
62
+ "phoneNumber" => "555-123-4567",
63
+ "extensionNumber" => "123"
64
+ },
65
+ "userAgent" => "Mozilla"
66
+ }
67
+
68
+ expect(input.to_graphql_variables).to eq(expected_variables)
69
+
70
+
71
+ end
72
+
73
+ it "handles nil values" do
74
+ attributes = {}
75
+ input = Braintree::CustomerSessionInput.new(attributes)
76
+ expected_variables = {}
77
+
78
+ expect(input.to_graphql_variables).to eq(expected_variables)
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+
4
+ describe Braintree::PhoneInput do
5
+ let(:phone_input_data) do
6
+ {
7
+ country_phone_code: "1",
8
+ phone_number: "555-123-4567",
9
+ extension_number: "123"
10
+ }
11
+ end
12
+
13
+ let(:partial_phone_input_data) do
14
+ {
15
+ country_phone_code: "1",
16
+ phone_number: "555-123-4567"
17
+ }
18
+ end
19
+
20
+
21
+ describe "#initialize" do
22
+ it "initialize and sets the input keys to attrs variable" do
23
+ phone_input = described_class.new(phone_input_data)
24
+
25
+ expect(phone_input.attrs).to include(:country_phone_code)
26
+ expect(phone_input.attrs).to include(:phone_number)
27
+ expect(phone_input.attrs).to include(:extension_number)
28
+ expect(phone_input.attrs.length).to eq(3)
29
+ end
30
+ end
31
+
32
+ describe "inspect" do
33
+ it "includes all phone input attributes" do
34
+ phone_input = described_class.new(phone_input_data)
35
+ output = phone_input.inspect
36
+
37
+ expect(output).to include("country_phone_code:\"1\"")
38
+ expect(output).to include("phone_number:\"555-123-4567\"")
39
+ expect(output).to include("extension_number:\"123\"")
40
+ end
41
+
42
+ it "includes only specified phone input attributes" do
43
+ phone_input = described_class.new(partial_phone_input_data)
44
+ output = phone_input.inspect
45
+
46
+ expect(output).to include("country_phone_code:\"1\"")
47
+ expect(output).to include("phone_number:\"555-123-4567\"")
48
+ expect(output).not_to include("extension_number")
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,93 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+
4
+ describe Braintree::UpdateCustomerSessionInput do
5
+ let(:input_data) do
6
+ {
7
+ merchant_account_id: "merchant-account-id",
8
+ session_id: "session-id",
9
+ customer: {email: "test@example.com"}
10
+ }
11
+ end
12
+ describe "#initialize" do
13
+ it "initializes with attributes" do
14
+ input = Braintree::UpdateCustomerSessionInput.new(input_data)
15
+
16
+ expect(input.attrs).to eq(input_data.keys)
17
+ expect(input.merchant_account_id).to eq("merchant-account-id")
18
+ expect(input.session_id).to eq("session-id")
19
+ expect(input.customer).to be_a(Braintree::CustomerSessionInput)
20
+ expect(input.customer.email).to eq("test@example.com")
21
+ end
22
+
23
+ it "disallows nil session id" do
24
+ attributes = {
25
+ merchant_account_id: "merchant-account-id",
26
+ }
27
+ expect do
28
+ Braintree::UpdateCustomerSessionInput.new(attributes)
29
+ end.to raise_error(ArgumentError, "Expected hash to contain a :session_id")
30
+ end
31
+
32
+ it "handles nil customer" do
33
+ attributes = {
34
+ merchant_account_id: "merchant-account-id",
35
+ session_id: "session-id",
36
+ }
37
+ input = Braintree::UpdateCustomerSessionInput.new(attributes)
38
+
39
+ expect(input.customer).to be_nil
40
+ end
41
+ end
42
+
43
+
44
+ describe "#inspect" do
45
+ it "returns a string representation of the object" do
46
+ input = Braintree::UpdateCustomerSessionInput.new(input_data)
47
+ expected_string = "#<Braintree::UpdateCustomerSessionInput merchant_account_id:\"merchant-account-id\" session_id:\"session-id\" customer:#<Braintree::CustomerSessionInput email:\"test@example.com\">>"
48
+ expect(input.inspect).to eq(expected_string)
49
+
50
+ end
51
+
52
+ it "handles nil values" do
53
+ attributes = {
54
+ merchant_account_id: "merchant-account-id",
55
+ session_id: "session-id",
56
+ }
57
+ input = Braintree::UpdateCustomerSessionInput.new(attributes)
58
+ expected_string = "#<Braintree::UpdateCustomerSessionInput merchant_account_id:\"merchant-account-id\" session_id:\"session-id\">"
59
+
60
+ expect(input.inspect).to eq(expected_string)
61
+ end
62
+
63
+ end
64
+
65
+ describe "#to_graphql_variables" do
66
+ it "converts the input to graphql variables" do
67
+ input = Braintree::UpdateCustomerSessionInput.new(input_data)
68
+ expected_variables = {
69
+ "merchantAccountId" => "merchant-account-id",
70
+ "sessionId" => "session-id",
71
+ "customer" => {"email" => "test@example.com"},
72
+ }
73
+
74
+ expect(input.to_graphql_variables).to eq(expected_variables)
75
+ end
76
+
77
+ it "handles nil values" do
78
+ attributes = {
79
+ merchant_account_id: "merchant-account-id",
80
+ session_id: "session-id",
81
+ }
82
+ input = Braintree::UpdateCustomerSessionInput.new(attributes)
83
+
84
+ expected_variables = {
85
+ "merchantAccountId" => "merchant-account-id",
86
+ "sessionId" => "session-id",
87
+ }
88
+
89
+ expect(input.to_graphql_variables).to eq(expected_variables)
90
+ end
91
+ end
92
+
93
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Braintree::GraphQLClient do
4
+
5
+ describe ".get_validation_errors" do
6
+ it "returns nil if no errors" do
7
+ expect(Braintree::GraphQLClient.get_validation_errors({})).to be_nil
8
+ end
9
+
10
+ it "returns nil if errors is not an array" do
11
+ expect(Braintree::GraphQLClient.get_validation_errors({:errors => "string"})).to be_nil
12
+ end
13
+
14
+ it "returns validation errors" do
15
+ response = {
16
+ :errors => [
17
+ {:message => "Invalid input", :extensions => {:legacyCode => "81803"}},
18
+ {:message => "Another error", :extensions => {:legacyCode => "91903"}}
19
+ ]
20
+ }
21
+ expected_errors = {
22
+ :errors => [
23
+ {:attribute => "", :code => "81803", :message => "Invalid input"},
24
+ {:attribute => "", :code => "91903", :message => "Another error"}
25
+ ]
26
+ }
27
+ expect(Braintree::GraphQLClient.get_validation_errors(response)).to eq(expected_errors)
28
+ end
29
+
30
+
31
+ it "handles missing legacyCode" do
32
+ response = {:errors => [{:message => "Invalid input"}]}
33
+ expected_errors = {:errors => [{:attribute => "", :code => nil, :message => "Invalid input"}]}
34
+ expect(Braintree::GraphQLClient.get_validation_errors(response)).to eq(expected_errors)
35
+ end
36
+ end
37
+ end
@@ -21,6 +21,8 @@ describe Braintree::Transaction::PayPalDetails do
21
21
  :payer_last_name => "Hopper",
22
22
  :payer_status =>"status",
23
23
  :payment_id => "payment-id",
24
+ :recipient_email => "test@paypal.com",
25
+ :recipient_phone => [:country_code => "1", :national_number => "4082222222"],
24
26
  :refund_from_transaction_fee_amount => "1.00",
25
27
  :refund_from_transaction_fee_currency_iso_code => "123",
26
28
  :refund_id => "refund-id",
@@ -49,6 +51,9 @@ describe Braintree::Transaction::PayPalDetails do
49
51
  expect(details.payer_last_name).to eq("Hopper")
50
52
  expect(details.payer_status).to eq("status")
51
53
  expect(details.payment_id).to eq("payment-id")
54
+ expect(details.recipient_email).to eq("test@paypal.com")
55
+ expect(details.recipient_phone.country_code).to eq("1")
56
+ expect(details.recipient_phone.national_number).to eq("4082222222")
52
57
  expect(details.refund_from_transaction_fee_amount).to eq("1.00")
53
58
  expect(details.refund_from_transaction_fee_currency_iso_code).to eq("123")
54
59
  expect(details.refund_id).to eq("refund-id")
@@ -73,24 +73,24 @@ describe Braintree::TransactionGateway do
73
73
  {:installments => [:count]},
74
74
  {:line_items => [:commodity_code, :description, :discount_amount, :image_url, :kind, :name, :product_code, :quantity, :tax_amount, :total_amount, :unit_amount, :unit_of_measure, :unit_tax_amount, :upc_code, :upc_type, :url]},
75
75
  {:options => [
76
- :hold_in_escrow,
77
- :store_in_vault,
78
- :store_in_vault_on_success,
79
- :submit_for_settlement,
80
76
  :add_billing_address_to_payment_method,
81
- :store_shipping_address_in_vault,
82
- :venmo_sdk_session, # Deprecated
77
+ {:amex_rewards => [:request_id, :points, :currency_amount, :currency_iso_code]},
78
+ {:credit_card => [:account_type, :process_debit_as_credit]},
79
+ :hold_in_escrow,
83
80
  :payee_id,
84
81
  :payee_email,
82
+ {:paypal => [:custom_field, :description, :payee_id, :payee_email, :recipient_email, {:recipient_phone => [:country_code, :national_number]}, {:supplementary_data => :_any_key_}]},
83
+ {:processing_overrides => [:customer_email, :customer_first_name, :customer_last_name, :customer_tax_identifier]},
85
84
  :skip_advanced_fraud_checking,
86
85
  :skip_avs,
87
86
  :skip_cvv,
88
- {:paypal => [:custom_field, :payee_id, :payee_email, :description, {:supplementary_data => :_any_key_}]},
89
- {:processing_overrides => [:customer_email, :customer_first_name, :customer_last_name, :customer_tax_identifier]},
87
+ :store_in_vault,
88
+ :store_in_vault_on_success,
89
+ :store_shipping_address_in_vault,
90
+ :submit_for_settlement,
90
91
  {:three_d_secure => [:required]},
91
- {:amex_rewards => [:request_id, :points, :currency_amount, :currency_iso_code]},
92
92
  {:venmo => [:profile_id]},
93
- {:credit_card => [:account_type, :process_debit_as_credit]},
93
+ :venmo_sdk_session, # Deprecated
94
94
  ]
95
95
  },
96
96
  {:paypal_account => [:email, :token, :paypal_data, :payee_id, :payee_email, :payer_id, :payment_id]},
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: 4.23.0
4
+ version: 4.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Braintree
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-29 00:00:00.000000000 Z
11
+ date: 2025-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -77,6 +77,7 @@ files:
77
77
  - lib/braintree/customer.rb
78
78
  - lib/braintree/customer_gateway.rb
79
79
  - lib/braintree/customer_search.rb
80
+ - lib/braintree/customer_session_gateway.rb
80
81
  - lib/braintree/descriptor.rb
81
82
  - lib/braintree/digest.rb
82
83
  - lib/braintree/disbursement.rb
@@ -108,6 +109,16 @@ files:
108
109
  - lib/braintree/gateway.rb
109
110
  - lib/braintree/google_pay_card.rb
110
111
  - lib/braintree/granted_payment_instrument_update.rb
112
+ - lib/braintree/graphql/enums/recommendations.rb
113
+ - lib/braintree/graphql/enums/recommended_payment_option.rb
114
+ - lib/braintree/graphql/inputs/create_customer_session_input.rb
115
+ - lib/braintree/graphql/inputs/customer_recommendations_input.rb
116
+ - lib/braintree/graphql/inputs/customer_session_input.rb
117
+ - lib/braintree/graphql/inputs/phone_input.rb
118
+ - lib/braintree/graphql/inputs/update_customer_session_input.rb
119
+ - lib/braintree/graphql/types/customer_recommendations_payload.rb
120
+ - lib/braintree/graphql/types/payment_options.rb
121
+ - lib/braintree/graphql/unions/customer_recommendations.rb
111
122
  - lib/braintree/graphql_client.rb
112
123
  - lib/braintree/http.rb
113
124
  - lib/braintree/local_payment_completed.rb
@@ -239,6 +250,7 @@ files:
239
250
  - spec/integration/braintree/credit_card_verification_search_spec.rb
240
251
  - spec/integration/braintree/credit_card_verification_spec.rb
241
252
  - spec/integration/braintree/customer_search_spec.rb
253
+ - spec/integration/braintree/customer_session_spec.rb
242
254
  - spec/integration/braintree/customer_spec.rb
243
255
  - spec/integration/braintree/disbursement_spec.rb
244
256
  - spec/integration/braintree/discount_spec.rb
@@ -290,6 +302,7 @@ files:
290
302
  - spec/unit/braintree/credit_card_verification_gateway_spec.rb
291
303
  - spec/unit/braintree/credit_card_verification_search_spec.rb
292
304
  - spec/unit/braintree/credit_card_verification_spec.rb
305
+ - spec/unit/braintree/customer_session_gateway_spec.rb
293
306
  - spec/unit/braintree/customer_spec.rb
294
307
  - spec/unit/braintree/digest_spec.rb
295
308
  - spec/unit/braintree/disbursement_spec.rb
@@ -304,6 +317,12 @@ files:
304
317
  - spec/unit/braintree/exchange_rate_quote_response_spec.rb
305
318
  - spec/unit/braintree/exchange_rate_quote_spec.rb
306
319
  - spec/unit/braintree/exchange_rate_spec.rb
320
+ - spec/unit/braintree/graphql/create_customer_session_input_spec.rb
321
+ - spec/unit/braintree/graphql/customer_recommendations_input_spec.rb
322
+ - spec/unit/braintree/graphql/customer_session_input_spec.rb
323
+ - spec/unit/braintree/graphql/phone_input_spec.rb
324
+ - spec/unit/braintree/graphql/update_customer_session_input_spec.rb
325
+ - spec/unit/braintree/graphql_client_spec.rb
307
326
  - spec/unit/braintree/http_spec.rb
308
327
  - spec/unit/braintree/local_payment_completed_spec.rb
309
328
  - spec/unit/braintree/local_payment_expired_spec.rb