solidus_braintree 2.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +42 -9
- data/.gitignore +1 -0
- data/.rubocop.yml +8 -1
- data/CHANGELOG.md +1 -189
- data/OLD_CHANGELOG.md +199 -0
- data/Rakefile +7 -1
- data/app/assets/config/solidus_braintree_manifest.js +0 -1
- data/app/assets/javascripts/spree/backend/solidus_braintree.js +4 -4
- data/app/models/solidus_braintree/gateway.rb +5 -1
- data/app/models/solidus_braintree/response.rb +1 -1
- data/app/models/solidus_braintree/source.rb +5 -0
- data/app/models/solidus_braintree/transaction.rb +1 -1
- data/app/models/solidus_braintree/transaction_import.rb +1 -0
- data/bin/dummy-app +37 -0
- data/bin/rails-dummy-app +17 -0
- data/bin/rspec +11 -0
- data/bin/sandbox +20 -62
- data/db/migrate/20230210104310_add_device_data_to_braintree_sources.rb +5 -0
- data/lib/generators/solidus_braintree/install/install_generator.rb +134 -34
- data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/javascripts/spree/frontend/paypal_button.js +1 -1
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/ajax.js +13 -0
- data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/apple_pay_button.js +2 -2
- data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/checkout.js +10 -5
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/client.js +239 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/constants.js +89 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/frontend.js +15 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/hosted_form.js +48 -0
- data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/paypal_button.js +4 -3
- data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/paypal_messaging.js +1 -1
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/promise.js +20 -0
- data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/venmo_button.js +1 -1
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree.js +1 -0
- data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/stylesheets/spree/frontend/solidus_braintree.scss +11 -0
- data/lib/{controllers/frontend → generators/solidus_braintree/install/templates/app/controllers}/solidus_braintree/checkouts_controller.rb +1 -1
- data/lib/{controllers/frontend → generators/solidus_braintree/install/templates/app/controllers}/solidus_braintree/transactions_controller.rb +5 -4
- data/lib/generators/solidus_braintree/install/templates/app/views/checkouts/existing_payment/_braintree.html.erb +2 -0
- data/lib/{views/frontend/spree/checkout → generators/solidus_braintree/install/templates/app/views/checkouts}/payment/_braintree.html.erb +1 -1
- data/lib/{views/frontend/solidus_braintree/payments/_payment.html.erb → generators/solidus_braintree/install/templates/app/views/payments/_braintree_payment_details.html.erb} +0 -3
- data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_apple_pay_button.html.erb +1 -1
- data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_braintree_head_scripts.html.erb +1 -1
- data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_braintree_hosted_fields.html.erb +1 -4
- data/lib/{views/frontend → generators/solidus_braintree/install/templates/app/views}/spree/shared/_paypal_checkout_button.html.erb +1 -0
- data/lib/solidus_braintree/engine.rb +15 -10
- data/lib/solidus_braintree/version.rb +1 -1
- data/solidus_braintree.gemspec +4 -8
- data/spec/controllers/solidus_braintree/checkouts_controller_spec.rb +2 -2
- data/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb +2 -2
- data/spec/controllers/solidus_braintree/configurations_controller_spec.rb +2 -2
- data/spec/controllers/solidus_braintree/transactions_controller_spec.rb +3 -3
- data/spec/fixtures/views/carts/_cart_footer.html.erb +18 -0
- data/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb +1 -1
- data/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb +1 -1
- data/spec/models/solidus_braintree/address_spec.rb +1 -1
- data/spec/models/solidus_braintree/avs_result_spec.rb +1 -1
- data/spec/models/solidus_braintree/gateway_spec.rb +35 -3
- data/spec/models/solidus_braintree/response_spec.rb +1 -1
- data/spec/models/solidus_braintree/source_spec.rb +17 -1
- data/spec/models/solidus_braintree/transaction_address_spec.rb +2 -2
- data/spec/models/solidus_braintree/transaction_import_spec.rb +2 -2
- data/spec/models/solidus_braintree/transaction_spec.rb +2 -2
- data/spec/models/spree/store_spec.rb +2 -2
- data/spec/requests/spree/api/orders_controller_spec.rb +2 -2
- data/spec/solidus_braintree_helper.rb +7 -0
- data/{lib/solidus_braintree/testing_support → spec/support/solidus_braintree}/factories.rb +17 -15
- data/spec/support/{order_ready_for_payment.rb → solidus_braintree/order_ready_for_payment.rb} +9 -2
- data/spec/support/solidus_braintree/order_walkthrough.rb +87 -0
- data/spec/support/solidus_braintree/with_prepended_view_fixtures.rb +19 -0
- data/spec/{features → system}/backend/configuration_spec.rb +2 -2
- data/spec/{features → system}/backend/new_payment_spec.rb +3 -4
- data/spec/{features → system}/frontend/braintree_credit_card_checkout_spec.rb +23 -15
- data/spec/{features → system}/frontend/paypal_checkout_spec.rb +6 -3
- data/spec/{features → system}/frontend/venmo_checkout_spec.rb +8 -9
- metadata +95 -114
- data/app/assets/javascripts/solidus_braintree/frontend.js +0 -14
- data/app/assets/javascripts/spree/frontend/solidus_braintree.js +0 -1
- data/app/decorators/controllers/solidus_braintree/checkout_controller_decorator.rb +0 -11
- data/app/decorators/controllers/solidus_braintree/orders_controller_decorator.rb +0 -11
- data/app/overrides/spree/payments/payment/add_paypal_funding_source_to_payment.rb +0 -9
- data/app/views/spree/checkout/existing_payment/_braintree.html.erb +0 -10
- data/spec/fixtures/views/spree/orders/edit.html.erb +0 -50
- data/spec/spec_helper.rb +0 -32
- data/spec/support/views.rb +0 -1
- /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/client.js +0 -0
- /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/constants.js +0 -0
- /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/hosted_form.js +0 -0
- /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/promise.js +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_blue_button_280x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_blue_button_320x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_blue_button_375x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_white_button_280x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_white_button_320x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_white_button_375x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_acceptance_mark.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_button_280x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_button_320x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_button_375x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_logo.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_acceptance_mark.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_button_280x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_button_320x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_button_375x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_logo.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/helpers/solidus_braintree/braintree_checkout_helper.rb +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_braintree_errors.html.erb +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_paypal_cart_button.html.erb +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_paypal_messaging.html.erb +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_venmo_button.html.erb +0 -0
- /data/lib/generators/solidus_braintree/install/templates/{initializer.rb → config/initializers/solidus_braintree.rb} +0 -0
- /data/spec/support/{capybara.rb → solidus_braintree/capybara.rb} +0 -0
- /data/spec/support/{gateway_helpers.rb → solidus_braintree/gateway_helpers.rb} +0 -0
- /data/spec/support/{vcr.rb → solidus_braintree/vcr.rb} +0 -0
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'solidus_braintree_helper'
|
2
2
|
|
3
|
-
describe SolidusBraintree::ClientTokensController do
|
3
|
+
RSpec.describe SolidusBraintree::ClientTokensController do
|
4
4
|
routes { SolidusBraintree::Engine.routes }
|
5
5
|
|
6
6
|
cassette_options = { cassette_name: "braintree/token" }
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'solidus_braintree_helper'
|
2
2
|
|
3
|
-
describe SolidusBraintree::ConfigurationsController, type: :controller do
|
3
|
+
RSpec.describe SolidusBraintree::ConfigurationsController, type: :controller do
|
4
4
|
routes { SolidusBraintree::Engine.routes }
|
5
5
|
|
6
6
|
let!(:store_1) { create :store }
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'solidus_braintree_helper'
|
2
2
|
|
3
3
|
RSpec.describe SolidusBraintree::TransactionsController, type: :controller do
|
4
4
|
routes { SolidusBraintree::Engine.routes }
|
@@ -130,7 +130,7 @@ RSpec.describe SolidusBraintree::TransactionsController, type: :controller do
|
|
130
130
|
context "when format is HTML" do
|
131
131
|
context "when import! leaves the order in confirm" do
|
132
132
|
it "redirects the user to the confirm page" do
|
133
|
-
expect(post_create).to redirect_to
|
133
|
+
expect(post_create).to redirect_to '/checkout/confirm'
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
@@ -138,7 +138,7 @@ RSpec.describe SolidusBraintree::TransactionsController, type: :controller do
|
|
138
138
|
before { allow(order).to receive(:complete?).and_return(true) }
|
139
139
|
|
140
140
|
it "displays the order to the user" do
|
141
|
-
expect(post_create).to redirect_to
|
141
|
+
expect(post_create).to redirect_to "/orders/#{order.number}"
|
142
142
|
end
|
143
143
|
end
|
144
144
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<% order = order_form.object %>
|
2
|
+
|
3
|
+
<footer class="cart-footer">
|
4
|
+
<p class="cart-footer__total">
|
5
|
+
<%= t('spree.total') %>: <strong><%= order.display_total %></strong>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<div class="cart-footer__primary-action">
|
9
|
+
<%= order_form.button(
|
10
|
+
I18n.t('spree.checkout'),
|
11
|
+
class: 'button-primary',
|
12
|
+
id: 'checkout-link',
|
13
|
+
name: :checkout
|
14
|
+
) %>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<%= render "spree/shared/paypal_cart_button" %>
|
18
|
+
</footer>
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'solidus_braintree_helper'
|
2
2
|
require 'webmock'
|
3
|
-
require 'support/order_ready_for_payment'
|
3
|
+
require 'support/solidus_braintree/order_ready_for_payment'
|
4
4
|
|
5
5
|
RSpec.describe SolidusBraintree::Gateway do
|
6
6
|
let(:gateway) do
|
@@ -16,7 +16,8 @@ RSpec.describe SolidusBraintree::Gateway do
|
|
16
16
|
nonce: 'fake-valid-nonce',
|
17
17
|
user: user,
|
18
18
|
payment_type: payment_type,
|
19
|
-
payment_method: gateway
|
19
|
+
payment_method: gateway,
|
20
|
+
device_data: 'fake-device-data'
|
20
21
|
)
|
21
22
|
end
|
22
23
|
|
@@ -220,6 +221,37 @@ RSpec.describe SolidusBraintree::Gateway do
|
|
220
221
|
expect(authorize.message).to eq 'authorized'
|
221
222
|
expect(authorize.authorization).to be_present
|
222
223
|
end
|
224
|
+
|
225
|
+
context 'with available device data' do
|
226
|
+
it 'passes the device data as a parameter in the request' do
|
227
|
+
expect_any_instance_of(Braintree::TransactionGateway).
|
228
|
+
to receive(:sale).
|
229
|
+
with(hash_including({ device_data: "fake-device-data" })).and_call_original
|
230
|
+
authorize
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context 'without device_data' do
|
235
|
+
let(:source) do
|
236
|
+
SolidusBraintree::Source.create!(
|
237
|
+
nonce: 'fake-valid-nonce',
|
238
|
+
user: user,
|
239
|
+
payment_type: payment_type,
|
240
|
+
payment_method: gateway
|
241
|
+
)
|
242
|
+
end
|
243
|
+
|
244
|
+
before do
|
245
|
+
allow_any_instance_of(Braintree::TransactionGateway).to receive(:sale).and_call_original
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'does not pass any device data in the request' do
|
249
|
+
expect_any_instance_of(Braintree::TransactionGateway)
|
250
|
+
.not_to receive(:sale).with(hash_including({ device_data: "" }))
|
251
|
+
|
252
|
+
authorize
|
253
|
+
end
|
254
|
+
end
|
223
255
|
end
|
224
256
|
|
225
257
|
context 'with different merchant account for currency', vcr: {
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require '
|
1
|
+
require 'solidus_braintree_helper'
|
2
|
+
require 'support/solidus_braintree/order_ready_for_payment'
|
2
3
|
|
3
4
|
RSpec.describe SolidusBraintree::Source, type: :model do
|
4
5
|
include_context 'when order is ready for payment'
|
@@ -536,4 +537,19 @@ RSpec.describe SolidusBraintree::Source, type: :model do
|
|
536
537
|
it { is_expected.to be_falsy }
|
537
538
|
end
|
538
539
|
end
|
540
|
+
|
541
|
+
describe "#device_data" do
|
542
|
+
let(:payment_source) { build(:solidus_braintree_source) }
|
543
|
+
|
544
|
+
context "when blank on validation" do
|
545
|
+
before do
|
546
|
+
payment_source.device_data = ""
|
547
|
+
payment_source.valid?
|
548
|
+
end
|
549
|
+
|
550
|
+
it "is set to nil" do
|
551
|
+
expect(payment_source.device_data).to be_nil
|
552
|
+
end
|
553
|
+
end
|
554
|
+
end
|
539
555
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'solidus_braintree_helper'
|
2
2
|
|
3
|
-
describe SolidusBraintree::TransactionImport do
|
3
|
+
RSpec.describe SolidusBraintree::TransactionImport do
|
4
4
|
let(:order) { Spree::Order.new }
|
5
5
|
let!(:country) { create :country, iso: "US" }
|
6
6
|
let(:braintree_gateway) { SolidusBraintree::Gateway.new }
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'solidus_braintree_helper'
|
2
2
|
|
3
|
-
describe Spree::Store do
|
3
|
+
RSpec.describe Spree::Store do
|
4
4
|
describe 'before_create :build_default_configuration' do
|
5
5
|
context 'when a braintree_configuration record already exists' do
|
6
6
|
it 'does not overwrite it' do
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'solidus_starter_frontend_helper'
|
2
|
+
|
3
|
+
require 'support/solidus_braintree/capybara'
|
4
|
+
require 'support/solidus_braintree/factories'
|
5
|
+
require 'support/solidus_braintree/gateway_helpers'
|
6
|
+
require 'support/solidus_braintree/order_walkthrough'
|
7
|
+
require 'support/solidus_braintree/vcr'
|
@@ -28,26 +28,28 @@ FactoryBot.define do
|
|
28
28
|
payment_type { SolidusBraintree::Source::APPLE_PAY }
|
29
29
|
end
|
30
30
|
end
|
31
|
-
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
factory :solidus_braintree_address, parent: :address do
|
33
|
+
trait :with_fixed_zipcode do
|
34
|
+
# The Solidus address factory randomizes the zipcode. The OrderWalkThrough
|
35
|
+
# we use in the credit card checkout spec uses this factory for the user
|
36
|
+
# addresses. For credit card payments we transmit the billing address to
|
37
|
+
# braintree, for paypal payments the shipping address. As we match the
|
38
|
+
# body in our VCR settings VCR can not match the request anymore and
|
39
|
+
# therefore cannot replay existing cassettes.
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
zipcode { '21088-0255' }
|
42
|
+
end
|
43
43
|
|
44
44
|
if SolidusSupport.combined_first_and_last_name_in_address?
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
trait :with_first_and_last_name do
|
46
|
+
transient do
|
47
|
+
firstname { "John" }
|
48
|
+
lastname { "Doe" }
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
+
name { "#{firstname} #{lastname}" }
|
52
|
+
end
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
data/spec/support/{order_ready_for_payment.rb → solidus_braintree/order_ready_for_payment.rb}
RENAMED
@@ -1,8 +1,15 @@
|
|
1
|
-
shared_context 'when order is ready for payment' do
|
1
|
+
RSpec.shared_context 'when order is ready for payment' do
|
2
2
|
let!(:country) { create :country }
|
3
3
|
|
4
4
|
let(:user) { create :user }
|
5
|
-
|
5
|
+
|
6
|
+
let(:address) do
|
7
|
+
create :solidus_braintree_address,
|
8
|
+
:with_first_and_last_name,
|
9
|
+
zipcode: "90210",
|
10
|
+
lastname: "Doe",
|
11
|
+
country: country
|
12
|
+
end
|
6
13
|
|
7
14
|
before do
|
8
15
|
create :shipping_method, cost: 5
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusBraintree
|
4
|
+
class OrderWalkthrough
|
5
|
+
def self.up_to(state, user: nil)
|
6
|
+
new.up_to(state, user: user)
|
7
|
+
end
|
8
|
+
|
9
|
+
def up_to(state, user: nil)
|
10
|
+
# Need to create a valid zone too...
|
11
|
+
@zone = ::FactoryBot.create(:zone)
|
12
|
+
@country = ::FactoryBot.create(:country)
|
13
|
+
@state = ::FactoryBot.create(:state, country: @country)
|
14
|
+
|
15
|
+
@zone.members << ::Spree::ZoneMember.create(zoneable: @country)
|
16
|
+
|
17
|
+
# A shipping method must exist for rates to be displayed on checkout page
|
18
|
+
::FactoryBot.create(:shipping_method, zones: [@zone]).tap do |sm|
|
19
|
+
sm.calculator.preferred_amount = 10
|
20
|
+
sm.calculator.preferred_currency = ::Spree::Config[:currency]
|
21
|
+
sm.calculator.save
|
22
|
+
end
|
23
|
+
|
24
|
+
order = ::Spree::Order.create!(
|
25
|
+
user: user,
|
26
|
+
email: "solidus@example.com",
|
27
|
+
store: ::Spree::Store.first || ::FactoryBot.create(:store)
|
28
|
+
)
|
29
|
+
add_line_item!(order)
|
30
|
+
order.next!
|
31
|
+
|
32
|
+
states_to_process = if state == :complete
|
33
|
+
states
|
34
|
+
else
|
35
|
+
end_state_position = states.index(state.to_sym)
|
36
|
+
states[..end_state_position]
|
37
|
+
end
|
38
|
+
|
39
|
+
states_to_process.each do |state_to_process|
|
40
|
+
send(state_to_process, order)
|
41
|
+
end
|
42
|
+
|
43
|
+
order
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def add_line_item!(order)
|
49
|
+
::FactoryBot.create(:line_item, order: order)
|
50
|
+
order.reload
|
51
|
+
end
|
52
|
+
|
53
|
+
def address(order)
|
54
|
+
order.bill_address =
|
55
|
+
::FactoryBot.create(:solidus_braintree_address, :with_fixed_zipcode, country: @country, state: @state)
|
56
|
+
|
57
|
+
order.ship_address =
|
58
|
+
::FactoryBot.create(:solidus_braintree_address, :with_fixed_zipcode, country: @country, state: @state)
|
59
|
+
|
60
|
+
order.next!
|
61
|
+
end
|
62
|
+
|
63
|
+
def delivery(order)
|
64
|
+
order.next!
|
65
|
+
end
|
66
|
+
|
67
|
+
def payment(order)
|
68
|
+
credit_card = ::FactoryBot.create(:credit_card, user: order.user)
|
69
|
+
order.payments.create!(payment_method: credit_card.payment_method, amount: order.total, source: credit_card)
|
70
|
+
# TODO: maybe look at some way of making this payment_state change automatic
|
71
|
+
order.payment_state = 'paid'
|
72
|
+
order.next!
|
73
|
+
end
|
74
|
+
|
75
|
+
def confirm(order)
|
76
|
+
order.complete!
|
77
|
+
end
|
78
|
+
|
79
|
+
def complete(order)
|
80
|
+
# noop?
|
81
|
+
end
|
82
|
+
|
83
|
+
def states
|
84
|
+
[:address, :delivery, :payment, :confirm]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.shared_context 'with prepended view fixtures' do
|
4
|
+
let(:view_fixtures_path) { 'spec/fixtures/views' }
|
5
|
+
|
6
|
+
before do
|
7
|
+
ApplicationController.prepend_view_path view_fixtures_path
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
view_paths = ApplicationController.view_paths.to_a
|
12
|
+
|
13
|
+
view_paths.delete_if do |view_path|
|
14
|
+
view_path.to_path.match?(/#{view_fixtures_path}$/)
|
15
|
+
end
|
16
|
+
|
17
|
+
ApplicationController.view_paths = view_paths
|
18
|
+
end
|
19
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'solidus_braintree_helper'
|
2
2
|
|
3
|
-
RSpec.describe "viewing the configuration interface" do
|
3
|
+
RSpec.describe "viewing the configuration interface", type: :feature do
|
4
4
|
stub_authorization!
|
5
5
|
|
6
6
|
# Regression to ensure this page still renders on old versions of solidus
|
@@ -1,7 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require 'spree/testing_support/order_walkthrough'
|
1
|
+
require 'solidus_braintree_helper'
|
3
2
|
|
4
|
-
shared_context "with backend checkout setup" do
|
3
|
+
RSpec.shared_context "with backend checkout setup" do
|
5
4
|
let(:braintree) { new_gateway(active: true) }
|
6
5
|
let!(:gateway) { create :payment_method }
|
7
6
|
let(:order) { create(:completed_order_with_totals, number: 'R9999999') }
|
@@ -26,7 +25,7 @@ shared_context "with backend checkout setup" do
|
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
|
-
describe 'creating a new payment', type: :feature, js: true do
|
28
|
+
RSpec.describe 'creating a new payment', type: :feature, js: true do
|
30
29
|
stub_authorization!
|
31
30
|
|
32
31
|
context "with valid credit card data", vcr: {
|
@@ -1,7 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require 'spree/testing_support/order_walkthrough'
|
1
|
+
require 'solidus_braintree_helper'
|
3
2
|
|
4
|
-
shared_context "with frontend checkout setup" do
|
3
|
+
RSpec.shared_context "with frontend checkout setup" do
|
5
4
|
let(:braintree) { new_gateway(active: true) }
|
6
5
|
let!(:gateway) { create :payment_method }
|
7
6
|
let(:three_d_secure_enabled) { false }
|
@@ -26,7 +25,7 @@ shared_context "with frontend checkout setup" do
|
|
26
25
|
end
|
27
26
|
|
28
27
|
order = if Spree.solidus_gem_version >= Gem::Version.new('2.6.0')
|
29
|
-
|
28
|
+
SolidusBraintree::OrderWalkthrough.up_to(:delivery)
|
30
29
|
else
|
31
30
|
OrderWalkthrough.up_to(:delivery)
|
32
31
|
end
|
@@ -36,13 +35,13 @@ shared_context "with frontend checkout setup" do
|
|
36
35
|
order.number = "R9999999"
|
37
36
|
order.recalculate
|
38
37
|
|
39
|
-
allow_any_instance_of(
|
40
|
-
allow_any_instance_of(
|
41
|
-
allow_any_instance_of(
|
38
|
+
allow_any_instance_of(CheckoutsController).to receive_messages(current_order: order)
|
39
|
+
allow_any_instance_of(CheckoutsController).to receive_messages(try_spree_current_user: user)
|
40
|
+
allow_any_instance_of(CheckoutsController).to receive_messages(spree_current_user: user)
|
42
41
|
allow_any_instance_of(Spree::Payment).to receive(:number).and_return("123ABC")
|
43
42
|
allow_any_instance_of(SolidusBraintree::Source).to receive(:nonce).and_return("fake-valid-nonce")
|
44
43
|
|
45
|
-
visit
|
44
|
+
visit checkout_state_path(:delivery)
|
46
45
|
click_button "Save and Continue"
|
47
46
|
choose("Braintree")
|
48
47
|
end
|
@@ -52,12 +51,12 @@ shared_context "with frontend checkout setup" do
|
|
52
51
|
end
|
53
52
|
end
|
54
53
|
|
55
|
-
describe 'entering credit card details', type: :feature, js: true do
|
54
|
+
RSpec.describe 'entering credit card details', type: :feature, js: true do
|
56
55
|
context 'when page loads' do
|
57
56
|
include_context "with frontend checkout setup"
|
58
57
|
|
59
58
|
it "selectors display correctly" do
|
60
|
-
expect(page).to have_selector("
|
59
|
+
expect(page).to have_selector("fieldset[name='payment-method-#{braintree.id}']", visible: :visible)
|
61
60
|
expect(page).to have_selector("iframe#braintree-hosted-field-number")
|
62
61
|
expect(page).to have_selector("iframe[type='number']")
|
63
62
|
end
|
@@ -98,9 +97,12 @@ describe 'entering credit card details', type: :feature, js: true do
|
|
98
97
|
end
|
99
98
|
|
100
99
|
it "checks out successfully" do
|
101
|
-
within("
|
100
|
+
within(".confirm-step") do
|
102
101
|
expect(page).to have_content("CONFIRM")
|
103
102
|
end
|
103
|
+
|
104
|
+
check('accept_terms_and_conditions')
|
105
|
+
|
104
106
|
click_button("Place Order")
|
105
107
|
expect(page).to have_content("Your order has been processed successfully")
|
106
108
|
end
|
@@ -111,10 +113,12 @@ describe 'entering credit card details', type: :feature, js: true do
|
|
111
113
|
it 'checks out successfully' do
|
112
114
|
authenticate_3ds
|
113
115
|
|
114
|
-
within("
|
116
|
+
within(".confirm-step") do
|
115
117
|
expect(page).to have_content("CONFIRM")
|
116
118
|
end
|
117
119
|
|
120
|
+
check('accept_terms_and_conditions')
|
121
|
+
|
118
122
|
click_button("Place Order")
|
119
123
|
expect(page).to have_content("Your order has been processed successfully")
|
120
124
|
end
|
@@ -142,13 +146,13 @@ describe 'entering credit card details', type: :feature, js: true do
|
|
142
146
|
|
143
147
|
it "displays an alert with a meaningful error message" do
|
144
148
|
expect(page).to have_text I18n.t("solidus_braintree.errors.empty_fields")
|
145
|
-
expect(page).to have_selector("
|
149
|
+
expect(page).to have_selector("[type='submit']:enabled")
|
146
150
|
end
|
147
151
|
|
148
152
|
# Same error should be produced when submitting an empty form again
|
149
153
|
context "when user tries to resubmit an empty form", vcr: { cassette_name: "checkout/invalid_credit_card" } do
|
150
154
|
it "displays an alert with a meaningful error message" do
|
151
|
-
expect(page).to have_selector("
|
155
|
+
expect(page).to have_selector("[type='submit']:enabled")
|
152
156
|
|
153
157
|
click_button "Save and Continue"
|
154
158
|
expect(page).to have_text I18n.t("solidus_braintree.errors.empty_fields")
|
@@ -171,9 +175,13 @@ describe 'entering credit card details', type: :feature, js: true do
|
|
171
175
|
fill_in("cvv", with: "123")
|
172
176
|
end
|
173
177
|
click_button("Save and Continue")
|
174
|
-
|
178
|
+
|
179
|
+
within(".confirm-step") do
|
175
180
|
expect(page).to have_content("CONFIRM")
|
176
181
|
end
|
182
|
+
|
183
|
+
check('accept_terms_and_conditions')
|
184
|
+
|
177
185
|
click_button("Place Order")
|
178
186
|
expect(page).to have_content("Your order has been processed successfully")
|
179
187
|
end
|
@@ -1,6 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'solidus_braintree_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'
|
2
6
|
|
3
|
-
describe "Checkout", type: :feature, js: true do
|
4
7
|
Capybara.default_max_wait_time = 60
|
5
8
|
|
6
9
|
# let!(:store) do
|
@@ -149,7 +152,7 @@ describe "Checkout", type: :feature, js: true do
|
|
149
152
|
end
|
150
153
|
|
151
154
|
def add_mug_to_cart
|
152
|
-
visit
|
155
|
+
visit root_path
|
153
156
|
click_link mug.name
|
154
157
|
click_button "add-to-cart-button"
|
155
158
|
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'spree/testing_support/order_walkthrough'
|
3
|
+
require 'solidus_braintree_helper'
|
5
4
|
|
6
|
-
describe "Checkout", type: :feature, js: true do
|
5
|
+
RSpec.describe "Checkout", type: :feature, js: true do
|
7
6
|
let(:braintree_preferences) { { venmo: true }.merge(preferences) }
|
8
7
|
let(:preferences) { {} }
|
9
8
|
let(:user) { create(:user) }
|
@@ -134,22 +133,22 @@ describe "Checkout", type: :feature, js: true do
|
|
134
133
|
|
135
134
|
def go_to_payment_checkout_page(order_number: 'R300000001' )
|
136
135
|
order = if Spree.solidus_gem_version >= Gem::Version.new('2.6.0')
|
137
|
-
|
136
|
+
SolidusBraintree::OrderWalkthrough.up_to(:address)
|
138
137
|
else
|
139
138
|
OrderWalkthrough.up_to(:address)
|
140
139
|
end
|
141
140
|
|
142
141
|
order.update!(user: user, number: order_number) # constant order number for VCRs
|
143
142
|
|
144
|
-
allow_any_instance_of(
|
143
|
+
allow_any_instance_of(CheckoutsController).to receive_messages(current_order: order)
|
145
144
|
|
146
145
|
first_user = Spree::User.first
|
147
|
-
allow_any_instance_of(
|
148
|
-
allow_any_instance_of(
|
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)
|
149
148
|
|
150
149
|
allow_any_instance_of(Spree::Payment).to receive(:gateway_order_id).and_return(order_number)
|
151
150
|
|
152
|
-
visit
|
151
|
+
visit checkout_state_path(order.state)
|
153
152
|
next_checkout_step
|
154
153
|
end
|
155
154
|
|
@@ -188,7 +187,7 @@ describe "Checkout", type: :feature, js: true do
|
|
188
187
|
|
189
188
|
def disable_hosted_fields_form_listener
|
190
189
|
# Once the submit button is enabled, the submit listener has been added
|
191
|
-
find("#checkout_form_payment
|
190
|
+
find("#checkout_form_payment [type='submit']:not(:disabled)")
|
192
191
|
page.execute_script("$('#checkout_form_payment').off('submit');")
|
193
192
|
end
|
194
193
|
end
|