Sha256: ed6bcf15de8f58a62eea90da4a0f8924f3806bcddcd38cb8f96936b50749fddb

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

module Spree
  module Api
    module Returnly
      class RefundsController < ApiController
        include Solidus::Returnly::RefundsConfiguration

        def estimate
          authorize! :create, Order
          render json: refund_calculator_class.process(order, line_items_params)
        end

        def create
          authorize! :create, Order

          refunds = refunder_class.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)
        end

        def order
          @order ||= Spree::Order.find_by!(number: params[:order_id])
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
solidus-returnly-0.4.3 app/controllers/spree/api/returnly/refunds_controller.rb
solidus-returnly-0.4.2 app/controllers/spree/api/returnly/refunds_controller.rb
solidus-returnly-0.4.1 app/controllers/spree/api/returnly/refunds_controller.rb
solidus-returnly-0.4.0 app/controllers/spree/api/returnly/refunds_controller.rb