add stripe integration for safebooru
This commit is contained in:
@@ -95,6 +95,10 @@ div#c-users {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
div.section {
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
|
||||
div#feature-comparison {
|
||||
overflow: hidden;
|
||||
margin-bottom: 1em;
|
||||
|
||||
@@ -5,18 +5,11 @@ class UserUpgradesController < ApplicationController
|
||||
skip_before_action :verify_authenticity_token, only: [:create]
|
||||
|
||||
def create
|
||||
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
|
||||
if params[:stripeToken]
|
||||
create_stripe
|
||||
elsif params[:order]
|
||||
create_coinbase
|
||||
end
|
||||
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def new
|
||||
@@ -46,6 +39,53 @@ class UserUpgradesController < ApplicationController
|
||||
|
||||
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
|
||||
crypt.decrypt_and_verify(params[:order][:custom]).split(/,/).map(&:to_i)
|
||||
end
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
module UserUpgradesHelper
|
||||
def stripe_button(desc, cost)
|
||||
def stripe_button(desc, cost, user)
|
||||
html = %{
|
||||
<form action="#{user_upgrade_path}" method="POST" class="stripe">
|
||||
<input type="hidden" name="authenticity_token" value="#{form_authenticity_token}">
|
||||
#{hidden_field_tag(:desc, desc)}
|
||||
#{hidden_field_tag(:user_id, user.id)}
|
||||
<script
|
||||
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
|
||||
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] %>
|
||||
<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 %>
|
||||
<% 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 %>
|
||||
</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>
|
||||
<% 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 %>
|
||||
<%= render "coinbase_payment" %>
|
||||
<% end %>
|
||||
|
||||
<% if Danbooru.config.stripe_publishable_key %>
|
||||
<% if CurrentUser.safe_mode? %>
|
||||
<%= render "stripe_payment" %>
|
||||
<% else %>
|
||||
<%= render "stripe_payment_safebooru" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user