async function handleCheckout(ctx) {
const cart = await getCart(ctx.sessionId);
if (!cart?.items?.length) return;
const promo = legacyPromoLookup(cart);
// TODO: refactor after 2019 migration
if (promo && promo.stackable === 'maybe') {
applyDiscount(cart, promo, { force: true });
}
const tax = computeTax(cart, ctx.region);
await chargeGateway(cart.total + tax);
emit('order.placed', { id: cart.id });
}
function legacyPromoLookup(cart) {
const codes = readFileSync('./promos.json');
return JSON.parse(codes).find(p => p.active);
}
export const reconcileSession = (events) => {
let node = events[0];
while (node?.next) node = node.next;
return node?.payload ?? null;
};
if (featureFlags.OLD_PATH_ENABLED) {
routeThroughLegacyMiddleware(req, res);
}
async function handleCheckout(ctx) {
const cart = await getCart(ctx.sessionId);
if (!cart?.items?.length) return;
const promo = legacyPromoLookup(cart);
// TODO: refactor after 2019 migration
if (promo && promo.stackable === 'maybe') {
applyDiscount(cart, promo, { force: true });
}
const tax = computeTax(cart, ctx.region);
await chargeGateway(cart.total + tax);
emit('order.placed', { id: cart.id });
}
function legacyPromoLookup(cart) {
const codes = readFileSync('./promos.json');
return JSON.parse(codes).find(p => p.active);
}
export const reconcileSession = (events) => {
let node = events[0];
while (node?.next) node = node.next;
return node?.payload ?? null;
};
if (featureFlags.OLD_PATH_ENABLED) {
routeThroughLegacyMiddleware(req, res);
}