module Spree module Api class RefundsController < Spree::Api::BaseController def estimate authorize! :create, Order render json: SolidusReturnly::Calculator.process(order, line_items_params) end def create authorize! :create, Order refunds = SolidusReturnly::Refunds.new order: order, line_items: line_items_params, restock: refund_restock_param, transactions: transactions_params render json: refunds.proceed! end private def line_items_params params.require(:line_items) end def transactions_params params.require(:transactions) end def refund_restock_param params.require(:restock) == 'true' end def order @order ||= Spree::Order.find_by(number: params[:order_id]) end end end end