Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix creating payment method on the admin panel (#12786)

Damian Kaczmarczyk9bb7f3f35f77
diff --git a/admin/app/controllers/spree/admin/payment_methods_controller.rb b/admin/app/controllers/spree/admin/payment_methods_controller.rb
index 90f8c6b434..ad2631e02d 100644
--- a/admin/app/controllers/spree/admin/payment_methods_controller.rb
+++ b/admin/app/controllers/spree/admin/payment_methods_controller.rb
@@ -14,10 +14,10 @@ module Spree
if params[:payment_method].present?
payment_type = params[:payment_method].delete(:type)
# Find the actual class from our allowed types rather than using constantize
- payment_class = allowed_payment_types.find { |type| type.to_s == payment_type }
+ payment_class = allowed_payment_types.find { |type| type == payment_type }
- if payment_class
- @object = payment_class.new
+ if payment_class.present?
+ @object = payment_class.constantize.new
end
end
end
@@ -45,7 +45,9 @@ module Spree
end
def allowed_payment_types
- Rails.application.config.spree.payment_methods
+ # We need to map to strings, otherwise some weird things happen with STI
+ # where Rails can't find the ancestor class when we try to save the payment method.
+ Rails.application.config.spree.payment_methods.map(&:to_s)
end
def permitted_resource_params