user upgrades: add upgrade code system.

Add a system for upgrading accounts using upgrade codes. Users purchase
an upgrade code off-site then redeem it on-site to upgrade their account
to Gold. Upgrade codes are randomly pre-generated and are one time use
only. Codes have enough randomness that guessing a code is infeasible.
This commit is contained in:
evazion
2022-05-25 17:28:39 -05:00
parent 7786fbaca6
commit 173e43b192
22 changed files with 461 additions and 22 deletions

View File

@@ -22,6 +22,8 @@ class UserUpgrade < ApplicationRecord
enum payment_processor: {
stripe: 0,
authorize_net: 100,
shopify: 200,
upgrade_code: 300,
}
scope :gifted, -> { where("recipient_id != purchaser_id") }
@@ -113,7 +115,7 @@ class UserUpgrade < ApplicationRecord
end
concerning :UpgradeMethods do
def process_upgrade!(payment_status)
def process_upgrade!(payment_status = "paid")
recipient.with_lock do
return unless pending? || processing?
@@ -174,6 +176,8 @@ class UserUpgrade < ApplicationRecord
PaymentTransaction::Stripe.new(self)
in "authorize_net"
PaymentTransaction::AuthorizeNet.new(self)
in "shopify"
PaymentTransaction::Shopify.new(self)
end
end