Sha256: 97fc932a122e04f18dbebd5f2d1411a7ed03adb11985c518499936952932ce24

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

module Spree
  module Api
    module Returnly
      class RefundsController < ApiController
        include ::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,
                                       product_refund_amount: product_refund_amount_param,
                                       shipping_refund_amount: shipping_refund_amount_param
          render json: refunds.proceed!
        end

        private

        def line_items_params
          params.require(:items)
        end

        def product_refund_amount_param
          params.require(:product_refund_amount)
        end

        def shipping_refund_amount_param
          params.require(:shipping_refund_amount)
        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.5.1 app/controllers/spree/api/returnly/refunds_controller.rb
solidus-returnly-0.5.0 app/controllers/spree/api/returnly/refunds_controller.rb
solidus-returnly-0.5.0.rc1 app/controllers/spree/api/returnly/refunds_controller.rb
solidus-returnly-0.5.0.pre app/controllers/spree/api/returnly/refunds_controller.rb