solidus_braintree 1.2.0 → 3.0.0
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 +78 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +1 -0
- data/.github_changelog_generator +2 -0
- data/.gitignore +21 -10
- data/.rspec +1 -1
- data/.rubocop.yml +86 -0
- data/CHANGELOG.md +186 -18
- data/Gemfile +35 -17
- data/LICENSE +26 -0
- data/README.md +389 -24
- data/Rakefile +6 -16
- data/app/assets/config/solidus_braintree_manifest.js +0 -0
- data/app/assets/javascripts/spree/backend/solidus_braintree/client.js +239 -0
- data/app/assets/javascripts/spree/backend/solidus_braintree/constants.js +89 -0
- data/app/assets/javascripts/spree/backend/solidus_braintree/hosted_form.js +46 -0
- data/app/assets/javascripts/spree/backend/solidus_braintree/promise.js +20 -0
- data/app/assets/javascripts/spree/backend/solidus_braintree.js +96 -0
- data/app/assets/stylesheets/spree/backend/solidus_braintree.scss +28 -0
- data/app/decorators/controllers/solidus_braintree/admin_payments_controller_decorator.rb +11 -0
- data/app/decorators/controllers/solidus_braintree/client_tokens_controller.rb +41 -0
- data/app/decorators/models/solidus_braintree/spree/store_decorator.rb +20 -0
- data/app/decorators/models/solidus_braintree/spree/user_decorator.rb +13 -0
- data/app/helpers/solidus_braintree/braintree_admin_helper.rb +23 -0
- data/app/models/application_record.rb +5 -0
- data/app/models/solidus_braintree/address.rb +64 -0
- data/app/models/solidus_braintree/avs_result.rb +69 -0
- data/app/models/solidus_braintree/configuration.rb +39 -0
- data/app/models/solidus_braintree/customer.rb +8 -0
- data/app/models/solidus_braintree/gateway.rb +437 -0
- data/app/models/solidus_braintree/response.rb +80 -0
- data/app/models/solidus_braintree/source.rb +140 -0
- data/app/models/solidus_braintree/transaction.rb +31 -0
- data/app/models/solidus_braintree/transaction_address.rb +88 -0
- data/app/models/solidus_braintree/transaction_import.rb +98 -0
- data/app/views/spree/api/payments/source_views/_braintree.json.jbuilder +3 -0
- data/bin/console +4 -1
- data/bin/dummy-app +37 -0
- data/bin/rails +5 -5
- data/bin/rails-dummy-app +17 -0
- data/bin/rails-engine +13 -0
- data/bin/rails-sandbox +16 -0
- data/bin/rake +7 -0
- data/bin/rspec +11 -0
- data/bin/sandbox +61 -0
- data/bin/setup +5 -4
- data/config/locales/en.yml +94 -2
- data/config/locales/it.yml +56 -0
- data/config/routes.rb +12 -3
- data/db/migrate/20160830061749_create_solidus_paypal_braintree_sources.rb +16 -0
- data/db/migrate/20160906201711_create_solidus_paypal_braintree_customers.rb +13 -0
- data/db/migrate/20161114231422_create_solidus_paypal_braintree_configurations.rb +11 -0
- data/db/migrate/20161125172005_add_braintree_configuration_to_stores.rb +7 -0
- data/db/migrate/20170203191030_add_credit_card_to_braintree_configuration.rb +6 -0
- data/db/migrate/20170505193712_add_null_constraint_to_sources.rb +38 -0
- data/db/migrate/20170508085402_add_not_null_constraint_to_sources_payment_type.rb +14 -0
- data/db/migrate/20190705115327_add_paypal_button_preferences_to_braintree_configurations.rb +5 -0
- data/db/migrate/20190911141712_add_3d_secure_to_braintree_configuration.rb +5 -0
- data/db/migrate/20211222170950_add_paypal_funding_source_to_solidus_paypal_braintree_sources.rb +5 -0
- data/db/migrate/20220104150301_add_venmo_to_braintree_configuration.rb +5 -0
- data/db/migrate/20230109080950_rename_solidus_paypal_braintree_source_type.rb +31 -0
- data/db/migrate/20230210104310_add_device_data_to_braintree_sources.rb +5 -0
- data/lib/controllers/backend/solidus_braintree/configurations_controller.rb +48 -0
- data/lib/generators/solidus_braintree/install/install_generator.rb +155 -19
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_blue_button_280x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_blue_button_320x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_blue_button_375x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_white_button_280x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_white_button_320x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_white_button_375x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_blue_acceptance_mark.svg +15 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_blue_button_280x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_blue_button_320x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_blue_button_375x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_blue_logo.svg +18 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_white_acceptance_mark.svg +20 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_white_button_280x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_white_button_320x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_white_button_375x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_white_logo.svg +18 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/paypal_button.js +34 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/ajax.js +13 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/apple_pay_button.js +179 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/checkout.js +113 -0
- 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/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/paypal_button.js +178 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/paypal_messaging.js +22 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/promise.js +20 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/venmo_button.js +86 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree.js +1 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/stylesheets/spree/frontend/solidus_braintree.scss +62 -0
- data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/checkouts_controller.rb +31 -0
- data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/transactions_controller.rb +67 -0
- data/lib/generators/solidus_braintree/install/templates/app/helpers/solidus_braintree/braintree_checkout_helper.rb +60 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/checkouts/existing_payment/_braintree.html.erb +2 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/checkouts/payment/_braintree.html.erb +23 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/payments/_braintree_payment_details.html.erb +9 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_apple_pay_button.html.erb +27 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_braintree_errors.html.erb +16 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_braintree_head_scripts.html.erb +26 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_braintree_hosted_fields.html.erb +40 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_paypal_cart_button.html.erb +38 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_paypal_checkout_button.html.erb +32 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_paypal_messaging.html.erb +13 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_venmo_button.html.erb +33 -0
- data/lib/generators/solidus_braintree/install/templates/config/initializers/solidus_braintree.rb +6 -0
- data/lib/solidus_braintree/country_mapper.rb +37 -0
- data/lib/solidus_braintree/engine.rb +61 -11
- data/lib/solidus_braintree/extension_configuration.rb +23 -0
- data/lib/solidus_braintree/request_protection.rb +21 -0
- data/lib/solidus_braintree/version.rb +3 -1
- data/lib/solidus_braintree.rb +14 -2
- data/lib/solidus_paypal_braintree.rb +6 -0
- data/lib/views/backend/solidus_braintree/configurations/list.html.erb +63 -0
- data/lib/views/backend/spree/admin/payments/source_forms/_braintree.html.erb +16 -0
- data/lib/views/backend/spree/admin/payments/source_views/_braintree.html.erb +39 -0
- data/lib/views/backend/spree/admin/shared/preference_fields/_preference_select.html.erb +13 -0
- data/lib/views/backend_v1.2/spree/admin/payments/source_forms/_braintree.html.erb +16 -0
- data/lib/views/backend_v2.4/spree/admin/shared/preference_fields/_hash.html.erb +12 -0
- data/solidus_braintree.gemspec +37 -38
- data/spec/controllers/solidus_braintree/checkouts_controller_spec.rb +99 -0
- data/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb +55 -0
- data/spec/controllers/solidus_braintree/configurations_controller_spec.rb +73 -0
- data/spec/controllers/solidus_braintree/transactions_controller_spec.rb +183 -0
- data/spec/fixtures/cassettes/admin/invalid_credit_card.yml +63 -0
- data/spec/fixtures/cassettes/admin/resubmit_credit_card.yml +352 -0
- data/spec/fixtures/cassettes/admin/valid_credit_card.yml +412 -0
- data/spec/fixtures/cassettes/braintree/create_profile.yml +71 -0
- data/spec/fixtures/cassettes/braintree/generate_token.yml +63 -0
- data/spec/fixtures/cassettes/braintree/token.yml +63 -0
- data/spec/fixtures/cassettes/checkout/invalid_credit_card.yml +63 -0
- data/spec/fixtures/cassettes/checkout/resubmit_credit_card.yml +216 -0
- data/spec/fixtures/cassettes/checkout/update.yml +71 -0
- data/spec/fixtures/cassettes/checkout/valid_credit_card.yml +171 -0
- data/spec/fixtures/cassettes/checkout/valid_venmo_transaction.yml +599 -0
- data/spec/fixtures/cassettes/gateway/authorize/credit_card/address.yml +86 -0
- data/spec/fixtures/cassettes/gateway/authorize/merchant_account/EUR.yml +154 -0
- data/spec/fixtures/cassettes/gateway/authorize/paypal/EUR.yml +90 -0
- data/spec/fixtures/cassettes/gateway/authorize/paypal/address.yml +90 -0
- data/spec/fixtures/cassettes/gateway/authorize.yml +86 -0
- data/spec/fixtures/cassettes/gateway/authorized_transaction.yml +73 -0
- data/spec/fixtures/cassettes/gateway/cancel/missing.yml +63 -0
- data/spec/fixtures/cassettes/gateway/cancel/refunds.yml +272 -0
- data/spec/fixtures/cassettes/gateway/cancel/void.yml +201 -0
- data/spec/fixtures/cassettes/gateway/capture.yml +141 -0
- data/spec/fixtures/cassettes/gateway/complete.yml +157 -0
- data/spec/fixtures/cassettes/gateway/credit.yml +208 -0
- data/spec/fixtures/cassettes/gateway/customer.yml +79 -0
- data/spec/fixtures/cassettes/gateway/purchase.yml +87 -0
- data/spec/fixtures/cassettes/gateway/settled_transaction.yml +140 -0
- data/spec/fixtures/cassettes/gateway/void.yml +137 -0
- data/spec/fixtures/cassettes/source/bin.yml +295 -0
- data/spec/fixtures/cassettes/source/card_type.yml +267 -0
- data/spec/fixtures/cassettes/source/last4.yml +267 -0
- data/spec/fixtures/cassettes/transaction/import/valid/capture.yml +224 -0
- data/spec/fixtures/cassettes/transaction/import/valid.yml +71 -0
- data/spec/fixtures/views/carts/_cart_footer.html.erb +18 -0
- data/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb +17 -0
- data/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb +70 -0
- data/spec/models/solidus_braintree/address_spec.rb +71 -0
- data/spec/models/solidus_braintree/avs_result_spec.rb +317 -0
- data/spec/models/solidus_braintree/gateway_spec.rb +774 -0
- data/spec/models/solidus_braintree/response_spec.rb +280 -0
- data/spec/models/solidus_braintree/source_spec.rb +555 -0
- data/spec/models/solidus_braintree/transaction_address_spec.rb +235 -0
- data/spec/models/solidus_braintree/transaction_import_spec.rb +302 -0
- data/spec/models/solidus_braintree/transaction_spec.rb +86 -0
- data/spec/models/spree/store_spec.rb +14 -0
- data/spec/requests/spree/api/orders_controller_spec.rb +36 -0
- data/spec/solidus_braintree_helper.rb +7 -0
- data/spec/support/solidus_braintree/capybara.rb +7 -0
- data/spec/support/solidus_braintree/factories.rb +55 -0
- data/spec/support/solidus_braintree/gateway_helpers.rb +29 -0
- data/spec/support/solidus_braintree/order_ready_for_payment.rb +44 -0
- data/spec/support/solidus_braintree/order_walkthrough.rb +87 -0
- data/spec/support/solidus_braintree/vcr.rb +42 -0
- data/spec/support/solidus_braintree/with_prepended_view_fixtures.rb +19 -0
- data/spec/system/backend/configuration_spec.rb +23 -0
- data/spec/system/backend/new_payment_spec.rb +136 -0
- data/spec/system/frontend/braintree_credit_card_checkout_spec.rb +199 -0
- data/spec/system/frontend/paypal_checkout_spec.rb +169 -0
- data/spec/system/frontend/venmo_checkout_spec.rb +193 -0
- metadata +289 -255
- data/.travis.yml +0 -41
- data/LICENSE.txt +0 -21
- data/app/controllers/spree/api/braintree_client_token_controller.rb +0 -13
- data/app/helpers/braintree_view_helpers.rb +0 -20
- data/app/models/concerns/solidus_braintree/add_name_validation_concern.rb +0 -8
- data/app/models/concerns/solidus_braintree/inject_device_data_concern.rb +0 -18
- data/app/models/concerns/solidus_braintree/payment_braintree_nonce_concern.rb +0 -8
- data/app/models/concerns/solidus_braintree/permitted_attributes_concern.rb +0 -11
- data/app/models/concerns/solidus_braintree/skip_require_card_numbers_concern.rb +0 -14
- data/app/models/concerns/solidus_braintree/use_data_field_concern.rb +0 -23
- data/app/models/credit_card_decorator.rb +0 -3
- data/app/models/payment_decorator.rb +0 -2
- data/app/models/permitted_attributes_decorator.rb +0 -1
- data/app/models/solidus/gateway/braintree_gateway.rb +0 -306
- data/app/overrides/spree/checkout/_confirm/braintree_security.html.erb.deface +0 -9
- data/app/views/spree/admin/payments/source_forms/_braintree.html.erb +0 -38
- data/app/views/spree/admin/payments/source_views/_braintree.html.erb +0 -30
- data/app/views/spree/checkout/payment/_braintree.html.erb +0 -55
- data/app/views/spree/checkout/payment/_braintree_initialization.html.erb +0 -12
- data/config/initializers/braintree.rb +0 -1
- data/db/migrate/20150910170527_add_data_to_credit_card.rb +0 -5
- data/db/migrate/20160426221931_add_braintree_device_data_to_order.rb +0 -5
- data/lib/assets/javascripts/spree/backend/braintree/solidus_braintree.js +0 -59
- data/lib/assets/javascripts/spree/frontend/braintree/solidus_braintree.js +0 -144
- data/lib/assets/javascripts/vendor/braintree.js +0 -8
- data/lib/assets/stylesheets/spree/frontend/solidus_braintree.scss +0 -26
@@ -0,0 +1,55 @@
|
|
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
|
@@ -0,0 +1,29 @@
|
|
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
|
@@ -0,0 +1,44 @@
|
|
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(:line_item, 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
|
@@ -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,42 @@
|
|
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
|
+
|
39
|
+
# https://github.com/titusfortner/webdrivers/wiki/Using-with-VCR-or-WebMock
|
40
|
+
driver_hosts = Webdrivers::Common.subclasses.map { |driver| URI(driver.base_url).host }
|
41
|
+
c.ignore_hosts(*driver_hosts)
|
42
|
+
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
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'solidus_braintree_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
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'solidus_braintree_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
|
@@ -0,0 +1,199 @@
|
|
1
|
+
require 'solidus_braintree_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")
|
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")
|
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")
|
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
|