catarse_stripe 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/README.md +7 -3
- data/app/controllers/catarse_stripe/payment/stripe_controller.rb +91 -47
- data/app/views/catarse_stripe/payment/stripe/charge.html.erb +38 -0
- data/app/views/catarse_stripe/payment/stripe/connect.html.slim +29 -0
- data/app/views/catarse_stripe/payment/stripe/review.html.slim +9 -3
- data/catarse_stripe.gemspec +4 -0
- data/config/initializers/stripe.rb +15 -0
- data/config/locales/en.yml +1 -1
- data/config/routes.rb +2 -0
- data/db/migrate/20130217194840_add_stripe_key_to_users.rb +5 -0
- data/db/migrate/20130218164300_add_stripe_id_to_users.rb +5 -0
- data/db/migrate/20130218184756_add_stripe_access_token_to_users.rb +5 -0
- data/db/migrate/20130219201753_add_stripe_userid_and_stripe_access_token_to_projects.rb +6 -0
- data/db/migrate/20130220030158_add_stripe_key_to_projects.rb +5 -0
- data/lib/catarse_stripe/engine.rb +6 -0
- data/lib/catarse_stripe/version.rb +1 -1
- data/public/.DS_Store +0 -0
- data/spec/controllers/catarse_paypal_express/payment/{paypal_express_controller_spec.rb → stripe_controller_spec.rb} +34 -33
- data/spec/lib/processors/{paypal_spec.rb → stripe_spec.rb} +6 -6
- data/spec/spec_helper.rb +3 -3
- metadata +80 -10
- data/catarse_stripe-0.0.2.gem +0 -0
- data/catarse_stripe-0.0.3.gem +0 -0
- data/catarse_stripe-0.0.4.gem +0 -0
- data/config/initializers/active_merchant.rb +0 -2
data/.DS_Store
ADDED
Binary file
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
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
3
|
|
3
4
|
# CatarseStripe
|
4
5
|
|
@@ -6,9 +7,10 @@ Catarse Stripe integration with [Catarse](http://github.com/danielweinmann/catar
|
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
9
|
-
Add this lines to your Catarse application's Gemfile:
|
10
|
+
Add this lines to your Catarse application's Gemfile under the payments section:
|
10
11
|
|
11
|
-
gem 'catarse_stripe'
|
12
|
+
gem 'catarse_stripe', :git => 'git://github.com/lvxn0va/catarse_stripe.git'
|
13
|
+
gem 'stripe', :git => 'https://github.com/stripe/stripe-ruby'
|
12
14
|
|
13
15
|
And then execute:
|
14
16
|
|
@@ -20,7 +22,9 @@ Configure the routes for your Catarse application. Add the following lines in th
|
|
20
22
|
|
21
23
|
mount CatarseStripe::Engine => "/", :as => "catarse_stripe"
|
22
24
|
|
23
|
-
### Configurations
|
25
|
+
### Configurations
|
26
|
+
|
27
|
+
Signup for an account at [STRIPE PAYMENTS](http://www.stripe.com) - Go into your account settings and get your API Keys - Be sure to use your 'Test' keys until you're ready to go live. Alos make sure the live/test toggle in the Dashboard is appropriately set.
|
24
28
|
|
25
29
|
Create this configurations into Catarse database:
|
26
30
|
|
@@ -1,107 +1,151 @@
|
|
1
1
|
require 'catarse_stripe/processors'
|
2
|
+
require 'json'
|
3
|
+
require 'stripe'
|
2
4
|
|
3
5
|
module CatarseStripe::Payment
|
4
6
|
class StripeController < ApplicationController
|
5
|
-
|
7
|
+
|
6
8
|
skip_before_filter :verify_authenticity_token, :only => [:notifications]
|
7
|
-
skip_before_filter :detect_locale, :only => [:notifications]
|
8
|
-
skip_before_filter :set_locale, :only => [:notifications]
|
9
|
+
skip_before_filter :detect_locale, :only => [:notifications, :connect]
|
10
|
+
skip_before_filter :set_locale, :only => [:notifications, :connect]
|
9
11
|
skip_before_filter :force_http
|
10
12
|
|
11
|
-
before_filter :setup_gateway
|
12
|
-
|
13
13
|
SCOPE = "projects.backers.checkout"
|
14
|
+
SCOPE = "users.projects"
|
14
15
|
|
15
16
|
layout :false
|
16
17
|
|
17
|
-
|
18
|
+
#TODO add auth code - replace omniauth
|
19
|
+
def connect
|
20
|
+
@user = current_user
|
18
21
|
|
22
|
+
respond_to do |format|
|
23
|
+
format.html
|
24
|
+
format.js
|
25
|
+
end
|
26
|
+
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
|
34
|
+
|
35
|
+
def review
|
36
|
+
|
19
37
|
end
|
20
38
|
|
21
39
|
def ipn
|
22
|
-
backer = Backer.where(:payment_id =>
|
40
|
+
backer = Backer.where(:payment_id => details.id).first
|
23
41
|
if backer
|
24
42
|
notification = backer.payment_notifications.new({
|
25
43
|
extra_data: JSON.parse(params.to_json.force_encoding(params['charset']).encode('utf-8'))
|
26
44
|
})
|
27
45
|
notification.save!
|
28
|
-
backer.
|
29
|
-
:payment_service_fee => params['mc_fee'],
|
30
|
-
:payer_email => params['payer_email']
|
31
|
-
})
|
46
|
+
backer.update_attribute :payment_service_fee => details.fee
|
32
47
|
end
|
33
48
|
return render status: 200, nothing: true
|
34
|
-
rescue
|
49
|
+
rescue Stripe::CardError => e
|
35
50
|
::Airbrake.notify({ :error_class => "Stripe Notification Error", :error_message => "Stripe Notification Error: #{e.inspect}", :parameters => params}) rescue nil
|
36
51
|
return render status: 200, nothing: true
|
37
52
|
end
|
38
53
|
|
39
54
|
def notifications
|
40
55
|
backer = Backer.find params[:id]
|
41
|
-
|
42
|
-
|
43
|
-
|
56
|
+
details = Stripe::Charge.retrieve(
|
57
|
+
id: backer.payment_id
|
58
|
+
)
|
59
|
+
if details.paid = true
|
60
|
+
build_notification(backer, details)
|
44
61
|
render status: 200, nothing: true
|
45
62
|
else
|
46
63
|
render status: 404, nothing: true
|
47
64
|
end
|
48
|
-
rescue
|
65
|
+
rescue Stripe::CardError => e
|
49
66
|
::Airbrake.notify({ :error_class => "Stripe Notification Error", :error_message => "Stripe Notification Error: #{e.inspect}", :parameters => params}) rescue nil
|
50
67
|
render status: 404, nothing: true
|
51
68
|
end
|
52
69
|
|
70
|
+
def charge
|
71
|
+
@backer = current_user.backs.find params[:id]
|
72
|
+
access_token = @backer.project.stripe_access_token #Project Owner SECRET KEY
|
73
|
+
|
74
|
+
respond_to do |format|
|
75
|
+
format.html
|
76
|
+
format.js
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
53
80
|
def pay
|
54
|
-
backer = current_user.backs.find params[:id]
|
81
|
+
@backer = current_user.backs.find params[:id]
|
82
|
+
access_token = @backer.project.stripe_access_token #Project Owner SECRET KEY
|
55
83
|
begin
|
56
84
|
customer = Stripe::Customer.create(
|
57
|
-
|
58
|
-
|
85
|
+
{
|
86
|
+
email: @backer.payer_email,
|
87
|
+
card: params[:stripeToken]
|
88
|
+
},
|
89
|
+
access_token
|
59
90
|
)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
91
|
+
|
92
|
+
@backer.update_attributes(:payment_token => customer.id)
|
93
|
+
@backer.save
|
94
|
+
flash[:notice] = "Stripe Customer ID Saved!"
|
95
|
+
|
96
|
+
response = Stripe::Charge.create(
|
97
|
+
{
|
98
|
+
#card: token,
|
99
|
+
customer: @backer.payment_token,
|
100
|
+
amount: @backer.price_in_cents,
|
64
101
|
currency: 'usd',
|
65
|
-
description: t('stripe_description', scope: SCOPE, :project_name => backer.project.name, :value => backer.display_value)
|
102
|
+
description: t('stripe_description', scope: SCOPE, :project_name => @backer.project.name, :value => @backer.display_value),
|
103
|
+
application_fee: @backer.platform_fee.to_i
|
104
|
+
},
|
105
|
+
access_token #ACCESS_TOKEN (Stripe Secret Key of Connected Project Owner NOT platform)
|
66
106
|
)
|
67
107
|
|
68
|
-
backer.
|
69
|
-
|
70
|
-
|
71
|
-
|
108
|
+
@backer.update_attributes({
|
109
|
+
:payment_method => 'Stripe',
|
110
|
+
:payment_token => response.customer, #Stripe Backer Customer_id
|
111
|
+
:payment_id => response.id, #Stripe Backer Payment Id
|
112
|
+
:confirmed => response.paid #Paid = True, Confirmed = true
|
113
|
+
})
|
114
|
+
@backer.save
|
72
115
|
|
73
|
-
|
74
|
-
|
75
|
-
|
116
|
+
build_notification(@backer, response)
|
117
|
+
|
118
|
+
redirect_to payment_success_stripe_url(id: @backer.id)
|
119
|
+
rescue Stripe::CardError => e
|
120
|
+
::Airbrake.notify({ :error_class => "Stripe #Pay Error", :error_message => "Stripe #Pay Error: #{e.inspect}", :parameters => params}) rescue nil
|
76
121
|
Rails.logger.info "-----> #{e.inspect}"
|
77
|
-
|
78
|
-
return redirect_to main_app.new_project_backer_path(backer.project)
|
122
|
+
flash[:error] = e.message
|
123
|
+
return redirect_to main_app.new_project_backer_path(@backer.project)
|
79
124
|
end
|
80
125
|
end
|
81
126
|
|
82
127
|
def success
|
83
128
|
backer = current_user.backs.find params[:id]
|
129
|
+
access_token = backer.project.stripe_access_token #Project Owner SECRET KEY
|
84
130
|
begin
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
# we must get the deatils after the purchase in order to get the transaction_id
|
92
|
-
details = @@gateway.details_for(backer.payment_token)
|
131
|
+
details = Stripe::Charge.retrieve(
|
132
|
+
{
|
133
|
+
id: backer.payment_id
|
134
|
+
},
|
135
|
+
access_token
|
136
|
+
)
|
93
137
|
|
94
|
-
build_notification(backer, details
|
138
|
+
build_notification(backer, details)
|
95
139
|
|
96
|
-
if details.
|
97
|
-
backer.update_attribute :payment_id, details.
|
140
|
+
if details.id
|
141
|
+
backer.update_attribute :payment_id, details.id
|
98
142
|
end
|
99
|
-
|
143
|
+
stripe_flash_success
|
100
144
|
redirect_to main_app.thank_you_project_backer_path(project_id: backer.project.id, id: backer.id)
|
101
|
-
rescue
|
145
|
+
rescue Stripe::CardError => e
|
102
146
|
::Airbrake.notify({ :error_class => "Stripe Error", :error_message => "Stripe Error: #{e.message}", :parameters => params}) rescue nil
|
103
147
|
Rails.logger.info "-----> #{e.inspect}"
|
104
|
-
|
148
|
+
flash[:error] = e.message
|
105
149
|
return redirect_to main_app.new_project_backer_path(backer.project)
|
106
150
|
end
|
107
151
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Stripe Payment</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
|
+
</style>
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<div class="container">
|
23
|
+
<div class="row">
|
24
|
+
<div class="span4">
|
25
|
+
<div class="stripe-field">
|
26
|
+
<h2>Crowdfunding Payments with Stripe</h2>
|
27
|
+
<p>You've chosen to contribute using a credit card. Stripe payments for customers in US and Canada allow you to use your Visa, Mastercard or Amex. Credit Card information is not stored on the crowdfunding website, and is safely stored on Stripe's servers. For more info visit <a href="http://stripe.com"><b>STRIPE PAYMENTS</b></a></p>
|
28
|
+
<%= form_tag payment_pay_stripe_path(params[:id]) do %>
|
29
|
+
<script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button" data-key="<%= @backer.project.stripe_key %>" data-label="Contribute With Stripe"></script>
|
30
|
+
<% end %>
|
31
|
+
</stripe-field>
|
32
|
+
<script src="http://code.jquery.com/jquery.js"></script>
|
33
|
+
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/js/bootstrap.min.js"></script>
|
34
|
+
</div>
|
35
|
+
</div>
|
36
|
+
</div>
|
37
|
+
</body>
|
38
|
+
</html>
|
@@ -0,0 +1,29 @@
|
|
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))
|
@@ -3,7 +3,13 @@
|
|
3
3
|
h3= t('projects.backers.review.international.section_title')
|
4
4
|
|
5
5
|
#catarse_stripe_form
|
6
|
-
= form_tag
|
6
|
+
= form_tag payment_charge_stripe_path(params[:id]) do
|
7
7
|
.clearfix
|
8
|
-
|
9
|
-
|
8
|
+
.bootstrap-twitter
|
9
|
+
= submit_tag t('projects.backers.review.international.button'), :class => 'btn btn-primary btn-large'
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
data/catarse_stripe.gemspec
CHANGED
@@ -18,6 +18,10 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.add_dependency "rails", "~> 3.2.11"
|
20
20
|
s.add_dependency "activemerchant", ">= 1.17.0"
|
21
|
+
s.add_dependency "stripe"
|
22
|
+
s.add_dependency "omniauth-stripe-connect"
|
23
|
+
s.add_dependency "stripe_event"
|
24
|
+
s.add_dependency "figaro"
|
21
25
|
|
22
26
|
s.add_development_dependency "rspec-rails"
|
23
27
|
s.add_development_dependency "factory_girl_rails"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#Main Platform Stripe Keys - Enter manually according to catarse_stripe README or add to seeds.db -
|
2
|
+
#As it stands, because of Stripe Connect, the only key being referred to here is the Main Platform App key 'stripe_client_id' in Omniauth.rb
|
3
|
+
Rails.configuration.stripe = {
|
4
|
+
:publishable_key => (::Configuration['stripe_api_key']),
|
5
|
+
:secret_key => (::Configuration['stripe_secret_key']),
|
6
|
+
:stripe_client_id => (::Configuration['stripe_client_id'])
|
7
|
+
}
|
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]
|
12
|
+
|
13
|
+
#Stripe.api_key = ENV['STRIPE_API_KEY'] #PROJECT secret
|
14
|
+
#STRIPE_PUBLIC_KEY = ENV['STRIPE_PUBLIC_KEY'] #PROJECT publishable
|
15
|
+
#STRIPE_CLIENT_ID = ENV['STRIPE_CLIENT_ID'] #Platform owner app key
|
data/config/locales/en.yml
CHANGED
@@ -4,7 +4,7 @@ en:
|
|
4
4
|
review:
|
5
5
|
stripe: 'Stripe'
|
6
6
|
international:
|
7
|
-
section_title: 'You will be directed to the
|
7
|
+
section_title: 'You will be directed to the payment processor site to complete payment.'
|
8
8
|
user_document_label: 'CPF / CNPJ (only for Brazilians)'
|
9
9
|
button: 'Redirect to Payment By Stripe'
|
10
10
|
checkout:
|
data/config/routes.rb
CHANGED
@@ -6,5 +6,7 @@ CatarseStripe::Engine.routes.draw do
|
|
6
6
|
match '/stripe/:id/pay' => 'stripe#pay', :as => 'pay_stripe'
|
7
7
|
match '/stripe/:id/success' => 'stripe#success', :as => 'success_stripe'
|
8
8
|
match '/stripe/:id/cancel' => 'stripe#cancel', :as => 'cancel_stripe'
|
9
|
+
match '/stripe/:id/charge' => 'stripe#charge', :as => 'charge_stripe'
|
10
|
+
match '/stripe/connect' => 'stripe#connect', :as => 'connect_stripe'
|
9
11
|
end
|
10
12
|
end
|
data/public/.DS_Store
ADDED
Binary file
|
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
|
5
|
+
#TODO
|
6
|
+
describe CatarseStripe::Payment::StripeController do
|
6
7
|
before do
|
7
|
-
Configuration.create!(name: "paypal_username", value: "usertest_api1.teste.com")
|
8
|
-
Configuration.create!(name: "paypal_password", value: "HVN4PQBGZMHKFVGW")
|
9
|
-
Configuration.create!(name: "paypal_signature", value: "AeL-u-Ox.N6Jennvu1G3BcdiTJxQAWdQcjdpLTB9ZaP0-Xuf-U0EQtnS")
|
10
|
-
ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:details_for).and_return({})
|
8
|
+
#Configuration.create!(name: "paypal_username", value: "usertest_api1.teste.com")
|
9
|
+
#Configuration.create!(name: "paypal_password", value: "HVN4PQBGZMHKFVGW")
|
10
|
+
#Configuration.create!(name: "paypal_signature", value: "AeL-u-Ox.N6Jennvu1G3BcdiTJxQAWdQcjdpLTB9ZaP0-Xuf-U0EQtnS")
|
11
|
+
#ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:details_for).and_return({})
|
11
12
|
Airbrake.stub(:notify).and_return({})
|
12
13
|
end
|
13
14
|
|
@@ -20,7 +21,7 @@ describe CatarsePaypalExpress::Payment::PaypalExpressController do
|
|
20
21
|
let(:backer){ Factory(:backer, :payment_id => ipn_data['txn_id'] ) }
|
21
22
|
before do
|
22
23
|
backer
|
23
|
-
post :ipn, ipn_data.merge({ use_route: '
|
24
|
+
post :ipn, ipn_data.merge({ use_route: 'catarse_stripe' })
|
24
25
|
backer.reload
|
25
26
|
end
|
26
27
|
|
@@ -42,13 +43,13 @@ describe CatarsePaypalExpress::Payment::PaypalExpressController do
|
|
42
43
|
describe "POST notification" do
|
43
44
|
context 'when receive a notification' do
|
44
45
|
it 'and not found the backer, should return 404' do
|
45
|
-
post :notifications, { id: 1, use_route: '
|
46
|
+
post :notifications, { id: 1, use_route: 'catarse_stripe'}
|
46
47
|
response.status.should eq(404)
|
47
48
|
end
|
48
49
|
|
49
50
|
it 'and the transaction ID not match, should return 404' do
|
50
51
|
backer = Factory(:backer, payment_id: '1234')
|
51
|
-
post :notifications, { id: backer.id, txn_id: 123, use_route: '
|
52
|
+
post :notifications, { id: backer.id, txn_id: 123, use_route: 'catarse_stripe' }
|
52
53
|
response.status.should eq(404)
|
53
54
|
end
|
54
55
|
|
@@ -56,12 +57,12 @@ describe CatarsePaypalExpress::Payment::PaypalExpressController do
|
|
56
57
|
success_payment_response = mock()
|
57
58
|
success_payment_response.stubs(:params).returns({ 'transaction_id' => '1234', "checkout_status" => "PaymentActionCompleted" })
|
58
59
|
success_payment_response.stubs(:success?).returns(true)
|
59
|
-
ActiveMerchant::Billing::
|
60
|
+
ActiveMerchant::Billing::StripeGateway.any_instance.stub(:details_for).and_return(success_payment_response)
|
60
61
|
|
61
62
|
backer = Factory(:backer, payment_id: '1234')
|
62
63
|
backer.payment_notifications.should be_empty
|
63
64
|
|
64
|
-
post :notifications, { id: backer.id, txn_id: 1234 , use_route: '
|
65
|
+
post :notifications, { id: backer.id, txn_id: 1234 , use_route: 'catarse_stripe' }
|
65
66
|
backer.reload
|
66
67
|
|
67
68
|
backer.payment_notifications.should_not be_empty
|
@@ -71,10 +72,10 @@ describe CatarsePaypalExpress::Payment::PaypalExpressController do
|
|
71
72
|
success_payment_response = mock()
|
72
73
|
success_payment_response.stubs(:params).returns({ 'transaction_id' => '1234', "checkout_status" => "PaymentActionCompleted" })
|
73
74
|
success_payment_response.stubs(:success?).returns(true)
|
74
|
-
ActiveMerchant::Billing::
|
75
|
+
ActiveMerchant::Billing::StripeGateway.any_instance.stub(:details_for).and_return(success_payment_response)
|
75
76
|
backer = Factory(:backer, payment_id: '1234', confirmed: false)
|
76
77
|
|
77
|
-
post :notifications, { id: backer.id, txn_id: 1234, use_route: '
|
78
|
+
post :notifications, { id: backer.id, txn_id: 1234, use_route: 'catarse_stripe' }
|
78
79
|
|
79
80
|
backer.reload
|
80
81
|
response.status.should eq(200)
|
@@ -88,7 +89,7 @@ describe CatarsePaypalExpress::Payment::PaypalExpressController do
|
|
88
89
|
context 'when have some failures' do
|
89
90
|
it 'user not logged in, should redirect' do
|
90
91
|
pending 'problems with external application routes'
|
91
|
-
#get :pay, {locale: 'en', use_route: '
|
92
|
+
#get :pay, {locale: 'en', use_route: 'catarse_stripe' }
|
92
93
|
#response.status.should eq(302)
|
93
94
|
end
|
94
95
|
|
@@ -97,17 +98,17 @@ describe CatarsePaypalExpress::Payment::PaypalExpressController do
|
|
97
98
|
session[:user_id] = current_user.id
|
98
99
|
|
99
100
|
lambda {
|
100
|
-
get :pay, { id: backer.id, locale: 'en', use_route: '
|
101
|
+
get :pay, { id: backer.id, locale: 'en', use_route: 'catarse_stripe' }
|
101
102
|
}.should raise_exception ActiveRecord::RecordNotFound
|
102
103
|
end
|
103
104
|
|
104
105
|
it 'raise a exepction because invalid data and should be redirect and set the flash message' do
|
105
|
-
ActiveMerchant::Billing::
|
106
|
+
ActiveMerchant::Billing::StripeGateway.any_instance.stub(:setup_purchase).and_raise(StandardError)
|
106
107
|
session[:user_id] = current_user.id
|
107
108
|
backer = Factory(:backer, user: current_user)
|
108
109
|
|
109
|
-
get :pay, { id: backer.id, locale: 'en', use_route: '
|
110
|
-
flash[:failure].should == I18n.t('
|
110
|
+
get :pay, { id: backer.id, locale: 'en', use_route: 'catarse_stripe' }
|
111
|
+
flash[:failure].should == I18n.t('stripe_error', scope: CatarseStripe::Payment::StripeController::SCOPE)
|
111
112
|
response.should be_redirect
|
112
113
|
end
|
113
114
|
end
|
@@ -117,14 +118,14 @@ describe CatarsePaypalExpress::Payment::PaypalExpressController do
|
|
117
118
|
success_response = mock()
|
118
119
|
success_response.stub(:token).and_return('ABCD')
|
119
120
|
success_response.stub(:params).and_return({ 'correlation_id' => '123' })
|
120
|
-
ActiveMerchant::Billing::
|
121
|
+
ActiveMerchant::Billing::StripeGateway.any_instance.stub(:setup_purchase).and_return(success_response)
|
121
122
|
end
|
122
123
|
|
123
124
|
it 'should create a payment_notification' do
|
124
125
|
session[:user_id] = current_user.id
|
125
126
|
backer = Factory(:backer, user: current_user)
|
126
127
|
|
127
|
-
get :pay, { id: backer.id, locale: 'en', use_route: '
|
128
|
+
get :pay, { id: backer.id, locale: 'en', use_route: 'catarse_stripe' }
|
128
129
|
backer.reload
|
129
130
|
|
130
131
|
backer.payment_notifications.should_not be_empty
|
@@ -134,10 +135,10 @@ describe CatarsePaypalExpress::Payment::PaypalExpressController do
|
|
134
135
|
session[:user_id] = current_user.id
|
135
136
|
backer = Factory(:backer, user: current_user)
|
136
137
|
|
137
|
-
get :pay, { id: backer.id, locale: 'en', use_route: '
|
138
|
+
get :pay, { id: backer.id, locale: 'en', use_route: 'catarse_stripe' }
|
138
139
|
backer.reload
|
139
140
|
|
140
|
-
backer.payment_method.should == '
|
141
|
+
backer.payment_method.should == 'Stripe'
|
141
142
|
backer.payment_token.should == 'ABCD'
|
142
143
|
|
143
144
|
# The correlation id should not be stored in payment_id, which is only for transaction_id
|
@@ -150,13 +151,13 @@ describe CatarsePaypalExpress::Payment::PaypalExpressController do
|
|
150
151
|
end
|
151
152
|
|
152
153
|
describe "GET cancel" do
|
153
|
-
context 'when cancel the
|
154
|
+
context 'when cancel the stripe purchase' do
|
154
155
|
it 'should show for user the flash message' do
|
155
156
|
session[:user_id] = current_user.id
|
156
157
|
backer = Factory(:backer, user: current_user, payment_token: 'TOKEN')
|
157
158
|
|
158
|
-
get :cancel, { id: backer.id, locale: 'en', use_route: '
|
159
|
-
flash[:failure].should == I18n.t('
|
159
|
+
get :cancel, { id: backer.id, locale: 'en', use_route: 'catarse_stripe' }
|
160
|
+
flash[:failure].should == I18n.t('stripe_cancel', scope: CatarseStripe::Payment::StripeController::SCOPE)
|
160
161
|
response.should be_redirect
|
161
162
|
end
|
162
163
|
end
|
@@ -170,18 +171,18 @@ describe CatarsePaypalExpress::Payment::PaypalExpressController do
|
|
170
171
|
fake_success_details
|
171
172
|
end
|
172
173
|
|
173
|
-
context '
|
174
|
+
context 'stripe returning to success route' do
|
174
175
|
|
175
|
-
context 'when
|
176
|
+
context 'when stripe purchase is ok' do
|
176
177
|
before(:each) do
|
177
|
-
ActiveMerchant::Billing::
|
178
|
+
ActiveMerchant::Billing::StripeGateway.any_instance.stub(:details_for) do
|
178
179
|
# If we call the details_for before purchase the transaction_id will not be present
|
179
180
|
success_details.delete('transaction_id') unless success_details['transaction_id'] == '12345'
|
180
181
|
fake_success_details
|
181
182
|
end
|
182
183
|
fake_success_purchase = mock()
|
183
184
|
fake_success_purchase.stub(:success?).and_return(true)
|
184
|
-
ActiveMerchant::Billing::
|
185
|
+
ActiveMerchant::Billing::StripeGateway.any_instance.stub(:purchase) do
|
185
186
|
# only after the purchase command the transactio_id is set in the details_for
|
186
187
|
success_details['transaction_id'] = '12345' if success_details.include?('transaction_id')
|
187
188
|
fake_success_purchase
|
@@ -193,7 +194,7 @@ describe CatarsePaypalExpress::Payment::PaypalExpressController do
|
|
193
194
|
backer = Factory(:backer, user: current_user, payment_token: 'TOKEN')
|
194
195
|
backer.payment_notifications.should be_empty
|
195
196
|
|
196
|
-
get :success, { id: backer.id, PayerID: '123', locale: 'en', use_route: '
|
197
|
+
get :success, { id: backer.id, PayerID: '123', locale: 'en', use_route: 'catarse_stripe' }
|
197
198
|
backer.reload
|
198
199
|
|
199
200
|
backer.payment_notifications.should_not be_empty
|
@@ -203,18 +204,18 @@ describe CatarsePaypalExpress::Payment::PaypalExpressController do
|
|
203
204
|
end
|
204
205
|
end
|
205
206
|
|
206
|
-
context 'when
|
207
|
+
context 'when stripe purchase raise a error' do
|
207
208
|
before do
|
208
|
-
ActiveMerchant::Billing::
|
209
|
+
ActiveMerchant::Billing::StripeGateway.any_instance.stub(:purchase).and_raise(StandardError)
|
209
210
|
end
|
210
211
|
|
211
212
|
it 'should be redirect and show a flash message' do
|
212
213
|
session[:user_id] = current_user.id
|
213
214
|
backer = Factory(:backer, user: current_user)
|
214
215
|
|
215
|
-
get :success, { id: backer.id, PayerID: '123', locale: 'en', use_route: '
|
216
|
+
get :success, { id: backer.id, PayerID: '123', locale: 'en', use_route: 'catarse_stripe' }
|
216
217
|
|
217
|
-
flash[:failure].should == I18n.t('
|
218
|
+
flash[:failure].should == I18n.t('stripe_error', scope: CatarseStripe::Payment::StripeController::SCOPE)
|
218
219
|
response.should be_redirect
|
219
220
|
end
|
220
221
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
context "process
|
3
|
+
describe CatarseStripe::Processors::Stripe do
|
4
|
+
context "process stripe details_for response" do
|
5
5
|
let(:backer) { Factory(:backer, confirmed: false) }
|
6
6
|
|
7
7
|
it "should create a new payment_notifications for backer" do
|
@@ -11,17 +11,17 @@ describe CatarsePaypalExpress::Processors::Paypal do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should fill extra_data with all response data" do
|
14
|
-
subject.process!(backer,
|
15
|
-
backer.payment_notifications.first.extra_data.should ==
|
14
|
+
subject.process!(backer, stripe_details_response)
|
15
|
+
backer.payment_notifications.first.extra_data.should == stripe_details_response
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should confirm backer when checkout status is completed" do
|
19
|
-
subject.process!(backer,
|
19
|
+
subject.process!(backer, stripe_details_response)
|
20
20
|
backer.confirmed.should be_true
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should not confirm when checkout status is not completed" do
|
24
|
-
subject.process!(backer,
|
24
|
+
subject.process!(backer, stripe_details_response.merge!({"checkout_status" => "just_another_status"}) )
|
25
25
|
backer.confirmed.should be_false
|
26
26
|
end
|
27
27
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -35,7 +35,7 @@ RSpec.configure do |config|
|
|
35
35
|
config.infer_base_class_for_anonymous_controllers = false
|
36
36
|
|
37
37
|
# Include Engine routes (needed for Controller specs)
|
38
|
-
config.include
|
38
|
+
config.include CatarseStripe::Engine.routes.url_helpers
|
39
39
|
|
40
40
|
# Include Catarse routes
|
41
41
|
config.include Catarse::Application.routes.url_helpers
|
@@ -67,13 +67,13 @@ def fixture_file(filename)
|
|
67
67
|
File.read(file_path)
|
68
68
|
end
|
69
69
|
|
70
|
-
def
|
70
|
+
def stripe_setup_purchase_success_response
|
71
71
|
{ "timestamp"=>"2012-07-23T00:24:21Z", "ack"=>"Success", "correlation_id"=>"dcb8596be51cd", "version"=>"62.0", "build"=>"3332236",
|
72
72
|
"token"=>"EC-49X25168KR2556548", "Timestamp"=>"2012-07-23T00:24:21Z", "Ack"=>"Success", "CorrelationID"=>"dcb8596be51cd",
|
73
73
|
"Version"=>"62.0", "Build"=>"3332236", "Token"=>"EC-49X25168KR2556548" }
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
76
|
+
def stripe_details_response
|
77
77
|
{
|
78
78
|
"transaction_id" => "1234",
|
79
79
|
"checkout_status" => "PaymentActionCompleted"
|
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.0
|
4
|
+
version: 0.1.0
|
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-
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -43,6 +43,70 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 1.17.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: stripe
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: omniauth-stripe-connect
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: stripe_event
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: figaro
|
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'
|
46
110
|
- !ruby/object:Gem::Dependency
|
47
111
|
name: rspec-rails
|
48
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,6 +162,7 @@ executables: []
|
|
98
162
|
extensions: []
|
99
163
|
extra_rdoc_files: []
|
100
164
|
files:
|
165
|
+
- .DS_Store
|
101
166
|
- .gitignore
|
102
167
|
- Gemfile
|
103
168
|
- Gemfile.lock
|
@@ -111,25 +176,30 @@ files:
|
|
111
176
|
- app/assets/javascripts/catarse_stripe/stripe_form.js
|
112
177
|
- app/assets/javascripts/catarse_stripe/user_document.js
|
113
178
|
- app/controllers/catarse_stripe/payment/stripe_controller.rb
|
179
|
+
- app/views/catarse_stripe/payment/stripe/charge.html.erb
|
180
|
+
- app/views/catarse_stripe/payment/stripe/connect.html.slim
|
114
181
|
- app/views/catarse_stripe/payment/stripe/review.html.slim
|
115
|
-
- catarse_stripe-0.0.2.gem
|
116
|
-
- catarse_stripe-0.0.3.gem
|
117
|
-
- catarse_stripe-0.0.4.gem
|
118
182
|
- catarse_stripe.gemspec
|
119
|
-
- config/initializers/active_merchant.rb
|
120
183
|
- config/initializers/register.rb
|
184
|
+
- config/initializers/stripe.rb
|
121
185
|
- config/locales/en.yml
|
122
186
|
- config/routes.rb
|
187
|
+
- db/migrate/20130217194840_add_stripe_key_to_users.rb
|
188
|
+
- db/migrate/20130218164300_add_stripe_id_to_users.rb
|
189
|
+
- db/migrate/20130218184756_add_stripe_access_token_to_users.rb
|
190
|
+
- db/migrate/20130219201753_add_stripe_userid_and_stripe_access_token_to_projects.rb
|
191
|
+
- db/migrate/20130220030158_add_stripe_key_to_projects.rb
|
123
192
|
- lib/catarse_stripe.rb
|
124
193
|
- lib/catarse_stripe/engine.rb
|
125
194
|
- lib/catarse_stripe/processors.rb
|
126
195
|
- lib/catarse_stripe/processors/stripe.rb
|
127
196
|
- lib/catarse_stripe/version.rb
|
128
197
|
- lib/tasks/catarse_stripe_tasks.rake
|
198
|
+
- public/.DS_Store
|
129
199
|
- script/rails
|
130
|
-
- spec/controllers/catarse_paypal_express/payment/
|
200
|
+
- spec/controllers/catarse_paypal_express/payment/stripe_controller_spec.rb
|
131
201
|
- spec/fixtures/ipn_data.txt
|
132
|
-
- spec/lib/processors/
|
202
|
+
- spec/lib/processors/stripe_spec.rb
|
133
203
|
- spec/spec_helper.rb
|
134
204
|
- test/.DS_Store
|
135
205
|
homepage: http://github.com/lvxn0va/catarse_stripe
|
@@ -157,8 +227,8 @@ signing_key:
|
|
157
227
|
specification_version: 3
|
158
228
|
summary: Stripe Payments Integration with Catarse.
|
159
229
|
test_files:
|
160
|
-
- spec/controllers/catarse_paypal_express/payment/
|
230
|
+
- spec/controllers/catarse_paypal_express/payment/stripe_controller_spec.rb
|
161
231
|
- spec/fixtures/ipn_data.txt
|
162
|
-
- spec/lib/processors/
|
232
|
+
- spec/lib/processors/stripe_spec.rb
|
163
233
|
- spec/spec_helper.rb
|
164
234
|
- test/.DS_Store
|
data/catarse_stripe-0.0.2.gem
DELETED
Binary file
|
data/catarse_stripe-0.0.3.gem
DELETED
Binary file
|
data/catarse_stripe-0.0.4.gem
DELETED
Binary file
|