Files
openfoodnetwork/app/controllers/api/v1/customer_account_transaction_controller.rb
Gaetan Craig-Riou be7be9bbc6 Add api endpoing to create customer transactions
Plus specs and documentation
2026-03-10 16:07:41 +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: }
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.internal.find_by(
name: Rails.application.config.api_payment_method[:name]
)&.id
end
end
end
end