@unchainedshop/plugins
Version:
Because of a Typescript issue with upstream "postfinancecheckout", the Postfinance plugin has been disabled from transpilation, import the source ts files from src and enable node_module tsc or copy over the src/payment/postfinance-checkout to your projec
39 lines • 1.96 kB
JavaScript
import { createLogger } from '@unchainedshop/logger';
import { getTransaction, getTransactionCompletion } from './api.js';
const logger = createLogger('unchained:core-payment:postfinance-checkout');
export const postfinanceCheckoutHandler = async (req, res) => {
const context = req.unchainedContext;
const { services, modules } = context;
const data = req.body;
if (data.listenerEntityTechnicalName === 'TransactionCompletion') {
try {
const transactionCompletion = await getTransactionCompletion(data.entityId);
const transaction = await getTransaction(transactionCompletion.linkedTransaction);
const { orderPaymentId } = transaction.metaData;
const orderPayment = await modules.orders.payments.findOrderPayment({
orderPaymentId,
});
if (!orderPayment)
throw new Error('Order Payment not found');
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
paymentContext: {
transactionId: transactionCompletion.linkedTransaction,
},
});
logger.info(`PostFinance Checkout Webhook: Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData.orderPaymentId} as paid`);
res.writeHead(200);
res.end(`Order marked as paid: ${order.orderNumber}`);
}
catch (e) {
logger.error(`PostFinance Checkout Webhook: Unchained rejected to checkout with message`, e);
res.writeHead(500);
res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
}
}
else {
logger.error(`PostFinance Checkout Webhook: Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`);
res.writeHead(404);
res.end();
}
};
//# sourceMappingURL=handler-express.js.map