add some
Some checks failed
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled

This commit is contained in:
2026-09-19 04:47:43 +05:00
parent 6c7c402390
commit 599c12ef87
9 changed files with 68 additions and 25 deletions

View File

@@ -1,8 +1,15 @@
-- Reverse 20260918130000_add_payment_settings_and_visamaster_pay.up.sql
-- Reverse 20260918130000_add_payment_settings_and_visamaster_pay.up.sql,
-- in reverse order of that file's sections.
-- 4. visa_master_payment_logs
DROP TABLE IF EXISTS visa_master_payment_logs;
-- 3. visa_master_order_payments
DROP TABLE IF EXISTS visa_master_order_payments;
-- 2. visa_master_payment_orders.amount_usd
ALTER TABLE visa_master_payment_orders
DROP COLUMN IF EXISTS amount_usd;
-- 1. payment_settings
DROP TABLE IF EXISTS payment_settings;

View File

@@ -1,27 +1,12 @@
-- Adds the "Töleg" payment feature for Visa/Master/Sber money-transfer
-- orders:
-- 1. payment_settings is a single-row settings table for the admin-
-- configurable commission fees used on every payment. Visa/Master
-- 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 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.
-- orders. Each section below is a distinct, independently reversible piece
-- of that feature - see the matching comment in each section for why it's
-- shaped the way it is.
-- 1. Single-row, admin-configurable commission fees used on every payment.
-- Visa/Master 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.
CREATE TABLE IF NOT EXISTS payment_settings (
id smallint PRIMARY KEY DEFAULT 1,
bank_fee_tmt numeric(12, 2) NOT NULL DEFAULT 100,
@@ -39,9 +24,19 @@ INSERT INTO payment_settings (id, bank_fee_tmt, gbus_fee_tmt, sber_bank_fee_tmt,
VALUES (1, 100, 15, 100, 18)
ON CONFLICT (id) DO NOTHING;
-- 2. The requested USD amount for a visa/master/sber order (order data, set
-- when the order is created). visa_master_payment_orders already has `paid`.
ALTER TABLE visa_master_payment_orders
ADD COLUMN amount_usd numeric(18, 2);
ADD COLUMN IF NOT EXISTS amount_usd numeric(18, 2);
-- 3. Every payout attempt for an order, as its own row - 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. gateway_status/gateway_reference/gateway_response
-- track the GBÜS register→callback round trip (pending until the callback
-- verifies the outcome server-to-server).
CREATE TABLE IF NOT EXISTS visa_master_order_payments (
id bigserial PRIMARY KEY,
order_id bigint NOT NULL,
@@ -73,6 +68,12 @@ CREATE TABLE IF NOT EXISTS visa_master_order_payments (
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);
-- 4. 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 visa_master_payment_logs (
id bigserial PRIMARY KEY,
order_id bigint NOT NULL,