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
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class RenameStripeIdToTransactionIdOnUserUpgrades < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :user_upgrades, :payment_processor, :integer, null: false, default: 0
|
||||
rename_column :user_upgrades, :stripe_id, :transaction_id
|
||||
add_index :user_upgrades, :payment_processor
|
||||
end
|
||||
end
|
||||
@@ -2131,7 +2131,8 @@ CREATE TABLE public.user_upgrades (
|
||||
purchaser_id bigint NOT NULL,
|
||||
upgrade_type integer NOT NULL,
|
||||
status integer NOT NULL,
|
||||
stripe_id character varying
|
||||
transaction_id character varying,
|
||||
payment_processor integer DEFAULT 0 NOT NULL
|
||||
);
|
||||
|
||||
|
||||
@@ -4732,6 +4733,13 @@ CREATE INDEX index_user_sessions_on_session_id ON public.user_sessions USING btr
|
||||
CREATE INDEX index_user_sessions_on_updated_at ON public.user_sessions USING btree (updated_at);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_user_upgrades_on_payment_processor; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_user_upgrades_on_payment_processor ON public.user_upgrades USING btree (payment_processor);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_user_upgrades_on_purchaser_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@@ -4754,10 +4762,10 @@ CREATE INDEX index_user_upgrades_on_status ON public.user_upgrades USING btree (
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_user_upgrades_on_stripe_id; Type: INDEX; Schema: public; Owner: -
|
||||
-- Name: index_user_upgrades_on_transaction_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_user_upgrades_on_stripe_id ON public.user_upgrades USING btree (stripe_id);
|
||||
CREATE INDEX index_user_upgrades_on_transaction_id ON public.user_upgrades USING btree (transaction_id);
|
||||
|
||||
|
||||
--
|
||||
@@ -5823,6 +5831,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20220403220558'),
|
||||
('20220407203236'),
|
||||
('20220410050628'),
|
||||
('20220504235329');
|
||||
('20220504235329'),
|
||||
('20220514175125');
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ FactoryBot.define do
|
||||
purchaser { recipient }
|
||||
upgrade_type { "gold" }
|
||||
status { "pending" }
|
||||
stripe_id { nil }
|
||||
transaction_id { nil }
|
||||
|
||||
factory(:self_gold_upgrade) do
|
||||
upgrade_type { "gold" }
|
||||
|
||||
@@ -269,7 +269,7 @@ class UserUpgradesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal(@user, @user_upgrade.recipient)
|
||||
assert_equal("gold", @user_upgrade.upgrade_type)
|
||||
assert_equal("pending", @user_upgrade.status)
|
||||
assert_not_nil(@user_upgrade.stripe_id)
|
||||
assert_not_nil(@user_upgrade.transaction_id)
|
||||
assert_match(/redirectToCheckout/, response.body)
|
||||
end
|
||||
end
|
||||
@@ -286,7 +286,7 @@ class UserUpgradesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal(@user, @user_upgrade.recipient)
|
||||
assert_equal("platinum", @user_upgrade.upgrade_type)
|
||||
assert_equal("pending", @user_upgrade.status)
|
||||
assert_not_nil(@user_upgrade.stripe_id)
|
||||
assert_not_nil(@user_upgrade.transaction_id)
|
||||
assert_match(/redirectToCheckout/, response.body)
|
||||
end
|
||||
end
|
||||
@@ -303,7 +303,7 @@ class UserUpgradesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal(@user, @user_upgrade.recipient)
|
||||
assert_equal("gold_to_platinum", @user_upgrade.upgrade_type)
|
||||
assert_equal("pending", @user_upgrade.status)
|
||||
assert_not_nil(@user_upgrade.stripe_id)
|
||||
assert_not_nil(@user_upgrade.transaction_id)
|
||||
assert_match(/redirectToCheckout/, response.body)
|
||||
end
|
||||
end
|
||||
@@ -323,7 +323,7 @@ class UserUpgradesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal(@recipient, @user_upgrade.recipient)
|
||||
assert_equal("gold", @user_upgrade.upgrade_type)
|
||||
assert_equal("pending", @user_upgrade.status)
|
||||
assert_not_nil(@user_upgrade.stripe_id)
|
||||
assert_not_nil(@user_upgrade.transaction_id)
|
||||
assert_match(/redirectToCheckout/, response.body)
|
||||
end
|
||||
end
|
||||
@@ -341,7 +341,7 @@ class UserUpgradesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal(@recipient, @user_upgrade.recipient)
|
||||
assert_equal("platinum", @user_upgrade.upgrade_type)
|
||||
assert_equal("pending", @user_upgrade.status)
|
||||
assert_not_nil(@user_upgrade.stripe_id)
|
||||
assert_not_nil(@user_upgrade.transaction_id)
|
||||
assert_match(/redirectToCheckout/, response.body)
|
||||
end
|
||||
end
|
||||
@@ -359,7 +359,7 @@ class UserUpgradesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal(@recipient, @user_upgrade.recipient)
|
||||
assert_equal("gold_to_platinum", @user_upgrade.upgrade_type)
|
||||
assert_equal("pending", @user_upgrade.status)
|
||||
assert_not_nil(@user_upgrade.stripe_id)
|
||||
assert_not_nil(@user_upgrade.transaction_id)
|
||||
assert_match(/redirectToCheckout/, response.body)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user