UNPKG

@mnpay/golomt

Version:
74 lines (73 loc) 3 kB
import w from "axios"; import { z as c } from "zod"; const a = (t) => t, k = "https://ecommerce.golomtbank.com"; var s = /* @__PURE__ */ ((t) => (t.invoice = "/api/invoice", t.inquiry = "/api/inquiry", t.check = "/api/check", t.payTransaction = "/api/pay", t.confirmation = "/api/confirmation", t.getToken = "/api/get/token", t.getSettlementDetails = "/api/getSettlementDetails", t))(s || {}); const T = async () => { if (typeof window > "u") return (await import("crypto")).createHmac; throw new Error("HMAC is not supported in the browser"); }, i = async (t, e) => (await T())("sha256", t.trim()).update(e.trim()).digest("hex"), f = async (t, e) => t.checksum ? t.checksum : await i(e, `${t.transactionId}${t.amount}${t.returnType}${t.callback}`), h = async (t, e) => t.checksum ? t.checksum : await i(e, `${t.transactionId}${t.transactionId}`), C = async (t, e) => t.checksum ? t.checksum : await i(e, `${t.amount}${t.transactionId}${t.token}`), E = ({ baseUrl: t = k, paymentMethod: e, language: n, invoiceNumber: r }) => `${t}/${e}/${n}/${r}`, v = a((t, e) => async (n) => { const r = await f(n, e.secret), o = { ...n, checksum: r }; return t.post(s.invoice, o); }), I = a((t, e) => async (n) => { const r = await h(n, e.secret), o = { ...n, checksum: r }; return t.post(s.inquiry, o); }), b = a((t) => (e) => t.post(s.confirmation, e)), S = a( (t, e) => async (n) => { const r = await C(n, e.secret), o = { ...n, checksum: r }; return t.post(s.payTransaction, o); } ), q = a( (t, e) => async (n) => { const r = await h(n, e.secret), o = { ...n, checksum: r }; return t.post(s.check, o); } ), D = a((t) => (e) => t.post(s.getToken, e)), H = (t) => (e, n) => t.post(s.getSettlementDetails, e, { params: n }), R = (t) => (e, n) => { t(e.body), n.sendStatus(200); }, U = c.object({ timestamp: c.string(), status: c.literal(200).or(c.literal(400)).or(c.literal(403)).or(c.literal(500)), error: c.enum(["Validation", "NotFound", "Internal", "Forbidden"]), message: c.string(), path: c.nativeEnum(s) }), j = c.object({ invoice: c.string(), status_code: c.string(), desc: c.string() }), z = (t) => { const e = `${t.endpoint ?? k}`, n = { ...t, endpoint: e }, r = w.create({ baseURL: e }); r.interceptors.request.use(async (u) => { const m = t.token; return m && (u.headers.Authorization = `Bearer ${m}`), u; }); const o = v(r, n), p = I(r, n), l = D(r), y = S(r, n), g = q(r, n), d = b(r), $ = H(r); return { api: r, getSettlementDetails: $, createInvoice: o, inquiry: p, tokenConfirmation: l, payTransaction: y, checkTransaction: g, tokenCreation: d, onNotification: R }; }; export { s as GolomtRequestPath, E as generateGolomtInvoiceUrl, f as generateInvoiceChecksum, C as generatePayTransactionChecksum, h as generateTransactionCheckChecksum, k as golomtDefaultBaseUrl, U as golomtErrorResponseSchema, j as merchantRedirectSchema, z as useGolomt };