add stripe integration for safebooru
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -46,6 +46,7 @@ gem 'radix62', '~> 1.0.1'
|
|||||||
gem 'streamio-ffmpeg'
|
gem 'streamio-ffmpeg'
|
||||||
gem 'rubyzip', :require => "zip"
|
gem 'rubyzip', :require => "zip"
|
||||||
gem 'coinbase'
|
gem 'coinbase'
|
||||||
|
gem 'stripe'
|
||||||
|
|
||||||
# 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"
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ 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.10.2)
|
||||||
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)
|
||||||
@@ -187,6 +188,9 @@ GEM
|
|||||||
raindrops (0.13.0)
|
raindrops (0.13.0)
|
||||||
rake (10.4.2)
|
rake (10.4.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)
|
||||||
@@ -225,6 +229,10 @@ GEM
|
|||||||
sprockets (>= 2.8, < 4.0)
|
sprockets (>= 2.8, < 4.0)
|
||||||
statistics2 (0.54)
|
statistics2 (0.54)
|
||||||
streamio-ffmpeg (1.0.0)
|
streamio-ffmpeg (1.0.0)
|
||||||
|
stripe (1.18.0)
|
||||||
|
json (~> 1.8.1)
|
||||||
|
mime-types (>= 1.25, < 3.0)
|
||||||
|
rest-client (~> 1.4)
|
||||||
term-ansicolor (1.3.0)
|
term-ansicolor (1.3.0)
|
||||||
tins (~> 1.0)
|
tins (~> 1.0)
|
||||||
therubyracer (0.12.1)
|
therubyracer (0.12.1)
|
||||||
@@ -301,6 +309,7 @@ DEPENDENCIES
|
|||||||
sprockets-rails
|
sprockets-rails
|
||||||
statistics2
|
statistics2
|
||||||
streamio-ffmpeg
|
streamio-ffmpeg
|
||||||
|
stripe
|
||||||
term-ansicolor
|
term-ansicolor
|
||||||
therubyracer
|
therubyracer
|
||||||
timecop
|
timecop
|
||||||
|
|||||||
@@ -95,6 +95,10 @@ div#c-users {
|
|||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.section {
|
||||||
|
margin-bottom: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
div#feature-comparison {
|
div#feature-comparison {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
|
|||||||
@@ -5,18 +5,11 @@ class UserUpgradesController < ApplicationController
|
|||||||
skip_before_action :verify_authenticity_token, only: [:create]
|
skip_before_action :verify_authenticity_token, only: [:create]
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if params[:order][:status] == "completed"
|
if params[:stripeToken]
|
||||||
user_id, level = decrypt_custom
|
create_stripe
|
||||||
member = User.find(user_id)
|
elsif params[:order]
|
||||||
|
create_coinbase
|
||||||
if member.level < User::Levels::PLATINUM && level >= User::Levels::GOLD && level <= User::Levels::PLATINUM
|
|
||||||
CurrentUser.scoped(User.admins.first, "127.0.0.1") do
|
|
||||||
member.promote_to!(level, :skip_feedback => true)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
render :nothing => true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@@ -46,6 +39,53 @@ class UserUpgradesController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def create_stripe
|
||||||
|
@user = user
|
||||||
|
|
||||||
|
if params[:desc] == "Upgrade to Gold"
|
||||||
|
level = User::Levels::GOLD
|
||||||
|
cost = 2000
|
||||||
|
elsif params[:desc] == "Upgrade to Platinum"
|
||||||
|
level = User::Levels::PLATINUM
|
||||||
|
cost = 4000
|
||||||
|
elsif params[:desc] == "Upgrade Gold to Platinum" && @user.level == User::Levels::GOLD
|
||||||
|
level = User::Levels::PLATINUM
|
||||||
|
cost = 2000
|
||||||
|
else
|
||||||
|
raise "Invalid desc"
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
charge = Stripe::Charge.create(
|
||||||
|
:amount => cost,
|
||||||
|
:currency => "usd",
|
||||||
|
:card => params[:stripeToken],
|
||||||
|
:description => params[:desc]
|
||||||
|
)
|
||||||
|
@user.promote_to!(level, :skip_feedback => true)
|
||||||
|
flash[:success] = true
|
||||||
|
rescue Stripe::CardError => e
|
||||||
|
flash[:error] = e.message
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to user_upgrade_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_coinbase
|
||||||
|
if params[:order][:status] == "completed"
|
||||||
|
user_id, level = decrypt_custom
|
||||||
|
member = User.find(user_id)
|
||||||
|
|
||||||
|
if member.level < User::Levels::PLATINUM && level >= User::Levels::GOLD && level <= User::Levels::PLATINUM
|
||||||
|
CurrentUser.scoped(User.admins.first, "127.0.0.1") do
|
||||||
|
member.promote_to!(level, :skip_feedback => true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
render :nothing => true
|
||||||
|
end
|
||||||
|
|
||||||
def decrypt_custom
|
def decrypt_custom
|
||||||
crypt.decrypt_and_verify(params[:order][:custom]).split(/,/).map(&:to_i)
|
crypt.decrypt_and_verify(params[:order][:custom]).split(/,/).map(&:to_i)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
module UserUpgradesHelper
|
module UserUpgradesHelper
|
||||||
def stripe_button(desc, cost)
|
def stripe_button(desc, cost, user)
|
||||||
html = %{
|
html = %{
|
||||||
<form action="#{user_upgrade_path}" method="POST" class="stripe">
|
<form action="#{user_upgrade_path}" method="POST" class="stripe">
|
||||||
<input type="hidden" name="authenticity_token" value="#{form_authenticity_token}">
|
<input type="hidden" name="authenticity_token" value="#{form_authenticity_token}">
|
||||||
#{hidden_field_tag(:desc, desc)}
|
#{hidden_field_tag(:desc, desc)}
|
||||||
|
#{hidden_field_tag(:user_id, user.id)}
|
||||||
<script
|
<script
|
||||||
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
|
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
|
||||||
data-key="#{Danbooru.config.stripe_publishable_key}"
|
data-key="#{Danbooru.config.stripe_publishable_key}"
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
<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>
|
<div class="section">
|
||||||
|
<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 params[:user_id] %>
|
<% if user.level < User::Levels::GOLD %>
|
||||||
<p>You are gifting this account upgrade to <%= link_to user.pretty_name, user_path(params[:user_id]) %>.</p>
|
<%= 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 %>
|
||||||
<% else %>
|
<%= 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 %>
|
||||||
<p>You can also upgrade someone else's account for the same price. The easiest way is to go to their profile page and look for a "Gift Upgrade" link.</p>
|
<% elsif user.level < User::Levels::PLATINUM %>
|
||||||
<% end %>
|
<%= 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 %>
|
||||||
|
</div>
|
||||||
|
|
||||||
<% if 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 user.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 %>
|
|
||||||
|
|||||||
10
app/views/user_upgrades/_stripe_payment.html.erb
Normal file
10
app/views/user_upgrades/_stripe_payment.html.erb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<div class="section">
|
||||||
|
<p>You can pay with a credit card. Safebooru uses <a href="https://www.stripe.com">Stripe</a> as a payment intermediary so none of your personal information will be stored on the site.</p>
|
||||||
|
|
||||||
|
<% if user.level < User::Levels::GOLD %>
|
||||||
|
<%= stripe_button("Upgrade to Gold", 2000, user) %>
|
||||||
|
<%= stripe_button("Upgrade to Platinum", 4000, user) %>
|
||||||
|
<% elsif user.level < User::Levels::PLATINUM %>
|
||||||
|
<%= stripe_button("Upgrade Gold to Platinum", 2000, user) %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<div class="section">
|
||||||
|
<p>You can pay with a credit card on <%= link_to "Safebooru", new_user_upgrade_path(:only_path => false, :domain => "safebooru.donmai.us", :protocol => "https") %>. Your account will then also be upgraded on Danbooru. You can login to Safebooru with the same username and password you use on Danbooru.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ -85,9 +85,25 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<div class="section">
|
||||||
|
<% if params[:user_id] %>
|
||||||
|
<p>You are gifting this account upgrade to <%= link_to user.pretty_name, user_path(params[:user_id]) %>.</p>
|
||||||
|
<% else %>
|
||||||
|
<p>You can also upgrade someone else's account for the same price. The easiest way is to go to their profile page and look for a "Gift Upgrade" link.</p>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
<% if Danbooru.config.coinbase_api_key %>
|
<% if Danbooru.config.coinbase_api_key %>
|
||||||
<%= render "coinbase_payment" %>
|
<%= render "coinbase_payment" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% if Danbooru.config.stripe_publishable_key %>
|
||||||
|
<% if CurrentUser.safe_mode? %>
|
||||||
|
<%= render "stripe_payment" %>
|
||||||
|
<% else %>
|
||||||
|
<%= render "stripe_payment_safebooru" %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -335,5 +335,11 @@ module Danbooru
|
|||||||
|
|
||||||
def coinbase_api_secret
|
def coinbase_api_secret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stripe_secret_key
|
||||||
|
end
|
||||||
|
|
||||||
|
def stripe_publishable_key
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
1
config/initializers/stripe.rb
Normal file
1
config/initializers/stripe.rb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Stripe.api_key = Danbooru.config.stripe_secret_key
|
||||||
Reference in New Issue
Block a user