Skip to content

Instantly share code, notes, and snippets.

@tgoldenberg
Created September 7, 2015 15:03
Show Gist options
  • Select an option

  • Save tgoldenberg/410032261ebd783b8b07 to your computer and use it in GitHub Desktop.

Select an option

Save tgoldenberg/410032261ebd783b8b07 to your computer and use it in GitHub Desktop.
charges_controller
class ChargesController < ApplicationController
def new
end
def complete
@charge = Charge.find(params[:charge_id])
@puppy = Puppy.find_by(user_id: @charge.user_id,
arrived: false, name: @charge.item)
Stripe.api_key = ENV["stripe_api_key"]
token = params[:token]
charge = Stripe::Charge.create({
:amount => @charge.price*100,
:description => 'Rails Stripe customer',
:customer => params[:customer_id],
:currency => 'usd',
:destination => @charge.vendor.uid,
:application_fee => 200+(@charge.price*3)+ 31
},
)
@charge.update_attribute(:completed, true)
@puppy.update_attribute(:arrived, true)
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to charges_path
end
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment