diff --git a/app/controllers/user_upgrades_controller.rb b/app/controllers/user_upgrades_controller.rb index 4a0b199c2..62e4cee10 100644 --- a/app/controllers/user_upgrades_controller.rb +++ b/app/controllers/user_upgrades_controller.rb @@ -1,15 +1,18 @@ class UserUpgradesController < ApplicationController - helper_method :user respond_to :js, :html def create - @user_upgrade = authorize UserUpgrade.create(recipient: user, purchaser: CurrentUser.user, status: "pending", upgrade_type: params[:upgrade_type]) + @user_upgrade = authorize UserUpgrade.create(recipient: recipient, purchaser: CurrentUser.user, status: "pending", upgrade_type: params[:upgrade_type]) @checkout = @user_upgrade.create_checkout! respond_with(@user_upgrade) end def new + @user_upgrade = authorize UserUpgrade.new(recipient: recipient, purchaser: CurrentUser.user) + @recipient = @user_upgrade.recipient + + respond_with(@user_upgrade) end def show @@ -17,7 +20,9 @@ class UserUpgradesController < ApplicationController respond_with(@user_upgrade) end - def user + private + + def recipient if params[:user_id] User.find(params[:user_id]) else diff --git a/app/javascript/src/styles/base/020_base.scss b/app/javascript/src/styles/base/020_base.scss index 00180c2c6..3230c5db2 100644 --- a/app/javascript/src/styles/base/020_base.scss +++ b/app/javascript/src/styles/base/020_base.scss @@ -118,6 +118,17 @@ table tfoot { margin-top: 2em; } +details { + border-bottom: 1px solid var(--details-border); + + summary { + cursor: pointer; + user-select: none; + outline: none; + line-height: 2em; + } +} + .fineprint { color: var(--muted-text-color); font-style: italic; diff --git a/app/javascript/src/styles/base/040_colors.css b/app/javascript/src/styles/base/040_colors.css index 5dc30e914..4cf8a227e 100644 --- a/app/javascript/src/styles/base/040_colors.css +++ b/app/javascript/src/styles/base/040_colors.css @@ -35,9 +35,12 @@ --quick-search-form-background: var(--body-background-color); + --user-upgrade-basic-background-color: #F5F5FF; --user-upgrade-gold-background-color: #FFF380; --user-upgrade-platinum-background-color: #EEE; - --user-upgrade-table-row-hover-background-color: #FEF; + --user-upgrade-button-text-color: white; + --user-upgrade-button-background-color: var(--link-color); + --user-upgrade-button-hover-background-color: hsl(213, 100%, 40%); --table-header-border: 2px solid #666; --table-row-border: 1px solid #CCC; @@ -72,6 +75,8 @@ --comment-sticky-background-color: var(--subnav-menu-background-color); + --details-border: #DDD; + --post-tooltip-background-color: var(--body-background-color); --post-tooltip-border-color: hsla(210, 100%, 3%, 0.15); --post-tooltip-box-shadow: 0 4px 14px -2px hsla(210, 100%, 3%, 0.10); @@ -157,7 +162,8 @@ --bulk-update-request-failed-color: red; --login-link-color: #E00; - --footer-border: 1px solid #EEE; + --footer-border: 1px solid #DDD; + --details-border: #DDD; --jquery-ui-widget-content-background: var(--body-background-color); --jquery-ui-widget-content-text-color: var(--text-color); @@ -255,6 +261,7 @@ body[data-current-user-theme="dark"] { --subnav-menu-background-color: var(--grey-2); --responsive-menu-background-color: var(--grey-3); --footer-border: 1px solid var(--grey-3); + --details-border: var(--grey-3); --table-header-border: 2px solid var(--grey-3); --table-even-row-background: var(--grey-2); @@ -419,9 +426,12 @@ body[data-current-user-theme="dark"] { --uploads-dropzone-progress-bar-foreground-color: var(--link-color); --uploads-dropzone-progress-bar-background-color: var(--link-hover-color); - --user-upgrade-gold-background-color: var(--yellow-0); + --user-upgrade-basic-background-color: var(--grey-2); + --user-upgrade-gold-background-color: var(--indigo-0); --user-upgrade-platinum-background-color: var(--blue-0); - --user-upgrade-table-row-hover-background-color: transparent; + --user-upgrade-button-text-color: white; + --user-upgrade-button-background-color: var(--link-color); + --user-upgrade-button-hover-background-color: var(--link-hover-color); --wiki-page-other-name-background-color: var(--grey-3); --wiki-page-versions-diff-del-background: var(--red-0); diff --git a/app/javascript/src/styles/specific/user_upgrades.scss b/app/javascript/src/styles/specific/user_upgrades.scss index 2ab6b4625..b32fdf483 100644 --- a/app/javascript/src/styles/specific/user_upgrades.scss +++ b/app/javascript/src/styles/specific/user_upgrades.scss @@ -1,43 +1,66 @@ div#c-user-upgrades { div#a-new { - form.stripe { - display: inline; - } + margin: 0 auto; - div.section { - margin-bottom: 2em; - } - - div#feature-comparison { - overflow: hidden; + * { margin-bottom: 1em; + } - table { - width: 100%; + h1 { + text-align: center; + } - colgroup { - width: 10em; - } + .login-button, form.button_to input[type="submit"] { + display: inline-block; - colgroup#gold { - background-color: var(--user-upgrade-gold-background-color); - } + color: var(--user-upgrade-button-text-color); + background-color: var(--user-upgrade-button-background-color); - colgroup#platinum { - background-color: var(--user-upgrade-platinum-background-color); - } + border: none; + border-radius: 4px; + padding: 0.75em; - td, th { - text-align: center; - vertical-align: top; - padding: 0.5em 0; - } + transition: background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, border 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; + box-shadow: 0px 3px 1px -2px rgba(0,0,0,0.2), 0px 2px 2px 0px rgba(0,0,0,0.14), 0px 1px 5px 0px rgba(0,0,0,0.12); - tbody { - tr:hover { - background-color: var(--user-upgrade-table-row-hover-background-color); - } - } + &:hover:not([disabled]) { + background-color: var(--user-upgrade-button-hover-background-color); + box-shadow: 0px 2px 4px -1px rgba(0,0,0,0.2), 0px 4px 5px 0px rgba(0,0,0,0.14), 0px 1px 10px 0px rgba(0,0,0,0.12) + } + + &[disabled] { + background-color: grey; + cursor: default; + } + } + + table#feature-comparison { + width: 100%; + + th { + font-weight: bold; + } + + colgroup { + width: 10em; + } + + colgroup#basic { + background-color: var(--user-upgrade-basic-background-color); + } + + colgroup#gold { + background-color: var(--user-upgrade-gold-background-color); + } + + colgroup#platinum { + background-color: var(--user-upgrade-platinum-background-color); + } + + td, th { + text-align: center; + vertical-align: top; + padding: 0.5em 0; } } } diff --git a/app/models/user_upgrade.rb b/app/models/user_upgrade.rb index 5863d94a8..41aa69c6e 100644 --- a/app/models/user_upgrade.rb +++ b/app/models/user_upgrade.rb @@ -14,6 +14,14 @@ class UserUpgrade < ApplicationRecord complete: 20 } + def self.enabled? + stripe_secret_key.present? && stripe_publishable_key.present? && stripe_webhook_secret.present? + end + + def self.stripe_secret_key + Danbooru.config.stripe_secret_key + end + def self.stripe_publishable_key Danbooru.config.stripe_publishable_key end diff --git a/app/policies/user_upgrade_policy.rb b/app/policies/user_upgrade_policy.rb index 78365557f..a6568f5db 100644 --- a/app/policies/user_upgrade_policy.rb +++ b/app/policies/user_upgrade_policy.rb @@ -3,6 +3,10 @@ class UserUpgradePolicy < ApplicationPolicy user.is_member? end + def new? + UserUpgrade.enabled? + end + def show? record.recipient == user || record.purchaser == user || user.is_owner? end diff --git a/app/views/user_upgrades/new.html.erb b/app/views/user_upgrades/new.html.erb index 89d7ea4d6..b5d278fd9 100644 --- a/app/views/user_upgrades/new.html.erb +++ b/app/views/user_upgrades/new.html.erb @@ -6,116 +6,165 @@
-

Upgrade Account

- <% unless params[:user_id] %> -

Want more searching power? Upgrade your account and become a power user of the best database of anime artwork on the internet.

+ <% if @user_upgrade.is_gift? %> +

Gift Account Upgrade

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BasicGoldPlatinum
CostFree - <%= cents_to_usd(UserUpgrade.gold_price) %> -
One time fee
-
- <%= cents_to_usd(UserUpgrade.platinum_price) %> -
One time fee
-
Tag Limit2<%= Danbooru.config.base_tag_query_limit %><%= Danbooru.config.base_tag_query_limit*2 %>
Favorite Limit10,00020,000Unlimited
Favorite Groups3510
Page Limit1,0002,0005,000
Saved Searches2502501,000
See Hidden TagsNoYesYes
Search Timeout3 sec6 sec9 sec
-
+ <% if @user_upgrade.recipient.is_platinum? %> +

<%= link_to_user @recipient %> is already above Platinum level and can't be upgraded!

+ <% else %> +
You are gifting this upgrade to <%= link_to_user @user_upgrade.recipient %>.
+ <% end %> + <% else %> +

Upgrade Account

+ +

Upgrading your account gives you exclusive benefits and helps support + <%= Danbooru.config.canonical_app_name %>. Your support helps keep the + site ad-free for everyone!

+ +

You can also gift an account upgrade to someone else. Just go to + their profile page and look for a "Gift Upgrade" link.

<% end %> -
- <% if params[:user_id] %> -

You are gifting this account upgrade to <%= link_to user.pretty_name, user_path(params[:user_id]) %>.

- <% else %> -

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.

- <% end %> -
- - <% if Danbooru.config.stripe_publishable_key %> - <% if CurrentUser.is_anonymous? %> -

<%= link_to "Sign up", new_user_path %> or <%= link_to "login", login_path(url: new_user_upgrade_path) %> first to upgrade your account.

- <% elsif CurrentUser.safe_mode? %> -
-

You can pay with a credit or debit card. Safebooru uses Stripe - as a payment intermediary so none of your personal information will be stored on the site.

- - <% if user.level == User::Levels::MEMBER %> -

<%= button_to "Upgrade to Gold", user_upgrades_path(user_id: user.id, upgrade_type: "gold"), remote: true, disable_with: "Redirecting..." %>

-

<%= button_to "Upgrade to Platinum", user_upgrades_path(user_id: user.id, upgrade_type: "platinum"), remote: true, disable_with: "Redirecting..." %>

- <% elsif user.level == User::Levels::GOLD %> -

<%= button_to "Upgrade Gold to Platinum", user_upgrades_path(user_id: user.id, upgrade_type: "gold_to_platinum"), remote: true, disable_with: "Redirecting..." %>

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <% if @user_upgrade.purchaser.is_anonymous? %> + + + + <% elsif @recipient.level == User::Levels::MEMBER %> + + + + <% elsif @recipient.level == User::Levels::GOLD %> + + + + <% else %> + + + <% end %> - - <% else %> -
-

You can pay with a credit or debit card on - <%= link_to "Safebooru", new_user_upgrade_url(user_id: user.id, host: "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.

-
- <% end %> - <% end %> + + +
BasicGoldPlatinum
Free + <%= cents_to_usd(UserUpgrade.gold_price) %> +
One time fee
+
+ <%= cents_to_usd(UserUpgrade.platinum_price) %> +
One time fee
+
Tag Limit2<%= Danbooru.config.base_tag_query_limit %><%= Danbooru.config.base_tag_query_limit*2 %>
See Hidden TagsNoYesYes
Page Limit1,0002,0005,000
Favorite Limit10,00020,000Unlimited
Favorite Groups3510
Saved Searches2502501,000
Search Timeout3 sec6 sec9 sec
<%= link_to "Login", login_path(url: new_user_upgrade_path), class: "login-button" %><%= link_to "Get #{Danbooru.config.canonical_app_name} Gold", login_path(url: new_user_upgrade_path), class: "login-button" %><%= link_to "Get #{Danbooru.config.canonical_app_name} Platinum", login_path(url: new_user_upgrade_path), class: "login-button" %><%= button_to "Get #{Danbooru.config.canonical_app_name} Gold", user_upgrades_path(user_id: @recipient.id, upgrade_type: "gold"), remote: true, disable_with: "Redirecting..." %><%= button_to "Get #{Danbooru.config.canonical_app_name} Platinum", user_upgrades_path(user_id: @recipient.id, upgrade_type: "platinum"), remote: true, disable_with: "Redirecting..." %><%= button_to "Get #{Danbooru.config.canonical_app_name} Gold", nil, disabled: true %><%= button_to "Get #{Danbooru.config.canonical_app_name} Platinum", user_upgrades_path(user_id: @recipient.id, upgrade_type: "gold_to_platinum"), remote: true, disable_with: "Redirecting..." %><%= button_to "Get #{Danbooru.config.canonical_app_name} Gold", nil, disabled: true %><%= button_to "Get #{Danbooru.config.canonical_app_name} Platinum", nil, disabled: true %>
+ +

Frequently Asked Questions

+ +
+
+ What are the benefits of <%= Danbooru.config.canonical_app_name %> Gold? + +

<%= Danbooru.config.canonical_app_name %> Gold lets you do more + complicated searches, and it lets you see hidden tags that non-Gold users + can't see. You can search more tags at once, browser deeper in search + results, and also keep more favorites, favorite groups, and saved searches.

+
+ +
+ What are the benefits of <%= Danbooru.config.canonical_app_name %> Platinum? + +

Platinum is like Gold, but it lets you search even more tags at once, + and keep even more favorites, favorite groups, and saved searches.

+
+ +
+ What payment methods do you support? + +

We support all major credit and debit cards, including international + cards. Payments are securely handled by Stripe. + We don't support PayPal or Bitcoin at this time.

+
+ +
+ Is this a subscription? + +

No, this is not a subscription. This is a one-time payment. You pay + only once and keep the upgrade forever.

+
+ +
+ If I upgrade to Gold first, can I upgrade to Platinum later? + +

Yes, if you have a Gold account, you can always upgrade to a Platinum + account later. You don't have to pay full price to upgrade from Gold to + Platinum. You only have to pay the difference.

+
+ +
+ What is your refund policy? + +

You can <%= link_to "contact us", contact_path %> to request a refund + for any reason within 48 hours of your purchase.

+
+
diff --git a/app/views/users/_statistics.html.erb b/app/views/users/_statistics.html.erb index fe708c18c..581028cbd 100644 --- a/app/views/users/_statistics.html.erb +++ b/app/views/users/_statistics.html.erb @@ -75,8 +75,13 @@ Level <%= user.level_string %> - <% if CurrentUser.user == user && !CurrentUser.is_gold? %> - (<%= link_to "upgrade", new_user_upgrade_path %>) + + <% if !user.is_platinum? %> + <% if CurrentUser.user == user %> + (<%= link_to "Upgrade account", new_user_upgrade_path %>) + <% else %> + (<%= link_to "Gift upgrade", new_user_upgrade_path(user_id: user.id) %>) + <% end %> <% end %> diff --git a/test/functional/user_upgrades_controller_test.rb b/test/functional/user_upgrades_controller_test.rb index ba6240730..4f466c86e 100644 --- a/test/functional/user_upgrades_controller_test.rb +++ b/test/functional/user_upgrades_controller_test.rb @@ -3,20 +3,41 @@ require 'test_helper' class UserUpgradesControllerTest < ActionDispatch::IntegrationTest context "The user upgrades controller" do context "new action" do - should "render for a self upgrade" do + should "render for a self upgrade to Gold" do @user = create(:user) get_auth new_user_upgrade_path, @user assert_response :success end - should "render for a gift upgrade" do + should "render for a self upgrade to Platinum" do + @user = create(:gold_user) + get_auth new_user_upgrade_path, @user + + assert_response :success + end + + should "render for a gifted upgrade to Gold" do @recipient = create(:user) get_auth new_user_upgrade_path(user_id: @recipient.id), create(:user) assert_response :success end + should "render for a gifted upgrade to Platinum" do + @recipient = create(:gold_user) + get_auth new_user_upgrade_path(user_id: @recipient.id), create(:user) + + assert_response :success + end + + should "render for an invalid gifted upgrade to a user who is already Platinum" do + @recipient = create(:platinum_user) + get_auth new_user_upgrade_path(user_id: @recipient.id), create(:user) + + assert_response :success + end + should "render for an anonymous user" do get new_user_upgrade_path