From 2e0fa0dcb767ccbde0c3a4e4fd25a302038a8354 Mon Sep 17 00:00:00 2001 From: George Mendoza Date: Thu, 2 Mar 2023 15:25:00 +0800 Subject: [PATCH 1/3] Fix incorrect description for starter option spec --- core/spec/generators/solidus/install/install_generator_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/spec/generators/solidus/install/install_generator_spec.rb b/core/spec/generators/solidus/install/install_generator_spec.rb index 88f4b7ce26f..842502ab9de 100644 --- a/core/spec/generators/solidus/install/install_generator_spec.rb +++ b/core/spec/generators/solidus/install/install_generator_spec.rb @@ -113,7 +113,7 @@ expect(strip_ansi questions.first[:desc]).to include('[none]') end - it 'presents different options for the "classic"' do + it 'presents different options for the "starter"' do questions = [] generator = described_class.new([], ['--frontend=starter', '--authentication=devise']) allow(generator).to receive(:ask_with_description) { |**args| questions << args } From 54a4abc93ee0609e799dbc8fde6a20b58a3c7125 Mon Sep 17 00:00:00 2001 From: George Mendoza Date: Thu, 2 Mar 2023 15:25:56 +0800 Subject: [PATCH 2/3] Convert PAYMENT_METHODS into an array of payment method hashes --- .../solidus/install/install_generator.rb | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/core/lib/generators/solidus/install/install_generator.rb b/core/lib/generators/solidus/install/install_generator.rb index 831b53bdca6..b9bdfbfdb6c 100644 --- a/core/lib/generators/solidus/install/install_generator.rb +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -29,10 +29,25 @@ class InstallGenerator < Rails::Generators::AppBase none ] - PAYMENT_METHODS = %w[ - paypal - bolt - none + PAYMENT_METHODS = [ + { + name: 'paypal', + frontends: %w[none classic starter], + description: 'Install `solidus_paypal_commerce_platform`', + default: true, + }, + { + name: 'bolt', + frontends: %w[classic], + description: 'Install `solidus_bolt`', + default: false, + }, + { + name: 'none', + frontends: %w[none classic starter], + description: 'Skip installing a payment method', + default: false, + }, ] class_option :migrate, type: :boolean, default: true, banner: 'Run Solidus migrations' @@ -48,7 +63,7 @@ class InstallGenerator < Rails::Generators::AppBase class_option :frontend, type: :string, enum: FRONTENDS + LEGACY_FRONTENDS, default: nil, desc: "Indicates which frontend to install." class_option :authentication, type: :string, enum: AUTHENTICATIONS, default: nil, desc: "Indicates which authentication system to install." - class_option :payment_method, type: :string, enum: PAYMENT_METHODS, default: nil, desc: "Indicates which payment method to install." + class_option :payment_method, type: :string, enum: PAYMENT_METHODS.map { |payment_method| payment_method[:name] }, default: nil, desc: "Indicates which payment method to install." # DEPRECATED class_option :with_authentication, type: :boolean, hide: true, default: nil @@ -323,29 +338,26 @@ 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'] - 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) + selected_frontend_payment_methods = PAYMENT_METHODS.select do |payment_method| + payment_method[:frontends].include?(@selected_frontend) end selected = options[:payment_method] || (options[:auto_accept] && 'paypal') || ask_with_description( default: 'paypal', - limited_to: payment_methods, + limited_to: selected_frontend_payment_methods.map { |payment_method| payment_method[:name] }, desc: <<~TEXT Which payment method would you like to use? - #{descriptions.values.join("\n")} + #{selected_frontend_payment_methods.map { |payment_method| formatted_payment_method_description(payment_method) }.join("\n")} TEXT ) end + + def formatted_payment_method_description(payment_method) + default_label = " (#{set_color :default, :bold})" if payment_method[:default] + + "- [#{set_color payment_method[:name], :bold}] #{payment_method[:description]}#{default_label}." + end end end From 3b9d19632404926cff79b6046649fc59f3d46880 Mon Sep 17 00:00:00 2001 From: George Mendoza Date: Thu, 2 Mar 2023 15:58:46 +0800 Subject: [PATCH 3/3] Add Braintree to the installer as a payment method option Closes https://github.com/solidusio/solidus/issues/4749. --- .circleci/config.yml | 8 ++++++++ .../install/app_templates/payment_method/braintree.rb | 5 +++++ core/lib/generators/solidus/install/install_generator.rb | 6 ++++++ .../generators/solidus/install/install_generator_spec.rb | 4 +++- 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 core/lib/generators/solidus/install/app_templates/payment_method/braintree.rb diff --git a/.circleci/config.yml b/.circleci/config.yml index f2218d74418..273f17fc5e8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -218,6 +218,14 @@ jobs: cd /tmp/my_app bundle list | grep 'solidus_paypal_commerce_platform (1.' + - install_solidus: { flags: "--sample=false --frontend=starter --payment-method=braintree" } + - test_page: { expected_text: "The only eCommerce platform you’ll ever need." } + - run: + name: Ensure the correct Braintree is installed for SSF + command: | + cd /tmp/my_app + bundle list | grep 'solidus_braintree (3.' + - install_solidus: { flags: "--sample=false --frontend=none --authentication=none" } - test_page: { expected_text: "Ruby on Rails" } diff --git a/core/lib/generators/solidus/install/app_templates/payment_method/braintree.rb b/core/lib/generators/solidus/install/app_templates/payment_method/braintree.rb new file mode 100644 index 00000000000..a3bebb93132 --- /dev/null +++ b/core/lib/generators/solidus/install/app_templates/payment_method/braintree.rb @@ -0,0 +1,5 @@ +unless Bundler.locked_gems.dependencies['solidus_braintree'] + bundle_command 'add solidus_braintree --version "~> 3.0"' +end + +generate 'solidus_braintree:install' diff --git a/core/lib/generators/solidus/install/install_generator.rb b/core/lib/generators/solidus/install/install_generator.rb index b9bdfbfdb6c..fb82b5edb8f 100644 --- a/core/lib/generators/solidus/install/install_generator.rb +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -42,6 +42,12 @@ class InstallGenerator < Rails::Generators::AppBase description: 'Install `solidus_bolt`', default: false, }, + { + name: 'braintree', + frontends: %w[none starter], + description: 'Install `solidus_braintree`', + default: false, + }, { name: 'none', frontends: %w[none classic starter], diff --git a/core/spec/generators/solidus/install/install_generator_spec.rb b/core/spec/generators/solidus/install/install_generator_spec.rb index 842502ab9de..fe110bdc526 100644 --- a/core/spec/generators/solidus/install/install_generator_spec.rb +++ b/core/spec/generators/solidus/install/install_generator_spec.rb @@ -110,6 +110,7 @@ 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_not include('[braintree]') expect(strip_ansi questions.first[:desc]).to include('[none]') end @@ -121,10 +122,11 @@ generator.prepare_options expect(questions.size).to eq(1) - expect(questions.first[:limited_to]).to eq(['paypal', 'none']) + expect(questions.first[:limited_to]).to eq(['paypal', 'braintree', '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('[braintree]') expect(strip_ansi questions.first[:desc]).to include('[none]') end end