Sha256: ae0125bdd39c7b87af78b3beeb17715cd17b387fa6d6f118a9b7b763cdcbe4eb

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

module Trade
  class Admin::PaymentOrdersController < Admin::BaseController
    before_action :set_payment
    before_action :set_payment_order, only: [:update, :cancel]
    after_action only: [:create] do
      mark_audits(instance: :@payment, include: [:payment_orders])
    end

    def new
      @payment_order = PaymentOrder.new
      @orders = @payment.pending_orders
    end

    def create
      @payment_order = @payment.payment_orders.build(payment_order_params)

      if @payment_order.confirm!
        render 'create'
      else
        render 'create_fail'
      end
    end

    def update
      @payment_order.assign_attributes payment_order_params

      if @payment_order.confirm!
        render 'update'
      else
        render 'create_fail'
      end
    end

    def cancel
      @payment_order.revert_confirm!
    end

    private
    def set_payment_order
      @payment_order = PaymentOrder.find(params[:id])
    end

    def set_payment
      @payment = Payment.find(params[:payment_id])
    end

    def payment_order_params
      params.fetch(:payment_order, {}).permit(
        :order_id,
        :check_amount
      ).merge(
        state: 'confirmed'
      )
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_trade-0.0.3 app/controllers/trade/admin/payment_orders_controller.rb