Skip to content

Instantly share code, notes, and snippets.

@zmachuca
Last active August 29, 2015 14:15
Show Gist options
  • Save zmachuca/a8756aa060ad044ceddb to your computer and use it in GitHub Desktop.
Save zmachuca/a8756aa060ad044ceddb to your computer and use it in GitHub Desktop.
def create
@user = User.new(user_params)
if @user.save
ExampleMailer.purchase_email(@user).deliver
ExampleMailer.sale_email(@user).deliver
redirect_to root_path, notice: "Your Purchase Was Successful! You should recieve an email shortly."
else
render action: "new"
end
begin
@amount = 999
customer = Stripe::Customer.create(
:email => 'example@stripe.com',
:card => params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => @amount,
:description => 'Rails Stripe Customer',
:currency => 'usd'
)
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to root_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment