Extract filters for available PMs into service object

This commit is contained in:
Rob Harrington
2017-09-13 09:01:33 +10:00
parent 0bbaafbd41
commit 1cd1e9dc37
2 changed files with 21 additions and 10 deletions

View 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