Expose gateway tracking fields on order transactions.
Include authority, track id, masked card, and paid-at from gateway meta for support and reconciliation. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
0a330b8749
commit
0d9e866a57
@@ -29,6 +29,9 @@ import {
|
|||||||
} from './dto/order.dto';
|
} from './dto/order.dto';
|
||||||
import { ShippingAddressDto } from '../cart/dto/cart.dto';
|
import { ShippingAddressDto } from '../cart/dto/cart.dto';
|
||||||
|
|
||||||
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||||
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||||
|
}
|
||||||
type OrderWithItems = Prisma.OrderGetPayload<{
|
type OrderWithItems = Prisma.OrderGetPayload<{
|
||||||
include: typeof ORDER_RELATIONS_INCLUDE;
|
include: typeof ORDER_RELATIONS_INCLUDE;
|
||||||
}>;
|
}>;
|
||||||
@@ -910,6 +913,18 @@ export class OrdersService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private serializeTransaction(transaction: Transaction) {
|
private serializeTransaction(transaction: Transaction) {
|
||||||
|
const meta = isRecord(transaction.gatewayMeta)
|
||||||
|
? transaction.gatewayMeta
|
||||||
|
: null;
|
||||||
|
const verify = meta && isRecord(meta.verify) ? meta.verify : null;
|
||||||
|
const cardPan =
|
||||||
|
(verify && typeof verify.cardPan === 'string' && verify.cardPan.trim()) ||
|
||||||
|
(meta && typeof meta.cardPan === 'string' && meta.cardPan.trim()) ||
|
||||||
|
null;
|
||||||
|
const completedAt =
|
||||||
|
(meta && typeof meta.completedAt === 'string' && meta.completedAt.trim()) ||
|
||||||
|
null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: transaction.id.toString(),
|
id: transaction.id.toString(),
|
||||||
type: transaction.type,
|
type: transaction.type,
|
||||||
@@ -919,6 +934,8 @@ export class OrdersService {
|
|||||||
gatewayType: transaction.gatewayType,
|
gatewayType: transaction.gatewayType,
|
||||||
gatewayRef: transaction.gatewayRef ?? null,
|
gatewayRef: transaction.gatewayRef ?? null,
|
||||||
gatewayTrackId: transaction.gatewayTrackId ?? null,
|
gatewayTrackId: transaction.gatewayTrackId ?? null,
|
||||||
|
cardPan,
|
||||||
|
paidAt: completedAt,
|
||||||
transferAccount: transaction.transferAccount,
|
transferAccount: transaction.transferAccount,
|
||||||
transferRefNumber: transaction.transferRefNumber,
|
transferRefNumber: transaction.transferRefNumber,
|
||||||
notes: transaction.notes,
|
notes: transaction.notes,
|
||||||
|
|||||||
Reference in New Issue
Block a user