Skip to content

Commit

Permalink
Merge pull request #4743 from nebulab/elia/paypal-ssf-support
Browse files Browse the repository at this point in the history
Add back PayPal as a payment method for the starter frontend
  • Loading branch information
waiting-for-dev authored Dec 13, 2022
2 parents 7cd09f5 + d40a01c commit 553c26e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 13 deletions.
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'
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.",
}

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

0 comments on commit 553c26e

Please sign in to comment.