braintree 4.24.0 → 4.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/lib/braintree/apple_pay_card.rb +1 -0
  3. data/lib/braintree/bin_data.rb +2 -1
  4. data/lib/braintree/credit_card.rb +6 -5
  5. data/lib/braintree/customer_session_gateway.rb +194 -0
  6. data/lib/braintree/error_codes.rb +41 -0
  7. data/lib/braintree/error_result.rb +1 -1
  8. data/lib/braintree/errors.rb +2 -1
  9. data/lib/braintree/gateway.rb +8 -0
  10. data/lib/braintree/google_pay_card.rb +1 -0
  11. data/lib/braintree/graphql/enums/recommendations.rb +7 -0
  12. data/lib/braintree/graphql/enums/recommended_payment_option.rb +8 -0
  13. data/lib/braintree/graphql/inputs/create_customer_session_input.rb +35 -0
  14. data/lib/braintree/graphql/inputs/customer_recommendations_input.rb +41 -0
  15. data/lib/braintree/graphql/inputs/customer_session_input.rb +39 -0
  16. data/lib/braintree/graphql/inputs/phone_input.rb +32 -0
  17. data/lib/braintree/graphql/inputs/update_customer_session_input.rb +37 -0
  18. data/lib/braintree/graphql/types/customer_recommendations_payload.rb +32 -0
  19. data/lib/braintree/graphql/types/payment_options.rb +33 -0
  20. data/lib/braintree/graphql/unions/customer_recommendations.rb +34 -0
  21. data/lib/braintree/graphql_client.rb +16 -0
  22. data/lib/braintree/meta_checkout_card.rb +6 -5
  23. data/lib/braintree/meta_checkout_token.rb +6 -5
  24. data/lib/braintree/paypal_payment_resource.rb +22 -0
  25. data/lib/braintree/paypal_payment_resource_gateway.rb +36 -0
  26. data/lib/braintree/successful_result.rb +2 -0
  27. data/lib/braintree/test/credit_card.rb +1 -0
  28. data/lib/braintree/transaction/apple_pay_details.rb +1 -0
  29. data/lib/braintree/transaction/credit_card_details.rb +12 -10
  30. data/lib/braintree/transaction/google_pay_details.rb +11 -10
  31. data/lib/braintree/transaction/meta_checkout_card_details.rb +5 -2
  32. data/lib/braintree/transaction/meta_checkout_token_details.rb +6 -2
  33. data/lib/braintree/transaction/visa_checkout_card_details.rb +5 -2
  34. data/lib/braintree/version.rb +1 -1
  35. data/lib/braintree/visa_checkout_card.rb +5 -5
  36. data/lib/braintree.rb +13 -0
  37. data/spec/integration/braintree/credit_card_spec.rb +12 -0
  38. data/spec/integration/braintree/credit_card_verification_spec.rb +24 -0
  39. data/spec/integration/braintree/customer_session_spec.rb +143 -0
  40. data/spec/integration/braintree/customer_spec.rb +22 -6
  41. data/spec/integration/braintree/payment_method_nonce_spec.rb +11 -0
  42. data/spec/integration/braintree/paypal_payment_resource_spec.rb +141 -0
  43. data/spec/integration/braintree/transaction_spec.rb +15 -0
  44. data/spec/unit/braintree/apple_pay_card_spec.rb +1 -0
  45. data/spec/unit/braintree/credit_card_spec.rb +5 -0
  46. data/spec/unit/braintree/customer_session_gateway_spec.rb +120 -0
  47. data/spec/unit/braintree/google_pay_card_spec.rb +8 -0
  48. data/spec/unit/braintree/graphql/create_customer_session_input_spec.rb +81 -0
  49. data/spec/unit/braintree/graphql/customer_recommendations_input_spec.rb +110 -0
  50. data/spec/unit/braintree/graphql/customer_session_input_spec.rb +81 -0
  51. data/spec/unit/braintree/graphql/phone_input_spec.rb +51 -0
  52. data/spec/unit/braintree/graphql/update_customer_session_input_spec.rb +93 -0
  53. data/spec/unit/braintree/graphql_client_spec.rb +37 -0
  54. data/spec/unit/braintree/meta_checkout_card_spec.rb +53 -51
  55. data/spec/unit/braintree/meta_checkout_token_spec.rb +3 -1
  56. data/spec/unit/braintree/payment_method_nonce_spec.rb +4 -1
  57. data/spec/unit/braintree/paypal_payment_resource_spec.rb +125 -0
  58. data/spec/unit/braintree/transaction/apple_pay_details_spec.rb +8 -0
  59. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +2 -1
  60. data/spec/unit/braintree/transaction/google_pay_details_spec.rb +8 -0
  61. data/spec/unit/braintree/transaction/meta_checkout_card_details_spec.rb +8 -0
  62. data/spec/unit/braintree/transaction/meta_checkout_token_details_spec.rb +8 -0
  63. data/spec/unit/braintree/transaction/visa_checkout_card_details_spec.rb +8 -0
  64. data/spec/unit/braintree/transaction_spec.rb +2 -0
  65. data/spec/unit/braintree/visa_checkout_card_spec.rb +8 -0
  66. data/spec/unit/credit_card_details_spec.rb +8 -0
  67. metadata +33 -2
@@ -230,6 +230,16 @@ describe Braintree::PaymentMethodNonce do
230
230
  expect(nonce.bin_data.prepaid).to eq(Braintree::CreditCard::Prepaid::Yes)
231
231
  end
232
232
 
233
+ it "returns bin_data with prepaid_reloadable set to Yes" do
234
+ result = Braintree::PaymentMethodNonce.find("fake-valid-prepaid-reloadable-nonce")
235
+
236
+ nonce = result.payment_method_nonce
237
+
238
+ expect(result).to be_success
239
+ expect(nonce.bin_data).not_to be_nil
240
+ expect(nonce.bin_data.prepaid_reloadable).to eq(Braintree::CreditCard::PrepaidReloadable::Yes)
241
+ end
242
+
233
243
  it "returns bin_data with unknown indicators" do
234
244
  result = Braintree::PaymentMethodNonce.find("fake-valid-unknown-indicators-nonce")
235
245
 
@@ -245,6 +255,7 @@ describe Braintree::PaymentMethodNonce do
245
255
  expect(nonce.bin_data.issuing_bank).to eq(Braintree::CreditCard::IssuingBank::Unknown)
246
256
  expect(nonce.bin_data.payroll).to eq(Braintree::CreditCard::Payroll::Unknown)
247
257
  expect(nonce.bin_data.prepaid).to eq(Braintree::CreditCard::Prepaid::Unknown)
258
+ expect(nonce.bin_data.prepaid_reloadable).to eq(Braintree::CreditCard::PrepaidReloadable::Unknown)
248
259
  expect(nonce.bin_data.product_id).to eq(Braintree::CreditCard::ProductId::Unknown)
249
260
  end
250
261
 
@@ -0,0 +1,141 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
3
+
4
+ describe Braintree::PayPalPaymentResource do
5
+
6
+ describe "self.update" do
7
+ it "successfully updates a payment resource" do
8
+ nonce = nonce_for_paypal_account(
9
+ :intent => "order",
10
+ :payment_token => "fake-paypal-payment-token",
11
+ :payer_id => "fake-paypal-payer-id",
12
+ )
13
+
14
+ result = Braintree::PayPalPaymentResource.update(
15
+ :amount => BigDecimal("55.00"),
16
+ :amount_breakdown => {
17
+ :discount => BigDecimal("15.00"),
18
+ :handling => BigDecimal("0.00"),
19
+ :insurance => BigDecimal("5.00"),
20
+ :item_total => BigDecimal("45.00"),
21
+ :shipping => BigDecimal("10.00"),
22
+ :shipping_discount => BigDecimal("0.00"),
23
+ :tax_total => BigDecimal("10.00"),
24
+ },
25
+ :currency_iso_code => "USD",
26
+ :custom_field => "0437",
27
+ :description => "This is a test",
28
+ :line_items => [{
29
+ :description => "Shoes",
30
+ :image_url => "https://example.com/products/23434/pic.png",
31
+ :kind => "debit",
32
+ :name => "Name #1",
33
+ :product_code => "23434",
34
+ :quantity => "1",
35
+ :total_amount => BigDecimal("45.00"),
36
+ :unit_amount => BigDecimal("45.00"),
37
+ :unit_tax_amount => BigDecimal("10.00"),
38
+ :url => "https://example.com/products/23434",
39
+ }],
40
+ :order_id => "order-123456789",
41
+ :payee_email => "bt_buyer_us@paypal.com",
42
+ :payment_method_nonce => nonce,
43
+ :shipping => {
44
+ :country_name => "United States",
45
+ :country_code_alpha2 => "US",
46
+ :country_code_alpha3 => "USA",
47
+ :country_code_numeric => "484",
48
+ :extended_address => "Apt. #1",
49
+ :first_name => "John",
50
+ :international_phone => {
51
+ :country_code => "1",
52
+ :national_number => "4081111111",
53
+ },
54
+ :last_name => "Doe",
55
+ :locality => "Chicago",
56
+ :postal_code => "60618",
57
+ :region => "IL",
58
+ :street_address => "123 Division Street",
59
+ },
60
+ :shipping_options => [{
61
+ :amount => BigDecimal("10.00"),
62
+ :id => "option1",
63
+ :label => "fast",
64
+ :selected => true,
65
+ :type => "SHIPPING"
66
+ }],
67
+ )
68
+
69
+ expect(result.success?).to eq(true)
70
+ expect(result.payment_method_nonce).not_to be_nil
71
+ expect(result.payment_method_nonce.nonce).not_to be_nil
72
+ end
73
+
74
+ it "returns validation errors" do
75
+ nonce = nonce_for_paypal_account(
76
+ :intent => "order",
77
+ :payment_token => "fake-paypal-payment-token",
78
+ :payer_id => "fake-paypal-payer-id",
79
+ )
80
+
81
+ result = Braintree::PayPalPaymentResource.update(
82
+ :amount => BigDecimal("55.00"),
83
+ :amount_breakdown => {
84
+ :discount => BigDecimal("15.00"),
85
+ :handling => BigDecimal("0.00"),
86
+ :insurance => BigDecimal("5.00"),
87
+ :item_total => BigDecimal("45.00"),
88
+ :shipping => BigDecimal("10.00"),
89
+ :shipping_discount => BigDecimal("0.00"),
90
+ :tax_total => BigDecimal("10.00"),
91
+ },
92
+ :currency_iso_code => "USD",
93
+ :custom_field => "0437",
94
+ :description => "This is a test",
95
+ :line_items => [{
96
+ :description => "Shoes",
97
+ :image_url => "https://example.com/products/23434/pic.png",
98
+ :kind => "debit",
99
+ :name => "Name #1",
100
+ :product_code => "23434",
101
+ :quantity => "1",
102
+ :total_amount => BigDecimal("45.00"),
103
+ :unit_amount => BigDecimal("45.00"),
104
+ :unit_tax_amount => BigDecimal("10.00"),
105
+ :url => "https://example.com/products/23434",
106
+ }],
107
+ :order_id => "order-123456789",
108
+ :payee_email => "bt_buyer_us@paypal",
109
+ :payment_method_nonce => nonce,
110
+ :shipping => {
111
+ :country_name => "United States",
112
+ :country_code_alpha2 => "US",
113
+ :country_code_alpha3 => "USA",
114
+ :country_code_numeric => "484",
115
+ :extended_address => "Apt. #1",
116
+ :first_name => "John",
117
+ :international_phone => {
118
+ :country_code => "1",
119
+ :national_number => "4081111111",
120
+ },
121
+ :last_name => "Doe",
122
+ :locality => "Chicago",
123
+ :postal_code => "60618",
124
+ :region => "IL",
125
+ :street_address => "123 Division Street",
126
+ },
127
+ :shipping_options => [{
128
+ :amount => BigDecimal("10.00"),
129
+ :id => "option1",
130
+ :label => "fast",
131
+ :selected => true,
132
+ :type => "SHIPPING"
133
+ }],
134
+ )
135
+
136
+ expect(result.success?).to eq(false)
137
+ errors = result.errors.for(:paypal_payment_resource)
138
+ expect(errors.on(:payee_email)[0].code).to eq(Braintree::ErrorCodes::PayPalPaymentResource::InvalidEmail)
139
+ end
140
+ end
141
+ end
@@ -267,6 +267,19 @@ describe Braintree::Transaction do
267
267
  expect(result.transaction.credit_card_details.prepaid).to eq(Braintree::CreditCard::Prepaid::Yes)
268
268
  expect(result.transaction.payment_instrument_type).to eq(Braintree::PaymentInstrumentType::CreditCard)
269
269
  end
270
+
271
+ it "sets the prepaid_reloadable field if the card is prepaid reloadable" do
272
+ result = Braintree::Transaction.create(
273
+ :type => "sale",
274
+ :amount => 1_00,
275
+ :credit_card => {
276
+ :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::PrepaidReloadable,
277
+ :expiration_date => "05/2009"
278
+ },
279
+ )
280
+ expect(result.transaction.credit_card_details.prepaid_reloadable).to eq(Braintree::CreditCard::PrepaidReloadable::Yes)
281
+ expect(result.transaction.payment_instrument_type).to eq(Braintree::PaymentInstrumentType::CreditCard)
282
+ end
270
283
  end
271
284
 
272
285
  describe "sca_exemption" do
@@ -2183,6 +2196,7 @@ describe Braintree::Transaction do
2183
2196
  meta_checkout_card_details.last_4.should == "1881"
2184
2197
  meta_checkout_card_details.masked_number.should == "401288******1881"
2185
2198
  meta_checkout_card_details.prepaid.should == "No"
2199
+ meta_checkout_card_details.prepaid_reloadable.should == "Unknown"
2186
2200
  end
2187
2201
 
2188
2202
  it "can create a transaction with a fake meta checkout token nonce" do
@@ -2213,6 +2227,7 @@ describe Braintree::Transaction do
2213
2227
  meta_checkout_token_details.last_4.should == "1881"
2214
2228
  meta_checkout_token_details.masked_number.should == "401288******1881"
2215
2229
  meta_checkout_token_details.prepaid.should == "No"
2230
+ meta_checkout_token_details.prepaid_reloadable.should == "Unknown"
2216
2231
  end
2217
2232
 
2218
2233
  it "can create a transaction with a fake apple pay nonce" do
@@ -39,6 +39,7 @@ describe Braintree::ApplePayCard do
39
39
  :payment_instrument_name => nil,
40
40
  :payroll => "No",
41
41
  :prepaid => "No",
42
+ :prepaid_reloadable => "No",
42
43
  :product_id => "MAC",
43
44
  :source_card_last4 => "1234",
44
45
  :source_description => "blah",
@@ -266,4 +266,9 @@ describe Braintree::CreditCard do
266
266
  end
267
267
  end
268
268
  end
269
+
270
+ it "initializes prepaid reloadable correctly" do
271
+ card = Braintree::CreditCard._new(:gateway, {:prepaid_reloadable => "No"})
272
+ expect(card.prepaid_reloadable).to eq("No")
273
+ end
269
274
  end
@@ -0,0 +1,120 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Braintree::CustomerSessionGateway do
4
+ let(:gateway) { double(:gateway) }
5
+ let(:graphql_client) { double(:graphql_client) }
6
+ let(:customer_session_gateway) { Braintree::CustomerSessionGateway.new(gateway, graphql_client) }
7
+
8
+ describe "#create_customer_session" do
9
+ let(:input) do
10
+ {
11
+ :merchant_account_id => "merchant-account-id",
12
+ }
13
+ end
14
+
15
+ let(:response) do
16
+ {
17
+ data: {
18
+ createCustomerSession: {
19
+ sessionId: "session-id"
20
+ }
21
+ }
22
+ }
23
+ end
24
+
25
+
26
+ it "executes the createCustomerSession mutation" do
27
+ create_input = Braintree::CreateCustomerSessionInput.new(input)
28
+ expect(graphql_client).to receive(:query).with(Braintree::CustomerSessionGateway::CREATE_CUSTOMER_SESSION,
29
+ {
30
+ "input" => create_input.to_graphql_variables
31
+ }).and_return(response)
32
+
33
+ expect(Braintree::GraphQLClient).to receive(:get_validation_errors).with(response).and_return(nil)
34
+ result = customer_session_gateway.create_customer_session(create_input)
35
+ expect(result).to be_a(Braintree::SuccessfulResult)
36
+ expect(result.session_id).to eq("session-id")
37
+ end
38
+
39
+ it "returns an error result if there are validation errors" do
40
+ create_input = Braintree::CreateCustomerSessionInput.new(input)
41
+ errors = {:errors =>
42
+ [ {:attribute => "", :code => "123", :message => "error"} ]
43
+ }
44
+ expect(graphql_client).to receive(:query).and_return(response)
45
+ expect(Braintree::GraphQLClient).to receive(:get_validation_errors).with(response).and_return(errors)
46
+ result = customer_session_gateway.create_customer_session(create_input)
47
+ expect(result).to be_a(Braintree::ErrorResult)
48
+ expect(result.errors.first.message).to eq("error")
49
+ end
50
+
51
+ it "raises an UnexpectedError if there is a problem parsing the response" do
52
+ create_input = Braintree::CreateCustomerSessionInput.new(input)
53
+ badResonse = {:data => {}}
54
+ expect(graphql_client).to receive(:query).and_return(badResonse)
55
+ expect(Braintree::GraphQLClient).to receive(:get_validation_errors).with(badResonse).and_return(nil)
56
+ expect { customer_session_gateway.create_customer_session(create_input) }.to raise_error(Braintree::UnexpectedError)
57
+ end
58
+ end
59
+
60
+
61
+ describe "#update_customer_session" do
62
+ let(:input) do
63
+ {
64
+ :merchant_account_id => "merchant-account-id", :session_id => "session-id"
65
+ }
66
+ end
67
+ let(:response) do
68
+ {
69
+ data: {
70
+ updateCustomerSession: {
71
+ sessionId: "session-id"
72
+ }
73
+ }
74
+ }
75
+ end
76
+
77
+ it "executes the updateCustomerSession mutation" do
78
+ update_input = Braintree::UpdateCustomerSessionInput.new(input)
79
+ expect(graphql_client).to receive(:query).with(Braintree::CustomerSessionGateway::UPDATE_CUSTOMER_SESSION,
80
+ {
81
+ "input" => update_input.to_graphql_variables
82
+ }).and_return(response)
83
+ expect(Braintree::GraphQLClient).to receive(:get_validation_errors).with(response).and_return(nil)
84
+ result = customer_session_gateway.update_customer_session(update_input)
85
+ expect(result).to be_a(Braintree::SuccessfulResult)
86
+ expect(result.session_id).to eq("session-id")
87
+ end
88
+ end
89
+
90
+ describe "#get_customer_recommendations" do
91
+ let(:customer_recommendations_input) { double(:customer_recommendations_input, to_graphql_variables: {"sessionId" => "session_id", recommendations: ["PAYMENT_RECOMMENDATIONS"]}) }
92
+ let(:response) do
93
+ {
94
+ data: {
95
+ customerRecommendations: {
96
+ isInPayPalNetwork: true,
97
+ recommendations: {
98
+ paymentOptions: [
99
+ {paymentOption: "PAYPAL", recommendedPriority: 1}
100
+ ]
101
+ }
102
+ }
103
+ }
104
+ }
105
+ end
106
+
107
+ it "fetches customer recommendations" do
108
+ expected_variables = {"input" => {"sessionId" => "session_id", recommendations: ["PAYMENT_RECOMMENDATIONS"]}}
109
+ expect(graphql_client).to receive(:query).with(Braintree::CustomerSessionGateway::GET_CUSTOMER_RECOMMENDATIONS, expected_variables).and_return(response)
110
+ expect(Braintree::GraphQLClient).to receive(:get_validation_errors).with(response).and_return(nil)
111
+
112
+ result = customer_session_gateway.get_customer_recommendations(customer_recommendations_input)
113
+ expect(result).to be_a(Braintree::SuccessfulResult)
114
+ expect(result.customer_recommendations.is_in_paypal_network).to eq(true)
115
+ expect(result.customer_recommendations.recommendations.payment_options[0].payment_option).to eq("PAYPAL")
116
+ expect(result.customer_recommendations.recommendations.payment_options[0].recommended_priority).to eq(1)
117
+ end
118
+ end
119
+
120
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Braintree::GooglePayCard do
4
+ it "initializes prepaid reloadable correctly" do
5
+ card = Braintree::GooglePayCard._new(:gateway, {:prepaid_reloadable => "No"})
6
+ expect(card.prepaid_reloadable).to eq("No")
7
+ end
8
+ end
@@ -0,0 +1,81 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+
4
+ describe Braintree::CreateCustomerSessionInput do
5
+ let(:input_data) do
6
+ {
7
+ merchant_account_id: "merchant-account-id",
8
+ session_id: "session-id",
9
+ customer: {
10
+ email: "test@example.com" ,
11
+ },
12
+ domain: "example.com"
13
+ }
14
+ end
15
+
16
+ describe "#initialize" do
17
+ it "initializes with attributes" do
18
+ input = Braintree::CreateCustomerSessionInput.new(input_data)
19
+
20
+ expect(input.attrs).to eq(input_data.keys)
21
+ expect(input.merchant_account_id).to eq("merchant-account-id")
22
+ expect(input.session_id).to eq("session-id")
23
+ expect(input.customer).to be_a(Braintree::CustomerSessionInput)
24
+ expect(input.customer.email).to eq("test@example.com")
25
+ expect(input.domain).to eq("example.com")
26
+ end
27
+
28
+ it "handles nil customer" do
29
+ attributes = {merchant_account_id: "merchant-account-id"}
30
+ input = Braintree::CreateCustomerSessionInput.new(attributes)
31
+ expect(input.customer).to be_nil
32
+ end
33
+ end
34
+
35
+
36
+ describe "#inspect" do
37
+ it "returns a string representation of the object" do
38
+ input = Braintree::CreateCustomerSessionInput.new(input_data)
39
+ expected_string = "#<Braintree::CreateCustomerSessionInput merchant_account_id:\"merchant-account-id\" session_id:\"session-id\" customer:#<Braintree::CustomerSessionInput email:\"test@example.com\"> domain:\"example.com\">"
40
+ expect(input.inspect).to eq(expected_string)
41
+
42
+ end
43
+
44
+ it "handles nil values" do
45
+ attributes = {
46
+ merchant_account_id: "merchant-account-id",
47
+ session_id: nil,
48
+ customer: nil
49
+ }
50
+ input = Braintree::CreateCustomerSessionInput.new(attributes)
51
+ expected_string = "#<Braintree::CreateCustomerSessionInput merchant_account_id:\"merchant-account-id\" session_id:nil customer:nil>"
52
+
53
+ expect(input.inspect).to eq(expected_string)
54
+ end
55
+
56
+ end
57
+
58
+ describe "#to_graphql_variables" do
59
+ it "converts the input to graphql variables" do
60
+ input = Braintree::CreateCustomerSessionInput.new(input_data)
61
+ expected_variables = {
62
+ "merchantAccountId" => "merchant-account-id",
63
+ "sessionId" => "session-id",
64
+ "domain" => "example.com",
65
+ "customer" => {"email" => "test@example.com"}
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 = {merchant_account_id: "merchant-account-id"}
75
+ input = Braintree::CreateCustomerSessionInput.new(attributes)
76
+ expected_variables = {"merchantAccountId" => "merchant-account-id"}
77
+
78
+ expect(input.to_graphql_variables).to eq(expected_variables)
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,110 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+
4
+ describe Braintree::CustomerRecommendationsInput do
5
+ let(:input_data) do
6
+ {
7
+ merchant_account_id: "merchant-account-id",
8
+ session_id: "session-id",
9
+ recommendations: ["PAYMENT_RECOMMENDATIONS"],
10
+ customer: {email: "test@example.com"}
11
+ }
12
+ end
13
+ describe "#initialize" do
14
+ it "initializes with attributes" do
15
+ input = Braintree::CustomerRecommendationsInput.new(input_data)
16
+
17
+ expect(input.attrs).to eq(input_data.keys)
18
+ expect(input.merchant_account_id).to eq("merchant-account-id")
19
+ expect(input.session_id).to eq("session-id")
20
+ expect(input.customer).to be_a(Braintree::CustomerSessionInput)
21
+ expect(input.recommendations[0]).to eq("PAYMENT_RECOMMENDATIONS")
22
+ end
23
+
24
+ it "disallows nil session id" do
25
+ attributes = {
26
+ merchant_account_id: "merchant-account-id",
27
+ recommendations: ["PAYMENT_RECOMMENDATIONS"],
28
+ }
29
+ expect do
30
+ Braintree::CustomerRecommendationsInput.new(attributes)
31
+ end.to raise_error(ArgumentError, "Expected hash to contain a :session_id")
32
+ end
33
+
34
+ it "disallows nil recommendations" do
35
+ attributes = {
36
+ merchant_account_id: "merchant-account-id",
37
+ session_id: "session-id",
38
+ }
39
+ expect do
40
+ Braintree::CustomerRecommendationsInput.new(attributes)
41
+ end.to raise_error(ArgumentError, "Expected hash to contain a :recommendations")
42
+ end
43
+
44
+ it "handles nil customer" do
45
+ attributes = {
46
+ merchant_account_id: "merchant-account-id",
47
+ session_id: "session-id",
48
+ recommendations: ["PAYMENT_RECOMMENDATIONS"],
49
+ }
50
+ input = Braintree::CustomerRecommendationsInput.new(attributes)
51
+
52
+ expect(input.customer).to be_nil
53
+ end
54
+ end
55
+
56
+
57
+ describe "#inspect" do
58
+ it "returns a string representation of the object" do
59
+ input = Braintree::CustomerRecommendationsInput.new(input_data)
60
+ expected_string = "#<Braintree::CustomerRecommendationsInput merchant_account_id:\"merchant-account-id\" session_id:\"session-id\" recommendations:[\"PAYMENT_RECOMMENDATIONS\"] customer:#<Braintree::CustomerSessionInput email:\"test@example.com\">>"
61
+ expect(input.inspect).to eq(expected_string)
62
+
63
+ end
64
+
65
+ it "handles nil values" do
66
+ attributes = {
67
+ merchant_account_id: "merchant-account-id",
68
+ session_id: "session-id",
69
+ recommendations: ["PAYMENT_RECOMMENDATIONS"],
70
+ }
71
+ input = Braintree::CustomerRecommendationsInput.new(attributes)
72
+ expected_string = "#<Braintree::CustomerRecommendationsInput merchant_account_id:\"merchant-account-id\" session_id:\"session-id\" recommendations:[\"PAYMENT_RECOMMENDATIONS\"]>"
73
+
74
+ expect(input.inspect).to eq(expected_string)
75
+ end
76
+
77
+ end
78
+
79
+ describe "#to_graphql_variables" do
80
+ it "converts the input to graphql variables" do
81
+ input = Braintree::CustomerRecommendationsInput.new(input_data)
82
+ expected_variables = {
83
+ "merchantAccountId" => "merchant-account-id",
84
+ "sessionId" => "session-id",
85
+ "customer" => {"email" => "test@example.com"},
86
+ "recommendations" => ["PAYMENT_RECOMMENDATIONS"],
87
+ }
88
+
89
+ expect(input.to_graphql_variables).to eq(expected_variables)
90
+ end
91
+
92
+ it "handles nil values" do
93
+ attributes = {
94
+ merchant_account_id: "merchant-account-id",
95
+ session_id: "session-id",
96
+ recommendations: ["PAYMENT_RECOMMENDATIONS"],
97
+ }
98
+ input = Braintree::CustomerRecommendationsInput.new(attributes)
99
+
100
+ expected_variables = {
101
+ "merchantAccountId" => "merchant-account-id",
102
+ "sessionId" => "session-id",
103
+ "recommendations" => ["PAYMENT_RECOMMENDATIONS"],
104
+ }
105
+
106
+ expect(input.to_graphql_variables).to eq(expected_variables)
107
+ end
108
+ end
109
+
110
+ end
@@ -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