upgrades: add authorize.net integration.

Add integration for accepting payments with Authorize.net.

https://developer.authorize.net/hello_world.html
This commit is contained in:
evazion
2022-05-15 00:39:31 -05:00
parent 4b65e96abc
commit 1eb15da7c5
11 changed files with 340 additions and 17 deletions

View File

@@ -1,2 +1,15 @@
var stripe = Stripe("<%= j Danbooru.config.stripe_publishable_key %>");
stripe.redirectToCheckout({ sessionId: "<%= j @checkout.id %>" });
<% if @user_upgrade.stripe? %>
var stripe = Stripe("<%= j Danbooru.config.stripe_publishable_key %>");
stripe.redirectToCheckout({ sessionId: "<%= j @checkout.id %>" });
<% elsif @user_upgrade.authorize_net? %>
$(function() {
var url = "<%= j @checkout[0] %>";
var token = "<%= j @checkout[1] %>";
var $form = $('<form method="POST">').attr("action", url)
var $input = $('<input type="hidden" name="token">').val(token);
$form.append($input).appendTo("body").submit();
});
<% else %>
<% raise NotImplementedError, "payment method not implemented" %>
<% end %>

View File

@@ -56,7 +56,7 @@
<% if Danbooru.config.is_promotion? %>
<s>$20</s>
<% end %>
<b><%= cents_to_usd(UserUpgrade.gold_price) %></b>
<b><%= number_to_currency(UserUpgrade.gold_price) %></b>
<div class="fineprint">One time fee</div>
</td>
</tr>
@@ -110,7 +110,7 @@
<% if @user_upgrade.purchaser.is_anonymous? %>
<%= link_to "Get #{Danbooru.config.canonical_app_name} Gold", new_user_path(url: new_user_upgrade_path), class: "button-primary" %>
<% elsif @user_upgrade.recipient.level <= User::Levels::MEMBER %>
<%= button_to "Get #{Danbooru.config.canonical_app_name} Gold", user_upgrades_path(user_id: @recipient.id, upgrade_type: "gold", country: params[:country], promo: params[:promo]), class: "button-primary", remote: true, disable_with: "Redirecting..." %>
<%= button_to "Get #{Danbooru.config.canonical_app_name} Gold", user_upgrades_path(user_id: @recipient.id, upgrade_type: "gold", country: params[:country], promo: params[:promo], payment_processor: "authorize_net"), class: "button-primary", remote: true, disable_with: "Redirecting..." %>
<% else %>
<%= button_to "Get #{Danbooru.config.canonical_app_name} Gold", user_upgrades_path(user_id: @recipient.id), class: "button-primary", disabled: true %>
<% end %>

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 #{cents_to_usd(UserUpgrade.gold_price)}!", new_user_upgrade_path, id: "goto-upgrade-account" %></h2>
<h2><%= link_to "Upgrade your account for only #{number_to_currency(UserUpgrade.gold_price)}!", new_user_upgrade_path, id: "goto-upgrade-account" %></h2>
<div><%= link_to "No thanks", "#", id: "hide-upgrade-account-notice" %></div>
</div>