Class: Checkout::PaymentController

Inherits:
CheckoutController
  • Object
show all
Defined in:
app/controllers/gemgento/checkout/payment_controller.rb

Instance Method Summary collapse

Instance Method Details

#showObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/gemgento/checkout/payment_controller.rb', line 8

def show
  initialize_payment_variables

  respond_to do |format|
    format.html
    format.json { render json: {
        quote: @quote,
        payment_methods:(@payment_methods || nil),
        saved_credit_cards: @saved_credit_cards,
        totals: @quote.totals
    } }
  end
end

#updateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/gemgento/checkout/payment_controller.rb', line 22

def update
  @quote.push_payment_method = true

  respond_to do |format|
    if @quote.update(quote_params)
      session[:payment_data] = quote_params[:payment_attributes]

      if !@quote.payment.is_redirecting_payment_method?('payment_after')
        format.html { redirect_to checkout_confirm_path }
        format.json { render json: { result: true, order: @quote, totals: @quote.totals } }
      else
        format.html { redirect_to payment_after_redirect_url }
        format.json { render json: { result: true, payment_redirect_url: payment_after_redirect_url } }
      end

    else
      initialize_payment_variables
      format.html { render action: :show }
      format.json { render json: { result: false, errors: @quote.errors }, status: 422 }
    end
  end
end