UNPKG

@coursebuilder/core

Version:

Core package for Course Builder

54 lines (52 loc) 1.43 kB
import { REFUND_PROCESSED_EVENT } from "./chunk-G5E54GVJ.js"; import { __name } from "./chunk-VLQXSCFN.js"; // src/lib/actions/process-refund.ts async function processRefund(request, cookies, options) { if (!options.adapter) throw new Error("Adapter not found"); if (request.headers?.["x-skill-secret"] !== process.env.SKILL_SECRET) { return { status: 401, body: "unauthorized" }; } try { const merchantChargeId = request.query?.merchantChargeId || request.body?.merchantChargeId; if (!merchantChargeId) throw new Error("No merchant charge id"); console.log("refunding purchase for:", merchantChargeId); const merchantCharge = await options.adapter?.getMerchantCharge(merchantChargeId); let refund; if (!merchantCharge) { refund = options.provider.refundCharge(merchantChargeId); } else { refund = options.provider.refundCharge(merchantCharge.identifier); } try { await options.inngest.send({ name: REFUND_PROCESSED_EVENT, data: { merchantChargeId } }); } catch (e) { console.log("error", e); } return { status: 200, body: JSON.stringify(refund) }; } catch (e) { console.log("error", e); throw new Error("unable-to-lookup-user"); } } __name(processRefund, "processRefund"); export { processRefund }; //# sourceMappingURL=chunk-MQGN7QP6.js.map