From 6c281e288cf55158d17b04ccdea4df686ad0cc8d Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 24 Jul 2021 22:50:46 +0100 Subject: [PATCH 1/8] Switch filter to StripeSCA, this must have been an error, must be tested (manually or automatically) --- lib/open_food_network/available_payment_method_filter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/open_food_network/available_payment_method_filter.rb b/lib/open_food_network/available_payment_method_filter.rb index f15714d1fb..4afbfa94d5 100644 --- a/lib/open_food_network/available_payment_method_filter.rb +++ b/lib/open_food_network/available_payment_method_filter.rb @@ -5,12 +5,12 @@ module OpenFoodNetwork def filter!(payment_methods) if stripe_enabled? payment_methods.to_a.reject! do |payment_method| - payment_method.type.ends_with?("StripeConnect") && + payment_method.type.ends_with?("StripeSCA") && stripe_configuration_incomplete?(payment_method) end else payment_methods.to_a.reject! do |payment_method| - payment_method.type.ends_with?("StripeConnect") + payment_method.type.ends_with?("StripeSCA") end end end From 60adaf36469fc9581a27991fc25cda76087e62e4 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 26 Nov 2021 16:34:17 +1100 Subject: [PATCH 2/8] Disallow StripeConnect in subscriptions --- app/models/subscription.rb | 1 - .../subscriptions/validator_spec.rb | 4 ++-- spec/jobs/subscription_confirm_job_spec.rb | 17 ----------------- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/app/models/subscription.rb b/app/models/subscription.rb index 304b7e71d9..ce87b1dd57 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -4,7 +4,6 @@ class Subscription < ApplicationRecord include SetUnusedAddressFields ALLOWED_PAYMENT_METHOD_TYPES = ["Spree::PaymentMethod::Check", - "Spree::Gateway::StripeConnect", "Spree::Gateway::StripeSCA"].freeze searchable_attributes :shop_id, :canceled_at, :paused_at diff --git a/engines/order_management/spec/services/order_management/subscriptions/validator_spec.rb b/engines/order_management/spec/services/order_management/subscriptions/validator_spec.rb index 7c52fba12a..5219714424 100644 --- a/engines/order_management/spec/services/order_management/subscriptions/validator_spec.rb +++ b/engines/order_management/spec/services/order_management/subscriptions/validator_spec.rb @@ -360,9 +360,9 @@ module OrderManagement end end - context "when using the StripeConnect payment gateway" do + context "when using the StripeSCA payment gateway" do let(:payment_method) { - instance_double(Spree::PaymentMethod, type: "Spree::Gateway::StripeConnect") + instance_double(Spree::PaymentMethod, type: "Spree::Gateway::StripeSCA") } before { expect(subscription).to receive(:customer).at_least(:once) { customer } } diff --git a/spec/jobs/subscription_confirm_job_spec.rb b/spec/jobs/subscription_confirm_job_spec.rb index 8c2ac1a2cb..8681f5fc6d 100644 --- a/spec/jobs/subscription_confirm_job_spec.rb +++ b/spec/jobs/subscription_confirm_job_spec.rb @@ -190,23 +190,6 @@ describe SubscriptionConfirmJob do job.send(:confirm_order!, order) end end - - context "Stripe Connect" do - let(:stripe_connect_payment_method) { create(:stripe_connect_payment_method) } - let(:stripe_connect_payment) { - create(:payment, amount: 10, payment_method: stripe_connect_payment_method) - } - - before do - allow(order).to receive(:pending_payments) { [stripe_connect_payment] } - allow(stripe_connect_payment_method).to receive(:purchase) { true } - end - - it "runs the charges in offline mode" do - job.send(:confirm_order!, order) - expect(stripe_connect_payment_method).to have_received(:purchase) - end - end end context "when payments need to be processed" do From 178d296c9fafe1370c9cff711af99aee4b966c8c Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 26 Nov 2021 16:36:47 +1100 Subject: [PATCH 3/8] Adapt specs to use stripe_sca_payment_method There are still some specs directly related to StripeConnect and I left them for now. --- .../stripe_payment_setup_spec.rb | 2 +- .../admin/subscriptions_controller_spec.rb | 2 +- .../payments/payments_controller_spec.rb | 16 ----- .../admin/payment_methods_controller_spec.rb | 6 +- spec/helpers/enterprises_helper_spec.rb | 10 ++-- spec/lib/stripe/profile_storer_spec.rb | 33 ++++------- spec/models/spree/gateway_tagging_spec.rb | 4 +- spec/models/spree/order_spec.rb | 2 +- spec/models/spree/payment_spec.rb | 4 +- spec/support/request/stripe_stubs.rb | 8 +-- spec/system/admin/subscriptions_spec.rb | 6 +- .../consumer/shopping/checkout_stripe_spec.rb | 59 ------------------- 12 files changed, 32 insertions(+), 120 deletions(-) diff --git a/engines/order_management/spec/services/order_management/subscriptions/stripe_payment_setup_spec.rb b/engines/order_management/spec/services/order_management/subscriptions/stripe_payment_setup_spec.rb index ee4d754b49..7936648f15 100644 --- a/engines/order_management/spec/services/order_management/subscriptions/stripe_payment_setup_spec.rb +++ b/engines/order_management/spec/services/order_management/subscriptions/stripe_payment_setup_spec.rb @@ -34,7 +34,7 @@ module OrderManagement end context "when the payment method is a stripe payment method" do - let(:payment_method) { create(:stripe_connect_payment_method) } + let(:payment_method) { create(:stripe_sca_payment_method) } context "and the card is already set (the payment source is a credit card)" do it "returns the pending payment with no change" do diff --git a/spec/controllers/admin/subscriptions_controller_spec.rb b/spec/controllers/admin/subscriptions_controller_spec.rb index 125271c483..8ca50fdacf 100644 --- a/spec/controllers/admin/subscriptions_controller_spec.rb +++ b/spec/controllers/admin/subscriptions_controller_spec.rb @@ -753,7 +753,7 @@ describe Admin::SubscriptionsController, type: :controller do end context "when other payment methods exist" do - let!(:stripe) { create(:stripe_connect_payment_method, distributors: [shop]) } + let!(:stripe) { create(:stripe_sca_payment_method, distributors: [shop]) } let!(:paypal) { Spree::Gateway::PayPalExpress.create!(name: "PayPalExpress", distributor_ids: [shop.id]) } diff --git a/spec/controllers/spree/admin/orders/payments/payments_controller_spec.rb b/spec/controllers/spree/admin/orders/payments/payments_controller_spec.rb index 47d0376534..896d6f60a1 100644 --- a/spec/controllers/spree/admin/orders/payments/payments_controller_spec.rb +++ b/spec/controllers/spree/admin/orders/payments/payments_controller_spec.rb @@ -44,22 +44,6 @@ describe Spree::Admin::PaymentsController, type: :controller do end end - context "with Stripe payment where payment.process! errors out" do - let!(:payment_method) { create(:stripe_connect_payment_method, distributors: [shop]) } - before do - allow_any_instance_of(Spree::Payment). - to receive(:process_offline!). - and_raise(Spree::Core::GatewayError.new("Payment Gateway Error")) - end - - it "redirects to new payment page with flash error" do - spree_post :create, payment: params, order_id: order.number - - redirects_to_new_payment_page_with_flash_error("Payment Gateway Error") - expect(order.reload.payments.last.state).to eq "checkout" - end - end - context "with StripeSCA payment" do let!(:payment_method) { create(:stripe_sca_payment_method, distributors: [shop]) } diff --git a/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/spec/controllers/spree/admin/payment_methods_controller_spec.rb index 418a7a2a56..cab1c80092 100644 --- a/spec/controllers/spree/admin/payment_methods_controller_spec.rb +++ b/spec/controllers/spree/admin/payment_methods_controller_spec.rb @@ -108,12 +108,12 @@ module Spree end end - context "on a StripeConnect payment method" do + context "on a StripeSCA payment method" do let!(:user) { create(:user, enterprise_limit: 2) } let!(:enterprise1) { create(:distributor_enterprise, owner: user) } let!(:enterprise2) { create(:distributor_enterprise, owner: create(:user)) } let!(:payment_method) { - create(:stripe_connect_payment_method, distributor_ids: [enterprise1.id, enterprise2.id], + create(:stripe_sca_payment_method, distributor_ids: [enterprise1.id, enterprise2.id], preferred_enterprise_id: enterprise2.id) } @@ -124,7 +124,7 @@ module Spree { id: payment_method.id, payment_method: { - type: "Spree::Gateway::StripeConnect", + type: "Spree::Gateway::StripeSCA", preferred_enterprise_id: enterprise1.id } } diff --git a/spec/helpers/enterprises_helper_spec.rb b/spec/helpers/enterprises_helper_spec.rb index 5959392667..7029ede7c3 100644 --- a/spec/helpers/enterprises_helper_spec.rb +++ b/spec/helpers/enterprises_helper_spec.rb @@ -262,14 +262,14 @@ describe EnterprisesHelper, type: :helper do end end - context "when StripeConnect payment methods are present" do + context "when Stripe payment methods are present" do let!(:pm3) { - create(:stripe_connect_payment_method, distributors: [distributor], - preferred_enterprise_id: distributor.id) + create(:stripe_sca_payment_method, distributors: [distributor], + preferred_enterprise_id: distributor.id) } let!(:pm4) { - create(:stripe_connect_payment_method, distributors: [distributor], - preferred_enterprise_id: some_other_distributor.id) + create(:stripe_sca_payment_method, distributors: [distributor], + preferred_enterprise_id: some_other_distributor.id) } let(:available_payment_methods) { helper.available_payment_methods } diff --git a/spec/lib/stripe/profile_storer_spec.rb b/spec/lib/stripe/profile_storer_spec.rb index d23ed84e95..e7b69f8c8c 100644 --- a/spec/lib/stripe/profile_storer_spec.rb +++ b/spec/lib/stripe/profile_storer_spec.rb @@ -4,41 +4,28 @@ require 'spec_helper' module Stripe describe ProfileStorer do + include StripeStubs + describe "create_customer_from_token" do - let(:payment) { create(:payment) } - let(:stripe_payment_method) { create(:stripe_connect_payment_method) } + let(:stripe_payment_method) { create(:stripe_sca_payment_method) } + let(:card) { create(:credit_card, gateway_payment_profile_id: card_id) } + let(:payment) { create(:payment, source: card, payment_method: stripe_payment_method) } let(:profile_storer) { Stripe::ProfileStorer.new(payment, stripe_payment_method.provider) } let(:customer_id) { "cus_A123" } let(:card_id) { "card_2342" } - let(:customer_response_mock) { { status: 200, body: customer_response_body } } + let(:customer_response_mock) { + { status: 200, body: JSON.generate(id: customer_id, sources: { data: [{ id: "1" }] }) } + } before do Stripe.api_key = "sk_test_12345" - stub_request(:post, "https://api.stripe.com/v1/customers") - .with(basic_auth: ["sk_test_12345", ""], body: { email: payment.order.email }) - .to_return(customer_response_mock) - end - - context "when called from Stripe Connect" do - let(:customer_response_body) { - JSON.generate(id: customer_id, default_card: card_id, sources: { data: [{ id: "1" }] }) - } - - it "fetches the customer id and the card id from the correct response fields" do - profile_storer.create_customer_from_token - - expect(payment.source.gateway_customer_profile_id).to eq customer_id - expect(payment.source.gateway_payment_profile_id).to eq card_id - end + stub_customers_post_request(email: payment.order.email, response: customer_response_mock) + stub_payment_method_attach_request(payment_method: card_id, customer: customer_id) end context "when called from Stripe SCA" do - let(:customer_response_body) { - JSON.generate(customer: customer_id, id: card_id, sources: { data: [{ id: "1" }] }) - } - it "fetches the customer id and the card id from the correct response fields" do profile_storer.create_customer_from_token diff --git a/spec/models/spree/gateway_tagging_spec.rb b/spec/models/spree/gateway_tagging_spec.rb index 35b08ae9bb..410ef1ec35 100644 --- a/spec/models/spree/gateway_tagging_spec.rb +++ b/spec/models/spree/gateway_tagging_spec.rb @@ -45,9 +45,9 @@ module Spree it_behaves_like "taggable", "Spree::PaymentMethod" end - describe Gateway::StripeConnect do + describe Gateway::StripeSCA do subject do - # StripeConnect needs an owner to be valid. + # StripeSCA needs an owner to be valid. valid_subject.tap { |m| m.preferred_enterprise_id = shop.id } end diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index ecc4d5dae8..0d485041f9 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -1213,7 +1213,7 @@ describe Spree::Order do let!(:enterprise) { create(:enterprise) } let!(:order) { create(:order, distributor: enterprise) } let!(:payment_method) { - create(:stripe_connect_payment_method, distributor_ids: [enterprise.id]) + create(:stripe_sca_payment_method, distributor_ids: [enterprise.id]) } let!(:payment) { create(:payment, order: order, payment_method: payment_method) } diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb index 8ae18a4611..6f062d22a0 100644 --- a/spec/models/spree/payment_spec.rb +++ b/spec/models/spree/payment_spec.rb @@ -920,8 +920,8 @@ describe Spree::Payment do context "to Stripe payments" do let(:shop) { create(:enterprise) } let(:payment_method) { - create(:stripe_connect_payment_method, distributor_ids: [create(:distributor_enterprise).id], - preferred_enterprise_id: shop.id) + create(:stripe_sca_payment_method, distributor_ids: [create(:distributor_enterprise).id], + preferred_enterprise_id: shop.id) } let(:payment) { create(:payment, order: order, payment_method: payment_method, amount: order.total) diff --git a/spec/support/request/stripe_stubs.rb b/spec/support/request/stripe_stubs.rb index 637c8b7ab7..53bf241c3b 100644 --- a/spec/support/request/stripe_stubs.rb +++ b/spec/support/request/stripe_stubs.rb @@ -28,11 +28,11 @@ module StripeStubs end # Attaches the payment method to the customer in the hub's stripe account - def stub_payment_method_attach_request + def stub_payment_method_attach_request(payment_method: "pm_123", customer: "cus_A123") stub_request(:post, - "https://api.stripe.com/v1/payment_methods/pm_123/attach") - .with(body: { customer: "cus_A123" }) - .to_return(hub_payment_method_response_mock({ pm_id: "pm_123" })) + "https://api.stripe.com/v1/payment_methods/#{payment_method}/attach") + .with(body: { customer: customer }) + .to_return(hub_payment_method_response_mock({ pm_id: payment_method })) end def stub_retrieve_payment_method_request(payment_method_id = "pm_1234") diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index e5d544ef7b..41807ec0e4 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -220,7 +220,7 @@ describe 'Subscriptions' do } let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) } let!(:payment_method) { - create(:stripe_connect_payment_method, name: 'Credit Card', distributors: [shop]) + create(:stripe_sca_payment_method, name: 'Credit Card', distributors: [shop]) } let!(:shipping_method) { create(:shipping_method, distributors: [shop]) } @@ -387,7 +387,7 @@ describe 'Subscriptions' do } let!(:payment_method) { create(:payment_method, distributors: [shop]) } let!(:stripe_payment_method) { - create(:stripe_connect_payment_method, name: 'Credit Card', distributors: [shop]) + create(:stripe_sca_payment_method, name: 'Credit Card', distributors: [shop]) } let!(:shipping_method) { create(:shipping_method, distributors: [shop]) } let!(:subscription) { @@ -536,7 +536,7 @@ describe 'Subscriptions' do let!(:enterprise_fee) { create(:enterprise_fee, amount: 1.75) } let!(:order_cycle) { create(:simple_order_cycle, coordinator: shop) } let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) } - let!(:payment_method) { create(:stripe_connect_payment_method, distributors: [shop]) } + let!(:payment_method) { create(:stripe_sca_payment_method, distributors: [shop]) } let!(:shipping_method) { create(:shipping_method, distributors: [shop]) } before do diff --git a/spec/system/consumer/shopping/checkout_stripe_spec.rb b/spec/system/consumer/shopping/checkout_stripe_spec.rb index 8e236dc60d..c91d64de10 100644 --- a/spec/system/consumer/shopping/checkout_stripe_spec.rb +++ b/spec/system/consumer/shopping/checkout_stripe_spec.rb @@ -37,65 +37,6 @@ describe "Check out with Stripe", js: true do distributor.shipping_methods << [shipping_with_fee, free_shipping] end - context 'login in as user' do - let(:user) { create(:user) } - - before do - login_as(user) - end - - context "with Stripe Connect" do - let!(:stripe_pm) do - create(:stripe_connect_payment_method, distributors: [distributor]) - end - - let!(:saved_card) do - create(:credit_card, - user_id: user.id, - month: "01", - year: "2025", - cc_type: "visa", - number: "1111111111111111", - payment_method_id: stripe_pm.id, - gateway_customer_profile_id: "i_am_saved") - end - - let!(:stripe_account) { - create(:stripe_account, enterprise_id: distributor.id, stripe_user_id: 'some_id') - } - - let(:response_mock) { { id: "ch_1234", object: "charge", amount: 2000 } } - - around do |example| - original_stripe_connect_enabled = Spree::Config[:stripe_connect_enabled] - example.run - Spree::Config.set(stripe_connect_enabled: original_stripe_connect_enabled) - end - - before do - stub_request(:post, "https://api.stripe.com/v1/charges") - .with(basic_auth: ["sk_test_12345", ""]) - .to_return(status: 200, body: JSON.generate(response_mock)) - - visit checkout_path - fill_out_form(shipping_with_fee.name, stripe_pm.name, save_default_addresses: false) - end - - it "allows use of a saved card" do - # shows the saved credit card dropdown - expect(page).to have_content I18n.t("spree.checkout.payment.stripe.used_saved_card") - - # default card is selected, form element is not shown - expect(page).to have_no_selector "#card-element.StripeElement" - expect(page).to have_select 'selected_card', selected: "Visa x-1111 Exp:01/2025" - - # allows checkout - place_order - expect(page).to have_content "Your order has been processed successfully" - end - end - end - describe "using Stripe SCA" do let!(:stripe_account) { create(:stripe_account, enterprise: distributor) } let!(:stripe_sca_payment_method) { From 28e6fa235c715a3277d18fae003a2c04837744b5 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Mon, 20 Dec 2021 15:23:58 +1100 Subject: [PATCH 4/8] Style Layout/HashAlignment --- .../spree/admin/payment_methods_controller_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/spec/controllers/spree/admin/payment_methods_controller_spec.rb index cab1c80092..457ef4afe5 100644 --- a/spec/controllers/spree/admin/payment_methods_controller_spec.rb +++ b/spec/controllers/spree/admin/payment_methods_controller_spec.rb @@ -113,8 +113,11 @@ module Spree let!(:enterprise1) { create(:distributor_enterprise, owner: user) } let!(:enterprise2) { create(:distributor_enterprise, owner: create(:user)) } let!(:payment_method) { - create(:stripe_sca_payment_method, distributor_ids: [enterprise1.id, enterprise2.id], - preferred_enterprise_id: enterprise2.id) + create( + :stripe_sca_payment_method, + distributor_ids: [enterprise1.id, enterprise2.id], + preferred_enterprise_id: enterprise2.id + ) } before { allow(controller).to receive(:spree_current_user) { user } } From 6966dea0f56f3c66617e2ced65786b6a0245a758 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 26 Nov 2021 17:49:41 +1100 Subject: [PATCH 5/8] Extract changing Stripe method selection logic It will change and it's clearer in a separate method. --- .../spree/admin/payment_methods_controller.rb | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/controllers/spree/admin/payment_methods_controller.rb b/app/controllers/spree/admin/payment_methods_controller.rb index e1dc035e91..223d7cbe2d 100644 --- a/app/controllers/spree/admin/payment_methods_controller.rb +++ b/app/controllers/spree/admin/payment_methods_controller.rb @@ -101,12 +101,7 @@ module Spree end def load_data - @providers = if Rails.env.dev? || Rails.env.test? - Gateway.providers.sort_by(&:name) - else - Gateway.providers.reject{ |p| p.name.include? "Bogus" }.sort_by(&:name) - end - @providers.reject!{ |provider| stripe_provider?(provider) } unless show_stripe? + @providers = load_providers @calculators = PaymentMethod.calculators.sort_by(&:name) end @@ -126,6 +121,20 @@ module Spree # rubocop:enable Style/TernaryParentheses end + def load_providers + providers = Gateway.providers.sort_by(&:name) + + unless Rails.env.dev? || Rails.env.test? + providers.reject! { |provider| provider.name.include? "Bogus" } + end + + unless show_stripe? + providers.reject! { |provider| stripe_provider?(provider) } + end + + providers + end + # Show Stripe as an option if enabled, or if the # current payment_method is already a Stripe method def show_stripe? From 22de35772463801b66e8c1e723813592444cc1e9 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Mon, 20 Dec 2021 17:12:19 +1100 Subject: [PATCH 6/8] Hide deprecated StripeConnect payment gateway StripeConnect has been replaced by StripeSCA but some people still use the old StripeConnect. Let's prevent people from creating deprecated payment methods before migrating existing data. --- .../spree/admin/payment_methods_controller.rb | 5 ++ .../admin/payment_methods_controller_spec.rb | 53 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/app/controllers/spree/admin/payment_methods_controller.rb b/app/controllers/spree/admin/payment_methods_controller.rb index 223d7cbe2d..26f5e9e2cd 100644 --- a/app/controllers/spree/admin/payment_methods_controller.rb +++ b/app/controllers/spree/admin/payment_methods_controller.rb @@ -132,6 +132,11 @@ module Spree providers.reject! { |provider| stripe_provider?(provider) } end + # This method is deprecated and will be removed soon: + unless @payment_method&.type == "Spree::Gateway::StripeConnect" + providers.reject! { |provider| provider.name.ends_with?("StripeConnect") } + end + providers end diff --git a/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/spec/controllers/spree/admin/payment_methods_controller_spec.rb index 457ef4afe5..837f175469 100644 --- a/spec/controllers/spree/admin/payment_methods_controller_spec.rb +++ b/spec/controllers/spree/admin/payment_methods_controller_spec.rb @@ -8,6 +8,59 @@ module Spree end describe Admin::PaymentMethodsController, type: :controller do + let(:user) { + create(:user, enterprises: [create(:distributor_enterprise)]) + } + + describe "#new" do + before { allow(controller).to receive(:spree_current_user) { user } } + + it "allows to select from a range of payment gateways" do + spree_get :new + providers = assigns(:providers).map(&:to_s) + + expect(providers).to eq %w[ + Spree::Gateway::Bogus + Spree::Gateway::BogusSimple + Spree::Gateway::PayPalExpress + Spree::PaymentMethod::Check + ] + end + + it "allows to select StripeSCA when configured" do + allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(true) + + spree_get :new + providers = assigns(:providers).map(&:to_s) + + expect(providers).to include "Spree::Gateway::StripeSCA" + expect(providers).to_not include "Spree::Gateway::StripeConnect" + end + end + + describe "#edit" do + let(:deprecated_stripe) { + create( + :stripe_connect_payment_method, + distributor_ids: [enterprise_id], + preferred_enterprise_id: enterprise_id + ) + } + let(:enterprise_id) { user.enterprise_ids.first } + + before { allow(controller).to receive(:spree_current_user) { user } } + + it "shows the current gateway type even if deprecated" do + allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(true) + + spree_get :edit, id: deprecated_stripe.id + providers = assigns(:providers).map(&:to_s) + + expect(providers).to include "Spree::Gateway::StripeSCA" + expect(providers).to include "Spree::Gateway::StripeConnect" + end + end + describe "#create and #update" do let!(:enterprise) { create(:distributor_enterprise, owner: user) } let(:payment_method) { From 470fc928257ba81cef492aa202449ca810f1083b Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 1 Dec 2021 16:27:45 +1100 Subject: [PATCH 7/8] Fix old, confusing typo --- app/controllers/spree/admin/payment_methods_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/spree/admin/payment_methods_controller.rb b/app/controllers/spree/admin/payment_methods_controller.rb index 26f5e9e2cd..088b90860c 100644 --- a/app/controllers/spree/admin/payment_methods_controller.rb +++ b/app/controllers/spree/admin/payment_methods_controller.rb @@ -124,7 +124,7 @@ module Spree def load_providers providers = Gateway.providers.sort_by(&:name) - unless Rails.env.dev? || Rails.env.test? + unless Rails.env.development? || Rails.env.test? providers.reject! { |provider| provider.name.include? "Bogus" } end From 6d1e984af7899f41d9f059612c64c2b9d8a1f76c Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 2 Dec 2021 09:50:03 +1100 Subject: [PATCH 8/8] Enable testers to activate StripeConnect This will make it easier to test the removal of StripeConnect. --- app/controllers/spree/admin/payment_methods_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/spree/admin/payment_methods_controller.rb b/app/controllers/spree/admin/payment_methods_controller.rb index 088b90860c..1a682d58f5 100644 --- a/app/controllers/spree/admin/payment_methods_controller.rb +++ b/app/controllers/spree/admin/payment_methods_controller.rb @@ -133,7 +133,8 @@ module Spree end # This method is deprecated and will be removed soon: - unless @payment_method&.type == "Spree::Gateway::StripeConnect" + unless @payment_method&.type == "Spree::Gateway::StripeConnect" || + OpenFoodNetwork::FeatureToggle.enabled?("StripeConnect") providers.reject! { |provider| provider.name.ends_with?("StripeConnect") } end