import { AppError } from '../common/errors/app-error'; import { Prisma } from '../generated/prisma/client'; export const activePartnerPayments = ( organizationId: string, orderId: string, ) => ({ organizationId, orderId, reversal: { is: null }, }); export function partnerPaymentBalance(total: string, paid: string) { const outstanding = new Prisma.Decimal(total).sub(paid); if (outstanding.isNegative()) throw new AppError('B2B_PAYMENT_BALANCE_INVALID'); return { paidTotal: new Prisma.Decimal(paid).toFixed(2), outstandingTotal: outstanding.toFixed(2), }; } export function assertPartnerPaymentFits( total: string, paid: string, amount: string, ) { if (new Prisma.Decimal(paid).add(amount).greaterThan(total)) throw new AppError('B2B_PAYMENT_AMOUNT_LIMIT'); }