Files
danbooru/app/controllers/user_upgrades_controller.rb
evazion ecd29c1a66 user upgrades: allow using promo codes during checkout.
Allow promo codes to be used during checkout if a secret promo=true url
param is passed. Allows promo codes to be offered without having the
promo code option always appear even when there aren't any active promos.
2021-01-01 04:24:24 -06:00

60 lines
1.6 KiB
Ruby

class UserUpgradesController < ApplicationController
respond_to :js, :html, :json, :xml
def create
@user_upgrade = authorize UserUpgrade.create(recipient: recipient, purchaser: CurrentUser.user, status: "pending", upgrade_type: params[:upgrade_type])
@country = params[:country] || CurrentUser.country || "US"
@allow_promotion_codes = params[:promo].to_s.truthy?
@checkout = @user_upgrade.create_checkout!(country: @country, allow_promotion_codes: @allow_promotion_codes)
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 index
@user_upgrades = authorize UserUpgrade.visible(CurrentUser.user).paginated_search(params, count_pages: true)
@user_upgrades = @user_upgrades.includes(:recipient, :purchaser) if request.format.html?
respond_with(@user_upgrades)
end
def show
@user_upgrade = authorize UserUpgrade.find(params[:id])
respond_with(@user_upgrade)
end
def refund
@user_upgrade = authorize UserUpgrade.find(params[:id])
@user_upgrade.refund!
flash[:notice] = "Upgrade refunded"
respond_with(@user_upgrade)
end
def receipt
@user_upgrade = authorize UserUpgrade.find(params[:id])
redirect_to @user_upgrade.receipt_url
end
def payment
@user_upgrade = authorize UserUpgrade.find(params[:id])
redirect_to @user_upgrade.payment_url
end
private
def recipient
if params[:user_id]
User.find(params[:user_id])
else
CurrentUser.user
end
end
end