catarse_stripe 0.1.0 → 0.1.0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store CHANGED
Binary file
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  ## The stripe_controller is a work in progress and things will be changing very rapidly. BEWARE!
2
- ### Tests are non-funtional at this point and will be adjusted to Stripe soon!
2
+ ### Tests are non-functional at this point and will be adjusted to Stripe soon!
3
3
 
4
4
  # CatarseStripe
5
5
 
6
- Catarse Stripe integration with [Catarse](http://github.com/danielweinmann/catarse) crowdfunding platform
6
+ Catarse Stripe integration with [Catarse](http://github.com/danielweinmann/catarse) crowdfunding platform.
7
+
8
+ So far, catarse_stripe uses Omniauth for an auth connection and to use Catarse as a Platform app. See the wiki on how to use Stripe-Connect.
7
9
 
8
10
  ## Installation
9
11
 
@@ -16,6 +18,11 @@ And then execute:
16
18
 
17
19
  $ bundle
18
20
 
21
+ Install the database migrations
22
+
23
+ bundle exec rake catarse_stripe:install:migrations
24
+ bundle exec rake db:migrate
25
+
19
26
  ## Usage
20
27
 
21
28
  Configure the routes for your Catarse application. Add the following lines in the routes file (config/routes.rb):
@@ -35,8 +42,76 @@ In Rails console, run this:
35
42
  Configuration.create!(name: "stripe_api_key", value: "API_KEY")
36
43
  Configuration.create!(name: "stripe_secret_key", value: "SECRET_KEY")
37
44
  Configuration.create!(name: "stripe_test", value: "TRUE/FALSE")
38
-
39
- NOTE: Be sure to add the correct keys from the API section of your Stripe account settings. Stripe_Test: TRUE = Using Stripe Test Server/Sandbox Mode / FALSE = Using Stripe live server.
45
+
46
+ If you've already created your application and been approved at Stripe.com add your Client_id
47
+
48
+ Configuration.create!(name: "stripe_client_id", value: "STRIPE_CLIENT_ID")
49
+
50
+ NOTE: Be sure to add the correct keys from the API section of your Stripe account settings. Stripe_Test: TRUE = Using Stripe Test Server/Sandbox Mode / FALSE = Using Stripe live server.
51
+
52
+ ### Authorization
53
+
54
+ Users who will be creating projects can now create and connect a Stripe.com project payments account. This is the account that will receive funds for each project.
55
+
56
+ Just above the #password field and in the My_Data section, add the following in `app/views/users/_current_user_fields.html.slim`:
57
+
58
+ ...
59
+ #payment_gateways
60
+ h1= t('.payment_gateways')
61
+ ul
62
+ li
63
+ - if @user.stripe_key.blank?
64
+ = link_to( image_tag('auth/stripe_blue.png'), '/payment/stripe/auth')
65
+ - else
66
+ = image_tag 'auth/stripe-solid.png'
67
+ br
68
+ p= t('.stripe_key_info')
69
+ p= @user.stripe_key
70
+ br
71
+ p= t('.stripe_customer_info')
72
+ p= @user.stripe_userid
73
+ ...
74
+
75
+ This will create a button in the User/settings tab to connect to the catarse_stripe auth and get a UserID, Secretkey and PublicKey for the User/Project Owner.
76
+
77
+ You'll then need to copy those keys to the matchin columns in the projects table. You can do this automatically when a created project is loaded by adding this to the bottom of app/controllers/projects_controller.rb:
78
+
79
+ def check_for_stripe_keys
80
+ if @project.stripe_userid.nil?
81
+ [:stripe_access_token, :stripe_key, :stripe_userid].each do |field|
82
+ @project.send("#{field.to_s}=", @project.user.send(field).dup)
83
+ end
84
+ elsif @project.stripe_userid != @project.user.stripe_userid
85
+ [:stripe_access_token, :stripe_key, :stripe_userid].each do |field|
86
+ @project.send("#{field.to_s}=", @project.user.send(field).dup)
87
+ end
88
+ end
89
+ @project.save
90
+ end
91
+
92
+ The insert `check_for_stripe_keys` in the :show method above 'show!' like so:
93
+
94
+ ...
95
+ check_for_stripe_keys
96
+
97
+ show!{
98
+ @title = @project.name
99
+ @rewards = @project.rewards.order(:minimum_value).all
100
+ @backers = @project.backers.confirmed.limit(12).order("confirmed_at DESC").all
101
+ fb_admins_add(@project.user.facebook_id) if @project.user.facebook_id
102
+ @update = @project.updates.where(:id => params[:update_id]).first if params[:update_id].present?
103
+ }
104
+ ...
105
+
106
+ As well as in the :create method after the bitly section like so:
107
+
108
+ ...
109
+ unless @project.new_record?
110
+ @project.reload
111
+ @project.update_attributes({ short_url: bitly })
112
+ end
113
+ check_for_stripe_keys
114
+ ...
40
115
 
41
116
  ## Development environment setup
42
117
 
Binary file
Binary file
@@ -0,0 +1,4 @@
1
+ module CatarseStripe::Payment
2
+ class ApplicationController < ::ApplicationController
3
+ end
4
+ end
@@ -1,6 +1,7 @@
1
1
  require 'catarse_stripe/processors'
2
2
  require 'json'
3
3
  require 'stripe'
4
+ require 'oauth2'
4
5
 
5
6
  module CatarseStripe::Payment
6
7
  class StripeController < ApplicationController
@@ -10,27 +11,45 @@ module CatarseStripe::Payment
10
11
  skip_before_filter :set_locale, :only => [:notifications, :connect]
11
12
  skip_before_filter :force_http
12
13
 
14
+ before_filter :setup_auth_gateway
15
+
13
16
  SCOPE = "projects.backers.checkout"
14
- SCOPE = "users.projects"
17
+ AUTH_SCOPE = "users.auth"
15
18
 
16
19
  layout :false
17
20
 
18
- #TODO add auth code - replace omniauth
19
- def connect
20
- @user = current_user
21
-
21
+ #Makes the call to @client.auth_code.authorize_url from auth.html.erg
22
+ def auth
23
+ @stripe_user = current_user
22
24
  respond_to do |format|
23
25
  format.html
24
26
  format.js
25
27
  end
26
28
  end
27
-
28
- #TODO add auth code - replace omniauth
29
- #def auth
30
- #if @user.stripe_key.present?
31
- #render :text => "You have already connected a Stripe account. Your Stripe Key is #{@user.stripe_key}."
32
- #end
33
- #end
29
+
30
+ #Brings back the authcode from Stripe and makes another call to Stripe to convert to a authtoken
31
+ def callback
32
+ @stripe_user = current_user
33
+ code = params[:code]
34
+
35
+ @response = @client.auth_code.get_token(code, {
36
+ :headers => {'Authorization' => "Bearer(::Configuration['stripe_secret_key'])"} #Platform Secret Key
37
+ })
38
+
39
+ #Save PROJECT owner's new keys
40
+ @stripe_user.stripe_access_token = @response.token
41
+ @stripe_user.stripe_key = @response.params['stripe_publishable_key']
42
+ @stripe_user.stripe_userid = @response.params['stripe_user_id']
43
+ @stripe_user.save
44
+
45
+
46
+ return redirect_to payment_stripe_auth_path(@stripe_user)
47
+ rescue Stripe::AuthenticationError => e
48
+ ::Airbrake.notify({ :error_class => "Stripe #Pay Error", :error_message => "Stripe #Pay Error: #{e.inspect}", :parameters => params}) rescue nil
49
+ Rails.logger.info "-----> #{e.inspect}"
50
+ flash[:error] = e.message
51
+ return redirect_to main_app.user_path(@stripe_user)
52
+ end
34
53
 
35
54
  def review
36
55
 
@@ -66,7 +85,7 @@ module CatarseStripe::Payment
66
85
  ::Airbrake.notify({ :error_class => "Stripe Notification Error", :error_message => "Stripe Notification Error: #{e.inspect}", :parameters => params}) rescue nil
67
86
  render status: 404, nothing: true
68
87
  end
69
-
88
+
70
89
  def charge
71
90
  @backer = current_user.backs.find params[:id]
72
91
  access_token = @backer.project.stripe_access_token #Project Owner SECRET KEY
@@ -95,7 +114,6 @@ module CatarseStripe::Payment
95
114
 
96
115
  response = Stripe::Charge.create(
97
116
  {
98
- #card: token,
99
117
  customer: @backer.payment_token,
100
118
  amount: @backer.price_in_cents,
101
119
  currency: 'usd',
@@ -157,6 +175,16 @@ module CatarseStripe::Payment
157
175
  end
158
176
 
159
177
  private
178
+ #Setup the Oauth2 Stripe call with needed params - See initializers.stripe..rb..the Stripe keys are setup in the seed.db or added manually with a Configuration.create! call.
179
+ def setup_auth_gateway
180
+ session[:oauth] ||= {}
181
+
182
+ @client = OAuth2::Client.new((::Configuration['stripe_client_id']), (::Configuration['stripe_access_token']), {
183
+ :site => 'https://connect.stripe.com',
184
+ :authorize_url => '/oauth/authorize',
185
+ :token_url => '/oauth/token'
186
+ })
187
+ end
160
188
 
161
189
  def build_notification(backer, data)
162
190
  processor = CatarseStripe::Processors::Stripe.new
@@ -171,15 +199,12 @@ module CatarseStripe::Payment
171
199
  flash[:success] = t('success', scope: SCOPE)
172
200
  end
173
201
 
174
- def setup_gateway
175
- if ::Configuration[:stripe_api_key]# and ::Configuration[:stripe_secret_key]
176
- @@gateway ||= ActiveMerchant::Billing::StripeGateway.new({
177
- :login => ::Configuration[:stripe_api_key]
178
- #:login => ::Configuration[:stripe_secret_key]
179
- })
180
- else
181
- puts "[Stripe] API key is required to make requests to Stripe"
182
- end
202
+ def stripe_auth_flash_error
203
+ flash[:failure] = t('stripe_error', scope: AUTH_SCOPE)
204
+ end
205
+
206
+ def stripe_auth_flash_success
207
+ flash[:success] = t('success', scope: AUTH_SCOPE)
183
208
  end
184
209
  end
185
210
  end
@@ -0,0 +1,49 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Stripe Connect</title>
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <!-- Bootstrap -->
7
+ <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css" rel="stylesheet">
8
+ <style>
9
+ body{background-color: #e5e5e5;}
10
+ div.container { position: relative;}
11
+ div.row { position: absolute; margin:30px 50px 50px 50px;}
12
+ div.stripe-field {
13
+ position:absolute;
14
+ left: 0;
15
+ right: 0;
16
+ margin-left: auto;
17
+ margin-right: auto;
18
+ }
19
+ div.stripe-field .stripe-connect-btn { text-align: left;}
20
+ </style>
21
+ </head>
22
+ <body>
23
+ <div class="container">
24
+ <div class="row">
25
+ <div class="span4">
26
+ <div class="stripe-field">
27
+ <h2>Stripe Connect</h2>
28
+ <% if current_user.stripe_access_token %>
29
+ <h4>STRIPE CONNECTED!</h4>
30
+ <p> You are ready to receive payments for your projects!</p>
31
+ <p>Your Stripe user ID: <%= current_user.stripe_userid %></p>
32
+ <% else %>
33
+ <p> In order to use Stripe payments as your payment processor, you'll need to connect and create a Stripe account. You can do that easily through this Crowdfunding platform.</p>
34
+ <p> If you don't have a Stripe account, you'll be prompted to create one</p>
35
+ <p class="stripe-connect-btn">
36
+ <a href="<%= @client.auth_code.authorize_url(:scope => 'read_write', :stripe_landing => 'register') %>">
37
+ <img src="/assets/auth/stripe_blue.png">
38
+ </a>
39
+ </p>
40
+ <% end %>
41
+ <p><%= link_to "Back To User", main_app.user_path(@stripe_user), :class => "btn btn-primary" %></p>
42
+ </stripe-field>
43
+ <script src="http://code.jquery.com/jquery.js"></script>
44
+ <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/js/bootstrap.min.js"></script>
45
+ </div>
46
+ </div>
47
+ </div>
48
+ </body>
49
+ </html>
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency "stripe"
22
22
  s.add_dependency "omniauth-stripe-connect"
23
23
  s.add_dependency "stripe_event"
24
+ s.add_dependency "oauth2"
24
25
  s.add_dependency "figaro"
25
26
 
26
27
  s.add_development_dependency "rspec-rails"
@@ -6,9 +6,9 @@ Rails.configuration.stripe = {
6
6
  :stripe_client_id => (::Configuration['stripe_client_id'])
7
7
  }
8
8
 
9
- #Stripe.api_key = Rails.configuration.stripe[:secret_key]
10
- #STRIPE_PUBLIC_KEY = Rails.configuration.stripe[:publishable_key]
11
- #STRIPE_CLIENT_ID = Rails.configuration.stripe[:stripe_client_id]
9
+ Stripe.api_key = Rails.configuration.stripe[:secret_key]
10
+ STRIPE_PUBLIC_KEY = Rails.configuration.stripe[:publishable_key]
11
+ STRIPE_CLIENT_ID = Rails.configuration.stripe[:stripe_client_id]
12
12
 
13
13
  #Stripe.api_key = ENV['STRIPE_API_KEY'] #PROJECT secret
14
14
  #STRIPE_PUBLIC_KEY = ENV['STRIPE_PUBLIC_KEY'] #PROJECT publishable
@@ -11,4 +11,8 @@ en:
11
11
  stripe_cancel: "Your Stripe payment was canceled. Please try again."
12
12
  stripe_description: "Back project %{project_name} with %{value} (USD)"
13
13
  stripe_error: "Ooops. There was an error while sending your payment to Stripe. Please try again."
14
- success: "Your back was successfully made. Thanks a lot!"
14
+ success: "Your back was successfully made. Thanks a lot!"
15
+ users:
16
+ auth:
17
+ stripe_error: "Ooops. There was an error while authorizing your user to Stripe. Please try again."
18
+ success: "Your Stripe acct is connected. Your are ready to accept payments!"
@@ -2,11 +2,12 @@ CatarseStripe::Engine.routes.draw do
2
2
  namespace :payment do
3
3
  get '/stripe/:id/review' => 'stripe#review', :as => 'review_stripe'
4
4
  post '/stripe/notifications' => 'stripe#ipn', :as => 'ipn_stripe'
5
+ match '/stripe/callback' => 'stripe#callback', :as => 'stripe_auth_callback'
5
6
  match '/stripe/:id/notifications' => 'stripe#notifications', :as => 'notifications_stripe'
6
7
  match '/stripe/:id/pay' => 'stripe#pay', :as => 'pay_stripe'
7
8
  match '/stripe/:id/success' => 'stripe#success', :as => 'success_stripe'
8
9
  match '/stripe/:id/cancel' => 'stripe#cancel', :as => 'cancel_stripe'
9
10
  match '/stripe/:id/charge' => 'stripe#charge', :as => 'charge_stripe'
10
- match '/stripe/connect' => 'stripe#connect', :as => 'connect_stripe'
11
+ match '/stripe/auth' => 'stripe#auth', :as => 'stripe_auth'
11
12
  end
12
13
  end
@@ -1,3 +1,3 @@
1
1
  module CatarseStripe
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.0.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catarse_stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-20 00:00:00.000000000 Z
12
+ date: 2013-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -91,6 +91,22 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: oauth2
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
94
110
  - !ruby/object:Gem::Dependency
95
111
  name: figaro
96
112
  requirement: !ruby/object:Gem::Requirement
@@ -169,15 +185,23 @@ files:
169
185
  - MIT-LICENSE
170
186
  - README.md
171
187
  - Rakefile
188
+ - app/.DS_Store
189
+ - app/assets/.DS_Store
190
+ - app/assets/images/.DS_Store
191
+ - app/assets/images/catarse_stripe/.DS_Store
172
192
  - app/assets/images/catarse_stripe/.gitkeep
193
+ - app/assets/images/catarse_stripe/auth/stripe-outline.png
194
+ - app/assets/images/catarse_stripe/auth/stripe_blue-2x.png
195
+ - app/assets/images/catarse_stripe/auth/stripe_blue.png
173
196
  - app/assets/javascripts/.DS_Store
174
197
  - app/assets/javascripts/catarse_stripe.js
175
198
  - app/assets/javascripts/catarse_stripe/.DS_Store
176
199
  - app/assets/javascripts/catarse_stripe/stripe_form.js
177
200
  - app/assets/javascripts/catarse_stripe/user_document.js
201
+ - app/controllers/catarse_stripe/payment/application_controller.rb
178
202
  - app/controllers/catarse_stripe/payment/stripe_controller.rb
203
+ - app/views/catarse_stripe/payment/stripe/auth.html.erb
179
204
  - app/views/catarse_stripe/payment/stripe/charge.html.erb
180
- - app/views/catarse_stripe/payment/stripe/connect.html.slim
181
205
  - app/views/catarse_stripe/payment/stripe/review.html.slim
182
206
  - catarse_stripe.gemspec
183
207
  - config/initializers/register.rb
@@ -1,29 +0,0 @@
1
- doctype
2
- html
3
- head
4
- title Stripe Payment
5
- meta content="width=(device-width,)initial-scale=1.0" name="viewport"
6
- /! Bootstrap
7
- link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css" rel="stylesheet"
8
- = javascript_include_tag "http://code.jquery.com/jquery.js"
9
- = javascript_include_tag "//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/js/bootstrap.min.js"
10
- css:
11
- | body{background-color: #e5e5e5;}
12
- | div.container { position: relative;}
13
- | div.row { position: absolute; margin:50px;}
14
- | div.stripe-field {
15
- | position:absolute;
16
- | left: 0;
17
- | right: 0;
18
- | margin-left: auto;
19
- | margin-right: auto;
20
- | }
21
- body
22
- .container
23
- .row
24
- .span4
25
- .stripe-field
26
- h2 Stripe Connect
27
- p In order to use Stripe payments as your processor, you'll need to connect and create a Stripe account. You can do that easily through the Crowdfunding platform. NOTE: To be PCI compliant and avoid credit card Aggregation you'll need to have a separate stripe account for each project you create.
28
- br
29
- = link_to(image_tag('/assets/auth/stripe_blue.png'), authorization_path(:stripe_connect))