diff --git a/app/models/spree/payment.rb b/app/models/spree/payment.rb index 5479e56fd4..ae224f44d0 100644 --- a/app/models/spree/payment.rb +++ b/app/models/spree/payment.rb @@ -123,8 +123,8 @@ module Spree # Allows by passing the default scope on Spree::PaymentMethod. It's needed to link payment # to internal payment method. - # Using ->{ unscope(where: :internal) } on the association doesn't work presumably because - # the default scope is not a simple `where`. + # Using ->{ unscoped } on the association doesn't work presumably because the default scope + # is not a simple `where`. def payment_method Spree::PaymentMethod.unscoped { super } end diff --git a/app/models/spree/payment_method.rb b/app/models/spree/payment_method.rb index f8cd301a21..9bfd51f73a 100644 --- a/app/models/spree/payment_method.rb +++ b/app/models/spree/payment_method.rb @@ -11,7 +11,7 @@ module Spree acts_as_paranoid DISPLAY = [:both, :back_end].freeze - INTERNAL = %w{Spree::PaymentMethod::CustomerCredit Spree::PaymentMethod::ApiCustomerCredit}.freeze + INTERNAL = Spree::PaymentMethod::CustomerCredit.to_s default_scope -> { where(deleted_at: nil).where.not(type: INTERNAL) } has_many :credit_cards, class_name: "Spree::CreditCard", dependent: :destroy @@ -54,18 +54,12 @@ module Spree .where(environment: [Rails.env, "", nil]) } - scope :internal, -> { unscoped.where(deleted_at: nil, type: INTERNAL) } - - # These two method are used to get the two internal payment method. They are accessible to all + # These method is used to get the internal payment method. It is accessible to all # enterprise, but the accessibility is managed by the code, as opposed to using the database. def self.customer_credit unscoped.find_by(type: "Spree::PaymentMethod::CustomerCredit", deleted_at: nil) end - def self.api_customer_credit - unscoped.find_by(type: "Spree::PaymentMethod::ApiCustomerCredit", deleted_at: nil) - end - def configured? !stripe? || stripe_configured? end @@ -132,13 +126,13 @@ module Spree end def internal? - type.in?(INTERNAL) + type == INTERNAL end private def distributor_validation - return true if type.in?(INTERNAL) + return true if internal? validates_with DistributorsValidator end diff --git a/app/models/spree/payment_method/api_customer_credit.rb b/app/models/spree/payment_method/api_customer_credit.rb deleted file mode 100644 index 61a02aad26..0000000000 --- a/app/models/spree/payment_method/api_customer_credit.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# This payment method is not intended to be used with payment, it's used with customer account -# transaction to indicate the transaction was created via API. -module Spree - class PaymentMethod - class ApiCustomerCredit < Spree::PaymentMethod - # Name and description are translatable string, to allow instances to customise them - def name - "api_payment_method.name" - end - - def description - "api_payment_method.description" - end - - def payment_source_class - nil - end - - def method_type - "check" # empty view - end - - def source_required? - false - end - end - end -end diff --git a/config/locales/en.yml b/config/locales/en.yml index 89761d6d08..548b85eaf8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -5196,9 +5196,6 @@ en: sentence_for_humans: "Please leave empty" timestamp_error_message: "Please try again after 5 seconds." api_customer_credit: "API credit: %{description}" - api_payment_method: - name: API customer credit - description: Used to credit customer via customer account transactions endpoint credit_payment_method: name: Customer credit description: Allow customer to pay with credit diff --git a/db/migrate/20260129230557_add_api_customer_credit_payment_method.rb b/db/migrate/20260129230557_add_api_customer_credit_payment_method.rb deleted file mode 100644 index 186f5cefbb..0000000000 --- a/db/migrate/20260129230557_add_api_customer_credit_payment_method.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class AddApiCustomerCreditPaymentMethod < ActiveRecord::Migration[7.1] - def up - # Create payment method - execute(<<~SQL.squish - INSERT INTO spree_payment_methods ( type, environment, active, display_on, created_at, updated_at) - VALUES ('Spree::PaymentMethod::ApiCustomerCredit', '#{Rails.env}', true, 'back_end', NOW(), NOW()) - SQL - ) - end - - def down - execute(<<~SQL.squish - DELETE FROM spree_payment_methods WHERE type = 'Spree::PaymentMethod::ApiCustomerCredit' - SQL - ) - end -end diff --git a/spec/factories/payment_method_factory.rb b/spec/factories/payment_method_factory.rb index 0c7de75341..c19881adec 100644 --- a/spec/factories/payment_method_factory.rb +++ b/spec/factories/payment_method_factory.rb @@ -33,8 +33,4 @@ FactoryBot.define do factory :customer_credit_payment_method, class: Spree::PaymentMethod::CustomerCredit do environment { 'test' } end - - factory :api_customer_credit_payment_method, class: Spree::PaymentMethod::ApiCustomerCredit do - environment { 'test' } - end end diff --git a/spec/models/spree/payment_method/api_customer_credit_spec.rb b/spec/models/spree/payment_method/api_customer_credit_spec.rb deleted file mode 100644 index 9a57e17f40..0000000000 --- a/spec/models/spree/payment_method/api_customer_credit_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe Spree::PaymentMethod::ApiCustomerCredit do - subject { build(:api_customer_credit_payment_method) } - - describe "#name" do - it { expect(subject.name).to eq("api_payment_method.name") } - end - - describe "#description" do - it { expect(subject.description).to eq("api_payment_method.description") } - end -end diff --git a/spec/models/spree/payment_method_spec.rb b/spec/models/spree/payment_method_spec.rb index e74707e0a3..881c4aa7da 100644 --- a/spec/models/spree/payment_method_spec.rb +++ b/spec/models/spree/payment_method_spec.rb @@ -80,18 +80,6 @@ RSpec.describe Spree::PaymentMethod do end end - describe "#internal" do - it "returns only internal payment method" do - external = create(:payment_method) - internal1 = create(:customer_credit_payment_method) - internal2 = create(:api_customer_credit_payment_method) - - payment_methods = described_class.internal - expect(payment_methods).to include(internal1, internal2) - expect(payment_methods).not_to include(external) - end - end - describe "#customer_credit" do it "returns the customer credit payment method" do create(:customer_credit_payment_method) @@ -99,13 +87,6 @@ RSpec.describe Spree::PaymentMethod do end end - describe "#api_customer_credit" do - it "returns the api customer credit payment method" do - create(:api_customer_credit_payment_method) - expect(Spree::PaymentMethod.api_customer_credit).to be_a(Spree::PaymentMethod::ApiCustomerCredit) - end - end - describe "#configured?" do context "non-Stripe payment method" do let(:payment_method) { build(:payment_method) }