Skip to content

Instantly share code, notes, and snippets.

@tubbo
Forked from ornerymoose/charge_mailer.rb
Last active August 29, 2015 13:59
Show Gist options
  • Select an option

  • Save tubbo/10782071 to your computer and use it in GitHub Desktop.

Select an option

Save tubbo/10782071 to your computer and use it in GitHub Desktop.
7 class ChargeMailer < ActionMailer::Base
6 default :from => "[email protected]"
5
4 def registration_confirmation(cust)
3 @customer = cust
2 mail(:to => "#{cust.email}", :subject => "Your Order Confirmation")
1 end
0 end
~
class ChargesController < ApplicationController
after_filter :destroy_cart, :only => [:show]
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 => 'Customer',
:currency => 'usd'
)
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to charges_path
end
respond_to do |format|
ChargeMailer.registration_confirmation(@customer).deliver
format.html { redirect_to charge_path(@cart) }
format.json { head :ok }
end
end
def show
@cart = current_cart
@current_cust = @@customer.email
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