add pay
This commit is contained in:
@@ -1,18 +1,8 @@
|
||||
-- Reverse 20260918130000_add_payment_settings_and_visamaster_pay.up.sql
|
||||
DROP TABLE IF EXISTS visa_master_payment_logs;
|
||||
DROP TABLE IF EXISTS visa_master_order_payments;
|
||||
|
||||
ALTER TABLE visa_master_payment_orders
|
||||
DROP COLUMN IF EXISTS amount_usd,
|
||||
DROP COLUMN IF EXISTS exchange_rate,
|
||||
DROP COLUMN IF EXISTS exchange_rate_rub,
|
||||
DROP COLUMN IF EXISTS amount_tmt,
|
||||
DROP COLUMN IF EXISTS bank_fee_tmt,
|
||||
DROP COLUMN IF EXISTS gbus_fee_tmt,
|
||||
DROP COLUMN IF EXISTS tveb_fee_usd,
|
||||
DROP COLUMN IF EXISTS tveb_fee_tmt,
|
||||
DROP COLUMN IF EXISTS total_amount_tmt,
|
||||
DROP COLUMN IF EXISTS payment_period,
|
||||
DROP COLUMN IF EXISTS gateway_status,
|
||||
DROP COLUMN IF EXISTS gateway_reference,
|
||||
DROP COLUMN IF EXISTS gateway_response,
|
||||
DROP COLUMN IF EXISTS paid_at;
|
||||
DROP COLUMN IF EXISTS amount_usd;
|
||||
|
||||
DROP TABLE IF EXISTS payment_settings;
|
||||
|
||||
@@ -5,11 +5,22 @@
|
||||
-- orders use bank_fee_tmt + gbus_fee_tmt; Sber orders use their own
|
||||
-- sber_bank_fee_tmt plus a USD-denominated tveb_fee_usd (converted to
|
||||
-- TMT at payout time via the USD rate) - Sber has no GBÜS fee.
|
||||
-- 2. visa_master_payment_orders gains the requested USD amount plus the
|
||||
-- payout columns (rate(s), TMT amount, fees, total, gateway result)
|
||||
-- filled in once the order is paid out. The Sber-specific columns
|
||||
-- (exchange_rate_rub, tveb_fee_usd, tveb_fee_tmt) stay null for
|
||||
-- non-Sber orders, same as gbus_fee_tmt stays null for Sber ones.
|
||||
-- 2. visa_master_payment_orders gains only the requested USD amount
|
||||
-- (order data, set when the order is created). It already has `paid`.
|
||||
-- 3. visa_master_order_payments records every payout attempt for an
|
||||
-- order as its own row - kept as a full audit trail (including failed
|
||||
-- gateway attempts) rather than columns on the order itself, so a
|
||||
-- retry after a failure doesn't erase what the previous attempt did.
|
||||
-- The Sber-specific columns (exchange_rate_rub, tveb_fee_usd,
|
||||
-- tveb_fee_tmt) stay null for non-Sber attempts, same as
|
||||
-- gbus_fee_tmt stays null for Sber ones.
|
||||
-- 4. visa_master_payment_logs records every individual step taken while
|
||||
-- processing a payout (validated, rate fetched, gateway request sent,
|
||||
-- gateway response received, order marked paid/attempt recorded) as
|
||||
-- its own row, so there's a step-by-step, timestamped record of what
|
||||
-- actually happened for a given order - evidence if a payout is later
|
||||
-- disputed, independent of (and more granular than) the one summary
|
||||
-- row in visa_master_order_payments.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS payment_settings (
|
||||
id smallint PRIMARY KEY DEFAULT 1,
|
||||
@@ -29,17 +40,50 @@ VALUES (1, 100, 15, 100, 18)
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
|
||||
ALTER TABLE visa_master_payment_orders
|
||||
ADD COLUMN amount_usd numeric(18, 2),
|
||||
ADD COLUMN exchange_rate numeric(18, 8),
|
||||
ADD COLUMN exchange_rate_rub numeric(18, 8),
|
||||
ADD COLUMN amount_tmt numeric(18, 2),
|
||||
ADD COLUMN bank_fee_tmt numeric(12, 2),
|
||||
ADD COLUMN gbus_fee_tmt numeric(12, 2),
|
||||
ADD COLUMN tveb_fee_usd numeric(12, 2),
|
||||
ADD COLUMN tveb_fee_tmt numeric(12, 2),
|
||||
ADD COLUMN total_amount_tmt numeric(18, 2),
|
||||
ADD COLUMN payment_period date,
|
||||
ADD COLUMN gateway_status character varying(32) NOT NULL DEFAULT 'pending',
|
||||
ADD COLUMN gateway_reference character varying(255),
|
||||
ADD COLUMN gateway_response jsonb,
|
||||
ADD COLUMN paid_at TIMESTAMP;
|
||||
ADD COLUMN amount_usd numeric(18, 2);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS visa_master_order_payments (
|
||||
id bigserial PRIMARY KEY,
|
||||
order_id bigint NOT NULL,
|
||||
user_id bigint NOT NULL,
|
||||
payment_period date NOT NULL,
|
||||
exchange_rate_usd numeric(18, 8) NOT NULL,
|
||||
exchange_rate_rub numeric(18, 8),
|
||||
amount_tmt numeric(18, 2) NOT NULL,
|
||||
bank_fee_tmt numeric(12, 2) NOT NULL,
|
||||
gbus_fee_tmt numeric(12, 2),
|
||||
tveb_fee_usd numeric(12, 2),
|
||||
tveb_fee_tmt numeric(12, 2),
|
||||
total_amount_tmt numeric(18, 2) NOT NULL,
|
||||
gateway_status character varying(32) NOT NULL DEFAULT 'pending',
|
||||
gateway_reference character varying(255),
|
||||
gateway_response jsonb,
|
||||
created_by bigint,
|
||||
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
|
||||
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
|
||||
deleted_at TIMESTAMPTZ,
|
||||
CONSTRAINT visa_master_order_payments_order_id_fkey
|
||||
FOREIGN KEY (order_id) REFERENCES visa_master_payment_orders(id),
|
||||
CONSTRAINT visa_master_order_payments_user_id_fkey
|
||||
FOREIGN KEY (user_id) REFERENCES users(id),
|
||||
CONSTRAINT visa_master_order_payments_created_by_fkey
|
||||
FOREIGN KEY (created_by) REFERENCES users(id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS visa_master_order_payments_order_id_idx ON visa_master_order_payments (order_id);
|
||||
CREATE INDEX IF NOT EXISTS visa_master_order_payments_user_id_idx ON visa_master_order_payments (user_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS visa_master_payment_logs (
|
||||
id bigserial PRIMARY KEY,
|
||||
order_id bigint NOT NULL,
|
||||
step character varying(100) NOT NULL,
|
||||
detail jsonb,
|
||||
created_by bigint,
|
||||
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
|
||||
CONSTRAINT visa_master_payment_logs_order_id_fkey
|
||||
FOREIGN KEY (order_id) REFERENCES visa_master_payment_orders(id),
|
||||
CONSTRAINT visa_master_payment_logs_created_by_fkey
|
||||
FOREIGN KEY (created_by) REFERENCES users(id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS visa_master_payment_logs_order_id_idx ON visa_master_payment_logs (order_id);
|
||||
|
||||
Reference in New Issue
Block a user