feat(TPV-FIXES): completed feature

This commit is contained in:
chattie
2026-08-25 06:47:33 +02:00
parent 99c9bd4c55
commit 0b0bba9be8
5 changed files with 130 additions and 67 deletions

View File

@@ -474,25 +474,28 @@ export default function RegisterPage() {
setProcessing(true);
setError('');
try {
// TPV-FIXES: items without variantId (recovered sales) must be sent as free items
const saleItems = cart.map((item) => {
if (item.kind === 'free' || !item.variantId) {
return {
kind: 'free' as const,
name: item.name,
unitPriceCents: item.unitPriceCents,
quantity: item.quantity,
};
}
return {
kind: 'stock' as const,
variantId: item.variantId,
quantity: item.quantity,
discountCents: item.discountCents,
};
});
const result = await posApi.createSale<PosSaleResponse>({
idempotencyKey: generateIdempotencyKey(),
cashSessionId: config.session.id,
terminalId: config.terminal.id,
items: cart.map((item) =>
item.kind === 'free'
? {
kind: 'free',
name: item.name,
unitPriceCents: item.unitPriceCents,
quantity: item.quantity,
}
: {
kind: 'stock',
variantId: item.variantId,
quantity: item.quantity,
discountCents: item.discountCents,
},
),
items: saleItems,
payments: payments.map((payment) => ({
methodCode: payment.methodCode,
amountCents: payment.amountCents,
@@ -536,25 +539,28 @@ export default function RegisterPage() {
setProcessing(true);
setError('');
try {
// TPV-FIXES: items without variantId (recovered sales) must be sent as free items
const saleItems = cart.map((item) => {
if (item.kind === 'free' || !item.variantId) {
return {
kind: 'free' as const,
name: item.name,
unitPriceCents: item.unitPriceCents,
quantity: item.quantity,
};
}
return {
kind: 'stock' as const,
variantId: item.variantId,
quantity: item.quantity,
discountCents: item.discountCents,
};
});
const result = await posApi.createSale<PosSaleResponse>({
idempotencyKey: generateIdempotencyKey(),
cashSessionId: config.session.id,
terminalId: config.terminal.id,
items: cart.map((item) =>
item.kind === 'free'
? {
kind: 'free',
name: item.name,
unitPriceCents: item.unitPriceCents,
quantity: item.quantity,
}
: {
kind: 'stock',
variantId: item.variantId,
quantity: item.quantity,
discountCents: item.discountCents,
},
),
items: saleItems,
payments: [],
...(customer ? { customerId: customer.id } : {}),
...(name ? { posLabel: name } : {}),
@@ -686,27 +692,32 @@ export default function RegisterPage() {
setRecoveringSaleId(mergePendingSale.id);
setError('');
try {
// Park current cart first
// TPV-FIXES: items without variantId (recovered sales) must be sent as free items
const parkItems = cart.map((item) => {
if (item.kind === 'free' || !item.variantId) {
// Free item or recovered item without variantId
return {
kind: 'free' as const,
name: item.name,
unitPriceCents: item.unitPriceCents,
quantity: item.quantity,
};
}
return {
kind: 'stock' as const,
variantId: item.variantId,
quantity: item.quantity,
discountCents: item.discountCents,
};
});
// Park current cart first (with customer if available)
await posApi.createSale<PosSaleResponse>({
idempotencyKey: generateIdempotencyKey(),
cashSessionId: config.session.id,
terminalId: config.terminal.id,
items: cart.map((item) =>
item.kind === 'free'
? {
kind: 'free',
name: item.name,
unitPriceCents: item.unitPriceCents,
quantity: item.quantity,
}
: {
kind: 'stock',
variantId: item.variantId,
quantity: item.quantity,
discountCents: item.discountCents,
},
),
items: parkItems,
payments: [],
...(customer ? { customerId: customer.id } : {}),
});
// Then recover the selected sale
await doRecoverSale(mergePendingSale);