Skip to content

Instantly share code, notes, and snippets.

@zmachuca
Created February 15, 2015 01:17
Show Gist options
  • Save zmachuca/74298c4053f330444379 to your computer and use it in GitHub Desktop.
Save zmachuca/74298c4053f330444379 to your computer and use it in GitHub Desktop.
def create
@user = User.new(user_params)
if @user.save
begin
Rails.logger.error("STRIPE API KEY: #{Stripe.api_key.inspect}")
@amount = 999
customer = Stripe::Customer.create(
:email => '[email protected]',
:card => params[:stripeToken]
)
@user.stripe_customer_id = customer.id; @user.save
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => @amount,
:description => 'Rails Stripe Customer',
:currency => 'usd'
)
rescue Stripe::StripeError => e
ExampleMailer.Stripe_error_email(@user).deliver
flash[:error] = e.message
redirect_to charges_path
rescue Stripe::APIConnectionError => e
ExampleMailer.API_error_email(@user).deliver
flash[:error] = e.message
redirect_to charges_path
rescue => e
ExampleMailer.NotStripe_error_email(@user).deliver
end
ExampleMailer.purchase_email(@user).deliver
ExampleMailer.sale_email(@user).deliver
else
render action: "new"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment