Let people choose which payment methods are available to customers on order cycles

This commit is contained in:
Cillian O'Ruanaidh
2022-10-07 17:14:11 +01:00
parent 5718f9f00c
commit 4e6d64c0a1
18 changed files with 789 additions and 340 deletions

View File

@@ -1,30 +0,0 @@
# frozen_string_literal: true
module OpenFoodNetwork
class AvailablePaymentMethodFilter
def filter!(payment_methods)
if stripe_enabled?
payment_methods.to_a.reject! do |payment_method|
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?("StripeSCA")
end
end
end
private
def stripe_enabled?
Spree::Config.stripe_connect_enabled && Stripe.publishable_key
end
def stripe_configuration_incomplete?(payment_method)
payment_method.preferred_enterprise_id.nil? ||
payment_method.preferred_enterprise_id.zero? ||
payment_method.stripe_account_id.blank?
end
end
end