Sha256: 22b118eaf8c206736c39974abb25d647bf0d1dad24a959dfbb24bd1454027584

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module Payments
  class TransactionsController < ApplicationController
    # before_action :redirect_to_balance, only: [:show]
    before_action :find_payment
    prepend_before_action :reset_cache, :set_account

    respond_to :json, only: [:features, :update, :show]

    def show
      @payment_types = PaymentType.visible
      @exchange_rates = TranslationCms::Api::Rates::Currency.all!

      if account_signed_in? && request.format.json?
        @features = TranslationCms::Api::Customers::Feature.get_available(@payment.order.number)
      end

      respond_with @payment, layout: 'cabinet'
    end

    def update
      if params[:features].present?
        @form = Account::FeaturesForm.new(params[:features])
        @form.submit if @form.valid?
      end
      params[:payment_method_id] ||= params[:payment_type_id]
      @payment_form = PaymentForm.new(params)
      @payment_form.submit if @payment_form.valid?

      @payment.payment_method_id = params[:payment_type_id] if params[:payment_type_id].present?

      respond_with @payment, location: payment_provider_redirect_url(@payment)
    end

    private

    def find_payment
      @payment = TranslationCms::Api::Payment.find(params[:id]).first
      raise ActiveRecord::RecordNotFound, "Payment #{params[:id]} not found" if @payment.nil?
    end

    def set_account
      @account = current_account
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_cms-0.1.5 app/controllers/payments/transactions_controller.rb