mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Extract filters for available PMs into service object
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
require 'open_food_network/available_payment_method_filter'
|
||||
|
||||
module EnterprisesHelper
|
||||
def current_distributor
|
||||
@current_distributor ||= current_order(false).andand.distributor
|
||||
@@ -22,7 +24,8 @@ module EnterprisesHelper
|
||||
return [] unless current_distributor.present?
|
||||
payment_methods = current_distributor.payment_methods.available(:front_end).all
|
||||
|
||||
apply_stripe_filters_to(payment_methods)
|
||||
filter = OpenFoodNetwork::AvailablePaymentMethodFilter.new
|
||||
filter.filter!(payment_methods)
|
||||
|
||||
applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor, "FilterPaymentMethods", current_customer.andand.tag_list)
|
||||
applicator.filter!(payment_methods)
|
||||
@@ -98,13 +101,4 @@ module EnterprisesHelper
|
||||
def show_bought_items?
|
||||
order_changes_allowed? && current_order.finalised_line_items.present?
|
||||
end
|
||||
|
||||
def apply_stripe_filters_to(payment_methods)
|
||||
stripe_enabled = Spree::Config.stripe_connect_enabled && Stripe.publishable_key
|
||||
if stripe_enabled
|
||||
payment_methods.reject!{ |p| p.type.ends_with?("StripeConnect") && p.preferred_enterprise_id == 0 }
|
||||
else
|
||||
payment_methods.reject!{ |p| p.type.ends_with?("StripeConnect") }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
17
lib/open_food_network/available_payment_method_filter.rb
Normal file
17
lib/open_food_network/available_payment_method_filter.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
module OpenFoodNetwork
|
||||
class AvailablePaymentMethodFilter
|
||||
def filter!(payment_methods)
|
||||
if stripe_enabled?
|
||||
payment_methods.reject!{ |p| p.type.ends_with?("StripeConnect") && p.preferred_enterprise_id.zero? }
|
||||
else
|
||||
payment_methods.reject!{ |p| p.type.ends_with?("StripeConnect") }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def stripe_enabled?
|
||||
Spree::Config.stripe_connect_enabled && Stripe.publishable_key
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user