user upgrades: factor out gold/platinum prices.

This commit is contained in:
evazion
2019-12-24 11:52:16 -06:00
parent 7694be9cb3
commit ef2eb9d0f5
6 changed files with 32 additions and 9 deletions

View File

@@ -30,13 +30,13 @@ class UserUpgradesController < ApplicationController
if params[:desc] == "Upgrade to Gold"
level = User::Levels::GOLD
cost = 2000
cost = UserUpgrade.gold_price
elsif params[:desc] == "Upgrade to Platinum"
level = User::Levels::PLATINUM
cost = 4000
cost = UserUpgrade.platinum_price
elsif params[:desc] == "Upgrade Gold to Platinum" && @user.level == User::Levels::GOLD
level = User::Levels::PLATINUM
cost = 2000
cost = UserUpgrade.upgrade_price
else
raise "Invalid desc"
end

View File

@@ -18,4 +18,8 @@ module UserUpgradesHelper
raw(html)
end
def cents_to_usd(cents)
number_to_currency(cents / 100, precision: 0)
end
end

View File

@@ -0,0 +1,13 @@
class UserUpgrade
def self.gold_price
2000
end
def self.platinum_price
4000
end
def self.upgrade_price
2000
end
end

View File

@@ -2,10 +2,10 @@
<p>You can pay with a credit or debit 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) %>
<%= stripe_button("Upgrade to Gold", UserUpgrade.gold_price, user) %>
<%= stripe_button("Upgrade to Platinum", UserUpgrade.platinum_price, user) %>
<% elsif user.level < User::Levels::PLATINUM %>
<%= stripe_button("Upgrade Gold to Platinum", 2000, user) %>
<%= stripe_button("Upgrade Gold to Platinum", UserUpgrade.upgrade_price, user) %>
<% end %>
</div>

View File

@@ -23,8 +23,14 @@
<tr>
<td>Cost</td>
<td>Free</td>
<td>$20<div class="fineprint">One time fee</div></td>
<td>$40<div class="fineprint">One time fee</div></td>
<td>
<%= cents_to_usd(UserUpgrade.gold_price) %>
<div class="fineprint">One time fee</div>
</td>
<td>
<%= cents_to_usd(UserUpgrade.platinum_price) %>
<div class="fineprint">One time fee</div>
</td>
</tr>
<tr>
<td>Tag Limit</td>

View File

@@ -1,4 +1,4 @@
<div class="notice notice-info notice-large" id="upgrade-account-notice">
<h2><%= link_to "Upgrade your account for only $20!", new_user_upgrade_path, id: "goto-upgrade-account" %></h2>
<h2><%= link_to "Upgrade your account for only #{cents_to_usd(UserUpgrade.gold_price)}!", new_user_upgrade_path, id: "goto-upgrade-account" %></h2>
<div><%= link_to "No thanks", "#", id: "hide-upgrade-account-notice" %></div>
</div>