From 303b91af5e3cb77509ec9d886c895626a4902cdf Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 17 Feb 2026 14:07:11 +1100 Subject: [PATCH] Move list of payment actions from card to gateway We currently ask the credit card first which payment actions like "void" it supports. But all the logic is not card specifc. It depends on the payment method which actions it supports. And instead of having two different classes potentially being the source of truth for actions, I prefer leaving that responsibility with exactly one class, the payment method. I'll move the `can_?` methods next. --- app/models/spree/credit_card.rb | 4 ---- app/models/spree/gateway.rb | 4 ++++ app/models/spree/payment.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/spree/credit_card.rb b/app/models/spree/credit_card.rb index 47fa1b8fca..19fc47bff3 100644 --- a/app/models/spree/credit_card.rb +++ b/app/models/spree/credit_card.rb @@ -63,10 +63,6 @@ module Spree "XXXX-XXXX-XXXX-#{last_digits}" end - def actions - %w{capture_and_complete_order void credit resend_authorization_email} - end - def can_resend_authorization_email?(payment) payment.requires_authorization? end diff --git a/app/models/spree/gateway.rb b/app/models/spree/gateway.rb index 08f6d20e27..1ab4e8808f 100644 --- a/app/models/spree/gateway.rb +++ b/app/models/spree/gateway.rb @@ -13,6 +13,10 @@ module Spree preference :server, :string, default: 'live' preference :test_mode, :boolean, default: false + def actions + %w{capture_and_complete_order void credit resend_authorization_email} + end + def payment_source_class CreditCard end diff --git a/app/models/spree/payment.rb b/app/models/spree/payment.rb index ae224f44d0..ef5c4d67a5 100644 --- a/app/models/spree/payment.rb +++ b/app/models/spree/payment.rb @@ -152,9 +152,9 @@ module Spree end def actions - return [] unless payment_source.respond_to?(:actions) + return [] unless payment_method.respond_to?(:actions) - payment_source.actions.select do |action| + payment_method.actions.select do |action| !payment_source.respond_to?("can_#{action}?") || payment_source.__send__("can_#{action}?", self) end