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.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/lint.yml +25 -0
- data/.github/workflows/test.yml +77 -0
- data/.rubocop.yml +5 -84
- data/.standard.yml +6 -0
- data/7.2 +0 -0
- data/Gemfile +12 -20
- data/README.md +7 -5
- data/Rakefile +7 -7
- data/app/helpers/solidus_braintree/braintree_admin_helper.rb +4 -4
- data/app/models/solidus_braintree/avs_result.rb +34 -34
- data/app/models/solidus_braintree/base_record.rb +11 -0
- data/app/models/solidus_braintree/configuration.rb +12 -12
- data/app/models/solidus_braintree/customer.rb +1 -1
- data/app/models/solidus_braintree/gateway.rb +14 -17
- data/app/models/solidus_braintree/response.rb +9 -9
- data/app/models/solidus_braintree/source.rb +9 -7
- data/app/models/solidus_braintree/transaction.rb +2 -2
- data/app/models/solidus_braintree/transaction_address.rb +5 -5
- data/app/models/solidus_braintree/transaction_import.rb +2 -2
- data/app/{decorators/models/solidus_braintree/spree_store_decorator.rb → patches/models/solidus_braintree/spree_store_patch.rb} +1 -1
- data/app/{decorators/models/solidus_braintree/spree_user_decorator.rb → patches/models/solidus_braintree/spree_user_patch.rb} +2 -2
- data/bin/dummy-app +23 -3
- data/bin/rails-sandbox +4 -4
- data/bin/rspec +6 -0
- data/bin/sandbox +55 -31
- data/db/migrate/20161114231422_create_solidus_paypal_braintree_configurations.rb +2 -2
- data/db/migrate/20170508085402_add_not_null_constraint_to_sources_payment_type.rb +2 -2
- data/db/migrate/20230109080950_rename_solidus_paypal_braintree_source_type.rb +3 -3
- data/{app/decorators/controllers → lib/controllers/api}/solidus_braintree/client_tokens_controller.rb +2 -2
- data/lib/controllers/backend/solidus_braintree/configurations_controller.rb +4 -4
- data/lib/generators/solidus_braintree/install/install_generator.rb +48 -40
- data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/checkouts_controller.rb +7 -7
- data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/transactions_controller.rb +7 -7
- data/lib/generators/solidus_braintree/install/templates/app/helpers/solidus_braintree/braintree_checkout_helper.rb +5 -5
- data/{app/decorators/controllers/solidus_braintree/admin_payments_controller_decorator.rb → lib/patches/backend/controllers/solidus_braintree/admin_payments_controller_patch.rb} +1 -1
- data/lib/solidus_braintree/engine.rb +13 -24
- data/lib/solidus_braintree/extension_configuration.rb +1 -1
- data/lib/solidus_braintree/request_protection.rb +2 -2
- data/lib/solidus_braintree/version.rb +1 -1
- data/lib/solidus_braintree.rb +8 -10
- data/lib/solidus_paypal_braintree.rb +2 -2
- data/mise.toml +2 -0
- data/solidus_braintree.gemspec +23 -22
- metadata +62 -152
- data/.circleci/config.yml +0 -80
- data/app/models/application_record.rb +0 -5
- data/lib/views/backend_v1.2/spree/admin/payments/source_forms/_braintree.html.erb +0 -16
- data/lib/views/backend_v2.4/spree/admin/shared/preference_fields/_hash.html.erb +0 -12
- data/spec/controllers/solidus_braintree/checkouts_controller_spec.rb +0 -99
- data/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb +0 -55
- data/spec/controllers/solidus_braintree/configurations_controller_spec.rb +0 -73
- data/spec/controllers/solidus_braintree/transactions_controller_spec.rb +0 -183
- data/spec/fixtures/cassettes/admin/invalid_credit_card.yml +0 -63
- data/spec/fixtures/cassettes/admin/resubmit_credit_card.yml +0 -352
- data/spec/fixtures/cassettes/admin/valid_credit_card.yml +0 -412
- data/spec/fixtures/cassettes/braintree/create_profile.yml +0 -71
- data/spec/fixtures/cassettes/braintree/generate_token.yml +0 -63
- data/spec/fixtures/cassettes/braintree/token.yml +0 -63
- data/spec/fixtures/cassettes/checkout/invalid_credit_card.yml +0 -63
- data/spec/fixtures/cassettes/checkout/resubmit_credit_card.yml +0 -216
- data/spec/fixtures/cassettes/checkout/update.yml +0 -71
- data/spec/fixtures/cassettes/checkout/valid_credit_card.yml +0 -171
- data/spec/fixtures/cassettes/checkout/valid_venmo_transaction.yml +0 -599
- data/spec/fixtures/cassettes/gateway/authorize/credit_card/address.yml +0 -86
- data/spec/fixtures/cassettes/gateway/authorize/merchant_account/EUR.yml +0 -154
- data/spec/fixtures/cassettes/gateway/authorize/paypal/EUR.yml +0 -90
- data/spec/fixtures/cassettes/gateway/authorize/paypal/address.yml +0 -90
- data/spec/fixtures/cassettes/gateway/authorize.yml +0 -86
- data/spec/fixtures/cassettes/gateway/authorized_transaction.yml +0 -73
- data/spec/fixtures/cassettes/gateway/cancel/missing.yml +0 -63
- data/spec/fixtures/cassettes/gateway/cancel/refunds.yml +0 -272
- data/spec/fixtures/cassettes/gateway/cancel/void.yml +0 -201
- data/spec/fixtures/cassettes/gateway/capture.yml +0 -141
- data/spec/fixtures/cassettes/gateway/complete.yml +0 -157
- data/spec/fixtures/cassettes/gateway/credit.yml +0 -208
- data/spec/fixtures/cassettes/gateway/customer.yml +0 -79
- data/spec/fixtures/cassettes/gateway/purchase.yml +0 -87
- data/spec/fixtures/cassettes/gateway/settled_transaction.yml +0 -140
- data/spec/fixtures/cassettes/gateway/void.yml +0 -137
- data/spec/fixtures/cassettes/source/bin.yml +0 -295
- data/spec/fixtures/cassettes/source/card_type.yml +0 -267
- data/spec/fixtures/cassettes/source/last4.yml +0 -267
- data/spec/fixtures/cassettes/transaction/import/valid/capture.yml +0 -224
- data/spec/fixtures/cassettes/transaction/import/valid.yml +0 -71
- data/spec/fixtures/views/carts/_cart_footer.html.erb +0 -18
- data/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb +0 -17
- data/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb +0 -70
- data/spec/models/solidus_braintree/address_spec.rb +0 -71
- data/spec/models/solidus_braintree/avs_result_spec.rb +0 -317
- data/spec/models/solidus_braintree/gateway_spec.rb +0 -774
- data/spec/models/solidus_braintree/response_spec.rb +0 -280
- data/spec/models/solidus_braintree/source_spec.rb +0 -555
- data/spec/models/solidus_braintree/transaction_address_spec.rb +0 -235
- data/spec/models/solidus_braintree/transaction_import_spec.rb +0 -302
- data/spec/models/solidus_braintree/transaction_spec.rb +0 -86
- data/spec/models/spree/store_spec.rb +0 -14
- data/spec/requests/spree/api/orders_controller_spec.rb +0 -36
- data/spec/solidus_braintree_spec_helper.rb +0 -9
- data/spec/support/solidus_braintree/capybara.rb +0 -7
- data/spec/support/solidus_braintree/factories.rb +0 -55
- data/spec/support/solidus_braintree/gateway_helpers.rb +0 -29
- data/spec/support/solidus_braintree/order_ready_for_payment.rb +0 -44
- data/spec/support/solidus_braintree/order_walkthrough.rb +0 -87
- data/spec/support/solidus_braintree/vcr.rb +0 -38
- data/spec/support/solidus_braintree/with_prepended_view_fixtures.rb +0 -19
- data/spec/system/backend/configuration_spec.rb +0 -23
- data/spec/system/backend/new_payment_spec.rb +0 -136
- data/spec/system/frontend/braintree_credit_card_checkout_spec.rb +0 -199
- data/spec/system/frontend/paypal_checkout_spec.rb +0 -168
- data/spec/system/frontend/venmo_checkout_spec.rb +0 -193
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
FactoryBot.define do
|
|
4
|
-
# Define your Spree extensions Factories within this file to enable applications,
|
|
5
|
-
# and other extensions to use and override them.
|
|
6
|
-
#
|
|
7
|
-
# Example adding this to your spec_helper will load these Factories for use:
|
|
8
|
-
# require 'solidus_braintree/factories'
|
|
9
|
-
|
|
10
|
-
factory :solidus_braintree_payment_method, class: SolidusBraintree::Gateway do
|
|
11
|
-
name { 'Solidus Braintree Gateway' }
|
|
12
|
-
active { true }
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
factory :solidus_braintree_source, class: SolidusBraintree::Source do
|
|
16
|
-
association(:payment_method, factory: :solidus_braintree_payment_method)
|
|
17
|
-
user
|
|
18
|
-
|
|
19
|
-
trait :credit_card do
|
|
20
|
-
payment_type { SolidusBraintree::Source::CREDIT_CARD }
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
trait :paypal do
|
|
24
|
-
payment_type { SolidusBraintree::Source::PAYPAL }
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
trait :apple_pay do
|
|
28
|
-
payment_type { SolidusBraintree::Source::APPLE_PAY }
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
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
|
-
|
|
41
|
-
zipcode { '21088-0255' }
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
if SolidusSupport.combined_first_and_last_name_in_address?
|
|
45
|
-
trait :with_first_and_last_name do
|
|
46
|
-
transient do
|
|
47
|
-
firstname { "John" }
|
|
48
|
-
lastname { "Doe" }
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
name { "#{firstname} #{lastname}" }
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
module SolidusBraintree
|
|
2
|
-
module GatewayHelpers
|
|
3
|
-
def new_gateway(opts = {})
|
|
4
|
-
SolidusBraintree::Gateway.new({
|
|
5
|
-
name: "Braintree",
|
|
6
|
-
preferences: {
|
|
7
|
-
environment: 'sandbox',
|
|
8
|
-
public_key: ENV.fetch('BRAINTREE_PUBLIC_KEY', 'dummy_public_key'),
|
|
9
|
-
private_key: ENV.fetch('BRAINTREE_PRIVATE_KEY', 'dummy_private_key'),
|
|
10
|
-
merchant_id: ENV.fetch('BRAINTREE_MERCHANT_ID', 'dummy_merchant_id'),
|
|
11
|
-
merchant_currency_map: {
|
|
12
|
-
'EUR' => 'stembolt_EUR'
|
|
13
|
-
},
|
|
14
|
-
paypal_payee_email_map: {
|
|
15
|
-
'EUR' => ENV.fetch('BRAINTREE_PAYPAL_PAYEE_EMAIL', 'paypal+europe@example.com')
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}.merge(opts))
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def create_gateway(opts = {})
|
|
22
|
-
new_gateway(opts).tap(&:save!)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
RSpec.configure do |config|
|
|
28
|
-
config.include SolidusBraintree::GatewayHelpers
|
|
29
|
-
end
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
RSpec.shared_context 'when order is ready for payment' do
|
|
2
|
-
let!(:country) { create :country }
|
|
3
|
-
|
|
4
|
-
let(:user) { create :user }
|
|
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
|
|
13
|
-
|
|
14
|
-
before do
|
|
15
|
-
create :shipping_method, cost: 5
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
let(:gateway) do
|
|
19
|
-
new_gateway(auto_capture: true)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
let(:order) do
|
|
23
|
-
order = Spree::Order.create!(
|
|
24
|
-
line_items: create_list(:line_item, 1, price: 50),
|
|
25
|
-
email: 'test@example.com',
|
|
26
|
-
bill_address: address,
|
|
27
|
-
ship_address: address,
|
|
28
|
-
user: user
|
|
29
|
-
)
|
|
30
|
-
order.recalculate
|
|
31
|
-
|
|
32
|
-
expect(order.state).to eq "cart"
|
|
33
|
-
|
|
34
|
-
# push through cart, address and delivery
|
|
35
|
-
# its sadly unsafe to use any reasonable factory here accross
|
|
36
|
-
# supported solidus versions
|
|
37
|
-
order.next!
|
|
38
|
-
order.next!
|
|
39
|
-
order.next!
|
|
40
|
-
|
|
41
|
-
expect(order.state).to eq "payment"
|
|
42
|
-
order
|
|
43
|
-
end
|
|
44
|
-
end
|
|
@@ -1,87 +0,0 @@
|
|
|
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
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
require 'vcr'
|
|
2
|
-
require 'webmock'
|
|
3
|
-
|
|
4
|
-
VCR.configure do |c|
|
|
5
|
-
c.cassette_library_dir = "spec/fixtures/cassettes"
|
|
6
|
-
c.hook_into :webmock
|
|
7
|
-
c.configure_rspec_metadata!
|
|
8
|
-
c.default_cassette_options = {
|
|
9
|
-
match_requests_on: [:method, :uri, :body]
|
|
10
|
-
}
|
|
11
|
-
c.allow_http_connections_when_no_cassette = false
|
|
12
|
-
c.ignore_localhost = true
|
|
13
|
-
c.ignore_hosts 'chromedriver.storage.googleapis.com'
|
|
14
|
-
|
|
15
|
-
# client token used for the fronted JS lib cannot be mocked:
|
|
16
|
-
# it contains a cryptographically signed string containing the merchant id
|
|
17
|
-
# that's sent back to braintree's server by the JS lib
|
|
18
|
-
c.ignore_request do |request|
|
|
19
|
-
!(request.uri =~ %r{/merchants/\w+/client_token\z}).nil?
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# match a request to Braintree sandbox APIs by ignoring the merchant ID
|
|
23
|
-
# in the request URI
|
|
24
|
-
c.register_request_matcher :braintree_uri do |request1, request2|
|
|
25
|
-
extract_url_resource = lambda do |uri|
|
|
26
|
-
uri_match_pattern =
|
|
27
|
-
%r{\Ahttps://api\.sandbox\.braintreegateway\.com/merchants/\w+(/.*)\z}
|
|
28
|
-
|
|
29
|
-
if match = uri.match(uri_match_pattern)
|
|
30
|
-
match.captures.first
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
r1_resource = extract_url_resource.call(request1.uri)
|
|
34
|
-
r2_resource = extract_url_resource.call(request2.uri)
|
|
35
|
-
|
|
36
|
-
!r1_resource.nil? && r1_resource == r2_resource
|
|
37
|
-
end
|
|
38
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
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,23 +0,0 @@
|
|
|
1
|
-
require 'solidus_braintree_spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe "viewing the configuration interface", type: :feature do
|
|
4
|
-
stub_authorization!
|
|
5
|
-
|
|
6
|
-
# Regression to ensure this page still renders on old versions of solidus
|
|
7
|
-
it "doesn't raise any errors due to unavailable route helpers" do
|
|
8
|
-
visit "/solidus_braintree/configurations/list"
|
|
9
|
-
expect(page).to have_content("Braintree Configurations")
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# Regression to ensure this page renders on Solidus 2.4
|
|
13
|
-
it "doesn't raise any errors due to unavailable preference field partial" do
|
|
14
|
-
Rails.application.config.spree.payment_methods << SolidusBraintree::Gateway
|
|
15
|
-
Spree::PaymentMethod.create!(
|
|
16
|
-
type: 'SolidusBraintree::Gateway',
|
|
17
|
-
name: 'Braintree Payments'
|
|
18
|
-
)
|
|
19
|
-
visit '/admin/payment_methods'
|
|
20
|
-
page.find('a[title="Edit"]').click
|
|
21
|
-
expect(page).to have_field 'Name', with: 'Braintree Payments'
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
require 'solidus_braintree_spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.shared_context "with backend checkout setup" do
|
|
4
|
-
let(:braintree) { new_gateway(active: true) }
|
|
5
|
-
let!(:gateway) { create :payment_method }
|
|
6
|
-
let(:order) { create(:completed_order_with_totals, number: 'R9999999') }
|
|
7
|
-
let(:pending_case_insensitive) { /pending/i }
|
|
8
|
-
let(:expiration) { "02/#{Date.current.year.next}" }
|
|
9
|
-
|
|
10
|
-
before do
|
|
11
|
-
braintree.save!
|
|
12
|
-
create(:store, payment_methods: [gateway, braintree]).tap do |store|
|
|
13
|
-
store.braintree_configuration.update!(credit_card: true)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
allow_any_instance_of(SolidusBraintree::Source).to receive(:nonce).and_return("fake-valid-nonce")
|
|
17
|
-
|
|
18
|
-
# Order and payment numbers must be identical between runs to re-use the VCR
|
|
19
|
-
# cassette
|
|
20
|
-
allow_any_instance_of(Spree::Payment).to receive(:number).and_return("123ABC")
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
around do |example|
|
|
24
|
-
Capybara.using_wait_time(20) { example.run }
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
RSpec.describe 'creating a new payment', type: :feature, js: true do
|
|
29
|
-
stub_authorization!
|
|
30
|
-
|
|
31
|
-
context "with valid credit card data", vcr: {
|
|
32
|
-
cassette_name: 'admin/valid_credit_card',
|
|
33
|
-
match_requests_on: [:braintree_uri]
|
|
34
|
-
} do
|
|
35
|
-
include_context "with backend checkout setup"
|
|
36
|
-
|
|
37
|
-
it "checks out successfully" do
|
|
38
|
-
visit "/admin/orders/#{order.number}/payments/new"
|
|
39
|
-
choose('Braintree')
|
|
40
|
-
expect(page).to have_selector("#payment_method_#{braintree.id}", visible: :visible)
|
|
41
|
-
expect(page).to have_selector("iframe#braintree-hosted-field-number")
|
|
42
|
-
|
|
43
|
-
within_frame("braintree-hosted-field-number") do
|
|
44
|
-
fill_in("credit-card-number", with: "4111111111111111")
|
|
45
|
-
end
|
|
46
|
-
within_frame("braintree-hosted-field-expirationDate") do
|
|
47
|
-
fill_in("expiration", with: expiration)
|
|
48
|
-
end
|
|
49
|
-
within_frame("braintree-hosted-field-cvv") do
|
|
50
|
-
fill_in("cvv", with: "123")
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
click_button("Update")
|
|
54
|
-
|
|
55
|
-
within('table#payments') do
|
|
56
|
-
expect(page).to have_content('Braintree')
|
|
57
|
-
expect(page).to have_content(pending_case_insensitive)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
click_icon(:capture)
|
|
61
|
-
|
|
62
|
-
expect(page).not_to have_content('Cannot perform requested operation')
|
|
63
|
-
expect(page).to have_content('Payment Updated')
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
context "with invalid credit card data" do
|
|
68
|
-
include_context "with backend checkout setup"
|
|
69
|
-
|
|
70
|
-
# Attempt to submit an invalid form once
|
|
71
|
-
before do
|
|
72
|
-
visit "/admin/orders/#{order.number}/payments/new"
|
|
73
|
-
choose('Braintree')
|
|
74
|
-
|
|
75
|
-
within_frame("braintree-hosted-field-number") do
|
|
76
|
-
fill_in("credit-card-number", with: "1111111111111111")
|
|
77
|
-
end
|
|
78
|
-
within_frame("braintree-hosted-field-expirationDate") do
|
|
79
|
-
fill_in("expiration", with: expiration)
|
|
80
|
-
end
|
|
81
|
-
within_frame("braintree-hosted-field-cvv") do
|
|
82
|
-
fill_in("cvv", with: "123")
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
click_button "Update"
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it "displays a meaningful error message" do
|
|
89
|
-
expect(page).to have_text(
|
|
90
|
-
"BraintreeError: Some payment input fields are invalid. Cannot tokenize invalid card fields."
|
|
91
|
-
)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
# Same error should be produced when submitting an empty form again
|
|
95
|
-
context "when user tries to resubmit another invalid form", vcr: {
|
|
96
|
-
cassette_name: "admin/invalid_credit_card",
|
|
97
|
-
match_requests_on: [:braintree_uri]
|
|
98
|
-
} do
|
|
99
|
-
it "displays a meaningful error message" do
|
|
100
|
-
click_button "Update"
|
|
101
|
-
expect(page).to have_text(
|
|
102
|
-
"BraintreeError: Some payment input fields are invalid. Cannot tokenize invalid card fields."
|
|
103
|
-
)
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# User should be able to checkout after submit fails once
|
|
108
|
-
context "when user enters valid data", vcr: {
|
|
109
|
-
cassette_name: "admin/resubmit_credit_card",
|
|
110
|
-
match_requests_on: [:braintree_uri]
|
|
111
|
-
} do
|
|
112
|
-
it "creates the payment successfully" do
|
|
113
|
-
within_frame("braintree-hosted-field-number") do
|
|
114
|
-
fill_in("credit-card-number", with: "4111111111111111")
|
|
115
|
-
end
|
|
116
|
-
within_frame("braintree-hosted-field-expirationDate") do
|
|
117
|
-
fill_in("expiration", with: expiration)
|
|
118
|
-
end
|
|
119
|
-
within_frame("braintree-hosted-field-cvv") do
|
|
120
|
-
fill_in("cvv", with: "123")
|
|
121
|
-
end
|
|
122
|
-
click_button("Update")
|
|
123
|
-
|
|
124
|
-
within('table#payments') do
|
|
125
|
-
expect(page).to have_content('Braintree')
|
|
126
|
-
expect(page).to have_content(pending_case_insensitive)
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
click_icon(:capture)
|
|
130
|
-
|
|
131
|
-
expect(page).not_to have_content('Cannot perform requested operation')
|
|
132
|
-
expect(page).to have_content('Payment Updated')
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
end
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
require 'solidus_braintree_spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.shared_context "with frontend checkout setup" do
|
|
4
|
-
let(:braintree) { new_gateway(active: true) }
|
|
5
|
-
let!(:gateway) { create :payment_method }
|
|
6
|
-
let(:three_d_secure_enabled) { false }
|
|
7
|
-
let(:venmo_enabled) { false }
|
|
8
|
-
let(:card_number) { "4111111111111111" }
|
|
9
|
-
let(:card_expiration) { "01/#{Time.now.utc.year + 3}" }
|
|
10
|
-
|
|
11
|
-
before do
|
|
12
|
-
braintree.save!
|
|
13
|
-
|
|
14
|
-
create(:store, payment_methods: [gateway, braintree]).tap do |store|
|
|
15
|
-
store.braintree_configuration.update!(
|
|
16
|
-
credit_card: true,
|
|
17
|
-
three_d_secure: three_d_secure_enabled,
|
|
18
|
-
venmo: venmo_enabled
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
braintree.update(
|
|
22
|
-
preferred_credit_card_fields_style: { input: { 'font-size': '30px' } },
|
|
23
|
-
preferred_placeholder_text: { number: "Enter Your Card Number" }
|
|
24
|
-
)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
order = if Spree.solidus_gem_version >= Gem::Version.new('2.6.0')
|
|
28
|
-
SolidusBraintree::OrderWalkthrough.up_to(:delivery)
|
|
29
|
-
else
|
|
30
|
-
OrderWalkthrough.up_to(:delivery)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
user = create(:user)
|
|
34
|
-
order.user = user
|
|
35
|
-
order.number = "R9999999"
|
|
36
|
-
order.recalculate
|
|
37
|
-
|
|
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)
|
|
41
|
-
allow_any_instance_of(Spree::Payment).to receive(:number).and_return("123ABC")
|
|
42
|
-
allow_any_instance_of(SolidusBraintree::Source).to receive(:nonce).and_return("fake-valid-nonce")
|
|
43
|
-
|
|
44
|
-
visit checkout_state_path(:delivery)
|
|
45
|
-
click_button "Save and Continue"
|
|
46
|
-
choose("Braintree")
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
around do |example|
|
|
50
|
-
Capybara.using_wait_time(20) { example.run }
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
RSpec.describe 'entering credit card details', type: :feature, js: true do
|
|
55
|
-
context 'when page loads' do
|
|
56
|
-
include_context "with frontend checkout setup"
|
|
57
|
-
|
|
58
|
-
it "selectors display correctly" do
|
|
59
|
-
expect(page).to have_selector("fieldset[name='payment-method-#{braintree.id}']", visible: :visible)
|
|
60
|
-
expect(page).to have_selector("iframe#braintree-hosted-field-number")
|
|
61
|
-
expect(page).to have_selector("iframe[type='number']")
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "credit card field style variable is set" do
|
|
65
|
-
within_frame("braintree-hosted-field-number") do
|
|
66
|
-
expect(find("#credit-card-number").style("font-size")).to eq({ "font-size" => "30px" })
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "sets the placeholder text correctly" do
|
|
71
|
-
within_frame("braintree-hosted-field-number") do
|
|
72
|
-
expect(find("#credit-card-number")['placeholder']).to eq("Enter Your Card Number")
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
context "with valid credit card data", vcr: {
|
|
78
|
-
cassette_name: 'checkout/valid_credit_card',
|
|
79
|
-
match_requests_on: [:braintree_uri]
|
|
80
|
-
} do
|
|
81
|
-
include_context "with frontend checkout setup"
|
|
82
|
-
# To ensure Venmo inputs do not conflict with checkout
|
|
83
|
-
let(:venmo_enabled) { true }
|
|
84
|
-
|
|
85
|
-
before do
|
|
86
|
-
within_frame("braintree-hosted-field-number") do
|
|
87
|
-
fill_in("credit-card-number", with: card_number)
|
|
88
|
-
end
|
|
89
|
-
within_frame("braintree-hosted-field-expirationDate") do
|
|
90
|
-
fill_in("expiration", with: card_expiration)
|
|
91
|
-
end
|
|
92
|
-
within_frame("braintree-hosted-field-cvv") do
|
|
93
|
-
fill_in("cvv", with: "123")
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
click_button("Save and Continue")
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "checks out successfully" do
|
|
100
|
-
within(".confirm-step") do
|
|
101
|
-
expect(page).to have_content(/confirm/i)
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
check('accept_terms_and_conditions')
|
|
105
|
-
|
|
106
|
-
click_button("Place Order")
|
|
107
|
-
expect(page).to have_content("Your order has been processed successfully")
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
context 'with 3D secure enabled' do
|
|
111
|
-
let(:three_d_secure_enabled) { true }
|
|
112
|
-
|
|
113
|
-
it 'checks out successfully' do
|
|
114
|
-
authenticate_3ds
|
|
115
|
-
|
|
116
|
-
within(".confirm-step") do
|
|
117
|
-
expect(page).to have_content(/confirm/i)
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
check('accept_terms_and_conditions')
|
|
121
|
-
|
|
122
|
-
click_button("Place Order")
|
|
123
|
-
expect(page).to have_content("Your order has been processed successfully")
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
context 'with 3ds authentication error' do
|
|
127
|
-
let(:card_number) { "4000000000001125" }
|
|
128
|
-
|
|
129
|
-
it 'shows a 3ds authentication error' do
|
|
130
|
-
authenticate_3ds
|
|
131
|
-
expect(page).to have_content(
|
|
132
|
-
"3D Secure authentication failed. Please try again using a different payment method."
|
|
133
|
-
)
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
context "with invalid credit card data" do
|
|
140
|
-
include_context "with frontend checkout setup"
|
|
141
|
-
|
|
142
|
-
# Attempt to submit an empty form once
|
|
143
|
-
before do
|
|
144
|
-
click_button "Save and Continue"
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
it "displays an alert with a meaningful error message" do
|
|
148
|
-
expect(page).to have_text I18n.t("solidus_braintree.errors.empty_fields")
|
|
149
|
-
expect(page).to have_selector("[type='submit']:enabled")
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
# Same error should be produced when submitting an empty form again
|
|
153
|
-
context "when user tries to resubmit an empty form", vcr: { cassette_name: "checkout/invalid_credit_card" } do
|
|
154
|
-
it "displays an alert with a meaningful error message" do
|
|
155
|
-
expect(page).to have_selector("[type='submit']:enabled")
|
|
156
|
-
|
|
157
|
-
click_button "Save and Continue"
|
|
158
|
-
expect(page).to have_text I18n.t("solidus_braintree.errors.empty_fields")
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
# User should be able to checkout after submit fails once
|
|
163
|
-
context "when user enters valid data", vcr: {
|
|
164
|
-
cassette_name: "checkout/resubmit_credit_card",
|
|
165
|
-
match_requests_on: [:braintree_uri]
|
|
166
|
-
} do
|
|
167
|
-
it "allows them to resubmit and complete the purchase" do
|
|
168
|
-
within_frame("braintree-hosted-field-number") do
|
|
169
|
-
fill_in("credit-card-number", with: "4111111111111111")
|
|
170
|
-
end
|
|
171
|
-
within_frame("braintree-hosted-field-expirationDate") do
|
|
172
|
-
fill_in("expiration", with: card_expiration)
|
|
173
|
-
end
|
|
174
|
-
within_frame("braintree-hosted-field-cvv") do
|
|
175
|
-
fill_in("cvv", with: "123")
|
|
176
|
-
end
|
|
177
|
-
click_button("Save and Continue")
|
|
178
|
-
|
|
179
|
-
within(".confirm-step") do
|
|
180
|
-
expect(page).to have_content(/confirm/i)
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
check('accept_terms_and_conditions')
|
|
184
|
-
|
|
185
|
-
click_button("Place Order")
|
|
186
|
-
expect(page).to have_content("Your order has been processed successfully")
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def authenticate_3ds
|
|
192
|
-
within_frame("Cardinal-CCA-IFrame") do
|
|
193
|
-
fill_in("challengeDataEntry", with: "1234")
|
|
194
|
-
continue_button = find_button("SUBMIT")
|
|
195
|
-
continue_button.scroll_to(continue_button)
|
|
196
|
-
continue_button.click
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
end
|