mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-11 03:40:20 +00:00
Remove payment method ApiCustomerCredit
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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) }
|
||||
|
||||
Reference in New Issue
Block a user