-
-
Save rfunduk/37980da54712ba7944a7 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
def create | |
@user = User.new(user_params) | |
if @user.save | |
ExampleMailer.purchase_email(@user).deliver | |
ExampleMailer.sale_email(@user).deliver | |
begin | |
Rails.logger.error("STRIPE API KEY: #{Stripe.api_key.inspect}") | |
@amount = 999 | |
customer = Stripe::Customer.create( | |
:email => '[email protected]', | |
:card => params[:stripeToken] | |
) | |
charge = Stripe::Charge.create( | |
:customer => customer.id, | |
:amount => @amount, | |
:description => 'Rails Stripe Customer', | |
:currency => 'usd' | |
) | |
redirect_to root_path, notice: "Your Purchase Was Successful! You should recieve an email shortly." | |
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 | |
else | |
render action: "new" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment