Class: TbCheckout::TransactionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/tb_checkout/transactions_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/tb_checkout/transactions_controller.rb', line 26

def create
  @transaction = @cart.transactions.new(transaction_params)
  @transaction.session_id = session.id
  if @transaction.save() && @transaction.capture!
    flash[:notice] = 'Thanks! Your payment was collected successfully'
    redirect_to tb_checkout_transaction_path(@transaction)
  else
    if @transaction.response
      flash.now[:error] = @transaction.response.message
    end
    if @transaction.status == TbCheckout::Transaction::Status::FAIL
      @transaction = TbCheckout::Transaction.new(transaction_params)
    end
    render 'new'
  end
end

#indexObject



5
6
7
8
9
10
11
12
13
# File 'app/controllers/tb_checkout/transactions_controller.rb', line 5

def index
  @transactions = TbCheckout::Transaction.captured.includes(:cart => :cart_items).paginate(:page => params[:page], :per_page => 10)
  if current_user
    @transactions = @transactions.for_user(current_user)
  else
    @transactions = @transactions.for_session(session.id)
  end
  respond_with @transactions
end

#newObject



15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/tb_checkout/transactions_controller.rb', line 15

def new
  @transaction = @cart.transactions.new()
  if !Rails.env.production?
    # These values will work against the Authorize.Net sandbox environment
    @transaction.card_type = 'visa'
    @transaction.card_number = 4007000000027
    @transaction.card_ccv = 123
    @transaction.card_expiration = Date.today.next_year
  end
end

#showObject



43
44
45
46
47
48
49
50
51
# File 'app/controllers/tb_checkout/transactions_controller.rb', line 43

def show
  @transaction = TbCheckout::Transaction.captured.find_by(:id => params[:id])
  if @transaction.present? && @transaction.belongs_to?(user_id:current_user_id, session_id:session.id)
    render 'show'
  else
    flash[:error] = 'The transaction you were looking for could not be found'
    redirect_to tb_checkout_cart_path
  end
end