braintree 4.26.0 → 4.28.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 (86) hide show
  1. checksums.yaml +4 -4
  2. data/lib/braintree/apple_pay_card.rb +4 -0
  3. data/lib/braintree/bin_data.rb +7 -2
  4. data/lib/braintree/configuration.rb +1 -1
  5. data/lib/braintree/credit_card.rb +11 -5
  6. data/lib/braintree/credit_card_gateway.rb +1 -0
  7. data/lib/braintree/credit_card_verification_gateway.rb +1 -0
  8. data/lib/braintree/customer_session_gateway.rb +11 -10
  9. data/lib/braintree/error_codes.rb +5 -104
  10. data/lib/braintree/google_pay_card.rb +4 -0
  11. data/lib/braintree/graphql/enums/recommendations.rb +2 -0
  12. data/lib/braintree/graphql/enums/recommended_payment_option.rb +2 -0
  13. data/lib/braintree/graphql/inputs/create_customer_session_input.rb +10 -1
  14. data/lib/braintree/graphql/inputs/customer_recommendations_input.rb +7 -8
  15. data/lib/braintree/graphql/inputs/customer_session_input.rb +6 -0
  16. data/lib/braintree/graphql/inputs/monetary_amount_input.rb +28 -0
  17. data/lib/braintree/graphql/inputs/paypal_payee_input.rb +28 -0
  18. data/lib/braintree/graphql/inputs/paypal_purchase_unit_input.rb +31 -0
  19. data/lib/braintree/graphql/inputs/phone_input.rb +2 -0
  20. data/lib/braintree/graphql/inputs/update_customer_session_input.rb +5 -0
  21. data/lib/braintree/graphql/types/customer_recommendations_payload.rb +112 -18
  22. data/lib/braintree/graphql/types/payment_options.rb +2 -0
  23. data/lib/braintree/graphql/types/payment_recommendations.rb +35 -0
  24. data/lib/braintree/graphql/unions/customer_recommendations.rb +38 -25
  25. data/lib/braintree/merchant_account.rb +1 -25
  26. data/lib/braintree/merchant_account_gateway.rb +0 -81
  27. data/lib/braintree/meta_checkout_card.rb +8 -4
  28. data/lib/braintree/meta_checkout_token.rb +10 -6
  29. data/lib/braintree/payment_method_gateway.rb +3 -0
  30. data/lib/braintree/test/credit_card.rb +4 -0
  31. data/lib/braintree/transaction/apple_pay_details.rb +4 -0
  32. data/lib/braintree/transaction/credit_card_details.rb +8 -0
  33. data/lib/braintree/transaction/google_pay_details.rb +4 -0
  34. data/lib/braintree/transaction/meta_checkout_card_details.rb +9 -3
  35. data/lib/braintree/transaction/meta_checkout_token_details.rb +11 -5
  36. data/lib/braintree/transaction/visa_checkout_card_details.rb +8 -3
  37. data/lib/braintree/transaction.rb +0 -26
  38. data/lib/braintree/transaction_gateway.rb +9 -20
  39. data/lib/braintree/version.rb +1 -1
  40. data/lib/braintree/visa_checkout_card.rb +9 -4
  41. data/lib/braintree/webhook_notification.rb +0 -4
  42. data/lib/braintree/webhook_testing_gateway.rb +0 -33
  43. data/lib/braintree.rb +4 -3
  44. data/spec/integration/braintree/credit_card_spec.rb +101 -0
  45. data/spec/integration/braintree/credit_card_verification_spec.rb +118 -0
  46. data/spec/integration/braintree/customer_session_spec.rb +59 -49
  47. data/spec/integration/braintree/customer_spec.rb +71 -4
  48. data/spec/integration/braintree/disbursement_spec.rb +1 -1
  49. data/spec/integration/braintree/merchant_account_spec.rb +0 -342
  50. data/spec/integration/braintree/payment_method_nonce_spec.rb +44 -0
  51. data/spec/integration/braintree/payment_method_spec.rb +50 -3
  52. data/spec/integration/braintree/transaction_payment_facilitator_spec.rb +119 -0
  53. data/spec/integration/braintree/transaction_spec.rb +60 -328
  54. data/spec/spec_helper.rb +1 -1
  55. data/spec/unit/braintree/apple_pay_card_spec.rb +4 -0
  56. data/spec/unit/braintree/configuration_spec.rb +1 -1
  57. data/spec/unit/braintree/credit_card_spec.rb +22 -2
  58. data/spec/unit/braintree/credit_card_verification_gateway_spec.rb +1 -0
  59. data/spec/unit/braintree/customer_session_gateway_spec.rb +10 -9
  60. data/spec/unit/braintree/customer_spec.rb +2 -1
  61. data/spec/unit/braintree/google_pay_card_spec.rb +20 -0
  62. data/spec/unit/braintree/graphql/create_customer_session_input_spec.rb +25 -4
  63. data/spec/unit/braintree/graphql/customer_recommendations_input_spec.rb +21 -51
  64. data/spec/unit/braintree/graphql/customer_recommendations_spec.rb +40 -0
  65. data/spec/unit/braintree/graphql/update_customer_session_input_spec.rb +21 -7
  66. data/spec/unit/braintree/meta_checkout_card_spec.rb +8 -0
  67. data/spec/unit/braintree/meta_checkout_token_spec.rb +4 -0
  68. data/spec/unit/braintree/payment_method_nonce_spec.rb +9 -2
  69. data/spec/unit/braintree/payment_method_spec.rb +12 -0
  70. data/spec/unit/braintree/transaction/apple_pay_details_spec.rb +20 -0
  71. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +5 -1
  72. data/spec/unit/braintree/transaction/google_pay_details_spec.rb +20 -0
  73. data/spec/unit/braintree/transaction/meta_checkout_card_details_spec.rb +20 -0
  74. data/spec/unit/braintree/transaction/meta_checkout_token_details_spec.rb +20 -0
  75. data/spec/unit/braintree/transaction/visa_checkout_card_details_spec.rb +20 -0
  76. data/spec/unit/braintree/transaction_gateway_spec.rb +19 -0
  77. data/spec/unit/braintree/transaction_spec.rb +8 -0
  78. data/spec/unit/braintree/visa_checkout_card_spec.rb +20 -0
  79. data/spec/unit/braintree/webhook_notification_spec.rb +0 -53
  80. data/spec/unit/credit_card_details_spec.rb +20 -0
  81. metadata +8 -7
  82. data/lib/braintree/merchant_account/business_details.rb +0 -17
  83. data/lib/braintree/merchant_account/funding_details.rb +0 -18
  84. data/lib/braintree/merchant_account/individual_details.rb +0 -20
  85. data/spec/unit/braintree/disbursement_spec.rb +0 -131
  86. data/spec/unit/braintree/merchant_account_spec.rb +0 -33
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
2
  require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
3
3
 
4
4
  describe Braintree::CustomerSessionGateway do
5
- let(:gateway) do
5
+ let(:pwpp_gateway) do
6
6
  Braintree::Gateway.new(
7
7
  :environment => :development,
8
8
  :merchant_id => "pwpp_multi_account_merchant",
@@ -13,37 +13,43 @@ describe Braintree::CustomerSessionGateway do
13
13
 
14
14
  describe "create" do
15
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)
16
+ input = Braintree::CreateCustomerSessionInput.new(
17
+ merchant_account_id: "usd_pwpp_multi_account_merchant_account",
18
+ )
19
+ result = pwpp_gateway.customer_session.create_customer_session(input)
18
20
  expect(result.success?).to eq(true)
19
21
  expect(result.session_id).not_to be_nil
20
22
  end
21
23
 
22
- it "can can create customer session with merchant provided session id" do
24
+ it "can create customer session with merchant provided session id" do
23
25
  merchant_session_id = "11EF-A1E7-A5F5EE5C-A2E5-AFD2801469FC"
24
26
  input = Braintree::CreateCustomerSessionInput.new(
25
27
  session_id: merchant_session_id,
26
28
  )
27
- result = gateway.customer_session.create_customer_session(input)
29
+ result = pwpp_gateway.customer_session.create_customer_session(input)
28
30
  expect(result.success?).to eq(true)
29
31
  expect(result.session_id).to eq(merchant_session_id)
30
32
  end
31
33
 
32
34
  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
+ result = build_customer_session(nil)
36
+ expect(result.session_id).not_to be_nil
37
+ end
38
+
39
+ it "can create customer session with purchase units" do
40
+ input = Braintree::CreateCustomerSessionInput.new(
41
+ purchase_units: build_purchase_units,
42
+ )
43
+ result = pwpp_gateway.customer_session.create_customer_session(input)
35
44
  expect(result.success?).to eq(true)
36
45
  expect(result.session_id).not_to be_nil
37
46
  end
38
47
 
39
48
  it "cannot create duplicate customer session" do
40
49
  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)
50
+ result = build_customer_session(existing_session_id)
45
51
  expect(result.success?).to eq(false)
46
- expect(result.errors.first.message).to include("Session IDs must be unique per merchant.")
52
+ expect(result.errors.first.message).to include("Session IDs must be unique per merchant")
47
53
  end
48
54
  end
49
55
 
@@ -53,33 +59,29 @@ describe Braintree::CustomerSessionGateway do
53
59
  create_input = Braintree::CreateCustomerSessionInput.new(
54
60
  merchant_account_id: "usd_pwpp_multi_account_merchant_account",
55
61
  session_id: session_id,
62
+ purchase_units: build_purchase_units,
56
63
  )
64
+ pwpp_gateway.customer_session.create_customer_session(create_input)
57
65
 
58
- gateway.customer_session.create_customer_session(create_input)
59
-
60
- customer = build_customer_session_input("PR5_test@example.com", "4085005005")
61
-
66
+ customer = build_customer_session_input
62
67
  update_input = Braintree::UpdateCustomerSessionInput.new(
63
68
  session_id: session_id,
64
69
  customer: customer,
65
70
  )
66
-
67
- result = gateway.customer_session.update_customer_session(update_input)
71
+ result = pwpp_gateway.customer_session.update_customer_session(update_input)
68
72
 
69
73
  expect(result.success?).to eq(true)
70
74
  expect(result.session_id).to eq(session_id)
71
-
72
75
  end
73
76
 
74
77
  it "cannot update a non-existent customer session" do
75
78
  session_id = "11EF-34BC-2702904B-9026-C3ECF4BAC765"
76
- customer = build_customer_session_input("PR9_test@example.com", "4085005009")
79
+ customer = build_customer_session_input
77
80
  update_input = Braintree::UpdateCustomerSessionInput.new(
78
81
  session_id: session_id,
79
82
  customer: customer,
80
83
  )
81
-
82
- result = gateway.customer_session.update_customer_session(update_input)
84
+ result = pwpp_gateway.customer_session.update_customer_session(update_input)
83
85
 
84
86
  expect(result.success?).to eq(false)
85
87
  expect(result.errors.first.message).to include("does not exist")
@@ -88,56 +90,64 @@ describe Braintree::CustomerSessionGateway do
88
90
 
89
91
  describe "customer recommendations" do
90
92
  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 = build_customer_session_input
93
94
  customer_recommendations_input = Braintree::CustomerRecommendationsInput.new(
94
- session_id: "11EF-A1E7-A5F5EE5C-A2E5-AFD2801469FC",
95
- recommendations: recommendations,
95
+ session_id: "94f0b2db-5323-4d86-add3-paypal000000",
96
96
  customer: customer,
97
+ purchase_units: build_purchase_units,
98
+ domain: "domain.com",
97
99
  )
98
- result = gateway.customer_session.get_customer_recommendations(customer_recommendations_input)
100
+
101
+ result = pwpp_gateway.customer_session.get_customer_recommendations(customer_recommendations_input)
99
102
 
100
103
  expect(result.success?).to eq(true)
101
104
  payload = result.customer_recommendations
102
105
  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
+
107
+ recommendation = payload.recommendations.payment_recommendations[0]
108
+ expect(recommendation.payment_option).to eq(Braintree::RecommendedPaymentOption::PAYPAL)
109
+ expect(recommendation.recommended_priority).to eq(1)
106
110
  end
107
111
 
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]
112
+ it "raises an error when not authorized" do
113
+ customer = build_customer_session_input
111
114
  customer_recommendations_input = Braintree::CustomerRecommendationsInput.new(
112
- session_id: "11EF-34BC-2702904B-9026-C3ECF4BAC765",
113
- recommendations: recommendations,
115
+ session_id: "6B29FC40-CA47-1067-B31D-00DD010662DA",
114
116
  customer: customer,
117
+ purchase_units: build_purchase_units,
118
+ domain: "domain.com",
119
+ merchant_account_id: "gbp_pwpp_multi_account_merchant_account",
115
120
  )
116
- result = gateway.customer_session.get_customer_recommendations(customer_recommendations_input)
117
121
 
118
- expect(result.success?).to eq(false)
119
- expect(result.errors.first.message).to include("does not exist")
122
+ expect {
123
+ pwpp_gateway.customer_session.get_customer_recommendations(customer_recommendations_input)
124
+ }.to raise_error(Braintree::AuthorizationError)
120
125
  end
121
126
  end
122
127
 
123
128
  private
124
129
 
125
130
  def build_customer_session(session_id = nil)
126
- customer = build_customer_session_input("PR1_test@example.com", "4085005002")
131
+ customer = build_customer_session_input
132
+ input_attributes = {customer: customer}
133
+ input_attributes[:session_id] = session_id if session_id
127
134
 
128
- input = session_id ? CreateCustomerSessionInput.new(customer: customer, session_id: session_id) : CreateCustomerSessionInput.new(customer => customer)
129
- @gateway.customer_session.create_customer_session(input)
135
+ input = Braintree::CreateCustomerSessionInput.new(input_attributes)
136
+ pwpp_gateway.customer_session.create_customer_session(input)
130
137
  end
131
138
 
132
- def build_customer_session_input(email, phone_number)
139
+ def build_customer_session_input
133
140
  {
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"
141
+ hashed_email: "48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08",
142
+ hashed_phone_number: "a2df2987b2a3384210d3aa1c9fb8b627ebdae1f5a9097766c19ca30ec4360176",
143
+ device_fingerprint_id: "00DD010662DE",
144
+ user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/x.x.x.x Safari/537.36",
140
145
  }
141
146
  end
142
147
 
143
- end
148
+ def build_purchase_units
149
+ amount = {currency_code: "USD", value: "10.00"}
150
+ purchase_unit = {amount: amount}
151
+ [purchase_unit]
152
+ end
153
+ end
@@ -991,7 +991,10 @@ 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.business).not_to be_nil
994
995
  expect(apple_pay_card.commercial).not_to be_nil
996
+ expect(apple_pay_card.consumer).not_to be_nil
997
+ expect(apple_pay_card.corporate).not_to be_nil
995
998
  expect(apple_pay_card.country_of_issuance).not_to be_nil
996
999
  expect(apple_pay_card.debit).not_to be_nil
997
1000
  expect(apple_pay_card.durbin_regulated).not_to be_nil
@@ -1003,6 +1006,7 @@ describe Braintree::Customer do
1003
1006
  expect(apple_pay_card.prepaid).not_to be_nil
1004
1007
  expect(apple_pay_card.prepaid_reloadable).not_to be_nil
1005
1008
  expect(apple_pay_card.product_id).not_to be_nil
1009
+ expect(apple_pay_card.purchase).not_to be_nil
1006
1010
  expect(apple_pay_card.token).not_to be_nil
1007
1011
  end
1008
1012
 
@@ -1017,7 +1021,10 @@ describe Braintree::Customer do
1017
1021
  expect(found_customer.payment_methods.size).to eq(1)
1018
1022
  google_pay_card = found_customer.google_pay_cards.first
1019
1023
  expect(google_pay_card).to be_a Braintree::GooglePayCard
1024
+ expect(google_pay_card.business).not_to be_nil
1020
1025
  expect(google_pay_card.commercial).not_to be_nil
1026
+ expect(google_pay_card.consumer).not_to be_nil
1027
+ expect(google_pay_card.corporate).not_to be_nil
1021
1028
  expect(google_pay_card.country_of_issuance).not_to be_nil
1022
1029
  expect(google_pay_card.debit).not_to be_nil
1023
1030
  expect(google_pay_card.durbin_regulated).not_to be_nil
@@ -1029,6 +1036,7 @@ describe Braintree::Customer do
1029
1036
  expect(google_pay_card.prepaid).not_to be_nil
1030
1037
  expect(google_pay_card.prepaid_reloadable).not_to be_nil
1031
1038
  expect(google_pay_card.product_id).not_to be_nil
1039
+ expect(google_pay_card.purchase).not_to be_nil
1032
1040
  expect(google_pay_card.token).not_to be_nil
1033
1041
  end
1034
1042
 
@@ -1043,19 +1051,23 @@ describe Braintree::Customer do
1043
1051
  expect(found_customer.payment_methods.size).to eq(1)
1044
1052
  google_pay_card = found_customer.google_pay_cards.first
1045
1053
  expect(google_pay_card).to be_a Braintree::GooglePayCard
1046
- expect(google_pay_card.token).not_to be_nil
1047
- expect(google_pay_card.expiration_year).not_to be_nil
1048
- expect(google_pay_card.is_network_tokenized?).to eq(true)
1054
+ expect(google_pay_card.business).not_to be_nil
1049
1055
  expect(google_pay_card.commercial).not_to be_nil
1056
+ expect(google_pay_card.consumer).not_to be_nil
1057
+ expect(google_pay_card.corporate).not_to be_nil
1050
1058
  expect(google_pay_card.country_of_issuance).not_to be_nil
1051
1059
  expect(google_pay_card.debit).not_to be_nil
1052
1060
  expect(google_pay_card.durbin_regulated).not_to be_nil
1061
+ expect(google_pay_card.expiration_year).not_to be_nil
1053
1062
  expect(google_pay_card.healthcare).not_to be_nil
1063
+ expect(google_pay_card.is_network_tokenized?).to eq(true)
1054
1064
  expect(google_pay_card.issuing_bank).not_to be_nil
1055
1065
  expect(google_pay_card.payroll).not_to be_nil
1056
1066
  expect(google_pay_card.prepaid).not_to be_nil
1057
1067
  expect(google_pay_card.prepaid_reloadable).not_to be_nil
1058
1068
  expect(google_pay_card.product_id).not_to be_nil
1069
+ expect(google_pay_card.purchase).not_to be_nil
1070
+ expect(google_pay_card.token).not_to be_nil
1059
1071
  end
1060
1072
 
1061
1073
  it "returns associated venmo accounts" do
@@ -1750,6 +1762,57 @@ describe Braintree::Customer do
1750
1762
  end
1751
1763
  end
1752
1764
 
1765
+ describe "account information inquiry" do
1766
+ it "includes ani response when account information inquiry is sent in options" do
1767
+ result = Braintree::Customer.create(
1768
+ :credit_card => {
1769
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1770
+ :expiration_date => "05/2027",
1771
+ :cvv => "100",
1772
+ :billing_address => {
1773
+ :first_name => "John",
1774
+ :last_name => "Doe",
1775
+ },
1776
+ :options => {
1777
+ :account_information_inquiry => "send_data",
1778
+ :verify_card => true,
1779
+ },
1780
+ },
1781
+ )
1782
+
1783
+ expect(result).to be_success
1784
+ verification = result.customer.credit_cards.first.verification
1785
+ expect(verification.ani_first_name_response_code).not_to be_nil
1786
+ expect(verification.ani_last_name_response_code).not_to be_nil
1787
+ end
1788
+
1789
+ it "includes ani response after updating the options with account information inquiry" do
1790
+ customer = Braintree::Customer.create!(
1791
+ :first_name => "Joe",
1792
+ )
1793
+ updated_result = Braintree::Customer.update(
1794
+ customer.id,
1795
+ :credit_card => {
1796
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1797
+ :expiration_date => "12/2029",
1798
+ :billing_address => {
1799
+ :first_name => "John",
1800
+ :last_name => "Doe",
1801
+ },
1802
+ :options => {
1803
+ :account_information_inquiry => "send_data",
1804
+ :verify_card => true,
1805
+ },
1806
+ },
1807
+ )
1808
+
1809
+ expect(updated_result).to be_success
1810
+ verification = updated_result.customer.credit_cards.first.verification
1811
+ expect(verification.ani_first_name_response_code).not_to be_nil
1812
+ expect(verification.ani_last_name_response_code).not_to be_nil
1813
+ end
1814
+ end
1815
+
1753
1816
  describe "paypal" do
1754
1817
  context "future" do
1755
1818
  it "creates a customer with a future paypal account" do
@@ -1916,7 +1979,7 @@ describe Braintree::Customer do
1916
1979
  end
1917
1980
  end
1918
1981
 
1919
- it "returns prepaid_reloadable from VisaCheckoutCard" do
1982
+ it "returns bin fields from VisaCheckoutCard" do
1920
1983
  result = Braintree::Customer.create(
1921
1984
  :payment_method_nonce => Braintree::Test::Nonce::VisaCheckoutVisa,
1922
1985
  )
@@ -1926,6 +1989,10 @@ describe Braintree::Customer do
1926
1989
  expect(found_customer.visa_checkout_cards).not_to be_nil
1927
1990
  visa_checkout_card = found_customer.visa_checkout_cards.first
1928
1991
  expect(visa_checkout_card).to be_a Braintree::VisaCheckoutCard
1992
+ expect(visa_checkout_card.business).not_to be_nil
1993
+ expect(visa_checkout_card.consumer).not_to be_nil
1994
+ expect(visa_checkout_card.corporate).not_to be_nil
1929
1995
  expect(visa_checkout_card.prepaid_reloadable).not_to be_nil
1996
+ expect(visa_checkout_card.purchase).not_to be_nil
1930
1997
  end
1931
1998
  end
@@ -28,4 +28,4 @@ describe Braintree::Disbursement do
28
28
  expect(transaction.id).to eq("sub_merchant_transaction")
29
29
  end
30
30
  end
31
- end
31
+ end