upgrades: rename stripe_id to transaction_id
* Rename the stripe_id column to transaction_id. * Add a new payment_processor column to identity the processor used for this transaction (and hence, which backend system the transaction_id is for).
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
# @see app/logical/payment_transaction/stripe.rb
|
||||
class PaymentTransaction
|
||||
attr_reader :user_upgrade
|
||||
delegate :recipient, :purchaser, :upgrade_type, :pending?, :stripe_id, to: :user_upgrade
|
||||
delegate :recipient, :purchaser, :upgrade_type, :pending?, :transaction_id, to: :user_upgrade
|
||||
|
||||
def initialize(user_upgrade)
|
||||
@user_upgrade = user_upgrade
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PaymentTransaction::Stripe < PaymentTransaction
|
||||
delegate :stripe_id, to: :user_upgrade
|
||||
delegate :transaction_id, to: :user_upgrade
|
||||
|
||||
def self.enabled?
|
||||
Danbooru.config.stripe_secret_key.present? && Danbooru.config.stripe_publishable_key.present? && Danbooru.config.stripe_webhook_secret.present?
|
||||
@@ -36,7 +36,7 @@ class PaymentTransaction::Stripe < PaymentTransaction
|
||||
}
|
||||
)
|
||||
|
||||
user_upgrade.update!(stripe_id: checkout_session.id)
|
||||
user_upgrade.update!(payment_processor: :stripe, transaction_id: checkout_session.id)
|
||||
checkout_session
|
||||
end
|
||||
|
||||
@@ -100,12 +100,12 @@ class PaymentTransaction::Stripe < PaymentTransaction
|
||||
end
|
||||
|
||||
def receipt_url
|
||||
return nil if pending? || stripe_id.nil?
|
||||
return nil if pending? || transaction_id.nil?
|
||||
charge.receipt_url
|
||||
end
|
||||
|
||||
def payment_url
|
||||
return nil if pending? || stripe_id.nil?
|
||||
return nil if pending? || transaction_id.nil?
|
||||
"https://dashboard.stripe.com/payments/#{payment_intent.id}"
|
||||
end
|
||||
|
||||
@@ -118,8 +118,8 @@ class PaymentTransaction::Stripe < PaymentTransaction
|
||||
end
|
||||
|
||||
private def checkout_session
|
||||
return nil if stripe_id.nil?
|
||||
@checkout_session ||= ::Stripe::Checkout::Session.retrieve(stripe_id)
|
||||
return nil if transaction_id.nil?
|
||||
@checkout_session ||= ::Stripe::Checkout::Session.retrieve(transaction_id)
|
||||
end
|
||||
|
||||
private def payment_intent
|
||||
|
||||
@@ -19,6 +19,10 @@ class UserUpgrade < ApplicationRecord
|
||||
refunded: 30,
|
||||
}
|
||||
|
||||
enum payment_processor: {
|
||||
stripe: 0,
|
||||
}
|
||||
|
||||
scope :gifted, -> { where("recipient_id != purchaser_id") }
|
||||
scope :self_upgrade, -> { where("recipient_id = purchaser_id") }
|
||||
|
||||
@@ -85,7 +89,7 @@ class UserUpgrade < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :upgrade_type, :status, :stripe_id, :recipient, :purchaser)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :upgrade_type, :status, :transaction_id, :payment_processor, :recipient, :purchaser)
|
||||
|
||||
if params[:is_gifted].to_s.truthy?
|
||||
q = q.gifted
|
||||
|
||||
Reference in New Issue
Block a user