solidus_braintree 3.2.0 → 3.4.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 (112) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +7 -0
  3. data/.github/workflows/lint.yml +25 -0
  4. data/.github/workflows/test.yml +77 -0
  5. data/.rubocop.yml +5 -84
  6. data/.standard.yml +6 -0
  7. data/7.2 +0 -0
  8. data/Gemfile +12 -20
  9. data/README.md +7 -5
  10. data/Rakefile +7 -7
  11. data/app/helpers/solidus_braintree/braintree_admin_helper.rb +4 -4
  12. data/app/models/solidus_braintree/avs_result.rb +34 -34
  13. data/app/models/solidus_braintree/base_record.rb +11 -0
  14. data/app/models/solidus_braintree/configuration.rb +12 -12
  15. data/app/models/solidus_braintree/customer.rb +1 -1
  16. data/app/models/solidus_braintree/gateway.rb +14 -17
  17. data/app/models/solidus_braintree/response.rb +9 -9
  18. data/app/models/solidus_braintree/source.rb +9 -7
  19. data/app/models/solidus_braintree/transaction.rb +2 -2
  20. data/app/models/solidus_braintree/transaction_address.rb +5 -5
  21. data/app/models/solidus_braintree/transaction_import.rb +2 -2
  22. data/app/{decorators/models/solidus_braintree/spree_store_decorator.rb → patches/models/solidus_braintree/spree_store_patch.rb} +1 -1
  23. data/app/{decorators/models/solidus_braintree/spree_user_decorator.rb → patches/models/solidus_braintree/spree_user_patch.rb} +2 -2
  24. data/bin/dummy-app +23 -3
  25. data/bin/rails-sandbox +4 -4
  26. data/bin/rspec +6 -0
  27. data/bin/sandbox +55 -31
  28. data/db/migrate/20161114231422_create_solidus_paypal_braintree_configurations.rb +2 -2
  29. data/db/migrate/20170508085402_add_not_null_constraint_to_sources_payment_type.rb +2 -2
  30. data/db/migrate/20230109080950_rename_solidus_paypal_braintree_source_type.rb +3 -3
  31. data/{app/decorators/controllers → lib/controllers/api}/solidus_braintree/client_tokens_controller.rb +2 -2
  32. data/lib/controllers/backend/solidus_braintree/configurations_controller.rb +4 -4
  33. data/lib/generators/solidus_braintree/install/install_generator.rb +48 -40
  34. data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/checkouts_controller.rb +7 -7
  35. data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/transactions_controller.rb +7 -7
  36. data/lib/generators/solidus_braintree/install/templates/app/helpers/solidus_braintree/braintree_checkout_helper.rb +5 -5
  37. data/{app/decorators/controllers/solidus_braintree/admin_payments_controller_decorator.rb → lib/patches/backend/controllers/solidus_braintree/admin_payments_controller_patch.rb} +1 -1
  38. data/lib/solidus_braintree/engine.rb +13 -24
  39. data/lib/solidus_braintree/extension_configuration.rb +1 -1
  40. data/lib/solidus_braintree/request_protection.rb +2 -2
  41. data/lib/solidus_braintree/version.rb +1 -1
  42. data/lib/solidus_braintree.rb +8 -10
  43. data/lib/solidus_paypal_braintree.rb +2 -2
  44. data/mise.toml +2 -0
  45. data/solidus_braintree.gemspec +23 -22
  46. metadata +62 -152
  47. data/.circleci/config.yml +0 -80
  48. data/app/models/application_record.rb +0 -5
  49. data/lib/views/backend_v1.2/spree/admin/payments/source_forms/_braintree.html.erb +0 -16
  50. data/lib/views/backend_v2.4/spree/admin/shared/preference_fields/_hash.html.erb +0 -12
  51. data/spec/controllers/solidus_braintree/checkouts_controller_spec.rb +0 -99
  52. data/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb +0 -55
  53. data/spec/controllers/solidus_braintree/configurations_controller_spec.rb +0 -73
  54. data/spec/controllers/solidus_braintree/transactions_controller_spec.rb +0 -183
  55. data/spec/fixtures/cassettes/admin/invalid_credit_card.yml +0 -63
  56. data/spec/fixtures/cassettes/admin/resubmit_credit_card.yml +0 -352
  57. data/spec/fixtures/cassettes/admin/valid_credit_card.yml +0 -412
  58. data/spec/fixtures/cassettes/braintree/create_profile.yml +0 -71
  59. data/spec/fixtures/cassettes/braintree/generate_token.yml +0 -63
  60. data/spec/fixtures/cassettes/braintree/token.yml +0 -63
  61. data/spec/fixtures/cassettes/checkout/invalid_credit_card.yml +0 -63
  62. data/spec/fixtures/cassettes/checkout/resubmit_credit_card.yml +0 -216
  63. data/spec/fixtures/cassettes/checkout/update.yml +0 -71
  64. data/spec/fixtures/cassettes/checkout/valid_credit_card.yml +0 -171
  65. data/spec/fixtures/cassettes/checkout/valid_venmo_transaction.yml +0 -599
  66. data/spec/fixtures/cassettes/gateway/authorize/credit_card/address.yml +0 -86
  67. data/spec/fixtures/cassettes/gateway/authorize/merchant_account/EUR.yml +0 -154
  68. data/spec/fixtures/cassettes/gateway/authorize/paypal/EUR.yml +0 -90
  69. data/spec/fixtures/cassettes/gateway/authorize/paypal/address.yml +0 -90
  70. data/spec/fixtures/cassettes/gateway/authorize.yml +0 -86
  71. data/spec/fixtures/cassettes/gateway/authorized_transaction.yml +0 -73
  72. data/spec/fixtures/cassettes/gateway/cancel/missing.yml +0 -63
  73. data/spec/fixtures/cassettes/gateway/cancel/refunds.yml +0 -272
  74. data/spec/fixtures/cassettes/gateway/cancel/void.yml +0 -201
  75. data/spec/fixtures/cassettes/gateway/capture.yml +0 -141
  76. data/spec/fixtures/cassettes/gateway/complete.yml +0 -157
  77. data/spec/fixtures/cassettes/gateway/credit.yml +0 -208
  78. data/spec/fixtures/cassettes/gateway/customer.yml +0 -79
  79. data/spec/fixtures/cassettes/gateway/purchase.yml +0 -87
  80. data/spec/fixtures/cassettes/gateway/settled_transaction.yml +0 -140
  81. data/spec/fixtures/cassettes/gateway/void.yml +0 -137
  82. data/spec/fixtures/cassettes/source/bin.yml +0 -295
  83. data/spec/fixtures/cassettes/source/card_type.yml +0 -267
  84. data/spec/fixtures/cassettes/source/last4.yml +0 -267
  85. data/spec/fixtures/cassettes/transaction/import/valid/capture.yml +0 -224
  86. data/spec/fixtures/cassettes/transaction/import/valid.yml +0 -71
  87. data/spec/fixtures/views/carts/_cart_footer.html.erb +0 -18
  88. data/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb +0 -17
  89. data/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb +0 -70
  90. data/spec/models/solidus_braintree/address_spec.rb +0 -71
  91. data/spec/models/solidus_braintree/avs_result_spec.rb +0 -317
  92. data/spec/models/solidus_braintree/gateway_spec.rb +0 -774
  93. data/spec/models/solidus_braintree/response_spec.rb +0 -280
  94. data/spec/models/solidus_braintree/source_spec.rb +0 -555
  95. data/spec/models/solidus_braintree/transaction_address_spec.rb +0 -235
  96. data/spec/models/solidus_braintree/transaction_import_spec.rb +0 -302
  97. data/spec/models/solidus_braintree/transaction_spec.rb +0 -86
  98. data/spec/models/spree/store_spec.rb +0 -14
  99. data/spec/requests/spree/api/orders_controller_spec.rb +0 -36
  100. data/spec/solidus_braintree_spec_helper.rb +0 -9
  101. data/spec/support/solidus_braintree/capybara.rb +0 -7
  102. data/spec/support/solidus_braintree/factories.rb +0 -55
  103. data/spec/support/solidus_braintree/gateway_helpers.rb +0 -29
  104. data/spec/support/solidus_braintree/order_ready_for_payment.rb +0 -44
  105. data/spec/support/solidus_braintree/order_walkthrough.rb +0 -87
  106. data/spec/support/solidus_braintree/vcr.rb +0 -38
  107. data/spec/support/solidus_braintree/with_prepended_view_fixtures.rb +0 -19
  108. data/spec/system/backend/configuration_spec.rb +0 -23
  109. data/spec/system/backend/new_payment_spec.rb +0 -136
  110. data/spec/system/frontend/braintree_credit_card_checkout_spec.rb +0 -199
  111. data/spec/system/frontend/paypal_checkout_spec.rb +0 -168
  112. data/spec/system/frontend/venmo_checkout_spec.rb +0 -193
@@ -1,168 +0,0 @@
1
- require 'solidus_braintree_spec_helper'
2
- require 'support/solidus_braintree/with_prepended_view_fixtures'
3
-
4
- RSpec.describe "Checkout", type: :feature, js: true do
5
- include_context 'with prepended view fixtures'
6
-
7
- Capybara.default_max_wait_time = 60
8
-
9
- # let!(:store) do
10
- # create(:store, payment_methods: [payment_method]).tap do |s|
11
- # s.braintree_configuration.update!(braintree_preferences)
12
- # end
13
- # end
14
- let(:braintree_preferences) { { paypal: true }.merge(paypal_options) }
15
- let(:paypal_options) { {} }
16
-
17
- let!(:country) { create(:country, states_required: true) }
18
- # let!(:state) { create(:state, country: country, abbr: "CA", name: "California") }
19
- # let!(:shipping_method) { create(:shipping_method) }
20
- # let!(:stock_location) { create(:stock_location) }
21
- let!(:mug) { create(:product, name: "RoR Mug") }
22
- let!(:payment_method) { create_gateway }
23
- # let!(:zone) { create(:zone) }
24
-
25
- before do
26
- create(:store, payment_methods: [payment_method]).tap do |s|
27
- s.braintree_configuration.update!(braintree_preferences)
28
- end
29
- create(:state, country: country, abbr: "CA", name: "California")
30
- create(:shipping_method)
31
- create(:stock_location)
32
- create(:zone)
33
- end
34
-
35
- context "when going through express checkout using paypal cart button" do
36
- before do
37
- payment_method
38
- add_mug_to_cart
39
- end
40
-
41
- it "checks out successfully", skip: "Broken. To be revisited" do
42
- pend_if_paypal_slow do
43
- expect_any_instance_of(Spree::Order).to receive(:restart_checkout_flow)
44
- move_through_paypal_popup
45
- expect(page).to have_content("Shipments")
46
- click_on "Place Order"
47
- expect(page).to have_content("Your order has been processed successfully")
48
- end
49
- end
50
-
51
- context 'when using custom paypal button style' do
52
- let(:paypal_options) { { preferred_paypal_button_color: 'blue' } }
53
-
54
- it 'displays required PayPal button style' do
55
- within_frame find('#paypal-button iframe') do
56
- expect(page).to have_selector('.paypal-button-color-blue')
57
- end
58
- end
59
- end
60
- end
61
-
62
- context "when going through regular checkout using paypal payment method" do
63
- before do
64
- payment_method
65
- add_mug_to_cart
66
- click_button("Checkout")
67
- fill_in("order_email", with: "paypal_buyer@paypaltest.com")
68
- click_button("Continue")
69
- fill_in_address
70
- click_button("Save and Continue")
71
- click_button("Save and Continue")
72
- end
73
-
74
- it "formats the address variable correctly" do
75
- expect(page.evaluate_script("address['recipientName']")).to eq "Ryan Bigg"
76
- end
77
-
78
- it "checks out successfully", skip: "Broken. To be revisited" do
79
- pend_if_paypal_slow do
80
- expect_any_instance_of(Spree::Order).not_to receive(:restart_checkout_flow)
81
- move_through_paypal_popup
82
-
83
- expect(page).to have_content("Shipments")
84
- click_on "Place Order"
85
- expect(page).to have_content("Your order has been processed successfully")
86
- end
87
- end
88
- end
89
-
90
- # Selenium does not clear cookies properly between test runs, even when
91
- # using Capybara.reset_sessions!, see:
92
- # https://github.com/jnicklas/capybara/issues/535
93
- #
94
- # This causes Paypal to remain logged in and not prompt for an email on the
95
- # second test run and causes the test to fail. Adding conditional logic for
96
- # this greatly increases the test time, so it is left out since CI runs
97
- # these with poltergeist.
98
- def move_through_paypal_popup
99
- expect(page).to have_css('#paypal-button .paypal-button')
100
-
101
- sleep 2 # the PayPal button is not immediately ready
102
-
103
- popup = page.window_opened_by do
104
- within_frame find('#paypal-button iframe') do
105
- find('div.paypal-button').click
106
- end
107
- end
108
- page.switch_to_window(popup)
109
-
110
- # We don't control this popup window.
111
- # So javascript errors are not our errors.
112
- begin
113
- expect(page).not_to have_selector('body.loading')
114
- fill_in("login_email", with: "stembolt_buyer@stembolttest.com")
115
- click_on "Next"
116
- fill_in("login_password", with: "test1234")
117
-
118
- expect(page).not_to have_selector('body.loading')
119
- click_button("btnLogin")
120
-
121
- expect(page).not_to have_selector('body.loading')
122
- click_button("Continue")
123
- click_button("Agree & Continue")
124
- rescue Selenium::WebDriver::Error::JavascriptError => e
125
- pending "PayPal had javascript errors in their popup window."
126
- raise e
127
- rescue Capybara::ElementNotFound => e
128
- pending "PayPal delivered unkown HTML in their popup window."
129
- raise e
130
- rescue Selenium::WebDriver::Error::NoSuchWindowError => e
131
- pending "PayPal popup not available."
132
- raise e
133
- end
134
-
135
- page.switch_to_window(page.windows.first)
136
- end
137
-
138
- def fill_in_address
139
- address = "order_bill_address_attributes"
140
- if page.has_css?("##{address}_firstname", wait: 0)
141
- fill_in "#{address}_firstname", with: "Ryan"
142
- fill_in "#{address}_lastname", with: "Bigg"
143
- else
144
- fill_in "#{address}_name", with: "Ryan Bigg"
145
- end
146
- fill_in "#{address}_address1", with: "143 Swan Street"
147
- fill_in "#{address}_city", with: "San Jose"
148
- select "United States of America", from: "#{address}_country_id"
149
- select "California", from: "#{address}_state_id"
150
- fill_in "#{address}_zipcode", with: "95131"
151
- fill_in "#{address}_phone", with: "(555) 555-0111"
152
- end
153
-
154
- def add_mug_to_cart
155
- visit product_path(mug)
156
- click_button "add-to-cart-button"
157
- end
158
-
159
- def pend_if_paypal_slow
160
- yield
161
- rescue RSpec::Expectations::ExpectationNotMetError => e
162
- pending "PayPal did not answer in #{Capybara.default_max_wait_time} seconds."
163
- raise e
164
- rescue Selenium::WebDriver::Error::JavascriptError => e
165
- pending "PayPal delivered wrong payload because of errors in their popup window."
166
- raise e
167
- end
168
- end
@@ -1,193 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'solidus_braintree_spec_helper'
4
-
5
- RSpec.describe "Checkout", type: :feature, js: true do
6
- let(:braintree_preferences) { { venmo: true }.merge(preferences) }
7
- let(:preferences) { {} }
8
- let(:user) { create(:user) }
9
- let!(:payment_method) { create_gateway }
10
-
11
- before do
12
- create(:store, payment_methods: [payment_method]).tap do |s|
13
- s.braintree_configuration.update!(braintree_preferences)
14
- end
15
-
16
- go_to_payment_checkout_page
17
- end
18
-
19
- context 'with Venmo checkout' do
20
- context 'when Venmo is disabled' do
21
- let(:preferences) { { venmo: false } }
22
-
23
- it 'does not load the Venmo payment button' do
24
- expect(page).not_to have_selector('#venmo-button')
25
- end
26
- end
27
-
28
- context 'when Venmo is enabled' do
29
- it 'loads the Venmo payment button' do
30
- expect(page).to have_selector('#venmo-button')
31
- end
32
- end
33
-
34
- context "when Venmo's button style is customized" do
35
- context 'when venmo_button_color is "blue" and venmo_button_width is "280"' do
36
- let(:preferences) { { preferred_venmo_button_color: 'blue', preferred_venmo_button_width: '280' } }
37
-
38
- it 'has the correct style' do
39
- venmo_button.assert_matches_style(width: '280px', 'background-image': /venmo_blue_button_280x48/)
40
- venmo_button.hover
41
- venmo_button.assert_matches_style('background-image': /venmo_active_blue_button_280x48/)
42
- end
43
- end
44
-
45
- context 'when venmo_button_color is "white" and venmo_button_width is "375"' do
46
- let(:preferences) { { preferred_venmo_button_color: 'white', preferred_venmo_button_width: '375' } }
47
-
48
- it 'has the correct style' do
49
- venmo_button.assert_matches_style(width: '375px', 'background-image': /venmo_white_button_375x48/)
50
- venmo_button.hover
51
- venmo_button.assert_matches_style('background-image': /venmo_active_white_button_375x48/)
52
- end
53
- end
54
- end
55
-
56
- context 'when the Venmo button is clicked' do
57
- before { venmo_button.click }
58
-
59
- it 'opens the QR modal which shows an error when closed' do
60
- within_frame(venmo_frame) do
61
- expect(page).to have_selector('#venmo-qr-code-view')
62
-
63
- click_button('close-icon')
64
-
65
- expect(page).not_to have_selector('#venmo-qr-code-view')
66
- end
67
-
68
- expect(page).to have_content('Venmo authorization was canceled by closing the Venmo Desktop modal.')
69
- end
70
- end
71
-
72
- # TODO: Reenable these specs once Venmo is enabled on the Braintree sandbox.
73
- xcontext 'with Venmo transactions', vcr: { cassette_name: 'checkout/valid_venmo_transaction' } do
74
- before do
75
- fake_venmo_successful_tokenization
76
- end
77
-
78
- context 'with CreditCard disabled' do
79
- it 'can checkout with Venmo' do
80
- next_checkout_step
81
- finalize_checkout
82
-
83
- expect(Spree::Order.last.complete?).to be(true)
84
- end
85
- end
86
-
87
- # To test that the hosted-fields inputs do not conflict with Venmo's
88
- context 'with CreditCard enabled' do
89
- let(:preferences) { { credit_card: true } }
90
-
91
- it 'can checkout with Venmo' do
92
- disable_hosted_fields_inputs
93
- disable_hosted_fields_form_listener
94
-
95
- next_checkout_step
96
- finalize_checkout
97
-
98
- expect(Spree::Order.last.complete?).to be(true)
99
- expect(Spree::Payment.last.source.venmo?).to be(true)
100
- end
101
- end
102
-
103
- # https://developer.paypal.com/braintree/docs/guides/venmo/client-side#custom-integration
104
- it "meet's Braintree's acceptance criteria during checkout", aggregate_failures: true do
105
- next_checkout_step
106
-
107
- expect(page).to have_content('Payment Type: Venmo')
108
-
109
- finalize_checkout
110
-
111
- expect(page).to have_content('Venmo Account: venmojoe')
112
- end
113
-
114
- # the VCR must be based on this test, so it includes HTTP requests of the second order
115
- it 'saves the used Venmo source in the wallet and can be reused' do
116
- next_checkout_step
117
- finalize_checkout
118
- go_to_payment_checkout_page(order_number: 'R300000002')
119
-
120
- expect(Spree::User.first.wallet.wallet_payment_sources).not_to be_empty
121
- expect(page).to have_selector('#existing_cards')
122
- expect(page).to have_content('venmojoe')
123
-
124
- next_checkout_step
125
- finalize_checkout
126
-
127
- expect(Spree::Order.all.all?(&:complete?)).to be(true)
128
- end
129
- end
130
- end
131
-
132
- private
133
-
134
- def go_to_payment_checkout_page(order_number: 'R300000001' )
135
- order = if Spree.solidus_gem_version >= Gem::Version.new('2.6.0')
136
- SolidusBraintree::OrderWalkthrough.up_to(:address)
137
- else
138
- OrderWalkthrough.up_to(:address)
139
- end
140
-
141
- order.update!(user: user, number: order_number) # constant order number for VCRs
142
-
143
- allow_any_instance_of(CheckoutsController).to receive_messages(current_order: order)
144
-
145
- first_user = Spree::User.first
146
- allow_any_instance_of(CheckoutsController).to receive_messages(try_spree_current_user: first_user)
147
- allow_any_instance_of(CheckoutsController).to receive_messages(spree_current_user: first_user)
148
-
149
- allow_any_instance_of(Spree::Payment).to receive(:gateway_order_id).and_return(order_number)
150
-
151
- visit checkout_state_path(order.state)
152
- next_checkout_step
153
- end
154
-
155
- def next_checkout_step
156
- click_button('Save and Continue')
157
- end
158
-
159
- def finalize_checkout
160
- click_button('Place Order')
161
- end
162
-
163
- def venmo_button
164
- find_button('venmo-button', disabled: false)
165
- end
166
-
167
- def venmo_frame
168
- find('#venmo-desktop-iframe')
169
- end
170
-
171
- def fake_venmo_successful_tokenization
172
- enable_venmo_inputs
173
- fake_payment_method_nonce
174
- end
175
-
176
- def enable_venmo_inputs
177
- page.execute_script("$('.venmo-fields input').each(function(_index, input){input.removeAttribute('disabled');});")
178
- end
179
-
180
- def fake_payment_method_nonce
181
- page.execute_script("$('#venmo_payment_method_nonce').val('fake-venmo-account-nonce');")
182
- end
183
-
184
- def disable_hosted_fields_inputs
185
- page.execute_script("$('.hosted-fields input').each(function(_index, input){input.disabled=true;});")
186
- end
187
-
188
- def disable_hosted_fields_form_listener
189
- # Once the submit button is enabled, the submit listener has been added
190
- find("#checkout_form_payment [type='submit']:not(:disabled)")
191
- page.execute_script("$('#checkout_form_payment').off('submit');")
192
- end
193
- end