add payment settting
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 02:12:59 +05:00
parent 0971158e98
commit b8455625b5
21 changed files with 1760 additions and 12 deletions

View File

@@ -0,0 +1,18 @@
-- Reverse 20260918130000_add_payment_settings_and_visamaster_pay.up.sql
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 TABLE IF EXISTS payment_settings;

View File

@@ -0,0 +1,45 @@
-- 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 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.
CREATE TABLE IF NOT EXISTS payment_settings (
id smallint PRIMARY KEY DEFAULT 1,
bank_fee_tmt numeric(12, 2) NOT NULL DEFAULT 100,
gbus_fee_tmt numeric(12, 2) NOT NULL DEFAULT 15,
sber_bank_fee_tmt numeric(12, 2) NOT NULL DEFAULT 100,
tveb_fee_usd numeric(12, 2) NOT NULL DEFAULT 18,
updated_by bigint,
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
CONSTRAINT payment_settings_single_row CHECK (id = 1),
CONSTRAINT payment_settings_updated_by_fkey
FOREIGN KEY (updated_by) REFERENCES users(id)
);
INSERT INTO payment_settings (id, bank_fee_tmt, gbus_fee_tmt, sber_bank_fee_tmt, tveb_fee_usd)
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;