feat: centralized payment gateways + booking widget API
Backend:
- Migration 065: hotel_payment_gateways table (migrates YooKassa from deposit_settings)
- online_bookings table for widget submissions
- Routes: CRUD /api/hotels/:slug/payment-gateways
- Public widget API: /api/widget/:slug/{config,availability,bookings}
- yookassa.ts: add createCharge() for immediate capture
Frontend:
- PaymentSettingsPage: add 'Онлайн-оплата' section with gateway CRUD and module toggles
- DepositSettingsPage: replace YooKassa fields with link to centralized settings
- BookingWidgetPage: connect to real API, show gateway status, real booking submit
- api.ts: add PaymentGateway types, paymentGateways and widget API methods
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
52
backend/migrations/065_payment_gateways.sql
Normal file
52
backend/migrations/065_payment_gateways.sql
Normal file
@@ -0,0 +1,52 @@
|
||||
-- Centralized payment gateways (replaces per-module YooKassa config)
|
||||
CREATE TABLE IF NOT EXISTS hotel_payment_gateways (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
hotel_id UUID NOT NULL REFERENCES hotels(id) ON DELETE CASCADE,
|
||||
provider TEXT NOT NULL DEFAULT 'yookassa', -- yookassa | stripe | tinkoff
|
||||
label TEXT NOT NULL DEFAULT 'ЮКасса',
|
||||
shop_id TEXT,
|
||||
secret_key TEXT,
|
||||
currency TEXT NOT NULL DEFAULT 'RUB',
|
||||
is_active BOOLEAN NOT NULL DEFAULT true,
|
||||
-- Which modules use this gateway (JSON array)
|
||||
modules JSONB NOT NULL DEFAULT '["deposit","booking-widget","room-service"]'::jsonb,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Migrate existing YooKassa credentials from hotel_deposit_settings
|
||||
INSERT INTO hotel_payment_gateways (hotel_id, provider, label, shop_id, secret_key, currency, modules)
|
||||
SELECT
|
||||
hotel_id,
|
||||
'yookassa',
|
||||
'ЮКасса',
|
||||
yookassa_shop_id,
|
||||
yookassa_secret_key,
|
||||
'RUB',
|
||||
'["deposit","booking-widget","room-service"]'::jsonb
|
||||
FROM hotel_deposit_settings
|
||||
WHERE yookassa_shop_id IS NOT NULL
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
-- Online bookings table (from widget)
|
||||
CREATE TABLE IF NOT EXISTS online_bookings (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
hotel_id UUID NOT NULL REFERENCES hotels(id) ON DELETE CASCADE,
|
||||
room_id UUID REFERENCES rooms(id) ON DELETE SET NULL,
|
||||
guest_name TEXT NOT NULL,
|
||||
guest_email TEXT,
|
||||
guest_phone TEXT,
|
||||
check_in DATE NOT NULL,
|
||||
check_out DATE NOT NULL,
|
||||
adults INTEGER NOT NULL DEFAULT 1,
|
||||
children INTEGER NOT NULL DEFAULT 0,
|
||||
total_amount NUMERIC(12,2) NOT NULL DEFAULT 0,
|
||||
notes TEXT,
|
||||
services JSONB DEFAULT '[]'::jsonb,
|
||||
status TEXT NOT NULL DEFAULT 'pending', -- pending | paid | confirmed | cancelled
|
||||
payment_method TEXT DEFAULT 'none', -- none | yookassa
|
||||
yookassa_payment_id TEXT,
|
||||
yookassa_confirmation_url TEXT,
|
||||
yookassa_status TEXT,
|
||||
booking_id UUID REFERENCES bookings(id) ON DELETE SET NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
Reference in New Issue
Block a user