|
@@ -28,6 +28,7 @@ import {
|
|
|
} from '@/integrations/payments/catalog'
|
|
} from '@/integrations/payments/catalog'
|
|
|
import { db } from '@/lib/db'
|
|
import { db } from '@/lib/db'
|
|
|
import { type PaymentProvider, buildPaymentProvider } from '@/lib/payment-providers'
|
|
import { type PaymentProvider, buildPaymentProvider } from '@/lib/payment-providers'
|
|
|
|
|
+import { isUniqueViolation, writeAdoptionMarker } from './adoption-marker'
|
|
|
import { openCredentials, sealCredentials } from './vault'
|
|
import { openCredentials, sealCredentials } from './vault'
|
|
|
|
|
|
|
|
export { PAYMENT_CONNECTOR_IDS, isPaymentConnector }
|
|
export { PAYMENT_CONNECTOR_IDS, isPaymentConnector }
|
|
@@ -78,11 +79,7 @@ function inVendorOrder<T extends { connectorId: string }>(setups: T[]): T[] {
|
|
|
|
|
|
|
|
/** Record that the connections table decides online payments from now on. */
|
|
/** Record that the connections table decides online payments from now on. */
|
|
|
export async function markPaymentsAdopted(organizationId: string, userId: string): Promise<void> {
|
|
export async function markPaymentsAdopted(organizationId: string, userId: string): Promise<void> {
|
|
|
- await db.appSetting.upsert({
|
|
|
|
|
- where: { organizationId_key: { organizationId, key: PAYMENTS_ADOPTED_KEY } },
|
|
|
|
|
- create: { organizationId, userId, key: PAYMENTS_ADOPTED_KEY, value: new Date().toISOString() },
|
|
|
|
|
- update: {},
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ await writeAdoptionMarker(organizationId, PAYMENTS_ADOPTED_KEY, userId)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export interface LegacyPaymentSetup {
|
|
export interface LegacyPaymentSetup {
|
|
@@ -145,11 +142,6 @@ export async function legacyPaymentSetups(
|
|
|
return { setups, adopted }
|
|
return { setups, adopted }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/** Prisma's code for a unique constraint the row already satisfies. */
|
|
|
|
|
-function isUniqueViolation(err: unknown): boolean {
|
|
|
|
|
- return typeof err === 'object' && err !== null && (err as { code?: string }).code === 'P2002'
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
/** What the connection page shows as the account, for a setup that never went through identify. */
|
|
/** What the connection page shows as the account, for a setup that never went through identify. */
|
|
|
function accountNameOf(setup: LegacyPaymentSetup): string | null {
|
|
function accountNameOf(setup: LegacyPaymentSetup): string | null {
|
|
|
const msn = setup.credentials.merchantSerialNumber
|
|
const msn = setup.credentials.merchantSerialNumber
|