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