Skip to content

Commit

Permalink
Merge branch 'master' of github.com:igorgue/openfund
Browse files Browse the repository at this point in the history
Conflicts:
	app/views/layouts/application.html.erb
  • Loading branch information
igorgue committed Oct 14, 2012
2 parents 5a36447 + d4aa967 commit c8ca452
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 39 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -10,6 +10,8 @@ gem 'jquery-rails' # What did you call me, boy!?
gem 'paperclip', '3.3.0' # I can has?
gem 'rails', '3.2.8' # Kinda like django...
gem 'rails_config' # Real talk: https://github.com/railsjedi/rails_config
gem 'curb' # Short & curlies
gem 'json' # Friday the 13th?
gem 'mysql2'

group :production do
Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Expand Up @@ -41,6 +41,8 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.3.3)
curb (0.8.1)
daemons (1.1.9)
devise (2.1.2)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -139,14 +141,16 @@ PLATFORMS
DEPENDENCIES
annotate (= 2.5.0)
coffee-rails (~> 3.2.1)
curb
devise (= 2.1.2)
formtastic-bootstrap
jquery-rails
json
mysql2
paperclip (= 3.3.0)
rails (= 3.2.8)
rails_config
sass-rails (~> 3.2.3)
therubyracer
uglifier (>= 1.0.3)
unicorn
unicorn
30 changes: 28 additions & 2 deletions app/controllers/account_controller.rb
@@ -1,12 +1,38 @@
class AccountController < ApplicationController
before_filter :authenticate_user!
require 'curb'
require 'json'

def index

@code = current_user.stripe_access_token
end

def stripe_connect

post_data = { :code => params[:code], :grant_type => 'authorization_code' }

http = Curl.post("https://connect.stripe.com/oauth/token", post_data) do |http|
http.headers['Authorization'] = "Bearer #{STRIPE_SECRET_API_KEY}"
end
stripe_response = JSON.parse(http.body_str)

if stripe_response.has_key? "error"
@error = stripe_response[:error_description]
render "account/stripe_error"
end

# the presence of this one key indicates success
if stripe_response.has_key? "stripe_publishable_key"
current_user.update_attributes({
:stripe_livemode => stripe_response[:livemode],
:stripe_publishable_key => stripe_response[:stripe_publishable_key],
:stripe_user_id => stripe_response[:stripe_user_id],
:stripe_refresh_token => stripe_response[:refresh_token],
:stripe_access_token => stripe_response[:access_token]
})
@code = current_user.stripe_access_token
else
@code = 'oks'
end
end

end
4 changes: 3 additions & 1 deletion app/models/campaign_level.rb
Expand Up @@ -21,6 +21,8 @@ def price_to_cents
end

def application_fee_cents
(@cost.to_f * APPLICATION_FEE * 100).to_i
application_fee = Selfstarter::Application::APPLICATION_FEE

(@cost.to_f * application_fee * 100).to_i
end
end
4 changes: 3 additions & 1 deletion app/models/order.rb
Expand Up @@ -38,9 +38,11 @@ class Order < ActiveRecord::Base
def charge!
# get the credit card details submitted by the form
# create the charge on Stripe's servers - this will charge the user's card
currency = Selfstarter::Application::CURRENCY

charge = Stripe::Charge.create({
:amount => @campaign_level.price_to_cents, # amount in cents
:currency => CURRENCY,
:currency => currency,
:card => @card_id,
:description => @campaign_level.title,
:application_fee => @campaign_level.application_fee_cents # amount in cents
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Expand Up @@ -31,5 +31,7 @@ class User < ActiveRecord::Base

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
attr_accessible :stripe_livemode, :stripe_publishable_key, :stripe_user_id,
:stripe_refresh_token, :stripe_access_token
has_many :orders
end
1 change: 1 addition & 0 deletions app/views/account/index.html.erb
@@ -0,0 +1 @@
Code: <%= @code %> [index]
1 change: 1 addition & 0 deletions app/views/account/stripe_connect.html.erb
@@ -0,0 +1 @@
Code: <%= @code %>
1 change: 1 addition & 0 deletions app/views/account/stripe_error.html.erb
@@ -0,0 +1 @@
<%= @error %>
34 changes: 0 additions & 34 deletions app/views/campaigns/_header.html.erb

This file was deleted.

4 changes: 4 additions & 0 deletions config/environment.rb
Expand Up @@ -3,3 +3,7 @@

# Initialize the rails application
Selfstarter::Application.initialize!

# Stripe stuffies
STRIPE_CLIENT_ID = 'ca_0XkgAi8RhMInruJ8ctSuyFIp3myXfG6U'
STRIPE_SECRET_API_KEY = 'sk_test_Ew1OBL4sHHRwezQAvlceXrDW'

0 comments on commit c8ca452

Please sign in to comment.