feat: replace Iyzico with Stripe + single-page subscription stepper

Subscription/checkout flow rewritten end-to-end. The plan-card "Devam Et"
button silently wiped brand selection on re-click and the actual proceed
button lived offscreen — fixed by collapsing plan/brands/payment/confirm
into a single vertical stepper with one sticky CTA.

Backend
- Stripe Hosted Checkout (`/payments/stripe/checkout`) + webhook
  (`/payments/stripe/webhook`, raw body) replacing the stubbed Iyzico
  module. Webhook activates subscription on `checkout.session.completed`,
  expires the pending subscription on cancel/expire so users can retry.
- New `bank_accounts` table — multiple rows, single `is_active` enforced
  by a partial unique index. Admin CRUD under `/admin/bank-accounts`
  with multipart QR upload to MinIO; atomic `/activate` swap in a
  transaction; `GET /payments/bank-info` returns the active row.
- `payments` gains `stripe_session_id`, `stripe_payment_intent_id`,
  `bank_account_id`. EFT flow now reads the active bank account at
  payment time and stores the FK for reconciliation.
- Env: `IYZICO_*` removed, `STRIPE_*` added (validated by zod schema).
- `main.ts` `rawBody: true` for Stripe signature verification.
- Drizzle 0003 snapshot id collision fixed (VIEW-only migration shared
  prevId with 0002, blocking new generates).

Frontend
- `/dashboard/subscription` rewritten as a 4-step vertical stepper with
  step-aware sticky bottom CTA; plan re-selection is idempotent and
  preserves brand state. `/dashboard/subscription/pay` deleted; Stripe
  returns to the same page via `?stripe=success|cancelled` and the UI
  polls `/subscriptions/me` until the webhook activates the row.
- New components: `bank-transfer-card.tsx` (DB-driven IBAN + Kolay Adres
  + uploaded QR image + receipt upload) and `stripe-checkout-button.tsx`.
- Active subscription view, trial onboarding/urgency banner, downgrade
  and cancel dialogs preserved.
- TR/EN i18n: new `subscription.steps.*`, `subscription.stickyCta.*`,
  `payment.stripe.*`, `payment.bank.*`; provider label updated.

PostHog: `method: "iyzico"` → `"stripe"`; new events `iban_copied`,
`kolay_adres_copied`, `qr_viewed`, `eft_initiated`,
`stripe_redirect_returned`.

Deploy runs `db:migrate` which applies 0004_hot_quicksilver
(additive: new table + nullable columns; safe to apply on prod).
Operator must add `STRIPE_SECRET_KEY`, `STRIPE_PUBLISHABLE_KEY`,
`STRIPE_WEBHOOK_SECRET` to env and create the first
`bank_accounts` row via the admin endpoint before the bank tab works.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sase Dev
2026-05-13 22:42:28 +00:00
parent 0b6d4bb0a7
commit 6a0b36a7a0
31 changed files with 8756 additions and 4302 deletions

View File

@@ -162,6 +162,28 @@ export const userBrands = pgTable(
],
);
// ─── Bank Accounts (EFT/Havale destination accounts, one active at a time) ────
export const bankAccounts = pgTable(
"bank_accounts",
{
id: uuid("id").primaryKey().defaultRandom(),
bankName: varchar("bank_name", { length: 100 }).notNull(),
accountHolder: varchar("account_holder", { length: 200 }).notNull(),
iban: varchar("iban", { length: 34 }).notNull(),
kolayAdres: varchar("kolay_adres", { length: 100 }),
kolayAdresType: varchar("kolay_adres_type", { length: 20 }),
qrImageUrl: text("qr_image_url"),
descriptionTemplate: varchar("description_template", { length: 200 })
.notNull()
.default("SASE-{{paymentId}}"),
isActive: boolean("is_active").default(false).notNull(),
displayOrder: integer("display_order").default(0).notNull(),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
},
(table) => [index("bank_accounts_active_idx").on(table.isActive)],
);
// ─── Payments ───────────────────────────────────────
export const payments = pgTable(
"payments",
@@ -178,6 +200,9 @@ export const payments = pgTable(
method: varchar("method", { length: 20 }).notNull(),
status: varchar("status", { length: 20 }).default("pending").notNull(),
iyzicoPaymentId: text("iyzico_payment_id"),
stripeSessionId: text("stripe_session_id"),
stripePaymentIntentId: text("stripe_payment_intent_id"),
bankAccountId: uuid("bank_account_id").references(() => bankAccounts.id),
eftReceiptUrl: text("eft_receipt_url"),
adminNote: text("admin_note"),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
@@ -186,6 +211,7 @@ export const payments = pgTable(
(table) => [
index("payments_user_id_idx").on(table.userId),
index("payments_status_idx").on(table.status),
index("payments_stripe_session_id_idx").on(table.stripeSessionId),
],
);

View File

@@ -1,6 +1,7 @@
import { relations } from "drizzle-orm";
import {
accounts,
bankAccounts,
brands,
catalogVehicles,
categories,
@@ -75,6 +76,14 @@ export const paymentsRelations = relations(payments, ({ one }) => ({
fields: [payments.subscriptionId],
references: [userSubscriptions.id],
}),
bankAccount: one(bankAccounts, {
fields: [payments.bankAccountId],
references: [bankAccounts.id],
}),
}));
export const bankAccountsRelations = relations(bankAccounts, ({ many }) => ({
payments: many(payments),
}));
export const queryLogsRelations = relations(queryLogs, ({ one }) => ({