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
@@ -30,5 +30,21 @@ module Braintree
30
30
  body = Zlib::GzipReader.new(StringIO.new(body)).read if response.header["Content-Encoding"] == "gzip"
31
31
  JSON.parse(body, :symbolize_names => true)
32
32
  end
33
+
34
+ def self.get_validation_errors(response)
35
+ return nil unless response.key?(:errors) && response[:errors].is_a?(Array)
36
+ validation_errors = response[:errors].map do |error|
37
+ {
38
+ :attribute => "",
39
+ :code => get_validation_error_code(error),
40
+ :message => error[:message]
41
+ }
42
+ end
43
+ {errors: validation_errors}
44
+ end
45
+
46
+ def self.get_validation_error_code(error)
47
+ error[:extensions] && error[:extensions][:legacyCode] rescue nil
48
+ end
33
49
  end
34
50
  end
@@ -22,6 +22,7 @@ module Braintree
22
22
  attr_reader :last_4
23
23
  attr_reader :payroll
24
24
  attr_reader :prepaid
25
+ attr_reader :prepaid_reloadable
25
26
  attr_reader :product_id
26
27
  attr_reader :subscriptions
27
28
  attr_reader :token
@@ -74,11 +75,11 @@ module Braintree
74
75
 
75
76
  def self._attributes # :nodoc:
76
77
  [
77
- :bin, :card_type, :cardholder_name, :created_at,
78
- :customer_id, :customer_location, :expiration_month, :expiration_year,
79
- :last_4, :token, :updated_at, :prepaid, :payroll, :product_id,
80
- :commercial, :debit, :durbin_regulated, :healthcare,
81
- :country_of_issuance, :issuing_bank, :image_url, :container_id
78
+ :bin, :card_type, :cardholder_name, :commercial,
79
+ :container_id, :country_of_issuance, :created_at, :customer_id,
80
+ :customer_location, :debit, :durbin_regulated, :expiration_month,
81
+ :expiration_year, :healthcare, :image_url, :issuing_bank, :last_4, :payroll, :prepaid,
82
+ :prepaid_reloadable, :product_id, :token, :updated_at
82
83
  ]
83
84
  end
84
85
 
@@ -24,6 +24,7 @@ module Braintree
24
24
  attr_reader :last_4
25
25
  attr_reader :payroll
26
26
  attr_reader :prepaid
27
+ attr_reader :prepaid_reloadable
27
28
  attr_reader :product_id
28
29
  attr_reader :token
29
30
  attr_reader :unique_number_identifier
@@ -73,11 +74,11 @@ module Braintree
73
74
 
74
75
  def self._attributes # :nodoc:
75
76
  [
76
- :bin, :card_type, :cardholder_name, :created_at,
77
- :customer_id, :customer_location, :expiration_month, :expiration_year,
78
- :last_4, :token, :updated_at, :prepaid, :payroll, :product_id,
79
- :commercial, :debit, :durbin_regulated, :healthcare, :ecommerce_indicator,
80
- :country_of_issuance, :issuing_bank, :image_url, :container_id, :cryptogram
77
+ :bin, :card_type, :cardholder_name, :commercial, :container_id, :country_of_issuance,
78
+ :created_at, :cryptogram, :customer_id, :customer_location, :debit, :durbin_regulated,
79
+ :ecommerce_indicator, :expiration_month, :expiration_year, :healthcare, :image_url,
80
+ :issuing_bank, :last_4, :payroll, :prepaid, :prepaid_reloadable, :product_id, :token,
81
+ :updated_at
81
82
  ]
82
83
  end
83
84
 
@@ -0,0 +1,22 @@
1
+ module Braintree
2
+ class PayPalPaymentResource
3
+ include BaseModule
4
+
5
+ def self.update(*args)
6
+ Configuration.gateway.paypal_payment_resource.update(*args)
7
+ end
8
+
9
+ class << self
10
+ protected :new
11
+ def _new(*args)
12
+ self.new(*args)
13
+ end
14
+ end
15
+
16
+ def initialize(gateway, attributes)
17
+ @gateway = gateway
18
+ set_instance_variables_from_hash(attributes)
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,36 @@
1
+ module Braintree
2
+ class PayPalPaymentResourceGateway
3
+ include BaseModule
4
+
5
+ def initialize(gateway)
6
+ @gateway = gateway
7
+ @config = gateway.config
8
+ @config.assert_has_access_token_or_keys
9
+ end
10
+
11
+ def update(attributes)
12
+ Util.verify_keys(PayPalPaymentResourceGateway._update_signature, attributes)
13
+ response = @config.http.put("#{@config.base_merchant_path}/paypal/payment_resource", :paypal_payment_resource => attributes)
14
+ if response[:payment_method_nonce]
15
+ SuccessfulResult.new(:payment_method_nonce => PaymentMethodNonce._new(@gateway, response[:payment_method_nonce]))
16
+ elsif response[:api_error_response]
17
+ ErrorResult.new(@gateway, response[:api_error_response])
18
+ else
19
+ raise UnexpectedError, "expected :paypal_payment_resource or :api_error_response"
20
+ end
21
+ end
22
+
23
+ def self._update_signature
24
+ [
25
+ :amount,
26
+ {:amount_breakdown => [:discount, :handling, :insurance, :item_total, :shipping, :shipping_discount, :tax_total]},
27
+ :currency_iso_code, :custom_field, :description,
28
+ {:line_items => [:description, :image_url, :kind, :name, :product_code, :quantity, :total_amount, :unit_amount, :unit_tax_amount, :url]},
29
+ :order_id, :payee_email, :payment_method_nonce,
30
+ {:shipping => [:country_name, :country_code_alpha2, :country_code_alpha3, :country_code_numeric, :extended_address, :first_name, {:international_phone => [:country_code, :national_number]},
31
+ :last_name, :locality, :postal_code, :region, :street_address]},
32
+ {:shipping_options => [:amount, :id, :label, :selected, :type]}
33
+ ]
34
+ end
35
+ end
36
+ end
@@ -24,6 +24,8 @@ module Braintree
24
24
  attr_reader :supported_networks
25
25
  attr_reader :transaction
26
26
  attr_reader :us_bank_account_verification
27
+ attr_reader :session_id
28
+ attr_reader :customer_recommendations
27
29
 
28
30
  def initialize(attributes = {})
29
31
  @attrs = attributes.keys
@@ -3,6 +3,7 @@ module Braintree
3
3
  module CreditCardNumbers
4
4
  module CardTypeIndicators
5
5
  Prepaid = "4111111111111210"
6
+ PrepaidReloadable = "4229989900000002"
6
7
  Commercial = "4111111111131010"
7
8
  Payroll = "4111111114101010"
8
9
  Healthcare = "4111111510101010"
@@ -21,6 +21,7 @@ module Braintree
21
21
  attr_reader :payment_instrument_name
22
22
  attr_reader :payroll
23
23
  attr_reader :prepaid
24
+ attr_reader :prepaid_reloadable
24
25
  attr_reader :product_id
25
26
  attr_reader :source_card_last4
26
27
  attr_reader :source_description
@@ -20,6 +20,7 @@ module Braintree
20
20
  attr_reader :last_4
21
21
  attr_reader :payroll
22
22
  attr_reader :prepaid
23
+ attr_reader :prepaid_reloadable
23
24
  attr_reader :product_id
24
25
  attr_reader :token
25
26
  attr_reader :unique_number_identifier
@@ -34,23 +35,24 @@ module Braintree
34
35
 
35
36
  def inspect
36
37
  attr_order = [
37
- :token,
38
38
  :bin,
39
- :last_4,
40
39
  :card_type,
41
- :expiration_date,
42
40
  :cardholder_name,
41
+ :commercial,
42
+ :country_of_issuance,
43
43
  :customer_location,
44
- :prepaid,
45
- :healthcare,
46
- :durbin_regulated,
47
44
  :debit,
48
- :commercial,
45
+ :durbin_regulated,
46
+ :expiration_date,
47
+ :healthcare,
48
+ :image_url,
49
+ :issuing_bank,
50
+ :last_4,
49
51
  :payroll,
52
+ :prepaid,
53
+ :prepaid_reloadable,
50
54
  :product_id,
51
- :country_of_issuance,
52
- :issuing_bank,
53
- :image_url,
55
+ :token,
54
56
  :unique_number_identifier,
55
57
  ]
56
58
 
@@ -5,27 +5,28 @@ module Braintree
5
5
 
6
6
  attr_reader :bin
7
7
  attr_reader :card_type
8
+ attr_reader :commercial
9
+ attr_reader :country_of_issuance
10
+ attr_reader :debit
11
+ attr_reader :durbin_regulated
8
12
  attr_reader :expiration_month
9
13
  attr_reader :expiration_year
14
+ attr_reader :global_id
10
15
  attr_reader :google_transaction_id
16
+ attr_reader :healthcare
11
17
  attr_reader :image_url
18
+ attr_reader :issuing_bank
12
19
  attr_reader :last_4
20
+ attr_reader :payroll
21
+ attr_reader :prepaid
22
+ attr_reader :prepaid_reloadable
23
+ attr_reader :product_id
13
24
  attr_reader :source_card_last_4
14
25
  attr_reader :source_card_type
15
26
  attr_reader :source_description
16
27
  attr_reader :token
17
28
  attr_reader :virtual_card_last_4
18
29
  attr_reader :virtual_card_type
19
- attr_reader :prepaid
20
- attr_reader :healthcare
21
- attr_reader :debit
22
- attr_reader :durbin_regulated
23
- attr_reader :commercial
24
- attr_reader :payroll
25
- attr_reader :issuing_bank
26
- attr_reader :country_of_issuance
27
- attr_reader :product_id
28
- attr_reader :global_id
29
30
 
30
31
  def initialize(attributes)
31
32
  set_instance_variables_from_hash attributes unless attributes.nil?
@@ -22,6 +22,7 @@ module Braintree
22
22
  attr_reader :last_4
23
23
  attr_reader :payroll
24
24
  attr_reader :prepaid
25
+ attr_reader :prepaid_reloadable
25
26
  attr_reader :product_id
26
27
  attr_reader :token
27
28
  attr_reader :unique_number_identifier
@@ -36,8 +37,10 @@ module Braintree
36
37
  end
37
38
 
38
39
  def inspect
39
- attr_order = [:token, :bin, :last_4, :card_type, :expiration_date, :cardholder_name, :customer_location, :prepaid,
40
- :healthcare, :durbin_regulated, :debit, :commercial, :payroll, :product_id, :country_of_issuance, :issuing_bank, :image_url, :container_id]
40
+ attr_order = [
41
+ :bin, :card_type, :cardholder_name, :commercial, :container_id, :country_of_issuance,
42
+ :customer_location, :debit, :durbin_regulated, :expiration_date, :healthcare, :image_url,
43
+ :issuing_bank, :last_4, :payroll, :prepaid, :prepaid_reloadable, :product_id, :token]
41
44
  formatted_attrs = attr_order.map do |attr|
42
45
  "#{attr}: #{send(attr).inspect}"
43
46
  end
@@ -24,6 +24,7 @@ module Braintree
24
24
  attr_reader :last_4
25
25
  attr_reader :payroll
26
26
  attr_reader :prepaid
27
+ attr_reader :prepaid_reloadable
27
28
  attr_reader :product_id
28
29
  attr_reader :token
29
30
  attr_reader :unique_number_identifier
@@ -38,8 +39,11 @@ module Braintree
38
39
  end
39
40
 
40
41
  def inspect
41
- attr_order = [:container_id, :cryptogram, :ecommerce_indicator, :token, :bin, :last_4, :card_type, :expiration_date, :cardholder_name, :customer_location, :prepaid,
42
- :healthcare, :durbin_regulated, :debit, :commercial, :payroll, :product_id, :country_of_issuance, :issuing_bank, :is_network_tokenized, :image_url]
42
+ attr_order = [
43
+ :bin, :card_type, :cardholder_name, :commercial, :container_id, :country_of_issuance,
44
+ :cryptogram, :customer_location, :debit, :durbin_regulated, :ecommerce_indicator,
45
+ :expiration_date, :healthcare, :image_url, :is_network_tokenized, :issuing_bank, :last_4,
46
+ :payroll, :prepaid, :prepaid_reloadable, :product_id, :token]
43
47
  formatted_attrs = attr_order.map do |attr|
44
48
  "#{attr}: #{send(attr).inspect}"
45
49
  end
@@ -20,6 +20,7 @@ module Braintree
20
20
  attr_reader :last_4
21
21
  attr_reader :payroll
22
22
  attr_reader :prepaid
23
+ attr_reader :prepaid_reloadable
23
24
  attr_reader :product_id
24
25
  attr_reader :token
25
26
 
@@ -32,8 +33,10 @@ module Braintree
32
33
  end
33
34
 
34
35
  def inspect
35
- attr_order = [:token, :bin, :last_4, :card_type, :expiration_date, :cardholder_name, :customer_location, :prepaid,
36
- :healthcare, :durbin_regulated, :debit, :commercial, :payroll, :product_id, :country_of_issuance, :issuing_bank, :image_url, :call_id]
36
+ attr_order = [
37
+ :bin, :call_id, :card_type, :cardholder_name, :commercial, :country_of_issuance, :customer_location,
38
+ :debit, :durbin_regulated, :expiration_date, :healthcare, :image_url, :issuing_bank, :last_4, :payroll,
39
+ :prepaid, :prepaid_reloadable, :product_id, :token]
37
40
  formatted_attrs = attr_order.map do |attr|
38
41
  "#{attr}: #{send(attr).inspect}"
39
42
  end
@@ -1,7 +1,7 @@
1
1
  module Braintree
2
2
  module Version
3
3
  Major = 4
4
- Minor = 24
4
+ Minor = 26
5
5
  Tiny = 0
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Tiny}"
@@ -23,6 +23,7 @@ module Braintree
23
23
  attr_reader :last_4
24
24
  attr_reader :payroll
25
25
  attr_reader :prepaid
26
+ attr_reader :prepaid_reloadable
26
27
  attr_reader :product_id
27
28
  attr_reader :subscriptions
28
29
  attr_reader :token
@@ -75,11 +76,10 @@ module Braintree
75
76
 
76
77
  def self._attributes
77
78
  [
78
- :billing_address, :bin, :card_type, :cardholder_name, :created_at,
79
- :customer_id, :customer_location, :expiration_month, :expiration_year,
80
- :last_4, :token, :updated_at, :prepaid, :payroll, :product_id,
81
- :commercial, :debit, :durbin_regulated, :healthcare,
82
- :country_of_issuance, :issuing_bank, :image_url, :call_id
79
+ :bin, :billing_address, :card_type, :cardholder_name, :commercial, :container_id, :country_of_issuance,
80
+ :created_at, :customer_id, :customer_location, :debit, :durbin_regulated, :expiration_month,
81
+ :expiration_year, :healthcare, :image_url, :issuing_bank, :last_4, :payroll, :prepaid,
82
+ :prepaid_reloadable, :product_id, :token, :updated_at
83
83
  ]
84
84
  end
85
85
 
data/lib/braintree.rb CHANGED
@@ -51,6 +51,7 @@ require "braintree/customer"
51
51
  require "braintree/customer_gateway"
52
52
  require "braintree/granted_payment_instrument_update"
53
53
  require "braintree/customer_search"
54
+ require "braintree/customer_session_gateway"
54
55
  require "braintree/descriptor"
55
56
  require "braintree/digest"
56
57
  require "braintree/discount"
@@ -75,6 +76,16 @@ require "braintree/exchange_rate_quote_input"
75
76
  require "braintree/exchange_rate_quote_response"
76
77
  require "braintree/exchange_rate_quote_request"
77
78
  require "braintree/gateway"
79
+ require "braintree/graphql/enums/recommendations"
80
+ require "braintree/graphql/enums/recommended_payment_option"
81
+ require "braintree/graphql/inputs/create_customer_session_input"
82
+ require "braintree/graphql/inputs/customer_recommendations_input"
83
+ require "braintree/graphql/inputs/customer_session_input"
84
+ require "braintree/graphql/inputs/phone_input"
85
+ require "braintree/graphql/inputs/update_customer_session_input"
86
+ require "braintree/graphql/types/customer_recommendations_payload"
87
+ require "braintree/graphql/types/payment_options"
88
+ require "braintree/graphql/unions/customer_recommendations"
78
89
  require "braintree/graphql_client"
79
90
  require "braintree/google_pay_card"
80
91
  require "braintree/local_payment_completed"
@@ -106,6 +117,8 @@ require "braintree/payment_method_nonce_gateway"
106
117
  require "braintree/payment_method_parser"
107
118
  require "braintree/paypal_account"
108
119
  require "braintree/paypal_account_gateway"
120
+ require "braintree/paypal_payment_resource"
121
+ require "braintree/paypal_payment_resource_gateway"
109
122
  require "braintree/plan"
110
123
  require "braintree/plan_gateway"
111
124
  require "braintree/processor_response_types"
@@ -449,6 +449,18 @@ describe Braintree::CreditCard do
449
449
  expect(credit_card.prepaid).to eq(Braintree::CreditCard::Prepaid::Yes)
450
450
  end
451
451
 
452
+ it "sets the prepaid reloadable field if the card is prepaid reloadable" do
453
+ customer = Braintree::Customer.create!
454
+ result = Braintree::CreditCard.create(
455
+ :customer_id => customer.id,
456
+ :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::PrepaidReloadable,
457
+ :expiration_date => "05/2014",
458
+ :options => {:verify_card => true},
459
+ )
460
+ credit_card = result.credit_card
461
+ expect(credit_card.prepaid_reloadable).to eq(Braintree::CreditCard::PrepaidReloadable::Yes)
462
+ end
463
+
452
464
  it "sets the healthcare field if the card is healthcare" do
453
465
  customer = Braintree::Customer.create!
454
466
  result = Braintree::CreditCard.create(
@@ -322,6 +322,30 @@ describe Braintree::CreditCardVerification, "search" do
322
322
  found_verification = Braintree::CreditCardVerification.find(verification_id)
323
323
  expect(found_verification.credit_card[:prepaid]).to eq(Braintree::CreditCard::Prepaid::Yes)
324
324
  end
325
+
326
+ it "returns prepaid_reloadable on a prepaid card" do
327
+ cardholder_name = "Tom #{rand(1_000_000)} Smith"
328
+
329
+ Braintree::Customer.create(
330
+ :credit_card => {
331
+ :cardholder_name => cardholder_name,
332
+ :expiration_date => "05/2012",
333
+ :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::PrepaidReloadable,
334
+ :cvv => "200",
335
+ :options => {
336
+ :verify_card => true
337
+ }
338
+ })
339
+
340
+ search_results = Braintree::CreditCardVerification.search do |search|
341
+ search.credit_card_cardholder_name.is cardholder_name
342
+ end
343
+
344
+ verification_id = search_results.first.id
345
+
346
+ found_verification = Braintree::CreditCardVerification.find(verification_id)
347
+ expect(found_verification.credit_card[:prepaid_reloadable]).to eq(Braintree::CreditCard::PrepaidReloadable::Yes)
348
+ end
325
349
  end
326
350
  end
327
351
 
@@ -0,0 +1,143 @@
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::CustomerSessionGateway do
5
+ let(:gateway) do
6
+ Braintree::Gateway.new(
7
+ :environment => :development,
8
+ :merchant_id => "pwpp_multi_account_merchant",
9
+ :public_key => "pwpp_multi_account_merchant_public_key",
10
+ :private_key => "pwpp_multi_account_merchant_private_key",
11
+ )
12
+ end
13
+
14
+ describe "create" do
15
+ it "can create customer session without email and phone" do
16
+ input = Braintree::CreateCustomerSessionInput.new(merchant_account_id: "usd_pwpp_multi_account_merchant_account")
17
+ result = gateway.customer_session.create_customer_session(input)
18
+ expect(result.success?).to eq(true)
19
+ expect(result.session_id).not_to be_nil
20
+ end
21
+
22
+ it "can can create customer session with merchant provided session id" do
23
+ merchant_session_id = "11EF-A1E7-A5F5EE5C-A2E5-AFD2801469FC"
24
+ input = Braintree::CreateCustomerSessionInput.new(
25
+ session_id: merchant_session_id,
26
+ )
27
+ result = gateway.customer_session.create_customer_session(input)
28
+ expect(result.success?).to eq(true)
29
+ expect(result.session_id).to eq(merchant_session_id)
30
+ end
31
+
32
+ it "can create customer session with API-derived session id" do
33
+ input = Braintree::CreateCustomerSessionInput.new({})
34
+ result = gateway.customer_session.create_customer_session(input)
35
+ expect(result.success?).to eq(true)
36
+ expect(result.session_id).not_to be_nil
37
+ end
38
+
39
+ it "cannot create duplicate customer session" do
40
+ existing_session_id = "11EF-34BC-2702904B-9026-C3ECF4BAC765"
41
+ input = Braintree::CreateCustomerSessionInput.new(
42
+ session_id: existing_session_id,
43
+ )
44
+ result = gateway.customer_session.create_customer_session(input)
45
+ expect(result.success?).to eq(false)
46
+ expect(result.errors.first.message).to include("Session IDs must be unique per merchant.")
47
+ end
48
+ end
49
+
50
+ describe "update" do
51
+ it "can update a customer session" do
52
+ session_id = "11EF-A1E7-A5F5EE5C-A2E5-AFD2801469FC"
53
+ create_input = Braintree::CreateCustomerSessionInput.new(
54
+ merchant_account_id: "usd_pwpp_multi_account_merchant_account",
55
+ session_id: session_id,
56
+ )
57
+
58
+ gateway.customer_session.create_customer_session(create_input)
59
+
60
+ customer = build_customer_session_input("PR5_test@example.com", "4085005005")
61
+
62
+ update_input = Braintree::UpdateCustomerSessionInput.new(
63
+ session_id: session_id,
64
+ customer: customer,
65
+ )
66
+
67
+ result = gateway.customer_session.update_customer_session(update_input)
68
+
69
+ expect(result.success?).to eq(true)
70
+ expect(result.session_id).to eq(session_id)
71
+
72
+ end
73
+
74
+ it "cannot update a non-existent customer session" do
75
+ session_id = "11EF-34BC-2702904B-9026-C3ECF4BAC765"
76
+ customer = build_customer_session_input("PR9_test@example.com", "4085005009")
77
+ update_input = Braintree::UpdateCustomerSessionInput.new(
78
+ session_id: session_id,
79
+ customer: customer,
80
+ )
81
+
82
+ result = gateway.customer_session.update_customer_session(update_input)
83
+
84
+ expect(result.success?).to eq(false)
85
+ expect(result.errors.first.message).to include("does not exist")
86
+ end
87
+ end
88
+
89
+ describe "customer recommendations" do
90
+ it "can get customer recommendations" do
91
+ customer = build_customer_session_input("PR5_test@example.com", "4085005005")
92
+ recommendations = [Braintree::Recommendations::PAYMENT_RECOMMENDATIONS]
93
+ customer_recommendations_input = Braintree::CustomerRecommendationsInput.new(
94
+ session_id: "11EF-A1E7-A5F5EE5C-A2E5-AFD2801469FC",
95
+ recommendations: recommendations,
96
+ customer: customer,
97
+ )
98
+ result = gateway.customer_session.get_customer_recommendations(customer_recommendations_input)
99
+
100
+ expect(result.success?).to eq(true)
101
+ payload = result.customer_recommendations
102
+ expect(payload.is_in_paypal_network).to eq(true)
103
+ payment_options = payload.recommendations.payment_options
104
+ expect(payment_options[0].payment_option).to eq(Braintree::RecommendedPaymentOption::PAYPAL)
105
+ expect(payment_options[0].recommended_priority).to equal(1)
106
+ end
107
+
108
+ it "cannot get customer recommendations for non-existent session" do
109
+ customer = build_customer_session_input("PR9_test@example.com", "4085005009")
110
+ recommendations = [Braintree::Recommendations::PAYMENT_RECOMMENDATIONS]
111
+ customer_recommendations_input = Braintree::CustomerRecommendationsInput.new(
112
+ session_id: "11EF-34BC-2702904B-9026-C3ECF4BAC765",
113
+ recommendations: recommendations,
114
+ customer: customer,
115
+ )
116
+ result = gateway.customer_session.get_customer_recommendations(customer_recommendations_input)
117
+
118
+ expect(result.success?).to eq(false)
119
+ expect(result.errors.first.message).to include("does not exist")
120
+ end
121
+ end
122
+
123
+ private
124
+
125
+ def build_customer_session(session_id = nil)
126
+ customer = build_customer_session_input("PR1_test@example.com", "4085005002")
127
+
128
+ input = session_id ? CreateCustomerSessionInput.new(customer: customer, session_id: session_id) : CreateCustomerSessionInput.new(customer => customer)
129
+ @gateway.customer_session.create_customer_session(input)
130
+ end
131
+
132
+ def build_customer_session_input(email, phone_number)
133
+ {
134
+ email: email,
135
+ device_fingerprint_id: "test",
136
+ phone: {country_phone_code: "1", phone_number: phone_number},
137
+ paypal_app_installed: true,
138
+ venmo_app_installed: true,
139
+ user_agent: "Mozilla"
140
+ }
141
+ end
142
+
143
+ end
@@ -991,18 +991,19 @@ describe Braintree::Customer do
991
991
  expect(found_customer.apple_pay_cards).not_to be_nil
992
992
  apple_pay_card = found_customer.apple_pay_cards.first
993
993
  expect(apple_pay_card).to be_a Braintree::ApplePayCard
994
- expect(apple_pay_card.token).not_to be_nil
995
- expect(apple_pay_card.expiration_year).not_to be_nil
996
- expect(apple_pay_card.payment_instrument_name).to eq("AmEx 41002")
997
994
  expect(apple_pay_card.commercial).not_to be_nil
998
995
  expect(apple_pay_card.country_of_issuance).not_to be_nil
999
996
  expect(apple_pay_card.debit).not_to be_nil
1000
997
  expect(apple_pay_card.durbin_regulated).not_to be_nil
998
+ expect(apple_pay_card.expiration_year).not_to be_nil
1001
999
  expect(apple_pay_card.healthcare).not_to be_nil
1002
1000
  expect(apple_pay_card.issuing_bank).not_to be_nil
1001
+ expect(apple_pay_card.payment_instrument_name).to eq("AmEx 41002")
1003
1002
  expect(apple_pay_card.payroll).not_to be_nil
1004
1003
  expect(apple_pay_card.prepaid).not_to be_nil
1004
+ expect(apple_pay_card.prepaid_reloadable).not_to be_nil
1005
1005
  expect(apple_pay_card.product_id).not_to be_nil
1006
+ expect(apple_pay_card.token).not_to be_nil
1006
1007
  end
1007
1008
 
1008
1009
  it "returns associated google pay proxy cards" do
@@ -1016,18 +1017,19 @@ describe Braintree::Customer do
1016
1017
  expect(found_customer.payment_methods.size).to eq(1)
1017
1018
  google_pay_card = found_customer.google_pay_cards.first
1018
1019
  expect(google_pay_card).to be_a Braintree::GooglePayCard
1019
- expect(google_pay_card.token).not_to be_nil
1020
- expect(google_pay_card.expiration_year).not_to be_nil
1021
- expect(google_pay_card.is_network_tokenized?).to eq(false)
1022
1020
  expect(google_pay_card.commercial).not_to be_nil
1023
1021
  expect(google_pay_card.country_of_issuance).not_to be_nil
1024
1022
  expect(google_pay_card.debit).not_to be_nil
1025
1023
  expect(google_pay_card.durbin_regulated).not_to be_nil
1024
+ expect(google_pay_card.expiration_year).not_to be_nil
1026
1025
  expect(google_pay_card.healthcare).not_to be_nil
1026
+ expect(google_pay_card.is_network_tokenized?).to eq(false)
1027
1027
  expect(google_pay_card.issuing_bank).not_to be_nil
1028
1028
  expect(google_pay_card.payroll).not_to be_nil
1029
1029
  expect(google_pay_card.prepaid).not_to be_nil
1030
+ expect(google_pay_card.prepaid_reloadable).not_to be_nil
1030
1031
  expect(google_pay_card.product_id).not_to be_nil
1032
+ expect(google_pay_card.token).not_to be_nil
1031
1033
  end
1032
1034
 
1033
1035
  it "returns associated google pay network tokens" do
@@ -1052,6 +1054,7 @@ describe Braintree::Customer do
1052
1054
  expect(google_pay_card.issuing_bank).not_to be_nil
1053
1055
  expect(google_pay_card.payroll).not_to be_nil
1054
1056
  expect(google_pay_card.prepaid).not_to be_nil
1057
+ expect(google_pay_card.prepaid_reloadable).not_to be_nil
1055
1058
  expect(google_pay_card.product_id).not_to be_nil
1056
1059
  end
1057
1060
 
@@ -1912,4 +1915,17 @@ describe Braintree::Customer do
1912
1915
  end
1913
1916
  end
1914
1917
  end
1918
+
1919
+ it "returns prepaid_reloadable from VisaCheckoutCard" do
1920
+ result = Braintree::Customer.create(
1921
+ :payment_method_nonce => Braintree::Test::Nonce::VisaCheckoutVisa,
1922
+ )
1923
+ expect(result.success?).to eq(true)
1924
+
1925
+ found_customer = Braintree::Customer.find(result.customer.id)
1926
+ expect(found_customer.visa_checkout_cards).not_to be_nil
1927
+ visa_checkout_card = found_customer.visa_checkout_cards.first
1928
+ expect(visa_checkout_card).to be_a Braintree::VisaCheckoutCard
1929
+ expect(visa_checkout_card.prepaid_reloadable).not_to be_nil
1930
+ end
1915
1931
  end