Merge branch 'coinbase'

This commit is contained in:
r888888888
2014-11-25 16:12:30 -08:00
14 changed files with 77 additions and 585 deletions

View File

@@ -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

View 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 %>

View File

@@ -1,8 +0,0 @@
<p><strong>Upgrading from Gold to Platinum will only cost $20.</strong> If you have any further questions or concerns, feel free to contact me at <%= mail_to Danbooru.config.contact_email, nil, :encode => :javascript %>.</p>
<% if CurrentUser.user.level < User::Levels::GOLD %>
<%= stripe_button("Upgrade to Gold", 2000) %>
<%= stripe_button("Upgrade to Platinum", 4000) %>
<% elsif CurrentUser.user.level < User::Levels::PLATINUM %>
<%= stripe_button("Upgrade Gold to Platinum", 2000) %>
<% end %>

View File

@@ -1,4 +0,0 @@
<!--
<p>You can upgrade your account at <%= link_to "Safebooru", new_user_upgrade_path(:protocol => "https", :host => "safebooru.donmai.us", :only_path => false), :target => "_blank" %>.</p>
-->
<p>Account upgrades are presently not available.</p>

View File

@@ -83,10 +83,8 @@
</table>
</div>
<% if CurrentUser.safe_mode? %>
<%= render "stripe_payment" %>
<% else %>
<%= render "unavailable_payment" %>
<% if Danbooru.config.coinbase_api_key %>
<%= render "coinbase_payment" %>
<% end %>
</div>
</div>

View File

@@ -1,8 +1,6 @@
<div id="c-users">
<div id="a-upgrade-result">
<% if flash[:disable] %>
<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] %>
<% if flash[:success] %>
<h1>Congradulations!</h1>
<p>You are now a <%= CurrentUser.user.level_string %> level account. Thanks for supporting the site!</p>