diff --git a/Gemfile b/Gemfile index f70f08194..d90ec0dc3 100644 --- a/Gemfile +++ b/Gemfile @@ -45,7 +45,7 @@ gem 'capistrano-ext' gem 'radix62', '~> 1.0.1' gem 'streamio-ffmpeg' gem 'rubyzip', :require => "zip" -gem 'stripe', :git => "https://github.com/stripe/stripe-ruby" +gem 'coinbase' # needed for looser jpeg header compat gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes" diff --git a/Gemfile.lock b/Gemfile.lock index 7581f49dc..8e901e66c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -14,15 +14,6 @@ GIT specs: 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 remote: https://rubygems.org/ specs: @@ -78,6 +69,13 @@ GEM coffee-script-source execjs 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) crack (0.4.2) safe_yaml (~> 1.0.0) @@ -102,13 +100,20 @@ GEM execjs (2.0.2) factory_girl (4.4.0) activesupport (>= 3.0.0) + faraday (0.9.0) + multipart-post (>= 1.2, < 3) ffaker (1.24.0) + hashie (3.3.1) highline (1.6.21) hike (1.2.3) http-cookie (1.0.2) domain_name (~> 0.5) + httparty (0.13.3) + json (~> 1.8) + multi_xml (>= 0.5.2) i18n (0.6.11) json (1.8.1) + jwt (1.2.0) kgio (2.9.2) libv8 (3.16.14.3) mail (2.5.4) @@ -130,7 +135,13 @@ GEM minitest (5.4.0) mocha (1.0.0) 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_xml (0.5.5) + multipart-post (2.0.0) net-http-digest_auth (1.4) net-http-persistent (2.9.4) net-scp (1.2.0) @@ -140,11 +151,16 @@ GEM net-ssh (2.8.0) net-ssh-gateway (1.2.0) net-ssh (>= 2.6.5) - netrc (0.8.0) newrelic_rpm (3.9.6.257) nokogiri (1.6.1) mini_portile (~> 0.5.0) 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) polyglot (0.3.5) protected_attributes (1.0.7) @@ -178,9 +194,6 @@ GEM raindrops (0.13.0) rake (10.3.2) ref (1.0.5) - rest-client (1.7.2) - mime-types (>= 1.16, < 3.0) - netrc (~> 0.7) rmagick (2.13.3) ruby-prof (0.14.2) rubyzip (1.1.6) @@ -265,6 +278,7 @@ DEPENDENCIES capistrano-ext capistrano-unicorn coffee-rails + coinbase daemons dalli delayed_job @@ -297,7 +311,6 @@ DEPENDENCIES sprockets-rails statistics2 streamio-ffmpeg - stripe! term-ansicolor therubyracer timecop diff --git a/app/controllers/user_upgrades_controller.rb b/app/controllers/user_upgrades_controller.rb index 52db53a94..0903889bb 100644 --- a/app/controllers/user_upgrades_controller.rb +++ b/app/controllers/user_upgrades_controller.rb @@ -1,41 +1,21 @@ 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 - if params[:desc] == "Upgrade to Gold" - level = User::Levels::GOLD - cost = 2000 + if params[:order][:status] == "completed" + user_id, level = decrypt_custom + user = User.find(user_id) - elsif params[:desc] == "Upgrade to Platinum" - level = User::Levels::PLATINUM - cost = 4000 + if user.level < User::Levels::PLATINUM && level >= User::Levels::GOLD && level <= User::Levels::PLATINUM + user.promote_to!(level, :skip_feedback => true) + 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 - rescue Stripe::CardError => e - flash[:error] = e.message + else + flash[:error] = true end - redirect_to user_upgrade_path end @@ -47,4 +27,26 @@ class UserUpgradesController < ApplicationController def show 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 diff --git a/app/views/user_upgrades/_coinbase_payment.html.erb b/app/views/user_upgrades/_coinbase_payment.html.erb new file mode 100644 index 000000000..0a3c0e0ea --- /dev/null +++ b/app/views/user_upgrades/_coinbase_payment.html.erb @@ -0,0 +1,8 @@ +

You can pay with Bitcoin. You will pay either $20 USD or $40 USD equivalent in Bitcoin. Danbooru uses Coinbase as a payment intermediary so none of your personal information will be stored on the site.

+ +<% 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 %> diff --git a/app/views/user_upgrades/new.html.erb b/app/views/user_upgrades/new.html.erb index 75ed82a88..b0187e501 100644 --- a/app/views/user_upgrades/new.html.erb +++ b/app/views/user_upgrades/new.html.erb @@ -82,6 +82,10 @@ + + <% if Danbooru.config.coinbase_api_key %> + <%= render "coinbase_payment" %> + <% end %> diff --git a/app/views/user_upgrades/show.html.erb b/app/views/user_upgrades/show.html.erb index 443c54920..9c691f7f7 100644 --- a/app/views/user_upgrades/show.html.erb +++ b/app/views/user_upgrades/show.html.erb @@ -1,8 +1,6 @@
- <% if flash[:disable] %> -

You can upgrade your account at <%= link_to "Safebooru", new_user_upgrade_path(:protocol => "https", :host => "safebooru.donmai.us", :only_path => false) %>.

- <% elsif flash[:success] %> + <% if flash[:success] %>

Congradulations!

You are now a <%= CurrentUser.user.level_string %> level account. Thanks for supporting the site!

diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index 5ad3d8f51..b2276380d 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -326,5 +326,14 @@ module Danbooru def shared_dir_path "/var/www/danbooru2/shared" end + + def coinbase_secret + end + + def coinbase_api_key + end + + def coinbase_api_secret + end end end