vue3-flutterwave
Version:
Vue3 package for integrating to Flutter Payment Gateway to recieve payments
55 lines (54 loc) • 1.64 kB
JavaScript
import { defineComponent as i, ref as u, onMounted as l, openBlock as p, createElementBlock as m, toDisplayString as d } from "vue";
const v = () => new Promise((r, s) => {
const t = "https://checkout.flutterwave.com/v3.js", e = document.createElement("script");
e.src = t, e.async = !0, document.getElementsByTagName("head")[0].appendChild(e);
const o = () => {
r(!0), e.removeEventListener("error", n), e.removeEventListener("load", o);
};
e.addEventListener("load", o);
const n = (c) => {
s(c), e.removeEventListener("error", n), e.removeEventListener("load", o);
};
e.addEventListener("error", n);
}), _ = /* @__PURE__ */ i({
__name: "Flutterwave",
props: {
options: null,
text: null
},
emits: ["err"],
setup(r, { emit: s }) {
const t = r, e = u(!1), o = () => {
s("err");
};
async function n() {
try {
e.value = await v();
} catch {
e.value = !1, o();
}
}
function c() {
if (e.value == !1)
return;
const a = {
public_key: t.options?.public_key,
tx_ref: t.options?.tx_ref,
amount: t.options?.amount,
currency: t.options?.currency,
payment_options: t.options?.payment_options || null,
redirect_url: t.options?.redirect_url || null,
meta: t.options?.meta || null,
customer: t.options?.customer || null,
customizations: t.options.customizations || null
};
FlutterwaveCheckout(a);
}
return l(() => {
n();
}), (a, f) => (p(), m("button", { onClick: c }, d(r.text || "Pay now"), 1));
}
});
export {
_ as default
};