Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back PayPal as a payment method for the starter frontend #4743

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,22 @@ jobs:

- install_solidus: { flags: "--sample=false --frontend=starter --authentication=devise" }
- test_page: { expected_text: "The only eCommerce platform you’ll ever need." }
- run:
name: Ensure the correct PayPal is installed for SSF
command: |
cd /tmp/my_app
bundle list | grep 'solidus_paypal_commerce_platform (1.'

- install_solidus: { flags: "--sample=false --frontend=none --authentication=none" }
- test_page: { expected_text: "<title>Ruby on Rails" }

- install_solidus: { flags: "--sample=false --frontend=solidus_frontend --authentication=custom" }
- install_solidus: { flags: "--sample=false --frontend=classic --authentication=custom" }
- test_page: { expected_text: "data-hook=" }

- install_solidus: { flags: "--sample=false --frontend=solidus_starter_frontend --authentication=devise" }
- test_page: { expected_text: "The only eCommerce platform you’ll ever need." }
- run:
name: Ensure the correct PayPal is installed for SSF
command: |
cd /tmp/my_app
bundle list | grep 'solidus_paypal_commerce_platform (0.'

- run:
name: "Test `rake task: extensions:test_app`"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
end

unless Bundler.locked_gems.dependencies['solidus_paypal_commerce_platform']
bundle_command 'add solidus_paypal_commerce_platform'
version = @selected_frontend == 'classic' ? '< 1' : '>= 1.a'
waiting-for-dev marked this conversation as resolved.
Show resolved Hide resolved
bundle_command "add solidus_paypal_commerce_platform --version='#{version}'"
end

generate 'solidus_paypal_commerce_platform:install'
24 changes: 17 additions & 7 deletions core/lib/generators/solidus/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class InstallGenerator < Rails::Generators::AppBase
classic
starter
]

LEGACY_FRONTENDS = %w[
solidus_starter_frontend
solidus_frontend
Expand Down Expand Up @@ -322,18 +323,27 @@ def detect_payment_method_to_install
return 'paypal' if Bundler.locked_gems.dependencies['solidus_paypal_commerce_platform']
return 'bolt' if Bundler.locked_gems.dependencies['solidus_bolt']

options[:payment_method] ||
(options[:auto_accept] && @selected_frontend == 'classic' ? 'paypal' : 'none') ||
(@selected_frontend != 'classic' && 'none') || # bail out if it's not classic
descriptions = {
paypal: "- [#{set_color 'paypal', :bold}] Install `solidus_paypal_commerce_platform` (#{set_color :default, :bold}).",
bolt: "- [#{set_color 'bolt', :bold}] Install `solidus_bolt`.",
none: "- [#{set_color 'none', :bold}] Skip installing a payment method.",
elia marked this conversation as resolved.
Show resolved Hide resolved
}

payment_methods = PAYMENT_METHODS

if @selected_frontend != 'classic'
payment_methods -= ['bolt']
descriptions.delete(:bolt)
end

selected = options[:payment_method] || (options[:auto_accept] && 'paypal') ||
ask_with_description(
default: 'paypal',
limited_to: PAYMENT_METHODS,
limited_to: payment_methods,
desc: <<~TEXT
Which payment method would you like to use?

- [#{set_color 'paypal', :bold}] Install `solidus_paypal_commerce_platform` (#{set_color :default, :bold}).
- [#{set_color 'bolt', :bold}] Install `solidus_bolt`.
- [#{set_color 'none', :bold}] Skip installing a payment method.
#{descriptions.values.join("\n")}
TEXT
)
end
Expand Down
40 changes: 39 additions & 1 deletion core/spec/generators/solidus/install/install_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
aggregate_failures do
expect(generator.instance_variable_get(:@selected_frontend)).to eq("starter")
expect(generator.instance_variable_get(:@selected_authentication)).to eq("devise")
expect(generator.instance_variable_get(:@selected_payment_method)).to eq("none")
expect(generator.instance_variable_get(:@selected_payment_method)).to eq("paypal")
expect(generator.instance_variable_get(:@run_migrations)).to eq(true)
expect(generator.instance_variable_get(:@load_seed_data)).to eq(true)
expect(generator.instance_variable_get(:@load_sample_data)).to eq(true)
Expand Down Expand Up @@ -96,5 +96,43 @@
expect(generator.instance_variable_get(:@selected_frontend)).to eq('starter')
end
end

context 'when asked interactively' do
it 'presents different options for the "classic"' do
questions = []
generator = described_class.new([], ['--frontend=classic', '--authentication=devise'])
allow(generator).to receive(:ask_with_description) { |**args| questions << args }

generator.prepare_options

expect(questions.size).to eq(1)
expect(questions.first[:limited_to]).to eq(['paypal', 'bolt', 'none'])
expect(questions.first[:default]).to eq('paypal')
expect(strip_ansi questions.first[:desc]).to include('[paypal]')
expect(strip_ansi questions.first[:desc]).to include('[bolt]')
expect(strip_ansi questions.first[:desc]).to include('[none]')
end

it 'presents different options for the "classic"' do
questions = []
generator = described_class.new([], ['--frontend=starter', '--authentication=devise'])
allow(generator).to receive(:ask_with_description) { |**args| questions << args }

generator.prepare_options

expect(questions.size).to eq(1)
expect(questions.first[:limited_to]).to eq(['paypal', 'none'])
expect(questions.first[:default]).to eq('paypal')
expect(strip_ansi questions.first[:desc]).to include('[paypal]')
expect(strip_ansi questions.first[:desc]).not_to include('[bolt]')
expect(strip_ansi questions.first[:desc]).to include('[none]')
end
end
end

private

def strip_ansi(string)
string.gsub(/\u001b\[.*?m/, '')
end
end