implement coinbase integration
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -45,7 +45,7 @@ gem 'capistrano-ext'
|
|||||||
gem 'radix62', '~> 1.0.1'
|
gem 'radix62', '~> 1.0.1'
|
||||||
gem 'streamio-ffmpeg'
|
gem 'streamio-ffmpeg'
|
||||||
gem 'rubyzip', :require => "zip"
|
gem 'rubyzip', :require => "zip"
|
||||||
gem 'stripe', :git => "https://github.com/stripe/stripe-ruby"
|
gem 'coinbase'
|
||||||
|
|
||||||
# needed for looser jpeg header compat
|
# needed for looser jpeg header compat
|
||||||
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"
|
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"
|
||||||
|
|||||||
41
Gemfile.lock
41
Gemfile.lock
@@ -14,15 +14,6 @@ GIT
|
|||||||
specs:
|
specs:
|
||||||
ruby-imagespec (0.3.1)
|
ruby-imagespec (0.3.1)
|
||||||
|
|
||||||
GIT
|
|
||||||
remote: https://github.com/stripe/stripe-ruby
|
|
||||||
revision: da216fd53b7a5386c136e93bdfe5efaff20682b7
|
|
||||||
specs:
|
|
||||||
stripe (1.16.0)
|
|
||||||
json (~> 1.8.1)
|
|
||||||
mime-types (>= 1.25, < 3.0)
|
|
||||||
rest-client (~> 1.4)
|
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
@@ -78,6 +69,13 @@ GEM
|
|||||||
coffee-script-source
|
coffee-script-source
|
||||||
execjs
|
execjs
|
||||||
coffee-script-source (1.7.0)
|
coffee-script-source (1.7.0)
|
||||||
|
coinbase (2.1.1)
|
||||||
|
hashie (>= 1.2.0)
|
||||||
|
httparty (>= 0.8.3)
|
||||||
|
monetize (~> 0.3.0)
|
||||||
|
money (~> 6.0)
|
||||||
|
multi_json (>= 1.3.4)
|
||||||
|
oauth2 (~> 1.0)
|
||||||
columnize (0.8.9)
|
columnize (0.8.9)
|
||||||
crack (0.4.2)
|
crack (0.4.2)
|
||||||
safe_yaml (~> 1.0.0)
|
safe_yaml (~> 1.0.0)
|
||||||
@@ -102,13 +100,20 @@ GEM
|
|||||||
execjs (2.0.2)
|
execjs (2.0.2)
|
||||||
factory_girl (4.4.0)
|
factory_girl (4.4.0)
|
||||||
activesupport (>= 3.0.0)
|
activesupport (>= 3.0.0)
|
||||||
|
faraday (0.9.0)
|
||||||
|
multipart-post (>= 1.2, < 3)
|
||||||
ffaker (1.24.0)
|
ffaker (1.24.0)
|
||||||
|
hashie (3.3.1)
|
||||||
highline (1.6.21)
|
highline (1.6.21)
|
||||||
hike (1.2.3)
|
hike (1.2.3)
|
||||||
http-cookie (1.0.2)
|
http-cookie (1.0.2)
|
||||||
domain_name (~> 0.5)
|
domain_name (~> 0.5)
|
||||||
|
httparty (0.13.3)
|
||||||
|
json (~> 1.8)
|
||||||
|
multi_xml (>= 0.5.2)
|
||||||
i18n (0.6.11)
|
i18n (0.6.11)
|
||||||
json (1.8.1)
|
json (1.8.1)
|
||||||
|
jwt (1.2.0)
|
||||||
kgio (2.9.2)
|
kgio (2.9.2)
|
||||||
libv8 (3.16.14.3)
|
libv8 (3.16.14.3)
|
||||||
mail (2.5.4)
|
mail (2.5.4)
|
||||||
@@ -130,7 +135,13 @@ GEM
|
|||||||
minitest (5.4.0)
|
minitest (5.4.0)
|
||||||
mocha (1.0.0)
|
mocha (1.0.0)
|
||||||
metaclass (~> 0.0.1)
|
metaclass (~> 0.0.1)
|
||||||
|
monetize (0.3.0)
|
||||||
|
money (~> 6.1.0.beta1)
|
||||||
|
money (6.1.1)
|
||||||
|
i18n (~> 0.6.4)
|
||||||
multi_json (1.10.1)
|
multi_json (1.10.1)
|
||||||
|
multi_xml (0.5.5)
|
||||||
|
multipart-post (2.0.0)
|
||||||
net-http-digest_auth (1.4)
|
net-http-digest_auth (1.4)
|
||||||
net-http-persistent (2.9.4)
|
net-http-persistent (2.9.4)
|
||||||
net-scp (1.2.0)
|
net-scp (1.2.0)
|
||||||
@@ -140,11 +151,16 @@ GEM
|
|||||||
net-ssh (2.8.0)
|
net-ssh (2.8.0)
|
||||||
net-ssh-gateway (1.2.0)
|
net-ssh-gateway (1.2.0)
|
||||||
net-ssh (>= 2.6.5)
|
net-ssh (>= 2.6.5)
|
||||||
netrc (0.8.0)
|
|
||||||
newrelic_rpm (3.9.6.257)
|
newrelic_rpm (3.9.6.257)
|
||||||
nokogiri (1.6.1)
|
nokogiri (1.6.1)
|
||||||
mini_portile (~> 0.5.0)
|
mini_portile (~> 0.5.0)
|
||||||
ntlm-http (0.1.1)
|
ntlm-http (0.1.1)
|
||||||
|
oauth2 (1.0.0)
|
||||||
|
faraday (>= 0.8, < 0.10)
|
||||||
|
jwt (~> 1.0)
|
||||||
|
multi_json (~> 1.3)
|
||||||
|
multi_xml (~> 0.5)
|
||||||
|
rack (~> 1.2)
|
||||||
pg (0.17.1)
|
pg (0.17.1)
|
||||||
polyglot (0.3.5)
|
polyglot (0.3.5)
|
||||||
protected_attributes (1.0.7)
|
protected_attributes (1.0.7)
|
||||||
@@ -178,9 +194,6 @@ GEM
|
|||||||
raindrops (0.13.0)
|
raindrops (0.13.0)
|
||||||
rake (10.3.2)
|
rake (10.3.2)
|
||||||
ref (1.0.5)
|
ref (1.0.5)
|
||||||
rest-client (1.7.2)
|
|
||||||
mime-types (>= 1.16, < 3.0)
|
|
||||||
netrc (~> 0.7)
|
|
||||||
rmagick (2.13.3)
|
rmagick (2.13.3)
|
||||||
ruby-prof (0.14.2)
|
ruby-prof (0.14.2)
|
||||||
rubyzip (1.1.6)
|
rubyzip (1.1.6)
|
||||||
@@ -265,6 +278,7 @@ DEPENDENCIES
|
|||||||
capistrano-ext
|
capistrano-ext
|
||||||
capistrano-unicorn
|
capistrano-unicorn
|
||||||
coffee-rails
|
coffee-rails
|
||||||
|
coinbase
|
||||||
daemons
|
daemons
|
||||||
dalli
|
dalli
|
||||||
delayed_job
|
delayed_job
|
||||||
@@ -297,7 +311,6 @@ DEPENDENCIES
|
|||||||
sprockets-rails
|
sprockets-rails
|
||||||
statistics2
|
statistics2
|
||||||
streamio-ffmpeg
|
streamio-ffmpeg
|
||||||
stripe!
|
|
||||||
term-ansicolor
|
term-ansicolor
|
||||||
therubyracer
|
therubyracer
|
||||||
timecop
|
timecop
|
||||||
|
|||||||
@@ -1,41 +1,21 @@
|
|||||||
class UserUpgradesController < ApplicationController
|
class UserUpgradesController < ApplicationController
|
||||||
before_filter :member_only
|
before_filter :member_only, :only => [:new, :show]
|
||||||
|
helper_method :encrypt_custom, :coinbase
|
||||||
|
force_ssl :if => :ssl_enabled?
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if params[:desc] == "Upgrade to Gold"
|
if params[:order][:status] == "completed"
|
||||||
level = User::Levels::GOLD
|
user_id, level = decrypt_custom
|
||||||
cost = 2000
|
user = User.find(user_id)
|
||||||
|
|
||||||
elsif params[:desc] == "Upgrade to Platinum"
|
if user.level < User::Levels::PLATINUM && level >= User::Levels::GOLD && level <= User::Levels::PLATINUM
|
||||||
level = User::Levels::PLATINUM
|
user.promote_to!(level, :skip_feedback => true)
|
||||||
cost = 4000
|
end
|
||||||
|
|
||||||
elsif params[:desc] == "Upgrade Gold to Platinum" && CurrentUser.user.level == User::Levels::GOLD
|
|
||||||
level = User::Levels::PLATINUM
|
|
||||||
cost = 2000
|
|
||||||
|
|
||||||
else
|
|
||||||
render :text => "invalid desc", :status => 422
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
@user = CurrentUser.user
|
|
||||||
stripe_token = params[:stripeToken]
|
|
||||||
|
|
||||||
begin
|
|
||||||
charge = Stripe::Charge.create(
|
|
||||||
:amount => cost,
|
|
||||||
:currency => "usd",
|
|
||||||
:card => params[:stripeToken],
|
|
||||||
:description => params[:desc]
|
|
||||||
)
|
|
||||||
@user.promote_to!(level, :skip_feedback => true)
|
|
||||||
UserMailer.upgrade(@user, params[:email]).deliver
|
|
||||||
flash[:success] = true
|
flash[:success] = true
|
||||||
rescue Stripe::CardError => e
|
else
|
||||||
flash[:error] = e.message
|
flash[:error] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to user_upgrade_path
|
redirect_to user_upgrade_path
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -47,4 +27,26 @@ class UserUpgradesController < ApplicationController
|
|||||||
|
|
||||||
def show
|
def show
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def encrypt_custom(level)
|
||||||
|
crypt.encrypt_and_sign("#{CurrentUser.user.id},#{level}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def coinbase
|
||||||
|
@coinbase_api ||= Coinbase::Client.new(Danbooru.config.coinbase_api_key, Danbooru.config.coinbase_api_secret)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def decrypt_custom
|
||||||
|
crypt.decrypt_and_verify(params[:order][:custom]).split(/,/).map(&:to_i)
|
||||||
|
end
|
||||||
|
|
||||||
|
def crypt
|
||||||
|
ActiveSupport::MessageEncryptor.new(Danbooru.config.coinbase_secret)
|
||||||
|
end
|
||||||
|
|
||||||
|
def ssl_enabled?
|
||||||
|
!Rails.env.development? && !Rails.env.test?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
8
app/views/user_upgrades/_coinbase_payment.html.erb
Normal file
8
app/views/user_upgrades/_coinbase_payment.html.erb
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<p>You can pay with Bitcoin. You will pay either $20 USD or $40 USD equivalent in Bitcoin. Danbooru uses <a href="https://www.coinbase.com">Coinbase</a> as a payment intermediary so none of your personal information will be stored on the site.</p>
|
||||||
|
|
||||||
|
<% if CurrentUser.user.level < User::Levels::GOLD %>
|
||||||
|
<%= raw coinbase.create_button("Upgrade to Gold", 20.to_money("USD"), "Upgrade your Basic Account to a Gold Account", encrypt_custom(User::Levels::GOLD), :button => {:style => "custom_small", :text => "Upgrade to Gold", :callback_url => user_upgrade_path(:only_path => false, :host => Danbooru.config.hostname, :protocol => "https")}).embed_html %>
|
||||||
|
<%= raw coinbase.create_button("Upgrade to Platinum", 40.to_money("USD"), "Upgrade your Basic Account to a Platinum Account", encrypt_custom(User::Levels::PLATINUM), :button => {:style => "custom_small", :text => "Upgrade to Platinum", :callback_url => user_upgrade_path(:only_path => false, :host => Danbooru.config.hostname, :protocol => "https")}).embed_html %>
|
||||||
|
<% elsif CurrentUser.level < User::Levels::PLATINUM %>
|
||||||
|
<%= raw coinbase.create_button("Upgrade to Platinum", 20.to_money("USD"), "Upgrade your Gold Account to a Platinum Account", encrypt_custom(User::Levels::PLATINUM), :button => {:style => "custom_small", :text => "Upgrade to Platinum", :callback_url => user_upgrade_path(:only_path => false, :host => Danbooru.config.hostname, :protocol => "https")}).embed_html %>
|
||||||
|
<% end %>
|
||||||
@@ -82,6 +82,10 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% if Danbooru.config.coinbase_api_key %>
|
||||||
|
<%= render "coinbase_payment" %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
<div id="c-users">
|
<div id="c-users">
|
||||||
<div id="a-upgrade-result">
|
<div id="a-upgrade-result">
|
||||||
<% if flash[:disable] %>
|
<% if flash[:success] %>
|
||||||
<p>You can upgrade your account at <%= link_to "Safebooru", new_user_upgrade_path(:protocol => "https", :host => "safebooru.donmai.us", :only_path => false) %>.</p>
|
|
||||||
<% elsif flash[:success] %>
|
|
||||||
<h1>Congradulations!</h1>
|
<h1>Congradulations!</h1>
|
||||||
|
|
||||||
<p>You are now a <%= CurrentUser.user.level_string %> level account. Thanks for supporting the site!</p>
|
<p>You are now a <%= CurrentUser.user.level_string %> level account. Thanks for supporting the site!</p>
|
||||||
|
|||||||
@@ -326,5 +326,14 @@ module Danbooru
|
|||||||
def shared_dir_path
|
def shared_dir_path
|
||||||
"/var/www/danbooru2/shared"
|
"/var/www/danbooru2/shared"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def coinbase_secret
|
||||||
|
end
|
||||||
|
|
||||||
|
def coinbase_api_key
|
||||||
|
end
|
||||||
|
|
||||||
|
def coinbase_api_secret
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user