Created
April 16, 2014 16:23
-
-
Save ornerymoose/10902284 to your computer and use it in GitHub Desktop.
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 ChargesController < ApplicationController | |
after_filter :destroy_cart, :only => [:create] | |
def new | |
@cart = Cart.find(params[:id]) | |
end | |
def create | |
begin | |
@cart = Cart.find(params[:id]) | |
customer = Stripe::Customer.create( | |
:email => params[:stripeEmail], | |
:card => params[:stripeToken] | |
) | |
charge = Stripe::Charge.create( | |
:customer => customer.id, | |
:amount => @cart.total_price * 100, | |
:description => 'California Love Customer', | |
:currency => 'usd' | |
) | |
rescue Stripe::CardError => e | |
flash[:error] = e.message | |
redirect_to charges_path | |
end | |
respond_to do |format| | |
format.html { redirect_to order_path(@cart) } | |
format.json { head :ok } | |
end | |
end | |
private | |
def destroy_cart | |
@cart = current_cart | |
@cart.destroy | |
session[:cart_id] = nil | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment