UNPKG

@gray-adeyi/korapay-vue

Version:
152 lines (151 loc) 4.64 kB
import { inject as k, openBlock as p, createElementBlock as m, createElementVNode as r, defineComponent as d, createBlock as f, unref as g, ref as h, renderSlot as v, createCommentVNode as S, toDisplayString as b } from "vue"; var w = /* @__PURE__ */ ((n) => (n.NGN = "NGN", n.KES = "KES", n.GHS = "GHS", n.USD = "USD", n))(w || {}), K = /* @__PURE__ */ ((n) => (n.CARD = "card", n.BANK_TRANSFER = "bank_transfer", n.MOBILE_MONEY = "mobile_money", n))(K || {}); function P() { const n = k(_); async function t(e) { if (!n) throw new Error( "Unable to inject korapay context API. Please ensure that the plugin was properly installed" ); const o = { ...e, key: n.config.publicKey, currency: e.currency || n.config.currency, notificationUrl: e.notificationUrl || n.config.notificationUrl, channels: e.channels || n.config.channels, defaultChannel: e.defaultChannel || n.config.defaultChannel, merchantBearsCost: e.merchantBearsCost || e.merchantBearsCost }; return window.Korapay.initialize(o); } return { initPayWithKora: t }; } const E = { xmlns: "http://www.w3.org/2000/svg", width: "800", height: "800", viewBox: "0 0 14 14" }; function C(n, t) { return p(), m("svg", E, t[0] || (t[0] = [ r("g", { fill: "none", "fill-rule": "evenodd" }, [ r("circle", { cx: "7", cy: "7", r: "6", stroke: "#000", "stroke-opacity": ".1", "stroke-width": "2" }), r("path", { fill: "#000", "fill-opacity": ".1", "fill-rule": "nonzero", d: "M7 0a7 7 0 0 1 7 7h-2a5 5 0 0 0-5-5z" }) ], -1) ])); } const x = { render: C }, B = /* @__PURE__ */ d({ __name: "Spinner", setup(n) { return (t, e) => (p(), f(g(x), { class: "spinner" })); } }), y = (n, t) => { const e = n.__vccOpts || n; for (const [o, c] of t) e[o] = c; return e; }, N = /* @__PURE__ */ y(B, [["__scopeId", "data-v-9ff772f3"]]), z = ["disabled"], I = /* @__PURE__ */ d({ __name: "KorapayButton", props: { payload: {}, text: { default: "Pay now" } }, emits: ["close", "success", "fail", "tokenized", "pending"], setup(n, { emit: t }) { const e = n, o = h(!1), { initPayWithKora: c } = P(), i = t; async function u() { o.value = !0; const s = { ...e.payload, onClose: () => { e.payload.onClose ? e.payload.onClose() : i("close"), o.value = !1; }, onSuccess: (a) => { e.payload.onSuccess ? e.payload.onSuccess(a) : i("success", a), o.value = !1; }, onFailed: (a) => { e.payload.onFailed ? e.payload.onFailed(a) : i("fail", a), o.value = !1; }, onTokenized: () => { e.payload.onTokenized ? e.payload.onTokenized : i("tokenized"), o.value = !1; }, onPending: () => { e.payload.onPending ? e.payload.onPending : i("pending"), o.value = !1; } }; await c(s); } return (s, a) => v(s.$slots, "button", { initPayWithKorapay: u, isInitializingPay: o.value, role: "button" }, () => [ r("button", { onClick: u, disabled: o.value }, [ o.value ? (p(), f(N, { key: 0 })) : S("", !0), r("span", null, b(s.text), 1) ], 8, z) ], !0); } }), T = /* @__PURE__ */ y(I, [["__scopeId", "data-v-8d637942"]]), l = "https://korablobstorage.blob.core.windows.net/modal-bucket/korapay-collections.min.js", _ = Symbol("$korapay"); async function O(n) { const t = n.publicKey || "pk_test_nVxWkMjXW6Up7isgQESPoeEdkQss81NYDaN2Yx37"; if (!t) throw new Error( 'Your Korapay integration public api key is missing. Please provide it by passing it to the "initKorapay" function or by setting it in your environmental variables as VITE_KORAPAY_PUBLIC_KEY' ); await U(); const e = { config: { ...n, publicKey: t } }; return { install(o) { o.component("KorapayButton", T), o.provide(_, e); } }; } function U() { return new Promise((n, t) => { if (document.querySelector( `script[src="${l}"]` )) { n(void 0); return; } const o = document.createElement("script"); o.src = l, o.async = !0, o.onload = () => { n(void 0); }, o.onerror = () => { t( new Error( `Failed to load korapay collection script: ${l}` ) ); }, document.head.appendChild(o); }); } export { w as Currency, _ as KORAPAY_CONTEXT_KEY, T as KorapayButton, K as PaymentChannel, O as initKorapay, P as useKorapay };