UNPKG

@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.97 kB
import { createLogger } from '@unchainedshop/logger'; import { getTransaction, getTransactionCompletion } from './api.js'; const logger = createLogger('unchained:core-payment:postfinance-checkout'); export const postfinanceCheckoutHandler = async (req, reply) => { 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`); reply.status(200); return reply.send(`Order marked as paid: ${order.orderNumber}`); } catch (e) { logger.error(`PostFinance Checkout Webhook: Unchained rejected to checkout with message`, e); reply.status(500); return reply.send({ name: e.name, code: e.code, message: e.message }); } } else { logger.error(`PostFinance Checkout Webhook: Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`); reply.status(404); return reply.send(); } }; //# sourceMappingURL=handler-fastify.js.map