From ec106a8f83ecf02aa234b13c8e5ea02c8579c7d1 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Wed, 4 Mar 2026 13:07:06 +1100 Subject: [PATCH] Add new payment method ApiCustomerCredit It was previously modelled by a "Check" payment method --- .../payment_method/api_customer_credit.rb | 30 +++++++++++++++++++ spec/factories/payment_method_factory.rb | 5 ++++ .../api_customer_credit_spec.rb | 15 ++++++++++ 3 files changed, 50 insertions(+) create mode 100644 app/models/spree/payment_method/api_customer_credit.rb create mode 100644 spec/models/spree/payment_method/api_customer_credit_spec.rb diff --git a/app/models/spree/payment_method/api_customer_credit.rb b/app/models/spree/payment_method/api_customer_credit.rb new file mode 100644 index 0000000000..61a02aad26 --- /dev/null +++ b/app/models/spree/payment_method/api_customer_credit.rb @@ -0,0 +1,30 @@ +# 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/spec/factories/payment_method_factory.rb b/spec/factories/payment_method_factory.rb index 97006a4a98..d51f7971b4 100644 --- a/spec/factories/payment_method_factory.rb +++ b/spec/factories/payment_method_factory.rb @@ -34,4 +34,9 @@ FactoryBot.define do environment { 'test' } internal { true } end + + factory :api_customer_credit_payment_method, class: Spree::PaymentMethod::ApiCustomerCredit do + environment { 'test' } + internal { true } + 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 new file mode 100644 index 0000000000..9a57e17f40 --- /dev/null +++ b/spec/models/spree/payment_method/api_customer_credit_spec.rb @@ -0,0 +1,15 @@ +# 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