Created
September 7, 2015 15:03
-
-
Save tgoldenberg/410032261ebd783b8b07 to your computer and use it in GitHub Desktop.
charges_controller
This file contains hidden or 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
| 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