user upgrades: add UserUpgrade model.
Add a model to store the status of user upgrades. * Store the upgrade purchaser and the upgrade receiver (these are different for a gifted upgrade, the same for a self upgrade). * Store the upgrade type: gold, platinum, or gold-to-platinum upgrades. * Store the upgrade status: ** pending: User is still on the Stripe checkout page, no payment received yet. ** processing: User has completed checkout, but the checkout status in Stripe is still 'unpaid'. ** complete: We've received notification from Stripe that the payment has gone through and the user has been upgraded. * Store the Stripe checkout ID, to cross-reference the upgrade record on Danbooru with the checkout record on Stripe. This is the upgrade flow: * When the user clicks the upgrade button on the upgrade page, we call POST /user_upgrades and create a pending UserUpgrade. * We redirect the user to the checkout page on Stripe. * When the user completes checkout on Stripe, Stripe sends us a webhook notification at POST /webhooks/receive. * When we receive the webhook, we check the payment status, and if it's paid we mark the UserUpgrade as complete and upgrade the user. * After Stripe sees that we have successfully processed the webhook, they redirect the user to the /user_upgrades/:id page, where we show the user their upgrade receipt.
This commit is contained in:
@@ -101,11 +101,11 @@
|
||||
<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 %>
|
||||
<p><%= button_to "Upgrade to Gold", user_upgrade_path(user_id: user.id, level: User::Levels::GOLD), remote: true, disable_with: "Redirecting..." %></p>
|
||||
<p><%= button_to "Upgrade to Platinum", user_upgrade_path(user_id: user.id, level: User::Levels::PLATINUM), remote: true, disable_with: "Redirecting..." %></p>
|
||||
<% elsif user.level < User::Levels::PLATINUM %>
|
||||
<p><%= button_to "Upgrade Gold to Platinum", user_upgrade_path(user_id: user.id, level: User::Levels::PLATINUM), remote: true, disable_with: "Redirecting..." %></p>
|
||||
<% if user.level == User::Levels::MEMBER %>
|
||||
<p><%= button_to "Upgrade to Gold", user_upgrades_path(user_id: user.id, upgrade_type: "gold"), remote: true, disable_with: "Redirecting..." %></p>
|
||||
<p><%= button_to "Upgrade to Platinum", user_upgrades_path(user_id: user.id, upgrade_type: "platinum"), remote: true, disable_with: "Redirecting..." %></p>
|
||||
<% elsif user.level == User::Levels::GOLD %>
|
||||
<p><%= button_to "Upgrade Gold to Platinum", user_upgrades_path(user_id: user.id, upgrade_type: "gold_to_platinum"), remote: true, disable_with: "Redirecting..." %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
<% else %>
|
||||
|
||||
@@ -1,22 +1,47 @@
|
||||
<% page_title "Account Upgraded" %>
|
||||
<% page_title "User Upgrade Status" %>
|
||||
<%= render "users/secondary_links" %>
|
||||
|
||||
<div id="c-user-upgrades">
|
||||
<div id="a-show">
|
||||
<% if flash[:success] %>
|
||||
<h1>Congratulations!</h1>
|
||||
<h1>User Upgrade</h1>
|
||||
|
||||
<% if user != CurrentUser.user %>
|
||||
<p><%= user.name %> is now a <%= user.level_string %> user. Thanks for supporting the site!</p>
|
||||
<p>
|
||||
<ul>
|
||||
<li>
|
||||
<strong>Purchased</strong>
|
||||
<%= time_ago_in_words_tagged @user_upgrade.updated_at %>
|
||||
by <%= link_to_user @user_upgrade.purchaser %>
|
||||
<% if @user_upgrade.is_gift? %>
|
||||
for <%= link_to_user @user_upgrade.recipient %>
|
||||
<% end %>
|
||||
</li>
|
||||
<li>
|
||||
<strong>Upgrade Type</strong>
|
||||
<%= @user_upgrade.upgrade_type.humanize %>
|
||||
</li>
|
||||
<li>
|
||||
<strong>Status</strong>
|
||||
<%= @user_upgrade.status.humanize %>
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<% if @user_upgrade.status == "complete" %>
|
||||
<% if @user_upgrade.is_gift? && CurrentUser.user == @user_upgrade.recipient %>
|
||||
<p><%= link_to_user @user_upgrade.purchaser %> has upgraded your account to <%= @user_upgrade.level_string %>. Enjoy your new account!</p>
|
||||
<% elsif @user_upgrade.is_gift? && CurrentUser.user == @user_upgrade.purchaser %>
|
||||
<p><%= link_to_user @user_upgrade.recipient %> is now a <%= @user_upgrade.level_string %> user. Thanks for supporting the site!</p>
|
||||
<% else %>
|
||||
<p>You are now a <%= user.level_string %> user. Thanks for supporting the site!</p>
|
||||
<p>You are now a <%= @user_upgrade.level_string %> user. Thanks for supporting the site!</p>
|
||||
<% end %>
|
||||
|
||||
<p><%= link_to "Go back to #{Danbooru.config.canonical_app_name}", "https://danbooru.donmai.us" %> to start using your new account.</p>
|
||||
<% elsif flash[:error] %>
|
||||
<h1>An error occurred!</h1>
|
||||
<p><%= flash[:error] %></p>
|
||||
<p><%= link_to "Try again", new_user_upgrade_path %></p>
|
||||
<p><%= link_to "Go back to #{Danbooru.config.canonical_app_name}", "https://danbooru.donmai.us" %> to continue using the site.</p>
|
||||
<% else %>
|
||||
<%= content_for :html_header do %>
|
||||
<meta http-equiv="refresh" content="5">
|
||||
<% end %>
|
||||
|
||||
<p>This order is still being processed. You will be notified as soon as the order is complete.</p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user