Created
December 18, 2011 07:44
-
-
Save starflyer59/1492665 to your computer and use it in GitHub Desktop.
Stripe Code in the SHow Action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CartsController < ApplicationController | |
# GET /carts | |
# GET /carts.xml | |
def index | |
@carts = Cart.all | |
@cart = current_cart | |
respond_to do |format| | |
format.html # index.html.erb | |
format.xml { render :xml => @carts } | |
end | |
end | |
# GET /carts/1 | |
# GET /carts/1.xml | |
def show | |
@cart = Cart.find(params[:id]) | |
puts params[:stripeToken] | |
charge = Stripe::Charge.create( | |
:amount => 100, | |
:currency => "usd", | |
:card => params[:stripeToken], | |
:description => "Charge for test@example.com") | |
respond_to do |format| | |
format.html # show.html.erb | |
format.xml { render :xml => @cart } | |
end | |
end | |
# GET /carts/new | |
# GET /carts/new.xml | |
def new | |
@cart = Cart.new | |
respond_to do |format| | |
format.html # new.html.erb | |
format.xml { render :xml => @cart } | |
end | |
end | |
# GET /carts/1/edit | |
def edit | |
@cart = Cart.find(params[:id]) | |
end | |
# POST /carts | |
# POST /carts.xml | |
def create | |
@cart = Cart.new(params[:cart]) | |
respond_to do |format| | |
if @cart.save | |
format.html { redirect_to(@cart, :notice => 'Cart was successfully created.') } | |
format.xml { render :xml => @cart, :status => :created, :location => @cart } | |
else | |
format.html { render :action => "new" } | |
format.xml { render :xml => @cart.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
# PUT /carts/1 | |
# PUT /carts/1.xml | |
def update | |
@cart = Cart.find(params[:id]) | |
respond_to do |format| | |
if @cart.update_attributes(params[:cart]) | |
format.html { redirect_to(@cart, :notice => 'Cart was successfully updated.') } | |
format.xml { head :ok } | |
else | |
format.html { render :action => "edit" } | |
format.xml { render :xml => @cart.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /carts/1 | |
# DELETE /carts/1.xml | |
def destroy | |
@cart = Cart.find(params[:id]) | |
@cart.destroy | |
respond_to do |format| | |
format.html { redirect_to(carts_url) } | |
format.xml { head :ok } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment