solidus_paypal_braintree 0.2.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +40 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +17 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.rubocop.yml +76 -0
- data/CHANGELOG.md +258 -0
- data/Gemfile +41 -0
- data/LICENSE +2 -2
- data/README.md +208 -48
- data/Rakefile +4 -28
- data/app/assets/config/solidus_paypal_braintree_manifest.js +1 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_blue_button_280x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_blue_button_320x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_blue_button_375x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_white_button_280x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_white_button_320x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_white_button_375x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_acceptance_mark.svg +15 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_button_280x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_button_320x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_button_375x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_logo.svg +18 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_acceptance_mark.svg +20 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_button_280x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_button_320x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_button_375x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_logo.svg +18 -0
- data/app/assets/javascripts/solidus_paypal_braintree/checkout.js +32 -3
- data/app/assets/javascripts/solidus_paypal_braintree/client.js +58 -5
- data/app/assets/javascripts/solidus_paypal_braintree/constants.js +36 -5
- data/app/assets/javascripts/solidus_paypal_braintree/frontend.js +2 -0
- data/app/assets/javascripts/solidus_paypal_braintree/hosted_form.js +15 -5
- data/app/assets/javascripts/solidus_paypal_braintree/paypal_button.js +90 -26
- data/app/assets/javascripts/solidus_paypal_braintree/paypal_messaging.js +22 -0
- data/app/assets/javascripts/solidus_paypal_braintree/venmo_button.js +86 -0
- data/app/assets/javascripts/spree/backend/solidus_paypal_braintree.js +2 -2
- data/app/assets/javascripts/spree/frontend/paypal_button.js +15 -13
- data/app/assets/stylesheets/spree/frontend/solidus_paypal_braintree.css +12 -0
- data/app/decorators/controllers/solidus_paypal_braintree/admin_payments_controller_decorator.rb +11 -0
- data/app/decorators/controllers/solidus_paypal_braintree/checkout_controller_decorator.rb +11 -0
- data/app/decorators/controllers/solidus_paypal_braintree/client_tokens_controller.rb +41 -0
- data/app/decorators/controllers/solidus_paypal_braintree/orders_controller_decorator.rb +11 -0
- data/app/decorators/models/solidus_paypal_braintree/spree/store_decorator.rb +20 -0
- data/app/decorators/models/solidus_paypal_braintree/spree/user_decorator.rb +13 -0
- data/app/helpers/solidus_paypal_braintree/braintree_admin_helper.rb +23 -0
- data/app/helpers/solidus_paypal_braintree/braintree_checkout_helper.rb +60 -0
- data/app/models/application_record.rb +2 -0
- data/app/models/solidus_paypal_braintree/address.rb +64 -0
- data/app/models/solidus_paypal_braintree/avs_result.rb +69 -0
- data/app/models/solidus_paypal_braintree/configuration.rb +39 -3
- data/app/models/solidus_paypal_braintree/customer.rb +7 -3
- data/app/models/solidus_paypal_braintree/gateway.rb +150 -43
- data/app/models/solidus_paypal_braintree/response.rb +49 -21
- data/app/models/solidus_paypal_braintree/source.rb +70 -10
- data/app/models/solidus_paypal_braintree/transaction.rb +3 -2
- data/app/models/solidus_paypal_braintree/transaction_address.rb +36 -15
- data/app/models/solidus_paypal_braintree/transaction_import.rb +18 -12
- data/app/overrides/spree/payments/payment/add_paypal_funding_source_to_payment.rb +9 -0
- data/app/views/spree/api/payments/source_views/_paypal_braintree.json.jbuilder +3 -0
- data/app/views/spree/checkout/existing_payment/_paypal_braintree.html.erb +10 -0
- data/app/views/spree/shared/_apple_pay_button.html.erb +27 -0
- data/app/views/spree/shared/_braintree_errors.html.erb +16 -0
- data/app/views/spree/shared/_braintree_hosted_fields.html.erb +25 -8
- data/app/views/spree/shared/_paypal_braintree_head_scripts.html.erb +26 -0
- data/app/views/spree/shared/_paypal_cart_button.html.erb +38 -0
- data/app/views/spree/shared/_paypal_messaging.html.erb +13 -0
- data/app/views/spree/shared/_venmo_button.html.erb +33 -0
- data/bin/console +17 -0
- data/bin/rails +15 -0
- data/bin/setup +8 -0
- data/config/locales/en.yml +66 -0
- data/config/locales/it.yml +56 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20160906201711_create_solidus_paypal_braintree_customers.rb +3 -1
- data/db/migrate/20161125172005_add_braintree_configuration_to_stores.rb +5 -7
- data/db/migrate/20170505193712_add_null_constraint_to_sources.rb +3 -1
- 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/lib/controllers/backend/solidus_paypal_braintree/configurations_controller.rb +23 -5
- data/lib/controllers/frontend/solidus_paypal_braintree/checkouts_controller.rb +25 -21
- data/lib/controllers/frontend/solidus_paypal_braintree/transactions_controller.rb +56 -50
- data/lib/generators/solidus_paypal_braintree/install/install_generator.rb +7 -6
- data/lib/solidus_paypal_braintree/country_mapper.rb +4 -2
- data/lib/solidus_paypal_braintree/engine.rb +34 -22
- data/lib/solidus_paypal_braintree/factories.rb +41 -6
- data/lib/solidus_paypal_braintree/request_protection.rb +21 -0
- data/lib/solidus_paypal_braintree/version.rb +3 -1
- data/lib/solidus_paypal_braintree.rb +5 -1
- data/lib/views/backend/solidus_paypal_braintree/configurations/list.html.erb +38 -5
- data/lib/views/backend/spree/admin/payments/source_forms/_paypal_braintree.html.erb +2 -2
- data/lib/views/backend/spree/admin/payments/source_views/_paypal_braintree.html.erb +7 -2
- 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/_paypal_braintree.html.erb +2 -2
- data/lib/views/backend_v2.4/spree/admin/shared/preference_fields/_hash.html.erb +12 -0
- data/lib/views/frontend/solidus_paypal_braintree/payments/_payment.html.erb +12 -0
- data/lib/views/frontend/spree/checkout/payment/_paypal_braintree.html.erb +10 -77
- data/lib/views/frontend/spree/shared/_paypal_checkout_button.html.erb +32 -0
- data/solidus_paypal_braintree.gemspec +43 -0
- data/spec/controllers/solidus_paypal_braintree/checkouts_controller_spec.rb +99 -0
- data/spec/controllers/solidus_paypal_braintree/client_tokens_controller_spec.rb +55 -0
- data/spec/controllers/solidus_paypal_braintree/configurations_controller_spec.rb +73 -0
- data/spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb +183 -0
- data/spec/features/backend/configuration_spec.rb +23 -0
- data/spec/features/backend/new_payment_spec.rb +137 -0
- data/spec/features/frontend/braintree_credit_card_checkout_spec.rb +191 -0
- data/spec/features/frontend/paypal_checkout_spec.rb +166 -0
- data/spec/features/frontend/venmo_checkout_spec.rb +189 -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 +156 -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/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/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/spree/orders/edit.html.erb +50 -0
- data/spec/helpers/solidus_paypal_braintree/braintree_admin_helper_spec.rb +17 -0
- data/spec/helpers/solidus_paypal_braintree/braintree_checkout_helper_spec.rb +70 -0
- data/spec/models/solidus_paypal_braintree/address_spec.rb +71 -0
- data/spec/models/solidus_paypal_braintree/avs_result_spec.rb +317 -0
- data/spec/models/solidus_paypal_braintree/gateway_spec.rb +692 -0
- data/spec/models/solidus_paypal_braintree/response_spec.rb +280 -0
- data/spec/models/solidus_paypal_braintree/source_spec.rb +499 -0
- data/spec/models/solidus_paypal_braintree/transaction_address_spec.rb +235 -0
- data/spec/models/solidus_paypal_braintree/transaction_import_spec.rb +300 -0
- data/spec/models/solidus_paypal_braintree/transaction_spec.rb +85 -0
- data/spec/models/spree/store_spec.rb +14 -0
- data/spec/requests/spree/api/orders_controller_spec.rb +36 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/capybara.rb +7 -0
- data/spec/support/factories.rb +2 -0
- data/spec/support/gateway_helpers.rb +29 -0
- data/spec/support/order_ready_for_payment.rb +37 -0
- data/spec/support/vcr.rb +42 -0
- data/spec/support/views.rb +1 -0
- metadata +226 -166
- data/app/controllers/solidus_paypal_braintree/client_tokens_controller.rb +0 -21
- data/app/helpers/braintree_admin_helper.rb +0 -18
- data/app/models/spree/store_decorator.rb +0 -11
- data/app/overrides/admin_navigation_menu.rb +0 -6
- data/config/initializers/braintree.rb +0 -1
- data/lib/views/backend/solidus_paypal_braintree/configurations/_admin_tab.html.erb +0 -3
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'spree/testing_support/order_walkthrough'
|
3
|
+
|
4
|
+
shared_context "with backend checkout setup" do
|
5
|
+
let(:braintree) { new_gateway(active: true) }
|
6
|
+
let!(:gateway) { create :payment_method }
|
7
|
+
let(:order) { create(:completed_order_with_totals, number: 'R9999999') }
|
8
|
+
let(:pending_case_insensitive) { /pending/i }
|
9
|
+
let(:expiration) { "02/#{Date.current.year.next}" }
|
10
|
+
|
11
|
+
before do
|
12
|
+
braintree.save!
|
13
|
+
create(:store, payment_methods: [gateway, braintree]).tap do |store|
|
14
|
+
store.braintree_configuration.update!(credit_card: true)
|
15
|
+
end
|
16
|
+
|
17
|
+
allow_any_instance_of(SolidusPaypalBraintree::Source).to receive(:nonce).and_return("fake-valid-nonce")
|
18
|
+
|
19
|
+
# Order and payment numbers must be identical between runs to re-use the VCR
|
20
|
+
# cassette
|
21
|
+
allow_any_instance_of(Spree::Payment).to receive(:number).and_return("123ABC")
|
22
|
+
end
|
23
|
+
|
24
|
+
around do |example|
|
25
|
+
Capybara.using_wait_time(20) { example.run }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'creating a new payment', type: :feature, js: true do
|
30
|
+
stub_authorization!
|
31
|
+
|
32
|
+
context "with valid credit card data", vcr: {
|
33
|
+
cassette_name: 'admin/valid_credit_card',
|
34
|
+
match_requests_on: [:braintree_uri]
|
35
|
+
} do
|
36
|
+
include_context "with backend checkout setup"
|
37
|
+
|
38
|
+
it "checks out successfully" do
|
39
|
+
visit "/admin/orders/#{order.number}/payments/new"
|
40
|
+
choose('Braintree')
|
41
|
+
expect(page).to have_selector("#payment_method_#{braintree.id}", visible: :visible)
|
42
|
+
expect(page).to have_selector("iframe#braintree-hosted-field-number")
|
43
|
+
|
44
|
+
within_frame("braintree-hosted-field-number") do
|
45
|
+
fill_in("credit-card-number", with: "4111111111111111")
|
46
|
+
end
|
47
|
+
within_frame("braintree-hosted-field-expirationDate") do
|
48
|
+
fill_in("expiration", with: expiration)
|
49
|
+
end
|
50
|
+
within_frame("braintree-hosted-field-cvv") do
|
51
|
+
fill_in("cvv", with: "123")
|
52
|
+
end
|
53
|
+
|
54
|
+
click_button("Update")
|
55
|
+
|
56
|
+
within('table#payments') do
|
57
|
+
expect(page).to have_content('Braintree')
|
58
|
+
expect(page).to have_content(pending_case_insensitive)
|
59
|
+
end
|
60
|
+
|
61
|
+
click_icon(:capture)
|
62
|
+
|
63
|
+
expect(page).not_to have_content('Cannot perform requested operation')
|
64
|
+
expect(page).to have_content('Payment Updated')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "with invalid credit card data" do
|
69
|
+
include_context "with backend checkout setup"
|
70
|
+
|
71
|
+
# Attempt to submit an invalid form once
|
72
|
+
before do
|
73
|
+
visit "/admin/orders/#{order.number}/payments/new"
|
74
|
+
choose('Braintree')
|
75
|
+
|
76
|
+
within_frame("braintree-hosted-field-number") do
|
77
|
+
fill_in("credit-card-number", with: "1111111111111111")
|
78
|
+
end
|
79
|
+
within_frame("braintree-hosted-field-expirationDate") do
|
80
|
+
fill_in("expiration", with: expiration)
|
81
|
+
end
|
82
|
+
within_frame("braintree-hosted-field-cvv") do
|
83
|
+
fill_in("cvv", with: "123")
|
84
|
+
end
|
85
|
+
|
86
|
+
click_button "Update"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "displays a meaningful error message" do
|
90
|
+
expect(page).to have_text(
|
91
|
+
"BraintreeError: Some payment input fields are invalid. Cannot tokenize invalid card fields."
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Same error should be produced when submitting an empty form again
|
96
|
+
context "when user tries to resubmit another invalid form", vcr: {
|
97
|
+
cassette_name: "admin/invalid_credit_card",
|
98
|
+
match_requests_on: [:braintree_uri]
|
99
|
+
} do
|
100
|
+
it "displays a meaningful error message" do
|
101
|
+
click_button "Update"
|
102
|
+
expect(page).to have_text(
|
103
|
+
"BraintreeError: Some payment input fields are invalid. Cannot tokenize invalid card fields."
|
104
|
+
)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# User should be able to checkout after submit fails once
|
109
|
+
context "when user enters valid data", vcr: {
|
110
|
+
cassette_name: "admin/resubmit_credit_card",
|
111
|
+
match_requests_on: [:braintree_uri]
|
112
|
+
} do
|
113
|
+
it "creates the payment successfully" do
|
114
|
+
within_frame("braintree-hosted-field-number") do
|
115
|
+
fill_in("credit-card-number", with: "4111111111111111")
|
116
|
+
end
|
117
|
+
within_frame("braintree-hosted-field-expirationDate") do
|
118
|
+
fill_in("expiration", with: expiration)
|
119
|
+
end
|
120
|
+
within_frame("braintree-hosted-field-cvv") do
|
121
|
+
fill_in("cvv", with: "123")
|
122
|
+
end
|
123
|
+
click_button("Update")
|
124
|
+
|
125
|
+
within('table#payments') do
|
126
|
+
expect(page).to have_content('Braintree')
|
127
|
+
expect(page).to have_content(pending_case_insensitive)
|
128
|
+
end
|
129
|
+
|
130
|
+
click_icon(:capture)
|
131
|
+
|
132
|
+
expect(page).not_to have_content('Cannot perform requested operation')
|
133
|
+
expect(page).to have_content('Payment Updated')
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'spree/testing_support/order_walkthrough'
|
3
|
+
|
4
|
+
shared_context "with frontend checkout setup" do
|
5
|
+
let(:braintree) { new_gateway(active: true) }
|
6
|
+
let!(:gateway) { create :payment_method }
|
7
|
+
let(:three_d_secure_enabled) { false }
|
8
|
+
let(:venmo_enabled) { false }
|
9
|
+
let(:card_number) { "4111111111111111" }
|
10
|
+
let(:card_expiration) { "01/#{Time.now.utc.year + 2}" }
|
11
|
+
|
12
|
+
before do
|
13
|
+
braintree.save!
|
14
|
+
|
15
|
+
create(:store, payment_methods: [gateway, braintree]).tap do |store|
|
16
|
+
store.braintree_configuration.update!(
|
17
|
+
credit_card: true,
|
18
|
+
three_d_secure: three_d_secure_enabled,
|
19
|
+
venmo: venmo_enabled
|
20
|
+
)
|
21
|
+
|
22
|
+
braintree.update(
|
23
|
+
preferred_credit_card_fields_style: { input: { 'font-size': '30px' } },
|
24
|
+
preferred_placeholder_text: { number: "Enter Your Card Number" }
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
order = if Spree.solidus_gem_version >= Gem::Version.new('2.6.0')
|
29
|
+
Spree::TestingSupport::OrderWalkthrough.up_to(:delivery)
|
30
|
+
else
|
31
|
+
OrderWalkthrough.up_to(:delivery)
|
32
|
+
end
|
33
|
+
|
34
|
+
user = create(:user)
|
35
|
+
order.user = user
|
36
|
+
order.number = "R9999999"
|
37
|
+
order.recalculate
|
38
|
+
|
39
|
+
allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
|
40
|
+
allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
|
41
|
+
allow_any_instance_of(Spree::Payment).to receive(:number).and_return("123ABC")
|
42
|
+
allow_any_instance_of(SolidusPaypalBraintree::Source).to receive(:nonce).and_return("fake-valid-nonce")
|
43
|
+
|
44
|
+
visit spree.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
|
+
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("#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("#order_details") do
|
101
|
+
expect(page).to have_content("CONFIRM")
|
102
|
+
end
|
103
|
+
click_button("Place Order")
|
104
|
+
expect(page).to have_content("Your order has been processed successfully")
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'with 3D secure enabled' do
|
108
|
+
let(:three_d_secure_enabled) { true }
|
109
|
+
let(:card_number) { "4000000000000002" }
|
110
|
+
|
111
|
+
it 'checks out successfully' do
|
112
|
+
authenticate_3ds
|
113
|
+
|
114
|
+
within("#order_details") do
|
115
|
+
expect(page).to have_content("CONFIRM")
|
116
|
+
end
|
117
|
+
|
118
|
+
click_button("Place Order")
|
119
|
+
expect(page).to have_content("Your order has been processed successfully")
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'with 3ds authentication error' do
|
123
|
+
let(:card_number) { "4000000000000028" }
|
124
|
+
|
125
|
+
it 'shows a 3ds authentication error' do
|
126
|
+
authenticate_3ds
|
127
|
+
expect(page).to have_content(
|
128
|
+
"3D Secure authentication failed. Please try again using a different payment method."
|
129
|
+
)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context "with invalid credit card data" do
|
136
|
+
include_context "with frontend checkout setup"
|
137
|
+
|
138
|
+
# Attempt to submit an empty form once
|
139
|
+
before do
|
140
|
+
click_button "Save and Continue"
|
141
|
+
end
|
142
|
+
|
143
|
+
it "displays an alert with a meaningful error message" do
|
144
|
+
expect(page).to have_text I18n.t("solidus_paypal_braintree.errors.empty_fields")
|
145
|
+
expect(page).to have_selector("input[type='submit']:enabled")
|
146
|
+
end
|
147
|
+
|
148
|
+
# Same error should be produced when submitting an empty form again
|
149
|
+
context "when user tries to resubmit an empty form", vcr: { cassette_name: "checkout/invalid_credit_card" } do
|
150
|
+
it "displays an alert with a meaningful error message" do
|
151
|
+
expect(page).to have_selector("input[type='submit']:enabled")
|
152
|
+
|
153
|
+
click_button "Save and Continue"
|
154
|
+
expect(page).to have_text I18n.t("solidus_paypal_braintree.errors.empty_fields")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# User should be able to checkout after submit fails once
|
159
|
+
context "when user enters valid data", vcr: {
|
160
|
+
cassette_name: "checkout/resubmit_credit_card",
|
161
|
+
match_requests_on: [:braintree_uri]
|
162
|
+
} do
|
163
|
+
it "allows them to resubmit and complete the purchase" do
|
164
|
+
within_frame("braintree-hosted-field-number") do
|
165
|
+
fill_in("credit-card-number", with: "4111111111111111")
|
166
|
+
end
|
167
|
+
within_frame("braintree-hosted-field-expirationDate") do
|
168
|
+
fill_in("expiration", with: card_expiration)
|
169
|
+
end
|
170
|
+
within_frame("braintree-hosted-field-cvv") do
|
171
|
+
fill_in("cvv", with: "123")
|
172
|
+
end
|
173
|
+
click_button("Save and Continue")
|
174
|
+
within("#order_details") do
|
175
|
+
expect(page).to have_content("CONFIRM")
|
176
|
+
end
|
177
|
+
click_button("Place Order")
|
178
|
+
expect(page).to have_content("Your order has been processed successfully")
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def authenticate_3ds
|
184
|
+
within_frame("Cardinal-CCA-IFrame") do
|
185
|
+
within_frame("authWindow") do
|
186
|
+
fill_in("password", with: "1234")
|
187
|
+
click_button("Submit")
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Checkout", type: :feature, js: true do
|
4
|
+
Capybara.default_max_wait_time = 60
|
5
|
+
|
6
|
+
# let!(:store) do
|
7
|
+
# create(:store, payment_methods: [payment_method]).tap do |s|
|
8
|
+
# s.braintree_configuration.update!(braintree_preferences)
|
9
|
+
# end
|
10
|
+
# end
|
11
|
+
let(:braintree_preferences) { { paypal: true }.merge(paypal_options) }
|
12
|
+
let(:paypal_options) { {} }
|
13
|
+
|
14
|
+
let!(:country) { create(:country, states_required: true) }
|
15
|
+
# let!(:state) { create(:state, country: country, abbr: "CA", name: "California") }
|
16
|
+
# let!(:shipping_method) { create(:shipping_method) }
|
17
|
+
# let!(:stock_location) { create(:stock_location) }
|
18
|
+
let!(:mug) { create(:product, name: "RoR Mug") }
|
19
|
+
let!(:payment_method) { create_gateway }
|
20
|
+
# let!(:zone) { create(:zone) }
|
21
|
+
|
22
|
+
before do
|
23
|
+
create(:store, payment_methods: [payment_method]).tap do |s|
|
24
|
+
s.braintree_configuration.update!(braintree_preferences)
|
25
|
+
end
|
26
|
+
create(:state, country: country, abbr: "CA", name: "California")
|
27
|
+
create(:shipping_method)
|
28
|
+
create(:stock_location)
|
29
|
+
create(:zone)
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when going through express checkout using paypal cart button" do
|
33
|
+
before do
|
34
|
+
payment_method
|
35
|
+
add_mug_to_cart
|
36
|
+
end
|
37
|
+
|
38
|
+
it "checks out successfully", skip: "Broken. To be revisited" do
|
39
|
+
pend_if_paypal_slow do
|
40
|
+
expect_any_instance_of(Spree::Order).to receive(:restart_checkout_flow)
|
41
|
+
move_through_paypal_popup
|
42
|
+
expect(page).to have_content("Shipments")
|
43
|
+
click_on "Place Order"
|
44
|
+
expect(page).to have_content("Your order has been processed successfully")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when using custom paypal button style' do
|
49
|
+
let(:paypal_options) { { preferred_paypal_button_color: 'blue' } }
|
50
|
+
|
51
|
+
it 'displays required PayPal button style' do
|
52
|
+
within_frame find('#paypal-button iframe') do
|
53
|
+
expect(page).to have_selector('.paypal-button-color-blue')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when going through regular checkout using paypal payment method" do
|
60
|
+
before do
|
61
|
+
payment_method
|
62
|
+
add_mug_to_cart
|
63
|
+
click_button("Checkout")
|
64
|
+
fill_in("order_email", with: "paypal_buyer@paypaltest.com")
|
65
|
+
click_button("Continue")
|
66
|
+
fill_in_address
|
67
|
+
click_button("Save and Continue")
|
68
|
+
click_button("Save and Continue")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "formats the address variable correctly" do
|
72
|
+
expect(page.evaluate_script("address['recipientName']")).to eq "Ryan Bigg"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "checks out successfully", skip: "Broken. To be revisited" do
|
76
|
+
pend_if_paypal_slow do
|
77
|
+
expect_any_instance_of(Spree::Order).not_to receive(:restart_checkout_flow)
|
78
|
+
move_through_paypal_popup
|
79
|
+
|
80
|
+
expect(page).to have_content("Shipments")
|
81
|
+
click_on "Place Order"
|
82
|
+
expect(page).to have_content("Your order has been processed successfully")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Selenium does not clear cookies properly between test runs, even when
|
88
|
+
# using Capybara.reset_sessions!, see:
|
89
|
+
# https://github.com/jnicklas/capybara/issues/535
|
90
|
+
#
|
91
|
+
# This causes Paypal to remain logged in and not prompt for an email on the
|
92
|
+
# second test run and causes the test to fail. Adding conditional logic for
|
93
|
+
# this greatly increases the test time, so it is left out since CI runs
|
94
|
+
# these with poltergeist.
|
95
|
+
def move_through_paypal_popup
|
96
|
+
expect(page).to have_css('#paypal-button .paypal-button')
|
97
|
+
|
98
|
+
sleep 2 # the PayPal button is not immediately ready
|
99
|
+
|
100
|
+
popup = page.window_opened_by do
|
101
|
+
within_frame find('#paypal-button iframe') do
|
102
|
+
find('div.paypal-button').click
|
103
|
+
end
|
104
|
+
end
|
105
|
+
page.switch_to_window(popup)
|
106
|
+
|
107
|
+
# We don't control this popup window.
|
108
|
+
# So javascript errors are not our errors.
|
109
|
+
begin
|
110
|
+
expect(page).not_to have_selector('body.loading')
|
111
|
+
fill_in("login_email", with: "stembolt_buyer@stembolttest.com")
|
112
|
+
click_on "Next"
|
113
|
+
fill_in("login_password", with: "test1234")
|
114
|
+
|
115
|
+
expect(page).not_to have_selector('body.loading')
|
116
|
+
click_button("btnLogin")
|
117
|
+
|
118
|
+
expect(page).not_to have_selector('body.loading')
|
119
|
+
click_button("Continue")
|
120
|
+
click_button("Agree & Continue")
|
121
|
+
rescue Selenium::WebDriver::Error::JavascriptError => e
|
122
|
+
pending "PayPal had javascript errors in their popup window."
|
123
|
+
raise e
|
124
|
+
rescue Capybara::ElementNotFound => e
|
125
|
+
pending "PayPal delivered unkown HTML in their popup window."
|
126
|
+
raise e
|
127
|
+
rescue Selenium::WebDriver::Error::NoSuchWindowError => e
|
128
|
+
pending "PayPal popup not available."
|
129
|
+
raise e
|
130
|
+
end
|
131
|
+
|
132
|
+
page.switch_to_window(page.windows.first)
|
133
|
+
end
|
134
|
+
|
135
|
+
def fill_in_address
|
136
|
+
address = "order_bill_address_attributes"
|
137
|
+
if page.has_css?("##{address}_firstname", wait: 0)
|
138
|
+
fill_in "#{address}_firstname", with: "Ryan"
|
139
|
+
fill_in "#{address}_lastname", with: "Bigg"
|
140
|
+
else
|
141
|
+
fill_in "#{address}_name", with: "Ryan Bigg"
|
142
|
+
end
|
143
|
+
fill_in "#{address}_address1", with: "143 Swan Street"
|
144
|
+
fill_in "#{address}_city", with: "San Jose"
|
145
|
+
select "United States of America", from: "#{address}_country_id"
|
146
|
+
select "California", from: "#{address}_state_id"
|
147
|
+
fill_in "#{address}_zipcode", with: "95131"
|
148
|
+
fill_in "#{address}_phone", with: "(555) 555-0111"
|
149
|
+
end
|
150
|
+
|
151
|
+
def add_mug_to_cart
|
152
|
+
visit spree.root_path
|
153
|
+
click_link mug.name
|
154
|
+
click_button "add-to-cart-button"
|
155
|
+
end
|
156
|
+
|
157
|
+
def pend_if_paypal_slow
|
158
|
+
yield
|
159
|
+
rescue RSpec::Expectations::ExpectationNotMetError => e
|
160
|
+
pending "PayPal did not answer in #{Capybara.default_max_wait_time} seconds."
|
161
|
+
raise e
|
162
|
+
rescue Selenium::WebDriver::Error::JavascriptError => e
|
163
|
+
pending "PayPal delivered wrong payload because of errors in their popup window."
|
164
|
+
raise e
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'spree/testing_support/order_walkthrough'
|
5
|
+
|
6
|
+
describe "Checkout", type: :feature, js: true do
|
7
|
+
let(:braintree_preferences) { { venmo: true }.merge(preferences) }
|
8
|
+
let(:preferences) { {} }
|
9
|
+
let(:user) { create(:user) }
|
10
|
+
let!(:payment_method) { create_gateway }
|
11
|
+
|
12
|
+
before do
|
13
|
+
create(:store, payment_methods: [payment_method]).tap do |s|
|
14
|
+
s.braintree_configuration.update!(braintree_preferences)
|
15
|
+
end
|
16
|
+
|
17
|
+
go_to_payment_checkout_page
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with Venmo checkout' do
|
21
|
+
context 'when Venmo is disabled' do
|
22
|
+
let(:preferences) { { venmo: false } }
|
23
|
+
|
24
|
+
it 'does not load the Venmo payment button' do
|
25
|
+
expect(page).not_to have_selector('#venmo-button')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when Venmo is enabled' do
|
30
|
+
it 'loads the Venmo payment button' do
|
31
|
+
expect(page).to have_selector('#venmo-button')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when Venmo's button style is customized" do
|
36
|
+
context 'when venmo_button_color is "blue" and venmo_button_width is "280"' do
|
37
|
+
let(:preferences) { { preferred_venmo_button_color: 'blue', preferred_venmo_button_width: '280' } }
|
38
|
+
|
39
|
+
it 'has the correct style' do
|
40
|
+
venmo_button.assert_matches_style(width: '280px', 'background-image': /venmo_blue_button_280x48/)
|
41
|
+
venmo_button.hover
|
42
|
+
venmo_button.assert_matches_style('background-image': /venmo_active_blue_button_280x48/)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when venmo_button_color is "white" and venmo_button_width is "375"' do
|
47
|
+
let(:preferences) { { preferred_venmo_button_color: 'white', preferred_venmo_button_width: '375' } }
|
48
|
+
|
49
|
+
it 'has the correct style' do
|
50
|
+
venmo_button.assert_matches_style(width: '375px', 'background-image': /venmo_white_button_375x48/)
|
51
|
+
venmo_button.hover
|
52
|
+
venmo_button.assert_matches_style('background-image': /venmo_active_white_button_375x48/)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when the Venmo button is clicked' do
|
58
|
+
before { venmo_button.click }
|
59
|
+
|
60
|
+
it 'opens the QR modal which shows an error when closed' do
|
61
|
+
within_frame(venmo_frame) do
|
62
|
+
expect(page).to have_selector('#venmo-qr-code-view')
|
63
|
+
|
64
|
+
click_button('close-icon')
|
65
|
+
|
66
|
+
expect(page).not_to have_selector('#venmo-qr-code-view')
|
67
|
+
end
|
68
|
+
|
69
|
+
expect(page).to have_content('Venmo authorization was canceled by closing the Venmo Desktop modal.')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'with Venmo transactions', vcr: { cassette_name: 'checkout/valid_venmo_transaction' } do
|
74
|
+
before do
|
75
|
+
fake_venmo_successful_tokenization
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'with CreditCard disabled' do
|
79
|
+
it 'can checkout with Venmo' do
|
80
|
+
next_checkout_step
|
81
|
+
finalize_checkout
|
82
|
+
|
83
|
+
expect(Spree::Order.last.complete?).to eq(true)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# To test that the hosted-fields inputs do not conflict with Venmo's
|
88
|
+
context 'with CreditCard enabled' do
|
89
|
+
let(:preferences) { { credit_card: true } }
|
90
|
+
|
91
|
+
it 'can checkout with Venmo' do
|
92
|
+
disable_hosted_fields_inputs
|
93
|
+
disable_hosted_fields_form_listener
|
94
|
+
|
95
|
+
next_checkout_step
|
96
|
+
finalize_checkout
|
97
|
+
|
98
|
+
expect(Spree::Order.last.complete?).to eq(true)
|
99
|
+
expect(Spree::Payment.last.source.venmo?).to eq(true)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# https://developer.paypal.com/braintree/docs/guides/venmo/client-side#custom-integration
|
104
|
+
it "meet's Braintree's acceptance criteria during checkout", aggregate_failures: true do
|
105
|
+
next_checkout_step
|
106
|
+
|
107
|
+
expect(page).to have_content('Payment Type: Venmo')
|
108
|
+
|
109
|
+
finalize_checkout
|
110
|
+
|
111
|
+
expect(page).to have_content('Venmo Account: venmojoe')
|
112
|
+
end
|
113
|
+
|
114
|
+
# the VCR must be based on this test, so it includes HTTP requests of the second order
|
115
|
+
it 'saves the used Venmo source in the wallet and can be reused' do
|
116
|
+
next_checkout_step
|
117
|
+
finalize_checkout
|
118
|
+
go_to_payment_checkout_page(order_number: 'R300000002')
|
119
|
+
|
120
|
+
expect(Spree::User.first.wallet.wallet_payment_sources).not_to be_empty
|
121
|
+
expect(page).to have_selector('#existing_cards')
|
122
|
+
expect(page).to have_content('venmojoe')
|
123
|
+
|
124
|
+
next_checkout_step
|
125
|
+
finalize_checkout
|
126
|
+
|
127
|
+
expect(Spree::Order.all.all?(&:complete?)).to eq(true)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
|
134
|
+
def go_to_payment_checkout_page(order_number: 'R300000001' )
|
135
|
+
order = if Spree.solidus_gem_version >= Gem::Version.new('2.6.0')
|
136
|
+
Spree::TestingSupport::OrderWalkthrough.up_to(:address)
|
137
|
+
else
|
138
|
+
OrderWalkthrough.up_to(:address)
|
139
|
+
end
|
140
|
+
|
141
|
+
order.update!(user: user, number: order_number) # constant order number for VCRs
|
142
|
+
|
143
|
+
allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
|
144
|
+
allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: Spree::User.first)
|
145
|
+
allow_any_instance_of(Spree::Payment).to receive(:gateway_order_id).and_return(order_number)
|
146
|
+
|
147
|
+
visit spree.checkout_state_path(order.state)
|
148
|
+
next_checkout_step
|
149
|
+
end
|
150
|
+
|
151
|
+
def next_checkout_step
|
152
|
+
click_button('Save and Continue')
|
153
|
+
end
|
154
|
+
|
155
|
+
def finalize_checkout
|
156
|
+
click_button('Place Order')
|
157
|
+
end
|
158
|
+
|
159
|
+
def venmo_button
|
160
|
+
find_button('venmo-button', disabled: false)
|
161
|
+
end
|
162
|
+
|
163
|
+
def venmo_frame
|
164
|
+
find('#venmo-desktop-iframe')
|
165
|
+
end
|
166
|
+
|
167
|
+
def fake_venmo_successful_tokenization
|
168
|
+
enable_venmo_inputs
|
169
|
+
fake_payment_method_nonce
|
170
|
+
end
|
171
|
+
|
172
|
+
def enable_venmo_inputs
|
173
|
+
page.execute_script("$('.venmo-fields input').each(function(_index, input){input.removeAttribute('disabled');});")
|
174
|
+
end
|
175
|
+
|
176
|
+
def fake_payment_method_nonce
|
177
|
+
page.execute_script("$('#venmo_payment_method_nonce').val('fake-venmo-account-nonce');")
|
178
|
+
end
|
179
|
+
|
180
|
+
def disable_hosted_fields_inputs
|
181
|
+
page.execute_script("$('.hosted-fields input').each(function(_index, input){input.disabled=true;});")
|
182
|
+
end
|
183
|
+
|
184
|
+
def disable_hosted_fields_form_listener
|
185
|
+
# Once the submit button is enabled, the submit listener has been added
|
186
|
+
find("#checkout_form_payment input[type='submit']:not(:disabled)")
|
187
|
+
page.execute_script("$('#checkout_form_payment').off('submit');")
|
188
|
+
end
|
189
|
+
end
|