Files
openfoodnetwork/app/controllers/api/v1/customer_account_transaction_controller.rb
Gaetan Craig-Riou a4ca56c7a5 Refactored internal payment method
We now check on known payment method type, instead of using the internal
collumn.
2026-03-10 16:07:43 +11:00

37 lines
1.0 KiB
Ruby

# frozen_string_literal: true
module Api
module V1
class CustomerAccountTransactionController < Api::V1::BaseController
def create
authorize! :create, CustomerAccountTransaction
# We only allow using the api customer credit payment method
default_params = {
currency: CurrentConfig.get(:currency), payment_method_id:, created_by: current_api_user
}
transaction = CustomerAccountTransaction.new(
default_params.merge(customer_account_transaction_params)
)
if transaction.save
render json: Api::V1::CustomerAccountTransactionSerializer.new(transaction),
status: :created
else
invalid_resource! transaction
end
end
private
def customer_account_transaction_params
params.require(:customer_account_transaction).permit(:customer_id, :amount, :description)
end
def payment_method_id
Spree::PaymentMethod.api_customer_credit&.id
end
end
end
end